My Project
Loading...
Searching...
No Matches
CVoxelObject.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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.3.0
42*/
43//==============================================================================
44
45//------------------------------------------------------------------------------
46#ifndef CVoxelObjectH
47#define CVoxelObjectH
48//------------------------------------------------------------------------------
49#include "world/CMesh.h"
50#include "world/CMultiMesh.h"
51//------------------------------------------------------------------------------
52
53//------------------------------------------------------------------------------
54namespace chai3d {
55//------------------------------------------------------------------------------
57//------------------------------------------------------------------------------
58
59//==============================================================================
66//==============================================================================
67
68
69//------------------------------------------------------------------------------
70#ifndef DOXYGEN_SHOULD_SKIP_THIS
71//------------------------------------------------------------------------------
72
74struct cVoxelCoord
75{
76 int m_x;
77 int m_y;
78 int m_z;
79};
80
82struct 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//==============================================================================
107class cVoxelObject : public cMesh
108{
109 //--------------------------------------------------------------------------
110 // CONSTRUCTOR & DESTRUCTOR:
111 //--------------------------------------------------------------------------
112
113public:
114
116 cVoxelObject();
117
119 virtual ~cVoxelObject();
120
121
122 //--------------------------------------------------------------------------
123 // PUBLIC METHODS - GENERAL:
124 //--------------------------------------------------------------------------
125
126public:
127
129 virtual std::string getClassName() { return ("VoxelObject"); }
130
131
132 //--------------------------------------------------------------------------
133 // PUBLIC METHODS - RENDERING MODES:
134 //--------------------------------------------------------------------------
135
136public:
137
140
143
146
149
152
155
158
161
162
163 //--------------------------------------------------------------------------
164 // PUBLIC METHODS - SETTINGS:
165 //--------------------------------------------------------------------------
166
167public:
168
170 void setQuality(const double a_quality) { m_quality = cClamp(a_quality, 0.1, 10.0); }
171
173 double getQuality() { return (m_quality); }
174
176 void setIsosurfaceValue(const float a_isosurfaceValue) { m_isosurfaceValue = cClamp(a_isosurfaceValue, 0.0f, 1.0f); }
177
180
182 void setVoxelOpacity(const float a_voxelOpacity) { m_voxelOpacity = cClamp(a_voxelOpacity, 0.0f, 1.0f); }
183
185 float getVoxelOpacity() { return(m_voxelOpacity); }
186
188 void setOpacityThreshold(const float a_opacityThreshold) { m_opacityThreshold = cClamp(a_opacityThreshold, 0.0f, 1.0f); }
189
192
194 void setOpticalDensity(const float a_opticalDensity) { m_opticalDensity = fabs(a_opticalDensity); }
195
198
200 void setUseLinearInterpolation(const bool a_useLinearInterpolation) { m_useLinearInterpolation = a_useLinearInterpolation; }
201
204
206 void setUseColorMap(const bool a_useColorMap) { m_useColorMap = a_useColorMap; }
207
209 bool getUseColorMap() const { return m_useColorMap; }
210
211
212 //--------------------------------------------------------------------------
213 // PUBLIC METHODS - POLYGONIZATION:
214 //--------------------------------------------------------------------------
215
216public:
217
219 bool polygonize(cMesh* a_mesh, double a_gridSizeX = -1.0, double a_gridSizeY = -1.0, double a_gridSizeZ = -1.0);
220
222 bool polygonize(cMultiMesh* a_multiMesh, double a_gridSizeX = -1.0, double a_gridSizeY = -1.0, double a_gridSizeZ = -1.0);
223
224
225 //--------------------------------------------------------------------------
226 // PUBLIC METHODS - VOXELIZATION:
227 //--------------------------------------------------------------------------
228
229public:
230
232 bool voxelize(cMesh* a_mesh, unsigned int a_largestSideInVoxels, cColorb& a_color);
233
235 bool fill(unsigned int a_x, unsigned int a_y, unsigned int a_z, cColorb& a_color, double a_colorTolerance = 0.1);
236
237
238 //--------------------------------------------------------------------------
239 // PUBLIC MEMBERS:
240 //--------------------------------------------------------------------------
241
242public:
243
246
249
252
255
258
259
260 //--------------------------------------------------------------------------
261 // PROTECTED METHODS:
262 //--------------------------------------------------------------------------
263
264protected:
265
268
270 void update(cRenderOptions& a_options);
271
273 virtual void render(cRenderOptions& a_options);
274
276 virtual bool computeOtherCollisionDetection(cVector3d& a_segmentPointA,
277 cVector3d& a_segmentPointB,
278 cCollisionRecorder& a_recorder,
279 cCollisionSettings& a_settings);
280
281
282 //--------------------------------------------------------------------------
283 // PROTECTED MEMBERS:
284 //--------------------------------------------------------------------------
285
286protected:
287
290
292 double m_quality;
293
296
299
302
305
308
311
314
316 std::vector<cVoxelCoordList> m_voxelCoordList;
317
318
319 //--------------------------------------------------------------------------
320 // PROTECTED MEMBERS - SHADERS:
321 //--------------------------------------------------------------------------
322
323protected:
324
327
330
333
336};
337
338//------------------------------------------------------------------------------
339} // namespace chai3d
340//------------------------------------------------------------------------------
341
342//------------------------------------------------------------------------------
343#endif
344//------------------------------------------------------------------------------
Implements a class to model polygonal meshes.
Implements a 3D multi-mesh object.
This class implements a collision detection recorder that stores all collision events that are report...
Definition CCollisionBasics.h:186
This class implements a 3D polygonal mesh.
Definition CMesh.h:109
This class implements a 3D multi-mesh object.
Definition CMultiMesh.h:81
This class implements a 3D volumetric object composed of voxels.
Definition CVoxelObject.h:108
cVector3d m_edges[12][2]
List of edges.
Definition CVoxelObject.h:289
bool m_useColorMap
If true use color mapping.
Definition CVoxelObject.h:313
void setRenderingModeVoxelColorMap()
This method sets a basic voxel renderer with shader and colormap.
Definition CVoxelObject.cpp:197
cVoxelObject()
Constructor of cVoxelObject.
Definition CVoxelObject.cpp:84
float getVoxelOpacity()
This method returns the voxel opacity value.
Definition CVoxelObject.h:185
bool polygonize(cMesh *a_mesh, double a_gridSizeX=-1.0, double a_gridSizeY=-1.0, double a_gridSizeZ=-1.0)
This method converts this voxel object into a triangle mesh.
Definition CVoxelObject.cpp:1412
void setQuality(const double a_quality)
This method sets the quality level of the graphic rendering. This number ranges from 0....
Definition CVoxelObject.h:170
void setRenderingModeIsosurfaceMaterial()
This method sets an isosurface renderer using shader and material color.
Definition CVoxelObject.cpp:215
void setRenderingModeIsosurfaceColorMap()
This method sets an isosurface renderer using shader and colormap.
Definition CVoxelObject.cpp:280
float getIsosurfaceValue()
This method returns the isosurface value. This setting is used when isometric rendering is enabled.
Definition CVoxelObject.h:179
float getOpticalDensity()
This method returns the optical density factor.
Definition CVoxelObject.h:197
float m_voxelOpacity
Voxel opacity value.
Definition CVoxelObject.h:298
std::vector< cVoxelCoordList > m_voxelCoordList
List of points.
Definition CVoxelObject.h:316
cVector3d m_maxTextureCoord
Texture coordinate at point v111 (maximum corner).
Definition CVoxelObject.h:254
cVector3d m_minCorner
Corner with minimum position coordinate.
Definition CVoxelObject.h:245
void setRenderingModeCustom()
This method sets a custom shader renderer.
Definition CVoxelObject.cpp:322
cTexture1dPtr m_colorMap
Color Map. (Lookup table)
Definition CVoxelObject.h:257
cShaderProgramPtr m_programShaders[C_NUM_VOXEL_RENDERING_MODES]
Program shaders.
Definition CVoxelObject.h:335
virtual std::string getClassName()
This method returns the name of the object class.
Definition CVoxelObject.h:129
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:194
float m_opticalDensity
Optical density factor.
Definition CVoxelObject.h:304
void setRenderingModeIsosurfaceColors()
This method sets an isosurface renderer using shader and individual voxel colors.
Definition CVoxelObject.cpp:248
virtual ~cVoxelObject()
Destructor of cVoxelObject.
Definition CVoxelObject.cpp:151
bool getUseLinearInterpolation()
This method returns true if linear interpolation is enabled, false otherwise.
Definition CVoxelObject.h:203
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:1007
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:188
void setUseColorMap(const bool a_useColorMap)
This method enables or disables the use of the color look-up table.
Definition CVoxelObject.h:206
void setRenderingModeBasic()
This method sets the basic rendering mode without shader.
Definition CVoxelObject.cpp:161
bool getUseColorMap() const
This method returns true if the color look-up table is enabled, false otherwise.
Definition CVoxelObject.h:209
bool voxelize(cMesh *a_mesh, unsigned int a_largestSideInVoxels, cColorb &a_color)
This method creates a voxel model from a triangle mesh.
Definition CVoxelObject.cpp:1602
void setIsosurfaceValue(const float a_isosurfaceValue)
This method sets the isosurface value. Used when isometric rendering is enabled.
Definition CVoxelObject.h:176
int m_renderingMode
Rendering mode.
Definition CVoxelObject.h:307
void setUseLinearInterpolation(const bool a_useLinearInterpolation)
This method enables or disables linear interpolation.
Definition CVoxelObject.h:200
float m_opacityThreshold
Opacity threshold. This value is the opacity accumulated along the ray before the shader decides to s...
Definition CVoxelObject.h:301
double m_quality
Quality of the displayed graphical model.
Definition CVoxelObject.h:292
void setRenderingModeDVRColorMap()
This method sets a direct volume renderer.
Definition CVoxelObject.cpp:301
cShaderPtr m_vertexShaders[C_NUM_VOXEL_RENDERING_MODES]
Vertex shaders.
Definition CVoxelObject.h:329
bool m_flagShadersInitialized
Flag that indicates if shaders have been initialized.
Definition CVoxelObject.h:326
void update(cRenderOptions &a_options)
This method updates the mesh model.
Definition CVoxelObject.cpp:412
float m_isosurfaceValue
Isosurface value.
Definition CVoxelObject.h:295
cVector3d m_minTextureCoord
Texture coordinate at point v000 (minimum corner).
Definition CVoxelObject.h:251
void setRenderingModeVoxelColors()
This method sets a basic voxel renderer with shader.
Definition CVoxelObject.cpp:179
cVector3d m_maxCorner
Corner with maximum position coordinate.
Definition CVoxelObject.h:248
float getOpacityThreshold()
This method returns the opacity threshold.
Definition CVoxelObject.h:191
bool fill(unsigned int a_x, unsigned int a_y, unsigned int a_z, cColorb &a_color, double a_colorTolerance=0.1)
This method fills a voxel object at a given point, with a given color, and color tolerance in respect...
Definition CVoxelObject.cpp:1768
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:182
bool m_useLinearInterpolation
If true use linear interpolation, otherwise used nearest voxel.
Definition CVoxelObject.h:310
void loadRenderingShaders()
This method loads all rendering shaders.
Definition CVoxelObject.cpp:771
virtual void render(cRenderOptions &a_options)
This method renders the object graphically using OpenGL.
Definition CVoxelObject.cpp:342
double getQuality()
This method returns the quality level of the graphic rendering.
Definition CVoxelObject.h:173
cShaderPtr m_fragmentShaders[C_NUM_VOXEL_RENDERING_MODES]
Fragment shaders.
Definition CVoxelObject.h:332
Definition CAudioBuffer.cpp:57
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:387
std::shared_ptr< cShader > cShaderPtr
Definition CShader.h:110
const int C_NUM_VOXEL_RENDERING_MODES
Definition CVoxelObject.h:56
std::shared_ptr< cShaderProgram > cShaderProgramPtr
Definition CShaderProgram.h:71
std::shared_ptr< cTexture1d > cTexture1dPtr
Definition CTexture1d.h:68
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition CCollisionBasics.h:243
This class defines a color using a GLubyte representation for each component.
Definition CColor.h:1185
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition CRenderOptions.h:83
This class implements a 3D vector.
Definition CVector3d.h:89