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 |
|
---|
37 | using namespace std;
|
---|
38 |
|
---|
39 | class VolumeRenderer{
|
---|
40 |
|
---|
41 | private:
|
---|
42 | vector <Volume*> volume; //array of volumes
|
---|
43 | vector <TransferFunction*> tf;//array of corresponding transfer functions
|
---|
44 | int n_volumes;
|
---|
45 |
|
---|
46 | bool slice_mode; //enable cut planes
|
---|
47 | bool volume_mode; //enable full volume rendering
|
---|
48 |
|
---|
49 |
|
---|
50 | //cg related
|
---|
51 | CGcontext g_context; //the Nvidia cg context
|
---|
52 |
|
---|
53 | //shader parameters for rendering a single cubic volume
|
---|
54 | CGprogram m_one_volume_fprog;
|
---|
55 | CGparameter m_vol_one_volume_param;
|
---|
56 | CGparameter m_tf_one_volume_param;
|
---|
57 | CGparameter m_mvi_one_volume_param;
|
---|
58 | CGparameter m_mv_one_volume_param;
|
---|
59 | CGparameter m_render_param_one_volume_param;
|
---|
60 |
|
---|
61 |
|
---|
62 | //Shader parameters for rendering a single zincblende orbital.
|
---|
63 | //A simulation contains S, P, D and SS, total of 4 orbitals. A full rendering requires 4 zincblende orbital volumes.
|
---|
64 | //A zincblende orbital volume is decomposed into two "interlocking" cubic volumes and passed to the shader.
|
---|
65 | //We render each orbital with its own independent transfer functions then blend the result.
|
---|
66 | //
|
---|
67 | //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on
|
---|
68 | //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.
|
---|
69 | //This is equivalent to rendering 4 unrelated data sets occupying the same space.
|
---|
70 | CGprogram m_zincblende_volume_fprog;
|
---|
71 | CGparameter m_zincblende_tf_param; //four transfer functions
|
---|
72 | CGparameter m_zincblende_volume_a_param, m_zincblende_volume_b_param; //two cubic volumes (one zincblende orbital)
|
---|
73 | CGparameter m_zincblende_cell_size_param; //cell size in texture space
|
---|
74 | CGparameter m_zincblende_mvi_param; //modelview inverse matrix
|
---|
75 | CGparameter m_zincblende_render_param; //render parameters
|
---|
76 |
|
---|
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(int volume_index, 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(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(int volume_index); //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(CGcontext _context);
|
---|
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 set_specular(float val);
|
---|
115 | void set_diffuse(float val);
|
---|
116 | void set_slice_mode(bool val); //control independently.
|
---|
117 | void set_volume_mode(bool val);
|
---|
118 | void switch_slice_mode(); //switch_cutplane_mode
|
---|
119 | void switch_volume_mode();
|
---|
120 | void enable_volume(int index); //enable a volume
|
---|
121 | void disable_volume(int index); //disable a volume
|
---|
122 | };
|
---|
123 |
|
---|
124 | #endif
|
---|