Changeset 860 for trunk/vizservers


Ignore:
Timestamp:
Jan 29, 2008, 1:06:07 PM (17 years ago)
Author:
vrinside
Message:

Put flow protocol. It still needs to implement some function for lic slices.

Location:
trunk/vizservers/nanovis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/Command.cpp

    r851 r860  
    8282        int n_component, float* data, double vmin, double vmax,
    8383        double nzero_min);
     84extern void load_vector_stream(int index, std::istream& fin);
    8485
    8586// Tcl interpreter for incoming messages
     
    128129static Tcl_CmdProc UpCmd;
    129130static Tcl_CmdProc VolumeCmd;
     131static Tcl_CmdProc FlowCmd;
    130132
    131133static int GetVolumeIndices(Tcl_Interp *interp, int argc, const char *argv[],
     
    226228        return TCL_ERROR;
    227229    }
     230
     231    /*
     232    Trace("Camera pos(%f %f %f), rot(%f %f %f), aim(%f %f %f)\n",
     233            NanoVis::cam->location.x, NanoVis::cam->location.y, NanoVis::cam->location.z,
     234            NanoVis::cam->angle.x, NanoVis::cam->angle.y, NanoVis::cam->angle.z,
     235            NanoVis::cam->target.x, NanoVis::cam->target.y, NanoVis::cam->target.z);
     236
     237    NanoVis::cam->aim(0, 0, 100);
     238    NanoVis::cam->rotate(-51.868206, 88.637497, 0.000000);
     239    NanoVis::cam->move(-0.000000, -0.000000, -0.819200);
     240    */
     241
    228242    return TCL_OK;
    229243}
     
    10811095}
    10821096
     1097static int getDataStream(int nbytes, Rappture::Buffer* buf)
     1098{
     1099    Rappture::Outcome err;
     1100
     1101    char buffer[8096];
     1102    while (nbytes > 0) {
     1103        unsigned int chunk;
     1104                int status;
     1105
     1106                chunk = (sizeof(buffer) < (unsigned int) nbytes) ? sizeof(buffer) : nbytes;
     1107        status = fread(buffer, 1, chunk, stdin);
     1108                if (status > 0) {
     1109           buf->append(buffer,status);
     1110           nbytes -= status;
     1111        } else {
     1112                        printf("data unpacking failed\n");
     1113            Tcl_AppendResult(interp, "data unpacking failed: unexpected EOF",
     1114                (char*)NULL);
     1115            return TCL_ERROR;
     1116        }
     1117        }
     1118
     1119    err = Rappture::encoding::decode(*buf,RPENC_Z|RPENC_B64|RPENC_HDR);
     1120    if (err) {
     1121        printf("ERROR -- DECODING\n");
     1122        fflush(stdout);
     1123        Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
     1124        return TCL_ERROR;
     1125    }
     1126}
     1127
     1128static int
     1129FlowCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[])
     1130{
     1131    Rappture::Outcome err;
     1132
     1133    char c = argv[1][0];
     1134    if ((c == 'v') && (strcmp(argv[1], "vectorid") == 0))
     1135    {
     1136        int n = 0;
     1137        if (Tcl_GetInt(interp, argv[2], &n) != TCL_OK) {
     1138            return TCL_ERROR;
     1139        }
     1140
     1141        if (NanoVis::particleRenderer)
     1142        {
     1143
     1144            NanoVis::particleRenderer->setVectorField(
     1145                NanoVis::volume[n]->id,
     1146                1.0f,
     1147                NanoVis::volume[n]->height / (float) NanoVis::volume[n]->width,
     1148                NanoVis::volume[n]->depth / (float)  NanoVis::volume[n]->width,
     1149                NanoVis::volume[n]->range_max());
     1150       
     1151            NanoVis::initParticle();
     1152
     1153        }
     1154
     1155        if (NanoVis::licRenderer)
     1156        {
     1157            NanoVis::licRenderer->setVectorField(
     1158                NanoVis::volume[n]->id,
     1159                1.0f/NanoVis::volume[n]->aspect_ratio_width,
     1160                1.0f/NanoVis::volume[n]->aspect_ratio_height,
     1161                1.0f/NanoVis::volume[n]->aspect_ratio_depth,
     1162                NanoVis::volume[n]->range_max());
     1163            NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z);
     1164        }
     1165    }
     1166    else if (c == 'l' && strcmp(argv[1],"lic") == 0)
     1167    {
     1168        if (argc < 3) {
     1169            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1170                argv[1], " on|off \"", (char*)NULL);
     1171            return TCL_ERROR;
     1172        }
     1173
     1174        char ch = argv[2][0];
     1175        if (ch == 'o' && strcmp(argv[2],"on") == 0)
     1176        {
     1177                NanoVis::lic_on = true;
     1178        }
     1179        else if (ch == 'o' && strcmp(argv[2],"off") == 0)
     1180        {
     1181                NanoVis::lic_on = false;
     1182        }
     1183        else
     1184        {
     1185                return TCL_ERROR;
     1186        }
     1187    }
     1188    else if (c == 'p' && strcmp(argv[1],"particle") == 0)
     1189        {
     1190        if (argc < 4) {
     1191            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1192                argv[1], " more parameters \"", (char*)NULL);
     1193            return TCL_ERROR;
     1194        }
     1195
     1196                char ch = argv[2][0];
     1197                if (ch == 'v' && strcmp(argv[2],"visible") == 0)
     1198                {
     1199                        int state;
     1200                if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK)
     1201                        {
     1202                                return TCL_ERROR;
     1203                        }
     1204                        NanoVis::particle_on = state;
     1205                }
     1206                else if (ch == 's' && strcmp(argv[2],"slice") == 0)
     1207                {
     1208                        if (argv[3][0] == 'x')
     1209                        {
     1210                                NanoVis::lic_axis = 0;
     1211                        }
     1212                        else if (argv[3][0] == 'y')
     1213                        {
     1214                                NanoVis::lic_axis = 1;
     1215                        }
     1216                        else if (argv[3][0] == 'z')
     1217                        {
     1218                                NanoVis::lic_axis = 2;
     1219                        }
     1220                        else
     1221                        {
     1222                                // TBD.. put error message
     1223                                return TCL_ERROR;
     1224                        }
     1225
     1226                }
     1227                else if (ch == 's' && strcmp(argv[2],"slicepos") == 0)
     1228                {
     1229                        float pos;
     1230                        if (GetFloat(interp, argv[2], &pos) != TCL_OK)
     1231                        {
     1232                                return TCL_ERROR;
     1233                        }
     1234
     1235                        if (pos < 0.0f) pos = 0.0f;
     1236                        if (pos > 1.0f) pos = 1.0f;
     1237
     1238                        switch (NanoVis::lic_axis)
     1239                        {
     1240                        case 0 :
     1241                                NanoVis::lic_slice_x = pos;
     1242                                break;
     1243                        case 1 :
     1244                                NanoVis::lic_slice_y = pos;
     1245                                break;
     1246                        case 2 :
     1247                                NanoVis::lic_slice_z = pos;
     1248                                break;
     1249                        }
     1250                }
     1251                else
     1252                {
     1253                        return TCL_ERROR;
     1254                }
     1255        }
     1256    else if (c == 'r' && strcmp(argv[1],"reset") == 0)
     1257    {
     1258            NanoVis::initParticle();
     1259    }
     1260    else if (c == 'c' && strcmp(argv[1],"capture") == 0)
     1261    {
     1262                int frame_count;
     1263        if (Tcl_GetInt(interp, argv[2], &frame_count) != TCL_OK)
     1264                {
     1265                return TCL_ERROR;
     1266                }
     1267
     1268        if (NanoVis::licRenderer) NanoVis::licRenderer->activate();
     1269        if (NanoVis::particleRenderer) NanoVis::particleRenderer->activate();
     1270
     1271                // Karl
     1272                // pur your code ..
     1273
     1274        if (NanoVis::licRenderer) NanoVis::licRenderer->deactivate();
     1275        if (NanoVis::particleRenderer) NanoVis::particleRenderer->deactivate();
     1276        NanoVis::initParticle();
     1277    }
     1278    else if (c == 'd' && strcmp(argv[1],"data") == 0)
     1279        {
     1280                char ch = argv[2][0];
     1281        if (ch == 'f' && strcmp(argv[2],"follows") == 0) {
     1282            int nbytes;
     1283            if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK)
     1284                        {
     1285                return TCL_ERROR;
     1286            }
     1287
     1288                         Rappture::Buffer buf;
     1289                        if (getDataStream(nbytes, &buf) != TCL_OK)
     1290                        {
     1291                                /// TBD..
     1292                //Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
     1293                                return TCL_ERROR;
     1294                        }
     1295
     1296            int n = NanoVis::n_volumes;
     1297            std::stringstream fdata;
     1298            fdata.write(buf.bytes(),buf.size());
     1299            load_vector_stream(n, fdata);
     1300           
     1301            //
     1302            // BE CAREFUL:  Set the number of slices to something
     1303            //   slightly different for each volume.  If we have
     1304            //   identical volumes at exactly the same position
     1305            //   with exactly the same number of slices, the second
     1306            //   volume will overwrite the first, so the first won't
     1307            //   appear at all.
     1308            //
     1309            if (NanoVis::volume[n] != NULL)
     1310                        {
     1311                NanoVis::volume[n]->set_n_slice(256-n);
     1312                NanoVis::volume[n]->disable_cutplane(0);
     1313                NanoVis::volume[n]->disable_cutplane(1);
     1314                NanoVis::volume[n]->disable_cutplane(2);
     1315
     1316                NanoVis::vol_renderer->add_volume(NanoVis::volume[n],NanoVis::get_transfunc("default"));
     1317            }
     1318        }
     1319        }
     1320    else
     1321    {
     1322        return TCL_ERROR;
     1323    }
     1324   
     1325    return TCL_OK;
     1326}
     1327
    10831328static int
    10841329HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int argc,
     
    10871332    if (argc < 2) {
    10881333        srand((unsigned)time(NULL));
    1089         int size = 20 * 20;
     1334        int size = 20 * 200;
    10901335        double sigma = 5.0;
    10911336        double mean = exp(0.0) / (sigma * sqrt(2.0));
     
    10961341            x = - 10 + i%20;
    10971342            data[i] = exp(- (x * x)/(2 * sigma * sigma)) /
    1098                 (sigma * sqrt(2.0)) / mean * 2;
     1343                (sigma * sqrt(2.0)) / mean * 2 + 1000;
    10991344        }
    11001345
     
    11041349    float miny = 0.5f;
    11051350    float maxy = 3.5f;
    1106         heightMap->setHeight(minx, miny, maxx, maxy, 20, 20, data);
     1351        heightMap->setHeight(minx, miny, maxx, maxy, 20, 200, data);
    11071352        heightMap->setColorMap(NanoVis::get_transfunc("default"));
    11081353        heightMap->setVisible(true);
     
    17712016    // manipulate volume data
    17722017    Tcl_CreateCommand(interp, "volume", VolumeCmd,
     2018        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2019
     2020    Tcl_CreateCommand(interp, "flow", FlowCmd,
     2021        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2022
     2023    Tcl_CreateCommand(interp, "axis", AxisCmd,
     2024        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2025
     2026    Tcl_CreateCommand(interp, "grid", GridCmd,
     2027        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2028
     2029    Tcl_CreateCommand(interp, "heightmap", HeightMapCmd,
     2030        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2031
     2032    // get screenshot
     2033    Tcl_CreateCommand(interp, "screenshot", ScreenShotCmd,
     2034        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     2035
     2036    Tcl_CreateCommand(interp, "unirect2d", UniRect2dCmd,
    17732037        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    17742038
  • trunk/vizservers/nanovis/nanovis.cpp

    r854 r860  
    7878Camera* NanoVis::cam = NULL;
    7979bool NanoVis::axis_on = true;
     80//bool NanoVis::axis_on = false;
    8081int NanoVis::win_width = NPIX;                  //size of the render window
    8182int NanoVis::win_height = NPIX;                 //size of the render window
     
    9394NvLIC* NanoVis::licRenderer = 0;
    9495
     96bool NanoVis::lic_on = false;
     97bool NanoVis::particle_on = false;
     98bool NanoVis::vector_on = false;
     99
    95100// pointers to volumes, currently handle up to 10 volumes
    96101/*FIXME: Is the above comment true? Is there a 10 volume limit */
     
    176181float NanoVis::lic_slice_y = 0.0f;
    177182float NanoVis::lic_slice_z = 0.5f;
     183int NanoVis::lic_axis = 2;
    178184
    179185/*
  • trunk/vizservers/nanovis/nanovis.h

    r851 r860  
    127127    static float lic_slice_y;
    128128    static float lic_slice_z;
     129    static int lic_axis; /* 0:x, 1:y, 2:z */
    129130
    130131    static bool axis_on;
     
    132133    static int win_width;                       //size of the render window
    133134    static int win_height;                      //size of the render window
     135 
     136
     137    static bool lic_on;
     138    static bool particle_on;
     139    static bool vector_on;
    134140
    135141    static TransferFunction* get_transfunc(const char *name);
Note: See TracChangeset for help on using the changeset viewer.