source: trunk/src/testing/app/volvis/vVolume.h @ 4

Revision 4, 6.8 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/********************************************************************************
2 * Volatile - Volume Visualization Software for SAGE
3 * Copyright (C) 2004 Electronic Visualization Laboratory,
4 * University of Illinois at Chicago
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 *  * Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *  * Redistributions in binary form must reproduce the above
14 *    copyright notice, this list of conditions and the following disclaimer
15 *    in the documentation and/or other materials provided with the distribution.
16 *  * Neither the name of the University of Illinois at Chicago nor
17 *    the names of its contributors may be used to endorse or promote
18 *    products derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Direct questions, comments etc about Volatile to www.evl.uic.edu/cavern/forum
33 *********************************************************************************/
34
35#ifndef _VVOLUME_H_
36#define _VVOLUME_H_
37#include "mmap.h"
38#include "private.h"
39#include "caDataManagerClient.h"
40#include <vector>
41
42#define H2D_DIM 256*256
43//for one timestep volume
44class vFrameData {
45public:
46        GLubyte* voxelData;
47        unsigned char* gradData;
48        unsigned char* hist;
49        QUANTAts_mutex_c histMutex;
50
51        vFrameData() {
52                voxelData = gradData = hist = 0;
53        }
54};
55
56//This class defines a volume
57class vVolume {
58public:
59        //row, column and depth of volume thats loaded into gfx
60        unsigned int dimX, dimY, dimZ;
61        unsigned int maxDim; //maximum dimension
62        //dimensions of the whole volume - on file
63        unsigned int fileX, fileY, fileZ;
64        //offset into the whole volume to read the subvolume
65        unsigned int offsetX, offsetY, offsetZ;
66        //spacing into the whole volume to read the subvolume
67        float spacingX, spacingY, spacingZ;
68        //current probe point
69        unsigned int probeX, probeY, probeZ;
70        vector<vFrameData> cache; //pointer to the time-series volume
71        int curVolume, numVolumes; //no of volumes and the current volume index
72        int probeValue, isoValue; //current value of the probe
73        unsigned int texName; //name of 3D texture associated with this volume
74//Member functions
75        vVolume(int x, int y, int z); //size of the whole volume
76        virtual ~vVolume();
77        //here is where the volume is actually loaded
78        //needs to be overloaded
79        virtual void load(int loadx, int loady, int loadz) = 0;
80        virtual void load() = 0;
81        //roaming the volume - overload this
82        virtual void roam(int roamx, int roamy, int roamz) = 0;
83        virtual int hist2D(unsigned char *normHist);
84        virtual int hist1D(unsigned char *normHist);
85        virtual void saveVolume(const char* filename);
86        virtual void saveGradient(const char* filename = "grad");
87        virtual void probe(int probeX, int probeY, int probeZ);
88        virtual void next() = 0;
89        virtual void prev() = 0;
90        //sets the vol dims/does power of 2 checking etc
91        void setLoadDims(int x, int y, int z) ;
92        virtual NetVertexBuffer* isoSurface() = 0;
93        virtual NetPointBuffer* isoPoint() = 0;
94
95        inline GLubyte getValue(int d, int r, int c) {
96                return cache[curVolume].voxelData[d*dimY*dimX+r*dimX+c];
97        }
98
99        inline void setValue(int d, int r, int c, GLubyte value) {
100                cache[curVolume].voxelData[d*dimY*dimX+r*dimX+c] = value;
101        }
102
103        inline GLubyte* getVoxelData() {
104                return cache[curVolume].voxelData;
105        }
106
107        inline void getNormProbe(float& x, float& y, float& z) {
108                x = (float)probeX/(float)(dimX-1);
109                y = (float)probeY/(float)(dimY-1);
110                z = (float)probeZ/(float)(dimZ-1);
111        }
112
113        inline void getNormOffset(float& x, float& y, float& z) {
114                x = (float)offsetX/(float)(fileX-1);
115                y = (float)offsetY/(float)(fileY-1);
116                z = (float)offsetZ/(float)(fileZ-1);
117        }
118
119        inline void getNormDim(float& x, float& y, float& z) {
120                x = (float)dimX/(float)(fileX);
121                y = (float)dimY/(float)(fileY);
122                z = (float)dimZ/(float)(fileZ);
123        }
124
125        inline void incIsoValue(int inc) {
126                isoValue += inc;
127                if (isoValue > 255)
128                        isoValue = 255;
129                if (isoValue < 0)
130                        isoValue = 0;
131                fprintf(stderr,"Isovalue now is %d\n",isoValue);
132        }
133        inline int getIsoValue() {
134                return isoValue;
135        }
136        inline int setIsoValue(int i) {
137                isoValue = i;
138        }
139};
140#if 0
141//class that handle volume access from a file
142class vFileVolume: public vVolume {
143public:
144        //if the volume is smaller than the volume in file, we need to pad it equally
145        unsigned int padX, padY, padZ;
146        char filename[256]; //filename associated with this 3d texture
147        char*   gradientFile; //gradient file associated with this 3d texture
148        Mmap    mmap;
149        unsigned char* fileBuffer;
150
151//public member functions
152        vFileVolume(const char* filename, int c, int r, int d);
153        virtual ~vFileVolume();
154        void load(int x, int y, int z);
155        void load() {load(fileX,fileY,fileZ);};
156        //void roam(int roamx, int roamy, int roamz);
157private:
158        void loadVolumeFromFile(const char* filename);
159        void loadGradientFromFile(const char* filename); //load gradient info from file
160        void padVolume();//if volsize > filesize, pad the volume with black
161        void readASlice(GLubyte* plane, unsigned char* &curFilePtr) ; //read one plane from file
162        //if the volume is bigger than the file size, this will pad the volume
163        void calcGradient();
164};
165#endif
166//class to handle volume access from a data server
167class vOptiVolume: public vVolume {
168public:
169    cDataManagerClient* opClient; //pointer to the op client
170        int* indexList;
171        bool updateHist;
172//public member functions
173        vOptiVolume(const char*, const char*);
174        virtual ~vOptiVolume();
175        void load(int x, int y, int z);
176        void load();
177        void roam(int roamx, int roamy, int roamz);
178        int hist2D(unsigned char *normHist);
179        //get isosurface from opClient
180        NetVertexBuffer* isoSurface();
181        NetPointBuffer* isoPoint();
182        //void hist1D(unsigned char *normHist);
183        void setUpdateHist(bool flag) ;
184        bool getUpdateHist() ;
185        void next();
186        void prev();
187        void setCurVolume(int curVolume) ;
188};
189#endif
190
Note: See TracBrowser for help on using the repository browser.