Changeset 865


Ignore:
Timestamp:
Feb 5, 2008, 1:44:27 PM (17 years ago)
Author:
gah
Message:

general cleanup

File:
1 edited

Legend:

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

    r862 r865  
    5656// FOR testing new functions
    5757//#define  _LOCAL_ZINC_TEST_
     58#ifdef _LOCAL_ZINC_TEXT_
    5859#include "Test.h"
    59 
     60#endif
    6061// EXTERN DECLARATIONS
    6162// in Nv.cpp
     
    143144static int GetAxis(Tcl_Interp *interp, const char *string, int *valPtr);
    144145static int GetColor(Tcl_Interp *interp, const char *string, float *rgbPtr);
    145 static int FillBufferFromStdin(Tcl_Interp *interp, Rappture::Buffer &buf,
     146static int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf,
    146147        int nBytes);
    147148static HeightMap *CreateHeightMap(ClientData clientData, Tcl_Interp *interp,
     
    158159    }
    159160    *valuePtr = (float)value;
     161    return TCL_OK;
     162}
     163
     164static int
     165GetCullMode(Tcl_Interp *interp, const char *string,
     166            graphics::RenderContext::CullMode *modePtr)
     167{
     168    if (strcmp(string, "none") == 0) {
     169        *modePtr = graphics::RenderContext::NO_CULL;
     170    } else if (strcmp(string, "front") == 0) {
     171        *modePtr = graphics::RenderContext::FRONT;
     172    } else if (strcmp(string, "back") == 0) {
     173        *modePtr = graphics::RenderContext::BACK;
     174    } else {
     175        Tcl_AppendResult(interp, "invalid cull mode \"", string,
     176                "\": should be front, back, or none\"", (char *)NULL);
     177        return TCL_ERROR;
     178    }
     179    return TCL_OK;
     180}
     181
     182static int
     183GetShadingModel(Tcl_Interp *interp, const char *string,
     184                graphics::RenderContext::ShadingModel *modelPtr)
     185{
     186    if (strcmp(string,"flat") == 0) {
     187        *modelPtr = graphics::RenderContext::FLAT;
     188    } else if (strcmp(string,"smooth") == 0) {
     189        *modelPtr = graphics::RenderContext::SMOOTH;
     190    } else {
     191        Tcl_AppendResult(interp, "bad shading model \"", string,
     192                         "\": should be flat or smooth", (char *)NULL);
     193        return TCL_ERROR;
     194    }
     195    return TCL_OK;
     196}
     197
     198static int
     199GetPolygonMode(Tcl_Interp *interp, const char *string,
     200               graphics::RenderContext::PolygonMode *modePtr)
     201{
     202    if (strcmp(string,"wireframe") == 0) {
     203        *modePtr = graphics::RenderContext::LINE;
     204    } else if (strcmp(string,"fill") == 0) {
     205        *modePtr = graphics::RenderContext::FILL;
     206    } else {
     207        Tcl_AppendResult(interp, "invalid polygon mode \"", string,
     208        "\": should be wireframe or fill\"", (char *)NULL);
     209        return TCL_ERROR;
     210    }
    160211    return TCL_OK;
    161212}
     
    704755                return TCL_ERROR;
    705756            }
    706 
    707757            vector<unsigned int>::iterator iter = ivol.begin();
    708             while (iter != ivol.end())
    709             {
    710                 if(NanoVis::volume[*iter] != 0)
    711                 {
     758            while (iter != ivol.end()) {
     759                if(NanoVis::volume[*iter] != 0) {
    712760                    if (state) {
    713761                        NanoVis::volume[*iter]->enable_data();
     
    725773                    */
    726774                }
    727 
    728775                ++iter;
    729776            }
     
    738785            }
    739786
    740             Rappture::Outcome err;
    741             Rappture::Buffer buf;
    742 
    743             // DEBUG
    744             char buffer[8096];
    745             while (nbytes > 0) {
    746                 unsigned int chunk;
    747                 int status;
    748 
    749                 chunk = (sizeof(buffer) < (unsigned int) nbytes) ? sizeof(buffer) : nbytes;
    750                 status = fread(buffer, 1, chunk, stdin);
    751                 //printf("Begin Reading [%d Read : %d Left]\n", status, nbytes - status);
    752                 fflush(stdout);
    753                 if (status > 0) {
    754                     buf.append(buffer,status);
    755                     nbytes -= status;
    756                 } else {
    757                     printf("data unpacking failed\n");
    758                     Tcl_AppendResult(interp, "data unpacking failed: unexpected EOF",
    759                         (char*)NULL);
    760                     return TCL_ERROR;
    761                 }
    762             }
    763             err = Rappture::encoding::decode(buf,RPENC_Z|RPENC_B64|RPENC_HDR);
    764             if (err) {
    765                 printf("ERROR -- DECODING\n");
    766                 fflush(stdout);
    767                 Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
    768                 return TCL_ERROR;
    769             }
    770 
     787            Rappture::Buffer buf;
     788            if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
     789                return TCL_ERROR;
     790            }
    771791            int n = NanoVis::n_volumes;
    772792            char header[6];
     
    841861#endif
    842862            } else {
     863                Rappture::Outcome err;
     864
    843865                printf("OpenDX loading...\n");
    844866                fflush(stdout);
     
    11001122}
    11011123
    1102 static int getDataStream(int nbytes, Rappture::Buffer* buf)
    1103 {
    1104     Rappture::Outcome err;
    1105 
    1106     char buffer[8096];
    1107     while (nbytes > 0) {
    1108         unsigned int chunk;
    1109                 int status;
    1110 
    1111                 chunk = (sizeof(buffer) < (unsigned int) nbytes) ? sizeof(buffer) : nbytes;
    1112         status = fread(buffer, 1, chunk, stdin);
    1113                 if (status > 0) {
    1114            buf->append(buffer,status);
    1115            nbytes -= status;
    1116         } else {
    1117                         printf("data unpacking failed\n");
    1118             Tcl_AppendResult(interp, "data unpacking failed: unexpected EOF",
    1119                 (char*)NULL);
    1120             return TCL_ERROR;
    1121         }
    1122         }
    1123 
    1124     err = Rappture::encoding::decode(*buf,RPENC_Z|RPENC_B64|RPENC_HDR);
    1125     if (err) {
    1126         printf("ERROR -- DECODING\n");
    1127         fflush(stdout);
    1128         Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
    1129         return TCL_ERROR;
    1130     }
    1131     return TCL_OK;
    1132 }
    1133 
    11341124static int
    11351125FlowCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[])
     
    11381128
    11391129    char c = argv[1][0];
    1140     if ((c == 'v') && (strcmp(argv[1], "vectorid") == 0))
    1141     {
    1142         int n = 0;
    1143         if (Tcl_GetInt(interp, argv[2], &n) != TCL_OK) {
     1130    if ((c == 'v') && (strcmp(argv[1], "vectorid") == 0)) {
     1131        if (argc != 3) {
     1132            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1133                " vectorid volume", (char *)NULL);
     1134            return TCL_ERROR;
     1135        }
     1136        Volume *volPtr;
     1137
     1138        if (GetVolume(interp, argv[2], &volPtr) != TCL_OK) {
     1139            return TCL_ERROR;
     1140        }
     1141        if (NanoVis::particleRenderer != NULL) {
     1142            NanoVis::particleRenderer->setVectorField(volPtr->id, 1.0f,
     1143                volPtr->height / (float)volPtr->width,
     1144                volPtr->depth  / (float)volPtr->width,
     1145                volPtr->range_max());
     1146            NanoVis::initParticle();
     1147        }
     1148        if (NanoVis::licRenderer != NULL) {
     1149            NanoVis::licRenderer->setVectorField(volPtr->id,
     1150                1.0f / volPtr->aspect_ratio_width,
     1151                1.0f / volPtr->aspect_ratio_height,
     1152                1.0f / volPtr->aspect_ratio_depth,
     1153                volPtr->range_max());
     1154            NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z);
     1155        }
     1156    } else if (c == 'l' && strcmp(argv[1], "lic") == 0) {
     1157        if (argc != 3) {
     1158            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1159                " lic on|off\"", (char*)NULL);
    11441160            return TCL_ERROR;
    11451161        }
    1146 
    1147         if (NanoVis::particleRenderer)
    1148         {
    1149 
    1150             NanoVis::particleRenderer->setVectorField(
    1151                 NanoVis::volume[n]->id,
    1152                 1.0f,
    1153                 NanoVis::volume[n]->height / (float) NanoVis::volume[n]->width,
    1154                 NanoVis::volume[n]->depth / (float)  NanoVis::volume[n]->width,
    1155                 NanoVis::volume[n]->range_max());
    1156        
    1157             NanoVis::initParticle();
    1158 
    1159         }
    1160 
    1161         if (NanoVis::licRenderer)
    1162         {
    1163             NanoVis::licRenderer->setVectorField(
    1164                 NanoVis::volume[n]->id,
    1165                 1.0f/NanoVis::volume[n]->aspect_ratio_width,
    1166                 1.0f/NanoVis::volume[n]->aspect_ratio_height,
    1167                 1.0f/NanoVis::volume[n]->aspect_ratio_depth,
    1168                 NanoVis::volume[n]->range_max());
    1169             NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z);
    1170         }
    1171     }
    1172     else if (c == 'l' && strcmp(argv[1],"lic") == 0)
    1173     {
     1162        int ibool;
     1163        if (Tcl_GetBoolean(interp, argv[2], &ibool) != TCL_OK) {
     1164            return TCL_ERROR;
     1165        }
     1166        NanoVis::lic_on = (bool)ibool;
     1167    } else if ((c == 'p') && (strcmp(argv[1], "particle") == 0)) {
    11741168        if (argc < 3) {
    11751169            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1176                 argv[1], " on|off \"", (char*)NULL);
     1170                " particle visible|slice|slicepos arg \"", (char*)NULL);
    11771171            return TCL_ERROR;
    11781172        }
    1179 
    1180         char ch = argv[2][0];
    1181         if (ch == 'o' && strcmp(argv[2],"on") == 0)
    1182         {
    1183                 NanoVis::lic_on = true;
    1184         }
    1185         else if (ch == 'o' && strcmp(argv[2],"off") == 0)
    1186         {
    1187                 NanoVis::lic_on = false;
    1188         }
    1189         else
    1190         {
    1191                 return TCL_ERROR;
    1192         }
    1193     }
    1194     else if (c == 'p' && strcmp(argv[1],"particle") == 0)
    1195         {
    1196         if (argc < 4) {
     1173        c = argv[2][0];
     1174        if ((c == 'v') && (strcmp(argv[2], "visible") == 0)) {
     1175            if (argc != 4) {
     1176                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1177                        " particle visible on|off\"", (char*)NULL);
     1178                return TCL_ERROR;
     1179            }
     1180            int state;
     1181            if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK) {
     1182                return TCL_ERROR;
     1183            }
     1184            NanoVis::particle_on = state;
     1185        } else if ((c == 's') && (strcmp(argv[2], "slice") == 0)) {
     1186            if (argc != 4) {
     1187                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1188                        " particle slice volume\"", (char*)NULL);
     1189                return TCL_ERROR;
     1190            }
     1191            int axis;
     1192            if (GetAxis(interp, argv[3], &axis) != TCL_OK) {
     1193                return TCL_ERROR;
     1194            }
     1195            NanoVis::lic_axis = axis;
     1196        } else if ((c == 's') && (strcmp(argv[2], "slicepos") == 0)) {
     1197            if (argc != 4) {
     1198                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1199                        " particle slicepos value\"", (char*)NULL);
     1200                return TCL_ERROR;
     1201            }
     1202            float pos;
     1203            if (GetFloat(interp, argv[2], &pos) != TCL_OK) {
     1204                return TCL_ERROR;
     1205            }
     1206            if (pos < 0.0f) {
     1207                pos = 0.0f;
     1208            } else if (pos > 1.0f) {
     1209                pos = 1.0f;
     1210            }
     1211            switch (NanoVis::lic_axis) {
     1212            case 0 :
     1213                NanoVis::lic_slice_x = pos;
     1214                break;
     1215            case 1 :
     1216                NanoVis::lic_slice_y = pos;
     1217                break;
     1218            case 2 :
     1219                NanoVis::lic_slice_z = pos;
     1220                break;
     1221            }
     1222        } else {
     1223            Tcl_AppendResult(interp, "unknown operation \"", argv[2],
     1224                "\": should be \"", argv[0], " visible, slice, or slicepos\"",
     1225                (char *)NULL);
     1226            return TCL_ERROR;
     1227        }
     1228    } else if ((c == 'r') && (strcmp(argv[1],"reset") == 0)) {
     1229        NanoVis::initParticle();
     1230    } else if ((c == 'c') && (strcmp(argv[1],"capture") == 0)) {
     1231        if (argc != 3) {
    11971232            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1198                 argv[1], " more parameters \"", (char*)NULL);
     1233                " capture numframes\"", (char*)NULL);
    11991234            return TCL_ERROR;
    12001235        }
    1201 
    1202                 char ch = argv[2][0];
    1203                 if (ch == 'v' && strcmp(argv[2],"visible") == 0)
    1204                 {
    1205                         int state;
    1206                 if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK)
    1207                         {
    1208                                 return TCL_ERROR;
    1209                         }
    1210                         NanoVis::particle_on = state;
    1211                 }
    1212                 else if (ch == 's' && strcmp(argv[2],"slice") == 0)
    1213                 {
    1214                         if (argv[3][0] == 'x')
    1215                         {
    1216                                 NanoVis::lic_axis = 0;
    1217                         }
    1218                         else if (argv[3][0] == 'y')
    1219                         {
    1220                                 NanoVis::lic_axis = 1;
    1221                         }
    1222                         else if (argv[3][0] == 'z')
    1223                         {
    1224                                 NanoVis::lic_axis = 2;
    1225                         }
    1226                         else
    1227                         {
    1228                                 // TBD.. put error message
    1229                                 return TCL_ERROR;
    1230                         }
    1231 
    1232                 }
    1233                 else if (ch == 's' && strcmp(argv[2],"slicepos") == 0)
    1234                 {
    1235                         float pos;
    1236                         if (GetFloat(interp, argv[2], &pos) != TCL_OK)
    1237                         {
    1238                                 return TCL_ERROR;
    1239                         }
    1240 
    1241                         if (pos < 0.0f) pos = 0.0f;
    1242                         if (pos > 1.0f) pos = 1.0f;
    1243 
    1244                         switch (NanoVis::lic_axis)
    1245                         {
    1246                         case 0 :
    1247                                 NanoVis::lic_slice_x = pos;
    1248                                 break;
    1249                         case 1 :
    1250                                 NanoVis::lic_slice_y = pos;
    1251                                 break;
    1252                         case 2 :
    1253                                 NanoVis::lic_slice_z = pos;
    1254                                 break;
    1255                         }
    1256                 }
    1257                 else
    1258                 {
    1259                         return TCL_ERROR;
    1260                 }
    1261         }
    1262     else if (c == 'r' && strcmp(argv[1],"reset") == 0)
    1263     {
    1264             NanoVis::initParticle();
    1265     }
    1266     else if (c == 'c' && strcmp(argv[1],"capture") == 0)
    1267     {
    1268                 int total_frame_count = 0;
    1269         if (Tcl_GetInt(interp, argv[2], &total_frame_count) != TCL_OK)
    1270                 {
    1271                 return TCL_ERROR;
    1272                 }
    1273 
    1274         if (NanoVis::licRenderer) NanoVis::licRenderer->activate();
    1275         if (NanoVis::particleRenderer) NanoVis::particleRenderer->activate();
    1276 
     1236        int total_frame_count;
     1237
     1238        if (Tcl_GetInt(interp, argv[2], &total_frame_count) != TCL_OK) {
     1239            return TCL_ERROR;
     1240        }
     1241        if (NanoVis::licRenderer) {
     1242            NanoVis::licRenderer->activate();
     1243        }
     1244        if (NanoVis::particleRenderer) {
     1245            NanoVis::particleRenderer->activate();
     1246        }
    12771247        // Karl
    1278         {
    1279 
    1280         for (int frame_count = 0; frame_count<total_frame_count; frame_count++) {
    1281 
    1282                 // Generate the latest frame and send it back to the client
    1283                 if (NanoVis::licRenderer && NanoVis::licRenderer->isActivated())
    1284                       NanoVis::licRenderer->convolve();               
    1285 
    1286                 if (NanoVis::particleRenderer && NanoVis::particleRenderer->isActivated())
    1287                         NanoVis::particleRenderer->advect();
    1288 
    1289                 NanoVis::offscreen_buffer_capture();  //enable offscreen render
    1290                 NanoVis::display();
    1291 
    1292 //              printf("Read Screen for Writing to file...\n");
    1293 
    1294                 NanoVis::read_screen();
    1295                 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    1296 
    1297                 NanoVis::bmp_write_to_file(frame_count);
    1298 //              printf("Writing to file...\n");
    1299         }
    1300 
    1301 
    1302         }// put your code...
    1303 
    1304         if (NanoVis::licRenderer) NanoVis::licRenderer->deactivate();
    1305         if (NanoVis::particleRenderer) NanoVis::particleRenderer->deactivate();
     1248        for (int frame_count = 0; frame_count < total_frame_count;
     1249             frame_count++) {
     1250           
     1251            // Generate the latest frame and send it back to the client
     1252            if (NanoVis::licRenderer &&
     1253                NanoVis::licRenderer->isActivated()) {
     1254                NanoVis::licRenderer->convolve();               
     1255            }
     1256            if (NanoVis::particleRenderer &&
     1257                NanoVis::particleRenderer->isActivated()) {
     1258                NanoVis::particleRenderer->advect();
     1259            }
     1260            NanoVis::offscreen_buffer_capture();  //enable offscreen render
     1261            NanoVis::display();
     1262           
     1263            //          printf("Read Screen for Writing to file...\n");
     1264           
     1265            NanoVis::read_screen();
     1266            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     1267           
     1268            NanoVis::bmp_write_to_file(frame_count);
     1269            //          printf("Writing to file...\n");
     1270        }
     1271        // put your code...
     1272        if (NanoVis::licRenderer) {
     1273            NanoVis::licRenderer->deactivate();
     1274        }
     1275        if (NanoVis::particleRenderer) {
     1276            NanoVis::particleRenderer->deactivate();
     1277        }
    13061278        NanoVis::initParticle();
    1307     }
    1308     else if (c == 'd' && strcmp(argv[1],"data") == 0)
    1309         {
    1310                 char ch = argv[2][0];
    1311         if (ch == 'f' && strcmp(argv[2],"follows") == 0) {
     1279    } else if (c == 'd' && strcmp(argv[1],"data") == 0) {
     1280        if (argc < 3) {
     1281            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1282                " data follows ?args?", (char *)NULL);
     1283            return TCL_ERROR;
     1284        }
     1285        c = argv[2][0];
     1286        if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) {
     1287            if (argc != 4) {
     1288                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1289                                 " data follows length", (char *)NULL);
     1290                return TCL_ERROR;
     1291            }
    13121292            int nbytes;
    1313             if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK)
    1314                         {
    1315                 return TCL_ERROR;
    1316             }
    1317 
    1318                          Rappture::Buffer buf;
    1319                         if (getDataStream(nbytes, &buf) != TCL_OK)
    1320                         {
    1321                                 /// TBD..
    1322                 //Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
    1323                                 return TCL_ERROR;
    1324                         }
    1325 
     1293            if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) {
     1294                return TCL_ERROR;
     1295            }
     1296            Rappture::Buffer buf;
     1297            if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
     1298                return TCL_ERROR;
     1299            }
    13261300            int n = NanoVis::n_volumes;
    13271301            std::stringstream fdata;
    13281302            fdata.write(buf.bytes(),buf.size());
    13291303            load_vector_stream(n, fdata);
    1330            
     1304            Volume *volPtr = NanoVis::volume[n];
     1305
    13311306            //
    13321307            // BE CAREFUL:  Set the number of slices to something
     
    13371312            //   appear at all.
    13381313            //
    1339             if (NanoVis::volume[n] != NULL)
    1340                         {
    1341                 NanoVis::volume[n]->set_n_slice(256-n);
    1342                 NanoVis::volume[n]->disable_cutplane(0);
    1343                 NanoVis::volume[n]->disable_cutplane(1);
    1344                 NanoVis::volume[n]->disable_cutplane(2);
    1345 
    1346                 NanoVis::vol_renderer->add_volume(NanoVis::volume[n],NanoVis::get_transfunc("default"));
    1347             }
    1348         }
    1349         }
    1350     else
    1351     {
     1314            if (volPtr != NULL) {
     1315                volPtr->set_n_slice(256-n);
     1316                volPtr->disable_cutplane(0);
     1317                volPtr->disable_cutplane(1);
     1318                volPtr->disable_cutplane(2);
     1319
     1320                NanoVis::vol_renderer->add_volume(volPtr,
     1321                        NanoVis::get_transfunc("default"));
     1322            }
     1323        }
     1324    } else {
    13521325        return TCL_ERROR;
    13531326    }
    1354    
    13551327    return TCL_OK;
    13561328}
     
    13751347
    13761348        HeightMap* heightMap = new HeightMap();
    1377     float minx = 0.0f;
    1378     float maxx = 1.0f;
    1379     float miny = 0.5f;
    1380     float maxy = 3.5f;
     1349        float minx = 0.0f;
     1350        float maxx = 1.0f;
     1351        float miny = 0.5f;
     1352        float maxy = 3.5f;
    13811353        heightMap->setHeight(minx, miny, maxx, maxy, 20, 200, data);
    13821354        heightMap->setColorMap(NanoVis::get_transfunc("default"));
     
    13861358
    13871359
    1388     Vector3 min(minx, (float) heightMap->range_min(), miny);
    1389     Vector3 max(maxx, (float) heightMap->range_max(), maxy);
    1390 
    1391     NanoVis::grid->setMinMax(min, max);
    1392     NanoVis::grid->setVisible(true);
    1393 
     1360        Vector3 min(minx, (float) heightMap->range_min(), miny);
     1361        Vector3 max(maxx, (float) heightMap->range_max(), maxy);
     1362       
     1363        NanoVis::grid->setMinMax(min, max);
     1364        NanoVis::grid->setVisible(true);
     1365       
    13941366        return TCL_OK;
    13951367    }
     
    14091381        return TCL_OK;
    14101382    } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) {
     1383        if (argc < 3) {
     1384            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1385                " data follows|visible ?args?", (char *)NULL);
     1386            return TCL_ERROR;
     1387        }
    14111388        //bytes
    14121389        char c;
    14131390        c = argv[2][0];
    14141391        if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) {
     1392            if (argc < 4) {
     1393                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1394                        " data visible bool ?indices?", (char *)NULL);
     1395                return TCL_ERROR;
     1396            }
    14151397            int ivisible;
    14161398            vector<unsigned int> indices;
     
    14311413            }
    14321414        } else if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) {
     1415            if (argc != 4) {
     1416                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1417                        " data follow length", (char *)NULL);
     1418                return TCL_ERROR;
     1419            }
    14331420            Rappture::Buffer buf;
    14341421            int nBytes;
     
    14371424                return TCL_ERROR;
    14381425            }
    1439             if (FillBufferFromStdin(interp, buf, nBytes) != TCL_OK) {
     1426            if (GetDataStream(interp, buf, nBytes) != TCL_OK) {
    14401427                return TCL_ERROR;
    14411428            }
     
    14521439        }
    14531440    } else if ((c == 'l') && (strcmp(argv[1], "linecontour") == 0)) {
    1454         //bytes
     1441        if (argc < 3) {
     1442            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1443                " linecontour visible|color ?args?", (char *)NULL);
     1444            return TCL_ERROR;
     1445        }
    14551446        vector<unsigned int> indices;
    14561447        char c;
    14571448        c = argv[2][0];
    14581449        if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) {
     1450            if (argc < 4) {
     1451                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1452                        " linecontour visible boolean ?indices?", (char *)NULL);
     1453                return TCL_ERROR;
     1454            }
    14591455            int ivisible;
    14601456            bool visible;
    1461 
    14621457            if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
    14631458                return TCL_ERROR;
     
    14741469            }
    14751470        } else if ((c == 'c') && (strcmp(argv[2],"color") == 0)) {
     1471            if (argc < 6) {
     1472                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1473                        " linecontour color r g b ?indices?", (char *)NULL);
     1474                return TCL_ERROR;
     1475            }
    14761476            float r, g, b;
    14771477            if ((GetFloat(interp, argv[3], &r) != TCL_OK) ||
     
    14961496        }
    14971497    } else if ((c == 't') && (strcmp(argv[1], "transfunc") == 0)) {
     1498        if (argc < 3) {
     1499            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1500                " transfunc name ?indices?", (char *)NULL);
     1501            return TCL_ERROR;
     1502        }
    14981503        TransferFunction *tf;
    14991504
    1500             tf = NanoVis::get_transfunc(argv[2]);
     1505        tf = NanoVis::get_transfunc(argv[2]);
    15011506        if (tf == NULL) {
    15021507            Tcl_AppendResult(interp, "transfer function \"", argv[2],
     
    15051510        }
    15061511        vector<unsigned int> indices;
    1507         if (GetIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK)     {
     1512        if (GetIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK) {
    15081513                return TCL_ERROR;
    1509             }
    1510             for (unsigned int i = 0; i < indices.size(); ++i) {
    1511                 if ((indices[i] < NanoVis::heightMap.size()) &&
    1512                     (NanoVis::heightMap[indices[i]] != NULL)) {
    1513                         NanoVis::heightMap[indices[i]]->setColorMap(tf);
    1514                 }
    1515         }
    1516     }
    1517     else if ((c == 'l') && (strcmp(argv[1], "legend") == 0)) {
    1518             if (argc != 5) {
    1519                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1514        }
     1515        for (unsigned int i = 0; i < indices.size(); ++i) {
     1516            if ((indices[i] < NanoVis::heightMap.size()) &&
     1517                (NanoVis::heightMap[indices[i]] != NULL)) {
     1518                NanoVis::heightMap[indices[i]]->setColorMap(tf);
     1519            }
     1520        }
     1521    } else if ((c == 'l') && (strcmp(argv[1], "legend") == 0)) {
     1522        if (argc != 5) {
     1523            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    15201524                             " legend index width height\"", (char*)NULL);
    1521                 return TCL_ERROR;
    1522             }
    1523             HeightMap *hMap;
    1524             if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) {
    1525                 return TCL_ERROR;
    1526             }
    1527             TransferFunction *tf;
    1528             tf = hMap->getColorMap();
    1529             if (tf == NULL) {
    1530                 Tcl_AppendResult(interp,
    1531                         "no transfer function defined for heightmap \"",
    1532                         argv[1], "\"", (char*)NULL);
    1533                 return TCL_ERROR;
    1534             }
    1535             int width, height;
    1536             if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) ||
    1537                 (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) {
    1538                 return TCL_ERROR;
    1539             }
    1540             NanoVis::render_legend(tf, hMap->range_min(), hMap->range_max(),
    1541                                width, height, argv[1]);
    1542     }
    1543     else if ((c == 'p') && (strcmp(argv[1], "polygon") == 0))
    1544     {
    1545         if (!strcmp(argv[2],"wireframe"))
    1546         {
    1547             NanoVis::renderContext->setPolygonMode(graphics::RenderContext::LINE);
    1548                 return TCL_OK;
    1549         }
    1550         else if (!strcmp(argv[2],"fill"))
    1551         {
    1552             NanoVis::renderContext->setPolygonMode(graphics::RenderContext::FILL);
    1553                 return TCL_OK;
    1554         }
    1555             return TCL_ERROR;
    1556     }
    1557     else if ((c == 'c') && (strcmp(argv[1], "cull") == 0))
    1558     {
    1559         if (!strcmp(argv[2],"no"))
    1560         {
    1561             NanoVis::renderContext->setCullMode(graphics::RenderContext::NO_CULL);
    1562                 return TCL_OK;
    1563         }
    1564         else if (!strcmp(argv[2],"front"))
    1565         {
    1566             NanoVis::renderContext->setCullMode(graphics::RenderContext::FRONT);
    1567                 return TCL_OK;
    1568         }
    1569         else if (!strcmp(argv[2],"back"))
    1570         {
    1571             NanoVis::renderContext->setCullMode(graphics::RenderContext::BACK);
    1572                 return TCL_OK;
    1573         }
    1574             return TCL_ERROR;
    1575     }
    1576     else if ((c == 's') && (strcmp(argv[1], "shade") == 0))
    1577     {
    1578         if (!strcmp(argv[2],"flat"))
    1579         {
    1580             NanoVis::renderContext->setShadingModel(graphics::RenderContext::FLAT);
    1581                 return TCL_OK;
    1582         }
    1583         else if (!strcmp(argv[2],"smooth"))
    1584         {
    1585             NanoVis::renderContext->setShadingModel(graphics::RenderContext::SMOOTH);
    1586                 return TCL_OK;
    1587         }
    1588             return TCL_ERROR;
    1589     }
    1590     else {
    1591             Tcl_AppendResult(interp, "bad option \"", argv[1],
    1592         "\": should be data, linecontour, legend, or transfunc", (char*)NULL);
    1593             return TCL_ERROR;
     1525            return TCL_ERROR;
     1526        }
     1527        HeightMap *hMap;
     1528        if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) {
     1529            return TCL_ERROR;
     1530        }
     1531        TransferFunction *tf;
     1532        tf = hMap->getColorMap();
     1533        if (tf == NULL) {
     1534            Tcl_AppendResult(interp,
     1535                "no transfer function defined for heightmap \"", argv[1], "\"",
     1536                (char*)NULL);
     1537            return TCL_ERROR;
     1538        }
     1539        int width, height;
     1540        if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) ||
     1541            (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) {
     1542            return TCL_ERROR;
     1543        }
     1544        NanoVis::render_legend(tf, hMap->range_min(), hMap->range_max(),
     1545                width, height, argv[1]);
     1546    } else if ((c == 'p') && (strcmp(argv[1], "polygon") == 0)) {
     1547        if (argc != 3) {
     1548            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1549                " polygon mode", (char *)NULL);
     1550            return TCL_ERROR;
     1551        }
     1552        graphics::RenderContext::PolygonMode mode;
     1553        if (GetPolygonMode(interp, argv[2], &mode) != TCL_OK) {
     1554            return TCL_ERROR;
     1555        }
     1556        NanoVis::renderContext->setPolygonMode(mode);
     1557    } else if ((c == 'c') && (strcmp(argv[1], "cull") == 0)) {
     1558        if (argc != 3) {
     1559            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1560                " cull mode", (char *)NULL);
     1561            return TCL_ERROR;
     1562        }
     1563        graphics::RenderContext::CullMode mode;
     1564        if (GetCullMode(interp, argv[2], &mode) != TCL_OK) {
     1565            return TCL_ERROR;
     1566        }
     1567        NanoVis::renderContext->setCullMode(mode);
     1568    } else if ((c == 's') && (strcmp(argv[1], "shade") == 0)) {
     1569        if (argc != 3) {
     1570            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1571                " shade model", (char *)NULL);
     1572            return TCL_ERROR;
     1573        }
     1574        graphics::RenderContext::ShadingModel model;
     1575        if (GetShadingModel(interp, argv[2], &model) != TCL_OK) {
     1576            return TCL_ERROR;
     1577        }
     1578        NanoVis::renderContext->setShadingModel(model);
     1579    } else {
     1580        Tcl_AppendResult(interp, "bad option \"", argv[1],
     1581                "\": should be data, linecontour, legend, or transfunc", (char*)NULL);
     1582        return TCL_ERROR;
    15941583    }
    15951584    return TCL_OK;
     
    22102199 * -----------------------------------------------------------------------
    22112200 *
    2212  * FillBufferFromStdin --
     2201 * GetDataStream --
    22132202 *
    22142203 *      Read the requested number of bytes from standard input into the given
     
    22182207 */
    22192208static int
    2220 FillBufferFromStdin(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes)
     2209GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes)
    22212210{
    22222211    char buffer[8096];
     
    22262215        int nRead;
    22272216
    2228         chunk = (sizeof(buffer) < (unsigned int) nBytes) ? sizeof(buffer) : nBytes;
     2217        chunk = (sizeof(buffer) < (unsigned int) nBytes) ?
     2218            sizeof(buffer) : nBytes;
    22292219        nRead = fread(buffer, 1, chunk, stdin);
    2230         if (ferror(stdin) && feof(stdin)) {
    2231             Tcl_AppendResult(interp,
    2232                              "data unpacking failed: unexpected EOF",
    2233                              (char*)NULL);
    2234             return TCL_ERROR;
     2220        if (feof(stdin)) {
     2221            Tcl_AppendResult(interp, "premature EOF while reading data stream",
     2222                (char*)NULL);
     2223            return TCL_ERROR;
     2224        }
     2225        if (ferror(stdin)) {
     2226            Tcl_AppendResult(interp, "error while reading data stream: ",
     2227                Tcl_PosixError(interp), (char*)NULL);
     2228            return TCL_ERROR;
    22352229        }
    22362230        buf.append(buffer, nRead);
Note: See TracChangeset for help on using the changeset viewer.