mirror of https://github.com/CGAL/cgal
Add methods to easily transfer properties from one point set to another
This commit is contained in:
parent
237d7fcd30
commit
f778e5e151
|
|
@ -238,15 +238,6 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \cond SKIP_IN_MANUAL
|
|
||||||
Point_set_3 (const Point_set_3& ps)
|
|
||||||
{
|
|
||||||
*this = ps;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \endcond
|
|
||||||
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// \cond SKIP_IN_MANUAL
|
/// \cond SKIP_IN_MANUAL
|
||||||
|
|
@ -476,6 +467,15 @@ public:
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator insert (const Point_set_3& other, const Index& idx)
|
||||||
|
{
|
||||||
|
iterator out = insert();
|
||||||
|
Index new_idx = *out;
|
||||||
|
m_base.transfer(other.base(), idx, new_idx);
|
||||||
|
*out = new_idx; // Do not copy index from other point set
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// \name Accessors and Iterators
|
/// \name Accessors and Iterators
|
||||||
|
|
@ -840,6 +840,16 @@ public:
|
||||||
return m_points;
|
return m_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \cond SKIP_IN_MANUAL
|
||||||
|
void copy_properties (const Point_set_3& other)
|
||||||
|
{
|
||||||
|
m_base.copy_properties (other.base());
|
||||||
|
|
||||||
|
m_normals = this->property_map<Vector> ("normal").first; // In case normal was added
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns a vector with all strings that describe properties.
|
\brief Returns a vector with all strings that describe properties.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ public:
|
||||||
virtual void reset(size_t idx) = 0;
|
virtual void reset(size_t idx) = 0;
|
||||||
|
|
||||||
virtual bool transfer(const Base_property_array& other) = 0;
|
virtual bool transfer(const Base_property_array& other) = 0;
|
||||||
|
virtual bool transfer(const Base_property_array& other, std::size_t from, std::size_t to) = 0;
|
||||||
|
|
||||||
/// Let two elements swap their storage place.
|
/// Let two elements swap their storage place.
|
||||||
virtual void swap(size_t i0, size_t i1) = 0;
|
virtual void swap(size_t i0, size_t i1) = 0;
|
||||||
|
|
@ -77,12 +78,19 @@ public:
|
||||||
/// Return a deep copy of self.
|
/// Return a deep copy of self.
|
||||||
virtual Base_property_array* clone () const = 0;
|
virtual Base_property_array* clone () const = 0;
|
||||||
|
|
||||||
|
/// Return a empty copy of self.
|
||||||
|
virtual Base_property_array* empty_clone () const = 0;
|
||||||
|
|
||||||
/// Return the type_info of the property
|
/// Return the type_info of the property
|
||||||
virtual const std::type_info& type() = 0;
|
virtual const std::type_info& type() const = 0;
|
||||||
|
|
||||||
/// Return the name of the property
|
/// Return the name of the property
|
||||||
const std::string& name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
|
|
||||||
|
bool is_same (const Base_property_array& other)
|
||||||
|
{
|
||||||
|
return (name() == other.name() && type() == other.type());
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
@ -142,6 +150,18 @@ public: // virtual interface of Base_property_array
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool transfer(const Base_property_array& other, std::size_t from, std::size_t to)
|
||||||
|
{
|
||||||
|
const Property_array<T>* pa = dynamic_cast<const Property_array*>(&other);
|
||||||
|
if (pa != NULL)
|
||||||
|
{
|
||||||
|
data_[to] = (*pa)[from];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void shrink_to_fit()
|
virtual void shrink_to_fit()
|
||||||
{
|
{
|
||||||
vector_type(data_).swap(data_);
|
vector_type(data_).swap(data_);
|
||||||
|
|
@ -161,7 +181,13 @@ public: // virtual interface of Base_property_array
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const std::type_info& type() { return typeid(T); }
|
virtual Base_property_array* empty_clone() const
|
||||||
|
{
|
||||||
|
Property_array<T>* p = new Property_array<T>(this->name_, this->value_);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const std::type_info& type() const { return typeid(T); }
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -241,11 +267,11 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transfer(const Property_container& _rhs)
|
bool transfer(const Property_container& _rhs)
|
||||||
{
|
{
|
||||||
for(std::size_t i=0; i<parrays_.size(); ++i){
|
for(std::size_t i=0; i<parrays_.size(); ++i){
|
||||||
for (std::size_t j=0; j<_rhs.parrays_.size(); ++j){
|
for (std::size_t j=0; j<_rhs.parrays_.size(); ++j){
|
||||||
if(parrays_[i]->name() == _rhs.parrays_[j]->name()){
|
if(parrays_[i]->is_same (*(_rhs.parrays_[j]))){
|
||||||
parrays_[i]->transfer(* _rhs.parrays_[j]);
|
parrays_[i]->transfer(* _rhs.parrays_[j]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -253,6 +279,38 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy properties that don't already exist from another container
|
||||||
|
void copy_properties (const Property_container& _rhs)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < _rhs.parrays_.size(); ++ i)
|
||||||
|
{
|
||||||
|
bool property_already_exists = false;
|
||||||
|
for (std::size_t j = 0; j < parrays_.size(); ++ j)
|
||||||
|
if (_rhs.parrays_[i]->is_same (*(parrays_[j])))
|
||||||
|
{
|
||||||
|
property_already_exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property_already_exists)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
parrays_.push_back (_rhs.parrays_[i]->empty_clone());
|
||||||
|
parrays_.back()->resize(size_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfer one element with all properties
|
||||||
|
// WARNING: properties must be the same in the two containers
|
||||||
|
bool transfer(const Property_container& _rhs, std::size_t from, std::size_t to)
|
||||||
|
{
|
||||||
|
bool out = true;
|
||||||
|
for(std::size_t i=0; i<parrays_.size(); ++i)
|
||||||
|
if (!(parrays_[i]->transfer(* _rhs.parrays_[i], from, to)))
|
||||||
|
out = false;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
// returns the current size of the property arrays
|
// returns the current size of the property arrays
|
||||||
size_t size() const { return size_; }
|
size_t size() const { return size_; }
|
||||||
|
|
||||||
|
|
@ -529,6 +587,11 @@ public:
|
||||||
return parray_->transfer(*(other.parray_));
|
return parray_->transfer(*(other.parray_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool transfer (const Property_map_base& other, std::size_t from, std::size_t to)
|
||||||
|
{
|
||||||
|
return parray_->transfer(*(other.parray_), from, to);
|
||||||
|
}
|
||||||
|
|
||||||
/// Allows access to the underlying storage of the property. This
|
/// Allows access to the underlying storage of the property. This
|
||||||
/// is useful when the key associated with the properties is
|
/// is useful when the key associated with the properties is
|
||||||
/// unimportant and only the properties are of interest
|
/// unimportant and only the properties are of interest
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue