1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * ---------------------------------------------------------------------- |
---|
4 | * PlaneRenderer.cpp : PlaneRenderer class for volume visualization |
---|
5 | * |
---|
6 | * ====================================================================== |
---|
7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
9 | * |
---|
10 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
11 | * |
---|
12 | * See the file "license.terms" for information on usage and |
---|
13 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | * ====================================================================== |
---|
15 | */ |
---|
16 | |
---|
17 | #include <GL/glew.h> |
---|
18 | |
---|
19 | #include "PlaneRenderer.h" |
---|
20 | #include "Trace.h" |
---|
21 | |
---|
22 | PlaneRenderer::PlaneRenderer(int width, int height) : |
---|
23 | _activePlane(-1), |
---|
24 | _numPlanes(0), |
---|
25 | _renderWidth(width), |
---|
26 | _renderHeight(height), |
---|
27 | _shader(new NvColorTableShader()) |
---|
28 | { |
---|
29 | _plane.clear(); |
---|
30 | _tf.clear(); |
---|
31 | } |
---|
32 | |
---|
33 | PlaneRenderer::~PlaneRenderer() |
---|
34 | { |
---|
35 | delete _shader; |
---|
36 | } |
---|
37 | |
---|
38 | int |
---|
39 | PlaneRenderer::addPlane(Texture2D *planeTexture, TransferFunction *tf) |
---|
40 | { |
---|
41 | int ret = _numPlanes; |
---|
42 | |
---|
43 | _plane.push_back(planeTexture); |
---|
44 | _tf.push_back(tf); |
---|
45 | |
---|
46 | if (ret == 0) |
---|
47 | _activePlane = ret; |
---|
48 | |
---|
49 | _numPlanes++; |
---|
50 | return ret; |
---|
51 | } |
---|
52 | |
---|
53 | void |
---|
54 | PlaneRenderer::removePlane(int index) |
---|
55 | { |
---|
56 | std::vector<Texture2D *>::iterator piter = _plane.begin()+index; |
---|
57 | std::vector<TransferFunction *>::iterator tfiter = _tf.begin()+index; |
---|
58 | |
---|
59 | _plane.erase(piter); |
---|
60 | _tf.erase(tfiter); |
---|
61 | |
---|
62 | _numPlanes--; |
---|
63 | } |
---|
64 | |
---|
65 | void |
---|
66 | PlaneRenderer::render() |
---|
67 | { |
---|
68 | if (_numPlanes == 0) |
---|
69 | return; |
---|
70 | |
---|
71 | glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); |
---|
72 | |
---|
73 | glEnable(GL_TEXTURE_2D); |
---|
74 | glEnable(GL_BLEND); |
---|
75 | |
---|
76 | glViewport(0, 0, _renderWidth, _renderHeight); |
---|
77 | glMatrixMode(GL_PROJECTION); |
---|
78 | glPushMatrix(); |
---|
79 | glLoadIdentity(); |
---|
80 | gluOrtho2D(0, _renderWidth, 0, _renderHeight); |
---|
81 | glMatrixMode(GL_MODELVIEW); |
---|
82 | glPushMatrix(); |
---|
83 | glLoadIdentity(); |
---|
84 | |
---|
85 | //glColor3f(1., 1., 1.); //MUST HAVE THIS LINE!!! |
---|
86 | |
---|
87 | //if no active plane |
---|
88 | if (_activePlane == -1) |
---|
89 | return; |
---|
90 | |
---|
91 | _shader->bind(_plane[_activePlane], _tf[_activePlane]); |
---|
92 | glBegin(GL_QUADS); |
---|
93 | glTexCoord2f(0, 0); glVertex2f(0, 0); |
---|
94 | glTexCoord2f(1, 0); glVertex2f(_renderWidth, 0); |
---|
95 | glTexCoord2f(1, 1); glVertex2f(_renderWidth, _renderHeight); |
---|
96 | glTexCoord2f(0, 1); glVertex2f(0, _renderHeight); |
---|
97 | glEnd(); |
---|
98 | _shader->unbind(); |
---|
99 | |
---|
100 | glMatrixMode(GL_PROJECTION); |
---|
101 | glPopMatrix(); |
---|
102 | |
---|
103 | glMatrixMode(GL_MODELVIEW); |
---|
104 | glPopMatrix(); |
---|
105 | |
---|
106 | glPopAttrib(); |
---|
107 | } |
---|
108 | |
---|
109 | void |
---|
110 | PlaneRenderer::setActivePlane(int index) |
---|
111 | { |
---|
112 | _activePlane = index; |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | PlaneRenderer::setScreenSize(int w, int h) |
---|
117 | { |
---|
118 | _renderWidth = w; |
---|
119 | _renderHeight = h; |
---|
120 | } |
---|