28#ifndef EASY3D_CORE_POINT_CLOUD_H
29#define EASY3D_CORE_POINT_CLOUD_H
31#include <easy3d/core/model.h>
32#include <easy3d/core/types.h>
33#include <easy3d/core/property.h>
67 int idx()
const {
return idx_; }
86 return idx_ == _rhs.idx_;
95 return idx_ != _rhs.idx_;
104 return idx_ < _rhs.idx_;
140 std::ostream&
operator<<(std::ostream& os)
const {
return os <<
'v' <<
idx(); }
241 if (cloud_ && cloud_->has_garbage()) while (cloud_->is_valid(hnd_) && cloud_->is_deleted(hnd_)) ++hnd_.idx_;
257 return (hnd_==rhs.hnd_);
278 while (cloud_->has_garbage() && cloud_->is_valid(hnd_) && cloud_->is_deleted(hnd_)) ++hnd_.idx_;
290 while (cloud_->has_garbage() && cloud_->is_valid(hnd_) && cloud_->is_deleted(hnd_)) --hnd_.idx_;
416 unsigned int vertices_size()
const {
return static_cast<unsigned int>(vprops_.size()); }
433 void resize(
unsigned int nv) { vprops_.resize(nv); }
590 return vprops_.rename(old_name, new_name);
600 return mprops_.rename(old_name, new_name);
610 return vprops_.get_type(
name);
619 return mprops_.get_type(
name);
627 return vprops_.properties();
634 return mprops_.properties();
700 const std::vector<vec3>&
points()
const override {
return vpoint_.vector(); }
706 std::vector<vec3>&
points()
override {
return vpoint_.vector(); }
722 PropertyContainer vprops_;
723 PropertyContainer mprops_;
725 VertexProperty<bool> vdeleted_;
726 VertexProperty<vec3> vpoint_;
728 unsigned int deleted_vertices_;
742 return (os <<
'v' << v.
idx());
const std::string & name() const
The name of a model.
Definition model.h:61
Model(const std::string &name="unknown")
Default constructor. The parameter name is optional, but it is useful for handling multiple models wi...
Definition model.cpp:33
bool operator!=(const BaseHandle &_rhs) const
Are two handles different?
Definition point_cloud.h:94
bool is_valid() const
Return whether the handle is valid, i.e., the index is not equal to -1.
Definition point_cloud.h:78
int idx() const
Get the underlying index of this handle.
Definition point_cloud.h:67
bool operator<(const BaseHandle &_rhs) const
Compare operator useful for sorting handles.
Definition point_cloud.h:103
bool operator==(const BaseHandle &_rhs) const
Are two handles equal?
Definition point_cloud.h:85
void reset()
Reset handle to be invalid (index = -1).
Definition point_cloud.h:72
BaseHandle(int _idx=-1)
Constructor.
Definition point_cloud.h:61
Cloud property of type T.
Definition point_cloud.h:191
ModelProperty()=default
Default constructor.
Property< T >::reference operator[](size_t idx) override
Access the data stored for the cloud.
Definition point_cloud.h:208
ModelProperty(Property< T > p)
Constructor with property.
Definition point_cloud.h:201
Property< T >::const_reference operator[](size_t idx) const override
Access the data stored for the cloud.
Definition point_cloud.h:217
This helper class is a container for iterating through all vertices using C++11 range-based for-loops...
Definition point_cloud.h:309
VertexContainer(VertexIterator _begin, VertexIterator _end)
Constructor.
Definition point_cloud.h:316
VertexIterator begin() const
Get the begin iterator.
Definition point_cloud.h:321
VertexIterator end() const
Get the end iterator.
Definition point_cloud.h:326
This class iterates linearly over all vertices.
Definition point_cloud.h:232
VertexIterator(Vertex v=Vertex(), const PointCloud *m=nullptr)
Default constructor.
Definition point_cloud.h:239
Vertex operator*() const
Get the vertex the iterator refers to.
Definition point_cloud.h:248
bool operator==(const VertexIterator &rhs) const
Are two iterators equal?
Definition point_cloud.h:255
VertexIterator & operator--()
Pre-decrement iterator.
Definition point_cloud.h:286
bool operator!=(const VertexIterator &rhs) const
Are two iterators different?
Definition point_cloud.h:265
VertexIterator & operator++()
Pre-increment iterator.
Definition point_cloud.h:274
Vertex property of type T.
Definition point_cloud.h:151
VertexProperty(Property< T > p)
Constructor with property.
Definition point_cloud.h:161
Property< T >::const_reference operator[](Vertex v) const
Access the data stored for vertex v.
Definition point_cloud.h:178
Property< T >::reference operator[](Vertex v)
Access the data stored for vertex v.
Definition point_cloud.h:168
VertexProperty()=default
Default constructor.
A data structure for point clouds.
Definition point_cloud.h:45
const vec3 & position(Vertex v) const
Gets the position of a vertex (read only).
Definition point_cloud.h:687
const std::type_info & get_vertex_property_type(const std::string &name) const
Get the type_info T of vertex property name.
Definition point_cloud.h:609
PointCloud()
Default constructor.
Definition point_cloud.cpp:32
bool remove_vertex_property(const std::string &n)
Remove the vertex property named n.
Definition point_cloud.h:566
PointCloud & operator+=(const PointCloud &other)
Merges another point cloud into the current one.
Definition point_cloud.h:369
bool rename_vertex_property(const std::string &old_name, const std::string &new_name)
Rename a vertex property given its name.
Definition point_cloud.h:589
VertexContainer vertices() const
Returns vertex container for C++11 range-based for-loops.
Definition point_cloud.h:671
PointCloud & operator=(const PointCloud &rhs)
Assign rhs to *this. Performs a deep copy of all properties.
Definition point_cloud.cpp:49
bool has_garbage() const
Are there deleted vertices?
Definition point_cloud.h:440
VertexProperty< T > vertex_property(const std::string &name, const T t=T())
Gets or adds a vertex property of type T with name name.
Definition point_cloud.h:539
ModelProperty< T > get_model_property(const std::string &name) const
Gets the model property named name of type T.
Definition point_cloud.h:528
std::vector< std::string > vertex_properties() const
Returns the names of all vertex properties.
Definition point_cloud.h:626
PointCloud & assign(const PointCloud &rhs)
Assign rhs to *this. Does not copy custom properties.
Definition point_cloud.cpp:90
VertexProperty< T > get_vertex_property(const std::string &name) const
Get the vertex property named name of type T.
Definition point_cloud.h:513
bool is_deleted(Vertex v) const
Returns whether vertex v is deleted.
Definition point_cloud.h:461
std::vector< std::string > model_properties() const
Returns the names of all model properties.
Definition point_cloud.h:633
void collect_garbage()
Remove deleted vertices.
Definition point_cloud.cpp:202
const std::type_info & get_model_property_type(const std::string &name) const
Get the type_info T of model property name.
Definition point_cloud.h:618
std::vector< vec3 > & points() override
Returns the vector of vertex positions.
Definition point_cloud.h:706
ModelProperty< T > model_property(const std::string &name, const T t=T())
Gets or adds a model property of type T with name name.
Definition point_cloud.h:549
VertexProperty< T > add_vertex_property(const std::string &name, const T t=T())
Add a vertex property of type T with name name and default value t.
Definition point_cloud.h:488
bool remove_model_property(ModelProperty< T > &p)
Remove the model property p.
Definition point_cloud.h:574
bool rename_model_property(const std::string &old_name, const std::string &new_name)
Rename a model property given its name.
Definition point_cloud.h:599
ModelProperty< T > add_model_property(const std::string &name, const T t=T())
Add a vertex property of type T with name name and default value t.
Definition point_cloud.h:503
void property_stats(std::ostream &output) const override
Prints the names of all properties to an output stream (e.g., std::cout).
Definition point_cloud.cpp:144
void clear()
Clear cloud: remove all vertices.
Definition point_cloud.cpp:122
void resize(unsigned int nv)
Resize space for vertices and their currently associated properties.
Definition point_cloud.h:433
PointCloud(const PointCloud &rhs)
Copy constructor: copies rhs to *this. Performs a deep copy of all properties.
Definition point_cloud.h:351
PointCloud & join(const PointCloud &other)
Merges another point cloud into the current one.
Definition point_cloud.cpp:73
~PointCloud() override=default
Destructor (is virtual, since we inherit from Model).
vec3 & position(Vertex v)
Gets the position of a vertex.
Definition point_cloud.h:694
unsigned int vertices_size() const
Returns number of (deleted and valid) vertices in the cloud.
Definition point_cloud.h:416
bool remove_model_property(const std::string &n)
Remove the model property named n.
Definition point_cloud.h:581
void delete_vertex(Vertex v)
Deletes the vertex v from the cloud.
Definition point_cloud.cpp:188
VertexIterator vertices_begin() const
Returns start iterator for vertices.
Definition point_cloud.h:655
bool remove_vertex_property(VertexProperty< T > &p)
Remove the vertex property p.
Definition point_cloud.h:559
VertexIterator vertices_end() const
Returns end iterator for vertices.
Definition point_cloud.h:663
bool is_valid(Vertex v) const
Return whether vertex v is valid, i.e. the index is stores it within the array bounds.
Definition point_cloud.h:470
const std::vector< vec3 > & points() const override
Returns the vector of vertex positions (read only).
Definition point_cloud.h:700
unsigned int n_vertices() const
Returns number of vertices in the cloud.
Definition point_cloud.h:422
Vertex add_vertex(const vec3 &p)
Add a new vertex with position p.
Definition point_cloud.cpp:177
void push_back()
Adds a new element to each vector.
Definition property.h:771
PropertyArray< T >::const_reference const_reference
The const reference type of the property.
Definition property.h:329
virtual reference operator[](size_t i)
Accesses the i-th element.
Definition property.h:365
Property(PropertyArray< T > *p=nullptr)
Constructor.
Definition property.h:338
PropertyArray< T >::reference reference
The reference type of the property.
Definition property.h:328
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
std::ostream & operator<<(std::ostream &os, Graph::Vertex v)
Output stream support for Graph::Vertex.
Definition graph.h:1300
Helper structure to be able to use std::unordered_map.
Definition point_cloud.h:110
std::size_t operator()(const BaseHandle &h) const
Hash function for BaseHandle.
Definition point_cloud.h:116
This type represents a vertex (internally it is basically an index).
Definition point_cloud.h:129
std::ostream & operator<<(std::ostream &os) const
Output stream operator for Vertex.
Definition point_cloud.h:140
Vertex(int _idx=-1)
Default constructor (with invalid index).
Definition point_cloud.h:134