Changeset 426


Ignore:
Timestamp:
May 2, 2006, 12:54:02 PM (18 years ago)
Author:
qiaow
Message:

Added a bunch of basic communication commands. This is a minimum set that a rappture appliation should use.

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

Legend:

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

    r425 r426  
    4545
    4646void Camera::activate(){
    47   fprintf(stderr, "camera: %d, %d\n", width, height);
     47  //fprintf(stderr, "camera: %d, %d\n", width, height);
    4848  glViewport(0, 0, width, height);
    4949  glMatrixMode(GL_PROJECTION);
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r425 r426  
    105105static Tcl_Interp *interp;
    106106
    107 static int CameraCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    108 static int CutCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    109 static int HelloCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    110 static int LoadCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    111 static int RefreshCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    112 static int MoveCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    113 static int TransferFunctionCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    114 static int ScreenSizeCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));
    115 
    116107//Tcl callback functions
    117108static int
     
    120111
    121112        fprintf(stderr, "camera cmd\n");
    122         double x, y, z;
    123 
    124         if (argc != 4) {
     113        double angle_x, angle_y, angle_z, aim_x, aim_y, aim_z;
     114
     115        if (argc != 7) {
    125116                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    126                         " x_angle y_angle z_angle\"", (char*)NULL);
     117                        " x_angle y_angle z_angle aim_x aim_y aim_z\"", (char*)NULL);
    127118                return TCL_ERROR;
    128119        }
    129         if (Tcl_GetDouble(interp, argv[1], &x) != TCL_OK) {
     120        if (Tcl_GetDouble(interp, argv[1], &angle_x) != TCL_OK) {
    130121                return TCL_ERROR;
    131122        }
    132         if (Tcl_GetDouble(interp, argv[2], &y) != TCL_OK) {
     123        if (Tcl_GetDouble(interp, argv[2], &angle_y) != TCL_OK) {
    133124                return TCL_ERROR;
    134125        }
    135         if (Tcl_GetDouble(interp, argv[3], &z) != TCL_OK) {
     126        if (Tcl_GetDouble(interp, argv[3], &angle_z) != TCL_OK) {
    136127                return TCL_ERROR;
    137128        }
    138         set_camera(x, y, z);
     129        if (Tcl_GetDouble(interp, argv[4], &aim_x) != TCL_OK) {
     130                return TCL_ERROR;
     131        }
     132        if (Tcl_GetDouble(interp, argv[5], &aim_y) != TCL_OK) {
     133                return TCL_ERROR;
     134        }
     135        if (Tcl_GetDouble(interp, argv[6], &aim_z) != TCL_OK) {
     136                return TCL_ERROR;
     137        }
     138
     139        //set_camera(x, y, z);
     140        cam->rotate(angle_x, angle_y, angle_z);
     141        cam->aim(aim_x, aim_y, aim_z);
    139142        return TCL_OK;
    140143}
     
    145148//change screen size
    146149static int
    147 ScreenSizeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     150ScreenResizeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    148151{
    149152
     
    177180void update_transfer_function(int index, float* data);
    178181
    179 //The client sends the Transfer function command to tell the index of the transfer function
     182//The client sends the first sends the index of the transfer function
    180183//to modify. Then the client sends a chunck of binary floats.
    181184static int
    182 TransferFunctionCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     185TransferFunctionUpdateCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    183186{
    184   fprintf(stderr, "transfer function cmd\n");
    185 
    186   double index_d;
    187   int index;
     187  fprintf(stderr, "update transfer function cmd\n");
     188
     189  double index;
    188190
    189191  if (argc != 2) {
     
    192194    return TCL_ERROR;
    193195  }
    194   if (Tcl_GetDouble(interp, argv[1], &index_d) != TCL_OK) {
     196  if (Tcl_GetDouble(interp, argv[1], &index) != TCL_OK) {
    195197        return TCL_ERROR;
    196198  }
    197 
    198   index = int(index_d);
    199199
    200200  //Now read 256*4*4 bytes. The server expects the transfer function to be 256 units of (RGBA) floats
     
    206206  }
    207207
    208   update_transfer_function(index, (float*)tmp);
     208  update_transfer_function((int)index, (float*)tmp);
     209  return TCL_OK;
     210}
     211
     212
     213//The client sends the index of the index of the transfer function
     214//to create. Then the client sends a chunck of binary floats.
     215static int
     216TransferFunctionNewCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     217{
     218  fprintf(stderr, "update transfer function cmd\n");
     219
     220  double index;
     221
     222  if (argc != 2) {
     223    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     224                " tf_index\"", (char*)NULL);
     225    return TCL_ERROR;
     226  }
     227  if (Tcl_GetDouble(interp, argv[1], &index) != TCL_OK) {
     228        return TCL_ERROR;
     229  }
     230
     231  //Now read 256*4*4 bytes. The server expects the transfer function to be 256 units of (RGBA) floats
     232  char tmp[256*4*4];
     233  bzero(tmp, 256*4*4);
     234  int status = read(0, tmp, 256*4*4);
     235  if (status <= 0) {
     236    exit(0);
     237  }
     238
     239  tf[(int)index] = new TransferFunction(256, (float*)tmp);
    209240  return TCL_OK;
    210241}
     
    217248}
    218249
     250static int
     251VolumeLinkCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     252{
     253  fprintf(stderr, "link volume command\n");
     254
     255  double volume_index, tf_index;
     256
     257  if (argc != 3) {
     258    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     259                " volume_index tf_index \"", (char*)NULL);
     260    return TCL_ERROR;
     261  }
     262  if (Tcl_GetDouble(interp, argv[1], &volume_index) != TCL_OK) {
     263        return TCL_ERROR;
     264  }
     265  if (Tcl_GetDouble(interp, argv[2], &tf_index) != TCL_OK) {
     266        return TCL_ERROR;
     267  }
     268
     269  vol_render->add_volume(volume[(int)volume_index], tf[(int)tf_index]);
     270
     271  return TCL_OK;
     272}
     273
     274
     275static int
     276VolumeEnableCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     277{
     278  fprintf(stderr, "link volume command\n");
     279
     280  double volume_index, mode;
     281
     282  if (argc != 3) {
     283    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     284                " volume_index tf_index \"", (char*)NULL);
     285    return TCL_ERROR;
     286  }
     287  if (Tcl_GetDouble(interp, argv[1], &volume_index) != TCL_OK) {
     288        return TCL_ERROR;
     289  }
     290  if (Tcl_GetDouble(interp, argv[2], &mode) != TCL_OK) {
     291        return TCL_ERROR;
     292  }
     293
     294  if(mode==0)
     295    volume[(int)volume_index]->disable();
     296  else
     297    volume[(int)volume_index]->enable();
     298
     299  return TCL_OK;
     300}
     301
     302
    219303void load_volume(int index, int width, int height, int depth, int n_component, float* data);
    220304
    221305//The client sends the load data command to tell the index of the volume, and the dimensions of the data
    222 //Then the client sends a chunck of binary floats.
     306//Then the client sends a chunck of binary floats. This call creates a NEW volume
    223307static int
    224 LoadCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     308VolumeNewCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    225309{
    226310  fprintf(stderr, "load data command\n");
     
    230314  if (argc != 5) {
    231315    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    232                 " volume_index x y z \"", (char*)NULL);
     316                " volume_index w h d \"", (char*)NULL);
    233317    return TCL_ERROR;
    234318  }
     
    255339 
    256340  load_volume(int(index), int(w), int(h), int(d), 4, (float*) tmp);
     341 
    257342  delete[] tmp;
    258 
    259343  return TCL_OK;
    260344}
    261345
    262 //move the volume object in space so its starting corner is at (x, y, z)
    263 void move_volume(int index, float x, float y, float z){
    264   volume[index]->move(Vector3(x, y, z));
    265 }
    266 
    267346
    268347static int
    269 MoveCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     348VolumeMoveCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    270349{
    271350
    272         fprintf(stderr, "move cmd\n");
    273         double index_d, x, y, z;
     351        fprintf(stderr, "move volume cmd\n");
     352        double index, x, y, z;
    274353
    275354        if (argc != 5) {
     
    278357                return TCL_ERROR;
    279358        }
    280         if (Tcl_GetDouble(interp, argv[1], &index_d) != TCL_OK) {
     359        if (Tcl_GetDouble(interp, argv[1], &index) != TCL_OK) {
    281360                return TCL_ERROR;
    282361        }
     
    292371       
    293372        //set_object(x, y, z);
    294         move_volume((int)index_d, x, y, z);
     373        volume[(int)index]->move(Vector3(x, y, z));
    295374        return TCL_OK;
    296375}
    297376
     377
     378static int
     379CutMoveCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     380{
     381
     382        fprintf(stderr, "move cutplane cmd\n");
     383        double volume_index, cut_index, location;
     384
     385        if (argc != 4) {
     386                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     387                        " vol_index cut_index cut_location\"", (char*)NULL);
     388                return TCL_ERROR;
     389        }
     390        if (Tcl_GetDouble(interp, argv[1], &volume_index) != TCL_OK) {
     391                return TCL_ERROR;
     392        }
     393        if (Tcl_GetDouble(interp, argv[2], &cut_index) != TCL_OK) {
     394                return TCL_ERROR;
     395        }
     396        if (Tcl_GetDouble(interp, argv[3], &location) != TCL_OK) {
     397                return TCL_ERROR;
     398        }
     399       
     400        volume[(int)volume_index]->move_cutplane((int)cut_index, (float)location);
     401        return TCL_OK;
     402}
     403
     404
     405static int
     406CutEnableCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
     407{
     408  fprintf(stderr, "cutplane enable/disable command\n");
     409
     410  double volume_index, cut_index, mode;
     411
     412  if (argc != 4) {
     413    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     414                " volume_index cut_index mode\"", (char*)NULL);
     415    return TCL_ERROR;
     416  }
     417  if (Tcl_GetDouble(interp, argv[1], &volume_index) != TCL_OK) {
     418        return TCL_ERROR;
     419  }
     420  if (Tcl_GetDouble(interp, argv[2], &cut_index) != TCL_OK) {
     421        return TCL_ERROR;
     422  }
     423  if (Tcl_GetDouble(interp, argv[3], &mode) != TCL_OK) {
     424        return TCL_ERROR;
     425  }
     426
     427  if(mode==0)
     428    volume[(int)volume_index]->disable_cutplane((int)cut_index);
     429  else
     430    volume[(int)volume_index]->enable_cutplane((int)cut_index);
     431
     432  return TCL_OK;
     433}
    298434
    299435static int
     
    10881224  Tcl_MakeSafe(interp);
    10891225
     1226  //hello test
    10901227  Tcl_CreateCommand(interp, "hello", HelloCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1228
     1229  //set camera (viewing)
    10911230  Tcl_CreateCommand(interp, "camera", CameraCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
    1092   Tcl_CreateCommand(interp, "move", MoveCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
    1093   Tcl_CreateCommand(interp, "transferfunction", TransferFunctionCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1231
     1232  //resize the width and height of render screen
     1233  Tcl_CreateCommand(interp, "screen", ScreenResizeCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1234
     1235  //create new transfer function
     1236  Tcl_CreateCommand(interp, "tf_new", TransferFunctionNewCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1237  //update an existing transfer function
     1238  Tcl_CreateCommand(interp, "tf_update", TransferFunctionUpdateCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1239
     1240  //create new volume
     1241  Tcl_CreateCommand(interp, "volume_new", VolumeNewCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1242  //link an EXISTING volume and transfer function to the volume renderer.
     1243  //Only after being added, can a volume be rendered. This command does not create a volume nor a transfer function
     1244  Tcl_CreateCommand(interp, "volume_link", VolumeLinkCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1245  //move an volume
     1246  Tcl_CreateCommand(interp, "volume_move", VolumeMoveCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1247  //enable or disable an existing volume
     1248  Tcl_CreateCommand(interp, "volume_enable", VolumeEnableCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1249
     1250  //move a cut plane
     1251  Tcl_CreateCommand(interp, "cut_move", CutMoveCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1252  //enable or disable a cut plane
     1253  Tcl_CreateCommand(interp, "cut_enable", CutEnableCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
     1254
     1255  //refresh the screen (render again)
    10941256  Tcl_CreateCommand(interp, "refresh", RefreshCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
    1095   //Tcl_CreateCommand(interp, "cut", CutCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
    1096   Tcl_CreateCommand(interp, "load", LoadCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
    1097   Tcl_CreateCommand(interp, "screen", ScreenSizeCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);
    10981257}
    10991258
Note: See TracChangeset for help on using the changeset viewer.