source: trunk/packages/vizservers/nanovis/VolumeRenderer.h @ 1374

Last change on this file since 1374 was 1374, checked in by gah, 15 years ago
File size: 4.7 KB
Line 
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
41class VolumeRenderer {
42    friend class NanoVis;
43private:
44    std::vector <Volume*> volume;           //!<- array of volumes
45    std::vector <TransferFunction*> tf;    //!<- array of corresponding transfer functions
46    VolumeInterpolator* _volumeInterpolator;
47
48    int n_volumes;
49
50    bool slice_mode;    //!<- enable cut planes
51    bool volume_mode;   //!<- enable full volume rendering
52
53    /**
54     * shader parameters for rendering a single cubic volume
55     */
56    NvRegularVolumeShader* _regularVolumeShader;
57
58    /**
59     * Shader parameters for rendering a single zincblende orbital.  A
60     * simulation contains S, P, D and SS, total of 4 orbitals. A full
61     * rendering requires 4 zincblende orbital volumes.  A zincblende orbital
62     * volume is decomposed into two "interlocking" cubic volumes and passed
63     * to the shader.  We render each orbital with its own independent
64     * transfer functions then blend the result.
65     *
66     * The engine is already capable of rendering multiple volumes and combine
67     * them. Thus, we just invoke this shader on S, P, D and SS orbitals with
68     * different transfor functions. The result is a multi-orbital rendering.
69     * This is equivalent to rendering 4 unrelated data sets occupying the
70     * same space.
71     */
72    NvZincBlendeVolumeShader* _zincBlendeShader;
73 
74    /**
75     * standard vertex shader
76     */
77    NvStdVertexShader* _stdVertexShader;
78 
79    //standard vertex shader parameters
80    CGprogram m_vert_std_vprog;
81    CGparameter m_mvp_vert_std_param;
82    CGparameter m_mvi_vert_std_param;
83    GLuint font_base;           // The base of the font display list.
84    GLuint font_texture;        //the id of the font texture
85
86    void init_shaders();
87    void activate_volume_shader(Volume* vol, TransferFunction* tf,
88                                bool slice_mode);
89    void deactivate_volume_shader();
90    //draw bounding box
91    void draw_bounding_box(float x0, float y0, float z0,
92                           float x1, float y1, float z1,
93                           float r, float g, float b, float line_width);
94
95    void get_near_far_z(Mat4x4 mv, double &zNear, double &zFar);
96    bool init_font(const char* filename);
97    void glPrint(char* string, int set); //there are two sets of font in the
98                                         //texture. 0, 1
99    void draw_label(Volume* vol); //draw label using bitmap texture
100                                // the texture.
101    void build_font();          // Register the location of each alphabet in
102
103public:
104    VolumeRenderer();
105    ~VolumeRenderer();
106
107    int add_volume(Volume* _vol, TransferFunction* _tf);
108    // add a volume and its transfer function
109    // we require a transfer function when a
110    // volume is added.
111    void shade_volume(Volume* _vol, TransferFunction* _tf);
112    TransferFunction* get_volume_shading(Volume* _vol);
113
114    void render(int volume_index);
115    void render_all();  //render all enabled volumes;
116    void render_all_points(void); //render all enabled volumes;
117    void set_specular(float val);
118    void set_diffuse(float val);
119    void set_slice_mode(bool val); //control independently.
120    void set_volume_mode(bool val);
121    void switch_slice_mode(); //switch_cutplane_mode
122    void switch_volume_mode();
123    void enable_volume(int index); //enable a volume
124    void disable_volume(int index); //disable a volume
125
126    void clearAnimatedVolumeInfo(void) {
127        _volumeInterpolator->clearAll();
128    }
129    void addAnimatedVolume(Volume* volume, unsigned int volumeId) {
130        _volumeInterpolator->addVolume(volume, volumeId);
131    }
132    void startVolumeAnimation(void) {
133        _volumeInterpolator->start();
134    }
135    void stopVolumeAnimation(void) {
136        _volumeInterpolator->stop();
137    }
138    VolumeInterpolator* getVolumeInterpolator(void) {
139        return _volumeInterpolator;
140    }
141};
142
143#endif  /*_VOLUME_RENDERER_H_*/
Note: See TracBrowser for help on using the repository browser.