1 | /*
|
---|
2 | * ----------------------------------------------------------------------
|
---|
3 | * VolumeRenderer.h : VolumeRenderer class for volume visualization
|
---|
4 | *
|
---|
5 | * ======================================================================
|
---|
6 | * AUTHOR: Wei Qiao <qiaow@purdue.edu>
|
---|
7 | * Purdue Rendering and Perceptualization Lab (PURPL)
|
---|
8 | *
|
---|
9 | * Copyright (c) 2004-2006 Purdue Research Foundation
|
---|
10 | *
|
---|
11 | * See the file "license.terms" for information on usage and
|
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
---|
13 | * ======================================================================
|
---|
14 | */
|
---|
15 |
|
---|
16 | #ifndef _VOLUME_RENDERER_H_
|
---|
17 | #define _VOLUME_RENDERER_H_
|
---|
18 |
|
---|
19 | #include <GL/glew.h>
|
---|
20 | #include <Cg/cgGL.h>
|
---|
21 | #include <GL/glut.h>
|
---|
22 | #include <math.h>
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <assert.h>
|
---|
25 | #include <float.h>
|
---|
26 | #include <vector>
|
---|
27 |
|
---|
28 | #include "define.h"
|
---|
29 | #include "global.h"
|
---|
30 | #include "ConvexPolygon.h"
|
---|
31 | #include "TransferFunction.h"
|
---|
32 | #include "Mat4x4.h"
|
---|
33 | #include "Volume.h"
|
---|
34 | #include "ZincBlendeVolume.h"
|
---|
35 | #include "PerfQuery.h"
|
---|
36 | #include "NvRegularVolumeShader.h"
|
---|
37 | #include "NvZincBlendeVolumeShader.h"
|
---|
38 | #include "NvStdVertexShader.h"
|
---|
39 | #include "VolumeInterpolator.h"
|
---|
40 |
|
---|
41 | class VolumeRenderer {
|
---|
42 |
|
---|
43 | friend class NanoVis;
|
---|
44 | private:
|
---|
45 | std::vector <Volume*> volume; //!<- array of volumes
|
---|
46 | std::vector <TransferFunction*> tf; //!<- array of corresponding transfer functions
|
---|
47 | VolumeInterpolator* _volumeInterpolator;
|
---|
48 |
|
---|
49 | int n_volumes;
|
---|
50 |
|
---|
51 | bool slice_mode; //!<- enable cut planes
|
---|
52 | bool volume_mode; //!<- enable full volume rendering
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * shader parameters for rendering a single cubic volume
|
---|
56 | */
|
---|
57 | NvRegularVolumeShader* _regularVolumeShader;
|
---|
58 |
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Shader parameters for rendering a single zincblende orbital.
|
---|
62 | * A simulation contains S, P, D and SS, total of 4 orbitals. A full rendering requires 4 zincblende orbital volumes.
|
---|
63 | * A zincblende orbital volume is decomposed into two "interlocking" cubic volumes and passed to the shader.
|
---|
64 | * We render each orbital with its own independent transfer functions then blend the result.
|
---|
65 | *
|
---|
66 | * The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
|
---|
67 | * S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
|
---|
68 | * This is equivalent to rendering 4 unrelated data sets occupying the same space.
|
---|
69 | */
|
---|
70 | NvZincBlendeVolumeShader* _zincBlendeShader;
|
---|
71 |
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * standard vertex shader
|
---|
75 | */
|
---|
76 | NvStdVertexShader* _stdVertexShader;
|
---|
77 |
|
---|
78 | //standard vertex shader parameters
|
---|
79 | CGprogram m_vert_std_vprog;
|
---|
80 | CGparameter m_mvp_vert_std_param;
|
---|
81 | CGparameter m_mvi_vert_std_param;
|
---|
82 |
|
---|
83 | void init_shaders();
|
---|
84 | void activate_volume_shader(Volume* vol, TransferFunction* tf, bool slice_mode);
|
---|
85 | void deactivate_volume_shader();
|
---|
86 |
|
---|
87 | //draw bounding box
|
---|
88 | void draw_bounding_box(float x0, float y0, float z0,
|
---|
89 | float x1, float y1, float z1,
|
---|
90 | float r, float g, float b, float line_width);
|
---|
91 |
|
---|
92 | void get_near_far_z(Mat4x4 mv, double &zNear, double &zFar);
|
---|
93 |
|
---|
94 | void init_font(const char* filename);
|
---|
95 | GLuint font_texture; //the id of the font texture
|
---|
96 | void glPrint(char* string, int set); //there are two sets of font in the texture. 0, 1
|
---|
97 | void draw_label(Volume* vol); //draw label using bitmap texture
|
---|
98 | GLuint font_base; //the base of the font display list
|
---|
99 | void build_font(); //register the location of each alphabet in the texture
|
---|
100 |
|
---|
101 | public:
|
---|
102 | VolumeRenderer();
|
---|
103 | ~VolumeRenderer();
|
---|
104 |
|
---|
105 | int add_volume(Volume* _vol, TransferFunction* _tf);
|
---|
106 | //add a volume and its transfer function
|
---|
107 | //we require a transfer function when a
|
---|
108 | //volume is added.
|
---|
109 | void shade_volume(Volume* _vol, TransferFunction* _tf);
|
---|
110 | TransferFunction* get_volume_shading(Volume* _vol);
|
---|
111 |
|
---|
112 | void render(int volume_index);
|
---|
113 | void render_all(); //render all enabled volumes;
|
---|
114 | void render_all_points(); //render all enabled volumes;
|
---|
115 | void set_specular(float val);
|
---|
116 | void set_diffuse(float val);
|
---|
117 | void set_slice_mode(bool val); //control independently.
|
---|
118 | void set_volume_mode(bool val);
|
---|
119 | void switch_slice_mode(); //switch_cutplane_mode
|
---|
120 | void switch_volume_mode();
|
---|
121 | void enable_volume(int index); //enable a volume
|
---|
122 | void disable_volume(int index); //disable a volume
|
---|
123 |
|
---|
124 | void clearAnimatedVolumeInfo();
|
---|
125 | void addAnimatedVolume(Volume* volume, unsigned int volumeId);
|
---|
126 | void startVolumeAnimation();
|
---|
127 | void stopVolumeAnimation();
|
---|
128 |
|
---|
129 | VolumeInterpolator* getVolumeInterpolator();
|
---|
130 | };
|
---|
131 |
|
---|
132 | inline void VolumeRenderer::clearAnimatedVolumeInfo()
|
---|
133 | {
|
---|
134 | _volumeInterpolator->clearAll();
|
---|
135 | }
|
---|
136 |
|
---|
137 | inline void VolumeRenderer::addAnimatedVolume(Volume* volume, unsigned int volumeId)
|
---|
138 | {
|
---|
139 | _volumeInterpolator->addVolume(volume, volumeId);
|
---|
140 | }
|
---|
141 |
|
---|
142 | inline void VolumeRenderer::startVolumeAnimation()
|
---|
143 | {
|
---|
144 | _volumeInterpolator->start();
|
---|
145 | }
|
---|
146 |
|
---|
147 | inline void VolumeRenderer::stopVolumeAnimation()
|
---|
148 | {
|
---|
149 | _volumeInterpolator->stop();
|
---|
150 | }
|
---|
151 |
|
---|
152 | inline VolumeInterpolator* VolumeRenderer::getVolumeInterpolator()
|
---|
153 | {
|
---|
154 | return _volumeInterpolator;
|
---|
155 | }
|
---|
156 |
|
---|
157 | #endif
|
---|