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
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
int size
A generic 3D point cloud with index-based and presistent access to points.
A very simple point cloud (no point duplication)
void setPointScalarValue(unsigned pointIndex, ScalarType value) override
Sets the ith point associated scalar value.
virtual ScalarType getCurrentPointScalarValue() const
Returns the current point associated scalar value.
virtual void swap(unsigned i, unsigned j)
Swaps two point references.
bool enableScalarField() override
Enables the scalar field associated to the cloud.
unsigned char testVisibility(const CCVector3 &P) const override
BoundingBox m_bbox
Bounding-box.
std::vector< unsigned int > ReferencesContainer
Container of 3D point indexes.
std::atomic< unsigned > m_globalIterator
Iterator on the point references container.
void getPoint(unsigned index, CCVector3 &P) const override
Returns the ith point.
std::mutex m_mutex
For concurrent access.
void placeIteratorAtBeginning() override
Sets the cloud iterator at the beginning.
virtual unsigned getCurrentPointGlobalIndex() const
Returns the global index of the point pointed by the current element.
virtual const GenericIndexedCloudPersist * getAssociatedCloud() const
Returns the associated (source) cloud (const version)
virtual GenericIndexedCloudPersist * getAssociatedCloud()
Returns the associated (source) cloud.
unsigned size() const override
Returns the number of points.
void invalidateBoundingBox()
Invalidates the bounding-box.
const CCVector3 * getNextPoint() override
Returns the next point (relatively to the global iterator position)
virtual void removeCurrentPointGlobalIndex()
Removes current element.
ReferencesContainer m_theIndexes
Indexes of (some of) the associated cloud points.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
GenericIndexedCloudPersist * m_theAssociatedCloud
Associated cloud.
virtual unsigned capacity() const
Returns max capacity.
virtual void setCurrentPointScalarValue(ScalarType value)
Sets the current point associated scalar value.
void getPoint(unsigned index, double P[3]) const override
const CCVector3 * getPointPersistentPtr(unsigned index) override
Returns the ith point as a persistent pointer.
~ReferenceCloud() override=default
Destructor.
bool isScalarFieldEnabled() const override
Returns true if the scalar field is enabled, false otherwise.
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
ScalarType getPointScalarValue(unsigned pointIndex) const override
Returns the ith point associated scalar value.
virtual void forwardIterator()
Forwards the local element iterator.
Generic file read and write utility for python interface.
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1370