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.2.0 $Rev: 2171 $
42 */
43 //==============================================================================
44 
45 //------------------------------------------------------------------------------
46 #ifndef CVoxelObjectH
47 #define CVoxelObjectH
48 //------------------------------------------------------------------------------
49 #include "world/CMesh.h"
50 #include "world/CMultiMesh.h"
51 //------------------------------------------------------------------------------
52 
53 //------------------------------------------------------------------------------
54 namespace chai3d {
55 //------------------------------------------------------------------------------
57 //------------------------------------------------------------------------------
58 
59 //==============================================================================
66 //==============================================================================
67 
68 
69 //------------------------------------------------------------------------------
70 #ifndef DOXYGEN_SHOULD_SKIP_THIS
71 //------------------------------------------------------------------------------
72 
74 struct cVoxelCoord
75 {
76  int m_x;
77  int m_y;
78  int m_z;
79 };
80 
82 struct cVoxelCoordList
83 {
84  int m_radiusX;
85  int m_radiusY;
86  int m_radiusZ;
87  std::vector<cVoxelCoord> m_coords;
88 };
89 
90 //------------------------------------------------------------------------------
91 #endif // DOXYGEN_SHOULD_SKIP_THIS
92 //------------------------------------------------------------------------------
93 
94 
95 //==============================================================================
106 //==============================================================================
107 class cVoxelObject : public cMesh
108 {
109  //--------------------------------------------------------------------------
110  // CONSTRUCTOR & DESTRUCTOR:
111  //--------------------------------------------------------------------------
112 
113 public:
114 
116  cVoxelObject();
117 
119  virtual ~cVoxelObject();
120 
121 
122  //--------------------------------------------------------------------------
123  // PUBLIC METHODS - RENDERING MODES:
124  //--------------------------------------------------------------------------
125 
126 public:
127 
129  void setRenderingModeBasic();
130 
132  void setRenderingModeVoxelColors();
133 
135  void setRenderingModeVoxelColorMap();
136 
138  void setRenderingModeIsosurfaceMaterial();
139 
141  void setRenderingModeIsosurfaceColors();
142 
144  void setRenderingModeIsosurfaceColorMap();
145 
147  void setRenderingModeDVRColorMap();
148 
150  void setRenderingModeCustom();
151 
152 
153  //--------------------------------------------------------------------------
154  // PUBLIC METHODS - SETTINGS:
155  //--------------------------------------------------------------------------
156 
157 public:
158 
160  void setQuality(const double a_quality) { m_quality = cClamp(a_quality, 0.1, 10.0); }
161 
163  double getQuality() { return (m_quality); }
164 
166  void setIsosurfaceValue(const float a_isosurfaceValue) { m_isosurfaceValue = cClamp(a_isosurfaceValue, 0.0f, 1.0f); }
167 
169  float getIsosurfaceValue() { return (m_isosurfaceValue); }
170 
172  void setVoxelOpacity(const float a_voxelOpacity) { m_voxelOpacity = cClamp(a_voxelOpacity, 0.0f, 1.0f); }
173 
175  float getVoxelOpacity() { return(m_voxelOpacity); }
176 
178  void setOpacityThreshold(const float a_opacityThreshold) { m_opacityThreshold = cClamp(a_opacityThreshold, 0.0f, 1.0f); }
179 
181  float getOpacityThreshold() { return(m_opacityThreshold); }
182 
184  void setOpticalDensity(const float a_opticalDensity) { m_opticalDensity = fabs(a_opticalDensity); }
185 
187  float getOpticalDensity() { return(m_opacityThreshold); }
188 
190  void setUseLinearInterpolation(const bool a_useLinearInterpolation) { m_useLinearInterpolation = a_useLinearInterpolation; }
191 
193  bool getUseLinearInterpolation() { return (m_useLinearInterpolation); }
194 
196  void setUseColorMap(const bool a_useColorMap) { m_useColorMap = a_useColorMap; }
197 
199  bool getUseColorMap() const { return m_useColorMap; }
200 
201 
202  //--------------------------------------------------------------------------
203  // PUBLIC METHODS - POLYGONIZATION:
204  //--------------------------------------------------------------------------
205 
206 public:
207 
209  bool polygonize(cMesh* a_mesh, double a_gridSizeX = -1.0, double a_gridSizeY = -1.0, double a_gridSizeZ = -1.0);
210 
212  bool polygonize(cMultiMesh* a_multiMesh, double a_gridSizeX = -1.0, double a_gridSizeY = -1.0, double a_gridSizeZ = -1.0);
213 
214 
215  //--------------------------------------------------------------------------
216  // PUBLIC MEMBERS:
217  //--------------------------------------------------------------------------
218 
219 public:
220 
223 
226 
229 
232 
235 
236 
237  //--------------------------------------------------------------------------
238  // PROTECTED METHODS:
239  //--------------------------------------------------------------------------
240 
241 protected:
242 
244  void loadRenderingShaders();
245 
247  void update(cRenderOptions& a_options);
248 
250  virtual void render(cRenderOptions& a_options);
251 
253  virtual bool computeOtherCollisionDetection(cVector3d& a_segmentPointA,
254  cVector3d& a_segmentPointB,
255  cCollisionRecorder& a_recorder,
256  cCollisionSettings& a_settings);
257 
258 
259  //--------------------------------------------------------------------------
260  // PROTECTED MEMBERS:
261  //--------------------------------------------------------------------------
262 
263 protected:
264 
266  cVector3d m_edges[12][2];
267 
269  double m_quality;
270 
273 
276 
279 
282 
285 
288 
291 
293  std::vector<cVoxelCoordList> m_voxelCoordList;
294 
295 
296  //--------------------------------------------------------------------------
297  // PROTECTED MEMBERS - SHADERS:
298  //--------------------------------------------------------------------------
299 
300 protected:
301 
304 
307 
310 
313 };
314 
315 //------------------------------------------------------------------------------
316 } // namespace chai3d
317 //------------------------------------------------------------------------------
318 
319 //------------------------------------------------------------------------------
320 #endif
321 //------------------------------------------------------------------------------
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:225
float m_isosurfaceValue
Isosurface value.
Definition: CVoxelObject.h:272
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:178
This class implements a 3D multi-mesh object.
Definition: CMultiMesh.h:80
cVector3d m_minTextureCoord
Texture coordinate at point v000 (minimum corner).
Definition: CVoxelObject.h:228
cTexture1dPtr m_colorMap
Color Map. (Lookup table)
Definition: CVoxelObject.h:234
int m_renderingMode
Rendering mode.
Definition: CVoxelObject.h:284
Implements a class to model polygonal meshes.
cVector3d m_minCorner
Corner with minimum position coordinate.
Definition: CVoxelObject.h:222
const int C_NUM_VOXEL_RENDERING_MODES
Definition: CVoxelObject.h:56
double m_quality
Quality of the displayed graphical model.
Definition: CVoxelObject.h:269
std::shared_ptr< cTexture1d > cTexture1dPtr
Definition: CTexture1d.h:67
bool m_useColorMap
If true use color mapping.
Definition: CVoxelObject.h:290
Implements a 3D multi-mesh object.
std::shared_ptr< cShader > cShaderPtr
Definition: CShader.h:109
void setIsosurfaceValue(const float a_isosurfaceValue)
This method sets the isosurface value. Used when isometric rendering is enabled.
Definition: CVoxelObject.h:166
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:184
This class implements a 3D volumetric object composed of voxels.
Definition: CVoxelObject.h:107
float m_voxelOpacity
Voxel opacity value.
Definition: CVoxelObject.h:275
void setUseLinearInterpolation(const bool a_useLinearInterpolation)
This method enables or disables linear interpolation.
Definition: CVoxelObject.h:190
cVector3d m_maxTextureCoord
Texture coordinate at point v111 (maximum corner).
Definition: CVoxelObject.h:231
double getQuality()
This method returns the quality level of the graphic rendering.
Definition: CVoxelObject.h:163
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:287
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:160
void setUseColorMap(const bool a_useColorMap)
This method enables or disables the use of the color look-up table.
Definition: CVoxelObject.h:196
float getIsosurfaceValue()
This method returns the isosurface value. This setting is used when isometric rendering is enabled...
Definition: CVoxelObject.h:169
float getOpticalDensity()
This method returns the optical density factor.
Definition: CVoxelObject.h:187
bool m_flagShadersInitialized
Flag that indicates if shaders have been initialized.
Definition: CVoxelObject.h:303
This class implements a 3D polygonal mesh.
Definition: CMesh.h:108
bool getUseColorMap() const
This method returns true if the color look-up table is enabled, false otherwise.
Definition: CVoxelObject.h:199
std::shared_ptr< cShaderProgram > cShaderProgramPtr
Definition: CShaderProgram.h:70
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:172
float getOpacityThreshold()
This method returns the opacity threshold.
Definition: CVoxelObject.h:181
Definition: CAudioBuffer.cpp:56
bool getUseLinearInterpolation()
This method returns true if linear interpolation is enabled, false otherwise.
Definition: CVoxelObject.h:193
float m_opticalDensity
Optical density factor.
Definition: CVoxelObject.h:281
float m_opacityThreshold
Opacity threshold. This value is the opacity accumulated along the ray before the shader decides to s...
Definition: CVoxelObject.h:278
float getVoxelOpacity()
This method returns the voxel opacity value.
Definition: CVoxelObject.h:175
std::vector< cVoxelCoordList > m_voxelCoordList
List of points.
Definition: CVoxelObject.h:293