Changeset 1028 for trunk/packages
- Timestamp:
- Jun 9, 2008 9:08:02 AM (16 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Axis.cpp
r955 r1028 122 122 _name = NULL; 123 123 SetName(name); 124 _units = NULL; 124 125 _title = NULL; 125 126 _valueMin = DBL_MAX, _valueMax = -DBL_MAX; -
trunk/packages/vizservers/nanovis/Axis.h
r939 r1028 187 187 }; 188 188 189 c har *_name; /* Name of the axis. Malloc-ed */189 const char *_name; /* Name of the axis. Malloc-ed */ 190 190 191 191 unsigned int _flags; 192 192 193 char *_title; /* Title of the axis. */ 193 const char *_title; /* Title of the axis. */ 194 195 const char *_units; /* Units of the axis. */ 194 196 195 197 double _valueMin, _valueMax; /* The limits of the data. */ … … 227 229 public: 228 230 Axis(const char *name); 231 ~Axis(void) { 232 if (_name != NULL) { 233 free((void *)_name); 234 } 235 if (_units != NULL) { 236 free((void *)_units); 237 } 238 if (_title != NULL) { 239 free((void *)_title); 240 } 241 } 229 242 230 243 void ResetRange(void); … … 243 256 return _minor.FirstTick(iter); 244 257 } 245 void GetDataLimits(double min, double max); 258 void GetDataLimits(double &min, double &max) { 259 min = _valueMin, max = _valueMax; 260 } 246 261 double Map(double x); 247 262 double InvMap(double x); 248 c har *GetName(void) {249 return _name;263 const char *GetName(void) { 264 return (_name == NULL) ? "???" : _name; 250 265 } 251 266 void SetName(const char *name) { 252 _name = new char[strlen(name) + 1]; 253 strcpy(_name, name); 267 if (_name != NULL) { 268 free((void *)_name); 269 } 270 _name = strdup(name); 271 } 272 const char *GetUnits(void) { 273 return (_units == NULL) ? "???" : _units; 274 } 275 void SetUnits(const char *units) { 276 if (_units != NULL) { 277 free((void *)_units); 278 } 279 _units = strdup(units); 280 } 281 const char *GetTitle(void) { 282 return (_title == NULL) ? "???" : _title; 283 } 284 void SetTitle(const char *title) { 285 if (_title != NULL) { 286 free((void *)_title); 287 } 288 _title = strdup(title); 254 289 } 255 290 void SetMin(double min) { -
trunk/packages/vizservers/nanovis/Command.cpp
r1000 r1028 73 73 #include <NvLIC.h> 74 74 75 //#define ISO_TEST 175 #define ISO_TEST 1 76 76 #define PLANE_CMD 0 77 77 #define __TEST_CODE__ 0 … … 143 143 #endif 144 144 static Tcl_ObjCmdProc ScreenCmd; 145 static Tcl_ObjCmdProc S creenShotCmd;145 static Tcl_ObjCmdProc SnapshotCmd; 146 146 static Tcl_ObjCmdProc TransfuncCmd; 147 147 static Tcl_ObjCmdProc UniRect2dCmd; … … 175 175 static int 176 176 GetCullMode(Tcl_Interp *interp, Tcl_Obj *objPtr, 177 178 { 179 c har *string = Tcl_GetString(objPtr);177 graphics::RenderContext::CullMode *modePtr) 178 { 179 const char *string = Tcl_GetString(objPtr); 180 180 if (strcmp(string, "none") == 0) { 181 181 *modePtr = graphics::RenderContext::NO_CULL; … … 186 186 } else { 187 187 Tcl_AppendResult(interp, "invalid cull mode \"", string, 188 188 "\": should be front, back, or none\"", (char *)NULL); 189 189 return TCL_ERROR; 190 190 } … … 196 196 graphics::RenderContext::ShadingModel *modelPtr) 197 197 { 198 char *string = Tcl_GetString(objPtr); 198 const char *string = Tcl_GetString(objPtr); 199 199 200 if (strcmp(string,"flat") == 0) { 200 201 *modelPtr = graphics::RenderContext::FLAT; … … 213 214 graphics::RenderContext::PolygonMode *modePtr) 214 215 { 215 char *string = Tcl_GetString(objPtr); 216 const char *string = Tcl_GetString(objPtr); 217 216 218 if (strcmp(string,"wireframe") == 0) { 217 219 *modePtr = graphics::RenderContext::LINE; … … 220 222 } else { 221 223 Tcl_AppendResult(interp, "invalid polygon mode \"", string, 222 224 "\": should be wireframe or fill\"", (char *)NULL); 223 225 return TCL_ERROR; 224 226 } … … 243 245 static HeightMap * 244 246 CreateHeightMap(ClientData clientData, Tcl_Interp *interp, int objc, 245 Tcl_Obj * CONST*objv)247 Tcl_Obj *const *objv) 246 248 { 247 249 float xMin, yMin, xMax, yMax; … … 250 252 if (objc != 7) { 251 253 Tcl_AppendResult(interp, 252 253 254 "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights", 255 (char *)NULL); 254 256 return NULL; 255 257 } … … 280 282 if (heights == NULL) { 281 283 Tcl_AppendResult(interp, "can't allocate array of heights", 282 284 (char *)NULL); 283 285 return NULL; 284 286 } … … 317 319 if (index < 0) { 318 320 Tcl_AppendResult(interp, "can't have negative index \"", 319 321 Tcl_GetString(objPtr), "\"", (char*)NULL); 320 322 return TCL_ERROR; 321 323 } … … 347 349 if (hmPtr == NULL) { 348 350 Tcl_AppendResult(interp, "no heightmap defined for index \"", 349 351 Tcl_GetString(objPtr), "\"", (char*)NULL); 350 352 return TCL_ERROR; 351 353 } … … 376 378 if (index < 0) { 377 379 Tcl_AppendResult(interp, "can't have negative index \"", 378 380 Tcl_GetString(objPtr), "\"", (char*)NULL); 379 381 return TCL_ERROR; 380 382 } … … 412 414 if (vol == NULL) { 413 415 Tcl_AppendResult(interp, "no volume defined for index \"", 414 416 Tcl_GetString(objPtr), "\"", (char*)NULL); 415 417 return TCL_ERROR; 416 418 } … … 433 435 */ 434 436 static int 435 GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv,436 437 GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, 438 vector<unsigned int>* vectorPtr) 437 439 { 438 440 if (objc == 0) { … … 471 473 */ 472 474 static int 473 GetVolumes(Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv,474 475 GetVolumes(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, 476 vector<Volume *>* vectorPtr) 475 477 { 476 478 if (objc == 0) { … … 487 489 return TCL_ERROR; 488 490 } 489 491 vectorPtr->push_back(volPtr); 490 492 } 491 493 } … … 507 509 */ 508 510 static int 509 GetHeightMaps(Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv,510 511 GetHeightMaps(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, 512 vector<HeightMap *>* vectorPtr) 511 513 { 512 514 if (objc == 0) { … … 523 525 return TCL_ERROR; 524 526 } 525 527 vectorPtr->push_back(hmPtr); 526 528 } 527 529 } … … 560 562 } 561 563 Tcl_AppendResult(interp, "bad axis \"", string, 562 564 "\": should be x, y, or z", (char*)NULL); 563 565 return TCL_ERROR; 564 566 } … … 593 595 GetAxisDirFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr, int *dirPtr) 594 596 { 595 c har *string = Tcl_GetString(objPtr);597 const char *string = Tcl_GetString(objPtr); 596 598 597 599 int sign = 1; … … 620 622 */ 621 623 static int 622 GetColor(Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv, float *rgbPtr)624 GetColor(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, float *rgbPtr) 623 625 { 624 626 if (objc < 3) { 625 627 Tcl_AppendResult(interp, "missing color values\": ", 626 628 "should list of R G B values 0.0 - 1.0", (char*)NULL); 627 629 return TCL_ERROR; 628 630 } … … 661 663 if (ferror(stdin)) { 662 664 Tcl_AppendResult(interp, "while reading data stream: ", 663 665 Tcl_PosixError(interp), (char*)NULL); 664 666 return TCL_ERROR; 665 667 } 666 668 if (feof(stdin)) { 667 669 Tcl_AppendResult(interp, "premature EOF while reading data stream", 668 670 (char*)NULL); 669 671 return TCL_ERROR; 670 672 } … … 687 689 688 690 static int 689 CameraAimOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)691 CameraAimOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 690 692 { 691 693 double x0, y0, z0; … … 700 702 701 703 static int 702 CameraAngleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)704 CameraAngleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 703 705 { 704 706 double xangle, yangle, zangle; … … 713 715 714 716 static int 715 CameraZoomOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)717 CameraZoomOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 716 718 { 717 719 double zoom; … … 744 746 */ 745 747 static int 746 CameraCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)748 CameraCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 747 749 { 748 750 Tcl_ObjCmdProc *proc; 749 751 750 752 proc = Rappture::GetOpFromObj(interp, nCameraOps, cameraOps, 751 753 Rappture::CMDSPEC_ARG1, objc, objv, 0); 752 754 if (proc == NULL) { 753 755 return TCL_ERROR; … … 756 758 } 757 759 758 static int 759 ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int objc, 760 Tcl_Obj *CONST *objv) 761 { 762 #ifdef XINETD 763 NanoVis::resize_offscreen_buffer(1024, 1024); 764 NanoVis::cam->set_screen_size(30, 90, 1024 - 60, 1024 - 120); 760 /*ARGSUSED*/ 761 static int 762 SnapshotCmd(ClientData cdata, Tcl_Interp *interp, int objc, 763 Tcl_Obj *const *objv) 764 { 765 int w, h; 766 767 w = NanoVis::win_width, h = NanoVis::win_height; 768 NanoVis::resize_offscreen_buffer(2048, 2048); 769 #ifdef notdef 770 NanoVis::cam->set_screen_size(0, 0, NanoVis::win_width,NanoVis::win_height); 771 NanoVis::cam->set_screen_size(30, 90, 2048 - 60, 2048 - 120); 772 #endif 765 773 NanoVis::offscreen_buffer_capture(); //enable offscreen render 766 774 NanoVis::display(); 767 768 // INSOO 769 // TBD 770 /* 771 Volume* vol = NanoVis::volume[0]; 772 TransferFunction* tf; 773 tf = NanoVis::vol_renderer->get_volume_shading(vol); 774 if (tf != NULL) 775 { 776 float data[512]; 777 778 for (int i=0; i < 256; i++) { 779 data[i] = data[i+256] = (float)(i/255.0); 780 } 781 Texture2D* plane = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data); 782 NanoVis::color_table_renderer->render(1024, 1024, plane, tf, vol->wAxis.Min(), 783 vol->wAxis.Max()); 784 delete plane; 785 786 } 787 */ 775 NanoVis::read_screen(); 776 #ifdef notdef 777 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 788 778 #endif 789 779 NanoVis::ppm_write("nv>print -bytes"); 780 NanoVis::resize_offscreen_buffer(w, h); 790 781 return TCL_OK; 791 782 } … … 793 784 static int 794 785 CutplanePositionOp(ClientData cdata, Tcl_Interp *interp, int objc, 795 Tcl_Obj * CONST*objv)786 Tcl_Obj *const *objv) 796 787 { 797 788 float relval; … … 825 816 static int 826 817 CutplaneStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 827 Tcl_Obj * CONST*objv)818 Tcl_Obj *const *objv) 828 819 { 829 820 bool state; … … 877 868 */ 878 869 static int 879 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv) 870 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, 871 Tcl_Obj *const *objv) 880 872 { 881 873 Tcl_ObjCmdProc *proc; 882 874 883 875 proc = Rappture::GetOpFromObj(interp, nCutplaneOps, cutplaneOps, 884 876 Rappture::CMDSPEC_ARG1, objc, objv, 0); 885 877 if (proc == NULL) { 886 878 return TCL_ERROR; … … 901 893 */ 902 894 static int 903 LegendCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)895 LegendCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 904 896 { 905 897 if (objc != 4) { 906 898 Tcl_AppendResult(interp, "wrong # args: should be \"", 907 899 Tcl_GetString(objv[0]), " volIndex width height\"", (char*)NULL); 908 900 return TCL_ERROR; 909 901 } … … 917 909 if (tf == NULL) { 918 910 Tcl_AppendResult(interp, "no transfer function defined for volume \"", 919 920 return TCL_ERROR; 921 } 922 c har *label;911 Tcl_GetString(objv[1]), "\"", (char*)NULL); 912 return TCL_ERROR; 913 } 914 const char *label; 923 915 label = Tcl_GetString(objv[1]); 924 916 … … 929 921 } 930 922 if (volPtr->update_pending) { 931 923 NanoVis::SetVolumeRanges(); 932 924 } 933 925 NanoVis::render_legend(tf, Volume::valueMin, Volume::valueMax, w, h, label); … … 945 937 */ 946 938 static int 947 ScreenCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)939 ScreenCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 948 940 { 949 941 if (objc != 3) { 950 942 Tcl_AppendResult(interp, "wrong # args: should be \"", 951 943 Tcl_GetString(objv[0]), " width height\"", (char*)NULL); 952 944 return TCL_ERROR; 953 945 } … … 974 966 static int 975 967 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc, 976 Tcl_Obj *CONST*objv)968 Tcl_Obj *const *objv) 977 969 { 978 970 if (objc < 2) { 979 971 Tcl_AppendResult(interp, "wrong # args: should be \"", 980 981 return TCL_ERROR; 982 } 983 984 c har *string = Tcl_GetString(objv[1]);972 Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL); 973 return TCL_ERROR; 974 } 975 976 const char *string = Tcl_GetString(objv[1]); 985 977 char c = string[0]; 986 if ((c == 'd') && (strcmp(string, "define") == 0)) 987 { 978 if ((c == 'd') && (strcmp(string, "define") == 0)) { 988 979 if (objc != 5) { 989 980 Tcl_AppendResult(interp, "wrong # args: should be \"", 990 991 981 Tcl_GetString(objv[0]), " define name colorMap alphaMap\"", 982 (char*)NULL); 992 983 return TCL_ERROR; 993 984 } … … 1005 996 if ((cmapc % 4) != 0) { 1006 997 Tcl_AppendResult(interp, "wrong # elements is colormap: should be ", 1007 998 "{ v r g b ... }", (char*)NULL); 1008 999 return TCL_ERROR; 1009 1000 } … … 1013 1004 if ((wmapc % 2) != 0) { 1014 1005 Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ", 1015 1006 " { v w ... }", (char*)NULL); 1016 1007 return TCL_ERROR; 1017 1008 } … … 1026 1017 if ((q[j] < 0.0) || (q[j] > 1.0)) { 1027 1018 Tcl_AppendResult(interp, "bad colormap value \"", 1028 1029 1019 Tcl_GetString(cmapv[i+j]), 1020 "\": should be in the range 0-1", (char*)NULL); 1030 1021 return TCL_ERROR; 1031 1022 } … … 1045 1036 if ((q[j] < 0.0) || (q[j] > 1.0)) { 1046 1037 Tcl_AppendResult(interp, "bad alphamap value \"", 1047 1048 1038 Tcl_GetString(wmapv[i+j]), 1039 "\": should be in the range 0-1", (char*)NULL); 1049 1040 return TCL_ERROR; 1050 1041 } … … 1066 1057 } else { 1067 1058 Tcl_AppendResult(interp, "bad option \"", string, 1068 1059 "\": should be define", (char*)NULL); 1069 1060 return TCL_ERROR; 1070 1061 } … … 1082 1073 */ 1083 1074 static int 1084 UpCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)1075 UpCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 1085 1076 { 1086 1077 if (objc != 2) { 1087 1078 Tcl_AppendResult(interp, "wrong # args: should be \"", 1088 1079 Tcl_GetString(objv[0]), " x|y|z|-x|-y|-z\"", (char*)NULL); 1089 1080 return TCL_ERROR; 1090 1081 } … … 1102 1093 static int 1103 1094 VolumeAnimationCaptureOp(ClientData cdata, Tcl_Interp *interp, int objc, 1104 Tcl_Obj *CONST*objv)1095 Tcl_Obj *const *objv) 1105 1096 { 1106 1097 int total; 1107 1098 if (Tcl_GetIntFromObj(interp, objv[3], &total) != TCL_OK) { 1108 1099 return TCL_ERROR; 1109 1100 } 1110 1101 VolumeInterpolator* interpolator; … … 1112 1103 interpolator->start(); 1113 1104 if (interpolator->is_started()) { 1114 char *fileName = (objc < 5) ? NULL : Tcl_GetString(objv[4]); 1115 for (int frame_num = 0; frame_num < total; ++frame_num) { 1116 float fraction; 1117 1118 fraction = ((float)frame_num) / (total - 1); 1119 Trace("fraction : %f\n", fraction); 1120 //interpolator->update(((float)frame_num) / (total - 1)); 1121 interpolator->update(fraction); 1122 1123 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1124 1125 NanoVis::display(); 1126 NanoVis::read_screen(); 1127 1128 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1105 const char *fileName = (objc < 5) ? NULL : Tcl_GetString(objv[4]); 1106 for (int frame_num = 0; frame_num < total; ++frame_num) { 1107 float fraction; 1129 1108 1130 NanoVis::bmp_write_to_file(frame_num, fileName); 1131 } 1109 fraction = ((float)frame_num) / (total - 1); 1110 Trace("fraction : %f\n", fraction); 1111 //interpolator->update(((float)frame_num) / (total - 1)); 1112 interpolator->update(fraction); 1113 1114 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1115 1116 NanoVis::display(); 1117 NanoVis::read_screen(); 1118 1119 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1120 1121 NanoVis::bmp_write_to_file(frame_num, fileName); 1122 } 1132 1123 } 1133 1124 return TCL_OK; … … 1136 1127 static int 1137 1128 VolumeAnimationClearOp(ClientData cdata, Tcl_Interp *interp, int objc, 1138 Tcl_Obj *CONST*objv)1129 Tcl_Obj *const *objv) 1139 1130 { 1140 1131 NanoVis::vol_renderer->clearAnimatedVolumeInfo(); … … 1144 1135 static int 1145 1136 VolumeAnimationStartOp(ClientData cdata, Tcl_Interp *interp, int objc, 1146 Tcl_Obj *CONST*objv)1137 Tcl_Obj *const *objv) 1147 1138 { 1148 1139 NanoVis::vol_renderer->startVolumeAnimation(); … … 1152 1143 static int 1153 1144 VolumeAnimationStopOp(ClientData cdata, Tcl_Interp *interp, int objc, 1154 Tcl_Obj *CONST*objv)1145 Tcl_Obj *const *objv) 1155 1146 { 1156 1147 NanoVis::vol_renderer->stopVolumeAnimation(); … … 1160 1151 static int 1161 1152 VolumeAnimationVolumesOp(ClientData cdata, Tcl_Interp *interp, int objc, 1162 Tcl_Obj *CONST*objv)1153 Tcl_Obj *const *objv) 1163 1154 { 1164 1155 vector<unsigned int> ivol; 1165 1156 if (GetVolumeIndices(interp, objc - 3, objv + 3, &ivol) != TCL_OK) { 1166 1157 return TCL_ERROR; 1167 1158 } 1168 1159 Trace("parsing volume index\n"); 1169 1160 vector<unsigned int>::iterator iter; 1170 1161 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1171 1172 1162 Trace("index: %d\n", *iter); 1163 NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volume[*iter], *iter); 1173 1164 } 1174 1165 return TCL_OK; … … 1187 1178 static int 1188 1179 VolumeAnimationOp(ClientData cdata, Tcl_Interp *interp, int objc, 1189 Tcl_Obj *CONST*objv)1180 Tcl_Obj *const *objv) 1190 1181 { 1191 1182 Tcl_ObjCmdProc *proc; 1192 1183 1193 1184 proc = Rappture::GetOpFromObj(interp, nVolumeAnimationOps, volumeAnimationOps, 1194 1185 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1195 1186 if (proc == NULL) { 1196 1187 return TCL_ERROR; … … 1202 1193 static int 1203 1194 VolumeDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, 1204 Tcl_Obj * CONST*objv)1195 Tcl_Obj *const *objv) 1205 1196 { 1206 1197 printf("Data Loading\n"); … … 1335 1326 1336 1327 if (Volume::update_pending) { 1337 1328 NanoVis::SetVolumeRanges(); 1338 1329 } 1339 1330 volPtr = NanoVis::volume[n]; 1340 1331 sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n", 1341 1332 n, volPtr->wAxis.Min(), volPtr->wAxis.Max(), 1342 1333 Volume::valueMin, Volume::valueMax); 1343 1334 write(0, info, strlen(info)); 1344 1335 } … … 1348 1339 static int 1349 1340 VolumeDataStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1350 Tcl_Obj * CONST*objv)1341 Tcl_Obj *const *objv) 1351 1342 { 1352 1343 bool state; … … 1380 1371 static int 1381 1372 VolumeDataOp(ClientData cdata, Tcl_Interp *interp, int objc, 1382 Tcl_Obj *CONST*objv)1373 Tcl_Obj *const *objv) 1383 1374 { 1384 1375 Tcl_ObjCmdProc *proc; 1385 1376 1386 1377 proc = Rappture::GetOpFromObj(interp, nVolumeDataOps, volumeDataOps, 1387 1378 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1388 1379 if (proc == NULL) { 1389 1380 return TCL_ERROR; … … 1394 1385 static int 1395 1386 VolumeOutlineColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 1396 Tcl_Obj *CONST*objv)1387 Tcl_Obj *const *objv) 1397 1388 { 1398 1389 float rgb[3]; 1399 1390 if (GetColor(interp, objc - 3, objv + 3, rgb) != TCL_OK) { 1400 1391 return TCL_ERROR; 1401 1392 } 1402 1393 vector<Volume *> ivol; 1403 1394 if (GetVolumes(interp, objc - 6, objv + 6, &ivol) != TCL_OK) { 1404 1395 return TCL_ERROR; 1405 1396 } 1406 1397 vector<Volume *>::iterator iter; 1407 1398 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1408 1399 (*iter)->set_outline_color(rgb); 1409 1400 } 1410 1401 return TCL_OK; … … 1413 1404 static int 1414 1405 VolumeOutlineStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1415 Tcl_Obj *CONST*objv)1406 Tcl_Obj *const *objv) 1416 1407 { 1417 1408 bool state; 1418 1409 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) { 1419 1410 return TCL_ERROR; 1420 1411 } 1421 1412 vector<Volume *> ivol; 1422 1413 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { 1423 1414 return TCL_ERROR; 1424 1415 } 1425 1416 if (state) { 1426 1427 1428 1429 1417 vector<Volume *>::iterator iter; 1418 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1419 (*iter)->enable_outline(); 1420 } 1430 1421 } else { 1431 1432 1433 1434 1422 vector<Volume *>::iterator iter; 1423 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1424 (*iter)->disable_outline(); 1425 } 1435 1426 } 1436 1427 return TCL_OK; … … 1447 1438 static int 1448 1439 VolumeOutlineOp(ClientData cdata, Tcl_Interp *interp, int objc, 1449 Tcl_Obj *CONST*objv)1440 Tcl_Obj *const *objv) 1450 1441 { 1451 1442 Tcl_ObjCmdProc *proc; 1452 1443 1453 1444 proc = Rappture::GetOpFromObj(interp, nVolumeOutlineOps, volumeOutlineOps, 1454 1445 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1455 1446 if (proc == NULL) { 1456 1447 return TCL_ERROR; … … 1461 1452 static int 1462 1453 VolumeShadingDiffuseOp(ClientData cdata, Tcl_Interp *interp, int objc, 1463 Tcl_Obj *CONST*objv)1454 Tcl_Obj *const *objv) 1464 1455 { 1465 1456 float diffuse; 1466 1457 if (GetFloatFromObj(interp, objv[3], &diffuse) != TCL_OK) { 1467 1458 return TCL_ERROR; 1468 1459 } 1469 1460 1470 1461 vector<Volume *> ivol; 1471 1462 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { 1472 1463 return TCL_ERROR; 1473 1464 } 1474 1465 vector<Volume *>::iterator iter; 1475 1466 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1476 1467 (*iter)->set_diffuse(diffuse); 1477 1468 } 1478 1469 return TCL_OK; … … 1481 1472 static int 1482 1473 VolumeShadingIsosurfaceOp(ClientData cdata, Tcl_Interp *interp, int objc, 1483 Tcl_Obj *CONST*objv)1474 Tcl_Obj *const *objv) 1484 1475 { 1485 1476 bool iso_surface; 1486 1477 if (GetBooleanFromObj(interp, objv[3], &iso_surface) != TCL_OK) { 1487 1478 return TCL_ERROR; 1488 1479 } 1489 1480 vector<Volume *> ivol; 1490 1481 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { 1491 1482 return TCL_ERROR; 1492 1483 } 1493 1484 vector<Volume *>::iterator iter; 1494 1485 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1495 1486 (*iter)->set_isosurface(iso_surface); 1496 1487 } 1497 1488 return TCL_OK; … … 1500 1491 static int 1501 1492 VolumeShadingOpacityOp(ClientData cdata, Tcl_Interp *interp, int objc, 1502 Tcl_Obj *CONST*objv)1493 Tcl_Obj *const *objv) 1503 1494 { 1504 1495 1505 1496 float opacity; 1506 1497 if (GetFloatFromObj(interp, objv[3], &opacity) != TCL_OK) { 1507 1498 return TCL_ERROR; 1508 1499 } 1509 1500 printf("set opacity %f\n", opacity); 1510 1501 vector<Volume *> ivol; 1511 1502 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { 1512 1503 return TCL_ERROR; 1513 1504 } 1514 1505 vector<Volume *>::iterator iter; 1515 1506 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1516 1507 (*iter)->set_opacity_scale(opacity); 1517 1508 } 1518 1509 return TCL_OK; … … 1521 1512 static int 1522 1513 VolumeShadingSpecularOp(ClientData cdata, Tcl_Interp *interp, int objc, 1523 Tcl_Obj *CONST*objv)1514 Tcl_Obj *const *objv) 1524 1515 { 1525 1516 float specular; 1526 1517 if (GetFloatFromObj(interp, objv[3], &specular) != TCL_OK) { 1527 1518 return TCL_ERROR; 1528 1519 } 1529 1520 vector<Volume *> ivol; 1530 1521 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { 1531 1522 return TCL_ERROR; 1532 1523 } 1533 1524 vector<Volume *>::iterator iter; 1534 1525 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1535 1526 (*iter)->set_specular(specular); 1536 1527 } 1537 1528 return TCL_OK; … … 1540 1531 static int 1541 1532 VolumeShadingTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc, 1542 Tcl_Obj *CONST*objv)1533 Tcl_Obj *const *objv) 1543 1534 { 1544 1535 TransferFunction *tf; 1545 c har *name = Tcl_GetString(objv[3]);1536 const char *name = Tcl_GetString(objv[3]); 1546 1537 tf = NanoVis::get_transfunc(name); 1547 1538 if (tf == NULL) { 1548 1549 1550 1539 Tcl_AppendResult(interp, "transfer function \"", name, 1540 "\" is not defined", (char*)NULL); 1541 return TCL_ERROR; 1551 1542 } 1552 1543 vector<Volume *> ivol; 1553 1544 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { 1554 1545 return TCL_ERROR; 1555 1546 } 1556 1547 vector<Volume *>::iterator iter; 1557 1548 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1558 1549 NanoVis::vol_renderer->shade_volume(*iter, tf); 1559 1550 #ifdef POINTSET 1560 1561 1562 1563 1564 1551 // TBD.. 1552 // POINTSET 1553 if ((*iter)->pointsetIndex != -1) { 1554 g_pointSet[(*iter)->pointsetIndex]->updateColor(tf->getData(), 256); 1555 } 1565 1556 #endif /*POINTSET*/ 1566 1557 } … … 1579 1570 static int 1580 1571 VolumeShadingOp(ClientData cdata, Tcl_Interp *interp, int objc, 1581 Tcl_Obj *CONST*objv)1572 Tcl_Obj *const *objv) 1582 1573 { 1583 1574 Tcl_ObjCmdProc *proc; 1584 1575 1585 1576 proc = Rappture::GetOpFromObj(interp, nVolumeShadingOps, volumeShadingOps, 1586 1577 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1587 1578 if (proc == NULL) { 1588 1579 return TCL_ERROR; … … 1593 1584 static int 1594 1585 VolumeAxisOp(ClientData cdata, Tcl_Interp *interp, int objc, 1595 Tcl_Obj *CONST*objv)1596 { 1597 c har *string = Tcl_GetString(objv[2]);1586 Tcl_Obj *const *objv) 1587 { 1588 const char *string = Tcl_GetString(objv[2]); 1598 1589 char c; 1599 1590 c = string[0]; 1600 1591 if ((c == 'l') && (strcmp(string, "label") == 0)) { 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1592 int axis; 1593 if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) { 1594 return TCL_ERROR; 1595 } 1596 vector<Volume *> ivol; 1597 if (GetVolumes(interp, objc - 5, objv + 5, &ivol) != TCL_OK) { 1598 return TCL_ERROR; 1599 } 1600 vector<Volume *>::iterator iter; 1601 const char *label; 1602 label = Tcl_GetString(objv[4]); 1603 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1604 (*iter)->set_label(axis, label); 1605 } 1615 1606 } else { 1616 1617 1618 1607 Tcl_AppendResult(interp, "bad option \"", string, 1608 "\": should be label", (char*)NULL); 1609 return TCL_ERROR; 1619 1610 } 1620 1611 return TCL_OK; … … 1623 1614 static int 1624 1615 VolumeStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1625 Tcl_Obj *CONST*objv)1616 Tcl_Obj *const *objv) 1626 1617 { 1627 1618 bool state; 1628 1619 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 1629 1620 return TCL_ERROR; 1630 1621 } 1631 1622 vector<Volume *> ivol; 1632 1623 if (GetVolumes(interp, objc - 3, objv + 3, &ivol) != TCL_OK) { 1633 1624 return TCL_ERROR; 1634 1625 } 1635 1626 if (state) { 1636 1637 1638 1639 1627 vector<Volume *>::iterator iter; 1628 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1629 (*iter)->enable(); 1630 } 1640 1631 } else { 1641 1642 1643 1644 1632 vector<Volume *>::iterator iter; 1633 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1634 (*iter)->disable(); 1635 } 1645 1636 } 1646 1637 return TCL_OK; … … 1649 1640 static int 1650 1641 VolumeTestOp(ClientData cdata, Tcl_Interp *interp, int objc, 1651 Tcl_Obj *CONST*objv)1642 Tcl_Obj *const *objv) 1652 1643 { 1653 1644 NanoVis::volume[1]->disable_data(); … … 1684 1675 */ 1685 1676 static int 1686 VolumeCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)1677 VolumeCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 1687 1678 { 1688 1679 Tcl_ObjCmdProc *proc; 1689 1680 1690 1681 proc = Rappture::GetOpFromObj(interp, nVolumeOps, volumeOps, 1691 1682 Rappture::CMDSPEC_ARG1, objc, objv, 0); 1692 1683 if (proc == NULL) { 1693 1684 return TCL_ERROR; … … 1697 1688 1698 1689 static int 1699 FlowCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)1690 FlowCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 1700 1691 { 1701 1692 Rappture::Outcome err; … … 1703 1694 if (objc < 2) { 1704 1695 Tcl_AppendResult(interp, "wrong # args: should be \"", 1705 1706 return TCL_ERROR; 1707 } 1708 c har *string = Tcl_GetString(objv[1]);1696 Tcl_GetString(objv[0]), " option ?arg arg?", (char *)NULL); 1697 return TCL_ERROR; 1698 } 1699 const char *string = Tcl_GetString(objv[1]); 1709 1700 char c = string[0]; 1710 1701 if ((c == 'v') && (strcmp(string, "vectorid") == 0)) { 1711 1702 if (objc != 3) { 1712 1703 Tcl_AppendResult(interp, "wrong # args: should be \"", 1713 1704 Tcl_GetString(objv[0]), " vectorid volume", (char *)NULL); 1714 1705 return TCL_ERROR; 1715 1706 } … … 1720 1711 if (NanoVis::particleRenderer != NULL) { 1721 1712 NanoVis::particleRenderer->setVectorField(volPtr->id, 1.0f, 1722 1723 1724 1713 volPtr->height / (float)volPtr->width, 1714 volPtr->depth / (float)volPtr->width, 1715 volPtr->wAxis.Max()); 1725 1716 NanoVis::initParticle(); 1726 1717 } 1727 1718 if (NanoVis::licRenderer != NULL) { 1728 1719 NanoVis::licRenderer->setVectorField(volPtr->id, 1729 1730 1731 1732 1720 1.0f / volPtr->aspect_ratio_width, 1721 1.0f / volPtr->aspect_ratio_height, 1722 1.0f / volPtr->aspect_ratio_depth, 1723 volPtr->wAxis.Max()); 1733 1724 NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z); 1734 1725 } … … 1736 1727 if (objc != 3) { 1737 1728 Tcl_AppendResult(interp, "wrong # args: should be \"", 1738 1729 Tcl_GetString(objv[0]), " lic on|off\"", (char*)NULL); 1739 1730 return TCL_ERROR; 1740 1731 } … … 1747 1738 if (objc < 3) { 1748 1739 Tcl_AppendResult(interp, "wrong # args: should be \"", 1749 1750 1740 Tcl_GetString(objv[0]), " particle visible|slice|slicepos arg \"", 1741 (char*)NULL); 1751 1742 return TCL_ERROR; 1752 1743 } 1753 c har *string = Tcl_GetString(objv[2]);1744 const char *string = Tcl_GetString(objv[2]); 1754 1745 c = string[0]; 1755 1746 if ((c == 'v') && (strcmp(string, "visible") == 0)) { 1756 1747 if (objc != 4) { 1757 1748 Tcl_AppendResult(interp, "wrong # args: should be \"", 1758 1759 1749 Tcl_GetString(objv[0]), " particle visible on|off\"", 1750 (char*)NULL); 1760 1751 return TCL_ERROR; 1761 1752 } … … 1768 1759 if (objc != 4) { 1769 1760 Tcl_AppendResult(interp, "wrong # args: should be \"", 1770 1771 1761 Tcl_GetString(objv[0]), 1762 " particle slice volume\"", (char*)NULL); 1772 1763 return TCL_ERROR; 1773 1764 } … … 1780 1771 if (objc != 4) { 1781 1772 Tcl_AppendResult(interp, "wrong # args: should be \"", 1782 1783 1773 Tcl_GetString(objv[0]), " particle slicepos value\"", 1774 (char*)NULL); 1784 1775 return TCL_ERROR; 1785 1776 } … … 1805 1796 } 1806 1797 } else { 1807 Tcl_AppendResult(interp, "unknown option \"", string,"\": should be \"",1808 Tcl_GetString(objv[0]), " visible, slice, or slicepos\"", 1809 1798 Tcl_AppendResult(interp, "unknown option \"", string, 1799 "\": should be \"", Tcl_GetString(objv[0]), 1800 " visible, slice, or slicepos\"", (char *)NULL); 1810 1801 return TCL_ERROR; 1811 1802 } … … 1815 1806 if (objc > 4 || objc < 3) { 1816 1807 Tcl_AppendResult(interp, "wrong # args: should be \"", 1817 1818 1808 Tcl_GetString(objv[0]), " capture numframes [directory]\"", 1809 (char*)NULL); 1819 1810 return TCL_ERROR; 1820 1811 } … … 1833 1824 // 1834 1825 Trace("FLOW started\n"); 1835 c har *fileName;1826 const char *fileName; 1836 1827 fileName = (objc < 4) ? NULL : Tcl_GetString(objv[3]); 1837 1828 for (int frame_count = 0; frame_count < total_frame_count; … … 1869 1860 if (objc < 3) { 1870 1861 Tcl_AppendResult(interp, "wrong # args: should be \"", 1871 1862 Tcl_GetString(objv[0]), " data follows ?args?", (char *)NULL); 1872 1863 return TCL_ERROR; 1873 1864 } 1874 c har *string = Tcl_GetString(objv[2]);;1865 const char *string = Tcl_GetString(objv[2]);; 1875 1866 c = string[0]; 1876 1867 if ((c == 'f') && (strcmp(string,"follows") == 0)) { 1877 1868 if (objc != 4) { 1878 1869 Tcl_AppendResult(interp, "wrong # args: should be \"", 1879 1880 1870 Tcl_GetString(objv[0]), " data follows length", 1871 (char *)NULL); 1881 1872 return TCL_ERROR; 1882 1873 } … … 1910 1901 1911 1902 NanoVis::vol_renderer->add_volume(volPtr, 1912 1903 NanoVis::get_transfunc("default")); 1913 1904 } 1914 1905 } … … 1922 1913 static int 1923 1914 HeightMapDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, 1924 Tcl_Obj * CONST*objv)1915 Tcl_Obj *const *objv) 1925 1916 { 1926 1917 Rappture::Buffer buf; … … 1945 1936 static int 1946 1937 HeightMapDataVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, 1947 Tcl_Obj * CONST*objv)1938 Tcl_Obj *const *objv) 1948 1939 { 1949 1940 bool visible; … … 1957 1948 vector<HeightMap *>::iterator iter; 1958 1949 for (iter = imap.begin(); iter != imap.end(); iter++) { 1959 1950 (*iter)->setVisible(visible); 1960 1951 } 1961 1952 return TCL_OK; … … 1970 1961 static int 1971 1962 HeightMapDataOp(ClientData cdata, Tcl_Interp *interp, int objc, 1972 Tcl_Obj *CONST*objv)1963 Tcl_Obj *const *objv) 1973 1964 { 1974 1965 Tcl_ObjCmdProc *proc; 1975 1966 1976 1967 proc = Rappture::GetOpFromObj(interp, nHeightMapDataOps, heightMapDataOps, 1977 1968 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1978 1969 if (proc == NULL) { 1979 1970 return TCL_ERROR; … … 1985 1976 static int 1986 1977 HeightMapLineContourColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 1987 Tcl_Obj *CONST*objv)1978 Tcl_Obj *const *objv) 1988 1979 { 1989 1980 float rgb[3]; … … 1997 1988 vector<HeightMap *>::iterator iter; 1998 1989 for (iter = imap.begin(); iter != imap.end(); iter++) { 1999 1990 (*iter)->setLineContourColor(rgb); 2000 1991 } 2001 1992 return TCL_OK; … … 2004 1995 static int 2005 1996 HeightMapLineContourVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, 2006 Tcl_Obj * CONST*objv)1997 Tcl_Obj *const *objv) 2007 1998 { 2008 1999 bool visible; … … 2016 2007 vector<HeightMap *>::iterator iter; 2017 2008 for (iter = imap.begin(); iter != imap.end(); iter++) { 2018 2009 (*iter)->setLineContourVisible(visible); 2019 2010 } 2020 2011 return TCL_OK; … … 2029 2020 static int 2030 2021 HeightMapLineContourOp(ClientData cdata, Tcl_Interp *interp, int objc, 2031 Tcl_Obj *CONST*objv)2022 Tcl_Obj *const *objv) 2032 2023 { 2033 2024 Tcl_ObjCmdProc *proc; 2034 2025 2035 2026 proc = Rappture::GetOpFromObj(interp, nHeightMapLineContourOps, 2036 2027 heightMapLineContourOps, Rappture::CMDSPEC_ARG2, objc, objv, 0); 2037 2028 if (proc == NULL) { 2038 2029 return TCL_ERROR; … … 2043 2034 static int 2044 2035 HeightMapCullOp(ClientData cdata, Tcl_Interp *interp, int objc, 2045 Tcl_Obj *CONST*objv)2036 Tcl_Obj *const *objv) 2046 2037 { 2047 2038 graphics::RenderContext::CullMode mode; … … 2055 2046 static int 2056 2047 HeightMapCreateOp(ClientData cdata, Tcl_Interp *interp, int objc, 2057 Tcl_Obj * CONST*objv)2048 Tcl_Obj *const *objv) 2058 2049 { 2059 2050 HeightMap *hmPtr; … … 2071 2062 static int 2072 2063 HeightMapLegendOp(ClientData cdata, Tcl_Interp *interp, int objc, 2073 Tcl_Obj * CONST*objv)2064 Tcl_Obj *const *objv) 2074 2065 { 2075 2066 HeightMap *hmPtr; … … 2081 2072 if (tf == NULL) { 2082 2073 Tcl_AppendResult(interp, "no transfer function defined for heightmap \"", 2083 2074 Tcl_GetString(objv[2]), "\"", (char*)NULL); 2084 2075 return TCL_ERROR; 2085 2076 } … … 2090 2081 } 2091 2082 if (HeightMap::update_pending) { 2092 2083 NanoVis::SetHeightmapRanges(); 2093 2084 } 2094 2085 NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h, 2095 2086 "label"); 2096 2087 return TCL_OK; 2097 2088 } … … 2099 2090 static int 2100 2091 HeightMapPolygonOp(ClientData cdata, Tcl_Interp *interp, int objc, 2101 Tcl_Obj * CONST*objv)2092 Tcl_Obj *const *objv) 2102 2093 { 2103 2094 graphics::RenderContext::PolygonMode mode; … … 2111 2102 static int 2112 2103 HeightMapShadingOp(ClientData cdata, Tcl_Interp *interp, int objc, 2113 Tcl_Obj *CONST*objv)2104 Tcl_Obj *const *objv) 2114 2105 { 2115 2106 graphics::RenderContext::ShadingModel model; … … 2123 2114 static int 2124 2115 HeightMapTestOp(ClientData cdata, Tcl_Interp *interp, int objc, 2125 Tcl_Obj *CONST*objv)2116 Tcl_Obj *const *objv) 2126 2117 { 2127 2118 srand((unsigned)time(NULL)); … … 2155 2146 static int 2156 2147 HeightMapTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc, 2157 Tcl_Obj * CONST*objv)2158 { 2159 c har *name;2148 Tcl_Obj *const *objv) 2149 { 2150 const char *name; 2160 2151 name = Tcl_GetString(objv[2]); 2161 2152 TransferFunction *tf; … … 2172 2163 vector<HeightMap *>::iterator iter; 2173 2164 for (iter = imap.begin(); iter != imap.end(); iter++) { 2174 2165 (*iter)->setColorMap(tf); 2175 2166 } 2176 2167 return TCL_OK; … … 2192 2183 2193 2184 static int 2194 HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)2185 HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2195 2186 { 2196 2187 Tcl_ObjCmdProc *proc; 2197 2188 2198 2189 proc = Rappture::GetOpFromObj(interp, nHeightMapOps, heightMapOps, 2199 2190 Rappture::CMDSPEC_ARG1, objc, objv, 0); 2200 2191 if (proc == NULL) { 2201 2192 return TCL_ERROR; … … 2206 2197 static int 2207 2198 GridAxisColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 2208 Tcl_Obj * CONST*objv)2199 Tcl_Obj *const *objv) 2209 2200 { 2210 2201 float r, g, b, a; … … 2226 2217 static int 2227 2218 GridAxisNameOp(ClientData cdata, Tcl_Interp *interp, int objc, 2228 Tcl_Obj *CONST *objv) 2229 { 2230 int axisId; 2231 if (GetAxisFromObj(interp, objv[2], &axisId) != TCL_OK) { 2232 return TCL_ERROR; 2233 } 2234 if (NanoVis::grid) { 2235 #ifdef notdef 2236 NanoVis::grid->setAxisName(axisId, Tcl_GetString(objv[3])); 2237 #endif 2219 Tcl_Obj *const *objv) 2220 { 2221 int axis; 2222 if (GetAxisFromObj(interp, objv[2], &axis) != TCL_OK) { 2223 return TCL_ERROR; 2224 } 2225 if (NanoVis::grid != NULL) { 2226 Axis *axisPtr; 2227 2228 switch (axis) { 2229 case 0: axisPtr = &NanoVis::grid->xAxis; break; 2230 case 1: axisPtr = &NanoVis::grid->yAxis; break; 2231 case 2: axisPtr = &NanoVis::grid->zAxis; break; 2232 } 2233 axisPtr->SetName(Tcl_GetString(objv[3])); 2234 axisPtr->SetUnits(Tcl_GetString(objv[4])); 2238 2235 } 2239 2236 return TCL_OK; … … 2242 2239 static int 2243 2240 GridLineColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 2244 Tcl_Obj * CONST*objv)2241 Tcl_Obj *const *objv) 2245 2242 { 2246 2243 float r, g, b, a; … … 2261 2258 2262 2259 static int 2263 GridVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)2260 GridVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2264 2261 { 2265 2262 bool visible; … … 2273 2270 static Rappture::CmdSpec gridOps[] = { 2274 2271 {"axiscolor", 5, GridAxisColorOp, 5, 6, "r g b ?a?",}, 2275 {"axisname", 5, GridAxisNameOp, 5, 5, "index width height",},2272 {"axisname", 5, GridAxisNameOp, 5, 5, "index title units",}, 2276 2273 {"linecolor", 7, GridLineColorOp, 5, 6, "r g b ?a?",}, 2277 2274 {"visible", 1, GridVisibleOp, 3, 3, "bool",}, … … 2280 2277 2281 2278 static int 2282 GridCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)2279 GridCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2283 2280 { 2284 2281 Tcl_ObjCmdProc *proc; 2285 2282 2286 2283 proc = Rappture::GetOpFromObj(interp, nGridOps, gridOps, 2287 2284 Rappture::CMDSPEC_ARG1, objc, objv, 0); 2288 2285 if (proc == NULL) { 2289 2286 return TCL_ERROR; … … 2293 2290 2294 2291 static int 2295 AxisCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)2292 AxisCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2296 2293 { 2297 2294 if (objc < 2) { 2298 2295 Tcl_AppendResult(interp, "wrong # args: should be \"", 2299 2300 return TCL_ERROR; 2301 } 2302 c har *string = Tcl_GetString(objv[1]);2296 Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL); 2297 return TCL_ERROR; 2298 } 2299 const char *string = Tcl_GetString(objv[1]); 2303 2300 char c = string[0]; 2304 2301 if ((c == 'v') && (strcmp(string, "visible") == 0)) { … … 2319 2316 #if PLANE_CMD 2320 2317 static int 2321 PlaneNewOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)2318 PlaneNewOp(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2322 2319 { 2323 2320 fprintf(stderr, "load plane for 2D visualization command\n"); … … 2325 2322 if (objc != 4) { 2326 2323 Tcl_AppendResult(interp, "wrong # args: should be \"", 2327 2324 Tcl_GetString(objv[0]), " plane_index w h \"", (char*)NULL); 2328 2325 return TCL_ERROR; 2329 2326 } … … 2338 2335 } 2339 2336 2340 //Now read w*h*4 bytes. The server expects the plane to be a stream of floats 2337 //Now read w*h*4 bytes. The server expects the plane to be a stream of 2338 //floats 2341 2339 char* tmp = new char[int(w*h*sizeof(float))]; 2342 2340 if (tmp == NULL) { … … 2358 2356 static int 2359 2357 PlaneLinkOp(ClientData cdata, Tcl_Interp *interp, int objc, 2360 Tcl_Obj *CONST*objv)2358 Tcl_Obj *const *objv) 2361 2359 { 2362 2360 fprintf(stderr, "link the plane to the 2D renderer command\n"); … … 2366 2364 if (objc != 3) { 2367 2365 Tcl_AppendResult(interp, "wrong # args: should be \"", 2368 2366 Tcl_GetString(objv[0]), " plane_index tf_index \"", (char*)NULL); 2369 2367 return TCL_ERROR; 2370 2368 } … … 2383 2381 static int 2384 2382 PlaneEnableOp(ClientData cdata, Tcl_Interp *interp, int objc, 2385 Tcl_Obj *CONST*objv)2383 Tcl_Obj *const *objv) 2386 2384 { 2387 2385 fprintf(stderr,"enable a plane so the 2D renderer can render it command\n"); … … 2389 2387 if (objc != 3) { 2390 2388 Tcl_AppendResult(interp, "wrong # args: should be \"", 2391 2389 Tcl_GetString(objv[0]), " plane_index mode \"", (char*)NULL); 2392 2390 return TCL_ERROR; 2393 2391 } … … 2415 2413 2416 2414 static int 2417 PlaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST*objv)2415 PlaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2418 2416 { 2419 2417 Tcl_ObjCmdProc *proc; 2420 2418 2421 2419 proc = Rappture::GetOpFromObj(interp, nPlaneOps, planeOps, 2422 2420 Rappture::CMDSPEC_ARG1, objc, objv, 0); 2423 2421 if (proc == NULL) { 2424 2422 return TCL_ERROR; … … 2441 2439 */ 2442 2440 static int 2443 UniRect2dCmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv) 2441 UniRect2dCmd(ClientData clientData, Tcl_Interp *interp, int objc, 2442 Tcl_Obj *const *objv) 2444 2443 { 2445 2444 int xNum, yNum, zNum; … … 2449 2448 if ((objc & 0x01) == 0) { 2450 2449 Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ", 2451 2452 2450 "wrong number of arguments: should be key-value pairs", 2451 (char *)NULL); 2453 2452 return TCL_ERROR; 2454 2453 } … … 2458 2457 int i; 2459 2458 for (i = 1; i < objc; i += 2) { 2460 c har *string;2459 const char *string; 2461 2460 2462 2461 string = Tcl_GetString(objv[i]); … … 2510 2509 } else { 2511 2510 Tcl_AppendResult(interp, "unknown key \"", string, 2512 2513 2511 "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues", 2512 (char *)NULL); 2514 2513 return TCL_ERROR; 2515 2514 } … … 2521 2520 if (zNum != (xNum * yNum)) { 2522 2521 Tcl_AppendResult(interp, "wrong number of z values must be xnum*ynum", 2523 2522 (char *)NULL); 2524 2523 return TCL_ERROR; 2525 2524 } … … 2559 2558 Tcl_CreateObjCommand(interp, "legend", LegendCmd, NULL, NULL); 2560 2559 Tcl_CreateObjCommand(interp, "screen", ScreenCmd, NULL, NULL); 2561 Tcl_CreateObjCommand(interp, "s creenshot", ScreenShotCmd,NULL, NULL);2560 Tcl_CreateObjCommand(interp, "snapshot", SnapshotCmd, NULL, NULL); 2562 2561 Tcl_CreateObjCommand(interp, "transfunc", TransfuncCmd, NULL, NULL); 2563 2562 Tcl_CreateObjCommand(interp, "unirect2d", UniRect2dCmd, NULL, NULL); … … 2632 2631 if (status != TCL_OK) { 2633 2632 std::ostringstream errmsg; 2634 errmsg << " ERROR: " << Tcl_GetStringResult(interp) << std::endl;2633 errmsg << "NanoVis Server Error: " << Tcl_GetStringResult(interp) << std::endl; 2635 2634 write(0, errmsg.str().c_str(), errmsg.str().size()); 2636 2635 return; … … 2677 2676 write(0, rle, rle_size); //unsigned byte 2678 2677 #else 2679 NanoVis:: bmp_write("nv>image -bytes");2678 NanoVis::ppm_write("nv>image -bytes"); 2680 2679 #endif 2681 2680 } -
trunk/packages/vizservers/nanovis/HeightMap.cpp
r1000 r1028 20 20 double HeightMap::valueMax = 1.0; 21 21 22 #define TOPCONTOUR 22 #define TOPCONTOUR 0 23 23 HeightMap::HeightMap() : 24 24 _vertexBufferObjectID(0), … … 150 150 } 151 151 152 #if defTOPCONTOUR152 #if TOPCONTOUR 153 153 if (_topContourVisible) { 154 154 glDisable(GL_BLEND); … … 303 303 _contour = lineFilter.create(0.0f, 1.0f, 10, heights, xCount, yCount); 304 304 305 #if defTOPCONTOUR305 #if TOPCONTOUR 306 306 ContourLineFilter topLineFilter; 307 307 topLineFilter.setHeightTop(true); … … 379 379 _contour = lineFilter.create(0.0f, 1.0f, 10, heightMap, xCount, yCount); 380 380 381 #if defTOPCONTOUR381 #if TOPCONTOUR 382 382 ContourLineFilter topLineFilter; 383 383 topLineFilter.setHeightTop(true); -
trunk/packages/vizservers/nanovis/Makefile.in
r951 r1028 128 128 TransferFunction.o \ 129 129 Util.o \ 130 Vector3.o \131 Vector4.o \132 130 Volume.o \ 133 131 VolumeInterpolator.o \ … … 267 265 PlaneRenderer.o: PlaneRenderer.cpp PlaneRenderer.h 268 266 Mat4x4.o: Mat4x4.cpp Mat4x4.h 269 Vector4.o: Vector4.cpp Vector4.h270 Vector3.o: Vector3.cpp Vector3.h271 267 Plane.o: Plane.cpp Plane.h 272 268 ConvexPolygon.o: ConvexPolygon.cpp ConvexPolygon.h -
trunk/packages/vizservers/nanovis/Mat4x4.cpp
r226 r1028 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 18 19 #include <assert.h> 19 20 20 Mat4x4::Mat4x4(){} 21 22 Mat4x4::Mat4x4(float *vals){ 23 int i; 24 for (i=0;i<16;i++) 25 m[i] = vals[i]; 21 Mat4x4::Mat4x4(float *vals) { 22 int i; 23 for (i=0;i<16;i++) 24 m[i] = vals[i]; 26 25 } 27 26 28 Mat4x4::~Mat4x4(){} 29 30 void Mat4x4::print(){ 31 fprintf(stderr, "\n%f %f %f %f\n", m[0], m[1], m[2], m[3]); 32 fprintf(stderr, "%f %f %f %f\n", m[4], m[5], m[6], m[7]); 33 fprintf(stderr, "%f %f %f %f\n", m[8], m[9], m[10], m[11]); 34 fprintf(stderr, "%f %f %f %f\n\n", m[12], m[13], m[14], m[15]); 27 void 28 Mat4x4::print(){ 29 fprintf(stderr, "\n%f %f %f %f\n", m[0], m[1], m[2], m[3]); 30 fprintf(stderr, "%f %f %f %f\n", m[4], m[5], m[6], m[7]); 31 fprintf(stderr, "%f %f %f %f\n", m[8], m[9], m[10], m[11]); 32 fprintf(stderr, "%f %f %f %f\n\n", m[12], m[13], m[14], m[15]); 35 33 } 36 34 37 Mat4x4 Mat4x4::inverse(){ 38 Mat4x4 p; 39 35 Mat4x4 36 Mat4x4::inverse(){ 37 Mat4x4 p; 38 40 39 float m00 = m[0], m01 = m[4], m02 = m[8], m03 = m[12]; 41 40 float m10 = m[1], m11 = m[5], m12 = m[9], m13 = m[13]; … … 105 104 p.m[15]= cof33 * inv0; 106 105 107 return p; 108 /* 109 Mat4x4 ret; 110 int i, j; 111 double dst[4][4]; 112 double tmp[12]; 113 114 // calculate pairs for first 8 mements (cofactors) 115 tmp[0] = m[10] * m[15]; 116 tmp[1] = m[11] * m[14]; 117 tmp[2] = m[9] * m[15]; 118 tmp[3] = m[11] * m[13]; 119 tmp[4] = m[9] * m[14]; 120 tmp[5] = m[10] * m[13]; 121 tmp[6] = m[8] * m[15]; 122 tmp[7] = m[11] * m[12]; 123 tmp[8] = m[8] * m[14]; 124 tmp[9] = m[10] * m[12]; 125 tmp[10] = m[8] * m[13]; 126 tmp[11] = m[9] * m[12]; 127 128 // calculate first 8 mements (cofactors) 129 dst[0][0] = tmp[0]*m[5] + tmp[3]*m[6] + tmp[4]*m[7]; 130 dst[0][0] -= tmp[1]*m[5] + tmp[2]*m[6] + tmp[5]*m[7]; 131 dst[0][1] = tmp[1]*m[4] + tmp[6]*m[6] + tmp[9]*m[7]; 132 dst[0][1]-= tmp[0]*m[4] + tmp[7]*m[6] + tmp[8]*m[7]; 133 dst[0][2] = tmp[2]*m[4] + tmp[7]*m[5] + tmp[10]*m[7]; 134 dst[0][2] -= tmp[3]*m[4] + tmp[6]*m[5] + tmp[11]*m[7]; 135 dst[0][3] = tmp[5]*m[4] + tmp[8]*m[5] + tmp[11]*m[6]; 136 dst[0][3] -= tmp[4]*m[4] + tmp[9]*m[5] + tmp[10]*m[6]; 137 dst[1][0] = tmp[1]*m[1] + tmp[2]*m[2] + tmp[5]*m[3]; 138 dst[1][0] -= tmp[0]*m[1] + tmp[3]*m[2] + tmp[4]*m[3]; 139 dst[1][1] = tmp[0]*m[0] + tmp[7]*m[2] + tmp[8]*m[3]; 140 dst[1][1] -= tmp[1]*m[0] + tmp[6]*m[2] + tmp[9]*m[3]; 141 dst[1][2] = tmp[3]*m[0] + tmp[6]*m[1] + tmp[11]*m[3]; 142 dst[1][2] -= tmp[2]*m[0] + tmp[7]*m[1] + tmp[10]*m[3]; 143 dst[1][3] = tmp[4]*m[0] + tmp[9]*m[1] + tmp[10]*m[2]; 144 dst[1][3] -= tmp[5]*m[0] + tmp[8]*m[1] + tmp[11]*m[2]; 145 146 // calculate pairs for second 8 mements (cofactors) 147 tmp[0] = m[2]*m[7]; 148 tmp[1] = m[3]*m[6]; 149 tmp[2] = m[1]*m[7]; 150 tmp[3] = m[3]*m[5]; 151 tmp[4] = m[1]*m[6]; 152 tmp[5] = m[2]*m[5]; 153 tmp[6] = m[0]*m[7]; 154 tmp[7] = m[3]*m[4]; 155 tmp[8] = m[0]*m[6]; 156 tmp[9] = m[2]*m[4]; 157 tmp[10] = m[0]*m[5]; 158 tmp[11] = m[1]*m[4]; 159 160 // calculate second 8 mements (cofactors) 161 dst[2][0] = tmp[0]*m[13] + tmp[3]*m[14] + tmp[4]*m[15]; 162 dst[2][0] -= tmp[1]*m[13] + tmp[2]*m[14] + tmp[5]*m[15]; 163 dst[2][1] = tmp[1]*m[12] + tmp[6]*m[14] + tmp[9]*m[15]; 164 dst[2][1] -= tmp[0]*m[12] + tmp[7]*m[14] + tmp[8]*m[15]; 165 dst[2][2] = tmp[2]*m[12] + tmp[7]*m[13] + tmp[10]*m[15]; 166 dst[2][2]-= tmp[3]*m[12] + tmp[6]*m[13] + tmp[11]*m[15]; 167 dst[2][3] = tmp[5]*m[12] + tmp[8]*m[13] + tmp[11]*m[14]; 168 dst[2][3]-= tmp[4]*m[12] + tmp[9]*m[13] + tmp[10]*m[14]; 169 dst[3][0] = tmp[2]*m[10] + tmp[5]*m[11] + tmp[1]*m[9]; 170 dst[3][0]-= tmp[4]*m[11] + tmp[0]*m[9] + tmp[3]*m[10]; 171 dst[3][1] = tmp[8]*m[11] + tmp[0]*m[8] + tmp[7]*m[10]; 172 dst[3][1]-= tmp[6]*m[10] + tmp[9]*m[11] + tmp[1]*m[8]; 173 dst[3][2] = tmp[6]*m[9] + tmp[11]*m[11] + tmp[3]*m[8]; 174 dst[3][2]-= tmp[10]*m[11] + tmp[2]*m[8] + tmp[7]*m[9]; 175 dst[3][3] = tmp[10]*m[10] + tmp[4]*m[8] + tmp[9]*m[9]; 176 dst[3][3]-= tmp[8]*m[9] + tmp[11]*m[10] + tmp[5]*m[8]; 177 178 // calculate determinant 179 double determinant=m[0]*dst[0][0]+m[1]*dst[0][1]+m[2]*dst[0][2]+m[3]*dst[0][3]; 180 181 assert(fabs(determinant) != 0.0); 182 183 // calculate matrix inverse 184 determinant = 1/determinant; 185 for(i = 0; i < 4; i++){ 186 for (j = 0; j < 4; j++){ 187 dst[i][j] *= determinant; 188 ret.m[i*4+j] = dst[i][j]; 189 } 190 } 191 192 return ret; 193 */ 106 return p; 194 107 } 195 108 196 Vector4 Mat4x4::multiply_row_vector(Vector4 v){ 197 Vector4 ret; 198 ret.x = m[0]*v.x + m[1]*v.y + m[2]*v.z + m[3]*v.w; 199 ret.y = m[4]*v.x + m[5]*v.y + m[6]*v.z + m[7]*v.w; 200 ret.z = m[8]*v.x + m[9]*v.y + m[10]*v.z + m[11]*v.w; 201 ret.w = m[12]*v.x + m[13]*v.y + m[14]*v.z + m[15]*v.w; 202 return ret; 109 Vector4 110 Mat4x4::multiply_row_vector(Vector4 v){ 111 Vector4 ret; 112 ret.x = (m[0] * v.x) + (m[1] * v.y) + (m[2] * v.z) + (m[3] * v.w); 113 ret.y = (m[4] * v.x) + (m[5] * v.y) + (m[6] * v.z) + (m[7] * v.w); 114 ret.z = (m[8] * v.x) + (m[9] * v.y) + (m[10] * v.z) + (m[11] * v.w); 115 ret.w = (m[12] * v.x) + (m[13] * v.y) + (m[14] * v.z) + (m[15] * v.w); 116 return ret; 203 117 } 204 118 205 Vector4 Mat4x4::transform(Vector4 vector){206 Vector4 ret; 207 ret.x = vector.x*m[0]+vector.y*m[4]+vector.z*m[8]+vector.w*m[12];208 ret.y = vector.x*m[1]+vector.y*m[5]+vector.z*m[9]+vector.w*m[13];209 ret.z = vector.x*m[2]+vector.y*m[6]+vector.z*m[10]+vector.w*m[14];210 ret.w = vector.x*m[3]+vector.y*m[7]+vector.z*m[11]+vector.w*m[15];211 212 119 Vector4 120 Mat4x4::transform(Vector4 v){ 121 Vector4 ret; 122 ret.x = v.x*m[0]+v.y*m[4]+v.z*m[8]+v.w*m[12]; 123 ret.y = v.x*m[1]+v.y*m[5]+v.z*m[9]+v.w*m[13]; 124 ret.z = v.x*m[2]+v.y*m[6]+v.z*m[10]+v.w*m[14]; 125 ret.w = v.x*m[3]+v.y*m[7]+v.z*m[11]+v.w*m[15]; 126 return ret; 213 127 } 214 128 215 Mat4x4 Mat4x4::operator *(Mat4x4 mat){ 216 Mat4x4 ret; 217 218 ret.m[0] = m[0]*mat.m[0]+m[1]*mat.m[4]+m[2]*mat.m[8]+m[3]*mat.m[12]; 219 ret.m[1] = m[0]*mat.m[1]+m[1]*mat.m[5]+m[2]*mat.m[9]+m[3]*mat.m[13]; 220 ret.m[2] = m[0]*mat.m[2]+m[1]*mat.m[6]+m[2]*mat.m[10]+m[3]*mat.m[14]; 221 ret.m[3] = m[0]*mat.m[3]+m[1]*mat.m[7]+m[2]*mat.m[11]+m[3]*mat.m[15]; 222 223 ret.m[4] = m[4]*mat.m[0]+m[5]*mat.m[4]+m[6]*mat.m[8]+m[7]*mat.m[12]; 224 ret.m[5] = m[4]*mat.m[1]+m[5]*mat.m[5]+m[6]*mat.m[9]+m[7]*mat.m[13]; 225 ret.m[6] = m[4]*mat.m[2]+m[5]*mat.m[6]+m[6]*mat.m[10]+m[7]*mat.m[14]; 226 ret.m[7] = m[4]*mat.m[3]+m[5]*mat.m[7]+m[6]*mat.m[11]+m[7]*mat.m[15]; 227 228 ret.m[8] = m[8]*mat.m[0]+m[9]*mat.m[4]+m[10]*mat.m[8]+m[11]*mat.m[12]; 229 ret.m[9] = m[8]*mat.m[1]+m[9]*mat.m[5]+m[10]*mat.m[9]+m[11]*mat.m[13]; 230 ret.m[10] = m[8]*mat.m[2]+m[9]*mat.m[6]+m[10]*mat.m[10]+m[11]*mat.m[14]; 231 ret.m[11] = m[8]*mat.m[3]+m[9]*mat.m[7]+m[10]*mat.m[11]+m[11]*mat.m[15]; 232 233 ret.m[12] = m[12]*mat.m[0]+m[13]*mat.m[4]+m[14]*mat.m[8]+m[15]*mat.m[12]; 234 ret.m[13] = m[12]*mat.m[1]+m[13]*mat.m[5]+m[14]*mat.m[9]+m[15]*mat.m[13]; 235 ret.m[14] = m[12]*mat.m[2]+m[13]*mat.m[6]+m[14]*mat.m[10]+m[15]*mat.m[14]; 236 ret.m[15] = m[12]*mat.m[3]+m[13]*mat.m[7]+m[14]*mat.m[11]+m[15]*mat.m[15]; 237 238 return ret; 129 Mat4x4 130 Mat4x4::operator *(Mat4x4 mat){ 131 Mat4x4 ret; 132 133 ret.m[0] = m[0]*mat.m[0]+m[1]*mat.m[4]+m[2]*mat.m[8]+m[3]*mat.m[12]; 134 ret.m[1] = m[0]*mat.m[1]+m[1]*mat.m[5]+m[2]*mat.m[9]+m[3]*mat.m[13]; 135 ret.m[2] = m[0]*mat.m[2]+m[1]*mat.m[6]+m[2]*mat.m[10]+m[3]*mat.m[14]; 136 ret.m[3] = m[0]*mat.m[3]+m[1]*mat.m[7]+m[2]*mat.m[11]+m[3]*mat.m[15]; 137 138 ret.m[4] = m[4]*mat.m[0]+m[5]*mat.m[4]+m[6]*mat.m[8]+m[7]*mat.m[12]; 139 ret.m[5] = m[4]*mat.m[1]+m[5]*mat.m[5]+m[6]*mat.m[9]+m[7]*mat.m[13]; 140 ret.m[6] = m[4]*mat.m[2]+m[5]*mat.m[6]+m[6]*mat.m[10]+m[7]*mat.m[14]; 141 ret.m[7] = m[4]*mat.m[3]+m[5]*mat.m[7]+m[6]*mat.m[11]+m[7]*mat.m[15]; 142 143 ret.m[8] = m[8]*mat.m[0]+m[9]*mat.m[4]+m[10]*mat.m[8]+m[11]*mat.m[12]; 144 ret.m[9] = m[8]*mat.m[1]+m[9]*mat.m[5]+m[10]*mat.m[9]+m[11]*mat.m[13]; 145 ret.m[10] = m[8]*mat.m[2]+m[9]*mat.m[6]+m[10]*mat.m[10]+m[11]*mat.m[14]; 146 ret.m[11] = m[8]*mat.m[3]+m[9]*mat.m[7]+m[10]*mat.m[11]+m[11]*mat.m[15]; 147 148 ret.m[12] = m[12]*mat.m[0]+m[13]*mat.m[4]+m[14]*mat.m[8]+m[15]*mat.m[12]; 149 ret.m[13] = m[12]*mat.m[1]+m[13]*mat.m[5]+m[14]*mat.m[9]+m[15]*mat.m[13]; 150 ret.m[14] = m[12]*mat.m[2]+m[13]*mat.m[6]+m[14]*mat.m[10]+m[15]*mat.m[14]; 151 ret.m[15] = m[12]*mat.m[3]+m[13]*mat.m[7]+m[14]*mat.m[11]+m[15]*mat.m[15]; 152 153 return ret; 239 154 } 240 155 241 Mat4x4 Mat4x4::transpose(){242 Mat4x4 ret; 243 for(int i=0; i<4; i++){ 244 for(int j=0; j<4; j++){245 ret.m[j+4*i] = this->m[i+4*j];246 }156 Mat4x4 157 Mat4x4::transpose(){ 158 Mat4x4 ret; 159 for(int i=0; i<4; i++){ 160 for(int j=0; j<4; j++){ 161 ret.m[j+4*i] = this->m[i+4*j]; 247 162 } 248 return ret; 163 } 164 return ret; 249 165 } 250 166 -
trunk/packages/vizservers/nanovis/Mat4x4.h
r226 r1028 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 20 21 class Mat4x4 21 22 { 22 23 23 24 public: 24 float m[16]; //row by row 25 Mat4x4(); 26 Mat4x4(float *vals); 27 ~Mat4x4(); 25 float m[16]; //row by row 26 Mat4x4() { 27 /*empty*/ 28 }; 29 Mat4x4(float *vals); 28 30 29 void print();30 Mat4x4 inverse();31 Mat4x4 transpose();32 33 34 31 void print(void); 32 Mat4x4 inverse(void); 33 Mat4x4 transpose(void); 34 Vector4 multiply_row_vector(Vector4 v); 35 Vector4 transform(Vector4 v); 36 Mat4x4 operator*(Mat4x4 op); 35 37 }; 36 38 -
trunk/packages/vizservers/nanovis/NvLIC.cpp
r984 r1028 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 23 24 #include <Trace.h> 24 25 25 NvLIC::NvLIC(int _size, int _width, int _height, float _offset, CGcontext _context) 26 : Renderable(Vector3(0.0f,0.0f,0.0f)), 26 NvLIC::NvLIC(int _size, int _width, int _height, float _offset, 27 CGcontext _context) : 28 Renderable(Vector3(0.0f,0.0f,0.0f)), 27 29 disListID(0), 28 29 30 30 width(_width), 31 height(_height), 32 size(_size), 31 33 scale(1.0f, 1.0f, 1.0f), 32 34 offset(_offset), 33 35 iframe(0), 34 35 36 37 36 Npat(64), 37 alpha((int) 0.12*255), 38 tmax(NPIX/(SCALE*NPN)), 39 dmax(SCALE/NPIX), 38 40 max(1.0f), 39 41 m_g_context(_context), 40 42 vectorFieldID((NVISid) 0), 41 43 _activate(false) … … 78 80 79 81 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 80 82 GL_TEXTURE_RECTANGLE_NV, slice_vector_tex, 0); 81 83 82 84 … … 149 151 150 152 for (i = 0; i < 256; i++) { 151 153 lut[i] = i < 127 ? 0 : 255; 152 154 } 153 155 for (i = 0; i < NPN; i++) { 154 155 phase[i][j] = rand() % 256;156 for (j = 0; j < NPN; j++) { 157 phase[i][j] = rand() >> 8; 156 158 } 157 159 } 158 160 for (k = 0; k < Npat; k++) { 159 t = k*256/Npat; 160 for (i = 0; i < NPN; i++) { 161 for (j = 0; j < NPN; j++) { 162 pat[i][j][0] = 163 pat[i][j][1] = 164 pat[i][j][2] = lut[(t + phase[i][j]) % 255]; 165 pat[i][j][3] = alpha; 166 } 167 } 168 glNewList(disListID + k, GL_COMPILE); 169 glBindTexture(GL_TEXTURE_2D, pattern_tex); 170 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, 171 GL_RGBA, GL_UNSIGNED_BYTE, pat); 172 glEndList(); 161 t = (k << 8) / Npat; 162 for (i = 0; i < NPN; i++) { 163 for (j = 0; j < NPN; j++) { 164 pat[i][j][0] = pat[i][j][1] = pat[i][j][2] = 165 lut[(t + phase[i][j]) % 255]; 166 pat[i][j][3] = alpha; 167 } 168 } 169 glNewList(disListID + k, GL_COMPILE); 170 glBindTexture(GL_TEXTURE_2D, pattern_tex); 171 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, GL_RGBA, 172 GL_UNSIGNED_BYTE, pat); 173 glEndList(); 173 174 } 174 175 175 176 glBindTexture(GL_TEXTURE_2D, pattern_tex); 176 177 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, 177 178 GL_RGBA, GL_UNSIGNED_BYTE, pat); 178 179 Trace("finish make_patterns\n"); 179 180 } … … 187 188 for(int i=0; i<NMESH; i++){ 188 189 for(int j=0; j<NMESH; j++){ 189 190 float x=DM*i; 191 float y=DM*j; 192 193 float magnitude = sqrt(x*x+y*y)/1.414; 194 195 //from green to red 196 GLubyte r = (GLubyte) floor(magnitude*255); 197 GLubyte g = 0; 198 GLubyte b = 255 - r; 199 GLubyte a = 122; 200 201 mag[i][j][0] = r; 202 mag[i][j][1] = g; 203 mag[i][j][2] = b; 204 mag[i][j][3] = a; 190 float x=DM*i; 191 float y=DM*j; 192 193 float magnitude = sqrt(x*x+y*y)/1.414; 194 195 //from green to red 196 GLubyte r = (GLubyte) floor(magnitude*255); 197 GLubyte g = 0; 198 GLubyte b = 255 - r; 199 GLubyte a = 122; 200 201 mag[i][j][0] = r; 202 mag[i][j][1] = g; 203 mag[i][j][2] = b; 204 mag[i][j][3] = a; 205 205 } 206 206 } … … 213 213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 214 214 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); 215 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NMESH, NMESH, 0, GL_RGBA, GL_UNSIGNED_BYTE, mag); 215 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NMESH, NMESH, 0, GL_RGBA, 216 GL_UNSIGNED_BYTE, mag); 216 217 glBindTexture(GL_TEXTURE_2D, 0); 217 218 } 218 219 219 void NvLIC::get_slice() 220 void 221 NvLIC::get_slice() 220 222 { 221 223 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); … … 242 244 243 245 glBegin(GL_QUADS); 246 { 244 247 glTexCoord3f(0., 0., offset); glVertex2f(0., 0.); 245 248 glTexCoord3f(1., 0., offset); glVertex2f(size, 0.); 246 249 glTexCoord3f(1., 1., offset); glVertex2f(size, size); 247 250 glTexCoord3f(0., 1., offset); glVertex2f(0., size); 251 } 248 252 glEnd(); 249 253 … … 261 265 int lim = size * size * 4; 262 266 float* v= slice_vector; 263 for (int i = 0; i < lim; ++i) 264 { 265 if (isnan(*v)) *v = 0.0f; 267 for (int i = 0; i < lim; ++i) { 268 if (isnan(*v)) { 269 *v = 0.0f; 270 } 266 271 ++v; 267 272 } … … 269 274 270 275 //line integral convolution 271 void NvLIC::convolve() 276 void 277 NvLIC::convolve() 272 278 { 273 279 int i, j; 274 280 float x1, x2, y, px, py; 275 281 276 282 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 277 283 278 284 glMatrixMode(GL_PROJECTION); 279 285 glLoadIdentity(); … … 283 289 //glScalef(2.0, 2.0, 1.0); 284 290 glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -10.0f, 10.0f); 285 291 286 292 glMatrixMode(GL_MODELVIEW); 287 293 glLoadIdentity(); 288 294 289 295 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 290 296 291 297 //sa = 0.010*cos(iframe*2.0*M_PI/200.0); 292 298 glEnable(GL_TEXTURE_2D); 293 299 glBindTexture(GL_TEXTURE_2D, pattern_tex); 294 300 sa = 0.01; 295 296 for (i = 0; i < NMESH-1; i++) 297 { 301 302 for (i = 0; i < NMESH-1; i++) { 298 303 x1 = DM*i; x2 = x1 + DM; 299 304 glBegin(GL_QUAD_STRIP); 300 305 for (j = 0; j < NMESH-1; j++) { 301 y = DM*j;302 glTexCoord2f(x1, y);303 get_velocity(x1, y, &px, &py);304 glVertex2f(px, py);305 306 glTexCoord2f(x2, y);307 get_velocity(x2, y, &px, &py);308 glVertex2f(px, py);306 y = DM*j; 307 glTexCoord2f(x1, y); 308 get_velocity(x1, y, &px, &py); 309 glVertex2f(px, py); 310 311 glTexCoord2f(x2, y); 312 get_velocity(x2, y, &px, &py); 313 glVertex2f(px, py); 309 314 } 310 315 glEnd(); 311 }312 iframe = iframe + 1;313 314 glEnable(GL_BLEND);315 316 } 317 iframe = iframe + 1; 318 319 glEnable(GL_BLEND); 320 316 321 // INSOO ADD 317 322 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 318 323 319 324 glEnable(GL_TEXTURE_2D); 320 glCallList(iframe % Npat + disListID); 321 glBegin(GL_QUAD_STRIP); 322 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); 323 glTexCoord2f(0.0, tmax); glVertex2f(0.0, 1.0); 324 glTexCoord2f(tmax, 0.0); glVertex2f(1.0, 0.0); 325 glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0); 326 glEnd(); 325 glCallList(iframe % Npat + disListID); 326 glBegin(GL_QUAD_STRIP); 327 { 328 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); 329 glTexCoord2f(0.0, tmax); glVertex2f(0.0, 1.0); 330 glTexCoord2f(tmax, 0.0); glVertex2f(1.0, 0.0); 331 glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0); 332 glEnd(); 333 } 327 334 glDisable(GL_TEXTURE_2D); 328 329 /*330 //inject dye331 glDisable(GL_TEXTURE_2D);332 glColor4f(1.,0.8,0.,1.);333 glBegin(GL_QUADS);334 335 336 337 338 glEnd();339 */340 335 336 /* 337 //inject dye 338 glDisable(GL_TEXTURE_2D); 339 glColor4f(1.,0.8,0.,1.); 340 glBegin(GL_QUADS); 341 glVertex2d(0.6, 0.6); 342 glVertex2d(0.6, 0.62); 343 glVertex2d(0.62, 0.62); 344 glVertex2d(0.62, 0.6); 345 glEnd(); 346 */ 347 341 348 /// INSOO ADDED 342 349 glDisable(GL_ALPHA_TEST); 343 344 glDisable(GL_BLEND); 345 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0); 346 347 /* 348 //blend magnitude texture 349 glBindTexture(GL_TEXTURE_2D, mag_tex); 350 glEnable(GL_TEXTURE_2D); 351 glEnable(GL_BLEND); 352 glBegin(GL_QUADS); 353 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); 354 glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.); 355 glTexCoord2f(1.0, 1.0); glVertex2f(1., 1.); 356 glTexCoord2f(1.0, 0.0); glVertex2f(1., 0.0); 357 glEnd(); 358 */ 359 360 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 361 350 351 glDisable(GL_BLEND); 352 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0); 353 354 /* 355 //blend magnitude texture 356 glBindTexture(GL_TEXTURE_2D, mag_tex); 357 glEnable(GL_TEXTURE_2D); 358 glEnable(GL_BLEND); 359 glBegin(GL_QUADS); 360 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); 361 glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.); 362 glTexCoord2f(1.0, 1.0); glVertex2f(1., 1.); 363 glTexCoord2f(1.0, 0.0); glVertex2f(1., 0.0); 364 glEnd(); 365 */ 366 367 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 362 368 glPopAttrib(); 363 364 369 glPopMatrix(); 365 370 glMatrixMode(GL_PROJECTION); … … 371 376 372 377 373 void NvLIC::display() 374 { 375 glBindTexture(GL_TEXTURE_2D, color_tex); 376 glEnable(GL_TEXTURE_2D); 377 378 //draw line integral convolution quad 379 glEnable(GL_DEPTH_TEST); 380 381 glPushMatrix(); 382 378 void 379 NvLIC::display() 380 { 381 glBindTexture(GL_TEXTURE_2D, color_tex); 382 glEnable(GL_TEXTURE_2D); 383 384 //draw line integral convolution quad 385 glEnable(GL_DEPTH_TEST); 386 387 glPushMatrix(); 388 383 389 //glScalef(scale.x, scale.y, scale.z); 384 390 float w = 1.0f / scale.x; 385 391 glScalef(1.0f, 1.0f / scale.y / w, 1.0f / scale.z / w); 386 387 glBegin(GL_QUADS); 388 glTexCoord2f(0, 0); glVertex3f(0, 0, offset); 389 glTexCoord2f(1, 0); glVertex3f(1, 0, offset); 390 glTexCoord2f(1, 1); glVertex3f(1, 1, offset); 391 glTexCoord2f(0, 1); glVertex3f(0, 1, offset); 392 glEnd(); 393 394 glPopMatrix(); 395 396 glBindTexture(GL_TEXTURE_2D,0); 397 398 glDisable(GL_DEPTH_TEST); 399 glDisable(GL_TEXTURE_2D); 400 401 } 392 393 glBegin(GL_QUADS); 394 { 395 glTexCoord2f(0, 0); glVertex3f(0, 0, offset); 396 glTexCoord2f(1, 0); glVertex3f(1, 0, offset); 397 glTexCoord2f(1, 1); glVertex3f(1, 1, offset); 398 glTexCoord2f(0, 1); glVertex3f(0, 1, offset); 399 } 400 glEnd(); 401 402 glPopMatrix(); 403 404 glBindTexture(GL_TEXTURE_2D,0); 405 406 glDisable(GL_DEPTH_TEST); 407 glDisable(GL_TEXTURE_2D); 408 } 409 402 410 /* 403 411 { … … 433 441 434 442 435 void NvLIC::setVectorField(unsigned int texID, float scaleX, float scaleY, float scaleZ, float max) 443 void 444 NvLIC::setVectorField(unsigned int texID, float scaleX, float scaleY, 445 float scaleZ, float max) 436 446 { 437 447 Trace("NvLIC: vector field is assigned [%d]\n", texID); … … 443 453 } 444 454 445 void NvLIC::get_velocity(float x, float y, float *px, float *py) 455 void 456 NvLIC::get_velocity(float x, float y, float *px, float *py) 446 457 { 447 458 float vx, vy, r; … … 456 467 457 468 //Trace("(vx vx) = (%f %f), r=%f, ", vx, vy, r); 458 if (r > dmax*dmax) {469 if (r > (dmax*dmax)) { 459 470 r = sqrt(r); 460 471 vx *= dmax/r; … … 468 479 } 469 480 470 void NvLIC::set_offset(float v) 471 { 472 offset = v; 473 get_slice(); 474 } 481 void 482 NvLIC::set_offset(float v) 483 { 484 offset = v; 485 get_slice(); 486 } -
trunk/packages/vizservers/nanovis/NvParticleRenderer.cpp
r851 r1028 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 27 28 28 29 NvParticleRenderer::NvParticleRenderer(int w, int h, CGcontext context) 29 : scale(1, 1, 1), _activate(false)30 { 31 psys_width = w;32 psys_height = h;33 34 psys_frame = 0;35 reborn = true;36 flip = true;37 max_life = 500;38 39 data = (Particle*) malloc(w*h*sizeof(Particle));40 41 m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT);42 43 assert(glGetError()==0);44 45 glGenFramebuffersEXT(2, psys_fbo);46 glGenTextures(2, psys_tex);47 48 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);49 50 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);51 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);52 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);53 54 #ifdef NV_32 55 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);56 #else 57 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);58 #endif 59 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[0], 0);60 61 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);62 63 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);64 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);65 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);66 #ifdef NV_32 67 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);68 #else 69 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);70 #endif 71 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[1], 0);72 73 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);74 75 CHECK_FRAMEBUFFER_STATUS();76 77 //load related shaders78 /*79 m_g_context = context;80 81 R2string path = R2FilePath::getInstance()->getPath("update_pos.cg");82 m_pos_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, path);83 m_pos_timestep_param = cgGetNamedParameter(m_pos_fprog, "timestep");84 m_vel_tex_param = cgGetNamedParameter(m_pos_fprog, "vel_tex");85 m_pos_tex_param = cgGetNamedParameter(m_pos_fprog, "pos_tex");86 m_scale_param = cgGetNamedParameter(m_pos_fprog, "scale");87 cgGLSetTextureParameter(m_vel_tex_param, volume);88 cgGLSetParameter3f(m_scale_param, scale_x, scale_y, scale_z);89 */90 91 _advectionShader = new NvParticleAdvectionShader();30 : scale(1, 1, 1), _activate(false) 31 { 32 psys_width = w; 33 psys_height = h; 34 35 psys_frame = 0; 36 reborn = true; 37 flip = true; 38 max_life = 500; 39 40 data = (Particle*) malloc(w*h*sizeof(Particle)); 41 42 m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT); 43 44 assert(glGetError()==0); 45 46 glGenFramebuffersEXT(2, psys_fbo); 47 glGenTextures(2, psys_tex); 48 49 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]); 50 51 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 52 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 53 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 54 55 #ifdef NV_32 56 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL); 57 #else 58 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL); 59 #endif 60 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[0], 0); 61 62 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]); 63 64 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]); 65 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 66 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 67 #ifdef NV_32 68 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL); 69 #else 70 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL); 71 #endif 72 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[1], 0); 73 74 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 75 76 CHECK_FRAMEBUFFER_STATUS(); 77 78 //load related shaders 79 /* 80 m_g_context = context; 81 82 R2string path = R2FilePath::getInstance()->getPath("update_pos.cg"); 83 m_pos_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, path); 84 m_pos_timestep_param = cgGetNamedParameter(m_pos_fprog, "timestep"); 85 m_vel_tex_param = cgGetNamedParameter(m_pos_fprog, "vel_tex"); 86 m_pos_tex_param = cgGetNamedParameter(m_pos_fprog, "pos_tex"); 87 m_scale_param = cgGetNamedParameter(m_pos_fprog, "scale"); 88 cgGLSetTextureParameter(m_vel_tex_param, volume); 89 cgGLSetParameter3f(m_scale_param, scale_x, scale_y, scale_z); 90 */ 91 92 _advectionShader = new NvParticleAdvectionShader(); 92 93 93 94 } … … 135 136 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)data);# 136 137 #endif 137 glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);138 glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0); 138 139 139 140 flip = true; … … 151 152 152 153 if (flip) 153 {154 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);155 glEnable(GL_TEXTURE_RECTANGLE_NV);156 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);157 158 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);159 //glClear(GL_COLOR_BUFFER_BIT);160 161 glViewport(0, 0, psys_width, psys_height);162 glMatrixMode(GL_PROJECTION);163 glLoadIdentity();164 //gluOrtho2D(0, psys_width, 0, psys_height);165 glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f);166 glMatrixMode(GL_MODELVIEW);167 glLoadIdentity();168 169 _advectionShader->bind(psys_tex[0]);154 { 155 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]); 156 glEnable(GL_TEXTURE_RECTANGLE_NV); 157 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 158 159 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 160 //glClear(GL_COLOR_BUFFER_BIT); 161 162 glViewport(0, 0, psys_width, psys_height); 163 glMatrixMode(GL_PROJECTION); 164 glLoadIdentity(); 165 //gluOrtho2D(0, psys_width, 0, psys_height); 166 glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f); 167 glMatrixMode(GL_MODELVIEW); 168 glLoadIdentity(); 169 170 _advectionShader->bind(psys_tex[0]); 170 171 171 //cgGLBindProgram(m_pos_fprog);172 //cgGLSetParameter1f(m_pos_timestep_param, 0.05);173 //cgGLEnableTextureParameter(m_vel_tex_param);174 //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[0]);175 //cgGLEnableTextureParameter(m_pos_tex_param);176 //cgGLEnableProfile(CG_PROFILE_FP30);172 //cgGLBindProgram(m_pos_fprog); 173 //cgGLSetParameter1f(m_pos_timestep_param, 0.05); 174 //cgGLEnableTextureParameter(m_vel_tex_param); 175 //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[0]); 176 //cgGLEnableTextureParameter(m_pos_tex_param); 177 //cgGLEnableProfile(CG_PROFILE_FP30); 177 178 178 draw_quad(psys_width, psys_height, psys_width, psys_height);179 180 //cgGLDisableProfile(CG_PROFILE_FP30);181 //cgGLDisableTextureParameter(m_vel_tex_param);182 //cgGLDisableTextureParameter(m_pos_tex_param);183 glDisable(GL_TEXTURE_RECTANGLE_NV);184 }185 else186 {187 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);188 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);189 190 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);191 //glClear(GL_COLOR_BUFFER_BIT);192 193 glViewport(0, 0, psys_width, psys_height);194 glMatrixMode(GL_PROJECTION);195 glLoadIdentity();196 //gluOrtho2D(0, psys_width, 0, psys_height);197 glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f);198 glMatrixMode(GL_MODELVIEW);199 glLoadIdentity();200 201 _advectionShader->bind(psys_tex[1]);202 203 //cgGLBindProgram(m_pos_fprog);204 //cgGLSetParameter1f(m_pos_timestep_param, 0.05);205 //cgGLEnableTextureParameter(m_vel_tex_param);206 //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]);207 //cgGLEnableTextureParameter(m_pos_tex_param);208 //cgGLEnableProfile(CG_PROFILE_FP30);209 210 draw_quad(psys_width, psys_height, psys_width, psys_height);211 //draw_quad(psys_width, psys_height, 1.0f, 1.0f);212 213 //cgGLDisableProfile(CG_PROFILE_FP30);214 //cgGLDisableTextureParameter(m_vel_tex_param);215 //cgGLDisableTextureParameter(m_pos_tex_param);216 }179 draw_quad(psys_width, psys_height, psys_width, psys_height); 180 181 //cgGLDisableProfile(CG_PROFILE_FP30); 182 //cgGLDisableTextureParameter(m_vel_tex_param); 183 //cgGLDisableTextureParameter(m_pos_tex_param); 184 glDisable(GL_TEXTURE_RECTANGLE_NV); 185 } 186 else 187 { 188 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]); 189 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]); 190 191 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 192 //glClear(GL_COLOR_BUFFER_BIT); 193 194 glViewport(0, 0, psys_width, psys_height); 195 glMatrixMode(GL_PROJECTION); 196 glLoadIdentity(); 197 //gluOrtho2D(0, psys_width, 0, psys_height); 198 glOrtho(0, psys_width, 0, psys_height, -10.0f, 10.0f); 199 glMatrixMode(GL_MODELVIEW); 200 glLoadIdentity(); 201 202 _advectionShader->bind(psys_tex[1]); 203 204 //cgGLBindProgram(m_pos_fprog); 205 //cgGLSetParameter1f(m_pos_timestep_param, 0.05); 206 //cgGLEnableTextureParameter(m_vel_tex_param); 207 //cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]); 208 //cgGLEnableTextureParameter(m_pos_tex_param); 209 //cgGLEnableProfile(CG_PROFILE_FP30); 210 211 draw_quad(psys_width, psys_height, psys_width, psys_height); 212 //draw_quad(psys_width, psys_height, 1.0f, 1.0f); 213 214 //cgGLDisableProfile(CG_PROFILE_FP30); 215 //cgGLDisableTextureParameter(m_vel_tex_param); 216 //cgGLDisableTextureParameter(m_pos_tex_param); 217 } 217 218 218 219 _advectionShader->unbind(); 219 220 220 //soft_read_verts();221 //soft_read_verts(); 221 222 222 update_vertex_buffer();223 update_vertex_buffer(); 223 224 224 225 flip = (!flip); … … 226 227 psys_frame++; 227 228 if(psys_frame==max_life) 228 {229 psys_frame=0;230 reborn = true;231 }229 { 230 psys_frame=0; 231 reborn = true; 232 } 232 233 233 234 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); … … 277 278 { 278 279 scale.set(scaleX, scaleY, scaleZ); 279 _advectionShader->setScale(scale);280 _advectionShader->setVelocityVolume(texID, max);281 } 280 _advectionShader->setScale(scale); 281 _advectionShader->setVelocityVolume(texID, max); 282 } -
trunk/packages/vizservers/nanovis/PCASplit.cpp
r846 r1028 1 1 2 #include <stdio.h> 2 3 #include "PCASplit.h" … … 15 16 namespace PCA { 16 17 17 PCASplit::PCASplit() 18 : _maxLevel(4), _minDistance(0.5f), _distanceScale(0.2f), _indexCount(0), _finalMaxLevel(0) 19 { 20 _indices = new unsigned int[MAX_INDEX]; 21 _memClusterChunk1 = new ClusterListNode[MAX_INDEX]; 22 _memClusterChunk2 = new ClusterListNode[MAX_INDEX]; 23 _curMemClusterChunk = _memClusterChunk1; 24 _memClusterChunkIndex = 0; 18 PCASplit::PCASplit() : 19 _maxLevel(4), 20 _minDistance(0.5f), 21 _distanceScale(0.2f), 22 _indexCount(0), 23 _finalMaxLevel(0) 24 { 25 _indices = new unsigned int[MAX_INDEX]; 26 _memClusterChunk1 = new ClusterListNode[MAX_INDEX]; 27 _memClusterChunk2 = new ClusterListNode[MAX_INDEX]; 28 _curMemClusterChunk = _memClusterChunk1; 29 _memClusterChunkIndex = 0; 25 30 } 26 31 27 32 PCASplit::~PCASplit() 28 33 { 29 delete [] _indices; 30 delete [] _memClusterChunk1; 31 delete [] _memClusterChunk2; 32 } 33 34 void PCASplit::computeCentroid(Point* data, int count, Vector3& mean/*, float& minValue, float& maxValue*/) 35 { 36 float sumx= 0, sumy = 0, sumz = 0; 37 float size = 0; 38 float sumsize = 0; 39 for (int i = 0; i < count; ++i) 40 { 41 size = data[i].size; 42 sumx += data[i].position.x * size; 43 sumy += data[i].position.y * size; 44 sumz += data[i].position.z * size; 45 sumsize += size; 46 } 47 48 sumsize = 1.0f / sumsize; 49 mean.set(sumx * sumsize, sumy * sumsize, sumz * sumsize); 50 } 51 52 void PCASplit::computeCovariant(Point* data, int count, const Vector3& mean, float* m) 53 { 54 memset(m, 0, sizeof(float) * 9); 55 56 for (int i = 0; i < count; ++i) 57 { 58 m[0] += (data[i].position.x - mean.x) * (data[i].position.x - mean.x); 59 m[1] += (data[i].position.x - mean.x) * (data[i].position.y - mean.y); 60 m[2] += (data[i].position.x - mean.x) * (data[i].position.z - mean.z); 61 m[4] += (data[i].position.y - mean.y) * (data[i].position.y - mean.y); 62 m[5] += (data[i].position.y - mean.y) * (data[i].position.z - mean.z); 63 m[8] += (data[i].position.z - mean.z) * (data[i].position.z - mean.z); 64 } 65 66 float invCount = 1.0f / (count - 1); 67 m[0] *= invCount; 68 m[1] *= invCount; 69 m[2] *= invCount; 70 m[4] *= invCount; 71 m[5] *= invCount; 72 m[8] *= invCount; 73 m[3] = m[1]; 74 m[6] = m[2]; 75 m[7] = m[5]; 76 } 77 78 void PCASplit::computeDistortion(Point* data, int count, const Vector3& mean, float& distortion, float& finalSize) 79 { 80 distortion = 0.0f; 81 finalSize = 0.0f; 82 83 float maxSize = 0.0f; 84 float distance; 85 for (int i = 0; i < count; ++i) 86 { 87 // sum 88 distance = mean.distanceSquare(data[i].position.x, data[i].position.y, data[i].position.z); 89 distortion += distance; 90 91 if (data[i].size > maxSize) 92 { 93 maxSize = data[i].size; 94 } 95 96 /* 97 finalSize += data[i].size * sqrt(distance); 98 */ 99 if (distance > finalSize) finalSize = distance; 100 } 101 102 // equation 2 103 //finalSize = 0.5f * sqrt (finalSize) / (float) (count - 1) + maxSize; 104 finalSize = sqrt (finalSize) + maxSize; 105 } 106 107 void PCASplit::init() 108 { 109 _curClusterNode = 0; 110 _curClusterCount = 0; 111 } 112 113 Cluster* PCASplit::createClusterBlock(ClusterListNode* clusterList, int count, int level) 114 { 115 static int cc = 0; 116 cc += count; 117 Cluster* clusterBlock = new Cluster[count]; 118 119 _clusterHeader->numOfClusters[level - 1] = count; 120 _clusterHeader->startPointerCluster[level - 1] = clusterBlock; 121 122 printf("Cluster created %d [in level %d]:total %d\n", count, level, cc); 34 delete [] _indices; 35 delete [] _memClusterChunk1; 36 delete [] _memClusterChunk2; 37 } 38 39 void 40 PCASplit::computeCentroid(Point* data, int count, Vector3& mean) 41 { 42 float sumx= 0, sumy = 0, sumz = 0; 43 float size = 0; 44 float sumsize = 0; 45 for (int i = 0; i < count; ++i) { 46 size = data[i].size; 47 sumx += data[i].position.x * size; 48 sumy += data[i].position.y * size; 49 sumz += data[i].position.z * size; 50 sumsize += size; 51 } 52 sumsize = 1.0f / sumsize; 53 mean.set(sumx * sumsize, sumy * sumsize, sumz * sumsize); 54 } 55 56 void 57 PCASplit::computeCovariant(Point* data, int count, const Vector3& mean, 58 float* m) 59 { 60 memset(m, 0, sizeof(float) * 9); 61 62 for (int i = 0; i < count; ++i) { 63 m[0] += (data[i].position.x - mean.x) * (data[i].position.x - mean.x); 64 m[1] += (data[i].position.x - mean.x) * (data[i].position.y - mean.y); 65 m[2] += (data[i].position.x - mean.x) * (data[i].position.z - mean.z); 66 m[4] += (data[i].position.y - mean.y) * (data[i].position.y - mean.y); 67 m[5] += (data[i].position.y - mean.y) * (data[i].position.z - mean.z); 68 m[8] += (data[i].position.z - mean.z) * (data[i].position.z - mean.z); 69 } 70 71 float invCount = 1.0f / (count - 1); 72 m[0] *= invCount; 73 m[1] *= invCount; 74 m[2] *= invCount; 75 m[4] *= invCount; 76 m[5] *= invCount; 77 m[8] *= invCount; 78 m[3] = m[1]; 79 m[6] = m[2]; 80 m[7] = m[5]; 81 } 82 83 void 84 PCASplit::computeDistortion(Point* data, int count, const Vector3& mean, 85 float& distortion, float& finalSize) 86 { 87 distortion = 0.0f; 88 finalSize = 0.0f; 89 90 float maxSize = 0.0f; 91 float distance; 92 for (int i = 0; i < count; ++i) { 93 // sum 94 distance = mean.distanceSquare(data[i].position.x, data[i].position.y, data[i].position.z); 95 distortion += distance; 96 97 if (data[i].size > maxSize) { 98 maxSize = data[i].size; 99 } 100 101 /* 102 finalSize += data[i].size * sqrt(distance); 103 */ 104 if (distance > finalSize) { 105 finalSize = distance; 106 } 107 } 108 // equation 2 109 //finalSize = 0.5f * sqrt (finalSize) / (float) (count - 1) + maxSize; 110 finalSize = sqrt (finalSize) + maxSize; 111 } 112 113 void 114 PCASplit::init() 115 { 116 _curClusterNode = 0; 117 _curClusterCount = 0; 118 } 119 120 Cluster* 121 PCASplit::createClusterBlock(ClusterListNode* clusterList, int count, int level) 122 { 123 static int cc = 0; 124 cc += count; 125 Cluster* clusterBlock = new Cluster[count]; 126 127 _clusterHeader->numOfClusters[level - 1] = count; 128 _clusterHeader->startPointerCluster[level - 1] = clusterBlock; 129 130 printf("Cluster created %d [in level %d]:total %d\n", count, level, cc); 123 131 fflush(stdout); 124 125 int i = 0; 126 ClusterListNode* clusterNode = clusterList; 127 while (clusterNode) 128 { 129 clusterBlock[i].centroid = clusterList->data->centroid_t; 130 clusterBlock[i].level = level; 131 clusterBlock[i].scale = clusterList->data->scale_t; 132 133 clusterNode = clusterNode->next; 134 ++i; 135 } 136 if (count != i) 137 { 138 printf("ERROR\n"); 139 } 140 return clusterBlock; 132 133 int i = 0; 134 ClusterListNode* clusterNode = clusterList; 135 while (clusterNode) { 136 clusterBlock[i].centroid = clusterList->data->centroid_t; 137 clusterBlock[i].level = level; 138 clusterBlock[i].scale = clusterList->data->scale_t; 139 140 clusterNode = clusterNode->next; 141 ++i; 142 } 143 if (count != i) { 144 printf("ERROR\n"); 145 } 146 return clusterBlock; 141 147 } 142 148 143 149 ClusterAccel* PCASplit::doIt(Point* data, int count) 144 150 { 145 init(); 146 147 _clusterHeader = new ClusterAccel(_maxLevel); 148 149 Cluster* root = new Cluster; 151 init(); 152 153 _clusterHeader = new ClusterAccel(_maxLevel); 154 155 Cluster* root = new Cluster; 156 Cluster_t* cluster_t = new Cluster_t(); 157 cluster_t->points_t = data; 158 cluster_t->numOfPoints_t = count; 159 root->level = 1; 160 161 _clusterHeader->root = root; 162 _clusterHeader->numOfClusters[0] = 1; 163 _clusterHeader->startPointerCluster[0] = root; 164 165 Vector3 mean; 166 float distortion, scale; 167 168 computeCentroid(cluster_t->points_t, cluster_t->numOfPoints_t, mean); 169 computeDistortion(cluster_t->points_t, cluster_t->numOfPoints_t, mean, 170 distortion, scale); 171 172 cluster_t->centroid_t = mean; 173 cluster_t->scale_t = scale; 174 175 float mindistance = _minDistance; 176 int level = 2; 177 178 ClusterListNode* clustNodeList = &(_memClusterChunk2[0]); 179 clustNodeList->data = cluster_t; 180 clustNodeList->next = 0; 181 182 _curRoot = root; 183 do { 184 analyze(clustNodeList, _curRoot, level, mindistance); 185 186 mindistance *= _distanceScale; 187 ++level; 188 189 // swap memory buffer & init 190 _curMemClusterChunk = (_curMemClusterChunk == _memClusterChunk1)? 191 _memClusterChunk2 : _memClusterChunk1; 192 _memClusterChunkIndex = 0; 193 194 clustNodeList = _curClusterNode; 195 196 } while (level <= _maxLevel); 197 198 return _clusterHeader; 199 } 200 201 void 202 PCASplit::addLeafCluster(Cluster_t* cluster) 203 { 204 ClusterListNode* clusterNode = 205 &_curMemClusterChunk[_memClusterChunkIndex++]; 206 clusterNode->data = cluster; 207 clusterNode->next = _curClusterNode; 208 _curClusterNode = clusterNode; 209 ++_curClusterCount; 210 } 211 212 void 213 PCASplit::split(Point* data, int count, float limit) 214 { 215 Vector3 mean; 216 float m[9]; 217 218 computeCentroid(data, count, mean); 219 float scale, distortion; 220 computeDistortion(data, count, mean, distortion, scale); 221 222 //if (distortion < limit) 223 if (scale < limit) { 150 224 Cluster_t* cluster_t = new Cluster_t(); 225 cluster_t->centroid_t = mean; 151 226 cluster_t->points_t = data; 152 227 cluster_t->numOfPoints_t = count; 153 root->level = 1;154 155 _clusterHeader->root = root;156 _clusterHeader->numOfClusters[0] = 1;157 _clusterHeader->startPointerCluster[0] = root;158 159 Vector3 mean;160 float distortion, scale;161 162 computeCentroid(cluster_t->points_t, cluster_t->numOfPoints_t, mean);163 computeDistortion(cluster_t->points_t, cluster_t->numOfPoints_t, mean, distortion, scale);164 165 cluster_t->centroid_t = mean;166 228 cluster_t->scale_t = scale; 167 168 float mindistance = _minDistance; 169 int level = 2; 170 171 ClusterListNode* clustNodeList = &(_memClusterChunk2[0]); 172 clustNodeList->data = cluster_t; 173 clustNodeList->next = 0; 174 175 _curRoot = root; 176 do { 177 analyze(clustNodeList, _curRoot, level, mindistance); 178 179 mindistance *= _distanceScale; 180 ++level; 181 182 // swap memory buffer & init 183 _curMemClusterChunk = (_curMemClusterChunk == _memClusterChunk1)? 184 _memClusterChunk2 : _memClusterChunk1; 185 _memClusterChunkIndex = 0; 186 187 clustNodeList = _curClusterNode; 188 189 } while (level <= _maxLevel); 190 191 return _clusterHeader; 192 } 193 194 void PCASplit::addLeafCluster(Cluster_t* cluster) 195 { 196 ClusterListNode* clusterNode = &_curMemClusterChunk[_memClusterChunkIndex++]; 197 clusterNode->data = cluster; 198 clusterNode->next = _curClusterNode; 199 _curClusterNode = clusterNode; 200 ++_curClusterCount; 201 } 202 203 void PCASplit::split(Point* data, int count, float limit) 204 { 205 Vector3 mean; 206 float m[9]; 207 208 computeCentroid(data, count, mean); 209 float scale, distortion; 210 computeDistortion(data, count, mean, distortion, scale); 211 212 //if (distortion < limit) 213 if (scale < limit) 214 { 215 Cluster_t* cluster_t = new Cluster_t(); 216 cluster_t->centroid_t = mean; 217 cluster_t->points_t = data; 218 cluster_t->numOfPoints_t = count; 219 cluster_t->scale_t = scale; 220 addLeafCluster(cluster_t); 221 return; 222 } 223 224 computeCovariant(data, count, mean, m); 225 226 SymmetricMatrix A(3); 227 for (int i = 1; i <= 3; ++i) 228 for (int j = 1; j <= i; ++j) 229 { 230 A(i, j) = m[(i - 1) * 3 + j - 1]; 229 addLeafCluster(cluster_t); 230 return; 231 } 232 233 computeCovariant(data, count, mean, m); 234 235 SymmetricMatrix A(3); 236 for (int i = 1; i <= 3; ++i) { 237 for (int j = 1; j <= i; ++j) { 238 A(i, j) = m[(i - 1) * 3 + j - 1]; 239 } 240 } 241 242 Matrix U; DiagonalMatrix D; 243 eigenvalues(A,D,U); 244 Vector3 emax(U(1, 3), U(2, 3), U(3, 3)); 245 246 int left = 0, right = count - 1; 247 248 Point p; 249 for (;left < right;) { 250 while (left < count && emax.dot(data[left].position - mean) >= 0.0f) { 251 ++left; 252 } 253 while (right >= 0 && emax.dot(data[right].position - mean) < 0.0f) { 254 --right; 255 } 256 if (left > right) { 257 break; 258 } 259 260 p = data[left]; 261 data[left] = data[right]; 262 data[right] = p; 263 ++left, --right; 264 265 } 266 267 if (left == 0 || right == count - 1) { 268 printf("error\n"); 269 exit(1); 270 } else { 271 split(data, left, limit); 272 split(data + left, count - left, limit); 273 } 274 } 275 276 void 277 PCASplit::analyze(ClusterListNode* clusterNode, Cluster* parent, int level, 278 float limit) 279 { 280 if (level > _maxLevel) { 281 return; 282 } 283 if (level > _finalMaxLevel) { 284 _finalMaxLevel = level; 285 } 286 287 init(); 288 289 ClusterListNode* clNode = clusterNode; 290 291 // initialize the indexCount of indices 292 _indexCount = 0; 293 while (clNode) { 294 if (clNode->data) { 295 split(clNode->data->points_t, clNode->data->numOfPoints_t, limit); 296 _indices[_indexCount++] = _curClusterCount; 297 } 298 clNode = clNode->next; 299 } 300 301 //Vector3 mean; 302 //computeCentroid(cluster->points, cluster->numOfPoints, mean); 303 304 // the process values of split are in _curClusterNode and _curClusterCount 305 ClusterListNode* curClusterNode = _curClusterNode; 306 unsigned int curClusterNodeCount = _curClusterCount; 307 308 if (curClusterNodeCount) { 309 310 // create and init centroid 311 Cluster* retClusterBlock = 312 createClusterBlock(curClusterNode, curClusterNodeCount, level); 313 314 _curRoot = retClusterBlock; 315 316 if (level == _maxLevel) { 317 ClusterListNode* node = curClusterNode; 318 if (_indexCount > 0) { 319 // for parent 320 Point* points = new Point[curClusterNodeCount]; 321 322 parent[0].setChildren(retClusterBlock, _indices[0]); 323 parent[0].setPoints(points, _indices[0]); 324 325 for (unsigned int i = 0, in = 0; i < curClusterNodeCount; ++i) { 326 if (i >= _indices[in]) { 327 in++; 328 parent[in].setChildren(retClusterBlock + _indices[in - 1], _indices[in] - _indices[in - 1]); 329 parent[in].setPoints(points + _indices[in - 1], _indices[in] - _indices[in - 1]); 330 } 331 332 retClusterBlock[i].scale = node->data->scale_t; 333 retClusterBlock[i].centroid = node->data->centroid_t; 334 retClusterBlock[i].points = node->data->points_t; 335 retClusterBlock[i].numOfPoints = node->data->numOfPoints_t; 336 retClusterBlock[i].color.set(float(rand()) / RAND_MAX, 337 float(rand()) / RAND_MAX, 338 float(rand()) / RAND_MAX, 339 0.2); 340 341 points[i].position = node->data->centroid_t; 342 points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f); 343 points[i].size = node->data->scale_t; 344 345 node = node->next; 231 346 } 232 233 234 Matrix U; DiagonalMatrix D; 235 eigenvalues(A,D,U); 236 Vector3 emax(U(1, 3), U(2, 3), U(3, 3)); 237 238 int left = 0, right = count - 1; 239 240 Point p; 241 for (;left < right;) 242 { 243 while (left < count && emax.dot(data[left].position - mean) >= 0.0f) ++left; 244 while (right >= 0 && emax.dot(data[right].position - mean) < 0.0f) --right; 347 } 348 } else { 349 Point* points = new Point[curClusterNodeCount]; 350 ClusterListNode* node = curClusterNode; 351 352 if (_indexCount > 0) { 353 parent[0].setPoints(points, _indices[0]); 354 parent[0].setChildren(retClusterBlock, _indices[0]); 355 for (int k = 1; k < _indexCount; ++k) { 356 parent[k].setPoints(points + _indices[k - 1], 357 _indices[k] - _indices[k - 1]); 358 parent[k].setChildren(retClusterBlock + _indices[k - 1], 359 _indices[k] - _indices[k - 1]); 360 } 361 362 // set points of sub-clusters 363 for (unsigned int i = 0; i < curClusterNodeCount; ++i) { 364 points[i].position = node->data->centroid_t; 365 points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f); 366 points[i].size = node->data->scale_t; 367 node = node->next; 368 } 245 369 246 if (left > right) break; 247 248 p = data[left]; 249 data[left] = data[right]; 250 data[right] = p; 251 ++left, --right; 252 253 } 254 255 if (left == 0 || right == count - 1) 256 { 257 printf("error\n"); 258 exit(1); 259 } 260 else 261 { 262 split(data, left, limit); 263 split(data + left, count - left, limit); 264 } 265 } 266 267 void PCASplit::analyze(ClusterListNode* clusterNode, Cluster* parent, int level, float limit) 268 { 269 fflush(stdout); 270 if (level > _maxLevel) return; 271 else if (level > _finalMaxLevel) _finalMaxLevel = level; 272 273 init(); 274 275 ClusterListNode* clNode = clusterNode; 276 277 // initialize the indexCount of indices 278 _indexCount = 0; 279 280 while (clNode) 281 { 282 if (clNode->data) 283 { 284 split(clNode->data->points_t, clNode->data->numOfPoints_t, limit); 285 _indices[_indexCount++] = _curClusterCount; 286 } 287 288 clNode = clNode->next; 289 } 290 291 //Vector3 mean; 292 //computeCentroid(cluster->points, cluster->numOfPoints, mean); 293 294 // the process values of split are in _curClusterNode and _curClusterCount 295 ClusterListNode* curClusterNode = _curClusterNode; 296 unsigned int curClusterNodeCount = _curClusterCount; 297 298 if (curClusterNodeCount) 299 { 300 301 // create and init centroid 302 Cluster* retClusterBlock = createClusterBlock(curClusterNode, curClusterNodeCount, level); 303 304 _curRoot = retClusterBlock; 305 306 if (level == _maxLevel) 307 { 308 ClusterListNode* node = curClusterNode; 309 if (_indexCount > 0) 310 { 311 // for parent 312 Point* points = new Point[curClusterNodeCount]; 313 314 parent[0].setChildren(retClusterBlock, _indices[0]); 315 parent[0].setPoints(points, _indices[0]); 316 317 for (unsigned int i = 0, in = 0; i < curClusterNodeCount; ++i) 318 { 319 if (i >= _indices[in]) 320 { 321 in++; 322 parent[in].setChildren(retClusterBlock + _indices[in - 1], _indices[in] - _indices[in - 1]); 323 parent[in].setPoints(points + _indices[in - 1], _indices[in] - _indices[in - 1]); 324 } 325 326 retClusterBlock[i].scale = node->data->scale_t; 327 retClusterBlock[i].centroid = node->data->centroid_t; 328 retClusterBlock[i].points = node->data->points_t; 329 retClusterBlock[i].numOfPoints = node->data->numOfPoints_t; 330 retClusterBlock[i].color.set( 331 float(rand()) / RAND_MAX, float(rand()) / RAND_MAX, float(rand()) / RAND_MAX, 332 0.2); 333 334 points[i].position = node->data->centroid_t; 335 points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f); 336 points[i].size = node->data->scale_t; 337 338 node = node->next; 339 340 //::glGenBuffers(1, &(cluster[i].vbo)); 341 //glBindBuffer(GL_ARRAY_BUFFER, cluster[i].vbo); 342 // glBufferData(GL_ARRAY_BUFFER, 343 // sizeof(Point) * cluster[i].numOfPoints, 344 // cluster[i].points, 345 // GL_STATIC_DRAW); 346 //glBindBuffer(GL_ARRAY_BUFFER, 0); 347 348 } 349 350 /* 351 ::glGenBuffers(1, &(_clusterHeader->_vbo[level - 1])); 352 ::glBindBuffer(GL_ARRAY_BUFFER, _clusterHeader->_vbo[level - 1]); 353 ::glBufferData(GL_ARRAY_BUFFER, 354 sizeof(Point) * curClusterNodeCount, 355 points, 356 GL_STATIC_DRAW); 357 ::glBindBuffer(GL_ARRAY_BUFFER, 0); 358 */ 359 } 360 361 362 363 } 364 else 365 { 366 Point* points = new Point[curClusterNodeCount]; 367 ClusterListNode* node = curClusterNode; 368 369 if (_indexCount > 0) 370 { 371 parent[0].setPoints(points, _indices[0]); 372 parent[0].setChildren(retClusterBlock, _indices[0]); 373 for (int k = 1; k < _indexCount; ++k) 374 { 375 parent[k].setPoints(points + _indices[k - 1], _indices[k] - _indices[k - 1]); 376 parent[k].setChildren(retClusterBlock + _indices[k - 1], _indices[k] - _indices[k - 1]); 377 } 378 379 // set points of sub-clusters 380 for (unsigned int i = 0; i < curClusterNodeCount; ++i) 381 { 382 points[i].position = node->data->centroid_t; 383 points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f); 384 points[i].size = node->data->scale_t; 385 node = node->next; 386 } 387 388 } 389 } 390 } 391 } 392 393 } 394 370 } 371 } 372 } 373 } 374 375 } /*namespace PCA */ 376 -
trunk/packages/vizservers/nanovis/PCASplit.h
r934 r1028 37 37 public : 38 38 39 Cluster() : color(1.0f, 1.0f, 1.0f, 1.0f), scale(0.0f), numOfChildren(0), numOfPoints(0), 40 points(0), children(0), vbo(0)/*, minValue(0.0f), maxValue(0.0f)*/ 41 , level(0) 39 Cluster() : 40 color(1.0f, 1.0f, 1.0f, 1.0f), 41 scale(0.0f), 42 numOfChildren(0), 43 numOfPoints(0), 44 points(0), 45 children(0), 46 vbo(0)/*, minValue(0.0f), maxValue(0.0f)*/ 47 , level(0) 42 48 { 43 49 } -
trunk/packages/vizservers/nanovis/Plane.cpp
r226 r1028 15 15 #include <assert.h> 16 16 #include "Plane.h" 17 18 Plane::Plane(){}19 17 20 18 Plane::Plane(float _a, float _b, float _c, float _d) { … … 36 34 } 37 35 38 void Plane::get_normal(Vector3 &normal){39 normal.x = a;40 normal.y = b;41 normal.z = c;42 }43 36 44 void Plane::get_point(Vector3 &point){ 45 if(a != 0){ 46 point.x = -d/a; 47 point.y = 0; 48 point.z = 0; 49 } 50 else if(b != 0){ 51 point.y = -d/b; 52 point.x = 0; 53 point.z = 0; 54 } 55 else if(c != 0){ 56 point.z = -d /c; 57 point.y = 0; 58 point.x = 0; 59 } 60 else{ 61 assert(false); 62 } 63 } 37 void 38 Plane::transform(Mat4x4 mat) { 39 Vector4 coeffs(a, b, c, d); 64 40 65 Vector4 Plane::get_coeffs(){ 66 Vector4 ret(a, b, c, d); 67 return ret; 68 } 69 70 void Plane::set_coeffs(float _a, float _b, float _c, float _d){ 71 a = _a; 72 b = _b; 73 c = _c; 74 d = _d; 75 } 76 77 void Plane::transform(Mat4x4 mat) { 78 Vector4 coeffs(a, b, c, d); 79 Mat4x4 inv = mat.inverse(); 80 Vector4 new_coeffs = inv.multiply_row_vector(coeffs); 81 41 Mat4x4 inv = mat.inverse(); 42 Vector4 new_coeffs = inv.multiply_row_vector(coeffs); 82 43 a = new_coeffs.x; 83 44 b = new_coeffs.y; … … 86 47 } 87 48 88 void Plane::transform(float *m){ 89 Mat4x4 mat(m); 90 transform(mat); 49 void 50 Plane::get_point(Vector3 &point){ 51 if (a != 0) { 52 point.x = -d/a; 53 point.y = 0; 54 point.z = 0; 55 } else if (b != 0) { 56 point.y = -d/b; 57 point.x = 0; 58 point.z = 0; 59 } else if (c != 0) { 60 point.z = -d /c; 61 point.y = 0; 62 point.x = 0; 63 } else{ 64 assert(false); 65 } 91 66 } 92 93 bool Plane::retains(Vector3 point){94 return (a * point.x + b * point.y + c * point.z + d >= 0);95 } -
trunk/packages/vizservers/nanovis/Plane.h
r415 r1028 20 20 21 21 class Plane { 22 float a, b, c, d; 22 23 public: 23 float a, b, c, d;24 24 25 25 Plane(float a, float b, float c, float d); 26 26 Plane(float coeffs[4]); 27 Plane(); 27 Plane(void) { 28 /*empty*/ 29 }; 28 30 29 void get_normal(Vector3 &normal);30 31 void get_point(Vector3 &point); 31 Vector4 get_coeffs();32 void set_coeffs(float _a, float _b, float _c, float _d);33 void transform(Mat4x4 mat);34 void transform(float *m);35 bool retains(Vector3 point);36 32 //bool clips(float point[3]) const { return !retains(point); } 37 33 34 void transform(Mat4x4 mat); 35 void transform(float *m) { 36 Mat4x4 mat(m); 37 transform(mat); 38 } 39 bool retains(Vector3 point) { 40 return ((a*point.x + b*point.y + c*point.z + d) >= 0); 41 } 42 Vector4 get_coeffs(void) { 43 return Vector4(a, b, c, d); 44 } 45 void set_coeffs(float a_val, float b_val, float c_val, float d_val) { 46 a = a_val, b = b_val, c = c_val, d = d_val; 47 } 48 void get_normal(Vector3 &normal) { 49 normal.x = a; 50 normal.y = b; 51 normal.z = c; 52 } 38 53 }; 39 54 -
trunk/packages/vizservers/nanovis/PointSet.cpp
r953 r1028 4 4 #include <stdio.h> 5 5 6 PointSet::PointSet() : 7 _sortLevel(4), 8 _cluster(0), 9 _max(1.0f), 10 _min(0.0f), 11 _visible(false) 12 { 13 /*empty*/ 14 } 15 16 PointSet::~PointSet() 17 { 18 if (_cluster) 19 { 20 delete _cluster; 21 } 22 } 23 24 void PointSet::initialize(Vector4* values, const unsigned int count, const Vector3& scale, const Vector3& origin, float min, float max) 6 void 7 PointSet::initialize(Vector4* values, const unsigned int count, 8 const Vector3& scale, const Vector3& origin, 9 float min, float max) 25 10 { 26 11 PCA::PCASplit pcaSplit; … … 32 17 33 18 PCA::Point* points = (PCA::Point*) malloc(sizeof(PCA::Point) * count); 34 for (unsigned int i = 0; i < count; ++i) 35 { 19 for (unsigned int i = 0; i < count; ++i) { 36 20 points[i].position.set(values[i].x, values[i].y, values[i].z); 37 21 points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f); … … 40 24 } 41 25 42 if (_cluster != 0) 43 { 26 if (_cluster != 0) { 44 27 delete _cluster; 45 28 } … … 49 32 } 50 33 51 void PointSet::updateColor(float* color, int colorCount) 34 void 35 PointSet::updateColor(float* color, int colorCount) 52 36 { 53 if (_cluster == 0) return; 54 37 if (_cluster == 0) { 38 return; 39 } 55 40 int level = 4; 56 41 57 58 59 60 61 62 42 PCA::Cluster* cluster = _cluster->startPointerCluster[level - 1]; 43 PCA::Cluster* c = &(cluster[0]); 44 PCA::Cluster* end = &(cluster[_cluster->numOfClusters[level - 1] - 1]); 45 46 Vector3 pos; 47 63 48 PCA::Point* points; 64 49 Vector4* colors = (Vector4*) color; 65 50 int numOfPoints; 66 51 int index; 67 52 float d = _max - _min; 68 for (; c <= end; c = (PCA::Cluster*) ((int) c + sizeof(PCA::Cluster))) 69 { 53 for (/*empty*/; c <= end; c = (PCA::Cluster*)((int)c+sizeof(PCA::Cluster))){ 70 54 points = c->points; 71 55 numOfPoints = c->numOfPoints; 72 73 for (int i = 0; i < numOfPoints; ++i) 74 { 56 57 for (int i = 0; i < numOfPoints; ++i) { 75 58 index = (points[i].value - _min) / d * (colorCount - 1); 76 if (index >= colorCount) index = colorCount - 1; 77 //printf("TEST %f %d/%d -> %d (%f %f %f)\n", points[i].value, i, numOfPoints, index, 78 // colors[index].x, colors[index].y, colors[index].z); 79 //fflush(stdout); 59 if (index >= colorCount) { 60 index = colorCount - 1; 61 } 80 62 points[i].color = colors[index]; 81 63 } 82 83 } 64 } 84 65 } 85 66 -
trunk/packages/vizservers/nanovis/PointSet.h
r953 r1028 17 17 bool _visible; 18 18 public : 19 PointSet(); 20 ~PointSet(); 19 void initialize(Vector4* values, const unsigned int count, 20 const Vector3& scale, const Vector3& origin, 21 float min, float max); 22 void updateColor(float* color, int count); 21 23 22 public : 23 void initialize(Vector4* values, const unsigned int count, const Vector3& scale, const Vector3& origin, float min, float max); 24 bool isVisible() const; 25 void setVisible(bool visible); 26 unsigned int getSortLevel()const; 27 PCA::ClusterAccel* getCluster(); 28 void updateColor(float* color, int count); 29 const Vector3& getScale() const; 30 Vector3& getScale(); 31 const Vector3& getOrigin() const; 32 Vector3& getOrigin(); 24 PointSet() : 25 _sortLevel(4), 26 _cluster(0), 27 _max(1.0f), 28 _min(0.0f), 29 _visible(false) 30 { 31 /*empty*/ 32 } 33 ~PointSet() { 34 if (_cluster) { 35 delete _cluster; 36 } 37 } 38 39 bool isVisible() const { 40 return _visible; 41 } 42 void setVisible(bool visible) { 43 _visible = visible; 44 } 45 unsigned int getSortLevel(void) const { 46 return _sortLevel; 47 } 48 PCA::ClusterAccel* getCluster(void) { 49 return _cluster; 50 } 51 Vector3& getScale(void) { 52 return _scale; 53 } 54 const Vector3& getScale(void) const { 55 return _scale; 56 } 57 Vector3& getOrigin(void) { 58 return _origin; 59 } 60 const Vector3& getOrigin(void) const { 61 return _origin; 62 } 33 63 }; 34 64 35 inline bool PointSet::isVisible() const 36 { 37 return _visible; 38 } 39 40 inline void PointSet::setVisible(bool visible) 41 { 42 _visible = visible; 43 } 44 45 inline unsigned int PointSet::getSortLevel()const 46 { 47 return _sortLevel; 48 } 49 50 inline PCA::ClusterAccel* PointSet::getCluster() 51 { 52 return _cluster; 53 } 54 55 inline Vector3& PointSet::getScale() 56 { 57 return _scale; 58 } 59 60 inline const Vector3& PointSet::getScale() const 61 { 62 return _scale; 63 } 64 65 inline Vector3& PointSet::getOrigin() 66 { 67 return _origin; 68 } 69 70 inline const Vector3& PointSet::getOrigin() const 71 { 72 return _origin; 73 } 74 75 #endif // 65 #endif /*__POINT_SET_H__*/ -
trunk/packages/vizservers/nanovis/RpDX.cpp
r973 r1028 22 22 using namespace Rappture; 23 23 24 DX::DX(const char* filename ) :24 DX::DX(const char* filename, Outcome *resultPtr) : 25 25 _dataMin(FLT_MAX), 26 26 _dataMax(-FLT_MAX), … … 47 47 48 48 if (filename == NULL) { 49 // error 49 resultPtr->AddError("filename is NULL"); 50 return; 50 51 } 51 52 // open the file with libdx … … 54 55 DXenable_locks(0); 55 56 _dxobj = DXImportDX((char*)filename,NULL,NULL,NULL,NULL); 57 if (_dxobj == NULL) { 58 resultPtr->AddError("can't import DX file \"%s\"", filename); 59 return; 60 } 56 61 57 62 fprintf(stdout, "dxobj=%x\n", (unsigned int)_dxobj); 58 63 fflush(stdout); 59 64 60 // parse out the positions array 61 // FIXME: nanowire will need a different way to parse out the positions array 62 // since it uses a productarray to store its positions. 63 // possibly use DXGetProductArray() 65 // parse out the positions array 66 67 // FIXME: nanowire will need a different way to parse out the positions 68 // array since it uses a productarray to store its positions. 69 // Possibly use DXGetProductArray(). 64 70 dxpos = (Array) DXGetComponentValue((Field) _dxobj, (char *)"positions"); 71 if (dxpos == NULL) { 72 resultPtr->AddError("can't get component value of \"positions\""); 73 return; 74 } 65 75 DXGetArrayInfo(dxpos, &_n, &type, &category, &_rank, &_shape); 66 76 67 77 fprintf(stdout, "_n = %d\n",_n); 68 78 if (type != TYPE_FLOAT) { 69 fprintf(stderr, "WARNING: positions is not type float (type=%d)\n", 70 type); 71 fflush(stderr); 79 resultPtr->AddError("\"positions\" is not type float (type=%d)\n", type); 80 return; 72 81 } 73 82 fprintf(stdout, "_rank = %d\n",_rank); … … 77 86 pos = (float*) DXGetArrayData(dxpos); 78 87 if (pos == NULL) { 79 fprintf(stdout, "DXGetArrayData failed to return positions array\n");80 fflush(stdout);88 resultPtr->AddError("DXGetArrayData failed to return positions array"); 89 return; 81 90 } 82 91 … … 85 94 if (DXQueryGridConnections(dxgrid, &_numAxis, NULL) == NULL) { 86 95 // raise error, data is not a regular grid and we cannot handle it 87 fprintf(stdout,"DX says our grid is not regular, we cannot handle this data\n");88 fflush(stdout);96 resultPtr->AddError("DX says our grid is not regular, we cannot handle this data"); 97 return; 89 98 } 90 99 … … 92 101 if (_positions == NULL) { 93 102 // malloc failed, raise error 94 fprintf(stdout,"malloc of _positions array failed");95 fflush(stdout);103 resultPtr->AddError("malloc of _positions array failed"); 104 return; 96 105 } 97 106 memcpy(_positions,pos,sizeof(float)*_n*_numAxis); … … 100 109 if (_axisLen == NULL) { 101 110 // malloc failed, raise error 102 fprintf(stdout,"malloc of _axisLen array failed");103 fflush(stdout);111 resultPtr->AddError("malloc of _axisLen array failed"); 112 return; 104 113 } 105 114 memset(_axisLen, 0, _numAxis); … … 107 116 _delta = new float[_numAxis*_numAxis]; 108 117 if (_delta == NULL) { 109 // malloc failed, raise error 110 fprintf(stdout, "malloc of _delta array failed"); 111 fflush(stdout); 118 resultPtr->AddError("malloc of _delta array failed"); 119 return; 112 120 } 113 121 memset(_delta, 0, _numAxis*_numAxis); … … 115 123 _origin = new float[_numAxis]; 116 124 if (_origin == NULL) { 117 // malloc failed, raise error 118 fprintf(stdout, "malloc of _origin array failed"); 119 fflush(stdout); 125 resultPtr->AddError("malloc of _origin array failed"); 126 return; 120 127 } 121 128 memset(_origin, 0, _numAxis); … … 123 130 _max = new float[_numAxis]; 124 131 if (_max == NULL) { 125 // malloc failed, raise error 126 fprintf(stdout, "malloc of _max array failed"); 127 fflush(stdout); 132 resultPtr->AddError("malloc of _max array failed"); 133 return; 128 134 } 129 135 memset(_max, 0, _numAxis); … … 148 154 _data = new float[_n]; 149 155 if (_data == NULL) { 150 // malloc failed, raise error 151 fprintf(stdout, "malloc of _data array failed"); 152 fflush(stdout); 156 resultPtr->AddError("malloc of _data array failed"); 157 return; 153 158 } 154 159 … … 167 172 } 168 173 default: 169 fprintf(stdout,"don't know how to handle data of type %d\n", type);170 fflush(stdout);174 resultPtr->AddError("don't know how to handle data of type %d\n", type); 175 return; 171 176 } 172 177 -
trunk/packages/vizservers/nanovis/RpDX.h
r956 r1028 19 19 // #include "rappture2.h" 20 20 #include <dx/dx.h> 21 #include <RpOutcome.h> 21 22 22 23 namespace Rappture { … … 25 26 public: 26 27 DX(); 27 DX(const char* filename );28 DX(const char* filename, RpOutcome *resultPtr); 28 29 DX(const DX& rpdx); 29 30 DX& operator=(const DX& rpdx); -
trunk/packages/vizservers/nanovis/Texture3D.cpp
r884 r1028 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 25 26 Texture3D::Texture3D(int width, int height, int depth, GLuint type=GL_FLOAT, GLuint interp=GL_LINEAR, int components=4) 26 27 { 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 28 assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT); 29 assert(interp == GL_LINEAR || interp == GL_NEAREST); 30 31 this->width = width; 32 this->height = height; 33 this->depth = depth; 34 35 //int m = (width > height) ? width : height; 36 //m = (m > depth) ? m : depth; 37 38 //int m = max(max(width, height), depth); 39 this->aspect_ratio_width = 1.; 40 this->aspect_ratio_height = (double)height/(double)width; 41 this->aspect_ratio_depth = (double)depth/(double)width; 42 43 //this->aspect_ratio_width = (double)width/(double)m; 44 //this->aspect_ratio_height = (double)height/(double)m; 45 //this->aspect_ratio_depth = (double)depth/(double)m; 46 47 this->type = type; 48 this->interp_type = interp; 49 this->n_components = components; 50 51 this->id = 0; 52 gl_resource_allocated = false; 52 53 } 53 54 54 55 void Texture3D::update(float* data) 55 56 { 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 57 //load texture with 16 bit half floating point precision if card is 6 series NV40 58 //half float with linear interpolation is only supported by 6 series and up cards 59 //If NV40 not defined, data is quantized to 8-bit from 32-bit. 60 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 61 62 glBindTexture(GL_TEXTURE_3D, id); 63 assert(id!=-1); 64 65 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 66 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 67 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 68 69 if(interp_type==GL_LINEAR){ 70 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 71 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 72 } 73 else{ 74 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 75 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 76 } 77 78 //to do: add handling to more formats 79 if(type==GL_FLOAT){ 80 switch(n_components){ 81 #ifdef NV40 82 case 1: 83 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data); 84 break; 85 case 2: 86 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 87 break; 88 case 3: 89 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data); 90 break; 91 case 4: 92 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data); 93 break; 94 #else 95 case 1: 96 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data); 97 break; 98 case 2: 99 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 100 break; 101 case 3: 102 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data); 103 break; 104 case 4: 105 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data); 106 break; 107 #endif 108 default: 109 break; 110 } 111 } 112 113 114 assert(glGetError()==0); 115 116 gl_resource_allocated = true; 116 117 117 118 } … … 119 120 GLuint Texture3D::initialize(float *data) 120 121 { 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 122 if (id != 0) glDeleteTextures(1, &id); 123 124 //load texture with 16 bit half floating point precision if card is 6 series NV40 125 //half float with linear interpolation is only supported by 6 series and up cards 126 //If NV40 not defined, data is quantized to 8-bit from 32-bit. 127 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 128 129 glGenTextures(1, &id); 130 glBindTexture(GL_TEXTURE_3D, id); 131 assert(id!=-1); 132 133 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 134 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 135 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 136 137 if(interp_type==GL_LINEAR){ 138 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 139 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 140 } 141 else{ 142 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 143 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 144 } 145 146 //to do: add handling to more formats 147 if(type==GL_FLOAT){ 148 switch(n_components){ 149 #ifdef NV40 150 case 1: 151 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE16F_ARB, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data); 152 break; 153 case 2: 154 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 155 break; 156 case 3: 157 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, width, height, depth, 0, GL_RGB, GL_FLOAT, data); 158 break; 159 case 4: 160 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, width, height, depth, 0, GL_RGBA, GL_FLOAT, data); 161 break; 162 #else 163 case 1: 164 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth, 0, GL_LUMINANCE, GL_FLOAT, data); 165 break; 166 case 2: 167 glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA, width, height, depth, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data); 168 break; 169 case 3: 170 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, width, height, depth, 0, GL_RGB, GL_FLOAT, data); 171 break; 172 case 4: 173 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, data); 174 break; 175 #endif 176 default: 177 break; 178 } 179 } 180 181 182 assert(glGetError()==0); 183 184 gl_resource_allocated = true; 185 return id; 185 186 } 186 187 187 188 void Texture3D::activate() 188 189 { 189 190 190 glEnable(GL_TEXTURE_3D); 191 glBindTexture(GL_TEXTURE_3D, id); 191 192 } 192 193 193 194 void Texture3D::deactivate() 194 195 { 195 glDisable(GL_TEXTURE_3D); 196 glDisable(GL_TEXTURE_3D); 196 197 } 197 198 198 199 Texture3D::~Texture3D() 199 200 { 200 201 glDeleteTextures(1, &id); 201 202 } 202 203 203 204 void Texture3D::check_max_size(){ 204 205 206 207 208 205 GLint max = 0; 206 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &max); 207 208 //printf("%d", glGetError()); 209 fprintf(stderr, "max 3d texture size: %d\n", max); 209 210 } 210 211 211 212 void Texture3D::check_max_unit(){ 212 213 214 215 216 } 213 int max; 214 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max); 215 216 fprintf(stderr, "max texture units: %d.\n", max); 217 } -
trunk/packages/vizservers/nanovis/Vector3.h
r911 r1028 16 16 #define _VECTOR3_H_ 17 17 18 class Mat4x4; 18 /* 19 * FIXME: The files that explicitly use the "rot*", "length", "distance", or 20 * "normalize" methods, should include the following headers. Don't do it 21 * here. 22 */ 23 #include <math.h> 24 #include "Mat4x4.h" 19 25 20 26 class Vector3{ 21 27 private: 28 float radians(float degree) const { 29 return (M_PI * degree) / 180.0; 30 } 22 31 public: 23 float x, y, z; 24 Vector3(float _x, float _y, float _z); 25 Vector3(); 26 27 Vector3 operator +(Vector3 &op2); 28 Vector3 operator -(Vector3 &op2); 29 Vector3 operator -(float scalar); 30 Vector3 operator +(float scalar); 31 bool equal(Vector3 &op2); 32 //float operator *(Vector3 &op2); //dot product 33 float operator *(Vector3 &op2); //dot product 34 Vector3 operator *(float op2); //mul per component 35 Vector3 operator /(float op2); //mul per component 36 void operator <(Vector3 &op2); //assign 37 Vector3 operator ^(Vector3 &op2); //cross product 38 Vector3 normalize(); 39 Vector3 rot_x(float degree); //rotation about x 40 Vector3 rot_y(float degree); //rotation about y 41 Vector3 rot_z(float degree); //rotation about z 42 void set(float newx, float newy, float newz); 43 void print(); 44 float distance(Vector3 &another) const; //compute distance 45 float distanceSquare(Vector3 &another) const; //compute distance 46 float distanceSquare(float vx, float vy, float vz) const; //compute distance 47 48 //fast version 49 Vector3 cross(Vector3 op2); 50 51 float dot(const Vector3& vec) const; 52 53 void transform(const Vector3& vec, const Mat4x4& mat); 54 float length() const; 32 float x, y, z; 33 Vector3(void) { 34 /*empty*/ 35 } 36 Vector3(float x_val, float y_val, float z_val) { 37 set(x_val, y_val, z_val); 38 } 39 Vector3 operator +(float scalar) { 40 return Vector3(x + scalar, y + scalar, z + scalar); 41 } 42 Vector3 operator -(float scalar) { 43 return Vector3(x - scalar, y - scalar, z - scalar); 44 } 45 Vector3 operator *(float scalar) { 46 return Vector3(x * scalar, y * scalar, z * scalar); 47 } 48 Vector3 operator /(float scalar) { 49 return Vector3(x / scalar, y / scalar, z / scalar); 50 } 51 Vector3 operator +(Vector3 &op2) { 52 return Vector3(x + op2.x, y + op2.y, z + op2.z); 53 } 54 Vector3 operator -(Vector3 &op2) { 55 return Vector3(x - op2.x, y - op2.y, z - op2.z); 56 } 57 float operator *(Vector3 &op2){ 58 return x*op2.x + y*op2.y + z*op2.z; 59 } 60 float dot(const Vector3& vec) const { 61 return x*vec.x + y*vec.y + z*vec.z; 62 } 63 bool equal(Vector3 &op2) { 64 return (x==op2.x) && (y==op2.y) && (z==op2.z); 65 } 66 Vector3 cross(Vector3 op2) { 67 return Vector3(y*op2.z - z*op2.y, z*op2.x - x*op2.z, x*op2.y - y*op2.x); 68 } 69 void operator<(Vector3 &op2) { 70 set(op2.x, op2.y, op2.z); 71 } 72 Vector3 operator ^(Vector3 &op2) { 73 return cross(op2); 74 } 75 Vector3 normalize(void) { 76 float len = length(); 77 return Vector3(x / len, y / len, z / len); 78 } 79 Vector3 rot_x(float degree) { 80 float rad = radians(degree); 81 return Vector3(x, 82 y*cos(rad) - z*sin(rad), 83 y*sin(rad) + z*cos(rad)); 84 } 85 Vector3 rot_y(float degree) { 86 float rad = radians(degree); 87 return Vector3(x*cos(rad) + z*sin(rad), 88 y, 89 -x*sin(rad) + z*cos(rad)); 90 } 91 Vector3 rot_z(float degree) { 92 float rad = radians(degree); 93 return Vector3(x*cos(rad) - y*sin(rad), 94 x*sin(rad) + y*cos(rad), 95 z); 96 } 97 void set(float x_val, float y_val, float z_val) { 98 x = x_val, y = y_val, z = z_val; 99 } 100 void print(void){ 101 fprintf(stderr, "x:%f, y:%f, z:%f\n", x, y, z); 102 } 103 float distance(Vector3 &v) const { 104 return sqrtf(distanceSquare(v)); 105 } 106 float distanceSquare(Vector3 &v) const { 107 return (x-v.x)*(x-v.x) + (y-v.y)*(y-v.y) + (z-v.z)*(z-v.z); 108 } 109 float distanceSquare(float vx, float vy, float vz) const { 110 return (x-vx)*(x-vx) + (y-vy)*(y-vy) + (z-vz)*(z-vz); 111 } 112 void transform(const Vector3& v, const Mat4x4& mat) { 113 const float* m = mat.m; 114 x = m[0] * v.x + m[4] * v.y + m[8] * v.z + m[12]; 115 y = m[1] * v.x + m[5] * v.y + m[9] * v.z + m[13]; 116 z = m[2] * v.x + m[6] * v.y + m[10] * v.z + m[14]; 117 } 118 float length(void) const { 119 return sqrt(x*x + y*y + z*z); 120 } 55 121 }; 56 122 57 inline Vector3 Vector3::operator +(float scalar)58 {59 Vector3 v;60 v.x = x + scalar;61 v.y = y + scalar;62 v.z = z + scalar;63 return v;64 }65 123 66 inline Vector3 Vector3::operator -(float scalar)67 {68 Vector3 v;69 v.x = x - scalar;70 v.y = y - scalar;71 v.z = z - scalar;72 return v;73 }74 124 #endif -
trunk/packages/vizservers/nanovis/Vector4.h
r819 r1028 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 16 17 #define _VECTOR4_H_ 17 18 19 #include <stdio.h> 20 18 21 class Vector4 19 22 { 20 23 public: 21 24 float x, y, z, w; 22 25 23 Vector4(); 24 Vector4(float _x, float _y, float _z, float _w); 25 ~Vector4(); 26 Vector4(void) { 27 /*empty*/ 28 } 29 Vector4(float x_val, float y_val, float z_val, float w_val) { 30 set(x_val, y_val, z_val, w_val); 31 } 32 void perspective_devide(void) { 33 /* Divide vector by w */ 34 x /= w, y /= w, z /= w, w = 1.; 35 } 26 36 27 void perspective_devide(); 28 void print(); 29 Vector4 operator +(Vector4 &op2); //plus 30 Vector4 operator -(Vector4 &op2); //minus 31 float operator *(Vector4 &op2); //dot product 32 Vector4 operator*(float op2); //mul per component 33 Vector4 operator/(float op2); //mul per component 34 void operator <(Vector4 &op2); //assign 37 void print(void) { 38 fprintf(stderr, "Vector4: (%.3f, %.3f, %.3f, %.3f)\n", x, y, z, w); 39 } 35 40 36 void set(float x1, float y1, float z1, float w1); 41 Vector4 operator +(Vector4 &op2){ 42 return Vector4(x + op2.x, y + op2.y, z + op2.z, w + op2.w); 43 } 44 45 Vector4 operator -(Vector4 &op2){ 46 return Vector4(x - op2.x, y - op2.y, z - op2.z, w - op2.w); 47 } 48 49 float operator *(Vector4 &op2) { 50 return (x * op2.x) + (y * op2.y) + (z * op2.z) + (w * op2.w); 51 } 52 53 Vector4 operator *(float op2){ 54 return Vector4(x * op2, y * op2, z * op2, w * op2); 55 } 56 57 Vector4 operator /(float op2) { 58 return Vector4(x / op2, y / op2, z / op2, w / op2); 59 } 60 61 void operator <(Vector4 &op2) { 62 set(op2.x, op2.y, op2.z, op2.w); 63 } 64 void set(float x_val, float y_val, float z_val, float w_val) { 65 x = x_val, y = y_val, z = z_val, w = w_val; 66 } 37 67 }; 38 68 -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r927 r1028 22 22 #include <sys/time.h> 23 23 #include "Trace.h" 24 24 #include "nanovis.h" 25 #include "Grid.h" 26 27 #define NUMDIGITS 6 25 28 26 29 VolumeRenderer::VolumeRenderer(): … … 242 245 model_view_trans_inverse = model_view_trans.inverse(); 243 246 244 //draw volume bounding box with translation (the correct location in space) 247 //draw volume bounding box with translation (the correct location in 248 //space) 245 249 if (cur_vol->outline_is_enabled()) { 246 250 float olcolor[3]; … … 484 488 485 489 //volume start location 486 Vector4 shift_4d(volume[volume_index]->location.x, volume[volume_index]->location.y, volume[volume_index]->location.z, 0); 490 Vector4 shift_4d(volume[volume_index]->location.x, 491 volume[volume_index]->location.y, 492 volume[volume_index]->location.z, 0); 487 493 488 494 double x0 = 0; … … 570 576 int axis = volume[volume_index]->get_cutplane(i)->orient; 571 577 572 if (axis==1){578 if (axis==1) { 573 579 vert1 = Vector4(-10, -10, offset, 1); 574 580 vert2 = Vector4(-10, +10, offset, 1); 575 581 vert3 = Vector4(+10, +10, offset, 1); 576 582 vert4 = Vector4(+10, -10, offset, 1); 577 } 578 else if(axis==2){ 583 } else if(axis==2){ 579 584 vert1 = Vector4(offset, -10, -10, 1); 580 585 vert2 = Vector4(offset, +10, -10, 1); 581 586 vert3 = Vector4(offset, +10, +10, 1); 582 587 vert4 = Vector4(offset, -10, +10, 1); 583 } 584 else if(axis==3){ 588 } else if(axis==3) { 585 589 vert1 = Vector4(-10, offset, -10, 1); 586 590 vert2 = Vector4(+10, offset, -10, 1); … … 692 696 } 693 697 694 void VolumeRenderer::draw_bounding_box(float x0, float y0, float z0, 695 float x1, float y1, float z1, 696 float r, float g, float b, float line_width) 698 void 699 VolumeRenderer::draw_bounding_box( 700 float x0, float y0, float z0, 701 float x1, float y1, float z1, 702 float r, float g, float b, 703 float line_width) 697 704 { 698 glDisable(GL_TEXTURE_2D); 699 700 glColor4d(r, g, b, 1.0); 701 glLineWidth(line_width); 705 glPushMatrix(); 706 glEnable(GL_DEPTH_TEST); 707 glDisable(GL_TEXTURE_2D); 708 glEnable(GL_BLEND); 709 710 glColor4d(r, g, b, 1.0); 711 glLineWidth(line_width); 712 713 glBegin(GL_LINE_LOOP); 714 { 715 glVertex3d(x0, y0, z0); 716 glVertex3d(x1, y0, z0); 717 glVertex3d(x1, y1, z0); 718 glVertex3d(x0, y1, z0); 719 } 720 glEnd(); 721 722 glBegin(GL_LINE_LOOP); 723 { 724 glVertex3d(x0, y0, z1); 725 glVertex3d(x1, y0, z1); 726 glVertex3d(x1, y1, z1); 727 glVertex3d(x0, y1, z1); 728 } 729 glEnd(); 730 731 732 glBegin(GL_LINE_LOOP); 733 { 734 glVertex3d(x0, y0, z0); 735 glVertex3d(x0, y0, z1); 736 glVertex3d(x0, y1, z1); 737 glVertex3d(x0, y1, z0); 738 } 739 glEnd(); 740 741 glBegin(GL_LINE_LOOP); 742 { 743 glVertex3d(x1, y0, z0); 744 glVertex3d(x1, y0, z1); 745 glVertex3d(x1, y1, z1); 746 glVertex3d(x1, y1, z0); 747 } 748 glEnd(); 749 750 #ifdef notdef 751 /* Rappture doesn't supply axis units yet. So turn labeling off until we 752 * can display the proper units with the distance of each bounding box 753 * dimension. 754 */ 755 glColor4f(1.0f, 1.0f, 0.0f, 1.0f); 756 757 if (NanoVis::fonts != NULL) { 758 double mv[16], prjm[16]; 759 int viewport[4]; 760 double wx, wy, wz; 761 double dx, dy, dz; 762 763 glGetDoublev(GL_MODELVIEW_MATRIX, mv); 764 glGetDoublev(GL_PROJECTION_MATRIX, prjm); 765 glGetIntegerv(GL_VIEWPORT, viewport); 702 766 703 glBegin(GL_LINE_LOOP); 704 705 glVertex3d(x0, y0, z0); 706 glVertex3d(x1, y0, z0); 707 glVertex3d(x1, y1, z0); 708 glVertex3d(x0, y1, z0); 709 710 glEnd(); 711 712 glBegin(GL_LINE_LOOP); 713 714 glVertex3d(x0, y0, z1); 715 glVertex3d(x1, y0, z1); 716 glVertex3d(x1, y1, z1); 717 glVertex3d(x0, y1, z1); 718 719 glEnd(); 720 721 722 glBegin(GL_LINE_LOOP); 723 724 glVertex3d(x0, y0, z0); 725 glVertex3d(x0, y0, z1); 726 glVertex3d(x0, y1, z1); 727 glVertex3d(x0, y1, z0); 728 729 glEnd(); 730 731 glBegin(GL_LINE_LOOP); 732 733 glVertex3d(x1, y0, z0); 734 glVertex3d(x1, y0, z1); 735 glVertex3d(x1, y1, z1); 736 glVertex3d(x1, y1, z0); 737 738 glEnd(); 739 740 glEnable(GL_TEXTURE_2D); 767 NanoVis::fonts->begin(); 768 dx = x1 - x0; 769 dy = y1 - y0; 770 dz = z1 - z0; 771 if (gluProject((x0 + x1) * 0.5, y0, z0, mv, prjm, viewport, 772 &wx, &wy, &wz)) { 773 char buff[20]; 774 double min, max; 775 776 NanoVis::grid->xAxis.GetDataLimits(min, max); 777 glLoadIdentity(); 778 glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f); 779 const char *units; 780 units = NanoVis::grid->xAxis.GetUnits(); 781 sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units); 782 NanoVis::fonts->draw(buff); 783 } 784 if (gluProject(x0, (y0 + y1) * 0.5, z0, mv, prjm, viewport, & 785 wx, &wy, &wz)) { 786 char buff[20]; 787 double min, max; 788 789 NanoVis::grid->yAxis.GetDataLimits(min, max); 790 glLoadIdentity(); 791 glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f); 792 const char *units; 793 units = NanoVis::grid->yAxis.GetUnits(); 794 sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units); 795 NanoVis::fonts->draw(buff); 796 } 797 if (gluProject(x0, y0, (z0 + z1) * 0.5, mv, prjm, viewport, 798 &wx, &wy, &wz)) { 799 glLoadIdentity(); 800 glTranslatef((int)wx, viewport[3] - (int) wy, 0.0f); 801 802 double min, max; 803 NanoVis::grid->zAxis.GetDataLimits(min, max); 804 const char *units; 805 units = NanoVis::grid->zAxis.GetUnits(); 806 char buff[20]; 807 sprintf(buff, "%.*g %s", NUMDIGITS, max - min, units); 808 NanoVis::fonts->draw(buff); 809 } 810 NanoVis::fonts->end(); 811 }; 812 #endif 813 glPopMatrix(); 814 glDisable(GL_DEPTH_TEST); 815 glDisable(GL_BLEND); 816 glEnable(GL_TEXTURE_2D); 741 817 } 742 818 … … 793 869 vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0; 794 870 795 for(int i=0;i<8;i++) 796 { 871 for(int i=0;i<8;i++) { 797 872 Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3])); 798 873 tmp.perspective_devide(); … … 834 909 835 910 /* make sure the file is there and open it read-only (binary) */ 836 if ((file = fopen(filename, "rb")) == NULL) 837 { 838 assert(false); 839 } 840 841 if(!fread(&bfType, sizeof(short int), 1, file)) 842 { 843 assert(false); 844 //printf("Error reading file!\n"); 911 if ((file = fopen(filename, "rb")) == NULL) { 912 fprintf(stderr, "can't open font file \"%s\"\n", filename); 913 abort(); 914 } 915 916 if(!fread(&bfType, sizeof(short int), 1, file)) { 917 fprintf(stderr, "can't read 2 bytes from font file \"%s\"\n", filename); 918 abort(); 845 919 } 846 920 847 921 /* check if file is a bitmap */ 848 if (bfType != 19778) 849 { 850 assert(false); 851 //printf("Not a Bitmap-File!\n"); 922 if (bfType != 19778) { 923 assert(false); 924 //printf("Not a Bitmap-File!\n"); 852 925 } 853 926 … … 857 930 858 931 /* get the position of the actual bitmap data */ 859 if (!fread(&bfOffBits, sizeof(long int), 1, file)) 860 { 861 assert(false); 862 //printf("Error reading file!\n"); 932 if (!fread(&bfOffBits, sizeof(long int), 1, file)) { 933 assert(false); 934 //printf("Error reading file!\n"); 863 935 } 864 936 //printf("Data at Offset: %ld\n", bfOffBits); … … 884 956 885 957 /* get the number of bits per pixel */ 886 if (!fread(&biBitCount, sizeof(short int), 1, file)) 887 { 888 assert(false); 889 //printf("Error reading file!\n"); 890 //return 0; 958 if (!fread(&biBitCount, sizeof(short int), 1, file)) { 959 assert(false); 960 //printf("Error reading file!\n"); 961 //return 0; 891 962 } 892 963 893 964 //printf("Bits per Pixel: %d\n", biBitCount); 894 if (biBitCount != 24) 895 { 896 assert(false); 897 //printf("Bits per Pixel not 24\n"); 898 //return 0; 965 if (biBitCount != 24) { 966 assert(false); 967 //printf("Bits per Pixel not 24\n"); 968 //return 0; 899 969 } 900 970 … … 907 977 /* seek to the actual data */ 908 978 fseek(file, bfOffBits, SEEK_SET); 909 if (!fread(data, biSizeImage, 1, file)) 910 { 911 assert(false); 912 //printf("Error loading file!\n"); 913 } 914 979 if (!fread(data, biSizeImage, 1, file)) { 980 assert(false); 981 //printf("Error loading file!\n"); 982 } 983 915 984 /* swap red and blue (bgr -> rgb) */ 916 for (i = 0; i < biSizeImage; i += 3) 917 { 985 for (i = 0; i < biSizeImage; i += 3) { 918 986 temp = data[i]; 919 987 data[i] = data[i + 2]; -
trunk/packages/vizservers/nanovis/config.h
r829 r1028 22 22 //#define DO_RLE //do run length compression 23 23 24 /* 25 * The following define controls whether new prototype features are to be 26 * compiled. Right now by default it's off (0). That's because nanovis 27 * releases are built directly from the subversion repository. So for now, 28 * we'll rely on developers to set this in their respective sandboxes. 29 */ 30 #define PROTOTYPE 0 31 32 /* 33 * The following define controls whether new load_volume_stream or 34 * load_volume_stream2 are used to load DX data. The difference is that 35 * load_volume_stream2 doesn't do any interpolation of the points to a coarser 36 * mesh. Right now, we're using load_volume_stream2 to make isosurfaces 37 * work correctly. 38 39 * [In the future, we'll use the OpenDX library reader and determine at 40 * runtime if mesh decimation is required] 41 */ 42 #define ISO_TEST 1 43 44 /* 45 * The following define controls whether the plane* commands are 46 * registered in the interpreter. Right now it's off. [Are these 47 * commands still required?] 48 */ 49 #define PLANE_CMD 0 50 24 51 #endif -
trunk/packages/vizservers/nanovis/dxReader2.cpp
r961 r1028 29 29 // write the dx file to disk, because DXImportDX takes a file name 30 30 // george suggested using a pipe here 31 32 // You can do it like this. Give 31 33 sprintf(dxfilename, "/tmp/dx%d.dx", getpid()); 32 34 … … 37 39 fclose(f); 38 40 39 Rappture::DX dxObj(dxfilename );41 Rappture::DX dxObj(dxfilename, &outcome); 40 42 41 43 if (remove(dxfilename) != 0) { -
trunk/packages/vizservers/nanovis/nanovis.cpp
r973 r1028 69 69 #include <R2/R2FilePath.h> 70 70 #include <R2/R2Fonts.h> 71 72 #define SIZEOF_BMP_HEADER 54 71 73 72 74 extern void NvInitCG(); // in Shader.cpp … … 104 106 105 107 108 //frame buffer for final rendering 109 NVISid NanoVis::final_fbo; 110 NVISid NanoVis::final_color_tex; 111 NVISid NanoVis::final_depth_rb; 112 106 113 // pointers to volumes, currently handle up to 10 volumes 107 114 /*FIXME: Is the above comment true? Is there a 10 volume limit */ … … 139 146 //static Lic* lic; 140 147 141 //frame buffer for final rendering142 static NVISid final_fbo, final_color_tex, final_depth_rb;143 148 144 149 //bool advect=false; … … 253 258 254 259 //report errors related to CG shaders 255 void cgErrorCallback(void) 260 void 261 cgErrorCallback(void) 256 262 { 257 263 CGerror lastError = cgGetError(); … … 408 414 //glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, screen_buffer); // INSOO's 409 415 410 std::ostringstream result; 411 result << "nv>legend " << volArg; 412 result << " " << min; 413 result << " " << max; 414 bmp_write(result.str().c_str()); 416 char prefix[200]; 417 sprintf(prefix, "nv>legend %s %g %g", volArg, min, max); 418 ppm_write(prefix); 415 419 write(0, "\n", 1); 416 420 … … 529 533 CHECK_FRAMEBUFFER_STATUS(); 530 534 //assert(glGetError()==0); 531 fprintf(stdin," after assert\n"); 532 } 533 535 } 536 537 /* 538 * FIXME: This routine is fairly expensive (60000 floating pt divides). 539 * I've put an ifdef around the call to it so that the released 540 * builds don't include it. Define PROTOTYPE to 1 in config.h 541 * to turn it back on. 542 */ 534 543 void 535 544 make_test_2D_data() 536 545 { 537 538 546 int w = 300; 539 547 int h = 200; … … 640 648 641 649 particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context); 650 651 #if PROTOTYPE 642 652 licRenderer = new NvLIC(NMESH, NPIX, NPIX, 0.5, g_context); 653 #endif 643 654 644 655 ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl()); 645 646 656 grid = new Grid(); 647 657 grid->setFont(fonts); … … 722 732 //create an 2D plane renderer 723 733 plane_render = new PlaneRenderer(g_context, win_width, win_height); 734 #if PROTOTYPE 724 735 make_test_2D_data(); 725 736 #endif /* PROTOTYPE */ 726 737 plane_render->add_plane(plane[0], get_transfunc("default")); 727 738 … … 732 743 NanoVis::init_lic(); 733 744 #endif 734 }735 736 void737 NanoVis::read_screen()738 {739 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,740 screen_buffer);741 745 } 742 746 … … 780 784 781 785 // used internally to build up the BMP file header 782 // writes an integer value into the header data structure at pos783 static void786 // Writes an integer value into the header data structure at pos 787 static inline void 784 788 bmp_header_add_int(unsigned char* header, int& pos, int data) 785 789 { 790 #ifdef WORDS_BIGENDIAN 791 header[pos++] = (data >> 24) & 0xFF; 792 header[pos++] = (data >> 16) & 0xFF; 793 header[pos++] = (data >> 8) & 0xFF; 794 header[pos++] = (data) & 0xFF; 795 #else 786 796 header[pos++] = data & 0xff; 787 797 header[pos++] = (data >> 8) & 0xff; 788 798 header[pos++] = (data >> 16) & 0xff; 789 799 header[pos++] = (data >> 24) & 0xff; 800 #endif 790 801 } 791 802 … … 793 804 // FOR DEBUGGING 794 805 void 795 NanoVis::bmp_write_to_file(int frame_number, c har*directory_name)796 { 797 unsigned char header[ 54];806 NanoVis::bmp_write_to_file(int frame_number, const char *directory_name) 807 { 808 unsigned char header[SIZEOF_BMP_HEADER]; 798 809 int pos = 0; 799 810 header[pos++] = 'B'; … … 808 819 809 820 // file size in bytes 810 int fsize = (3*win_width+pad)*win_height + sizeof(header);821 int fsize = (3*win_width+pad)*win_height + SIZEOF_BMP_HEADER; 811 822 bmp_header_add_int(header, pos, fsize); 812 823 … … 815 826 816 827 // offset in bytes to start of bitmap data 817 bmp_header_add_int(header, pos, sizeof(header));828 bmp_header_add_int(header, pos, SIZEOF_BMP_HEADER); 818 829 819 830 // size of the BITMAPINFOHEADER … … 875 886 } 876 887 } 877 fwrite((void*) header, sizeof(header), 1, f);888 fwrite((void*) header, SIZEOF_BMP_HEADER, 1, f); 878 889 fwrite((void*) screen_buffer, (3*win_width+pad)*win_height, 1, f); 879 890 fclose(f); … … 881 892 882 893 void 883 NanoVis::bmp_write(const char * cmd)884 { 885 unsigned char header[ 54];894 NanoVis::bmp_write(const char *prefix) 895 { 896 unsigned char header[SIZEOF_BMP_HEADER]; 886 897 int pos = 0; 887 header[pos++] = 'B';888 header[pos++] = 'M';889 898 890 899 // BE CAREFUL: BMP files must have an even multiple of 4 bytes … … 894 903 pad = 4 - ((3*win_width) % 4); 895 904 } 905 pad = 0; 906 int fsize = (3*win_width+pad)*win_height + sizeof(header); 907 908 char string[200]; 909 sprintf(string, "%s %d\n", prefix, fsize); 910 write(0, string, strlen(string)); 911 912 header[pos++] = 'B'; 913 header[pos++] = 'M'; 896 914 897 915 // file size in bytes 898 int fsize = (3*win_width+pad)*win_height + sizeof(header);899 916 bmp_header_add_int(header, pos, fsize); 900 917 … … 903 920 904 921 // offset in bytes to start of bitmap data 905 bmp_header_add_int(header, pos, sizeof(header));922 bmp_header_add_int(header, pos, SIZEOF_BMP_HEADER); 906 923 907 924 // size of the BITMAPINFOHEADER … … 944 961 } 945 962 946 std::ostringstream result; 947 result << cmd << " " << fsize << "\n"; 948 write(0, result.str().c_str(), result.str().size()); 949 950 write(0, header, sizeof(header)); 963 write(0, header, SIZEOF_BMP_HEADER); 951 964 write(0, screen_buffer, (3*win_width+pad)*win_height); 952 965 } 966 967 /* 968 * ppm_write -- 969 * 970 * Writes the screen image as PPM binary data to the nanovisviewer 971 * client. The PPM binary format is very simple. 972 * 973 * P6 w h 255\n 974 * 3-byte RGB pixel data. 975 * 976 * The nanovisviewer client (using the TkImg library) will do less work 977 * to unpack this format, as opposed to BMP or PNG. (This doesn't 978 * eliminate the need to look into DXT compression performed on the GPU). 979 * 980 * Note that currently the image data from the screen is both row-padded 981 * and the scan lines are reversed. This routine could be made even 982 * simpler (faster) if the screen buffer is an array of packed 3-bytes 983 * per pixels (no padding) and where the origin is the top-left corner. 984 */ 985 void 986 NanoVis::ppm_write(const char *prefix) 987 { 988 #define PPM_MAXVAL 255 989 char header[200]; 990 991 // Generate the PPM binary file header 992 sprintf(header, "P6 %d %d %d\n", win_width, win_height, PPM_MAXVAL); 993 994 size_t header_length = strlen(header); 995 size_t data_length = win_width * win_height * 3; 996 997 char command[200]; 998 sprintf(command, "%s %d\n", prefix, header_length + data_length); 999 1000 size_t wordsPerRow = (win_width * 24 + 31) / 32; 1001 size_t bytesPerRow = wordsPerRow * 4; 1002 size_t rowLength = win_width * 3; 1003 size_t nRecs = win_height + 2; 1004 1005 struct iovec *iov; 1006 iov = (struct iovec *)malloc(sizeof(struct iovec) * nRecs); 1007 1008 // Write the nanovisviewer command, then the image header and data. 1009 // Command 1010 iov[0].iov_base = command; 1011 iov[0].iov_len = strlen(command); 1012 // Header of image data 1013 iov[1].iov_base = header; 1014 iov[1].iov_len = header_length; 1015 // Image data. 1016 int y; 1017 unsigned char *srcRowPtr = screen_buffer; 1018 for (y = win_height + 1; y >= 2; y--) { 1019 iov[y].iov_base = srcRowPtr; 1020 iov[y].iov_len = rowLength; 1021 srcRowPtr += bytesPerRow; 1022 } 1023 writev(0, iov, nRecs); 1024 free(iov); 953 1025 } 954 1026 … … 1022 1094 } 1023 1095 1024 void1025 NanoVis::offscreen_buffer_capture()1026 {1027 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);1028 }1029 1030 #ifdef notdef1031 /*1032 * Is this routine being used? --gah1033 */1034 void1035 draw_bounding_box(float x0, float y0, float z0,1036 float x1, float y1, float z1,1037 float r, float g, float b, float line_width)1038 {1039 glDisable(GL_TEXTURE_2D);1040 glColor4d(r, g, b, 1.0);1041 glLineWidth(line_width);1042 glBegin(GL_LINE_LOOP);1043 {1044 glVertex3d(x0, y0, z0);1045 glVertex3d(x1, y0, z0);1046 glVertex3d(x1, y1, z0);1047 glVertex3d(x0, y1, z0);1048 }1049 glEnd();1050 glBegin(GL_LINE_LOOP);1051 {1052 glVertex3d(x0, y0, z1);1053 glVertex3d(x1, y0, z1);1054 glVertex3d(x1, y1, z1);1055 glVertex3d(x0, y1, z1);1056 }1057 glEnd();1058 glBegin(GL_LINE_LOOP);1059 {1060 glVertex3d(x0, y0, z0);1061 glVertex3d(x0, y0, z1);1062 glVertex3d(x0, y1, z1);1063 glVertex3d(x0, y1, z0);1064 }1065 glEnd();1066 glBegin(GL_LINE_LOOP);1067 {1068 glVertex3d(x1, y0, z0);1069 glVertex3d(x1, y0, z1);1070 glVertex3d(x1, y1, z1);1071 glVertex3d(x1, y1, z0);1072 }1073 glEnd();1074 glEnable(GL_TEXTURE_2D);1075 }1076 #endif1077 1078 1096 1079 1097 #ifdef notdef … … 1091 1109 void soft_read_verts() 1092 1110 { 1093 glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, vert); 1111 glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, 1112 vert); 1094 1113 //fprintf(stderr, "soft_read_vert"); 1095 1114 … … 1542 1561 glEnable(GL_TEXTURE_2D); 1543 1562 glEnable(GL_DEPTH_TEST); 1544 1563 1545 1564 //camera setting activated 1546 1565 cam->activate(); … … 1874 1893 main(int argc, char** argv) 1875 1894 { 1876 1877 1895 char *path; 1878 1896 path = NULL; -
trunk/packages/vizservers/nanovis/nanovis.h
r973 r1028 101 101 102 102 class NanoVis { 103 //frame buffer for final rendering 104 static NVISid final_fbo, final_color_tex, final_depth_rb; 103 105 public: 104 106 static VolumeRenderer* vol_renderer; … … 139 141 static bool vector_on; 140 142 143 141 144 static TransferFunction* get_transfunc(const char *name); 142 145 static TransferFunction* DefineTransferFunction(const char *name, … … 150 153 static void initParticle(); 151 154 static void resize_offscreen_buffer(int w, int h); 152 static void offscreen_buffer_capture(void);153 static void bmp_write(const char * cmd);154 static void bmp_write_to_file(int frame_number, c har* directory_name);155 static void ppm_write(const char *prefix); 156 static void bmp_write(const char *prefix); 157 static void bmp_write_to_file(int frame_number, const char* directory_name); 155 158 static void display(void); 156 159 static void update(void); 157 160 static void display_offscreen_buffer(); 158 static void read_screen();159 161 static void zoom(double zoom); 160 162 static int render_legend(TransferFunction *tf, double min, double max, … … 169 171 static void update_trans(int delta_x, int delta_y, int delta_z); 170 172 #endif 173 174 static void read_screen(void) { 175 glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, 176 screen_buffer); 177 } 178 static void offscreen_buffer_capture(void) { 179 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 180 } 171 181 }; 172 182
Note: See TracChangeset
for help on using the changeset viewer.