Changeset 432 for trunk


Ignore:
Timestamp:
May 5, 2006, 12:04:13 PM (18 years ago)
Author:
qiaow
Message:

Added some comments

Location:
trunk/gui/vizservers/nanovis
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/PlaneRenderer.cpp

    r431 r432  
    2020  g_context(_context),
    2121  render_width(_width),
    22   render_height(_height)
     22  render_height(_height),
     23  active_plane(-1)
    2324{
    2425  plane.clear();
     
    7273  //glColor3f(1.,1.,1.);         //MUST HAVE THIS LINE!!!
    7374
     75  //if no active plane
     76  if(active_plane == -1)
     77    return;
     78
    7479  activate_shader(active_plane);
    7580  glBegin(GL_QUADS);
     
    104109
    105110void PlaneRenderer::set_active_plane(int index) { active_plane = index; }
     111void PlaneRenderer::set_screen_size(int w, int h) { render_width = w;  render_height = h;}
    106112
  • trunk/gui/vizservers/nanovis/PlaneRenderer.h

    r431 r432  
    6464                                                //plane is added.
    6565  void set_active_plane(int index);             //set the active plane to be rendered
     66  void set_screen_size(int w, int h);           //change the rendering size
    6667  void render();
    6768};
  • trunk/gui/vizservers/nanovis/Texture2D.cpp

    r431 r432  
    132132  fprintf(stderr, "max texture units: %d.\n", max);
    133133}
     134
  • trunk/gui/vizservers/nanovis/Texture2D.h

    r431 r432  
    3636  void activate();
    3737  void deactivate();
     38  void enable();
     39  void disable();
    3840  GLuint initialize(float* data);
    3941  static void check_max_size();
  • trunk/gui/vizservers/nanovis/VolumeRenderer.cpp

    r431 r432  
    168168    float z_step = fabs(zNear-zFar)/n_slices;           
    169169    int n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1);
     170
     171    //if no cloud
     172    //n_actual_slices = 0;
     173   
    170174    actual_slices[cur_vol] = n_actual_slices;
    171175    polys[cur_vol] = new ConvexPolygon*[n_actual_slices];
     176
     177    //if no cloud
     178    //polys[cur_vol] = NULL;
    172179
    173180    float slice_z;
     
    259266
    260267    int counter = 0;
     268   
    261269    //transform slices and store them
    262270    for (int i=0; i<n_actual_slices; i++){
     
    291299        total_rendered_slices++;
    292300    }
     301   
    293302  } //iterate all volumes
    294303  //fprintf(stderr, "total slices: %d\n", total_rendered_slices);
     
    705714void VolumeRenderer::switch_volume_mode() { volume_mode = (!volume_mode); }
    706715
     716void VolumeRenderer::enable_volume(int index){
     717  volume[index]->enable();
     718}
     719
     720void VolumeRenderer::disable_volume(int index){
     721  volume[index]->disable();
     722}
  • trunk/gui/vizservers/nanovis/VolumeRenderer.h

    r423 r432  
    8686  void switch_slice_mode(); //switch_cutplane_mode
    8787  void switch_volume_mode();
     88  void enable_volume(int index); //enable a volume
     89  void disable_volume(int index); //disable a volume
    8890};
    8991
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r431 r432  
    129129static int OutlineCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    130130static int RefreshCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
     131static int Switch2D3DCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
     132static int PlaneNewCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
     133static int PlaneLinkCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
     134static int PlaneEnableCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    131135
    132136static int DecodeAxis _ANSI_ARGS_((Tcl_Interp *interp, char *str, int *valPtr));
     
    516520}
    517521
     522//Enable a volume.
     523//Can enable a volume that is not yet added to the volume renderer.
     524//But it won't be rendered until it's added to the volume renderer using VolumeLinkCmd
     525//volume_index: the index maintained in the volume renderer.
    518526static int
    519527VolumeEnableCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    520528{
    521   fprintf(stderr, "link volume command\n");
     529  fprintf(stderr, "enabled a volume to render command\n");
    522530
    523531  double volume_index, mode;
     
    525533  if (argc != 3) {
    526534    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    527                 " volume_index tf_index \"", (char*)NULL);
     535                " volume_index mode \"", (char*)NULL);
    528536    return TCL_ERROR;
    529537  }
     
    536544
    537545  if(mode==0)
    538     volume[(int)volume_index]->disable();
     546    vol_render->disable_volume((int)volume_index);
    539547  else
    540     volume[(int)volume_index]->enable();
     548    vol_render->enable_volume((int)volume_index);
    541549
    542550  return TCL_OK;
     
    617625        return TCL_OK;
    618626}
     627
     628
     629//Switch:
     630//arg[1] = 0 : 3D rendering
     631//arg[1] !=0 : 2D rendering
     632static int
     633Switch2D3DCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     634{
     635  fprintf(stderr, "switch 2D 3D rendering modes cmd\n");
     636
     637  double mode;
     638
     639  if (argc != 2) {
     640    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     641                " mode\"", (char*)NULL);
     642    return TCL_ERROR;
     643  }
     644  if (Tcl_GetDouble(interp, argv[1], &mode) != TCL_OK) {
     645        return TCL_ERROR;
     646  }
     647
     648  if(mode==0)
     649    volume_mode = true;
     650  else
     651    volume_mode = false;
     652
     653  return TCL_OK;
     654}
     655
     656
     657static int
     658PlaneNewCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])){
     659  fprintf(stderr, "load plane for 2D visualization command\n");
     660
     661  double index, w, h;
     662
     663  if (argc != 4) {
     664    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     665                " plane_index w h \"", (char*)NULL);
     666    return TCL_ERROR;
     667  }
     668  if (Tcl_GetDouble(interp, argv[1], &index) != TCL_OK) {
     669        return TCL_ERROR;
     670  }
     671  if (Tcl_GetDouble(interp, argv[2], &w) != TCL_OK) {
     672        return TCL_ERROR;
     673  }
     674  if (Tcl_GetDouble(interp, argv[3], &h) != TCL_OK) {
     675        return TCL_ERROR;
     676  }
     677
     678  //Now read w*h*4 bytes. The server expects the plane to be a stream of floats
     679  char* tmp = new char[int(w*h*sizeof(float))];
     680  bzero(tmp, w*h*4);
     681  int status = read(0, tmp, w*h*sizeof(float));
     682  if (status <= 0){
     683    exit(0);
     684  }
     685 
     686  plane[(int)index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp);
     687 
     688  delete[] tmp;
     689  return TCL_OK;
     690}
     691
     692
     693static
     694int PlaneLinkCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])){
     695  fprintf(stderr, "link the plane to the 2D renderer command\n");
     696
     697  double plane_index, tf_index;
     698
     699  if (argc != 3) {
     700    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     701                " plane_index tf_index \"", (char*)NULL);
     702    return TCL_ERROR;
     703  }
     704  if (Tcl_GetDouble(interp, argv[1], &plane_index) != TCL_OK) {
     705        return TCL_ERROR;
     706  }
     707  if (Tcl_GetDouble(interp, argv[2], &tf_index) != TCL_OK) {
     708        return TCL_ERROR;
     709  }
     710
     711  plane_render->add_plane(plane[(int)plane_index], tf[(int)tf_index]);
     712
     713  return TCL_OK;
     714}
     715
     716
     717//Enable a 2D plane for render
     718//The plane_index is the index mantained in the 2D plane renderer
     719static
     720int PlaneEnableCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])){
     721  fprintf(stderr, "enable a plane so the 2D renderer can render it command\n");
     722
     723  double plane_index, mode;
     724
     725  if (argc != 3) {
     726    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     727                " plane_index mode \"", (char*)NULL);
     728    return TCL_ERROR;
     729  }
     730  if (Tcl_GetDouble(interp, argv[1], &plane_index) != TCL_OK) {
     731        return TCL_ERROR;
     732  }
     733  if (Tcl_GetDouble(interp, argv[2], &mode) != TCL_OK) {
     734        return TCL_ERROR;
     735  }
     736
     737  if(mode==0)
     738    plane_render->set_active_plane(-1);
     739  else
     740    plane_render->set_active_plane(plane_index);
     741
     742  return TCL_OK;
     743}
     744
     745
    619746
    620747//report errors related to CG shaders
     
    11761303      screen_buffer = 0;
    11771304  }
    1178   screen_buffer = new unsigned char[5*win_width*win_height];
     1305  screen_buffer = new unsigned char[4*win_width*win_height];
    11791306  assert(screen_buffer!=0);
    11801307
     
    11901317  //change the camera setting
    11911318  cam->set_screen_size(win_width, win_height);
     1319  plane_render->set_screen_size(win_width, win_height);
    11921320
    11931321  //Reinitialize final fbo for final display
     
    13491477       screen_buffer = 0;
    13501478   }
    1351    screen_buffer = new unsigned char[5*win_width*win_height];
     1479   screen_buffer = new unsigned char[4*win_width*win_height];
    13521480   assert(screen_buffer!=0);
    13531481
     
    14731601 
    14741602  //debug: set magic number
    1475   memset(screen_buffer, 253, 5*win_width*win_height);
    1476 
    1477   glReadPixels(0, 0, win_width, win_height, GL_RGBA, GL_UNSIGNED_BYTE, screen_buffer);
    1478   //glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer);
     1603  //memset(screen_buffer, 253, 5*win_width*win_height);
     1604  //glReadPixels(0, 0, win_width, win_height, GL_RGBA, GL_UNSIGNED_BYTE, screen_buffer);
     1605 
     1606  glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer);
    14791607  assert(glGetError()==0);
    14801608 
     1609  /*
     1610  //debug: check from the back of screen_buffer to see how far ReadPixel went
    14811611  fprintf(stderr, "%d %d:", win_width, win_height);
    14821612  for(int i=5*win_width*win_height-1; i>=0; i--){
     
    14841614      fprintf(stderr, "%d\n", i);
    14851615      i=0;
    1486       //fprintf(stderr, "%d ", screen_buffer[i]);
    1487     }
    1488   }
     1616    }
     1617  }
     1618  */
    14891619 
    14901620  /*
     
    20292159   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    20302160
    2031    if( volume_mode){ //3D rendering mode
     2161   if(volume_mode){ //3D rendering mode
    20322162     glEnable(GL_TEXTURE_2D);
    20332163     glEnable(GL_DEPTH_TEST);
     
    20722202   read_screen();
    20732203#else
    2074    read_screen();
     2204   //read_screen();
    20752205#endif   
    20762206
Note: See TracChangeset for help on using the changeset viewer.