- Timestamp:
- Feb 12, 2008, 11:41:22 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Command.cpp
r871 r877 22 22 */ 23 23 24 /* 25 * TODO: In no particular order... 26 * o Convert to Tcl_CmdObj interface. 27 * o Use Tcl command option parser to reduce size of procedures, remove 28 * lots of extra error checking code. 29 * o Convert GetVolumeIndices to GetVolumes. Goal is to remove 30 * all references of Nanovis::volume[] from this file. Don't 31 * want to know how volumes are stored. Same for heightmaps. 32 * o Rationalize volume id scheme. Right now it's the index in 33 * the vector. 1) Use a list instead of a vector. 2) carry 34 * an id field that's a number that gets incremented each new volume. 35 * o Create R2, matrix, etc. libraries. 36 */ 24 37 25 38 #include "Command.h" … … 76 89 extern PlaneRenderer* plane_render; 77 90 extern Texture2D* plane[10]; 78 79 91 80 92 extern Rappture::Outcome load_volume_stream(int index, std::iostream& fin); … … 134 146 static int GetVolumeIndices(Tcl_Interp *interp, int argc, const char *argv[], 135 147 vector<unsigned int>* vectorPtr); 148 static int GetVolumes(Tcl_Interp *interp, int argc, const char *argv[], 149 vector<Volume *>* vectorPtr); 136 150 static int GetVolume(Tcl_Interp *interp, const char *string, 137 151 Volume **volPtrPtr); … … 149 163 int argc, const char *argv[]); 150 164 151 152 165 static int 153 166 GetFloat(Tcl_Interp *interp, const char *string, float *valuePtr) … … 275 288 NanoVis::zoom(zoom); 276 289 } else { 277 Tcl_AppendResult(interp, "bad option \"", argv[1],290 Tcl_AppendResult(interp, "bad camera option \"", argv[1], 278 291 "\": should be aim, angle, or zoom", (char*)NULL); 279 292 return TCL_ERROR; … … 299 312 { 300 313 #ifdef XINETD 301 int old_win_width = NanoVis::win_width;302 int old_win_height = NanoVis::win_height;303 304 314 NanoVis::resize_offscreen_buffer(1024, 1024); 305 315 NanoVis::cam->set_screen_size(30, 90, 1024 - 60, 1024 - 120); … … 327 337 } 328 338 */ 329 330 331 /*332 NanoVis::read_screen();333 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);334 335 NanoVis::bmp_write("nv>screenshot -bytes");336 337 //NanoVis::bmp_write_to_file();338 339 NanoVis::resize_offscreen_buffer(old_win_width, old_win_height);340 */341 342 339 #endif 343 340 … … 388 385 } 389 386 390 vector< unsigned int> ivol;391 if (GetVolume Indices(interp, argc-4, argv+4, &ivol) != TCL_OK) {387 vector<Volume *> ivol; 388 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 392 389 return TCL_ERROR; 393 390 } 394 391 if (state) { 395 vector< unsigned int>::iterator iter;392 vector<Volume *>::iterator iter; 396 393 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 397 NanoVis::volume[*iter]->enable_cutplane(axis);394 (*iter)->enable_cutplane(axis); 398 395 } 399 396 } else { 400 vector< unsigned int>::iterator iter;397 vector<Volume *>::iterator iter; 401 398 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 402 NanoVis::volume[*iter]->disable_cutplane(axis);399 (*iter)->disable_cutplane(axis); 403 400 } 404 401 } … … 414 411 return TCL_ERROR; 415 412 } 413 416 414 // keep this just inside the volume so it doesn't disappear 417 415 if (relval < 0.01f) { … … 426 424 } 427 425 428 vector< unsigned int> ivol;429 if (GetVolume Indices(interp, argc - 4, argv + 4, &ivol) != TCL_OK) {426 vector<Volume *> ivol; 427 if (GetVolumes(interp, argc - 4, argv + 4, &ivol) != TCL_OK) { 430 428 return TCL_ERROR; 431 429 } 432 vector< unsigned int>::iterator iter;430 vector<Volume *>::iterator iter; 433 431 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 434 NanoVis::volume[*iter]->move_cutplane(axis, relval);432 (*iter)->move_cutplane(axis, relval); 435 433 } 436 434 } else { … … 462 460 } 463 461 464 Volume *vol ;465 if (GetVolume(interp, argv[1], &vol ) != TCL_OK) {462 Volume *volPtr; 463 if (GetVolume(interp, argv[1], &volPtr) != TCL_OK) { 466 464 return TCL_ERROR; 467 465 } 468 466 TransferFunction *tf; 469 tf = NanoVis::vol_renderer->get_volume_shading(vol );467 tf = NanoVis::vol_renderer->get_volume_shading(volPtr); 470 468 if (tf == NULL) { 471 469 Tcl_AppendResult(interp, "no transfer function defined for volume \"", … … 479 477 return TCL_ERROR; 480 478 } 481 NanoVis::render_legend(tf, vol ->range_min(), vol->range_max(), width, height,482 argv[1]);479 NanoVis::render_legend(tf, volPtr->range_min(), volPtr->range_max(), 480 width, height, argv[1]); 483 481 return TCL_OK; 484 482 } … … 704 702 if (argc < 3) { 705 703 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 706 argv[1], "option ?arg arg...?\"", (char*)NULL);704 " axis option ?arg arg...?\"", (char*)NULL); 707 705 return TCL_ERROR; 708 706 } … … 711 709 if (argc < 4) { 712 710 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 713 argv[1], " label x|y|z string ?volume ...?\"", (char*)NULL); 714 return TCL_ERROR; 715 } 716 711 " axis label x|y|z string ?volume ...?\"", (char*)NULL); 712 return TCL_ERROR; 713 } 717 714 int axis; 718 715 if (GetAxis(interp, (char*)argv[3], &axis) != TCL_OK) { 719 716 return TCL_ERROR; 720 717 } 721 722 vector<unsigned int> ivol; 723 if (GetVolumeIndices(interp, argc - 5, argv + 5, &ivol) != TCL_OK) { 724 return TCL_ERROR; 725 } 726 727 vector<unsigned int>::iterator iter; 718 vector<Volume *> ivol; 719 if (GetVolumes(interp, argc - 5, argv + 5, &ivol) != TCL_OK) { 720 return TCL_ERROR; 721 } 722 vector<Volume *>::iterator iter; 728 723 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 729 NanoVis::volume[*iter]->set_label(axis, argv[4]);724 (*iter)->set_label(axis, argv[4]); 730 725 } 731 726 } else { 732 727 Tcl_AppendResult(interp, "bad option \"", argv[2], 733 "\": should be label", (char*)NULL); 734 return TCL_ERROR; 735 } 736 } 737 else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) { 728 "\": should be label", (char*)NULL); 729 return TCL_ERROR; 730 } 731 } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) { 738 732 if (argc < 3) { 739 733 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 740 argv[1], "option ?arg arg...?\"", (char*)NULL);734 " data option ?arg arg...?\"", (char*)NULL); 741 735 return TCL_ERROR; 742 736 } … … 745 739 if (argc < 4) { 746 740 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 747 argv[1], "state on|off ?volume ...?\"", (char*)NULL);741 " data state on|off ?volume ...?\"", (char*)NULL); 748 742 return TCL_ERROR; 749 743 } … … 752 746 return TCL_ERROR; 753 747 } 754 vector<unsigned int> ivol; 755 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 756 return TCL_ERROR; 757 } 758 vector<unsigned int>::iterator iter = ivol.begin(); 759 while (iter != ivol.end()) { 760 if(NanoVis::volume[*iter] != 0) { 761 if (state) { 762 NanoVis::volume[*iter]->enable_data(); 763 } else { 764 NanoVis::volume[*iter]->disable_data(); 765 } 766 767 // TBD.. 768 // POINTSET 769 /* 770 if (NanoVis::volume[*iter]->pointsetIndex != -1) 771 { 772 g_pointSet[volume[*iter]->pointsetIndex]->setVisible(state); 773 } 774 */ 775 } 776 ++iter; 777 } 778 } else if (c == 'f' && strcmp(argv[2],"follows") == 0) { 748 vector<Volume *> ivol; 749 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 750 return TCL_ERROR; 751 } 752 if (state) { 753 vector<Volume *>::iterator iter; 754 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 755 (*iter)->enable_data(); 756 } 757 } else { 758 vector<Volume *>::iterator iter; 759 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 760 (*iter)->disable_data(); 761 } 762 } 763 } else if (c == 'f' && strcmp(argv[2], "follows") == 0) { 764 if (argc < 4) { 765 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 766 " data follows size", (char*)NULL); 767 return TCL_ERROR; 768 } 779 769 printf("Data Loading\n"); 780 //fflush(stdout); 781 //return TCL_OK; 770 fflush(stdout); 782 771 783 772 int nbytes; … … 808 797 fread(b, buf.size(), 1, fp); 809 798 fclose(fp); 810 #endif 799 #endif /*_LOCAL_ZINC_TEST_*/ 811 800 printf("Checking header[%s]\n", header); 812 801 fflush(stdout); … … 824 813 #else 825 814 vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes()); 826 #endif 815 #endif /*_LOCAL_ZINC_TEST_*/ 827 816 828 817 printf("finish loading\n"); … … 860 849 } 861 850 */ 862 #endif 851 #endif /*__TEST_CODE__*/ 863 852 } else { 864 853 Rappture::Outcome err; … … 875 864 } 876 865 } 877 878 866 879 867 // … … 893 881 NanoVis::vol_renderer->add_volume(NanoVis::volume[n],NanoVis::get_transfunc("default")); 894 882 } 883 884 { 885 Volume *volPtr; 886 char info[1024]; 887 float vmin, vmax, min, max; 888 889 volPtr = NanoVis::volume[n]; 890 vmin = min = volPtr->range_min(); 891 vmax = max = volPtr->range_max(); 892 for (int i = 0; i < NanoVis::n_volumes; i++) { 893 if (NanoVis::volume[i] == NULL) { 894 continue; 895 } 896 volPtr = NanoVis::volume[i]; 897 if (vmin > volPtr->range_min()) { 898 vmin = volPtr->range_min(); 899 } 900 if (vmax < volPtr->range_max()) { 901 vmax = volPtr->range_max(); 902 } 903 } 904 sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n", 905 n, min, max, vmin, vmax); 906 write(0, info, strlen(info)); 907 } 895 908 } else { 896 Tcl_AppendResult(interp, "bad option \"", argv[2],897 909 Tcl_AppendResult(interp, "bad data option \"", argv[2], 910 "\": should be follows or state", (char*)NULL); 898 911 return TCL_ERROR; 899 912 } … … 901 914 if (argc < 3) { 902 915 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 903 argv[1], "option ?arg arg...?\"", (char*)NULL);916 " outline option ?arg arg...?\"", (char*)NULL); 904 917 return TCL_ERROR; 905 918 } … … 908 921 if (argc < 3) { 909 922 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 910 argv[1], "state on|off ?volume ...? \"", (char*)NULL);923 " outline state on|off ?volume ...? \"", (char*)NULL); 911 924 return TCL_ERROR; 912 925 } … … 916 929 return TCL_ERROR; 917 930 } 918 vector< unsigned int> ivol;919 if (GetVolume Indices(interp, argc-4, argv+4, &ivol) != TCL_OK) {931 vector<Volume *> ivol; 932 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 920 933 return TCL_ERROR; 921 934 } 922 935 if (state) { 923 vector< unsigned int>::iterator iter;936 vector<Volume *>::iterator iter; 924 937 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 925 NanoVis::volume[*iter]->enable_outline();938 (*iter)->enable_outline(); 926 939 } 927 940 } else { 928 vector< unsigned int>::iterator iter;941 vector<Volume *>::iterator iter; 929 942 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 930 NanoVis::volume[*iter]->disable_outline();943 (*iter)->disable_outline(); 931 944 } 932 945 } … … 953 966 if (argc < 3) { 954 967 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 955 argv[1], "color {R G B} ?volume ...? \"", (char*)NULL);968 " outline color {R G B} ?volume ...? \"", (char*)NULL); 956 969 return TCL_ERROR; 957 970 } … … 960 973 return TCL_ERROR; 961 974 } 962 vector< unsigned int> ivol;963 if (GetVolume Indices(interp, argc - 4, argv + 4, &ivol) != TCL_OK) {964 return TCL_ERROR; 965 } 966 vector< unsigned int>::iterator iter;975 vector<Volume *> ivol; 976 if (GetVolumes(interp, argc - 4, argv + 4, &ivol) != TCL_OK) { 977 return TCL_ERROR; 978 } 979 vector<Volume *>::iterator iter; 967 980 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 968 NanoVis::volume[*iter]->set_outline_color(rgb);981 (*iter)->set_outline_color(rgb); 969 982 } 970 983 } 971 984 else { 972 Tcl_AppendResult(interp, "bad o ption \"", argv[2],973 "\": should be coloror state", (char*)NULL);974 return TCL_ERROR; 975 985 Tcl_AppendResult(interp, "bad outline option \"", argv[2], 986 "\": should be color, visible, or state", (char*)NULL); 987 return TCL_ERROR; 988 } 976 989 } else if ((c == 's') && (strcmp(argv[1],"shading") == 0)) { 977 990 if (argc < 3) { 978 991 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 979 argv[1], "option ?arg arg...?\"", (char*)NULL);992 " shading option ?arg arg...?\"", (char*)NULL); 980 993 return TCL_ERROR; 981 994 } … … 984 997 if (argc < 4) { 985 998 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 986 argv[1], "transfunc name ?volume ...?\"", (char*)NULL);999 " shading transfunc name ?volume ...?\"", (char*)NULL); 987 1000 return TCL_ERROR; 988 1001 } … … 994 1007 return TCL_ERROR; 995 1008 } 996 vector<unsigned int> ivol; 997 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 998 return TCL_ERROR; 999 } 1000 1001 vector<unsigned int>::iterator iter = ivol.begin(); 1002 while (iter != ivol.end()) 1003 { 1004 NanoVis::vol_renderer->shade_volume(NanoVis::volume[*iter], tf); 1009 vector<Volume *> ivol; 1010 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1011 return TCL_ERROR; 1012 } 1013 vector<Volume *>::iterator iter; 1014 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1015 NanoVis::vol_renderer->shade_volume(*iter, tf); 1005 1016 // TBD.. 1006 1017 // POINTSET 1007 1018 /* 1008 if (NanoVis::volume[*iter] && NanoVis::volume[*iter]->pointsetIndex != -1) 1009 { 1010 g_pointSet[NanoVis::volume[*iter]->pointsetIndex]->updateColor(tf->getData(), 256); 1019 if ((*iter)->pointsetIndex != -1) { 1020 g_pointSet[(*iter)->pointsetIndex]->updateColor(tf->getData(), 256); 1011 1021 } 1012 1022 */ 1013 ++iter;1014 1023 } 1015 1024 } else if ((c == 'd') && (strcmp(argv[2], "diffuse") == 0)) { 1016 1025 if (argc < 4) { 1017 1026 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1018 argv[1], "diffuse value ?volume ...?\"", (char*)NULL);1027 " shading diffuse value ?volume ...?\"", (char*)NULL); 1019 1028 return TCL_ERROR; 1020 1029 } … … 1024 1033 return TCL_ERROR; 1025 1034 } 1026 vector< unsigned int> ivol;1027 if (GetVolume Indices(interp, argc-4, argv+4, &ivol) != TCL_OK) {1028 return TCL_ERROR; 1029 } 1030 vector< unsigned int>::iterator iter;1035 vector<Volume *> ivol; 1036 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1037 return TCL_ERROR; 1038 } 1039 vector<Volume *>::iterator iter; 1031 1040 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1032 NanoVis::volume[*iter]->set_diffuse(diffuse);1041 (*iter)->set_diffuse(diffuse); 1033 1042 } 1034 1043 } else if ((c == 'o') && (strcmp(argv[2], "opacity") == 0)) { 1035 1044 if (argc < 4) { 1036 1045 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1037 argv[1], "opacity value ?volume ...?\"", (char*)NULL);1046 " shading opacity value ?volume ...?\"", (char*)NULL); 1038 1047 return TCL_ERROR; 1039 1048 } … … 1042 1051 return TCL_ERROR; 1043 1052 } 1044 vector< unsigned int> ivol;1045 if (GetVolume Indices(interp, argc-4, argv+4, &ivol) != TCL_OK) {1046 return TCL_ERROR; 1047 } 1048 vector< unsigned int>::iterator iter;1053 vector<Volume *> ivol; 1054 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1055 return TCL_ERROR; 1056 } 1057 vector<Volume *>::iterator iter; 1049 1058 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1050 NanoVis::volume[*iter]->set_opacity_scale(opacity);1059 (*iter)->set_opacity_scale(opacity); 1051 1060 } 1052 1061 } else if ((c == 's') && (strcmp(argv[2], "specular") == 0)) { 1053 1062 if (argc < 4) { 1054 1063 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1055 argv[1], "specular value ?volume ...?\"", (char*)NULL);1064 " shading specular value ?volume ...?\"", (char*)NULL); 1056 1065 return TCL_ERROR; 1057 1066 } … … 1060 1069 return TCL_ERROR; 1061 1070 } 1062 vector< unsigned int> ivol;1063 if (GetVolume Indices(interp, argc-4, argv+4, &ivol) != TCL_OK) {1064 return TCL_ERROR; 1065 } 1066 vector< unsigned int>::iterator iter;1071 vector<Volume *> ivol; 1072 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1073 return TCL_ERROR; 1074 } 1075 vector<Volume *>::iterator iter; 1067 1076 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1068 NanoVis::volume[*iter]->set_specular(specular);1077 (*iter)->set_specular(specular); 1069 1078 } 1070 1079 } else if ((c == 'i') && (strcmp(argv[2], "isosurface") == 0)) { 1071 1072 1080 if (argc < 4) { 1073 1081 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1074 argv[1], " isosurface value ?volume ...?\"", (char*)NULL); 1075 return TCL_ERROR; 1076 } 1077 int iso_surface = 0; 1078 1079 if ((strcmp(argv[3], "true") == 0)) 1080 { 1081 iso_surface = 1; 1082 } 1083 1084 vector<unsigned int> ivol; 1085 if (GetVolumeIndices(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1086 return TCL_ERROR; 1087 } 1088 vector<unsigned int>::iterator iter; 1082 " shading isosurface on|off ?volume ...?\"", (char*)NULL); 1083 return TCL_ERROR; 1084 } 1085 int iso_surface = 0; 1086 if (Tcl_GetBoolean(interp, argv[3], &iso_surface) != TCL_OK) { 1087 return TCL_ERROR; 1088 } 1089 vector<Volume *> ivol; 1090 if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) { 1091 return TCL_ERROR; 1092 } 1093 #ifndef notdef 1094 vector<Volume *>::iterator iter; 1089 1095 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1090 NanoVis::volume[*iter]->set_isosurface(iso_surface); 1091 } 1092 } 1093 else { 1094 Tcl_AppendResult(interp, "bad option \"", argv[2], "\": should be ", 1095 "diffuse, opacity, specular, or transfunc", (char*)NULL); 1096 (*iter)->set_isosurface(iso_surface); 1097 } 1098 #endif 1099 } else { 1100 Tcl_AppendResult(interp, "bad shading option \"", argv[2], 1101 "\": should be diffuse, opacity, specular, transfunc, or ", 1102 "isosurface", (char*)NULL); 1096 1103 return TCL_ERROR; 1097 1104 } … … 1099 1106 if (argc < 3) { 1100 1107 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1101 argv[1], "on|off ?volume...?\"", (char*)NULL);1108 " state on|off ?volume...?\"", (char*)NULL); 1102 1109 return TCL_ERROR; 1103 1110 } … … 1106 1113 return TCL_ERROR; 1107 1114 } 1108 1109 vector<unsigned int> ivol; 1110 if (GetVolumeIndices(interp, argc-3, argv+3, &ivol) != TCL_OK) { 1115 vector<Volume *> ivol; 1116 if (GetVolumes(interp, argc-3, argv+3, &ivol) != TCL_OK) { 1111 1117 return TCL_ERROR; 1112 1118 } 1113 vector<unsigned int>::iterator iter = ivol.begin(); 1114 while (iter != ivol.end()) { 1115 if (state) { 1116 NanoVis::volume[*iter]->enable(); 1117 } else { 1118 NanoVis::volume[*iter]->disable(); 1119 } 1120 1121 // TBD 1122 // POINTSET 1123 /* 1124 if (volume[*iter]->pointsetIndex != -1) 1125 { 1126 g_pointSet[volume[*iter]->pointsetIndex]->setVisible(state); 1127 } 1128 */ 1129 ++iter; 1130 } 1119 if (state) { 1120 vector<Volume *>::iterator iter; 1121 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1122 (*iter)->enable(); 1123 } 1124 } else { 1125 vector<Volume *>::iterator iter; 1126 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1127 (*iter)->disable(); 1128 } 1129 } 1131 1130 } else if ((c == 't') && (strcmp(argv[1],"test2") == 0)) { 1132 1131 NanoVis::volume[1]->disable_data(); … … 2489 2488 return TCL_ERROR; 2490 2489 } 2491 2492 2490 HeightMap* hMap; 2493 2491 hMap = new HeightMap();
Note: See TracChangeset
for help on using the changeset viewer.