ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ReferenceCloud.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 "BoundingBox.h"
13 
14 // System
15 #include <atomic>
16 #include <cassert>
17 #include <mutex>
18 #include <vector>
19 
20 namespace cloudViewer {
21 
23 
30 public:
32  explicit ReferenceCloud(GenericIndexedCloudPersist* associatedCloud);
33 
35  ReferenceCloud(const ReferenceCloud& refCloud);
36 
38  ~ReferenceCloud() override = default;
39 
40  //**** inherited form GenericCloud ****//
41  inline unsigned size() const override {
42  return static_cast<unsigned>(m_theIndexes.size());
43  }
44  void forEach(genericPointAction action) override;
45  void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
46  inline unsigned char testVisibility(const CCVector3& P) const override {
47  assert(m_theAssociatedCloud);
48  return m_theAssociatedCloud->testVisibility(P);
49  }
50  inline void placeIteratorAtBeginning() override { m_globalIterator = 0; }
51  inline const CCVector3* getNextPoint() override {
52  assert(m_theAssociatedCloud);
53  return (m_globalIterator < size()
54  ? m_theAssociatedCloud->getPoint(
55  m_theIndexes[m_globalIterator++])
56  : nullptr);
57  }
58  inline bool enableScalarField() override {
59  assert(m_theAssociatedCloud);
60  return m_theAssociatedCloud->enableScalarField();
61  }
62  inline bool isScalarFieldEnabled() const override {
63  assert(m_theAssociatedCloud);
64  return m_theAssociatedCloud->isScalarFieldEnabled();
65  }
66  inline void setPointScalarValue(unsigned pointIndex,
67  ScalarType value) override {
68  assert(m_theAssociatedCloud && pointIndex < size());
69  m_theAssociatedCloud->setPointScalarValue(m_theIndexes[pointIndex],
70  value);
71  }
72  inline ScalarType getPointScalarValue(unsigned pointIndex) const override {
73  assert(m_theAssociatedCloud && pointIndex < size());
74  return m_theAssociatedCloud->getPointScalarValue(
75  m_theIndexes[pointIndex]);
76  }
77 
78  //**** inherited form GenericIndexedCloud ****//
79  inline const CCVector3* getPoint(unsigned index) const override {
80  assert(m_theAssociatedCloud && index < size());
81  return m_theAssociatedCloud->getPoint(m_theIndexes[index]);
82  }
83  inline void getPoint(unsigned index, CCVector3& P) const override {
84  assert(m_theAssociatedCloud && index < size());
85  m_theAssociatedCloud->getPoint(m_theIndexes[index], P);
86  }
87  inline void getPoint(unsigned index, double P[3]) const override {
88  assert(m_theAssociatedCloud && index < size());
89  m_theAssociatedCloud->getPoint(m_theIndexes[index], P);
90  }
91 
92  //**** inherited form GenericIndexedCloudPersist ****//
93  inline const CCVector3* getPointPersistentPtr(unsigned index) override {
94  assert(m_theAssociatedCloud && index < size());
95  return m_theAssociatedCloud->getPointPersistentPtr(m_theIndexes[index]);
96  }
97 
100 
103  inline virtual unsigned getPointGlobalIndex(unsigned localIndex) const {
104  return m_theIndexes[localIndex];
105  }
106 
108 
110  virtual const CCVector3* getCurrentPointCoordinates() const;
111 
113  inline virtual unsigned getCurrentPointGlobalIndex() const {
114  assert(m_globalIterator < size());
115  return m_theIndexes[m_globalIterator];
116  }
117 
119  inline virtual ScalarType getCurrentPointScalarValue() const {
120  assert(m_theAssociatedCloud && m_globalIterator < size());
121  return m_theAssociatedCloud->getPointScalarValue(
122  m_theIndexes[m_globalIterator]);
123  }
124 
126  inline virtual void setCurrentPointScalarValue(ScalarType value) {
127  assert(m_theAssociatedCloud && m_globalIterator < size());
128  m_theAssociatedCloud->setPointScalarValue(
129  m_theIndexes[m_globalIterator], value);
130  }
131 
133  inline virtual void forwardIterator() { ++m_globalIterator; }
134 
136 
138  virtual void clear(bool releaseMemory = false);
139 
141 
145  virtual bool addPointIndex(unsigned globalIndex);
146 
148 
153  virtual bool addPointIndex(unsigned firstIndex, unsigned lastIndex);
154 
156 
159  virtual void setPointIndex(unsigned localIndex, unsigned globalIndex);
160 
162 
165  virtual bool reserve(unsigned n);
166 
168 
171  virtual bool resize(unsigned n);
172 
174  inline virtual unsigned capacity() const {
175  return static_cast<unsigned>(m_theIndexes.capacity());
176  }
177 
179 
185  inline virtual void swap(unsigned i, unsigned j) {
186  m_mutex.lock();
187  std::swap(m_theIndexes[i], m_theIndexes[j]);
188  m_mutex.unlock();
189  }
190 
192 
195  inline virtual void removeCurrentPointGlobalIndex() {
196  removePointGlobalIndex(m_globalIterator);
197  }
198 
200 
203  virtual void removePointGlobalIndex(unsigned localIndex);
204 
207  return m_theAssociatedCloud;
208  }
209 
212  const {
213  return m_theAssociatedCloud;
214  }
215 
217  virtual void setAssociatedCloud(GenericIndexedCloudPersist* cloud);
218 
220 
224  bool add(const ReferenceCloud& cloud);
225 
227  inline void invalidateBoundingBox() { m_bbox.setValidity(false); }
228 
229 protected:
231  using ReferencesContainer = std::vector<unsigned int>;
232 
235 
237  std::atomic<unsigned> m_globalIterator;
238 
241 
243 
248 
250  std::mutex m_mutex;
251 };
252 
253 } // namespace cloudViewer
cloudViewer::ReferenceCloud::setCurrentPointScalarValue
virtual void setCurrentPointScalarValue(ScalarType value)
Sets the current point associated scalar value.
Definition: ReferenceCloud.h:126
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::ReferenceCloud::getPoint
void getPoint(unsigned index, double P[3]) const override
Definition: ReferenceCloud.h:87
cloudViewer::ReferenceCloud::size
unsigned size() const override
Returns the number of points.
Definition: ReferenceCloud.h:41
cloudViewer::ReferenceCloud::swap
virtual void swap(unsigned i, unsigned j)
Swaps two point references.
Definition: ReferenceCloud.h:185
cloudViewer::ReferenceCloud::m_theAssociatedCloud
GenericIndexedCloudPersist * m_theAssociatedCloud
Associated cloud.
Definition: ReferenceCloud.h:247
cloudViewer::ReferenceCloud::getAssociatedCloud
virtual const GenericIndexedCloudPersist * getAssociatedCloud() const
Returns the associated (source) cloud (const version)
Definition: ReferenceCloud.h:211
cloudViewer::ReferenceCloud::getPoint
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
Definition: ReferenceCloud.h:79
cloudViewer::ReferenceCloud::capacity
virtual unsigned capacity() const
Returns max capacity.
Definition: ReferenceCloud.h:174
cloudViewer::ReferenceCloud::getCurrentPointScalarValue
virtual ScalarType getCurrentPointScalarValue() const
Returns the current point associated scalar value.
Definition: ReferenceCloud.h:119
cloudViewer::ReferenceCloud::getPointGlobalIndex
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
Definition: ReferenceCloud.h:103
cloudViewer::ReferenceCloud::ReferencesContainer
std::vector< unsigned int > ReferencesContainer
Container of 3D point indexes.
Definition: ReferenceCloud.h:231
cloudViewer::ReferenceCloud::m_mutex
std::mutex m_mutex
For concurrent access.
Definition: ReferenceCloud.h:250
cloudViewer::ReferenceCloud::getCurrentPointGlobalIndex
virtual unsigned getCurrentPointGlobalIndex() const
Returns the global index of the point pointed by the current element.
Definition: ReferenceCloud.h:113
cloudViewer::ReferenceCloud::isScalarFieldEnabled
bool isScalarFieldEnabled() const override
Returns true if the scalar field is enabled, false otherwise.
Definition: ReferenceCloud.h:62
size
int size
Definition: FileIOFactory.cpp:130
Vector3Tpl< PointCoordinateType >
GenericIndexedCloudPersist.h
cloudViewer::ReferenceCloud::forwardIterator
virtual void forwardIterator()
Forwards the local element iterator.
Definition: ReferenceCloud.h:133
std::swap
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1370
cloudViewer::ReferenceCloud::invalidateBoundingBox
void invalidateBoundingBox()
Invalidates the bounding-box.
Definition: ReferenceCloud.h:227
cloudViewer::ReferenceCloud::placeIteratorAtBeginning
void placeIteratorAtBeginning() override
Sets the cloud iterator at the beginning.
Definition: ReferenceCloud.h:50
cloudViewer::ReferenceCloud::getPoint
void getPoint(unsigned index, CCVector3 &P) const override
Returns the ith point.
Definition: ReferenceCloud.h:83
cloudViewer::ReferenceCloud::enableScalarField
bool enableScalarField() override
Enables the scalar field associated to the cloud.
Definition: ReferenceCloud.h:58
cloudViewer::ReferenceCloud::setPointScalarValue
void setPointScalarValue(unsigned pointIndex, ScalarType value) override
Sets the ith point associated scalar value.
Definition: ReferenceCloud.h:66
cloudViewer::ReferenceCloud::m_bbox
BoundingBox m_bbox
Bounding-box.
Definition: ReferenceCloud.h:240
cloudViewer::ReferenceCloud::testVisibility
unsigned char testVisibility(const CCVector3 &P) const override
Definition: ReferenceCloud.h:46
cloudViewer::GenericIndexedCloudPersist
A generic 3D point cloud with index-based and presistent access to points.
Definition: GenericIndexedCloudPersist.h:18
cloudViewer::ReferenceCloud::m_globalIterator
std::atomic< unsigned > m_globalIterator
Iterator on the point references container.
Definition: ReferenceCloud.h:237
cloudViewer::ReferenceCloud
A very simple point cloud (no point duplication)
Definition: ReferenceCloud.h:29
cloudViewer::ReferenceCloud::getNextPoint
const CCVector3 * getNextPoint() override
Returns the next point (relatively to the global iterator position)
Definition: ReferenceCloud.h:51
cloudViewer::ReferenceCloud::m_theIndexes
ReferencesContainer m_theIndexes
Indexes of (some of) the associated cloud points.
Definition: ReferenceCloud.h:234
cloudViewer::BoundingBoxTpl< PointCoordinateType >
cloudViewer::ReferenceCloud::removeCurrentPointGlobalIndex
virtual void removeCurrentPointGlobalIndex()
Removes current element.
Definition: ReferenceCloud.h:195
cloudViewer::ReferenceCloud::getAssociatedCloud
virtual GenericIndexedCloudPersist * getAssociatedCloud()
Returns the associated (source) cloud.
Definition: ReferenceCloud.h:206
cloudViewer::ReferenceCloud::getPointPersistentPtr
const CCVector3 * getPointPersistentPtr(unsigned index) override
Returns the ith point as a persistent pointer.
Definition: ReferenceCloud.h:93
cloudViewer::ReferenceCloud::getPointScalarValue
ScalarType getPointScalarValue(unsigned pointIndex) const override
Returns the ith point associated scalar value.
Definition: ReferenceCloud.h:72
CV_CORE_LIB_API
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
BoundingBox.h