ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
DgmOctreeReferenceCloud.cpp
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 
9 
10 using namespace cloudViewer;
11 
13  DgmOctree::NeighboursSet* associatedSet, unsigned size /*=0*/)
14  : m_globalIterator(0),
15  m_validBB(false),
16  m_set(associatedSet),
17  m_size(size == 0 && associatedSet ? static_cast<unsigned>(m_set->size())
18  : size) {
19  assert(associatedSet);
20 }
21 
23  // empty cloud?!
24  unsigned count = size();
25  if (count) {
26  m_bbMin = m_bbMax = CCVector3(0, 0, 0);
27  return;
28  }
29 
30  // initialize BBox with first point
31  m_bbMin = m_bbMax = *m_set->at(0).point;
32 
33  for (unsigned i = 1; i < count; ++i) {
34  const CCVector3& P = *m_set->at(i).point;
35  // X boundaries
36  if (m_bbMin.x > P.x)
37  m_bbMin.x = P.x;
38  else if (m_bbMax.x < P.x)
39  m_bbMax.x = P.x;
40 
41  // Y boundaries
42  if (m_bbMin.y > P.y)
43  m_bbMin.y = P.y;
44  else if (m_bbMax.y < P.y)
45  m_bbMax.y = P.y;
46 
47  // Z boundaries
48  if (m_bbMin.z > P.z)
49  m_bbMin.z = P.z;
50  else if (m_bbMax.z < P.z)
51  m_bbMax.z = P.z;
52  }
53 
54  m_validBB = true;
55 }
56 
58  CCVector3& bbMax) {
59  if (!m_validBB) computeBB();
60 
61  bbMin = m_bbMin;
62  bbMax = m_bbMax;
63 }
64 
66  unsigned count = size();
67  for (unsigned i = 0; i < count; ++i) {
68  // we must change from double container to 'ScalarType' one!
69  ScalarType sqDist = static_cast<ScalarType>(m_set->at(i).squareDistd);
70  action(*m_set->at(i).point, sqDist);
71  m_set->at(i).squareDistd = static_cast<double>(sqDist);
72  }
73 }
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Definition: CVGeom.h:798
int size
int count
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override
Returns the cloud bounding box.
void forEach(genericPointAction action) override
Fast iteration mechanism.
unsigned size() const override
Returns the number of points.
CCVector3 m_bbMin
Bounding-box min corner.
DgmOctreeReferenceCloud(DgmOctree::NeighboursSet *associatedSet, unsigned count=0)
Default constructor.
virtual void computeBB()
Computes the cloud bounding-box (internal)
DgmOctree::NeighboursSet * m_set
Associated PointDescriptor set.
CCVector3 m_bbMax
Bounding-box max corner.
std::vector< PointDescriptor > NeighboursSet
A set of neighbours.
Definition: DgmOctree.h:133
std::function< void(const CCVector3 &, ScalarType &)> genericPointAction
Generic function applied to a point (used by foreach)
Definition: GenericCloud.h:30
Generic file read and write utility for python interface.