QUAOAR STUDIO // Mobius API
poly_SVO.h
1 //-----------------------------------------------------------------------------
2 // Created on: 10 December 2019
3 //-----------------------------------------------------------------------------
4 // Copyright (c) 2019-present, Sergey Slyadnev
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 // * Neither the name of Sergey Slyadnev nor the
16 // names of all contributors may be used to endorse or promote products
17 // derived from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 // DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
23 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //-----------------------------------------------------------------------------
30 
31 #ifndef poly_SVO_HeaderFile
32 #define poly_SVO_HeaderFile
33 
34 // Poly includes
35 #include <mobius/poly_ScalarMembership.h>
36 
37 // Core includes
38 #include <mobius/core_XYZ.h>
39 
40 // Standard includes
41 #include <map>
42 
43 namespace mobius {
44 
49 class poly_SVO
50 {
51 public:
52 
54  struct Summary
55  {
56  int membership;
57  std::map<double, int> grains;
58 
59  Summary() : membership(0) {}
60 
63  mobiusPoly_EXPORT void
64  AddCell(const double size);
65 
68  mobiusPoly_EXPORT void
69  Dump(std::ostream& oss) const;
70 
73  mobiusPoly_EXPORT void
74  DumpJSON(std::ostream& oss) const;
75  };
76 
77 public:
78 
82  mobiusPoly_EXPORT static bool
83  IsValidCornerId(const size_t id);
84 
123  mobiusPoly_EXPORT static size_t
124  GetCornerID(const size_t nx,
125  const size_t ny,
126  const size_t nz);
127 
165  mobiusPoly_EXPORT static void
166  GetCornerLocation(const size_t id,
167  size_t& nx,
168  size_t& ny,
169  size_t& nz);
170 
171 public:
172 
174  mobiusPoly_EXPORT
175  poly_SVO();
176 
180  mobiusPoly_EXPORT
181  poly_SVO(const t_xyz& cornerMin,
182  const t_xyz& cornerMax);
183 
185  mobiusPoly_EXPORT
186  ~poly_SVO();
187 
188 public:
189 
192  mobiusPoly_EXPORT void
193  Release();
194 
199  mobiusPoly_EXPORT bool
200  HasScalars();
201 
205  mobiusPoly_EXPORT void
206  SetScalar(const size_t id,
207  const double s);
208 
212  mobiusPoly_EXPORT double
213  GetScalar(const size_t id) const;
214 
217  mobiusPoly_EXPORT bool
218  IsLeaf() const;
219 
224  mobiusPoly_EXPORT void
225  GetLeaves(std::vector<const poly_SVO*>& leaves,
226  const int sm = ScalarMembership_OnInOut) const;
227 
230  mobiusPoly_EXPORT bool
231  IsNegative() const;
232 
235  mobiusPoly_EXPORT bool
236  IsPositive() const;
237 
240  mobiusPoly_EXPORT bool
241  IsZeroCrossing() const;
242 
245  mobiusPoly_EXPORT bool
246  Split();
247 
254  mobiusPoly_EXPORT void
255  SetChild(const size_t id, poly_SVO* pChild);
256 
261  mobiusPoly_EXPORT poly_SVO*
262  GetChild(const size_t id) const;
263 
269  mobiusPoly_EXPORT poly_SVO*
270  FindChild(const std::vector<size_t>& path) const;
271 
276  mobiusPoly_EXPORT unsigned
277  GetDepth0() const;
278 
289  mobiusPoly_EXPORT double
290  Eval(const t_xyz& P,
291  const bool bndOnly = false) const;
292 
297  mobiusPoly_EXPORT unsigned long long
298  GetMemoryInBytes(int& numNodes) const;
299 
311  mobiusPoly_EXPORT void
312  CollectSummary(const int sm,
313  Summary& summary) const;
314 
315 public:
316 
318  const t_xyz& GetCornerMin() const
319  {
320  return m_cornerMin;
321  }
322 
324  void SetCornerMin(const t_xyz& P)
325  {
326  m_cornerMin = P;
327  }
328 
330  const t_xyz& GetCornerMax() const
331  {
332  return m_cornerMax;
333  }
334 
336  void SetCornerMax(const t_xyz& P)
337  {
338  m_cornerMax = P;
339  }
340 
342  const t_xyz& GetP0() const
343  {
344  return m_cornerMin;
345  }
346 
348  t_xyz GetP1() const
349  {
350  return t_xyz( m_cornerMax.X(), m_cornerMin.Y(), m_cornerMin.Z() );
351  }
352 
354  t_xyz GetP2() const
355  {
356  return t_xyz( m_cornerMin.X(), m_cornerMax.Y(), m_cornerMin.Z() );
357  }
358 
360  t_xyz GetP3() const
361  {
362  return t_xyz( m_cornerMax.X(), m_cornerMax.Y(), m_cornerMin.Z() );
363  }
364 
366  t_xyz GetP4() const
367  {
368  return t_xyz( m_cornerMin.X(), m_cornerMin.Y(), m_cornerMax.Z() );
369  }
370 
372  t_xyz GetP5() const
373  {
374  return t_xyz( m_cornerMax.X(), m_cornerMin.Y(), m_cornerMax.Z() );
375  }
376 
378  t_xyz GetP6() const
379  {
380  return t_xyz( m_cornerMin.X(), m_cornerMax.Y(), m_cornerMax.Z() );
381  }
382 
384  const t_xyz& GetP7() const
385  {
386  return m_cornerMax;
387  }
388 
390  double GetCellSize() const
391  {
392  return (m_cornerMax - m_cornerMin).Modulus();
393  }
394 
395 protected:
396 
404  mobiusPoly_EXPORT void
405  getLeaves(const poly_SVO* pNode,
406  const int sm,
407  std::vector<const poly_SVO*>& leaves,
408  std::vector<long long>& depths,
409  const long long depth) const;
410 
416  mobiusPoly_EXPORT void
417  getLeaves(const poly_SVO* pNode,
418  const int sm,
419  std::vector<const poly_SVO*>& leaves) const;
420 
421 protected:
422 
424  double m_scalars[8];
425 
426  /*
427  NOTICE: we store the corner points of each cell for convenience. It is
428  not really necessary to have them here as the corners can be deduced
429  from the root node if we know its dimensions. At the same time,
430  we have found that the convenience of having the explicit corner
431  points as a part of cell definition outweights the memory overheads.
432  */
433 
434  /* 48 bytes for corners */
437 
438 };
439 
440 }
441 
442 #endif
mobius::poly_SVO::GetChild
mobiusPoly_EXPORT poly_SVO * GetChild(const size_t id) const
mobius
Defines an exception class C1 that inherits an exception class C2.
Definition: bspl_Decompose.h:41
mobius::core_XYZ
Definition: core_XYZ.h:45
mobius::poly_SVO::GetCornerMax
const t_xyz & GetCornerMax() const
Definition: poly_SVO.h:330
mobius::poly_SVO::Eval
mobiusPoly_EXPORT double Eval(const t_xyz &P, const bool bndOnly=false) const
mobius::poly_SVO::GetP3
t_xyz GetP3() const
Definition: poly_SVO.h:360
mobius::poly_SVO::IsPositive
mobiusPoly_EXPORT bool IsPositive() const
mobius::poly_SVO::GetScalar
mobiusPoly_EXPORT double GetScalar(const size_t id) const
mobius::poly_SVO::IsZeroCrossing
mobiusPoly_EXPORT bool IsZeroCrossing() const
mobius::poly_SVO::GetCornerMin
const t_xyz & GetCornerMin() const
Definition: poly_SVO.h:318
mobius::poly_SVO::GetP7
const t_xyz & GetP7() const
Definition: poly_SVO.h:384
mobius::core_XYZ::Y
double Y() const
Definition: core_XYZ.h:129
mobius::poly_SVO::GetCornerID
static mobiusPoly_EXPORT size_t GetCornerID(const size_t nx, const size_t ny, const size_t nz)
mobius::poly_SVO::SetCornerMax
void SetCornerMax(const t_xyz &P)
Sets new coordinates for the max corner point.
Definition: poly_SVO.h:336
mobius::poly_SVO::SetScalar
mobiusPoly_EXPORT void SetScalar(const size_t id, const double s)
mobius::poly_SVO::Split
mobiusPoly_EXPORT bool Split()
mobius::poly_SVO::GetCornerLocation
static mobiusPoly_EXPORT void GetCornerLocation(const size_t id, size_t &nx, size_t &ny, size_t &nz)
mobius::poly_SVO::Summary::membership
int membership
Membership qualifier.
Definition: poly_SVO.h:56
mobius::poly_SVO::Summary::grains
std::map< double, int > grains
Voxelization grains <size, count>.
Definition: poly_SVO.h:57
mobius::poly_SVO::m_pChildren
poly_SVO ** m_pChildren
Child octree nodes (8 bytes).
Definition: poly_SVO.h:423
mobius::poly_SVO::GetMemoryInBytes
mobiusPoly_EXPORT unsigned long long GetMemoryInBytes(int &numNodes) const
mobius::poly_SVO::GetP0
const t_xyz & GetP0() const
Definition: poly_SVO.h:342
mobius::core_XYZ::Z
double Z() const
Definition: core_XYZ.h:143
mobius::t_xyz
core_XYZ t_xyz
Definition: core_XYZ.h:356
mobius::poly_SVO::m_cornerMax
t_xyz m_cornerMax
Max corner of the SVO box.
Definition: poly_SVO.h:436
mobius::poly_SVO::SetCornerMin
void SetCornerMin(const t_xyz &P)
Sets new coordinates for the min corner point.
Definition: poly_SVO.h:324
mobius::poly_SVO::Summary::Dump
mobiusPoly_EXPORT void Dump(std::ostream &oss) const
mobius::poly_SVO::Summary::DumpJSON
mobiusPoly_EXPORT void DumpJSON(std::ostream &oss) const
mobius::poly_SVO
Definition: poly_SVO.h:49
mobius::poly_SVO::IsNegative
mobiusPoly_EXPORT bool IsNegative() const
mobius::poly_SVO::m_cornerMin
t_xyz m_cornerMin
Min corner of the SVO box.
Definition: poly_SVO.h:435
mobius::poly_SVO::HasScalars
mobiusPoly_EXPORT bool HasScalars()
mobius::poly_SVO::m_scalars
double m_scalars[8]
Stored scalar values (64 bytes).
Definition: poly_SVO.h:424
mobius::poly_SVO::Summary::AddCell
mobiusPoly_EXPORT void AddCell(const double size)
mobius::poly_SVO::GetCellSize
double GetCellSize() const
Definition: poly_SVO.h:390
mobius::poly_SVO::GetP5
t_xyz GetP5() const
Definition: poly_SVO.h:372
mobius::poly_SVO::~poly_SVO
mobiusPoly_EXPORT ~poly_SVO()
Dtor. It is not virtual to save 8 bytes of memory.
mobius::poly_SVO::getLeaves
mobiusPoly_EXPORT void getLeaves(const poly_SVO *pNode, const int sm, std::vector< const poly_SVO * > &leaves, std::vector< long long > &depths, const long long depth) const
mobius::poly_SVO::GetP4
t_xyz GetP4() const
Definition: poly_SVO.h:366
mobius::poly_SVO::GetP2
t_xyz GetP2() const
Definition: poly_SVO.h:354
mobius::poly_SVO::SetChild
mobiusPoly_EXPORT void SetChild(const size_t id, poly_SVO *pChild)
mobius::poly_SVO::FindChild
mobiusPoly_EXPORT poly_SVO * FindChild(const std::vector< size_t > &path) const
mobius::poly_SVO::GetDepth0
mobiusPoly_EXPORT unsigned GetDepth0() const
mobius::poly_SVO::IsValidCornerId
static mobiusPoly_EXPORT bool IsValidCornerId(const size_t id)
mobius::poly_SVO::CollectSummary
mobiusPoly_EXPORT void CollectSummary(const int sm, Summary &summary) const
mobius::poly_SVO::GetP6
t_xyz GetP6() const
Definition: poly_SVO.h:378
mobius::poly_SVO::GetP1
t_xyz GetP1() const
Definition: poly_SVO.h:348
mobius::poly_SVO::poly_SVO
mobiusPoly_EXPORT poly_SVO()
Default ctor.
mobius::poly_SVO::IsLeaf
mobiusPoly_EXPORT bool IsLeaf() const
mobius::poly_SVO::GetLeaves
mobiusPoly_EXPORT void GetLeaves(std::vector< const poly_SVO * > &leaves, const int sm=ScalarMembership_OnInOut) const
mobius::poly_SVO::Summary
Voxelization summary.
Definition: poly_SVO.h:54
mobius::poly_SVO::Release
mobiusPoly_EXPORT void Release()
mobius::core_XYZ::X
double X() const
Definition: core_XYZ.h:115