| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #ifndef POINTS_GRID_H
|
| | #define POINTS_GRID_H
|
| |
|
| | #include <limits>
|
| | #include <set>
|
| |
|
| | #include <Base/BoundBox.h>
|
| | #include <Base/Vector3D.h>
|
| |
|
| | #include "Points.h"
|
| |
|
| | static constexpr int POINTS_CT_GRID = 256;
|
| | static constexpr int POINTS_MAX_GRIDS = 100000;
|
| | static constexpr int POINTS_CT_GRID_PER_AXIS = 20;
|
| | static constexpr float PONTSGRID_BBOX_EXTENSION = 10.0F;
|
| |
|
| |
|
| | namespace Points
|
| | {
|
| | class PointsGrid;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | class PointsExport PointsGrid
|
| | {
|
| | public:
|
| |
|
| |
|
| |
|
| | explicit PointsGrid(const PointKernel& rclM);
|
| |
|
| | PointsGrid();
|
| |
|
| | PointsGrid(const PointKernel& rclM, int iCtGridPerAxis);
|
| |
|
| | PointsGrid(const PointKernel& rclM, double fGridLen);
|
| |
|
| | PointsGrid(const PointKernel& rclM, unsigned long ulX, unsigned long ulY, unsigned long ulZ);
|
| | PointsGrid(const PointsGrid&) = default;
|
| | PointsGrid(PointsGrid&&) = default;
|
| |
|
| | virtual ~PointsGrid() = default;
|
| | PointsGrid& operator=(const PointsGrid&) = default;
|
| | PointsGrid& operator=(PointsGrid&&) = default;
|
| |
|
| |
|
| | public:
|
| | |
| |
|
| | virtual void Attach(const PointKernel& rclM);
|
| |
|
| | virtual void Rebuild(
|
| | unsigned long ulPerGrid = POINTS_CT_GRID,
|
| | unsigned long ulMaxGrid = POINTS_MAX_GRIDS
|
| | );
|
| |
|
| | virtual void Rebuild(int iCtGridPerAxis = POINTS_CT_GRID_PER_AXIS);
|
| |
|
| | virtual void Rebuild(unsigned long ulX, unsigned long ulY, unsigned long ulZ);
|
| |
|
| |
|
| |
|
| |
|
| | virtual unsigned long InSide(
|
| | const Base::BoundBox3d& rclBB,
|
| | std::vector<unsigned long>& raulElements,
|
| | bool bDelDoubles = true
|
| | ) const;
|
| |
|
| | virtual unsigned long InSide(
|
| | const Base::BoundBox3d& rclBB,
|
| | std::set<unsigned long>& raulElementss
|
| | ) const;
|
| |
|
| | virtual unsigned long InSide(
|
| | const Base::BoundBox3d& rclBB,
|
| | std::vector<unsigned long>& raulElements,
|
| | const Base::Vector3d& rclOrg,
|
| | double fMaxDist,
|
| | bool bDelDoubles = true
|
| | ) const;
|
| | |
| |
|
| | void SearchNearestFromPoint(const Base::Vector3d& rclPt, std::set<unsigned long>& rclInd) const;
|
| |
|
| |
|
| |
|
| | virtual void GetGridLengths(double& rfLenX, double& rfLenY, double& rfLenZ) const
|
| | {
|
| | rfLenX = _fGridLenX;
|
| | rfLenY = _fGridLenY;
|
| | rfLenZ = _fGridLenZ;
|
| | }
|
| |
|
| | virtual void GetCtGrids(unsigned long& rulX, unsigned long& rulY, unsigned long& rulZ) const
|
| | {
|
| | rulX = _ulCtGridsX;
|
| | rulY = _ulCtGridsY;
|
| | rulZ = _ulCtGridsZ;
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| | inline Base::BoundBox3d GetBoundBox(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const;
|
| |
|
| | inline Base::BoundBox3d GetBoundBox() const;
|
| |
|
| |
|
| | unsigned long GetCtElements(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const
|
| | {
|
| | return _aulGrid[ulX][ulY][ulZ].size();
|
| | }
|
| |
|
| | unsigned long FindElements(const Base::Vector3d& rclPoint, std::set<unsigned long>& aulElements) const;
|
| |
|
| | virtual void Validate(const PointKernel& rclM);
|
| |
|
| | virtual void Validate();
|
| |
|
| | virtual bool Verify() const;
|
| | |
| |
|
| | virtual void Position(
|
| | const Base::Vector3d& rclPoint,
|
| | unsigned long& rulX,
|
| | unsigned long& rulY,
|
| | unsigned long& rulZ
|
| | ) const;
|
| |
|
| | unsigned long GetElements(
|
| | unsigned long ulX,
|
| | unsigned long ulY,
|
| | unsigned long ulZ,
|
| | std::set<unsigned long>& raclInd
|
| | ) const;
|
| |
|
| | protected:
|
| |
|
| | inline bool CheckPos(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const;
|
| |
|
| | virtual void InitGrid();
|
| |
|
| | virtual void Clear();
|
| |
|
| | virtual void CalculateGridLength(unsigned long ulCtGrid, unsigned long ulMaxGrids);
|
| |
|
| | virtual void CalculateGridLength(int iCtGridPerAxis);
|
| |
|
| | virtual void RebuildGrid();
|
| |
|
| | unsigned long HasElements() const
|
| | {
|
| | return _pclPoints->size();
|
| | }
|
| | |
| |
|
| | void GetHull(
|
| | unsigned long ulX,
|
| | unsigned long ulY,
|
| | unsigned long ulZ,
|
| | unsigned long ulDistance,
|
| | std::set<unsigned long>& raclInd
|
| | ) const;
|
| |
|
| | private:
|
| | std::vector<std::vector<std::vector<std::set<unsigned long>>>> _aulGrid; |
| |
|
| | const PointKernel* _pclPoints;
|
| | unsigned long _ulCtElements;
|
| | unsigned long _ulCtGridsX;
|
| | unsigned long _ulCtGridsY;
|
| | unsigned long _ulCtGridsZ;
|
| | double _fGridLenX;
|
| | double _fGridLenY;
|
| | double _fGridLenZ;
|
| | double _fMinX;
|
| | double _fMinY;
|
| | double _fMinZ;
|
| |
|
| |
|
| | friend class PointsGridIterator;
|
| | friend class PointsGridIteratorStatistic;
|
| |
|
| | public:
|
| | protected:
|
| | |
| |
|
| | void AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0F);
|
| |
|
| | void Pos(
|
| | const Base::Vector3d& rclPoint,
|
| | unsigned long& rulX,
|
| | unsigned long& rulY,
|
| | unsigned long& rulZ
|
| | ) const;
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | class PointsExport PointsGridIterator
|
| | {
|
| | public:
|
| |
|
| | explicit PointsGridIterator(const PointsGrid& rclG);
|
| |
|
| | Base::BoundBox3d GetBoundBox() const
|
| | {
|
| | return _rclGrid.GetBoundBox(_ulX, _ulY, _ulZ);
|
| | }
|
| |
|
| | void GetElements(std::vector<unsigned long>& raulElements) const
|
| | {
|
| | raulElements.insert(
|
| | raulElements.end(),
|
| | _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(),
|
| | _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()
|
| | );
|
| | }
|
| |
|
| |
|
| |
|
| | void Init()
|
| | {
|
| | _ulX = _ulY = _ulZ = 0;
|
| | }
|
| |
|
| | bool More() const
|
| | {
|
| | return (_ulZ < _rclGrid._ulCtGridsZ);
|
| | }
|
| |
|
| | void Next()
|
| | {
|
| | if (++_ulX >= (_rclGrid._ulCtGridsX)) {
|
| | _ulX = 0;
|
| | }
|
| | else {
|
| | return;
|
| | }
|
| | if (++_ulY >= (_rclGrid._ulCtGridsY)) {
|
| | _ulY = 0;
|
| | _ulZ++;
|
| | }
|
| | else {
|
| | return;
|
| | }
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | bool InitOnRay(
|
| | const Base::Vector3d& rclPt,
|
| | const Base::Vector3d& rclDir,
|
| | std::vector<unsigned long>& raulElements
|
| | );
|
| |
|
| | bool InitOnRay(
|
| | const Base::Vector3d& rclPt,
|
| | const Base::Vector3d& rclDir,
|
| | float fMaxSearchArea,
|
| | std::vector<unsigned long>& raulElements
|
| | );
|
| |
|
| | bool NextOnRay(std::vector<unsigned long>& raulElements);
|
| |
|
| |
|
| |
|
| | void GetGridPos(unsigned long& rulX, unsigned long& rulY, unsigned long& rulZ) const
|
| | {
|
| | rulX = _ulX;
|
| | rulY = _ulY;
|
| | rulZ = _ulZ;
|
| | }
|
| |
|
| | private:
|
| | const PointsGrid& _rclGrid;
|
| | unsigned long _ulX {0};
|
| | unsigned long _ulY {0};
|
| | unsigned long _ulZ {0};
|
| | Base::Vector3d _clPt;
|
| | Base::Vector3d _clDir;
|
| | bool _bValidRay {false};
|
| | float _fMaxSearchArea {std::numeric_limits<float>::max()};
|
| |
|
| | struct GridElement
|
| | {
|
| | GridElement(unsigned long x, unsigned long y, unsigned long z)
|
| | : x {x}
|
| | , y {y}
|
| | , z {z}
|
| | {}
|
| | bool operator<(const GridElement& pos) const
|
| | {
|
| | if (x == pos.x) {
|
| | if (y == pos.y) {
|
| | return z < pos.z;
|
| | }
|
| | else {
|
| | return y < pos.y;
|
| | }
|
| | }
|
| | else {
|
| | return x < pos.x;
|
| | }
|
| | }
|
| |
|
| | private:
|
| | unsigned long x, y, z;
|
| | };
|
| | std::set<GridElement> _cSearchPositions;
|
| | };
|
| |
|
| |
|
| |
|
| | inline Base::BoundBox3d PointsGrid::GetBoundBox(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const
|
| | {
|
| | double fX = _fMinX + (double(ulX) * _fGridLenX);
|
| | double fY = _fMinY + (double(ulY) * _fGridLenY);
|
| | double fZ = _fMinZ + (double(ulZ) * _fGridLenZ);
|
| |
|
| | return Base::BoundBox3d(fX, fY, fZ, fX + _fGridLenX, fY + _fGridLenY, fZ + _fGridLenZ);
|
| | }
|
| |
|
| | inline Base::BoundBox3d PointsGrid::GetBoundBox() const
|
| | {
|
| | return Base::BoundBox3d(
|
| | _fMinX,
|
| | _fMinY,
|
| | _fMinZ,
|
| | _fMinX + (_fGridLenX * double(_ulCtGridsX)),
|
| | _fMinY + (_fGridLenY * double(_ulCtGridsY)),
|
| | _fMinZ + (_fGridLenZ * double(_ulCtGridsZ))
|
| | );
|
| | }
|
| |
|
| | inline bool PointsGrid::CheckPos(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const
|
| | {
|
| | return ((ulX < _ulCtGridsX) && (ulY < _ulCtGridsY) && (ulZ < _ulCtGridsZ));
|
| | }
|
| |
|
| |
|
| |
|
| | }
|
| |
|
| | #endif
|
| |
|