source: trunk/src/testing/app/volvis/vSliceView.cpp @ 4

Revision 4, 6.4 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#include "vSliceView.h"
36#include "vCG.h"
37#include "vARB.h"
38#include "MatrixMath.h"
39
40vProbe::vProbe() :vPrimitive() {
41        xform.scale = 1.0f/(float)global.volume->maxDim;
42}
43
44//do opngl initialization here
45void vProbe::init() {
46}
47
48vProbe::~vProbe() {
49}
50
51//draws the cone here
52void vProbe::draw()
53{
54        color[0] = 0.0f;
55        color[1] = 1.0f;
56        color[2] = 0.0f;
57        glPushMatrix();
58        glPushAttrib(GL_ALL_ATTRIB_BITS);
59        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
60        glTranslatef(xform.trans[0],xform.trans[1],xform.trans[2]);
61        glMultMatrixf(xform.rotn);
62        glutSolidSphere(xform.scale,20,20);
63        glPopAttrib();
64        glPopMatrix();
65        return;
66}
67
68float sliceDim = 0.6f;
69float sliceVertexList[4][3] = {{0.0f, 0.0f, 0.0f},
70                                {0.0f, 1.0f, 0.0f},
71                                {1.0f, 1.0f, 0.0f},
72                                {1.0f, 0.0f, 0.0f}};
73float polygonVertexList[4][3] = {{-sliceDim*3.0f, -sliceDim, 0.0f},
74                                {-sliceDim*3.0f, sliceDim, 0.0f},
75                                {sliceDim*3.0f, sliceDim, 0.0f},
76                                {sliceDim*3.0f, -sliceDim, 0.0f}};
77float sepVertexList[2][4] = {{sliceDim+0.5f,sliceDim+0.5f, 0.0f},
78                                {sliceDim+0.5f, 0.5-sliceDim, 0.0f, 1.0f}};
79
80vSliceView::vSliceView() :vPrimitive() {
81        setTranslation(0.0f,-2.0f,0.0f);
82}
83
84//do opngl initialization here
85void vSliceView::init() {
86}
87
88vSliceView::~vSliceView() {
89}
90
91
92void vSliceView::draw() {
93        //draw slice view
94#if defined(ADDCGGL)
95        setCurTextureCG(global.volren.origDeptexName);
96#endif
97#if defined(ADDARBGL)
98        setCurTextureARB(global.volren.origDeptexName);
99#endif
100        float xptr, yptr, zptr;         //location of the probe in the volume
101        global.volume->getNormProbe(xptr,yptr,zptr);//between 0..1
102        axialProbe.setTranslation(xptr,1.0f-zptr,0.0f);
103        coronalProbe.setTranslation(xptr,yptr,0.0f);
104        sagittalProbe.setTranslation(1.0f-zptr,yptr,0.0f);
105
106        //push the slicevew down
107        glPushMatrix();
108        glPushAttrib(GL_ALL_ATTRIB_BITS);
109        glTranslatef(xform.trans[0], xform.trans[1], xform.trans[2]);
110        glMultMatrixf(xform.rotn);
111        glScalef(xform.scale,xform.scale,xform.scale);
112        disableTex3D();
113        glDisable(GL_LIGHTING);
114        glLineWidth(0.5f);
115        if (selected)
116                glColor3f(0.5f,0.5f,0.0f);
117        else
118                glColor3f(0.5f,0.5f,0.5f);
119        glBegin(GL_LINE_LOOP); //draw slice and texture map it
120                glVertex3fv(polygonVertexList[0]);
121                glVertex3fv(polygonVertexList[1]);
122                glVertex3fv(polygonVertexList[2]);
123                glVertex3fv(polygonVertexList[3]);
124        glEnd();
125        enableTex3D(global.volume->texName);
126        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
127
128        //the axial view, takes the y direction to index into the volume
129        glPushMatrix();
130        glTranslatef(-sliceDim*2,0.0f,0.0f);
131        glTranslatef(-0.5f,-0.5f,0.0f);
132        disableTex3D();
133        axialProbe.draw();
134        glBegin(GL_LINES);
135                glVertex3fv(sepVertexList[0]);
136                glVertex3fv(sepVertexList[1]);
137        glEnd();
138        //get the modelview matrix, multiply the pointer posn to see if it intersects this object
139
140        enableTex3D(global.volume->texName);
141        glBegin(GL_POLYGON); //draw slice and texture map it
142                glTexCoord3f(0.0f, yptr, 0.0f);
143                glVertex3fv(sliceVertexList[1]);
144                glTexCoord3f(0.0f, yptr, 1.0f);
145                glVertex3fv(sliceVertexList[0]);
146                glTexCoord3f(1.0f, yptr, 1.0f);
147                glVertex3fv(sliceVertexList[3]);
148                glTexCoord3f(1.0f, yptr, 0.0f);
149                glVertex3fv(sliceVertexList[2]);
150        glEnd();
151        glPopMatrix();
152
153        //the coronal view, takes the z
154        glPushMatrix();
155        glTranslatef(0.0f,0.0f,0.0f);
156        glTranslatef(-0.5f,-0.5f,0.0f);
157        disableTex3D();
158        coronalProbe.draw();
159        glBegin(GL_LINES);
160                glVertex3fv(sepVertexList[0]);
161                glVertex3fv(sepVertexList[1]);
162        glEnd();
163        enableTex3D(global.volume->texName);
164        glBegin(GL_POLYGON); //draw slice and texture map it
165                glTexCoord3f(0.0f, 0.0f, zptr);
166                glVertex3fv(sliceVertexList[0]);
167                glTexCoord3f(0.0f, 1.0f, zptr);
168                glVertex3fv(sliceVertexList[1]);
169                glTexCoord3f(1.0f, 1.0f, zptr);
170                glVertex3fv(sliceVertexList[2]);
171                glTexCoord3f(1.0f, 0.0f, zptr);
172                glVertex3fv(sliceVertexList[3]);
173        glEnd();
174        glPopMatrix();
175
176
177        //the sagittal view, takes the x
178        glPushMatrix();
179        glTranslatef(sliceDim*2,0.0f,0.0f);
180        //since we are starting (0..1)
181        glTranslatef(-0.5f,-0.5f,0.0f);
182        disableTex3D();
183        sagittalProbe.draw();
184        enableTex3D(global.volume->texName);
185        glBegin(GL_POLYGON); //draw slice and texture map it
186                glTexCoord3f(xptr, 0.0f, 0.0f);
187                glVertex3fv(sliceVertexList[3]);
188                glTexCoord3f(xptr, 0.0f, 1.0f);
189                glVertex3fv(sliceVertexList[0]);
190                glTexCoord3f(xptr, 1.0f, 1.0f);
191                glVertex3fv(sliceVertexList[1]);
192                glTexCoord3f(xptr, 1.0f, 0.0f);
193                glVertex3fv(sliceVertexList[2]);
194        glEnd();
195        glPopMatrix();
196
197        glPopAttrib();
198        glPopMatrix();
199}
200
201/*
202int vSliceView::select() {
203        if (withinBounds2D(mv,polygonVertexList,global.pointerPos)) {
204                selected = 1;
205        }
206        else
207                selected = 0;
208        return selected;
209}
210*/
Note: See TracBrowser for help on using the repository browser.