ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CVPointCloud.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
12 #include "PointCloudTpl.h"
13 
14 namespace cloudViewer {
15 
19  : public PointCloudTpl<GenericIndexedCloudPersist> {
20 public:
22  PointCloud() = default;
23 
25  ~PointCloud() override = default;
26 
28  bool reserveNormals(unsigned newCount) {
29  if (m_normals.capacity() < newCount) {
30  try {
31  m_normals.reserve(newCount);
32  } catch (const std::bad_alloc&) {
33  return false;
34  }
35  }
36 
37  return true;
38  }
39 
40  // inherited from PointCloudTpl
41  bool resize(unsigned newCount) override {
43  return false;
44  }
45 
46  // resize the normals as well
47  if (m_normals.capacity() != 0) {
48  try {
49  m_normals.resize(newCount);
50  } catch (const std::bad_alloc&) {
51  return false;
52  }
53  }
54 
55  return true;
56  }
57 
59 
61  inline void addNormal(const CCVector3& N) {
62  assert(m_normals.size() < m_normals.capacity());
63  m_normals.push_back(N);
64  }
65 
67  std::vector<CCVector3>& normals() { return m_normals; }
68 
70  const std::vector<CCVector3>& normals() const { return m_normals; }
71 
72  // inherited from cloudViewer::GenericIndexedCloud
73  bool normalsAvailable() const override {
74  return !m_normals.empty() && m_normals.size() >= size();
75  }
76  const CCVector3* getNormal(unsigned pointIndex) const override {
77  return &m_normals[pointIndex];
78  }
79 
80 protected:
82  std::vector<CCVector3> m_normals;
83 };
84 
85 } // namespace cloudViewer
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
int size
const std::vector< CCVector3 > & normals() const
Returns the set of normals (const version)
Definition: CVPointCloud.h:70
bool reserveNormals(unsigned newCount)
Reserves memory to store the normals.
Definition: CVPointCloud.h:28
bool resize(unsigned newCount) override
Resizes the point database.
Definition: CVPointCloud.h:41
~PointCloud() override=default
Default destructor.
std::vector< CCVector3 > m_normals
Point normals (if any)
Definition: CVPointCloud.h:82
PointCloud()=default
Default constructor.
const CCVector3 * getNormal(unsigned pointIndex) const override
If per-point normals are available, returns the one at a specific index.
Definition: CVPointCloud.h:76
void addNormal(const CCVector3 &N)
Adds a normal.
Definition: CVPointCloud.h:61
bool normalsAvailable() const override
Returns whether normals are available.
Definition: CVPointCloud.h:73
std::vector< CCVector3 > & normals()
Returns the set of normals.
Definition: CVPointCloud.h:67
Generic file read and write utility for python interface.