44 #ifndef OPENMESH_PROPERTY_HH 45 #define OPENMESH_PROPERTY_HH 51 #include <OpenMesh/Core/System/config.h> 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 const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:349
virtual void resize(size_t _n) override
Resize storage to hold n elements.
Definition: Property.hh:406
virtual void push_back() override
Extend the number of elements by one.
Definition: Property.hh:117
Handle representing a face property.
Definition: Property.hh:529
PropertyT(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
Definition: Property.hh:102
Handle for a face entity.
Definition: Handles.hh:141
size_t size_of(const T &_v)
Binary read a short from _is and perform byte swapping if _swap is true.
Definition: StoreRestore.hh:89
virtual size_t size_of() const override
Return size of property in bytes.
Definition: Property.hh:422
Handle representing a vertex property.
Definition: Property.hh:484
PropertyT< value_type > * clone() const override
Return a deep copy of self.
Definition: Property.hh:456
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:180
virtual void reserve(size_t _n) override
Reserve memory for n elements.
Definition: Property.hh:114
size_t restore(std::istream &_istr, bool _swap) override
Restore self from a binary block.
Definition: Property.hh:432
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:60
Definition: Property.hh:555
PropertyT(const PropertyT &_rhs)
Copy constructor.
Definition: Property.hh:109
virtual void copy(size_t _i0, size_t _i1) override
Copy one element to another.
Definition: Property.hh:120
virtual void set_persistent(bool _yn) override
Enable or disable persistency.
Definition: Property.hh:417
virtual void clear() override
Clear all elements and free memory.
Definition: Property.hh:407
size_t store(std::ostream &_ostr, bool _swap) const override
Store self as one binary block. Max. length of a string is 65535 bytes.
Definition: Property.hh:429
virtual void reserve(size_t _n) override
Reserve memory for n elements.
Definition: Property.hh:241
virtual void resize(size_t _n) override
Resize storage to hold n elements.
Definition: Property.hh:115
virtual size_t n_elements() const override
Number of elements in property.
Definition: Property.hh:257
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: BaseProperty.hh:65
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:361
virtual void clear() override
Clear all elements and free memory.
Definition: Property.hh:243
virtual void copy(size_t _i0, size_t _i1) override
Copy one element to another.
Definition: Property.hh:412
virtual size_t size_of(size_t _n_elem) const override
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:260
virtual void set_persistent(bool _yn) override
Enable or disable persistency.
Definition: Property.hh:125
virtual size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:258
const T * data() const
Get pointer to array (does not work for T==bool)
Definition: Property.hh:171
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:185
virtual size_t restore(std::istream &_istr, bool _swap) override
Restore self from a binary block.
Definition: Property.hh:158
size_t restore(std::istream &_istr, bool) override
Restore self from a binary block.
Definition: Property.hh:304
virtual void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
Definition: Property.hh:245
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:344
BaseProperty(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:83
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:197
virtual void reserve(size_t _n) override
Reserve memory for n elements.
Definition: Property.hh:405
virtual size_t n_elements() const override
Number of elements in property.
Definition: Property.hh:128
virtual size_t size_of(size_t) const override
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:425
virtual void set_persistent(bool _yn) override
Enable or disable persistency.
Definition: Property.hh:252
Handle for a vertex entity.
Definition: Handles.hh:120
Property specialization for bool type.
Definition: Property.hh:224
virtual size_t size_of() const override
Return size of property in bytes.
Definition: Property.hh:259
virtual void clear() override
Clear all elements and free memory.
Definition: Property.hh:116
virtual void resize(size_t _n) override
Resize storage to hold n elements.
Definition: Property.hh:242
virtual size_t size_of(size_t _n_elem) const override
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:145
Handle representing an edge property.
Definition: Property.hh:514
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:190
virtual void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
Definition: Property.hh:118
virtual size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:421
virtual void push_back() override
Extend the number of elements by one.
Definition: Property.hh:408
virtual size_t size_of(void) const override
Return size of property in bytes.
Definition: Property.hh:138
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
Definition: Property.hh:451
virtual void swap(size_t _i0, size_t _i1) override
Let two elements swap their storage place.
Definition: Property.hh:409
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:143
virtual size_t store(std::ostream &_ostr, bool _swap) const override
Store self as one binary block.
Definition: Property.hh:148
Handle for a edge entity.
Definition: Handles.hh:134
Base property handle.
Definition: Property.hh:468
Base class for all handle types.
Definition: Handles.hh:62
PropertyT< bool > * clone() const override
Make a copy of self.
Definition: Property.hh:368
Default property class for any type T.
Definition: Property.hh:89
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:354
Handle representing a mesh property.
Definition: Property.hh:544
Handle type for meshes to simplify some template programming.
Definition: Handles.hh:148
Handle representing a halfedge property.
Definition: Property.hh:499
virtual size_t element_size() const override
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:129
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
size_t store(std::ostream &_ostr, bool) const override
Store self as one binary block.
Definition: Property.hh:265
Handle for a halfedge entity.
Definition: Handles.hh:127
virtual void push_back() override
Extend the number of elements by one.
Definition: Property.hh:244
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:445
PropertyT< T > * clone() const override
Make a copy of self.
Definition: Property.hh:204
virtual void copy(size_t _i0, size_t _i1) override
Copy one element to another.
Definition: Property.hh:247
virtual size_t n_elements() const override
Number of elements in property.
Definition: Property.hh:420