44 #ifndef OPENMESH_PROPERTY_HH 45 #define OPENMESH_PROPERTY_HH 52 #include <OpenMesh/Core/Mesh/Handles.hh> 53 #include <OpenMesh/Core/Utils/BaseProperty.hh> 94 typedef std::vector<T> vector_type;
96 typedef typename vector_type::reference reference;
97 typedef typename vector_type::const_reference const_reference;
103 const std::string& _name =
"<unknown>",
104 const std::string& _internal_type_name =
"<unknown>")
114 virtual void reserve(
size_t _n)
override { data_.reserve(_n); }
115 virtual void resize(
size_t _n)
override { data_.resize(_n); }
116 virtual void clear()
override { data_.clear(); vector_type().swap(data_); }
117 virtual void push_back()
override { data_.push_back(T()); }
118 virtual void swap(
size_t _i0,
size_t _i1)
override 119 { std::swap(data_[_i0], data_[_i1]); }
120 virtual void copy(
size_t _i0,
size_t _i1)
override 121 { data_[_i1] = data_[_i0]; }
126 { check_and_set_persistent<T>( _yn ); }
128 virtual size_t n_elements()
const override {
return data_.size(); }
129 virtual size_t element_size()
const override {
return IO::size_of<T>(); }
131 #ifndef DOXY_IGNORE_THIS 133 size_t operator () (
size_t _b,
const T& _v )
134 {
return _b + IO::size_of<T>(_v); }
142 return std::accumulate(data_.begin(), data_.end(), size_t(0), plus());
145 virtual size_t size_of(
size_t _n_elem)
const override 148 virtual size_t store( std::ostream& _ostr,
bool _swap )
const override 150 if ( IO::is_streamable<vector_type>() )
151 return IO::store(_ostr, data_, _swap );
154 bytes += IO::store( _ostr, data_[i], _swap );
158 virtual size_t restore( std::istream& _istr,
bool _swap )
override 160 if ( IO::is_streamable<vector_type>() )
161 return IO::restore(_istr, data_, _swap );
164 bytes += IO::restore( _istr, data_[i], _swap );
192 assert(
size_t(_idx) < data_.size() );
199 assert(
size_t(_idx) < data_.size());
228 typedef std::vector<bool> vector_type;
229 typedef bool value_type;
230 typedef vector_type::reference reference;
231 typedef vector_type::const_reference const_reference;
235 explicit PropertyT(
const std::string& _name =
"<unknown>",
const std::string& _internal_type_name=
"" )
241 virtual void reserve(
size_t _n)
override { data_.reserve(_n); }
242 virtual void resize(
size_t _n)
override { data_.resize(_n); }
243 virtual void clear()
override { data_.clear(); vector_type().swap(data_); }
244 virtual void push_back()
override { data_.push_back(
bool()); }
245 virtual void swap(
size_t _i0,
size_t _i1)
override 246 {
bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
247 virtual void copy(
size_t _i0,
size_t _i1)
override 248 { data_[_i1] = data_[_i0]; }
254 check_and_set_persistent<bool>( _yn );
257 virtual size_t n_elements()
const override {
return data_.size(); }
260 virtual size_t size_of(
size_t _n_elem)
const override 262 return _n_elem / 8 + ((_n_elem % 8)!=0);
265 size_t store( std::ostream& _ostr,
bool )
const override 269 size_t N = data_.size() / 8;
270 size_t R = data_.size() % 8;
276 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
278 bits =
static_cast<unsigned char>(data_[bidx])
279 | (static_cast<unsigned char>(data_[bidx+1]) << 1)
280 | (static_cast<unsigned char>(data_[bidx+2]) << 2)
281 | (static_cast<unsigned char>(data_[bidx+3]) << 3)
282 | (static_cast<unsigned char>(data_[bidx+4]) << 4)
283 | (static_cast<unsigned char>(data_[bidx+5]) << 5)
284 | (static_cast<unsigned char>(data_[bidx+6]) << 6)
285 | (static_cast<unsigned char>(data_[bidx+7]) << 7);
293 for (idx=0; idx < R; ++idx)
294 bits |= static_cast<unsigned char>(data_[bidx+idx]) << idx;
304 size_t restore( std::istream& _istr,
bool )
override 308 size_t N = data_.size() / 8;
309 size_t R = data_.size() % 8;
315 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
318 data_[bidx+0] = (bits & 0x01) != 0;
319 data_[bidx+1] = (bits & 0x02) != 0;
320 data_[bidx+2] = (bits & 0x04) != 0;
321 data_[bidx+3] = (bits & 0x08) != 0;
322 data_[bidx+4] = (bits & 0x10) != 0;
323 data_[bidx+5] = (bits & 0x20) != 0;
324 data_[bidx+6] = (bits & 0x40) != 0;
325 data_[bidx+7] = (bits & 0x80) != 0;
332 for (idx=0; idx < R; ++idx)
333 data_[bidx+idx] = (bits & (1<<idx)) != 0;
356 assert(
size_t(_idx) < data_.size() );
363 assert(
size_t(_idx) < data_.size());
391 typedef std::string Value;
392 typedef std::vector<std::string> vector_type;
393 typedef std::string value_type;
394 typedef vector_type::reference reference;
395 typedef vector_type::const_reference const_reference;
399 explicit PropertyT(
const std::string& _name =
"<unknown>",
const std::string& _internal_type_name=
"" )
405 virtual void reserve(
size_t _n)
override { data_.reserve(_n); }
406 virtual void resize(
size_t _n)
override { data_.resize(_n); }
407 virtual void clear()
override { data_.clear(); vector_type().swap(data_); }
408 virtual void push_back()
override { data_.push_back(std::string()); }
409 virtual void swap(
size_t _i0,
size_t _i1)
override {
410 std::swap(data_[_i0], data_[_i1]);
412 virtual void copy(
size_t _i0,
size_t _i1)
override 413 { data_[_i1] = data_[_i0]; }
418 { check_and_set_persistent<std::string>( _yn ); }
420 virtual size_t n_elements()
const override {
return data_.size(); }
425 virtual size_t size_of(
size_t )
const override 429 size_t store( std::ostream& _ostr,
bool _swap )
const override 430 {
return IO::store( _ostr, data_, _swap ); }
432 size_t restore( std::istream& _istr,
bool _swap )
override 433 {
return IO::restore( _istr, data_, _swap ); }
437 const value_type*
data()
const {
441 return (value_type*) &data_[0];
446 assert(
size_t(_idx) < data_.size());
447 return ((value_type*) &data_[0])[_idx];
452 assert(
size_t(_idx) < data_.size());
453 return ((value_type*) &data_[0])[_idx];
471 typedef std::vector<T> vector_type;
472 typedef T value_type;
473 typedef typename vector_type::reference reference;
474 typedef typename vector_type::const_reference const_reference;
487 typedef T value_type;
502 typedef T value_type;
517 typedef T value_type;
532 typedef T value_type;
547 typedef T value_type;
554 template <
typename HandleT>
559 template <
typename T>
565 template <
typename T>
571 template <
typename T>
577 template <
typename T>
583 #endif // OPENMESH_PROPERTY_HH defined
virtual void push_back() override
Extend the number of elements by one.
Handle for a edge entity.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Handle for a face entity.
size_t store(std::ostream &_ostr, bool _swap) const override
Store self as one binary block. Max. length of a string is 65535 bytes.
virtual size_t size_of() const override
Return size of property in bytes.
PropertyT< T > * clone() const override
Make a copy of self.
Handle type for meshes to simplify some template programming.
virtual void copy(size_t _i0, size_t _i1) override
Copy one element to another.
size_t size_of(const T &_v)
virtual size_t size_of(size_t) const override
virtual void copy(size_t _i0, size_t _i1) override
Copy one element to another.
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
Handle for a halfedge entity.
BaseProperty(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
virtual void resize(size_t _n) override
Resize storage to hold n elements.
virtual void reserve(size_t _n) override
Reserve memory for n elements.
virtual void reserve(size_t _n) override
Reserve memory for n elements.
virtual void resize(size_t _n) override
Resize storage to hold n elements.
virtual size_t size_of(size_t _n_elem) const override
Base class for all handle types.
Handle for a vertex entity.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
virtual void resize(size_t _n) override
Resize storage to hold n elements.
virtual void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
virtual void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
size_t restore(std::istream &_istr, bool) override
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
virtual size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
virtual size_t size_of(size_t _n_elem) const override
virtual void clear() override
Clear all elements and free memory.
virtual void set_persistent(bool _yn) override
Default property class for any type T.
virtual void clear() override
Clear all elements and free memory.
virtual size_t n_elements() const override
Number of elements in property.
virtual void set_persistent(bool _yn) override
virtual size_t size_of() const
Return size of property in bytes.
const T * data() const
Get pointer to array (does not work for T==bool)
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
virtual void push_back() override
Extend the number of elements by one.
virtual void copy(size_t _i0, size_t _i1) override
Copy one element to another.
virtual size_t size_of() const override
Return size of property in bytes.
size_t restore(std::istream &_istr, bool _swap) override
virtual void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
virtual size_t store(std::ostream &_ostr, bool _swap) const override
Store self as one binary block.
virtual size_t n_elements() const override
Number of elements in property.
virtual void set_persistent(bool _yn) override
virtual size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
const vector_type & data_vector() const
Const access to property vector.
virtual size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
virtual size_t n_elements() const override
Number of elements in property.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual size_t restore(std::istream &_istr, bool _swap) override
virtual void push_back() override
Extend the number of elements by one.
virtual void reserve(size_t _n) override
Reserve memory for n elements.
PropertyT< value_type > * clone() const override
Return a deep copy of self.
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
const vector_type & data_vector() const
Const access to property vector.
virtual size_t size_of(void) const override
Return size of property in bytes.
size_t store(std::ostream &_ostr, bool) const override
Store self as one binary block.
PropertyT(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
PropertyT(const PropertyT &_rhs)
Copy constructor.
PropertyT< bool > * clone() const override
Make a copy of self.
virtual void clear() override
Clear all elements and free memory.
reference operator[](int _idx)
Access the i'th element. No range check is performed!