[4] | 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 | #include "global.h" |
---|
| 36 | #include "vGeometry.h" |
---|
| 37 | #include "VectorMath.h" //usefull vector/matrix operations |
---|
| 38 | #include "MatrixMath.h" |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | static float geomColor[6][4] = {{0.5f,0.0f,1.0f,1.0f}, |
---|
| 42 | {0.0f,0.5f,1.0f,1.0f}, |
---|
| 43 | {0.0f,1.0f,0.5f,1.0f}, |
---|
| 44 | {1.0f,0.5f,0.0f,1.0f}, |
---|
| 45 | {1.0f,0.0f,0.5f,1.0f}, |
---|
| 46 | {0.5f,0.0f,1.0f,1.0f}}; |
---|
| 47 | static float geomAxes[6][3] = {{0.0,1.0,1.0}, |
---|
| 48 | {1.0,1.0,0.0}, |
---|
| 49 | {1.0,0.0,1.0}, |
---|
| 50 | {0.5,0.0,1.0}, |
---|
| 51 | {1.0,0.0,0.5}, |
---|
| 52 | {1.0,0.5,0.0}}; |
---|
| 53 | static int geomIdx = 0; |
---|
| 54 | //only one geometry in this case |
---|
| 55 | vGeometry::vGeometry(NetVertexBuffer* vb) :vPrimitive() { |
---|
| 56 | opClient = NULL; |
---|
| 57 | indexList = 0; |
---|
| 58 | curFrame = 0; |
---|
| 59 | initScale = 1.0f; |
---|
| 60 | NetVertexBuffer* tmp = (NetVertexBuffer* )malloc(sizeof(NetVertexBuffer)); |
---|
| 61 | tmp->copy(vb); |
---|
| 62 | cache.push_back(tmp); |
---|
| 63 | numFrames = 1; |
---|
| 64 | color[0] = geomColor[geomIdx][0]; |
---|
| 65 | color[1] = geomColor[geomIdx][1]; |
---|
| 66 | color[2] = geomColor[geomIdx][2]; |
---|
| 67 | color[3] = geomColor[geomIdx][3]; |
---|
| 68 | axes[0] = geomAxes[geomIdx][0]; |
---|
| 69 | axes[1] = geomAxes[geomIdx][1]; |
---|
| 70 | axes[2] = geomAxes[geomIdx][2]; |
---|
| 71 | angle = 0.0f; |
---|
| 72 | geomIdx ++; |
---|
| 73 | geomIdx = geomIdx%6; |
---|
| 74 | //pb = 0; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | //may have an animation of geometry |
---|
| 78 | vGeometry::vGeometry(char* wildcard, char* serverName, float scale = 1.0f) |
---|
| 79 | { |
---|
| 80 | opClient = new cDataManagerClient((char*)serverName); |
---|
| 81 | fprintf(stderr,"vGeometry::vGeometry %s \n",wildcard); |
---|
| 82 | opClient->Open(); |
---|
| 83 | opClient->Init(); |
---|
| 84 | int num_datasets = opClient->Query(); |
---|
| 85 | |
---|
| 86 | indexList = 0; |
---|
| 87 | numFrames= opClient->GetMatching(wildcard,indexList); |
---|
| 88 | if (!numFrames) { |
---|
| 89 | fprintf(stderr,"ERROR: Cant find any geometry matching %s in Optistore\n",wildcard); |
---|
| 90 | exit(1); |
---|
| 91 | } |
---|
| 92 | fprintf(stderr,"Number of frames %d\n",numFrames); |
---|
| 93 | cache.resize(numFrames,NULL); //initialise the cache with null |
---|
| 94 | curFrame = 0; |
---|
| 95 | initScale = scale; |
---|
| 96 | color[0] = geomColor[geomIdx][0]; |
---|
| 97 | color[1] = geomColor[geomIdx][1]; |
---|
| 98 | color[2] = geomColor[geomIdx][2]; |
---|
| 99 | color[3] = geomColor[geomIdx][3]; |
---|
| 100 | axes[0] = geomAxes[geomIdx][0]; |
---|
| 101 | axes[1] = geomAxes[geomIdx][1]; |
---|
| 102 | axes[2] = geomAxes[geomIdx][2]; |
---|
| 103 | angle = 0.0f; |
---|
| 104 | geomIdx ++; |
---|
| 105 | geomIdx = geomIdx%6; |
---|
| 106 | |
---|
| 107 | //pb = 0; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | vGeometry::~vGeometry() { |
---|
| 113 | fprintf(stderr,"~vGeometry() after opClient->Exit()\n"); |
---|
| 114 | if (numFrames) { |
---|
| 115 | for (int i=0;i<numFrames;i++) { |
---|
| 116 | if (cache[i]) { |
---|
| 117 | cache[i]->freeArrays(); |
---|
| 118 | free(cache[i]); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | if (indexList) |
---|
| 123 | free(indexList); |
---|
| 124 | if (opClient) |
---|
| 125 | opClient->Exit(); |
---|
| 126 | |
---|
| 127 | /*if (pb) { |
---|
| 128 | free(pb->vertex); |
---|
| 129 | free(pb); |
---|
| 130 | } |
---|
| 131 | */ |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | //checks if the curframe is loaded, if not grabs it from the server |
---|
| 136 | void vGeometry::setCurFrame(int curFrame) { |
---|
| 137 | if (cache[curFrame] == NULL) {//get file from server |
---|
| 138 | opClient->Load(indexList[curFrame]);//get the index of this frame |
---|
| 139 | NetVertexBuffer* vb = opClient->Isosurface(1, 1, 0.20); // fake values |
---|
| 140 | cache[curFrame] = (NetVertexBuffer* )malloc(sizeof(NetVertexBuffer)); |
---|
| 141 | cache[curFrame]->copy(vb); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | } |
---|
| 145 | //get the first geometry if its animation |
---|
| 146 | void vGeometry::init() { |
---|
| 147 | fprintf(stderr,"Loading cur frame %d index %d\n",curFrame, indexList[curFrame]); |
---|
| 148 | setCurFrame(0); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void vGeometry::next() { |
---|
| 152 | curFrame++; |
---|
| 153 | fprintf(stderr,"next frame %d\n",curFrame); |
---|
| 154 | if (curFrame >= numFrames) |
---|
| 155 | curFrame = 0; |
---|
| 156 | setCurFrame(curFrame); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | void vGeometry::prev() { |
---|
| 160 | curFrame--; |
---|
| 161 | if (curFrame < 0) |
---|
| 162 | curFrame = numFrames-1; |
---|
| 163 | setCurFrame(curFrame); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | void vGeometry::drawBoundBox() { |
---|
| 167 | glDisable(GL_LIGHTING); |
---|
| 168 | glPushMatrix(); |
---|
| 169 | glTranslatef(-0.5f,-0.5f,-0.5f); |
---|
| 170 | glBegin(GL_LINES); |
---|
| 171 | glColor3f(0.0f,0.5f,0.5f); |
---|
| 172 | glVertex3f(1.0f,1.0f,1.0f); |
---|
| 173 | glVertex3f(1.0f,1.0f,0.0f); |
---|
| 174 | glVertex3f(1.0f,0.0f,1.0f); |
---|
| 175 | glVertex3f(1.0f,0.0f,0.0f); |
---|
| 176 | glVertex3f(0.0f,1.0f,1.0f); |
---|
| 177 | glVertex3f(0.0f,1.0f,0.0f); |
---|
| 178 | glVertex3f(0.0f,0.0f,1.0f); |
---|
| 179 | glVertex3f(0.0f,0.0f,0.0f); |
---|
| 180 | glVertex3f(1.0f,1.0f,1.0f); |
---|
| 181 | glVertex3f(1.0f,0.0f,1.0f); |
---|
| 182 | glVertex3f(1.0f,1.0f,0.0f); |
---|
| 183 | glVertex3f(1.0f,0.0f,0.0f); |
---|
| 184 | glVertex3f(0.0f,1.0f,1.0f); |
---|
| 185 | glVertex3f(0.0f,0.0f,1.0f); |
---|
| 186 | glVertex3f(0.0f,1.0f,0.0f); |
---|
| 187 | glVertex3f(0.0f,0.0f,0.0f); |
---|
| 188 | glVertex3f(1.0f,1.0f,1.0f); |
---|
| 189 | glVertex3f(0.0f,1.0f,1.0f); |
---|
| 190 | glVertex3f(1.0f,1.0f,0.0f); |
---|
| 191 | glVertex3f(0.0f,1.0f,0.0f); |
---|
| 192 | glVertex3f(1.0f,0.0f,1.0f); |
---|
| 193 | glVertex3f(0.0f,0.0f,1.0f); |
---|
| 194 | glVertex3f(1.0f,0.0f,0.0f); |
---|
| 195 | glVertex3f(0.0f,0.0f,0.0f); |
---|
| 196 | glEnd(); |
---|
| 197 | glPopMatrix(); |
---|
| 198 | glEnable(GL_LIGHTING); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | //draws the triangele strip here |
---|
| 202 | void vGeometry::draw() |
---|
| 203 | { |
---|
| 204 | int i,l; |
---|
| 205 | glPushMatrix(); |
---|
| 206 | glPushAttrib(GL_ALL_ATTRIB_BITS); |
---|
| 207 | glTranslatef(xform.trans[0], xform.trans[1], xform.trans[2]); |
---|
| 208 | glMultMatrixf(xform.rotn); |
---|
| 209 | glScalef(xform.scale, xform.scale,xform.scale); |
---|
| 210 | if (selected) |
---|
| 211 | drawBoundBox(); |
---|
| 212 | glTranslatef(-0.5,-0.5,-0.5); |
---|
| 213 | glScalef(initScale, initScale,initScale); |
---|
| 214 | glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); |
---|
| 215 | if (cache[curFrame]) { |
---|
| 216 | glEnable(GL_NORMALIZE); |
---|
| 217 | glEnableClientState(GL_VERTEX_ARRAY); |
---|
| 218 | glVertexPointer(3,GL_FLOAT,0, cache[curFrame]->vertex); |
---|
| 219 | |
---|
| 220 | //glEnableClientState(GL_COLOR_ARRAY); |
---|
| 221 | //glColorPointer(4,GL_UNSIGNED_BYTE,0,(void* )((GLubyte* )diffuse)); |
---|
| 222 | glDisableClientState(GL_COLOR_ARRAY); |
---|
| 223 | |
---|
| 224 | glEnableClientState(GL_NORMAL_ARRAY); |
---|
| 225 | glNormalPointer(GL_FLOAT,0, cache[curFrame]->normal); |
---|
| 226 | //glDisableClientState(GL_NORMAL_ARRAY); |
---|
| 227 | |
---|
| 228 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
---|
| 229 | //glPolygonMode(GL_FRONT, GL_LINE); |
---|
| 230 | //glPolygonMode(GL_BACK, GL_LINE); |
---|
| 231 | |
---|
| 232 | for(i = 0,l = 0; i < cache[curFrame]->lengths; l += cache[curFrame]->length[i],i++) |
---|
| 233 | { |
---|
| 234 | glDrawElements(GL_TRIANGLE_STRIP, |
---|
| 235 | cache[curFrame]->length[i],GL_UNSIGNED_INT,&(((GLuint* )cache[curFrame]->index)[l])); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | glDisable(GL_NORMAL_ARRAY); |
---|
| 239 | //glDisable(GL_VERTEX_ARRAY); |
---|
| 240 | } |
---|
| 241 | /* |
---|
| 242 | if (pb) { |
---|
| 243 | glBegin(GL_POINTS); // draw some points |
---|
| 244 | for (int i=0;i<pb->nbpts;i++) |
---|
| 245 | glVertex3f(pb->vertex[i*3+0],pb->vertex[i*3+1],pb->vertex[i*3+2]); |
---|
| 246 | glEnd(); |
---|
| 247 | } |
---|
| 248 | */ |
---|
| 249 | glPopAttrib(); |
---|
| 250 | glPopMatrix(); |
---|
| 251 | return; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | //for the pointer |
---|
| 255 | /* |
---|
| 256 | float geomVertexList[8][3] = {{0,0,0},{1.0f,0,0},{0,1.0f,0},{1.0f,1.0f,0},{0,0,1.0f},{1.0f,0,1.0f},{0,1.0f,1.0f},{1.0f,1.0f,1.0f}}; |
---|
| 257 | int vGeometry::select() { |
---|
| 258 | if (withinBounds3D(mv,geomVertexList,global.pointerPos)) { |
---|
| 259 | selected = 1; |
---|
| 260 | } |
---|
| 261 | else |
---|
| 262 | selected = 0; |
---|
| 263 | return selected; |
---|
| 264 | } |
---|
| 265 | */ |
---|
| 266 | |
---|
| 267 | /* |
---|
| 268 | vGeometry::vGeometry(NetPointBuffer* thePoints) :vPrimitive() { |
---|
| 269 | pb = (NetPointBuffer* )malloc(sizeof(NetPointBuffer)); |
---|
| 270 | pb->nbpts = thePoints->nbpts; |
---|
| 271 | pb->vertex = (float* )malloc(sizeof(float)*pb->nbpts*3); |
---|
| 272 | numFrames = curFrame = 0; |
---|
| 273 | } |
---|
| 274 | */ |
---|