ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
DgmOctree.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // Local
11 #include "CVPlatform.h"
12 #include "GenericOctree.h"
13 
14 // system
15 #include <cassert>
16 #include <cstring>
17 #include <vector>
18 
19 #ifdef CV_ENV_64
20 // enables 64 bits code octree (can go up to level 21, but take 50% more memory)
21 #define OCTREE_CODES_64_BITS
22 #endif
23 
24 // DGM: tests in progress
25 // #define TEST_CELLS_FOR_SPHERICAL_NN
26 
27 namespace cloudViewer {
28 
29 class ReferenceCloud;
30 class GenericIndexedCloudPersist;
31 class GenericProgressCallback;
32 class NormalizedProgress;
33 
35 
40 public:
42 
47  static unsigned char GET_BIT_SHIFT(unsigned char level);
48 
51 
54  static int OCTREE_LENGTH(int level);
55 
56  /*******************************/
58  /*******************************/
59 
61 
64 #ifdef OCTREE_CODES_64_BITS
65  static const int MAX_OCTREE_LEVEL = 21;
66 #else
67  static const int MAX_OCTREE_LEVEL = 10;
68 #endif
69 
71 
74 #ifdef OCTREE_CODES_64_BITS
75  using CellCode =
76  unsigned long long; // max 21 levels (but twice more memory!)
77 #else
78  using CellCode = unsigned; // max 10 levels
79 #endif
80 
82 
84  static const int MAX_OCTREE_LENGTH = (1 << MAX_OCTREE_LEVEL);
85 
87 
89  static const CellCode INVALID_CELL_CODE = (~static_cast<CellCode>(0));
90 
92  using cellCodesContainer = std::vector<CellCode>;
93 
95  using cellIndexesContainer = std::vector<unsigned int>;
96 
98 
103  const CCVector3* point;
105  unsigned pointIndex;
107  double squareDistd;
108 
110  PointDescriptor() : point(nullptr), pointIndex(0), squareDistd(-1.0) {}
111 
113  PointDescriptor(const CCVector3* P, unsigned index)
114  : point(P), pointIndex(index), squareDistd(-1.0) {}
115 
117  PointDescriptor(const CCVector3* P, unsigned index, double d2)
118  : point(P), pointIndex(index), squareDistd(d2) {}
119 
121 
126  static bool distComp(const PointDescriptor& a,
127  const PointDescriptor& b) {
128  return a.squareDistd < b.squareDistd;
129  }
130  };
131 
133  using NeighboursSet = std::vector<PointDescriptor>;
134 
136  struct CellDescriptor {
140  unsigned index;
141 
143  CellDescriptor() = default;
144 
146  CellDescriptor(const CCVector3& C, unsigned i) : center(C), index(i) {}
147  };
148 
150  using NeighbourCellsSet = std::vector<CellDescriptor>;
151 
153 
162  /*** Information to set before search ***/
163 
165 
169 
171  unsigned char level;
173 
179 
186 
190 
192 
197 
198  /*** Information to set to 0 before search ***/
199 
202 
207 
210 
216 
219 
226 
227  /*** Result ***/
228 
230 
234 
237  : queryPoint(0, 0, 0),
238  level(1),
239  minNumberOfNeighbors(1),
240  cellPos(0, 0, 0),
241  cellCenter(0, 0, 0),
242  maxSearchSquareDistd(0),
243  alreadyVisitedNeighbourhoodSize(0),
244  theNearestPointIndex(0) {}
245  };
246 
249 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
252  NeighboursSet pointsInSphericalNeighbourhood;
253 
256  NeighbourCellsSet cellsInNeighbourhood;
257 
260  PointCoordinateType maxInD2;
261 
264  PointCoordinateType minOutD2;
265 #endif
267  bool ready;
268 
270  inline void prepare(PointCoordinateType radius,
271  PointCoordinateType cellSize) {
272 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
273  PointCoordinateType cellDiag =
274  cellSize * static_cast<PointCoordinateType>(SQRT_3 / 2);
275  minOutD2 = radius + cellDiag;
276  minOutD2 *= minOutD2;
277  maxInD2 = radius - cellDiag;
278  if (maxInD2 <= 0)
279  maxInD2 = 0;
280  else
281  maxInD2 *= maxInD2;
282 #endif
283  }
284 
287  ready(false)
288 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
289  ,
290  maxInD2(0.0),
291  minOutD2(FLT_MAX)
292 #endif
293  {
294  }
295  };
296 
298 
301  struct IndexAndCode {
303  unsigned theIndex;
306 
308  IndexAndCode() : theIndex(0), theCode(0) {}
309 
311  IndexAndCode(unsigned index, CellCode code)
312  : theIndex(index), theCode(code) {}
313 
316  : theIndex(ic.theIndex), theCode(ic.theCode) {}
317 
319  inline bool operator<(const IndexAndCode& iac) const {
320  return theCode < iac.theCode;
321  }
322 
324  inline bool operator>(const IndexAndCode& iac) const {
325  return theCode > iac.theCode;
326  }
327 
329 
333  static bool codeComp(const IndexAndCode& a,
334  const IndexAndCode& b) throw() {
335  return a.theCode < b.theCode;
336  }
337 
339 
344  static bool indexComp(const IndexAndCode& a,
345  const IndexAndCode& b) throw() {
346  return a.theIndex < b.theIndex;
347  }
348  };
349 
351  using cellsContainer = std::vector<IndexAndCode>;
352 
354  struct octreeCell {
355  // Warning: put the non aligned members (< 4 bytes) at the end to avoid
356  // too much alignment padding!
357 
359  const DgmOctree* parentOctree; // 8 bytes
363  unsigned index; // 4 bytes
365  ReferenceCloud* points; // 8 bytes
367  unsigned char level; // 1 byte (+ 3 for alignment)
368 
369  // Total
370  // //32 bytes (for 64 bits arch.)
371 
373  explicit octreeCell(const DgmOctree* parentOctree);
374 
376  virtual ~octreeCell();
377 
378  private:
380  octreeCell(const octreeCell& cell);
381  };
382 
385 
393  using octreeCellFunc = bool (*)(const octreeCell&,
394  void**,
396 
397  /******************************/
399  /******************************/
400 
402 
404  explicit DgmOctree(GenericIndexedCloudPersist* cloud);
405 
407  ~DgmOctree() override = default;
408 
410  virtual void clear();
411 
413 
419  int build(GenericProgressCallback* progressCb = nullptr);
420 
422 
435  int build(const CCVector3& octreeMin,
436  const CCVector3& octreeMax,
437  const CCVector3* pointsMinFilter = nullptr,
438  const CCVector3* pointsMaxFilter = nullptr,
439  GenericProgressCallback* progressCb = nullptr);
440 
441  /**** GETTERS ****/
442 
444 
446  inline unsigned getNumberOfProjectedPoints() const {
447  return m_numberOfProjectedPoints;
448  }
449 
451 
453  inline const CCVector3& getOctreeMins() const { return m_dimMin; }
454 
456 
458  inline const CCVector3& getOctreeMaxs() const { return m_dimMax; }
459 
461 
465  void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) const;
466 
469 
474  inline const int* getMinFillIndexes(unsigned char level) const {
475  return m_fillIndexes + 6 * level;
476  }
477 
480 
485  inline const int* getMaxFillIndexes(unsigned char level) const {
486  return m_fillIndexes + 6 * level + 3;
487  }
488 
490 
494  inline const PointCoordinateType& getCellSize(unsigned char level) const {
495  return m_cellSize[level];
496  }
497 
500 
505  void getCellDistanceFromBorders(const Tuple3i& cellPos,
506  unsigned char level,
507  int* cellDists) const;
508 
511 
518  void getCellDistanceFromBorders(const Tuple3i& cellPos,
519  unsigned char level,
520  int neighbourhoodLength,
521  int* cellDists) const;
522 
524 
536  bool getPointsInCellByCellIndex(ReferenceCloud* cloud,
537  unsigned cellIndex,
538  unsigned char level,
539  bool clearOutputCloud = true) const;
540 
542 
549  bool getPointsInCell(CellCode cellCode,
550  unsigned char level,
551  ReferenceCloud* subset,
552  bool isCodeTruncated = false,
553  bool clearOutputCloud = true) const;
554 
556 
564  ReferenceCloud* getPointsInCellsWithSortedCellCodes(
565  cellCodesContainer& cellCodes,
566  unsigned char level,
567  ReferenceCloud* subset,
568  bool areCodesTruncated = false) const;
569 
570  /**** NEIGHBOURHOOD SEARCH ****/
571 
573 
588  unsigned findPointNeighbourhood(
589  const CCVector3* _queryPoint,
590  ReferenceCloud* Yk,
591  unsigned maxNumberOfNeighbors,
592  unsigned char level,
593  double& maxSquareDist,
594  double maxSearchDist = 0,
595  int* finalNeighbourhoodSize = nullptr) const;
596 
599 
605  double findTheNearestNeighborStartingFromCell(
606  NearestNeighboursSearchStruct& nNSS) const;
607 
610 
617  unsigned findNearestNeighborsStartingFromCell(
618  NearestNeighboursSearchStruct& nNSS,
619  bool getOnlyPointsWithValidScalar = false) const;
620 
622 
633  int findNeighborsInASphereStartingFromCell(
634  NearestNeighboursSearchStruct& nNSS,
635  double radius,
636  bool sortValues = true) const;
637 
638 public: // extraction of points inside geometrical volumes (sphere, cylinder,
639  // box, etc.)
640  // deprecated
641  // int getPointsInSphericalNeighbourhood(const CCVector3& sphereCenter,
642  // PointCoordinateType radius, NeighboursSet& neighbours) const;
643 
645 
651  int getPointsInSphericalNeighbourhood(const CCVector3& sphereCenter,
652  PointCoordinateType radius,
653  NeighboursSet& neighbours,
654  unsigned char level) const;
655 
670  unsigned char level;
674 
677  : center(0, 0, 0),
678  dir(0, 0, 1),
679  radius(0),
680  maxHalfLength(0),
681  level(0),
682  onlyPositiveDir(false) {}
683  };
684 
686 
694  std::size_t getPointsInCylindricalNeighbourhood(
695  CylindricalNeighbourhood& params) const;
696 
703 
711 
714  currentHalfLength(0),
715  prevMinCornerPos(-1, -1, -1),
716  prevMaxCornerPos(0, 0, 0) {}
717  };
718 
720 
723  std::size_t getPointsInCylindricalNeighbourhoodProgressive(
724  ProgressiveCylindricalNeighbourhood& params) const;
725 
737  unsigned char level;
738 
741  : center(0, 0, 0), axes(nullptr), dimensions(0, 0, 0), level(0) {}
742  };
743 
745 
749  std::size_t getPointsInBoxNeighbourhood(BoxNeighbourhood& params) const;
750 
751 public: /***** CELLS POSITION HANDLING *****/
754 
763  static CellCode GenerateTruncatedCellCode(const Tuple3i& cellPos,
764  unsigned char level);
765 
766 #ifndef OCTREE_CODES_64_BITS
768  static CellCode GenerateTruncatedCellCode(const Tuple3s& pos,
769  unsigned char level);
770 #endif
771 
774 
779  inline void getTheCellPosWhichIncludesThePoint(const CCVector3* thePoint,
780  Tuple3i& cellPos) const {
781  const PointCoordinateType& cs = getCellSize(MAX_OCTREE_LEVEL);
782  // DGM: if we admit that cs >= 0, then the 'floor' operator is useless
783  // (int cast = truncation)
784  cellPos.x = static_cast<int>(/*floor*/ (thePoint->x - m_dimMin.x) / cs);
785  cellPos.y = static_cast<int>(/*floor*/ (thePoint->y - m_dimMin.y) / cs);
786  cellPos.z = static_cast<int>(/*floor*/ (thePoint->z - m_dimMin.z) / cs);
787  }
788 
791 
798  inline void getTheCellPosWhichIncludesThePoint(const CCVector3* thePoint,
799  Tuple3i& cellPos,
800  unsigned char level) const {
801  assert(level <= MAX_OCTREE_LEVEL);
802 
803  getTheCellPosWhichIncludesThePoint(thePoint, cellPos);
804 
805  const unsigned char dec = MAX_OCTREE_LEVEL - level;
806  cellPos.x >>= dec;
807  cellPos.y >>= dec;
808  cellPos.z >>= dec;
809  }
810 
813 
823  inline void getTheCellPosWhichIncludesThePoint(const CCVector3* thePoint,
824  Tuple3i& cellPos,
825  unsigned char level,
826  bool& inBounds) const {
827  assert(level <= MAX_OCTREE_LEVEL);
828 
829  getTheCellPosWhichIncludesThePoint(thePoint, cellPos);
830 
831  inBounds = (cellPos.x >= 0 && cellPos.x < MAX_OCTREE_LENGTH &&
832  cellPos.y >= 0 && cellPos.y < MAX_OCTREE_LENGTH &&
833  cellPos.z >= 0 && cellPos.z < MAX_OCTREE_LENGTH);
834 
835  const unsigned char dec = MAX_OCTREE_LEVEL - level;
836  cellPos.x >>= dec;
837  cellPos.y >>= dec;
838  cellPos.z >>= dec;
839  }
840 
843 
849  void getCellPos(CellCode code,
850  unsigned char level,
851  Tuple3i& cellPos,
852  bool isCodeTruncated) const;
853 
856 
862  inline void computeCellCenter(CellCode code,
863  unsigned char level,
864  CCVector3& center,
865  bool isCodeTruncated = false) const {
866  Tuple3i cellPos;
867  getCellPos(code, level, cellPos, isCodeTruncated);
868 
869  return computeCellCenter(cellPos, level, center);
870  }
871 
874 
878  inline void computeCellCenter(const Tuple3i& cellPos,
879  unsigned char level,
880  CCVector3& center) const {
881  const PointCoordinateType& cs = getCellSize(level);
882  center.x =
883  m_dimMin.x + cs * (static_cast<PointCoordinateType>(0.5) +
884  static_cast<PointCoordinateType>(cellPos.x));
885  center.y =
886  m_dimMin.y + cs * (static_cast<PointCoordinateType>(0.5) +
887  static_cast<PointCoordinateType>(cellPos.y));
888  center.z =
889  m_dimMin.z + cs * (static_cast<PointCoordinateType>(0.5) +
890  static_cast<PointCoordinateType>(cellPos.z));
891  }
892 
893 #ifndef OCTREE_CODES_64_BITS
895  inline void computeCellCenter(const Tuple3s& cellPos,
896  unsigned char level,
897  CCVector3& center) const {
898  const PointCoordinateType& cs = getCellSize(level);
899  center.x =
900  m_dimMin.x + cs * (static_cast<PointCoordinateType>(0.5) +
901  static_cast<PointCoordinateType>(cellPos.x));
902  center.y =
903  m_dimMin.y + cs * (static_cast<PointCoordinateType>(0.5) +
904  static_cast<PointCoordinateType>(cellPos.y));
905  center.z =
906  m_dimMin.z + cs * (static_cast<PointCoordinateType>(0.5) +
907  static_cast<PointCoordinateType>(cellPos.z));
908  }
909 #endif
910 
912 
919  void computeCellLimits(CellCode code,
920  unsigned char level,
921  CCVector3& cellMin,
922  CCVector3& cellMax,
923  bool isCodeTruncated = false) const;
924 
925  /**** OCTREE DIAGNOSIS ****/
926 
930 
933  unsigned char findBestLevelForAGivenNeighbourhoodSizeExtraction(
934  PointCoordinateType radius) const;
935 
938 
943  unsigned char findBestLevelForComparisonWithOctree(
944  const DgmOctree* theOtherOctree) const;
945 
948 
951  unsigned char findBestLevelForAGivenPopulationPerCell(
952  unsigned indicativeNumberOfPointsPerCell) const;
953 
956 
959  unsigned char findBestLevelForAGivenCellNumber(
960  unsigned indicativeNumberOfCells) const;
961 
963  inline const CellCode& getCellCode(unsigned index) const {
964  return m_thePointsAndTheirCellCodes[index].theCode;
965  }
966 
969 
975  bool getCellCodes(unsigned char level,
976  cellCodesContainer& vec,
977  bool truncatedCodes = false) const;
978 
981 
987  bool getCellIndexes(unsigned char level, cellIndexesContainer& vec) const;
988 
991 
998  bool getCellCodesAndIndexes(unsigned char level,
999  cellsContainer& vec,
1000  bool truncatedCodes = false) const;
1001 
1004 
1011  void diff(const cellCodesContainer& codesA,
1012  const cellCodesContainer& codesB,
1013  cellCodesContainer& diffA,
1014  cellCodesContainer& diffB) const;
1015 
1018 
1029  bool diff(unsigned char octreeLevel,
1030  const cellsContainer& codesA,
1031  const cellsContainer& codesB,
1032  int& diffA,
1033  int& diffB,
1034  int& cellsA,
1035  int& cellsB) const;
1036 
1038  inline const unsigned& getCellNumber(unsigned char level) const {
1039  assert(level <= MAX_OCTREE_LEVEL);
1040  return m_cellCount[level];
1041  }
1042 
1045 
1048  double computeMeanOctreeDensity(unsigned char level) const;
1049 
1052 
1058  const CCVector3& queryPoint,
1060  const CCVector3& cellCenter) {
1061  PointCoordinateType d1 = std::abs(cellCenter.x - queryPoint.x);
1062  PointCoordinateType d2 = std::abs(cellCenter.y - queryPoint.y);
1063  if (d2 > d1) d1 = d2;
1064 
1065  d2 = std::abs(cellCenter.z - queryPoint.z);
1066  return cs / 2 - (d2 > d1 ? d2 : d1);
1067  }
1068 
1069  /**** ADVANCED METHODS ****/
1070 
1073 
1088  int extractCCs(const cellCodesContainer& cellCodes,
1089  unsigned char level,
1090  bool sixConnexity,
1091  GenericProgressCallback* progressCb = nullptr) const;
1092 
1095 
1108  int extractCCs(unsigned char level,
1109  bool sixConnexity,
1110  GenericProgressCallback* progressCb = nullptr) const;
1111 
1112  /**** OCTREE VISITOR ****/
1113 
1116 
1139  unsigned executeFunctionForAllCellsStartingAtLevel(
1140  unsigned char startingLevel,
1141  octreeCellFunc func,
1142  void** additionalParameters,
1143  unsigned minNumberOfPointsPerCell,
1144  unsigned maxNumberOfPointsPerCell,
1145  bool multiThread = true,
1146  GenericProgressCallback* progressCb = nullptr,
1147  const char* functionTitle = nullptr,
1148  int maxThreadCount = 0);
1149 
1152 
1169  unsigned executeFunctionForAllCellsAtLevel(
1170  unsigned char level,
1171  octreeCellFunc func,
1172  void** additionalParameters,
1173  bool multiThread = false,
1174  GenericProgressCallback* progressCb = nullptr,
1175  const char* functionTitle = nullptr,
1176  int maxThreadCount = 0);
1177 
1179  enum RayCastProcess { RC_NEAREST_POINT, RC_CLOSE_POINTS };
1180 
1182  bool rayCast(const CCVector3& rayAxis,
1183  const CCVector3& rayOrigin,
1184  double maxRadiusOrFov,
1185  bool isFOV, // whether the previous parameter is a radius
1186  // (distance) or a FOV (in radians)
1187  RayCastProcess process,
1188  std::vector<PointDescriptor>& output) const;
1189 
1192  return m_theAssociatedCloud;
1193  }
1194 
1197  return m_thePointsAndTheirCellCodes;
1198  }
1199 
1202  static bool MultiThreadSupport();
1203 
1204 protected:
1205  /*******************************/
1207  /*******************************/
1208 
1211  // Warning: put the non aligned members (< 4 bytes) at the end to avoid
1212  // too much alignment padding!
1213 
1215  unsigned pos; // 4 bytes
1217  unsigned elements; // 4 bytes
1219  unsigned char level; // 1 byte (+ 3 for alignment)
1220 
1221  // Total
1222  // //12 bytes
1223  };
1224 
1225  /********************************/
1227  /********************************/
1228 
1231 
1234 
1237 
1240  unsigned m_nearestPow2;
1241 
1246 
1253 
1255  PointCoordinateType m_cellSize[MAX_OCTREE_LEVEL + 2];
1258  int m_fillIndexes[(MAX_OCTREE_LEVEL + 1) * 6];
1260  unsigned m_cellCount[MAX_OCTREE_LEVEL + 1];
1262  unsigned m_maxCellPopulation[MAX_OCTREE_LEVEL + 1];
1264  double m_averageCellPopulation[MAX_OCTREE_LEVEL + 1];
1266  double m_stdDevCellPopulation[MAX_OCTREE_LEVEL + 1];
1267 
1268  /******************************/
1270  /******************************/
1271 
1273 
1278  int genericBuild(GenericProgressCallback* progressCb = nullptr);
1279 
1281  void updateMinAndMaxTables();
1282 
1285  void updateCellSizeTable();
1286 
1289  void updateCellCountTable();
1290 
1292 
1296  void computeCellsStatistics(unsigned char level);
1297 
1300 
1306  void getNeighborCellsAround(const Tuple3i& cellPos,
1307  cellIndexesContainer& neighborCellsIndexes,
1308  int neighbourhoodLength,
1309  unsigned char level) const;
1310 
1312 
1318  void getPointsInNeighbourCellsAround(
1320  int neighbourhoodLength,
1321  bool getOnlyPointsWithValidScalar = false) const;
1322 
1323 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
1324  void getPointsInNeighbourCellsAround(
1326  int minNeighbourhoodLength,
1327  int maxNeighbourhoodLength) const;
1328 #endif
1329 
1331 
1340  unsigned getCellIndex(CellCode truncatedCellCode,
1341  unsigned char bitDec) const;
1342 
1344 
1353  unsigned getCellIndex(CellCode truncatedCellCode,
1354  unsigned char bitDec,
1355  unsigned begin,
1356  unsigned end) const;
1357 };
1358 
1359 } // namespace cloudViewer
constexpr double SQRT_3
Square root of 3.
Definition: CVConst.h:29
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
cmdLineReadable * params[]
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
The octree structure used throughout the library.
Definition: DgmOctree.h:39
const int * getMaxFillIndexes(unsigned char level) const
Definition: DgmOctree.h:485
unsigned CellCode
Type of the code of an octree cell.
Definition: DgmOctree.h:78
std::vector< CellDescriptor > NeighbourCellsSet
A set of neighbour cells descriptors.
Definition: DgmOctree.h:150
void computeCellCenter(const Tuple3s &cellPos, unsigned char level, CCVector3 &center) const
Short version of computeCellCenter.
Definition: DgmOctree.h:895
GenericIndexedCloudPersist * m_theAssociatedCloud
Associated cloud.
Definition: DgmOctree.h:1233
GenericIndexedCloudPersist * associatedCloud() const
Returns the associated cloud.
Definition: DgmOctree.h:1191
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos, unsigned char level) const
Definition: DgmOctree.h:798
std::vector< unsigned int > cellIndexesContainer
Octree cell indexes container.
Definition: DgmOctree.h:95
const int * getMinFillIndexes(unsigned char level) const
Definition: DgmOctree.h:474
static PointCoordinateType ComputeMinDistanceToCellBorder(const CCVector3 &queryPoint, PointCoordinateType cs, const CCVector3 &cellCenter)
Definition: DgmOctree.h:1057
CCVector3 m_dimMax
Max coordinates of the octree bounding-box.
Definition: DgmOctree.h:1245
bool(*)(const octreeCell &, void **, NormalizedProgress *) octreeCellFunc
Definition: DgmOctree.h:395
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos) const
Definition: DgmOctree.h:779
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos, unsigned char level, bool &inBounds) const
Definition: DgmOctree.h:823
unsigned getNumberOfProjectedPoints() const
Returns the number of points projected into the octree.
Definition: DgmOctree.h:446
~DgmOctree() override=default
DgmOctree destructor.
void computeCellCenter(const Tuple3i &cellPos, unsigned char level, CCVector3 &center) const
Definition: DgmOctree.h:878
const PointCoordinateType & getCellSize(unsigned char level) const
Returns the octree cells length for a given level of subdivision.
Definition: DgmOctree.h:494
std::vector< CellCode > cellCodesContainer
Octree cell codes container.
Definition: DgmOctree.h:92
unsigned m_numberOfProjectedPoints
Number of points projected in the octree.
Definition: DgmOctree.h:1236
void computeCellCenter(CellCode code, unsigned char level, CCVector3 &center, bool isCodeTruncated=false) const
Definition: DgmOctree.h:862
const CCVector3 & getOctreeMins() const
Returns the lower boundaries of the octree.
Definition: DgmOctree.h:453
RayCastProcess
Ray casting processes.
Definition: DgmOctree.h:1179
const CCVector3 & getOctreeMaxs() const
Returns the higher boundaries of the octree.
Definition: DgmOctree.h:458
std::vector< IndexAndCode > cellsContainer
Container of 'IndexAndCode' structures.
Definition: DgmOctree.h:351
const CellCode & getCellCode(unsigned index) const
Returns the ith cell code.
Definition: DgmOctree.h:963
CCVector3 m_dimMin
Min coordinates of the octree bounding-box.
Definition: DgmOctree.h:1243
const cellsContainer & pointsAndTheirCellCodes() const
Returns the octree 'structure'.
Definition: DgmOctree.h:1196
cellsContainer m_thePointsAndTheirCellCodes
The coded octree structure.
Definition: DgmOctree.h:1230
const unsigned & getCellNumber(unsigned char level) const
Returns the number of cells for a given level of subdivision.
Definition: DgmOctree.h:1038
std::vector< PointDescriptor > NeighboursSet
A set of neighbours.
Definition: DgmOctree.h:133
A generic 3D point cloud with index-based and presistent access to points.
A very simple point cloud (no point duplication)
__host__ __device__ int2 abs(int2 v)
Definition: cutil_math.h:1267
Generic file read and write utility for python interface.
unsigned char octreeLevel
Input/output parameters structure for getPointsInBoxNeighbourhood.
Definition: DgmOctree.h:727
unsigned char level
subdivision level at which to apply the extraction process
Definition: DgmOctree.h:737
NeighboursSet neighbours
Neighbour points falling inside the box.
Definition: DgmOctree.h:735
CCVector3 * axes
Box axes (optional)
Definition: DgmOctree.h:731
BoxNeighbourhood()
Default constructor.
Definition: DgmOctree.h:740
CCVector3 dimensions
Box dimensions.
Definition: DgmOctree.h:733
Structure used during nearest neighbour search.
Definition: DgmOctree.h:136
CellDescriptor()=default
Default empty constructor.
CellDescriptor(const CCVector3 &C, unsigned i)
Constructor from a point and an index.
Definition: DgmOctree.h:146
unsigned index
First point index in associated NeighboursSet.
Definition: DgmOctree.h:140
unsigned char level
subdivision level at which to apply the extraction process
Definition: DgmOctree.h:670
PointCoordinateType maxHalfLength
Cylinder (half) length.
Definition: DgmOctree.h:666
NeighboursSet neighbours
Neighbour points falling inside the cylinder.
Definition: DgmOctree.h:668
PointCoordinateType radius
Cylinder radius.
Definition: DgmOctree.h:664
CCVector3 dir
Cylinder axis (direction)
Definition: DgmOctree.h:662
Association between an index and the code of an octree cell.
Definition: DgmOctree.h:301
IndexAndCode(unsigned index, CellCode code)
Constructor from an index and a code.
Definition: DgmOctree.h:311
IndexAndCode(const IndexAndCode &ic)
Copy constructor.
Definition: DgmOctree.h:315
IndexAndCode()
Default constructor.
Definition: DgmOctree.h:308
static bool codeComp(const IndexAndCode &a, const IndexAndCode &b)
Compares two IndexAndCode instances based on their code.
Definition: DgmOctree.h:333
bool operator<(const IndexAndCode &iac) const
Code-based 'less than' comparison operator.
Definition: DgmOctree.h:319
static bool indexComp(const IndexAndCode &a, const IndexAndCode &b)
Compares two IndexAndCode instances based on their index.
Definition: DgmOctree.h:344
bool operator>(const IndexAndCode &iac) const
Code-based 'greater than' comparison operator.
Definition: DgmOctree.h:324
Container of in/out parameters for nearest neighbour(s) search.
Definition: DgmOctree.h:161
unsigned char level
Level of subdivision of the octree at which to start the search.
Definition: DgmOctree.h:171
double maxSearchSquareDistd
Maximum neihgbours distance.
Definition: DgmOctree.h:196
Tuple3i cellPos
Position in the octree of the cell including the query point.
Definition: DgmOctree.h:184
CCVector3 cellCenter
Coordinates of the center of the cell including the query point.
Definition: DgmOctree.h:189
unsigned minNumberOfNeighbors
Minimal number of neighbours to find.
Definition: DgmOctree.h:177
bool ready
Whether pointsInSphericalNeighbourhood is ready or not.
Definition: DgmOctree.h:267
void prepare(PointCoordinateType radius, PointCoordinateType cellSize)
Updates maxD2 and minD2 with search radius and cellSize.
Definition: DgmOctree.h:270
Structure used during nearest neighbour search.
Definition: DgmOctree.h:101
PointDescriptor(const CCVector3 *P, unsigned index, double d2)
Constructor with point, its index and square distance.
Definition: DgmOctree.h:117
const CCVector3 * point
Point.
Definition: DgmOctree.h:103
PointDescriptor(const CCVector3 *P, unsigned index)
Constructor with point and its index.
Definition: DgmOctree.h:113
double squareDistd
Point associated distance value.
Definition: DgmOctree.h:107
PointDescriptor()
Default constructor.
Definition: DgmOctree.h:110
static bool distComp(const PointDescriptor &a, const PointDescriptor &b)
Comparison operator.
Definition: DgmOctree.h:126
Tuple3i prevMinCornerPos
Previous search box (min corner)
Definition: DgmOctree.h:708
Tuple3i prevMaxCornerPos
Previous search box (max corner)
Definition: DgmOctree.h:710
PointCoordinateType currentHalfLength
Current search depth.
Definition: DgmOctree.h:701
NeighboursSet potentialCandidates
Vector to store potential candidates for the next pass.
Definition: DgmOctree.h:706
Octree cell descriptor.
Definition: DgmOctree.h:354
ReferenceCloud * points
Set of points lying inside this cell.
Definition: DgmOctree.h:365
unsigned index
Cell index in octree structure (see m_thePointsAndTheirCellCodes)
Definition: DgmOctree.h:363
const DgmOctree * parentOctree
Octree to which the cell belongs.
Definition: DgmOctree.h:359
unsigned char level
Cell level of subdivision.
Definition: DgmOctree.h:367
CellCode truncatedCode
Truncated cell code.
Definition: DgmOctree.h:361
Internal structure used to perform a top-down scan of the octree.
Definition: DgmOctree.h:1210
unsigned pos
Cell position inside subdivision level.
Definition: DgmOctree.h:1215
unsigned elements
Number of points in cell.
Definition: DgmOctree.h:1217
unsigned char level
Subdivision level.
Definition: DgmOctree.h:1219
Definition: lsd.c:149