VAPOR3 3.9.4
RayCaster.h
Go to the documentation of this file.
1#ifndef RAYCASTER_H
2#define RAYCASTER_H
3
4#include <vapor/glutil.h>
5#ifndef WIN32
6 #include <sys/time.h>
7#endif
8
9#include <vapor/Renderer.h>
11#include "vapor/GLManager.h"
12
13#include <glm/glm.hpp>
14
15namespace VAPoR {
16
18public:
19 RayCaster(const ParamsMgr *pm, std::string &winName, std::string &dataSetName, std::string paramsType, std::string classType, std::string &instName, DataMgr *dataMgr);
20
21 virtual ~RayCaster();
22
23protected:
24 // C++ stuff
25 // pure virtual functions from Renderer
27 int _paintGL(bool fast);
28 void _clearCache(){};
29
30 // Makes RayCaster an abstract class that cannot be instantiated,
31 // and it's up to the subclasses to decide which shader to load.
32 // It returns 0 upon success, and non-zero upon errors.
33 virtual int _load3rdPassShaders() = 0;
34
35 enum CastingMode { FixedStep = 1, CellTraversal = 2 };
36
38 // Note: class UserCoordinates lives completely inside of class RayCaster,
39 // and is solely used by class RayCaster. Thus for simplicity, it has all
40 // of its member variables and methods public.
41 public:
42 // Y
43 // | Z (coming out the screen)
44 // | /
45 // | /
46 // |/
47 // 0 --------X
48 float * frontFace, *backFace; // user coordinates, size == bx * by * 3
49 float * rightFace, *leftFace; // user coordinates, size == by * bz * 3
50 float * topFace, *bottomFace; // user coordinates, size == bx * bz * 3
51 float * dataField; // data field of this volume
52 unsigned char *missingValueMask; // 0 == is missing value; non-zero == not missing value
53 float * vertCoords; // vertex coordinates in user coordinates
54 float * secondVarData; // values of a second variable
55 unsigned char *secondVarMask; // 0 == is missing value; non-zero == not missing value
56
57 size_t dims[3]; // num. of samples along each axis.
58
59 /* Also keep the current meta data */
61 std::string myVariableName;
62 std::string my2ndVarName;
63 int myRefinementLevel, myCompressionLevel;
64 float myGridMin[3], myGridMax[3]; // Keeps the min and max of the current grid.
65 // !!NOT!! the value retrieved from params.
66
67 // A few flags to indicate if certain data is out of date
71
72 /* Member functions */
75
76 //
77 // It returns 0 upon success, and non-zero upon errors.
78 //
79 int GetCurrentGrid(const RayCasterParams *params, DataMgr *dataMgr, StructuredGrid **gridpp) const;
80
81 void CheckUpToDateStatus(const RayCasterParams *params, const StructuredGrid *grid, DataMgr *dataMgr, bool use2ndVar);
82 //
83 // Update meta data, as well as pointers: 6 faces + dataField + missingValueMask
84 // It returns 0 upon success, and non-zero upon errors:
85 //
86 int UpdateFaceAndData(const RayCasterParams *params, const StructuredGrid *grid, DataMgr *dataMgr);
87 //
88 // Update pointers: xyCoords and zCoords
89 // |-- Note: meta data is updated in UpdateFaceAndData(), but *NOT* here, so
90 // | UpdateFaceAndData() needs to be called priori to UpdateVertCoords().
91 // |-- It returns 0 upon success, and non-zero upon errors:
92 //
93 int UpdateVertCoords(const RayCasterParams *params, const StructuredGrid *grid, DataMgr *dataMgr);
94
95 int Update2ndVariable(const RayCasterParams *params, DataMgr *dataMgr);
96
97 void FillCoordsXYPlane(const StructuredGrid *grid, // Input
98 size_t planeIdx, // Input: which plane to retrieve
99 float * coords); // Output buffer allocated by caller
100 void FillCoordsYZPlane(const StructuredGrid *grid, // Input
101 size_t planeIdx, // Input
102 float * coords); // Output
103 void FillCoordsXZPlane(const StructuredGrid *grid, // Input
104 size_t planeIdx, // Input
105 float * coords); // Output
106 void IterateAGrid(const StructuredGrid *grid,
107 size_t numOfVert, // Length of buffers.
108 float * dataBuf, // Need to be already allocated.
109 unsigned char * maskBuf); // Need to be already allocated.
110
111 }; // end of class UserCoordinates
112
114 std::vector<float> _colorMap;
115 float _colorMapRange[3]; // min, max, and diff values.
116 glm::mat4 _currentMV; // model view matrix in use
117 GLint _currentViewport[4]; // current viewport in use
119
120 // OpenGL stuff
121 // textures
133 const GLint _volumeTexOffset;
137 const GLint _depthTexOffset;
140
141 // buffers and vertex arrays
144 GLuint _vertexBufferId; // Keeps user coordinates of 6 faces.
145 GLuint _indexBufferId; // Auxiliary indices for efficiently drawing triangle strips.
146 GLuint _vertexAttribId; // Attribute of vertices: (i, j k) logical indices.
147
148 // shaders
154
155 //
156 // Render the volume surface using triangle strips
157 // This is a subroutine used by _drawVolumeFaces().
158 //
159 void _renderTriangleStrips(int whichPass, int castingMode) const;
160
161 void _drawVolumeFaces(int whichPass, int whichCastingMode, const std::vector<size_t> &cameraCellIdx, const glm::mat4 &inversedMV = glm::mat4(0.0f), bool fast = false) const;
162
163 void _load3rdPassUniforms(int castingMode, bool fast, bool insideVolume) const;
164
165 virtual void _3rdPassSpecialHandling(bool fast, int castingMode) const;
166 virtual void _colormapSpecialHandling(); // Cannot be const due to other subroutines.
167 virtual bool _use2ndVariable(const RayCasterParams *params) const;
168 virtual void _update2ndVarTextures();
169
170 //
171 // Initialization for 1) framebuffers and 2) textures
172 // It returns 0 upon success, and non-zero upon errors.
173 //
175
177
178 void _updateViewportWhenNecessary(const GLint *viewport);
181 int _updateVertCoordsTexture(const glm::mat4 &MV);
185 void _sleepAWhile() const;
186
187#ifndef WIN32
188 double _getElapsedSeconds(const struct timeval *begin, const struct timeval *end) const;
189#endif
190
191}; // End of class RayCaster
192
193}; // End of namespace VAPoR
194
195#endif
A cache based data reader.
Definition: DataMgr.h:110
A singleton class for managing Params instances.
Definition: ParamsMgr.h:53
void IterateAGrid(const StructuredGrid *grid, size_t numOfVert, float *dataBuf, unsigned char *maskBuf)
int UpdateFaceAndData(const RayCasterParams *params, const StructuredGrid *grid, DataMgr *dataMgr)
void FillCoordsXZPlane(const StructuredGrid *grid, size_t planeIdx, float *coords)
unsigned char * missingValueMask
Definition: RayCaster.h:52
void CheckUpToDateStatus(const RayCasterParams *params, const StructuredGrid *grid, DataMgr *dataMgr, bool use2ndVar)
int Update2ndVariable(const RayCasterParams *params, DataMgr *dataMgr)
int UpdateVertCoords(const RayCasterParams *params, const StructuredGrid *grid, DataMgr *dataMgr)
void FillCoordsYZPlane(const StructuredGrid *grid, size_t planeIdx, float *coords)
int GetCurrentGrid(const RayCasterParams *params, DataMgr *dataMgr, StructuredGrid **gridpp) const
void FillCoordsXYPlane(const StructuredGrid *grid, size_t planeIdx, float *coords)
GLuint _depthTextureId
Definition: RayCaster.h:128
const GLint _colorMapTexOffset
Definition: RayCaster.h:134
const GLint _missingValueTexOffset
Definition: RayCaster.h:135
GLuint _volumeTextureId
Definition: RayCaster.h:124
void _configure3DTextureNearestInterpolation() const
void _updateDataTextures()
const GLint _2ndVarMaskTexOffset
Definition: RayCaster.h:139
const GLint _frontFaceTexOffset
Definition: RayCaster.h:132
GLuint _colorMapTextureId
Definition: RayCaster.h:126
virtual void _colormapSpecialHandling()
int _paintGL(bool fast)
All OpenGL rendering is performed in the pure virtual paintGL method.
std::vector< float > _colorMap
Definition: RayCaster.h:114
GLuint _frameBufferId
Definition: RayCaster.h:142
GLuint _frontFaceTextureId
Definition: RayCaster.h:123
void _renderTriangleStrips(int whichPass, int castingMode) const
int _initializeFramebufferTextures()
const GLint _volumeTexOffset
Definition: RayCaster.h:133
void _clearCache()
Definition: RayCaster.h:28
virtual ~RayCaster()
const GLint _depthTexOffset
Definition: RayCaster.h:137
void _drawVolumeFaces(int whichPass, int whichCastingMode, const std::vector< size_t > &cameraCellIdx, const glm::mat4 &inversedMV=glm::mat4(0.0f), bool fast=false) const
GLuint _vertexBufferId
Definition: RayCaster.h:144
UserCoordinates _userCoordinates
Definition: RayCaster.h:113
const GLint _2ndVarDataTexOffset
Definition: RayCaster.h:138
double _getElapsedSeconds(const struct timeval *begin, const struct timeval *end) const
const GLint _backFaceTexOffset
Definition: RayCaster.h:131
GLuint _indexBufferId
Definition: RayCaster.h:145
void _updateColormap(RayCasterParams *params)
GLuint _vertexArrayId
Definition: RayCaster.h:143
ShaderProgram * _3rdPassMode1Shader
Definition: RayCaster.h:152
void _configure2DTextureLinearInterpolation() const
glm::mat4 _currentMV
Definition: RayCaster.h:116
void _load3rdPassUniforms(int castingMode, bool fast, bool insideVolume) const
int _selectDefaultCastingMethod() const
GLuint _vertCoordsTextureId
Definition: RayCaster.h:127
RayCaster(const ParamsMgr *pm, std::string &winName, std::string &dataSetName, std::string paramsType, std::string classType, std::string &instName, DataMgr *dataMgr)
void _updateViewportWhenNecessary(const GLint *viewport)
GLuint _missingValueTextureId
Definition: RayCaster.h:125
ShaderProgram * _3rdPassShader
Definition: RayCaster.h:151
GLuint _vertexAttribId
Definition: RayCaster.h:146
ShaderProgram * _3rdPassMode2Shader
Definition: RayCaster.h:153
ShaderProgram * _1stPassShader
Definition: RayCaster.h:149
GLuint _2ndVarMaskTexId
Definition: RayCaster.h:130
virtual int _load3rdPassShaders()=0
void _configure3DTextureLinearInterpolation() const
GLuint _2ndVarDataTexId
Definition: RayCaster.h:129
virtual void _update2ndVarTextures()
void _sleepAWhile() const
virtual void _3rdPassSpecialHandling(bool fast, int castingMode) const
virtual bool _use2ndVariable(const RayCasterParams *params) const
GLuint _backFaceTextureId
Definition: RayCaster.h:122
ShaderProgram * _2ndPassShader
Definition: RayCaster.h:150
int _updateVertCoordsTexture(const glm::mat4 &MV)
const GLint _vertCoordsTexOffset
Definition: RayCaster.h:136
A class that performs rendering in a Visualizer.
Definition: Renderer.h:121
Provides a C++ interface to the OpenGL shader program construct.
Definition: ShaderProgram.h:25
Abstract base class for a 2D or 3D structured grid.
#define RENDER_API
Definition: common.h:78