Changeset 1374 for trunk/packages
- Timestamp:
- Apr 2, 2009, 3:52:16 PM (16 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Command.cpp
r1370 r1374 68 68 #include "Grid.h" 69 69 #include "NvCamera.h" 70 #include <RenderContext.h> 71 #include <NvLIC.h> 70 #include "RenderContext.h" 71 #include "NvLIC.h" 72 #include "Unirect.h" 72 73 73 74 #define ISO_TEST 1 … … 103 104 std::istream& fin); 104 105 extern bool load_vector_stream2(Rappture::Outcome &result, int index, 105 std::istream& fin); 106 size_t length, char *bytes); 107 extern bool MakeVectorFieldFromUnirect3d(Rappture::Outcome &result, 108 Rappture::Unirect3d &data); 106 109 107 110 // Tcl interpreter for incoming messages … … 147 150 static Tcl_ObjCmdProc SnapshotCmd; 148 151 static Tcl_ObjCmdProc TransfuncCmd; 149 static Tcl_ObjCmdProc Uni Rect2dCmd;152 static Tcl_ObjCmdProc Unirect2dCmd; 150 153 static Tcl_ObjCmdProc UpCmd; 151 154 static Tcl_ObjCmdProc VolumeCmd; 152 155 153 staticbool156 bool 154 157 GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, bool *boolPtr) 155 158 { … … 163 166 } 164 167 165 staticint168 int 166 169 GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, float *valuePtr) 167 170 { … … 578 581 * ---------------------------------------------------------------------- 579 582 */ 580 staticint583 int 581 584 GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr) 582 585 { … … 650 653 * ----------------------------------------------------------------------- 651 654 */ 652 staticint655 int 653 656 GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes) 654 657 { … … 686 689 { 687 690 Rappture::Outcome err; 688 689 err = Rappture::encoding::decode(buf, RPENC_Z|RPENC_B64|RPENC_HDR); 690 if (err) { 691 unsigned int flags; 692 693 flags = RPENC_Z|RPENC_B64|RPENC_HDR; 694 if (!Rappture::encoding::decode(err, buf, flags)) { 691 695 printf("ERROR -- DECODING\n"); 692 696 fflush(stdout); … … 1734 1738 return TCL_ERROR; 1735 1739 } 1740 int extents; 1741 if (Tcl_GetIntFromObj(interp, objv[4], &extents) != TCL_OK) { 1742 return TCL_ERROR; 1743 } 1736 1744 1737 1745 Rappture::Buffer buf; … … 1740 1748 } 1741 1749 int n = NanoVis::n_volumes; 1742 std::stringstream fdata; 1743 fdata.write(buf.bytes(),buf.size()); 1744 // load_vector_stream(result, n, fdata); 1745 1746 if (!load_vector_stream2(result, n, fdata)) { 1747 Tcl_AppendResult(interp, result.remark(), (char *)NULL); 1748 return TCL_ERROR; 1749 } 1750 Volume *volPtr = NanoVis::volume[n]; 1751 1750 if (strncmp(buf.bytes(), "<DX>", 4) == 0) { 1751 if (!load_vector_stream2(result, n, buf.size(), (char *)buf.bytes())) { 1752 Tcl_AppendResult(interp, result.remark(), (char *)NULL); 1753 return TCL_ERROR; 1754 } 1755 } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) { 1756 Rappture::Unirect3d data; 1757 Tcl_CmdInfo cmdInfo; 1758 1759 /* Set the clientdata field of the unirect3d command to contain 1760 * the local data structure. */ 1761 if (!Tcl_GetCommandInfo(interp, "unirect3d", &cmdInfo)) { 1762 return TCL_ERROR; 1763 } 1764 data.extents(extents); 1765 cmdInfo.objClientData = (ClientData)&data; 1766 Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo); 1767 if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) { 1768 return TCL_ERROR; 1769 } 1770 if (!data.isInitialized()) { 1771 return TCL_ERROR; 1772 } 1773 if (!MakeVectorFieldFromUnirect3d(result, data)) { 1774 Tcl_AppendResult(interp, result.remark(), (char *)NULL); 1775 return TCL_ERROR; 1776 } 1777 } 1778 1779 Volume *volPtr = NanoVis::volume[NanoVis::n_volumes]; 1752 1780 // 1753 1781 // BE CAREFUL: Set the number of slices to something … … 1758 1786 // appear at all. 1759 1787 // 1760 if (volPtr != NULL) { 1761 volPtr->set_n_slice(256-n); 1762 // volPtr->set_n_slice(512-n); 1763 volPtr->disable_cutplane(0); 1764 volPtr->disable_cutplane(1); 1765 volPtr->disable_cutplane(2); 1766 1767 NanoVis::vol_renderer->add_volume(volPtr, 1768 NanoVis::get_transfunc("default")); 1769 1770 float dx0 = -0.5; 1771 float dy0 = -0.5*volPtr->height/volPtr->width; 1772 float dz0 = -0.5*volPtr->depth/volPtr->width; 1773 volPtr->move(Vector3(dx0, dy0, dz0)); 1774 1775 } 1776 1788 volPtr->set_n_slice(256-n); 1789 // volPtr->set_n_slice(512-n); 1790 volPtr->disable_cutplane(0); 1791 volPtr->disable_cutplane(1); 1792 volPtr->disable_cutplane(2); 1793 1794 NanoVis::vol_renderer->add_volume(volPtr, 1795 NanoVis::get_transfunc("default")); 1796 1797 float dx0 = -0.5; 1798 float dy0 = -0.5*volPtr->height/volPtr->width; 1799 float dz0 = -0.5*volPtr->depth/volPtr->width; 1800 volPtr->move(Vector3(dx0, dy0, dz0)); 1777 1801 return TCL_OK; 1778 1802 } … … 1901 1925 // FIXME: find a way to get the data from the movie object as a void* 1902 1926 Rappture::Buffer data; 1903 data.load(fileName); 1927 if (!data.load(result, fileName)) { 1928 Tcl_AppendResult(interp, "can't load data from temporary movie file \"", 1929 fileName, "\": ", result.remark(), (char *)NULL); 1930 return TCL_ERROR; 1931 } 1904 1932 1905 1933 // Build the command string for the client. … … 2002 2030 Tcl_Obj *const *objv) 2003 2031 { 2004 Tcl_ObjCmdProc *proc;2032 Tcl_ObjCmdProc *proc; 2005 2033 2006 2034 proc = Rappture::GetOpFromObj(interp, nFlowSliceOps, flowSliceOps, … … 2182 2210 } 2183 2211 buf.append("\0", 1); 2184 int result; 2185 result = Tcl_Eval(interp, buf.bytes()); 2186 if (result != TCL_OK) { 2212 2213 Rappture::Unirect2d grid; 2214 Tcl_CmdInfo cmdInfo; 2215 2216 /* Set the clientdata field of the unirect2d command to contain the local 2217 * grid structure. This is how we communicate through the Tcl command 2218 * interface. */ 2219 if (!Tcl_GetCommandInfo(interp, "unirect2d", &cmdInfo)) { 2220 return TCL_ERROR; 2221 } 2222 cmdInfo.objClientData = (ClientData)&grid; 2223 Tcl_SetCommandInfo(interp, "unirect2d", &cmdInfo); 2224 if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) { 2187 2225 fprintf(NanoVis::logfile, "error in command: %s\n", 2188 2226 Tcl_GetStringResult(interp)); 2189 2227 fflush(NanoVis::logfile); 2190 } 2191 return result; 2228 return TCL_ERROR; 2229 } 2230 if (!grid.isInitialized()) { 2231 return TCL_ERROR; 2232 } 2233 2234 HeightMap* hmPtr; 2235 hmPtr = new HeightMap(); 2236 2237 // Must set units before the heights. 2238 hmPtr->xAxis.units(grid.xUnits()); 2239 hmPtr->yAxis.units(grid.yUnits()); 2240 hmPtr->zAxis.units(grid.vUnits()); 2241 hmPtr->wAxis.units(grid.yUnits()); 2242 hmPtr->setHeight(grid.xMin(), grid.yMin(), grid.xMax(), grid.yMax(), 2243 grid.xNum(), grid.yNum(), grid.acceptValues()); 2244 hmPtr->setColorMap(NanoVis::get_transfunc("default")); 2245 hmPtr->setVisible(true); 2246 hmPtr->setLineContourVisible(true); 2247 NanoVis::heightMap.push_back(hmPtr); 2248 return TCL_OK; 2192 2249 } 2193 2250 … … 2729 2786 */ 2730 2787 static int 2731 Uni Rect2dCmd(ClientData clientData, Tcl_Interp *interp, int objc,2788 Unirect2dCmd(ClientData clientData, Tcl_Interp *interp, int objc, 2732 2789 Tcl_Obj *const *objv) 2733 2790 { 2734 int xNum, yNum, zNum; 2735 float xMin, yMin, xMax, yMax; 2736 float *zValues; 2737 const char *xUnits, *yUnits, *zUnits; 2738 2739 if ((objc & 0x01) == 0) { 2740 Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ", 2741 "wrong number of arguments: should be key-value pairs", 2742 (char *)NULL); 2743 return TCL_ERROR; 2744 } 2745 zValues = NULL; 2746 xNum = yNum = zNum = 0; 2747 xMin = yMin = xMax = yMax = 0.0f; 2748 xUnits = yUnits = zUnits = NULL; 2749 int i; 2750 for (i = 1; i < objc; i += 2) { 2751 const char *string; 2752 char c; 2753 2754 string = Tcl_GetString(objv[i]); 2755 c = string[0]; 2756 if ((c == 'x') && (strcmp(string, "xmin") == 0)) { 2757 if (GetFloatFromObj(interp, objv[i+1], &xMin) != TCL_OK) { 2758 return TCL_ERROR; 2759 } 2760 } else if ((c == 'x') && (strcmp(string, "xmax") == 0)) { 2761 if (GetFloatFromObj(interp, objv[i+1], &xMax) != TCL_OK) { 2762 return TCL_ERROR; 2763 } 2764 } else if ((c == 'x') && (strcmp(string, "xnum") == 0)) { 2765 if (Tcl_GetIntFromObj(interp, objv[i+1], &xNum) != TCL_OK) { 2766 return TCL_ERROR; 2767 } 2768 if (xNum <= 0) { 2769 Tcl_AppendResult(interp, "bad xnum value: must be > 0", 2770 (char *)NULL); 2771 return TCL_ERROR; 2772 } 2773 } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) { 2774 xUnits = Tcl_GetString(objv[i+1]); 2775 } else if ((c == 'y') && (strcmp(string, "ymin") == 0)) { 2776 if (GetFloatFromObj(interp, objv[i+1], &yMin) != TCL_OK) { 2777 return TCL_ERROR; 2778 } 2779 } else if ((c == 'y') && (strcmp(string, "ymax") == 0)) { 2780 if (GetFloatFromObj(interp, objv[i+1], &yMax) != TCL_OK) { 2781 return TCL_ERROR; 2782 } 2783 } else if ((c == 'y') && (strcmp(string, "ynum") == 0)) { 2784 if (Tcl_GetIntFromObj(interp, objv[i+1], &yNum) != TCL_OK) { 2785 return TCL_ERROR; 2786 } 2787 if (yNum <= 0) { 2788 Tcl_AppendResult(interp, "bad ynum value: must be > 0", 2789 (char *)NULL); 2790 return TCL_ERROR; 2791 } 2792 } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) { 2793 yUnits = Tcl_GetString(objv[i+1]); 2794 } else if ((c == 'z') && (strcmp(string, "zvalues") == 0)) { 2795 Tcl_Obj **zObj; 2796 2797 if (Tcl_ListObjGetElements(interp, objv[i+1], &zNum, &zObj)!= TCL_OK) { 2798 return TCL_ERROR; 2799 } 2800 int j; 2801 zValues = new float[zNum]; 2802 for (j = 0; j < zNum; j++) { 2803 if (GetFloatFromObj(interp, zObj[j], zValues + j) != TCL_OK) { 2804 return TCL_ERROR; 2805 } 2806 } 2807 } else if ((c == 'z') && (strcmp(string, "zunits") == 0)) { 2808 zUnits = Tcl_GetString(objv[i+1]); 2809 } else { 2810 Tcl_AppendResult(interp, "unknown key \"", string, 2811 "\": should be xmin, xmax, xnum, xunits, ymin, ymax, ynum, yunits, zvalues, or zunits", 2812 (char *)NULL); 2813 return TCL_ERROR; 2814 } 2815 } 2816 if (zValues == NULL) { 2817 Tcl_AppendResult(interp, "missing \"zvalues\" key", (char *)NULL); 2818 return TCL_ERROR; 2819 } 2820 if (zNum != (xNum * yNum)) { 2821 Tcl_AppendResult(interp, "wrong number of z values must be xnum*ynum", 2822 (char *)NULL); 2823 return TCL_ERROR; 2824 } 2825 HeightMap* hmPtr; 2826 hmPtr = new HeightMap(); 2827 2828 // Must set units before the heights. 2829 hmPtr->xAxis.units(xUnits); 2830 hmPtr->yAxis.units(yUnits); 2831 hmPtr->zAxis.units(zUnits); 2832 hmPtr->wAxis.units(yUnits); 2833 hmPtr->setHeight(xMin, yMin, xMax, yMax, xNum, yNum, zValues); 2834 hmPtr->setColorMap(NanoVis::get_transfunc("default")); 2835 hmPtr->setVisible(true); 2836 hmPtr->setLineContourVisible(true); 2837 NanoVis::heightMap.push_back(hmPtr); 2838 return TCL_OK; 2839 } 2840 2791 Rappture::Unirect2d *dataPtr = (Rappture::Unirect2d *)clientData; 2792 2793 return dataPtr->LoadData(interp, objc, objv); 2794 } 2795 2796 /* 2797 * This command should be Tcl procedure instead of a C command. The reason 2798 * for this that 1) we are using a safe interpreter so we would need a master 2799 * interpreter to load the Tcl environment properly (including our "unirect2d" 2800 * procedure). And 2) the way nanovis is currently deployed doesn't make it 2801 * easy to add new directories for procedures, since it's loaded into /tmp. 2802 * 2803 * Ideally, the "unirect2d" proc would do a rundimentary parsing of the data 2804 * to verify the structure and then pass it to the appropiate Tcl command 2805 * (heightmap, volume, etc). Our C command always creates a heightmap. 2806 */ 2807 2808 static int 2809 Unirect3dCmd(ClientData clientData, Tcl_Interp *interp, int objc, 2810 Tcl_Obj *const *objv) 2811 { 2812 Rappture::Unirect3d *dataPtr = (Rappture::Unirect3d *)clientData; 2813 2814 return dataPtr->LoadData(interp, objc, objv); 2815 } 2841 2816 2842 2817 Tcl_Interp * … … 2865 2840 Tcl_CreateObjCommand(interp, "snapshot", SnapshotCmd, NULL, NULL); 2866 2841 Tcl_CreateObjCommand(interp, "transfunc", TransfuncCmd, NULL, NULL); 2867 Tcl_CreateObjCommand(interp, "unirect2d", UniRect2dCmd, NULL, NULL); 2842 Tcl_CreateObjCommand(interp, "unirect2d", Unirect2dCmd, NULL, NULL); 2843 Tcl_CreateObjCommand(interp, "unirect3d", Unirect3dCmd, NULL, NULL); 2868 2844 Tcl_CreateObjCommand(interp, "up", UpCmd, NULL, NULL); 2869 2845 Tcl_CreateObjCommand(interp, "volume", VolumeCmd, NULL, NULL); -
trunk/packages/vizservers/nanovis/FlowCmds.cpp
r1370 r1374 98 98 extern int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes); 99 99 extern bool load_vector_stream2(Rappture::Outcome &result, int index, 100 int nBytes, char *bytes);100 size_t nBytes, char *bytes); 101 101 102 102 extern bool MakeVectorFieldFromUnirect3d(Rappture::Outcome &result, … … 145 145 } 146 146 Rappture::Buffer buf; 147 buf.load(fileName); 147 if (!buf.load(result, fileName)) { 148 Tcl_AppendResult(interp, "can't load data from \"", fileName, "\": ", 149 result.remark(), (char *)NULL); 150 return TCL_ERROR; 151 } 148 152 149 153 int n = NanoVis::n_volumes; … … 901 905 // FIXME: find a way to get the data from the movie object as a void* 902 906 Rappture::Buffer data; 903 data.load(fileName); 904 907 if (!data.load(result, fileName)) { 908 Tcl_AppendResult(interp, "can't load data from temporary movie file \"", 909 fileName, "\": ", result.remark(), (char *)NULL); 910 return TCL_ERROR; 911 } 905 912 // Build the command string for the client. 906 913 char command[200]; -
trunk/packages/vizservers/nanovis/LoadVector.cpp
r1365 r1374 240 240 241 241 242 #ifdef notdef 242 243 /* 243 244 * Load a 3D vector field from a dx-format file … … 363 364 } 364 365 366 #endif -
trunk/packages/vizservers/nanovis/Makefile.in
r1369 r1374 72 72 $(CG_LIB_SPEC) \ 73 73 $(GL_LIB_SPEC) \ 74 $(GLUI_LIB_SPEC) \75 74 $(FF_LIB_SPEC) \ 76 75 $(EXTRA_LIBS) \ … … 83 82 $(IMG_INC_SPEC) \ 84 83 $(MAT_INC_SPEC) \ 85 $(GLUI_INC_SPEC) \86 84 $(TCL_INC_SPEC) \ 87 85 $(CG_INC_SPEC) \ … … 105 103 ConvexPolygon.o \ 106 104 Event.o \ 105 Switch.o \ 106 FlowCmds.o \ 107 107 GradientFilter.o \ 108 108 Grid.o \ 109 109 HeightMap.o \ 110 LoadVector.o \ 111 Unirect.o \ 110 112 Mat4x4.o \ 111 113 Nv.o \ … … 178 180 $(srcdir)/shaders/zincblende_volume.cg 179 181 180 .PHONY: gluinewmat11 R2 imgloaders transfer-function nanovis181 182 all: gluinewmat11 R2 imgloaders transfer-function nanovis182 .PHONY: newmat11 R2 imgloaders transfer-function nanovis 183 184 all: newmat11 R2 imgloaders transfer-function nanovis 183 185 184 186 install: install-nanovis install-resources install-shaders … … 238 240 239 241 clean: 240 $(MAKE) -C $(GLUI_DIR) clean241 242 $(MAKE) -C $(MAT_DIR) clean 242 243 $(MAKE) -C $(R2_DIR)/src clean -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r1328 r1374 890 890 891 891 892 void VolumeRenderer::init_font(const char* filename) { 893 894 FILE *file; 892 bool 893 VolumeRenderer::init_font(const char* filename) 894 { 895 FILE *f; 895 896 unsigned short int bfType; 896 897 int bfOffBits; … … 901 902 int i; 902 903 unsigned char temp; 903 904 904 unsigned char* data; 905 905 /* make sure the file is there and open it read-only (binary) */ 906 if ((file = fopen(filename, "rb")) == NULL) { 906 f = fopen(filename, "rb"); 907 if (f == NULL) { 907 908 fprintf(stderr, "can't open font file \"%s\"\n", filename); 908 abort(); 909 } 910 911 if(!fread(&bfType, sizeof(short int), 1, file)) { 912 fprintf(stderr, "can't read 2 bytes from font file \"%s\"\n", filename); 913 abort(); 909 return false; 910 } 911 912 if (fread(&bfType, sizeof(short int), 1, f) != 1) { 913 fprintf(stderr, "can't read %d bytes from font file \"%s\"\n", 914 sizeof(short int), filename); 915 goto error; 914 916 } 915 917 916 918 /* check if file is a bitmap */ 917 919 if (bfType != 19778) { 918 assert(false);919 //printf("Not a Bitmap-File!\n");920 fprintf(stderr, "not a bmp file.\n"); 921 goto error; 920 922 } 921 923 922 924 /* get the file size */ 923 925 /* skip file size and reserved fields of bitmap file header */ 924 fseek(f ile, 8, SEEK_CUR);926 fseek(f, 8, SEEK_CUR); 925 927 926 928 /* get the position of the actual bitmap data */ 927 if ( !fread(&bfOffBits, sizeof(int), 1, file)) {928 assert(false);929 //printf("Error reading file!\n");929 if (fread(&bfOffBits, sizeof(int), 1, f) != 1) { 930 fprintf(stderr, "error reading file.\n"); 931 goto error; 930 932 } 931 933 //printf("Data at Offset: %ld\n", bfOffBits); 932 934 933 935 /* skip size of bitmap info header */ 934 fseek(f ile, 4, SEEK_CUR);936 fseek(f, 4, SEEK_CUR); 935 937 936 938 /* get the width of the bitmap */ 937 fread(&width, sizeof(int), 1, file); 939 if (fread(&width, sizeof(int), 1, f) != 1) { 940 fprintf(stderr, "error reading file.\n"); 941 goto error; 942 } 938 943 //printf("Width of Bitmap: %d\n", texture->width); 939 944 940 945 /* get the height of the bitmap */ 941 fread(&height, sizeof(int), 1, file); 946 if (fread(&height, sizeof(int), 1, f) != 1) { 947 fprintf(stderr, "error reading file.\n"); 948 goto error; 949 } 942 950 //printf("Height of Bitmap: %d\n", texture->height); 943 951 944 952 /* get the number of planes (must be set to 1) */ 945 fread(&biPlanes, sizeof(short int), 1, file); 946 if (biPlanes != 1) 947 { 948 assert(false); 949 //printf("Error: number of Planes not 1!\n"); 953 if (fread(&biPlanes, sizeof(short int), 1, f) != 1) { 954 fprintf(stderr, "error reading file.\n"); 955 goto error; 956 } 957 if (biPlanes != 1) { 958 fprintf(stderr, "Error: number of Planes not 1!\n"); 959 goto error; 950 960 } 951 961 952 962 /* get the number of bits per pixel */ 953 if (!fread(&biBitCount, sizeof(short int), 1, file)) { 954 assert(false); 955 //printf("Error reading file!\n"); 956 //return 0; 963 if (fread(&biBitCount, sizeof(short int), 1, f) != 1) { 964 fprintf(stderr, "error reading file.\n"); 965 goto error; 957 966 } 958 967 959 968 //printf("Bits per Pixel: %d\n", biBitCount); 960 969 if (biBitCount != 24) { 961 assert(false); 962 //printf("Bits per Pixel not 24\n"); 963 //return 0; 970 fprintf(stderr, "Bits per Pixel not 24\n"); 971 goto error; 964 972 } 965 973 … … 967 975 /* calculate the size of the image in bytes */ 968 976 biSizeImage = width * height * 3 * sizeof(unsigned char); 969 unsigned char* data = (unsigned char*) malloc(biSizeImage); 970 977 data = (unsigned char*) malloc(biSizeImage); 978 if (data == NULL) { 979 fprintf(stderr, "Can't allocate memory for image\n"); 980 goto error; 981 } 971 982 972 983 /* seek to the actual data */ 973 fseek(file, bfOffBits, SEEK_SET); 974 if (!fread(data, biSizeImage, 1, file)) { 975 assert(false); 976 //printf("Error loading file!\n"); 977 } 978 984 fseek(f, bfOffBits, SEEK_SET); 985 if (fread(data, biSizeImage, 1, f) != 1) { 986 fprintf(stderr, "Error loading file!\n"); 987 goto error; 988 } 989 fclose(f); 990 979 991 /* swap red and blue (bgr -> rgb) */ 980 992 for (i = 0; i < biSizeImage; i += 3) { … … 985 997 986 998 //insert alpha channel 987 unsigned char* data_with_alpha = (unsigned char*) malloc(width*height*4*sizeof(unsigned char)); 999 unsigned char* data_with_alpha; 1000 data_with_alpha = (unsigned char*) 1001 malloc(width*height*4*sizeof(unsigned char)); 988 1002 for(int i=0; i<height; i++){ 989 990 unsigned char r, g, b, a;991 r = data[3*(i*width+j)];992 g = data[3*(i*width+j)+1];993 b = data[3*(i*width+j)+2];994 995 if(r==0 && g==0 && b==0)996 997 else998 999 1000 data_with_alpha[4*(i*width+j)] = r;1001 data_with_alpha[4*(i*width+j) + 1] = g;1002 data_with_alpha[4*(i*width+j) + 2] = b;1003 data_with_alpha[4*(i*width+j) + 3] = a;1004 1005 1003 for(int j=0; j<width; j++){ 1004 unsigned char r, g, b, a; 1005 r = data[3*(i*width+j)]; 1006 g = data[3*(i*width+j)+1]; 1007 b = data[3*(i*width+j)+2]; 1008 1009 if(r==0 && g==0 && b==0) 1010 a = 0; 1011 else 1012 a = 255; 1013 1014 data_with_alpha[4*(i*width+j)] = r; 1015 data_with_alpha[4*(i*width+j) + 1] = g; 1016 data_with_alpha[4*(i*width+j) + 2] = b; 1017 data_with_alpha[4*(i*width+j) + 3] = a; 1018 1019 } 1006 1020 } 1007 1021 free(data); 1008 1022 1009 1023 //create opengl texture 1010 1024 glGenTextures(1, &font_texture); … … 1019 1033 1020 1034 build_font(); 1021 assert(glGetError()==0); 1022 } 1023 1024 1025 1026 void VolumeRenderer::draw_label(Volume* vol){ 1035 return (glGetError()==0); 1036 1037 error: 1038 fclose(f); 1039 return false; 1040 } 1041 1042 1043 1044 void 1045 VolumeRenderer::draw_label(Volume* vol) 1046 { 1027 1047 1028 1048 //glEnable(GL_TEXTURE_2D); -
trunk/packages/vizservers/nanovis/VolumeRenderer.h
r1362 r1374 94 94 95 95 void get_near_far_z(Mat4x4 mv, double &zNear, double &zFar); 96 voidinit_font(const char* filename);96 bool init_font(const char* filename); 97 97 void glPrint(char* string, int set); //there are two sets of font in the 98 98 //texture. 0, 1 -
trunk/packages/vizservers/nanovis/dxReader.cpp
r1370 r1374 44 44 #define _LOCAL_ZINC_TEST_ 0 45 45 46 static INLINE char * 47 skipspaces(char *string) 48 { 49 while (isspace(*string)) { 50 string++; 51 } 52 return string; 53 } 54 55 static INLINE char * 56 getline(char **stringPtr, char *endPtr) 57 { 58 char *line, *p; 59 60 line = skipspaces(*stringPtr); 61 for (p = line; p < endPtr; p++) { 62 if (*p == '\n') { 63 *p++ = '\0'; 64 *stringPtr = p; 65 return line; 66 } 67 } 68 *stringPtr = p; 69 return line; 70 } 71 46 72 /* 47 73 * Load a 3D vector field from a dx-format file 48 74 */ 49 75 bool 50 load_vector_stream2(Rappture::Outcome &result, int volindex, std::istream& fin) 76 load_vector_stream2(Rappture::Outcome &result, int ivol, size_t length, 77 char *string) 51 78 { 52 int dummy,nx, ny, nz, npts;79 int nx, ny, nz, npts; 53 80 double x0, y0, z0, dx, dy, dz, ddx, ddy, ddz; 54 char line[128], type[128], *start;81 char *p, *endPtr; 55 82 56 83 dx = dy = dz = 0.0; // Suppress compiler warning. 57 84 x0 = y0 = z0 = 0.0; // May not have an origin line. 58 85 for (p = string, endPtr = p + length; p < endPtr; /*empty*/) { 86 char *line; 87 88 line = getline(&p, endPtr); 89 if (line == endPtr) { 90 break; 91 } 92 if ((line[0] == '#') || (line == '\0')) { 93 continue; // Skip blank or comment lines. 94 } 95 if (sscanf(line, "object %*d class gridpositions counts %d %d %d", 96 &nx, &ny, &nz) == 4) { 97 printf("w:%d h:%d d:%d\n", nx, ny, nz); 98 // found grid size 99 } else if (sscanf(line, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) { 100 // found origin 101 } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) { 102 // found one of the delta lines 103 if (ddx != 0.0) { 104 dx = ddx; 105 } else if (ddy != 0.0) { 106 dy = ddy; 107 } else if (ddz != 0.0) { 108 dz = ddz; 109 } 110 } else if (sscanf(line, "object %*d class array type %*s shape 3" 111 " rank 1 items %d data follows", &npts) == 3) { 112 printf("point %d\n", npts); 113 if (npts != nx*ny*nz) { 114 result.addError("inconsistent data: expected %d points" 115 " but found %d points", nx*ny*nz, npts); 116 return false; 117 } 118 break; 119 } else if (sscanf(line, "object %*d class array type %*s rank 0" 120 " times %d data follows", &npts) == 3) { 121 if (npts != nx*ny*nz) { 122 result.addError("inconsistent data: expected %d points" 123 " but found %d points", nx*ny*nz, npts); 124 return false; 125 } 126 break; 127 } 128 } 59 129 Vector3 physicalMin; 60 130 Vector3 physicalMax; 61 131 62 while (!fin.eof()) {63 fin.getline(line, sizeof(line) - 1);64 if (fin.fail()) {65 result.addError("error in data stream");66 return false;67 }68 for (start=&line[0]; *start == ' ' || *start == '\t'; start++)69 ; // skip leading blanks70 71 if (*start != '#') { // skip comment lines72 if (sscanf(start, "object %d class gridpositions counts %d %d %d", &dummy, &nx, &ny, &nz) == 4) {73 printf("w:%d h:%d d:%d\n", nx, ny, nz);74 // found grid size75 } else if (sscanf(start, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) {76 // found origin77 } else if (sscanf(start, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {78 // found one of the delta lines79 if (ddx != 0.0) {80 dx = ddx;81 } else if (ddy != 0.0) {82 dy = ddy;83 } else if (ddz != 0.0) {84 dz = ddz;85 }86 } else if (sscanf(start, "object %d class array type %s shape 3 rank 1 items %d data follows", &dummy, type, &npts) == 3) {87 printf("point %d\n", npts);88 if (npts != nx*ny*nz) {89 result.addError("inconsistent data: expected %d points"90 " but found %d points", nx*ny*nz, npts);91 return false;92 }93 break;94 } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {95 if (npts != nx*ny*nz) {96 result.addError("inconsistent data: expected %d points"97 " but found %d points", nx*ny*nz, npts);98 return false;99 }100 break;101 }102 }103 }104 105 132 physicalMin.set(x0, y0, z0); 106 133 physicalMax.set(x0 + dx * nx, y0 + dy * ny, z0 + dz * nz); … … 108 135 // read data points 109 136 float* srcdata = new float[nx * ny * nz * 3]; 110 if (!fin.eof()) { 111 double vx, vy, vz, vm; 137 if (p >= endPtr) { 138 std::cerr << "WARNING: data not found in stream" << std::endl; 139 return true; 140 } 112 141 #ifdef notdef 113 114 115 142 double max_x = -1e21, min_x = 1e21; 143 double max_y = -1e21, min_y = 1e21; 144 double max_z = -1e21, min_z = 1e21; 116 145 #endif 117 double max_mag = -1e21, min_mag = 1e21; 118 int nread = 0; 119 for (int ix=0; ix < nx; ix++) { 120 for (int iy=0; iy < ny; iy++) { 121 for (int iz=0; iz < nz; iz++) { 122 if (fin.eof() || nread > npts) { 123 break; 124 } 125 fin.getline(line,sizeof(line)-1); 126 if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) { 127 int nindex = (iz*nx*ny + iy*nx + ix) * 3; 128 srcdata[nindex] = vx; 129 //if (srcdata[nindex] > max_x) max_x = srcdata[nindex]; 130 //if (srcdata[nindex] < min_x) min_x = srcdata[nindex]; 131 ++nindex; 132 133 srcdata[nindex] = vy; 134 //if (srcdata[nindex] > max_y) max_y = srcdata[nindex]; 135 //if (srcdata[nindex] < min_y) min_y = srcdata[nindex]; 136 ++nindex; 137 138 srcdata[nindex] = vz; 139 //if (srcdata[nindex] > max_z) max_z = srcdata[nindex]; 140 //if (srcdata[nindex] < min_z) min_z = srcdata[nindex]; 141 142 vm = sqrt(vx*vx + vy*vy + vz*vz); 143 if (vm > max_mag) { 144 max_mag = vm; 145 } 146 if (vm < min_mag) { 147 min_mag = vm; 148 } 149 150 ++nread; 151 } 152 } 153 } 154 } 155 156 // make sure that we read all of the expected points 157 if (nread != nx*ny*nz) { 158 result.addError("inconsistent data: expected %d points" 159 " but found %d points", nx*ny*nz, npts); 160 return false; 161 } 162 163 float *data = new float[4*nx*ny*nz]; 164 memset(data, 0, sizeof(float) * 4 * nx * ny * nz); 165 166 std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl; 167 168 // generate the uniformly sampled data that we need for a volume 169 #ifdef notdef 170 double nzero_min = 0.0; 171 #endif 172 int ngen = 0; 173 int nindex = 0; 174 for (int iz=0; iz < nz; iz++) { 175 for (int iy=0; iy < ny; iy++) { 176 for (int ix=0; ix < nx; ix++) { 177 178 vx = srcdata[nindex++]; 179 vy = srcdata[nindex++]; 180 vz = srcdata[nindex++]; 181 182 double vm; 183 vm = sqrt(vx*vx + vy*vy + vz*vz); 184 185 data[ngen] = vm / max_mag; ++ngen; 186 data[ngen] = vx /(2.0*max_mag) + 0.5; ++ngen; 187 data[ngen] = vy /(2.0*max_mag) + 0.5; ++ngen; 188 data[ngen] = vz /(2.0*max_mag) + 0.5; ++ngen; 189 } 190 } 191 } 192 193 Volume *volPtr; 194 volPtr = NanoVis::load_volume(volindex, nx, ny, nz, 4, data, 195 min_mag, max_mag, 0); 196 197 volPtr->xAxis.SetRange(x0, x0 + nx); 198 volPtr->yAxis.SetRange(y0, y0 + ny); 199 volPtr->zAxis.SetRange(z0, z0 + nz); 200 volPtr->wAxis.SetRange(min_mag, max_mag); 201 volPtr->update_pending = true; 202 volPtr->setPhysicalBBox(physicalMin, physicalMax); 203 delete [] data; 204 } else { 205 std::cerr << "WARNING: data not found in stream" << std::endl; 146 double max_mag = -1e21, min_mag = 1e21; 147 int nread = 0; 148 for (int ix=0; ix < nx; ix++) { 149 for (int iy=0; iy < ny; iy++) { 150 for (int iz=0; iz < nz; iz++) { 151 char *line; 152 double vx, vy, vz, vm; 153 154 if ((p == endPtr) || nread > npts) { 155 break; 156 } 157 line = getline(&p, endPtr); 158 if ((line == '#') || (line == '\0')) { 159 continue; // Skip blank or comment lines. 160 } 161 if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) { 162 int nindex = (iz*nx*ny + iy*nx + ix) * 3; 163 srcdata[nindex] = vx; 164 //if (srcdata[nindex] > max_x) max_x = srcdata[nindex]; 165 //if (srcdata[nindex] < min_x) min_x = srcdata[nindex]; 166 ++nindex; 167 168 srcdata[nindex] = vy; 169 //if (srcdata[nindex] > max_y) max_y = srcdata[nindex]; 170 //if (srcdata[nindex] < min_y) min_y = srcdata[nindex]; 171 ++nindex; 172 173 srcdata[nindex] = vz; 174 //if (srcdata[nindex] > max_z) max_z = srcdata[nindex]; 175 //if (srcdata[nindex] < min_z) min_z = srcdata[nindex]; 176 177 vm = sqrt(vx*vx + vy*vy + vz*vz); 178 if (vm > max_mag) { 179 max_mag = vm; 180 } 181 if (vm < min_mag) { 182 min_mag = vm; 183 } 184 ++nread; 185 } 186 } 187 } 206 188 } 189 190 // make sure that we read all of the expected points 191 if (nread != nx*ny*nz) { 192 result.addError("inconsistent data: expected %d points" 193 " but found %d points", nx*ny*nz, npts); 194 return false; 195 } 196 197 float *data = new float[4*nx*ny*nz]; 198 memset(data, 0, sizeof(float) * 4 * nx * ny * nz); 199 fprintf(stderr, "generating %dx%dx%d = %d points\n", nx, ny, nz, nx*ny*nz); 200 201 // generate the uniformly sampled data that we need for a volume 202 float *destPtr = data; 203 float *srcPtr = srcdata; 204 for (int iz=0; iz < nz; iz++) { 205 for (int iy=0; iy < ny; iy++) { 206 for (int ix=0; ix < nx; ix++) { 207 double vx, vy, vz, vm; 208 209 vx = srcPtr[0]; 210 vy = srcPtr[1]; 211 vz = srcPtr[2]; 212 213 vm = sqrt(vx*vx + vy*vy + vz*vz); 214 215 destPtr[0] = vm / max_mag; 216 destPtr[1] = vx /(2.0*max_mag) + 0.5; 217 destPtr[2] = vy /(2.0*max_mag) + 0.5; 218 destPtr[3] = vz /(2.0*max_mag) + 0.5; 219 srcPtr += 3; 220 destPtr += 4; 221 } 222 } 223 } 224 225 Volume *volPtr; 226 volPtr = NanoVis::load_volume(ivol, nx, ny, nz, 4, data, min_mag, max_mag, 227 0); 228 229 volPtr->xAxis.SetRange(x0, x0 + nx); 230 volPtr->yAxis.SetRange(y0, y0 + ny); 231 volPtr->zAxis.SetRange(z0, z0 + nz); 232 volPtr->wAxis.SetRange(min_mag, max_mag); 233 volPtr->update_pending = true; 234 volPtr->setPhysicalBBox(physicalMin, physicalMax); 235 delete [] data; 207 236 return true; 208 237 }
Note: See TracChangeset
for help on using the changeset viewer.