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 | //Class vOptiVolume: defines a 3d volume that is accessed through a server
|
---|
36 | //This class only manages the data(doesnt do the rendering)
|
---|
37 | //Shalini Venkataraman, Luc Renambot
|
---|
38 | //Sep 7 2003
|
---|
39 | #include <math.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <string.h>
|
---|
43 | #include "glUE.h"
|
---|
44 | #include "vVolume.h"
|
---|
45 | #include "VectorMath.h"
|
---|
46 | #include "global.h"
|
---|
47 |
|
---|
48 | //mutex for the update histogram
|
---|
49 | //the transfer fn thread also acceses the histogram
|
---|
50 | QUANTAts_mutex_c mutex;
|
---|
51 |
|
---|
52 | //constructor
|
---|
53 | vOptiVolume::vOptiVolume(const char* volName, const char* serverName):vVolume(0,0,0)
|
---|
54 | {
|
---|
55 | opClient = new cDataManagerClient((char*)serverName);
|
---|
56 | fprintf(stderr,"vOptiVolume::vOptiVolume %s\n",volName);
|
---|
57 | opClient->Open();
|
---|
58 | opClient->Init();
|
---|
59 | int numData = opClient->Query();
|
---|
60 |
|
---|
61 | numVolumes= opClient->GetMatching((char*)volName,indexList);
|
---|
62 | if (!numVolumes) {
|
---|
63 | fprintf(stderr,"ERROR: Cant find any volumes matching %s in Optistore\n",volName);
|
---|
64 | exit(1);
|
---|
65 | }
|
---|
66 | cache.resize(numVolumes);
|
---|
67 | opClient->GetDataDims(indexList[0],fileX, fileY, fileZ);
|
---|
68 | fprintf(stderr,"vOptiVolume file Dims %d %d %d\n",fileX, fileY, fileZ);
|
---|
69 | offsetX = offsetY = offsetZ = 0;
|
---|
70 | updateHist = false;
|
---|
71 | isoValue = 128;
|
---|
72 | curVolume = 0;
|
---|
73 | }
|
---|
74 |
|
---|
75 | //destructor
|
---|
76 | vOptiVolume::~vOptiVolume() {
|
---|
77 | opClient->Exit();
|
---|
78 | free(indexList);
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool vOptiVolume::getUpdateHist() {
|
---|
82 | bool ret;
|
---|
83 | mutex.lock();
|
---|
84 | ret = updateHist;
|
---|
85 | mutex.unlock();
|
---|
86 | return ret;
|
---|
87 | }
|
---|
88 |
|
---|
89 | void vOptiVolume::setUpdateHist(bool flag) {
|
---|
90 | mutex.lock();
|
---|
91 | updateHist = flag;
|
---|
92 | mutex.unlock();
|
---|
93 | }
|
---|
94 |
|
---|
95 | int vOptiVolume::hist2D(unsigned char* normHist) {
|
---|
96 | // Get 2D histogram of volume+gradient
|
---|
97 | if (getUpdateHist()) { //if we have a new hist for the volume, copy it
|
---|
98 | cache[curVolume].histMutex.lock();
|
---|
99 | if (cache[curVolume].hist) {//if we have a hist send it
|
---|
100 | memcpy(normHist,cache[curVolume].hist,H2D_DIM*sizeof(unsigned char));
|
---|
101 | cache[curVolume].histMutex.unlock();
|
---|
102 | setUpdateHist(false);
|
---|
103 | return 1;
|
---|
104 | }
|
---|
105 | else
|
---|
106 | cache[curVolume].histMutex.unlock();
|
---|
107 | }
|
---|
108 | return 0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void vOptiVolume::load() {
|
---|
112 | load(fileX, fileY, fileZ);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void vOptiVolume::setCurVolume(int curVolume) {
|
---|
116 | if (!cache[curVolume].voxelData) {//get from server
|
---|
117 | opClient->Load(indexList[curVolume]);
|
---|
118 | //opClient->Resample(dimX,dimY,dimZ);
|
---|
119 | opClient->Crop(offsetX, offsetY, offsetZ ,offsetX+dimX-1,offsetY+dimY-1, offsetZ+dimZ-1);
|
---|
120 | cache[curVolume].voxelData = new GLubyte[dimX*dimY*dimZ];
|
---|
121 | memcpy(cache[curVolume].voxelData,opClient->Volume(),dimX*dimY*dimZ*sizeof(GLubyte));
|
---|
122 | cache[curVolume].histMutex.lock();
|
---|
123 | cache[curVolume].hist = new unsigned char[H2D_DIM ];
|
---|
124 | //memcpy(cache[curVolume].hist,opClient->Histogram2D(),H2D_DIM*sizeof(unsigned char));
|
---|
125 | cache[curVolume].histMutex.unlock();
|
---|
126 | }
|
---|
127 | setUpdateHist(true); //amy listeners will have to update their hist
|
---|
128 | }
|
---|
129 |
|
---|
130 | void vOptiVolume::next() {
|
---|
131 | curVolume++;
|
---|
132 | if (curVolume >= numVolumes)
|
---|
133 | curVolume = 0;
|
---|
134 | setCurVolume(curVolume);
|
---|
135 | }
|
---|
136 |
|
---|
137 | void vOptiVolume::prev() {
|
---|
138 | curVolume--;
|
---|
139 | if (curVolume < 0)
|
---|
140 | curVolume = numVolumes-1;
|
---|
141 | setCurVolume(curVolume);
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 | void vOptiVolume::load(int loadx, int loady, int loadz) {
|
---|
147 | setLoadDims(loadx, loady, loadz); //does the power of 2 conversion here if needed
|
---|
148 | setCurVolume(0);
|
---|
149 | }
|
---|
150 |
|
---|
151 | void vOptiVolume::roam(int roamX, int roamY, int roamZ) {
|
---|
152 | //calculate new offset(cos the orig offset is unsigned..)
|
---|
153 | int newOffsetX = offsetX + roamX;
|
---|
154 | int newOffsetY = offsetY + roamY;
|
---|
155 | int newOffsetZ = offsetZ + roamZ;
|
---|
156 | //have to minus 1 since the bounds in Optistore are inclusive
|
---|
157 | int cropX = dimX-1;//so if dimX = 64, crop from (0,0,0) ->(63,63,63)
|
---|
158 | int cropY = dimY-1;
|
---|
159 | int cropZ = dimZ-1;
|
---|
160 | //now check if the newoFfset is withing range if not make it
|
---|
161 | if (newOffsetX+cropX>= fileX) //eg (1+63) >=64 so, offset = 64-64 = 0
|
---|
162 | newOffsetX = fileX-dimX;
|
---|
163 | if (newOffsetY+cropY>= fileY)
|
---|
164 | newOffsetY = fileY-dimY;
|
---|
165 | if (newOffsetZ+cropZ >= fileZ)
|
---|
166 | newOffsetZ = fileZ-dimZ;
|
---|
167 | if (newOffsetX < 0)
|
---|
168 | newOffsetX = 0;
|
---|
169 | if (newOffsetY < 0)
|
---|
170 | newOffsetY = 0;
|
---|
171 | if (newOffsetZ < 0)
|
---|
172 | newOffsetZ = 0;
|
---|
173 | //copy to the offset
|
---|
174 | offsetX = newOffsetX;
|
---|
175 | offsetY = newOffsetY;
|
---|
176 | offsetZ = newOffsetZ;
|
---|
177 |
|
---|
178 | //at this point delete our cache
|
---|
179 | for (int i=0;i<cache.size();i++) {
|
---|
180 | delete [] cache[i].voxelData;
|
---|
181 | cache[i].voxelData = 0;
|
---|
182 | cache[i].histMutex.lock();
|
---|
183 | delete [] cache[i].hist;
|
---|
184 | cache[i].hist= 0;
|
---|
185 | cache[i].histMutex.unlock();
|
---|
186 | }
|
---|
187 | opClient->Crop(offsetX, offsetY, offsetZ ,offsetX+dimX-1,offsetY+dimY-1, offsetZ+dimZ-1);
|
---|
188 | cache[curVolume].voxelData = new GLubyte[dimX*dimY*dimZ];
|
---|
189 | memcpy(cache[curVolume].voxelData,opClient->Volume(),dimX*dimY*dimZ*sizeof(GLubyte));
|
---|
190 | cache[curVolume].histMutex.lock();
|
---|
191 | cache[curVolume].hist = new unsigned char[H2D_DIM ];
|
---|
192 | //memcpy(cache[curVolume].hist,opClient->Histogram2D(),H2D_DIM*sizeof(unsigned char));
|
---|
193 | cache[curVolume].histMutex.unlock();
|
---|
194 | setUpdateHist(true); //amy listeners will have to update their hist
|
---|
195 | }
|
---|
196 |
|
---|
197 | NetVertexBuffer* vOptiVolume::isoSurface() {
|
---|
198 | isoValue = probeValue;
|
---|
199 | return (opClient->Isosurface(isoValue, 1, 0.40f));
|
---|
200 | }
|
---|
201 |
|
---|
202 | NetPointBuffer* vOptiVolume::isoPoint() {
|
---|
203 | isoValue = probeValue;
|
---|
204 | return (opClient->IsoPoints(isoValue, 1, 8000));
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 |
|
---|