gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
ImplicitSurface.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __ImplicitSurface_h
36 #define __ImplicitSurface_h
37 
38 
68 //******************************************************************************
69 // Include
70 //******************************************************************************
71 #ifndef __gVirtualXRayConfig_h
73 #endif
74 
75 #include <vector>
76 
77 #ifndef __Types_h
78 #include "gVirtualXRay/Types.h"
79 #endif
80 
81 #ifndef __Image_h
82 #include "gVirtualXRay/Image.h"
83 #endif
84 
85 
86 //******************************************************************************
87 // namespace
88 //******************************************************************************
89 namespace gVirtualXRay {
90 
91 
92 class PolygonMesh;
93 
94 
95 //==============================================================================
100 //==============================================================================
102 //------------------------------------------------------------------------------
103 {
104 //******************************************************************************
105 public:
106  //--------------------------------------------------------------------------
108  //--------------------------------------------------------------------------
109  typedef enum DensityFunctionTypeTag
110  {
112 
114 
117 
121 
122 
123  //--------------------------------------------------------------------------
125  //--------------------------------------------------------------------------
127  {
128  //**************************************************************************
129  public:
130  //----------------------------------------------------------------------
132 
141  //----------------------------------------------------------------------
143  const DensityFunctionType aDensityFunctionType = BLOBBY_MOLECULE,
144  RATIONAL_NUMBER a = 1,
145  RATIONAL_NUMBER b = 1):
146  //----------------------------------------------------------------------
147  m_density_function(aDensityFunctionType),
148  m_a(a),
149  m_b(b)
150  //----------------------------------------------------------------------
151  {}
152 
153 
156 
157 
160 
161 
165  };
166 
167 
168  //--------------------------------------------------------------------------
170  //--------------------------------------------------------------------------
171  ImplicitSurface();
172 
173 
174  //--------------------------------------------------------------------------
176  //--------------------------------------------------------------------------
178 
179 
180  //--------------------------------------------------------------------------
182 
187  //--------------------------------------------------------------------------
189  const DensityFunctionParameterType& aParameter) const;
190 
191 
192  //--------------------------------------------------------------------------
194  //--------------------------------------------------------------------------
195  void resetControlPoints();
196 
197 
198  //--------------------------------------------------------------------------
200  //--------------------------------------------------------------------------
201  void resetControlLines();
202 
203 
204  //--------------------------------------------------------------------------
206 
210  //--------------------------------------------------------------------------
211  void addControlPoint(const DensityFunctionParameterType& aParameter,
212  const VEC3& aControlPoint);
213 
214 
215  //--------------------------------------------------------------------------
217 
222  //--------------------------------------------------------------------------
223  void addControlLine(const DensityFunctionParameterType& aParameter,
224  const VEC3& aControlPoint1,
225  const VEC3& aControlPoint2);
226 
227 
228  //--------------------------------------------------------------------------
230 
233  //--------------------------------------------------------------------------
234  unsigned int getNumberOfControlPoints() const;
235 
236 
237  //--------------------------------------------------------------------------
239 
242  //--------------------------------------------------------------------------
243  unsigned int getNumberOfControlLineSegments() const;
244 
245 
246  void setControlPointParameters(unsigned int aPointID,
247  DensityFunctionType aDentityFunction,
248  float aParameter1,
249  float aParameter2 = 0.0);
250 
251 
252  void setControlLineSegmentParameters(unsigned int aLineSegmentID,
253  DensityFunctionType aDentityFunction,
254  float aParameter1,
255  float aParameter2 = 0.0);
256 
257 
258  //--------------------------------------------------------------------------
260 
264  //--------------------------------------------------------------------------
265  const VEC3& getControlPoint(unsigned int anIndex) const;
266 
267 
268  //--------------------------------------------------------------------------
270 
274  //--------------------------------------------------------------------------
275  VEC3& getControlPoint(unsigned int anIndex);
276 
277 
278  //--------------------------------------------------------------------------
280 
284  //--------------------------------------------------------------------------
285  const std::pair<VEC3, VEC3>& getControlLine(unsigned int anIndex) const;
286 
287 
288  //--------------------------------------------------------------------------
290 
294  //--------------------------------------------------------------------------
295  std::pair<VEC3, VEC3>& getControlLine(unsigned int anIndex);
296 
297 
298  //--------------------------------------------------------------------------
300 
306  //--------------------------------------------------------------------------
307  void voxelise(const Vec3ui& aNumberOfVoxels,
308  const VEC3& aCenter,
309  const VEC3& aVoxelSize,
310  unsigned char aVerboseLevel = 0);
311 
312 
313  //--------------------------------------------------------------------------
315 
321  //--------------------------------------------------------------------------
322  void voxelize(const Vec3ui& aNumberOfVoxels,
323  const VEC3& aCenter,
324  const VEC3& aVoxelSize,
325  unsigned char aVerboseLevel = 0);
326 
327 
328  //--------------------------------------------------------------------------
330 
333  //--------------------------------------------------------------------------
334  void writeVoxelData(const char* aFileName) const;
335 
336 
337  //--------------------------------------------------------------------------
339 
342  //--------------------------------------------------------------------------
343  void writeVoxelData(const std::string& aFileName) const;
344 
345 
346  //--------------------------------------------------------------------------
348 
351  //--------------------------------------------------------------------------
352  void writePolygonMesh(const char* aFileName);
353 
354 
355  //--------------------------------------------------------------------------
357 
360  //--------------------------------------------------------------------------
361  void writePolygonMesh(const std::string& aFileName);
362 
363 
364  //--------------------------------------------------------------------------
367 
371  //--------------------------------------------------------------------------
372  void extractIsoSurface(const RATIONAL_NUMBER& aThreshold = 0,
373  unsigned char aVerboseLevel = 0);
374 
375 
376  //--------------------------------------------------------------------------
379 
384  //--------------------------------------------------------------------------
385  void extractIsoSurface(const RATIONAL_NUMBER& aLowerThreshold,
386  const RATIONAL_NUMBER& anUpperThreshold,
387  unsigned char aVerboseLevel = 0);
388 
389 
390  //--------------------------------------------------------------------------
392 
395  //--------------------------------------------------------------------------
397 
398 
399  //--------------------------------------------------------------------------
401 
404  //--------------------------------------------------------------------------
405  const PolygonMesh& getPolygonMesh() const;
406 
407 
408  const Image<RATIONAL_NUMBER>& getVolume() const;
409 
410 
412 
413 
414 //******************************************************************************
415 protected:
417 
418 
420  RATIONAL_NUMBER a,
421  RATIONAL_NUMBER b) const;
422 
423 
425  RATIONAL_NUMBER a,
426  RATIONAL_NUMBER b) const;
427 
428 
430  RATIONAL_NUMBER a,
431  RATIONAL_NUMBER b) const;
432 
433 
435 
436 
438 
439 
441 
442 
443  std::vector<std::pair<DensityFunctionParameterType, VEC3> >
445 
446 
447  std::vector<std::pair<DensityFunctionParameterType,
448  std::pair<VEC3, VEC3> > > m_control_line_set;
449 };
450 
451 
452 } // namespace gVirtualXRay
453 
454 
455 //******************************************************************************
456 #include "ImplicitSurface.inl"
457 
458 
459 #endif // __ImplicitSurface_h
void addControlPoint(const DensityFunctionParameterType &aParameter, const VEC3 &aControlPoint)
Add a control point.
void writePolygonMesh(const char *aFileName)
Write the polygon data.
Type declarations.
DensityFunctionType
Type of density function.
RATIONAL_NUMBER evaluateMetaBall(RATIONAL_NUMBER r, RATIONAL_NUMBER a, RATIONAL_NUMBER b) const
DensityFunctionParameterType(const DensityFunctionType aDensityFunctionType=BLOBBY_MOLECULE, RATIONAL_NUMBER a=1, RATIONAL_NUMBER b=1)
Default constructor.
void setControlPointParameters(unsigned int aPointID, DensityFunctionType aDentityFunction, float aParameter1, float aParameter2=0.0)
RATIONAL_NUMBER evaluateBlobbyMolecule(RATIONAL_NUMBER r, RATIONAL_NUMBER a, RATIONAL_NUMBER b) const
const VEC3 & getControlPoint(unsigned int anIndex) const
Accessor on a given control point.
void resetControlPoints()
Remove all the control points.
const std::pair< VEC3, VEC3 > & getControlLine(unsigned int anIndex) const
Accessor on a given control line.
void extractIsoSurface(const RATIONAL_NUMBER &aThreshold=0, unsigned char aVerboseLevel=0)
unsigned int getNumberOfControlLineSegments() const
Accessor on the number of control line segments.
Image< RATIONAL_NUMBER > m_volume
std::vector< std::pair< DensityFunctionParameterType, std::pair< VEC3, VEC3 > > > m_control_line_set
RATIONAL_NUMBER evaluateSphere(RATIONAL_NUMBER r) const
void voxelise(const Vec3ui &aNumberOfVoxels, const VEC3 &aCenter, const VEC3 &aVoxelSize, unsigned char aVerboseLevel=0)
Accessor on a given control line.
std::vector< std::pair< DensityFunctionParameterType, VEC3 > > m_control_point_set
PolygonMesh is a class to handle polygon (triangles) meshes.
Definition: PolygonMesh.h:114
void voxelize(const Vec3ui &aNumberOfVoxels, const VEC3 &aCenter, const VEC3 &aVoxelSize, unsigned char aVerboseLevel=0)
Accessor on a given control line.
RATIONAL_NUMBER evaluateSoftObject(RATIONAL_NUMBER r, RATIONAL_NUMBER a, RATIONAL_NUMBER b) const
float RATIONAL_NUMBER
Type of data used to store real numbers.
Definition: Types.h:107
PolygonMesh & getPolygonMesh()
Accessor on the polygon data.
void resetControlLines()
Remove all the control lines.
void addControlLine(const DensityFunctionParameterType &aParameter, const VEC3 &aControlPoint1, const VEC3 &aControlPoint2)
Add a control line.
Class to handle a greyscale image.
void setControlLineSegmentParameters(unsigned int aLineSegmentID, DensityFunctionType aDentityFunction, float aParameter1, float aParameter2=0.0)
unsigned int getNumberOfControlPoints() const
Accessor on the number of control points.
Class to build 3D implicit surfaces. To know what implicit surfaces are, please visit Paul Bourke&#39;s t...
ImplicitSurface()
Default constructor.
void writeVoxelData(const char *aFileName) const
Write the current voxel data into a file.
RATIONAL_NUMBER evaluate(RATIONAL_NUMBER r, const DensityFunctionParameterType &aParameter) const
Evaluate the density function for the distance r.
RATIONAL_NUMBER m_a
First parameter of the density function.
ImplicitSurface is a class to build 3D implicit surfaces.
const Image< RATIONAL_NUMBER > & getVolume() const
DensityFunctionType m_density_function
Type of density function.