21 #define OCTREE_CODES_64_BITS
30 class GenericIndexedCloudPersist;
31 class GenericProgressCallback;
32 class NormalizedProgress;
47 static unsigned char GET_BIT_SHIFT(
unsigned char level);
54 static int OCTREE_LENGTH(
int level);
64 #ifdef OCTREE_CODES_64_BITS
65 static const int MAX_OCTREE_LEVEL = 21;
67 static const int MAX_OCTREE_LEVEL = 10;
74 #ifdef OCTREE_CODES_64_BITS
84 static const int MAX_OCTREE_LENGTH = (1 << MAX_OCTREE_LEVEL);
89 static const CellCode INVALID_CELL_CODE = (~static_cast<CellCode>(0));
114 :
point(P), pointIndex(index), squareDistd(-1.0) {}
118 :
point(P), pointIndex(index), squareDistd(d2) {}
237 : queryPoint(0, 0, 0),
239 minNumberOfNeighbors(1),
242 maxSearchSquareDistd(0),
243 alreadyVisitedNeighbourhoodSize(0),
244 theNearestPointIndex(0) {}
249 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
272 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
275 minOutD2 = radius + cellDiag;
276 minOutD2 *= minOutD2;
277 maxInD2 = radius - cellDiag;
288 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
312 : theIndex(index), theCode(code) {}
316 : theIndex(ic.theIndex), theCode(ic.theCode) {}
335 return a.theCode < b.theCode;
346 return a.theIndex < b.theIndex;
410 virtual void clear();
437 const CCVector3* pointsMinFilter =
nullptr,
438 const CCVector3* pointsMaxFilter =
nullptr,
447 return m_numberOfProjectedPoints;
475 return m_fillIndexes + 6 * level;
486 return m_fillIndexes + 6 * level + 3;
495 return m_cellSize[level];
505 void getCellDistanceFromBorders(
const Tuple3i& cellPos,
507 int* cellDists)
const;
518 void getCellDistanceFromBorders(
const Tuple3i& cellPos,
520 int neighbourhoodLength,
521 int* cellDists)
const;
539 bool clearOutputCloud =
true)
const;
549 bool getPointsInCell(CellCode cellCode,
552 bool isCodeTruncated =
false,
553 bool clearOutputCloud =
true)
const;
565 cellCodesContainer& cellCodes,
568 bool areCodesTruncated =
false)
const;
588 unsigned findPointNeighbourhood(
591 unsigned maxNumberOfNeighbors,
593 double& maxSquareDist,
594 double maxSearchDist = 0,
595 int* finalNeighbourhoodSize =
nullptr)
const;
605 double findTheNearestNeighborStartingFromCell(
606 NearestNeighboursSearchStruct& nNSS)
const;
617 unsigned findNearestNeighborsStartingFromCell(
618 NearestNeighboursSearchStruct& nNSS,
619 bool getOnlyPointsWithValidScalar =
false)
const;
633 int findNeighborsInASphereStartingFromCell(
634 NearestNeighboursSearchStruct& nNSS,
636 bool sortValues =
true)
const;
651 int getPointsInSphericalNeighbourhood(
const CCVector3& sphereCenter,
653 NeighboursSet& neighbours,
654 unsigned char level)
const;
682 onlyPositiveDir(false) {}
694 std::size_t getPointsInCylindricalNeighbourhood(
695 CylindricalNeighbourhood&
params)
const;
714 currentHalfLength(0),
715 prevMinCornerPos(-1, -1, -1),
716 prevMaxCornerPos(0, 0, 0) {}
723 std::size_t getPointsInCylindricalNeighbourhoodProgressive(
724 ProgressiveCylindricalNeighbourhood&
params)
const;
741 : center(0, 0, 0), axes(nullptr), dimensions(0, 0, 0), level(0) {}
749 std::size_t getPointsInBoxNeighbourhood(BoxNeighbourhood&
params)
const;
763 static CellCode GenerateTruncatedCellCode(
const Tuple3i& cellPos,
764 unsigned char level);
766 #ifndef OCTREE_CODES_64_BITS
768 static CellCode GenerateTruncatedCellCode(
const Tuple3s& pos,
769 unsigned char level);
784 cellPos.
x =
static_cast<int>( (thePoint->
x - m_dimMin.x) / cs);
785 cellPos.
y =
static_cast<int>( (thePoint->
y - m_dimMin.y) / cs);
786 cellPos.
z =
static_cast<int>( (thePoint->
z - m_dimMin.z) / cs);
800 unsigned char level)
const {
801 assert(level <= MAX_OCTREE_LEVEL);
803 getTheCellPosWhichIncludesThePoint(thePoint, cellPos);
805 const unsigned char dec = MAX_OCTREE_LEVEL - level;
826 bool& inBounds)
const {
827 assert(level <= MAX_OCTREE_LEVEL);
829 getTheCellPosWhichIncludesThePoint(thePoint, cellPos);
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);
835 const unsigned char dec = MAX_OCTREE_LEVEL - level;
849 void getCellPos(CellCode code,
852 bool isCodeTruncated)
const;
865 bool isCodeTruncated =
false)
const {
867 getCellPos(code, level, cellPos, isCodeTruncated);
869 return computeCellCenter(cellPos, level, center);
893 #ifndef OCTREE_CODES_64_BITS
919 void computeCellLimits(CellCode code,
923 bool isCodeTruncated =
false)
const;
933 unsigned char findBestLevelForAGivenNeighbourhoodSizeExtraction(
943 unsigned char findBestLevelForComparisonWithOctree(
951 unsigned char findBestLevelForAGivenPopulationPerCell(
952 unsigned indicativeNumberOfPointsPerCell)
const;
959 unsigned char findBestLevelForAGivenCellNumber(
960 unsigned indicativeNumberOfCells)
const;
964 return m_thePointsAndTheirCellCodes[index].theCode;
975 bool getCellCodes(
unsigned char level,
976 cellCodesContainer& vec,
977 bool truncatedCodes =
false)
const;
987 bool getCellIndexes(
unsigned char level, cellIndexesContainer& vec)
const;
998 bool getCellCodesAndIndexes(
unsigned char level,
1000 bool truncatedCodes =
false)
const;
1011 void diff(
const cellCodesContainer& codesA,
1012 const cellCodesContainer& codesB,
1013 cellCodesContainer& diffA,
1014 cellCodesContainer& diffB)
const;
1030 const cellsContainer& codesA,
1031 const cellsContainer& codesB,
1039 assert(level <= MAX_OCTREE_LEVEL);
1040 return m_cellCount[level];
1048 double computeMeanOctreeDensity(
unsigned char level)
const;
1063 if (d2 > d1) d1 = d2;
1066 return cs / 2 - (d2 > d1 ? d2 : d1);
1088 int extractCCs(
const cellCodesContainer& cellCodes,
1089 unsigned char level,
1108 int extractCCs(
unsigned char level,
1139 unsigned executeFunctionForAllCellsStartingAtLevel(
1140 unsigned char startingLevel,
1141 octreeCellFunc func,
1142 void** additionalParameters,
1143 unsigned minNumberOfPointsPerCell,
1144 unsigned maxNumberOfPointsPerCell,
1145 bool multiThread =
true,
1147 const char* functionTitle =
nullptr,
1148 int maxThreadCount = 0);
1169 unsigned executeFunctionForAllCellsAtLevel(
1170 unsigned char level,
1171 octreeCellFunc func,
1172 void** additionalParameters,
1173 bool multiThread =
false,
1175 const char* functionTitle =
nullptr,
1176 int maxThreadCount = 0);
1184 double maxRadiusOrFov,
1187 RayCastProcess process,
1188 std::vector<PointDescriptor>& output)
const;
1192 return m_theAssociatedCloud;
1197 return m_thePointsAndTheirCellCodes;
1202 static bool MultiThreadSupport();
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];
1281 void updateMinAndMaxTables();
1285 void updateCellSizeTable();
1289 void updateCellCountTable();
1296 void computeCellsStatistics(
unsigned char level);
1306 void getNeighborCellsAround(
const Tuple3i& cellPos,
1308 int neighbourhoodLength,
1309 unsigned char level)
const;
1318 void getPointsInNeighbourCellsAround(
1320 int neighbourhoodLength,
1321 bool getOnlyPointsWithValidScalar =
false)
const;
1323 #ifdef TEST_CELLS_FOR_SPHERICAL_NN
1324 void getPointsInNeighbourCellsAround(
1326 int minNeighbourhoodLength,
1327 int maxNeighbourhoodLength)
const;
1340 unsigned getCellIndex(
CellCode truncatedCellCode,
1341 unsigned char bitDec)
const;
1353 unsigned getCellIndex(
CellCode truncatedCellCode,
1354 unsigned char bitDec,
1356 unsigned end)
const;
constexpr double SQRT_3
Square root of 3.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
cmdLineReadable * params[]
The octree structure used throughout the library.
const int * getMaxFillIndexes(unsigned char level) const
unsigned CellCode
Type of the code of an octree cell.
std::vector< CellDescriptor > NeighbourCellsSet
A set of neighbour cells descriptors.
void computeCellCenter(const Tuple3s &cellPos, unsigned char level, CCVector3 ¢er) const
Short version of computeCellCenter.
GenericIndexedCloudPersist * m_theAssociatedCloud
Associated cloud.
GenericIndexedCloudPersist * associatedCloud() const
Returns the associated cloud.
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos, unsigned char level) const
std::vector< unsigned int > cellIndexesContainer
Octree cell indexes container.
const int * getMinFillIndexes(unsigned char level) const
static PointCoordinateType ComputeMinDistanceToCellBorder(const CCVector3 &queryPoint, PointCoordinateType cs, const CCVector3 &cellCenter)
CCVector3 m_dimMax
Max coordinates of the octree bounding-box.
bool(*)(const octreeCell &, void **, NormalizedProgress *) octreeCellFunc
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos) const
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos, unsigned char level, bool &inBounds) const
unsigned getNumberOfProjectedPoints() const
Returns the number of points projected into the octree.
~DgmOctree() override=default
DgmOctree destructor.
void computeCellCenter(const Tuple3i &cellPos, unsigned char level, CCVector3 ¢er) const
const PointCoordinateType & getCellSize(unsigned char level) const
Returns the octree cells length for a given level of subdivision.
std::vector< CellCode > cellCodesContainer
Octree cell codes container.
unsigned m_numberOfProjectedPoints
Number of points projected in the octree.
void computeCellCenter(CellCode code, unsigned char level, CCVector3 ¢er, bool isCodeTruncated=false) const
const CCVector3 & getOctreeMins() const
Returns the lower boundaries of the octree.
RayCastProcess
Ray casting processes.
const CCVector3 & getOctreeMaxs() const
Returns the higher boundaries of the octree.
std::vector< IndexAndCode > cellsContainer
Container of 'IndexAndCode' structures.
const CellCode & getCellCode(unsigned index) const
Returns the ith cell code.
CCVector3 m_dimMin
Min coordinates of the octree bounding-box.
const cellsContainer & pointsAndTheirCellCodes() const
Returns the octree 'structure'.
cellsContainer m_thePointsAndTheirCellCodes
The coded octree structure.
const unsigned & getCellNumber(unsigned char level) const
Returns the number of cells for a given level of subdivision.
std::vector< PointDescriptor > NeighboursSet
A set of neighbours.
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)
Generic file read and write utility for python interface.
Input/output parameters structure for getPointsInBoxNeighbourhood.
unsigned char level
subdivision level at which to apply the extraction process
CCVector3 center
Box center.
NeighboursSet neighbours
Neighbour points falling inside the box.
CCVector3 * axes
Box axes (optional)
BoxNeighbourhood()
Default constructor.
CCVector3 dimensions
Box dimensions.
Structure used during nearest neighbour search.
CellDescriptor()=default
Default empty constructor.
CellDescriptor(const CCVector3 &C, unsigned i)
Constructor from a point and an index.
unsigned index
First point index in associated NeighboursSet.
CCVector3 center
Cell center.
unsigned char level
subdivision level at which to apply the extraction process
PointCoordinateType maxHalfLength
Cylinder (half) length.
NeighboursSet neighbours
Neighbour points falling inside the cylinder.
CCVector3 center
Cylinder center.
CylindricalNeighbourhood()
Default constructor.
PointCoordinateType radius
Cylinder radius.
CCVector3 dir
Cylinder axis (direction)
Association between an index and the code of an octree cell.
IndexAndCode(unsigned index, CellCode code)
Constructor from an index and a code.
IndexAndCode(const IndexAndCode &ic)
Copy constructor.
IndexAndCode()
Default constructor.
static bool codeComp(const IndexAndCode &a, const IndexAndCode &b)
Compares two IndexAndCode instances based on their code.
bool operator<(const IndexAndCode &iac) const
Code-based 'less than' comparison operator.
static bool indexComp(const IndexAndCode &a, const IndexAndCode &b)
Compares two IndexAndCode instances based on their index.
bool operator>(const IndexAndCode &iac) const
Code-based 'greater than' comparison operator.
CellCode theCode
cell code
Structure used during nearest neighbour search.
PointDescriptor(const CCVector3 *P, unsigned index, double d2)
Constructor with point, its index and square distance.
const CCVector3 * point
Point.
PointDescriptor(const CCVector3 *P, unsigned index)
Constructor with point and its index.
double squareDistd
Point associated distance value.
PointDescriptor()
Default constructor.
unsigned pointIndex
Point index.
static bool distComp(const PointDescriptor &a, const PointDescriptor &b)
Comparison operator.
Tuple3i prevMinCornerPos
Previous search box (min corner)
Tuple3i prevMaxCornerPos
Previous search box (max corner)
PointCoordinateType currentHalfLength
Current search depth.
NeighboursSet potentialCandidates
Vector to store potential candidates for the next pass.
ProgressiveCylindricalNeighbourhood()
ReferenceCloud * points
Set of points lying inside this cell.
unsigned index
Cell index in octree structure (see m_thePointsAndTheirCellCodes)
const DgmOctree * parentOctree
Octree to which the cell belongs.
unsigned char level
Cell level of subdivision.
CellCode truncatedCode
Truncated cell code.
Internal structure used to perform a top-down scan of the octree.
unsigned pos
Cell position inside subdivision level.
unsigned elements
Number of points in cell.
unsigned char level
Subdivision level.