CVoxelObject.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Sonny Chan
40  \author Francois Conti
41  \version 3.1.1 $Rev: 1242 $
42 */
43 //==============================================================================
44 
45 //------------------------------------------------------------------------------
46 #ifndef CVoxelObjectH
47 #define CVoxelObjectH
48 //------------------------------------------------------------------------------
49 #include "CMesh.h"
50 //------------------------------------------------------------------------------
51 
52 //------------------------------------------------------------------------------
53 namespace chai3d {
54 //------------------------------------------------------------------------------
56 //------------------------------------------------------------------------------
57 
58 //==============================================================================
65 //==============================================================================
66 
67 
68 //------------------------------------------------------------------------------
69 #ifndef DOXYGEN_SHOULD_SKIP_THIS
70 //------------------------------------------------------------------------------
71 
73 struct cVoxelCoord
74 {
75  int m_x;
76  int m_y;
77  int m_z;
78 };
79 
81 struct cVoxelCoordList
82 {
83  int m_radiusX;
84  int m_radiusY;
85  int m_radiusZ;
86  std::vector<cVoxelCoord> m_coords;
87 };
88 
89 //------------------------------------------------------------------------------
90 #endif // DOXYGEN_SHOULD_SKIP_THIS
91 //------------------------------------------------------------------------------
92 
93 
94 //==============================================================================
105 //==============================================================================
106 class cVoxelObject : public cMesh
107 {
108  //--------------------------------------------------------------------------
109  // CONSTRUCTOR & DESTRUCTOR:
110  //--------------------------------------------------------------------------
111 
112 public:
113 
115  cVoxelObject();
116 
118  virtual ~cVoxelObject();
119 
120 
121  //--------------------------------------------------------------------------
122  // PUBLIC METHODS - RENDERING MODES:
123  //--------------------------------------------------------------------------
124 
125 public:
126 
128  void setRenderingModeBasic();
129 
132 
135 
138 
141 
144 
147 
149  void setRenderingModeCustom();
150 
151 
152  //--------------------------------------------------------------------------
153  // PUBLIC METHODS - SETTINGS:
154  //--------------------------------------------------------------------------
155 
156 public:
157 
159  void setQuality(const double a_quality) { m_quality = cClamp(a_quality, 0.1, 1.0); }
160 
162  double getQuality() { return (m_quality); }
163 
165  void setIsosurfaceValue(const float a_isosurfaceValue) { m_isosurfaceValue = cClamp(a_isosurfaceValue, 0.0f, 1.0f); }
166 
168  float getIsosurfaceValue() { return (m_isosurfaceValue); }
169 
171  void setVoxelOpacity(const float a_voxelOpacity) { m_voxelOpacity = cClamp(a_voxelOpacity, 0.0f, 1.0f); }
172 
174  float getVoxelOpacity() { return(m_voxelOpacity); }
175 
177  void setOpacityThreshold(const float a_opacityThreshold) { m_opacityThreshold = cClamp(a_opacityThreshold, 0.0f, 1.0f); }
178 
181 
183  void setOpticalDensity(const float a_opticalDensity) { m_opticalDensity = fabs(a_opticalDensity); }
184 
187 
189  void setUseLinearInterpolation(const bool a_useLinearInterpolation) { m_useLinearInterpolation = a_useLinearInterpolation; }
190 
193 
195  void setUseColorMap(const bool a_useColorMap) { m_useColorMap = a_useColorMap; }
196 
198  bool getUseColorMap() const { return m_useColorMap; }
199 
200 
201  //--------------------------------------------------------------------------
202  // PUBLIC MEMBERS:
203  //--------------------------------------------------------------------------
204 
205 public:
206 
209 
212 
215 
218 
221 
222 
223  //--------------------------------------------------------------------------
224  // PROTECTED METHODS:
225  //--------------------------------------------------------------------------
226 
227 protected:
228 
230  void loadRenderingShaders();
231 
233  void update(cRenderOptions& a_options);
234 
236  virtual void render(cRenderOptions& a_options);
237 
239  virtual bool computeOtherCollisionDetection(cVector3d& a_segmentPointA,
240  cVector3d& a_segmentPointB,
241  cCollisionRecorder& a_recorder,
242  cCollisionSettings& a_settings);
243 
244 
245  //--------------------------------------------------------------------------
246  // PROTECTED MEMBERS:
247  //--------------------------------------------------------------------------
248 
249 protected:
250 
253 
255  double m_quality;
256 
259 
262 
265 
268 
271 
274 
277 
279  std::vector<cVoxelCoordList> m_voxelCoordList;
280 
281 
282  //--------------------------------------------------------------------------
283  // PROTECTED MEMBERS - SHADERS:
284  //--------------------------------------------------------------------------
285 
286 protected:
287 
290 
293 
296 
299 };
300 
301 //------------------------------------------------------------------------------
302 } // namespace chai3d
303 //------------------------------------------------------------------------------
304 
305 //------------------------------------------------------------------------------
306 #endif
307 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
cVector3d m_maxCorner
Corner with maximum position coordinate.
Definition: CVoxelObject.h:211
float m_isosurfaceValue
Isosurface value.
Definition: CVoxelObject.h:258
cVoxelObject()
Constructor of cVoxelObject.
Definition: CVoxelObject.cpp:80
void setOpacityThreshold(const float a_opacityThreshold)
This method sets the opacity threshold. This value is the opacity accumulated along the ray before th...
Definition: CVoxelObject.h:177
void update(cRenderOptions &a_options)
This method updates the mesh model.
Definition: CVoxelObject.cpp:385
void setRenderingModeIsosurfaceMaterial()
This method sets an isosurface renderer using shader and material color.
Definition: CVoxelObject.cpp:203
cVector3d m_minTextureCoord
Texture coordinate at point v000 (minimum corner).
Definition: CVoxelObject.h:214
cTexture1dPtr m_colorMap
Color Map. (Lookup table)
Definition: CVoxelObject.h:220
int m_renderingMode
Rendering mode.
Definition: CVoxelObject.h:270
Implements a class to model polygonal meshes.
cVector3d m_minCorner
Corner with minimum position coordinate.
Definition: CVoxelObject.h:208
cShaderPtr m_vertexShaders[C_NUM_VOXEL_RENDERING_MODES]
Vertex shaders.
Definition: CVoxelObject.h:292
void setRenderingModeIsosurfaceColors()
This method sets an isosurface renderer using shader and individual voxel colors. ...
Definition: CVoxelObject.cpp:233
const int C_NUM_VOXEL_RENDERING_MODES
Definition: CVoxelObject.h:55
double m_quality
Quality of the displayed graphical model.
Definition: CVoxelObject.h:255
std::shared_ptr< cTexture1d > cTexture1dPtr
Definition: CTexture1d.h:67
bool m_useColorMap
If true use color mapping.
Definition: CVoxelObject.h:276
std::shared_ptr< cShader > cShaderPtr
Definition: CShader.h:89
void setRenderingModeIsosurfaceColorMap()
This method sets an isosurface renderer using shader and colormap.
Definition: CVoxelObject.cpp:262
virtual void render(cRenderOptions &a_options)
This method renders the object graphically using OpenGL.
Definition: CVoxelObject.cpp:315
void setIsosurfaceValue(const float a_isosurfaceValue)
This method sets the isosurface value. Used when isometric rendering is enabled.
Definition: CVoxelObject.h:165
void setOpticalDensity(const float a_opticalDensity)
This method sets the optical density factor. This setting is used when the direct volume rendering mo...
Definition: CVoxelObject.h:183
This class implements a 3D volumetric object composed of voxels.
Definition: CVoxelObject.h:106
float m_voxelOpacity
Voxel opacity value.
Definition: CVoxelObject.h:261
void setUseLinearInterpolation(const bool a_useLinearInterpolation)
This method enables or disables linear interpolation.
Definition: CVoxelObject.h:189
cVector3d m_maxTextureCoord
Texture coordinate at point v111 (maximum corner).
Definition: CVoxelObject.h:217
void setRenderingModeBasic()
This method sets the basic rendering mode without shader.
Definition: CVoxelObject.cpp:158
double getQuality()
This method returns the quality level of the graphic rendering.
Definition: CVoxelObject.h:162
void setRenderingModeVoxelColorMap()
This method sets a basic voxel renderer with shader and colormap.
Definition: CVoxelObject.cpp:188
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
bool m_useLinearInterpolation
If true use linear interpolation, otherwise used nearest voxel.
Definition: CVoxelObject.h:273
virtual ~cVoxelObject()
Destructor of cVoxelObject.
Definition: CVoxelObject.cpp:148
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition: CCollisionBasics.h:242
void setQuality(const double a_quality)
This method sets the quality level of the graphic rendering. This number ranges from 0...
Definition: CVoxelObject.h:159
void setUseColorMap(const bool a_useColorMap)
This method enables or disables the use of the color look-up table.
Definition: CVoxelObject.h:195
float getIsosurfaceValue()
This method returns the isosurface value. This setting is used when isometric rendering is enabled...
Definition: CVoxelObject.h:168
float getOpticalDensity()
This method returns the optical density factor.
Definition: CVoxelObject.h:186
bool m_flagShadersInitialized
Flag that indicates if shaders have been initialized.
Definition: CVoxelObject.h:289
This class implements a 3D polygonal mesh.
Definition: CMesh.h:108
cVector3d m_edges[12][2]
List of edges.
Definition: CVoxelObject.h:252
cShaderPtr m_fragmentShaders[C_NUM_VOXEL_RENDERING_MODES]
Fragment shaders.
Definition: CVoxelObject.h:295
virtual bool computeOtherCollisionDetection(cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings)
This method computes any collision between a segment and this object.
Definition: CVoxelObject.cpp:984
bool getUseColorMap() const
This method returns true if the color look-up table is enabled, false otherwise.
Definition: CVoxelObject.h:198
std::shared_ptr< cShaderProgram > cShaderProgramPtr
Definition: CShaderProgram.h:70
void setRenderingModeVoxelColors()
This method sets a basic voxel renderer with shader.
Definition: CVoxelObject.cpp:173
void loadRenderingShaders()
This method loads all rendering shaders.
Definition: CVoxelObject.cpp:748
T cClamp(const T &a_value, const T &a_low, const T &a_high)
This function clamps a value to a specified range.
Definition: CMaths.h:362
void setVoxelOpacity(const float a_voxelOpacity)
This method sets the voxel opacity value. This setting is used with basic voxel rendering mode...
Definition: CVoxelObject.h:171
float getOpacityThreshold()
This method returns the opacity threshold.
Definition: CVoxelObject.h:180
Definition: CAudioBuffer.cpp:56
bool getUseLinearInterpolation()
This method returns true if linear interpolation is enabled, false otherwise.
Definition: CVoxelObject.h:192
void setRenderingModeCustom()
This method sets a custom shader renderer.
Definition: CVoxelObject.cpp:298
float m_opticalDensity
Optical density factor.
Definition: CVoxelObject.h:267
cShaderProgramPtr m_programShaders[C_NUM_VOXEL_RENDERING_MODES]
Program shaders.
Definition: CVoxelObject.h:298
void setRenderingModeDVRColorMap()
This method sets a direct volume renderer.
Definition: CVoxelObject.cpp:280
float m_opacityThreshold
Opacity threshold. This value is the opacity accumulated along the ray before the shader decides to s...
Definition: CVoxelObject.h:264
float getVoxelOpacity()
This method returns the voxel opacity value.
Definition: CVoxelObject.h:174
std::vector< cVoxelCoordList > m_voxelCoordList
List of points.
Definition: CVoxelObject.h:279