gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
ImplicitSurface.inl
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2014, 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 
64 //******************************************************************************
65 // Include
66 //******************************************************************************
67 #include <cmath>
68 
69 #ifndef __OutOfBoundsException_h
71 #endif
72 
73 
74 //******************************************************************************
75 // define
76 //******************************************************************************
77 
78 
79 //******************************************************************************
80 // namespace
81 //******************************************************************************
82 namespace gVirtualXRay {
83 
84 
85 //----------------------------------------------------------------------------------------------------
87  const DensityFunctionParameterType& aParameter) const
88 //----------------------------------------------------------------------------------------------------
89 {
90  switch (aParameter.m_density_function)
91  {
92  case SPHERE:
93  return (evaluateSphere(r));
94 
95  case BLOBBY_MOLECULE:
96  return (evaluateBlobbyMolecule(r, aParameter.m_a, aParameter.m_b));
97 
98  case META_BALL:
99  return (evaluateMetaBall(r, aParameter.m_a, aParameter.m_b));
100 
101  case SOFT_OBJECT:
102  return (evaluateSoftObject(r, aParameter.m_a, aParameter.m_b));
103 
104  default:
105  return (0);
106  }
107 }
108 
109 
110 //-----------------------------------------------
112 //-----------------------------------------------
113 {
114  m_control_point_set.clear();
115 }
116 
117 
118 //----------------------------------------------
120 //----------------------------------------------
121 {
122  m_control_line_set.clear();
123 }
124 
125 
126 //------------------------------------------------------------------------------------------
128  const VEC3& aControlPoint)
129 //------------------------------------------------------------------------------------------
130 {
131  m_control_point_set.push_back(std::pair<DensityFunctionParameterType, VEC3>(aParameter, aControlPoint));
132 }
133 
134 
135 //-----------------------------------------------------------------------------------------
137  const VEC3& aControlPoint1,
138  const VEC3& aControlPoint2)
139 //-----------------------------------------------------------------------------------------
140 {
141  m_control_line_set.push_back(std::pair<DensityFunctionParameterType, std::pair<VEC3, VEC3> >(aParameter, std::pair<VEC3, VEC3>(aControlPoint1, aControlPoint2)));
142 }
143 
144 
145 //-------------------------------------------------------------------
146 inline unsigned int ImplicitSurface::getNumberOfControlPoints() const
147 //-------------------------------------------------------------------
148 {
149  return m_control_point_set.size();
150 }
151 
152 
153 //-------------------------------------------------------------------------
155 //-------------------------------------------------------------------------
156 {
157  return m_control_line_set.size();
158 }
159 
160 
161 //------------------------------------------------------------------------------------------
162 inline void ImplicitSurface::setControlPointParameters(unsigned int aPointID,
163  DensityFunctionType aDentityFunction,
164  float aParameter1,
165  float aParameter2)
166 //------------------------------------------------------------------------------------------
167 {
168  if (aPointID >= m_control_point_set.size())
169  {
170  OutOfBoundsException(__FILE__, __FUNCTION__, __LINE__);
171  }
172 
173  m_control_point_set[aPointID].first.m_density_function = aDentityFunction;
174  m_control_point_set[aPointID].first.m_a = aParameter1;
175  m_control_point_set[aPointID].first.m_b = aParameter2;
176 }
177 
178 
179 //------------------------------------------------------------------------------------------------
180 inline void ImplicitSurface::setControlLineSegmentParameters(unsigned int aLineSegmentID,
181  DensityFunctionType aDentityFunction,
182  float aParameter1,
183  float aParameter2)
184 //------------------------------------------------------------------------------------------------
185 {
186  if (aLineSegmentID >= m_control_line_set.size())
187  {
188  OutOfBoundsException(__FILE__, __FUNCTION__, __LINE__);
189  }
190 
191  m_control_line_set[aLineSegmentID].first.m_density_function = aDentityFunction;
192  m_control_line_set[aLineSegmentID].first.m_a = aParameter1;
193  m_control_line_set[aLineSegmentID].first.m_b = aParameter2;
194 }
195 
196 
197 //-----------------------------------------------------------------------------
198 inline const VEC3& ImplicitSurface::getControlPoint(unsigned int anIndex) const
199 //-----------------------------------------------------------------------------
200 {
201  if (anIndex >= m_control_point_set.size())
202  {
203  OutOfBoundsException(__FILE__, __FUNCTION__, __LINE__);
204  }
205 
206  return (m_control_point_set[anIndex].second);
207 }
208 
209 
210 //-----------------------------------------------------------------
211 inline VEC3& ImplicitSurface::getControlPoint(unsigned int anIndex)
212 //-----------------------------------------------------------------
213 {
214  if (anIndex >= m_control_point_set.size())
215  {
216  OutOfBoundsException(__FILE__, __FUNCTION__, __LINE__);
217  }
218 
219  return (m_control_point_set[anIndex].second);
220 }
221 
222 
223 //---------------------------------------------------------------------------------------------
224 inline const std::pair<VEC3, VEC3>& ImplicitSurface::getControlLine(unsigned int anIndex) const
225 //---------------------------------------------------------------------------------------------
226 {
227  if (anIndex >= m_control_line_set.size())
228  {
229  OutOfBoundsException(__FILE__, __FUNCTION__, __LINE__);
230  }
231 
232  return (m_control_line_set[anIndex].second);
233 }
234 
235 
236 //---------------------------------------------------------------------------------
237 inline std::pair<VEC3, VEC3>& ImplicitSurface::getControlLine(unsigned int anIndex)
238 //---------------------------------------------------------------------------------
239 {
240  if (anIndex >= m_control_line_set.size())
241  {
242  OutOfBoundsException(__FILE__, __FUNCTION__, __LINE__);
243  }
244 
245  return (m_control_line_set[anIndex].second);
246 }
247 
248 
249 //------------------------------------------------------------------
250 inline void ImplicitSurface::voxelize(const Vec3ui& aNumberOfVoxels,
251  const VEC3& aCenter,
252  const VEC3& aVoxelSize,
253  unsigned char aVerboseLevel)
254 //------------------------------------------------------------------
255 {
256  voxelise(aNumberOfVoxels, aCenter, aVoxelSize, aVerboseLevel);
257 }
258 
259 
260 //-----------------------------------------------------------------------------
261 inline void ImplicitSurface::writeVoxelData(const std::string& aFileName) const
262 //-----------------------------------------------------------------------------
263 {
264  writeVoxelData(aFileName.data());
265 }
266 
267 
268 //-------------------------------------------------------------------------
269 inline void ImplicitSurface::writePolygonMesh(const std::string& aFileName)
270 //-------------------------------------------------------------------------
271 {
272  writePolygonMesh(aFileName.data());
273 }
274 
275 /*
276 //-------------------------------------------------------------------------------
277 inline const std::vector<RATIONAL_NUMBER>& ImplicitSurface::getVertexData() const
278 //-------------------------------------------------------------------------------
279 {
280  return (m_p_vertex_data);
281 }
282 
283 
284 //---------------------------------------------------------------------------
285 inline const std::vector<unsigned int>& ImplicitSurface::getIndexData() const
286 //---------------------------------------------------------------------------
287 {
288  return (m_p_index_data);
289 }
290 */
291 
292 
293 //---------------------------------------------------
295 //---------------------------------------------------
296 {
297  return (m_mesh_data);
298 }
299 
300 
301 //---------------------------------------------------------------
303 //---------------------------------------------------------------
304 {
305  return (m_mesh_data);
306 }
307 
308 
309 //---------------------------------------------------------------------
311 //---------------------------------------------------------------------
312 {
313  return (m_volume);
314 }
315 
316 
317 //---------------------------------------------------------
319 //---------------------------------------------------------
320 {
321  return (m_volume);
322 }
323 
324 
325 //-----------------------------------------------------------------------------
327 //-----------------------------------------------------------------------------
328 {
329  if (0 <= r)
330  {
331  return (1.0 / (r * r));
332  }
333  else
334  {
335  return (0);
336  }
337 }
338 
339 
340 //-------------------------------------------------------------------------------------
342  RATIONAL_NUMBER a,
343  RATIONAL_NUMBER b) const
344 //-------------------------------------------------------------------------------------
345 {
346  if (0 <= r)
347  {
348  return (a * exp(-b * r * r));
349  }
350  else
351  {
352  return (0);
353  }
354 }
355 
356 
357 //-------------------------------------------------------------------------------
359  RATIONAL_NUMBER a,
360  RATIONAL_NUMBER b) const
361 //-------------------------------------------------------------------------------
362 {
363  if (0 <= r && r <= b / 3.0)
364  {
365  return (a * (1.0 - (3.0 * r * r) / (b * b)));
366  }
367  else if (b / 3.0 <= r && r <= b)
368  {
369  return (((3.0 * a) / 2.0) * pow((1.0 - (r / b)), 2.0));
370  }
371  else //if (m_b <= r)
372  {
373  return (0);
374  }
375 }
376 
377 
378 //---------------------------------------------------------------------------------
380  RATIONAL_NUMBER a,
381  RATIONAL_NUMBER b) const
382 //---------------------------------------------------------------------------------
383 {
384  if (0 <= r && r <= b)
385  {
386  return (a *
387  (1.0 -
388  (( 4.0 * std::pow(r, 6)) / (9.0 * std::pow(b, 6))) +
389  ((17.0 * std::pow(r, 4)) / (9.0 * std::pow(b, 4))) -
390  ((22.0 * std::pow(r, 2)) / (9.0 * std::pow(b, 2)))));
391  }
392  else
393  {
394  return (0);
395  }
396 }
397 
398 
399 } // namespace gVirtualXRay
void addControlPoint(const DensityFunctionParameterType &aParameter, const VEC3 &aControlPoint)
Add a control point.
void writePolygonMesh(const char *aFileName)
Write the polygon data.
DensityFunctionType
Type of density function.
RATIONAL_NUMBER evaluateMetaBall(RATIONAL_NUMBER r, RATIONAL_NUMBER a, RATIONAL_NUMBER b) const
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.
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.
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 handle exceptions when accessing an array cell that is not accessible, i.e. out of bounds memory access.
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.
const Image< RATIONAL_NUMBER > & getVolume() const