42 #ifndef OPENMESH_KERNEL_OSG_PROPERTYT_HH
43 #define OPENMESH_KERNEL_OSG_PROPERTYT_HH
49 #include <OpenMesh/Core/Mesh/BaseKernel.hh>
50 #include <OpenMesh/Core/Utils/GenProg.hh>
51 #include <OpenMesh/Core/Utils/Property.hh>
53 #include <osg/Geometry>
62 namespace Kernel_OSG {
84 template <
typename GeoProperty>
90 typedef GeoProperty property_t;
91 typedef typename property_t::PtrType property_ptr_t;
93 typedef typename property_t::StoredFieldType field_t;
94 typedef typename field_t::StoredType element_t;
95 typedef typename field_t::StoredType value_type;
101 const std::string& _name =
"<unknown>" )
108 oPropertyT(
const std::string& _name =
"<unknown>" )
111 data_ = property_t::create();
136 virtual void reserve(
size_t _n) { data_->getField().reserve( _n ); }
137 virtual void resize(
size_t _n) { data_->resize( _n ); }
138 virtual void push_back() { data_->resize( data_->size()+1 ); }
139 virtual void swap(
size_t _i0,
size_t _i1)
140 { std::swap( data_->getField()[_i0], data_->getField()[_i1] ); }
149 element_t *begin =
const_cast<element_t*
>(data());
151 element_t *dst =
const_cast<element_t*
>(dolly->data());
152 std::copy( begin, end, dst );
161 check_and_set_persistent<element_t>(_yn);
165 {
return data_==osg::NullFC ?
UnknownSize : data_->getSize(); }
170 virtual size_t store( std::ostream& _ostr,
bool _swap )
const
173 virtual size_t restore( std::istream& _istr,
bool _swap )
179 void clear(
void) { data_->clear(); }
184 property_ptr_t& osg_ptr()
187 const property_ptr_t& osg_ptr()
const
191 const element_t *data()
const
192 {
return &( (*this)[ 0 ] ); }
194 element_t& operator[](
size_t idx)
195 {
return data_->getField()[ idx ]; }
197 const element_t& operator[](
size_t idx)
const
198 {
return data_->getField()[ idx ]; }
203 property_ptr_t data_;
208 void osg_init_check(
void)
212 if ( data_ == osg::NullFC )
213 throw std::logic_error(
"OpenSG Runtime Environment is not initialized: " \
214 "Use osg::osgInit()");
217 oPropertyT(
const oPropertyT& );
285 template <
typename IsTriMesh >
291 typedef typename inherited_t::property_ptr_t property_ptr_t;
298 :
inherited_t( _geo_prop ), types_(_types), length_(_lengths)
311 void swap(
size_t _i0,
size_t _i1) { _swap( _i0, _i1, IsTriMesh() ); }
312 virtual void reserve(
size_t _n) { _reserve( _n, IsTriMesh() ); }
313 virtual void resize(
size_t _n) { _resize( _n, IsTriMesh() ); }
317 void _swap(
size_t _i0,
size_t _i1, GenProg::False )
319 omerr() <<
"Unsupported mesh type!" << std::endl;
323 void _swap(
size_t _i0,
size_t _i1, GenProg::True )
325 size_t j0 = _i0 + _i0 + _i0;
326 size_t j1 = _i1 + _i1 + _i1;
333 virtual void _reserve(
size_t _n, GenProg::True )
336 virtual void _reserve(
size_t _n, GenProg::False )
339 virtual void _resize(
size_t _n, GenProg::True )
342 virtual void _resize(
size_t _n, GenProg::False )
358 #ifndef DOXY_IGNORE_THIS
360 template <
typename T>
struct _t2vp;
361 template <>
struct _t2vp< osg::Pnt2f >
364 template <>
struct _t2vp< osg::Pnt3f >
367 template <>
struct _t2vp< osg::Pnt4f >
370 template <>
struct _t2vp< osg::Pnt2d >
372 template <>
struct _t2vp< osg::Pnt3d >
374 template <>
struct _t2vp< osg::Pnt4d >
377 template <
typename T>
struct _t2vn;
378 template <>
struct _t2vn< osg::Vec3f >
381 template <
typename T>
struct _t2vc;
382 template <>
struct _t2vc< osg::Color3f >
385 template <>
struct _t2vc< osg::Color4f >
388 template <>
struct _t2vc< osg::Color3ub >
391 template <>
struct _t2vc< osg::Color4ub >
394 template <
typename T>
struct _t2vtc;
395 template <>
struct _t2vtc< osg::Vec2f >
398 template <>
struct _t2vtc< osg::Vec3f >
407 #endif // OPENMESH_PROPERTYT_HH defined
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: PropertyT.hh:136
oPropertyT< osg::GeoPositions2f > GeoPositions2f
Adaptor for osg::GeoPositions.
Definition: PropertyT.hh:233
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:58
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: PropertyT.hh:312
Adaptor for osg::GeoIndicesUI32.
Definition: PropertyT.hh:286
oPropertyT< osg::GeoTexCoords3f > GeoTexCoords3f
Adaptor for osg::GeoTexCoords.
Definition: PropertyT.hh:253
oPropertyT< osg::GeoPositions4f > GeoPositions4f
Adaptor for osg::GeoPositions.
Definition: PropertyT.hh:237
Property adaptor for OpenSG GeoProperties.
Definition: PropertyT.hh:85
oPropertyT< osg::GeoColors3ub > GeoColors3ub
Adaptor for osg::GeoColors.
Definition: PropertyT.hh:261
virtual oPropertyT< property_t > * clone() const
Return a deep copy of self.
Definition: PropertyT.hh:142
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: PropertyT.hh:167
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: PropertyT.hh:159
oPropertyT< osg::GeoTexCoords2f > GeoTexCoords2f
Adaptor for osg::GeoTexCoords.
Definition: PropertyT.hh:252
oPropertyT< osg::GeoTexCoords1f > GeoTexCoords1f
Adaptor for osg::GeoTexCoords.
Definition: PropertyT.hh:251
This file provides some macros containing attribute usage.
oPropertyT< osg::GeoPositions4d > GeoPositions4d
Adaptor for osg::GeoPositions.
Definition: PropertyT.hh:236
oPropertyT< osg::GeoColors4ub > GeoColors4ub
Adaptor for osg::GeoColors.
Definition: PropertyT.hh:263
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: PropertyT.hh:313
virtual void push_back()
Extend the number of elements by one.
Definition: PropertyT.hh:138
virtual size_t n_elements() const
Number of elements in property.
Definition: PropertyT.hh:164
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: BaseProperty.hh:63
oPropertyT< osg::GeoNormals3f > GeoNormals3f
Adaptor for osg::GeoNormals.
Definition: PropertyT.hh:244
oPropertyT< osg::GeoPositions3f > GeoPositions3f
Adaptor for osg::GeoPositions.
Definition: PropertyT.hh:235
oPropertyT< osg::GeoPositions3d > GeoPositions3d
Adaptor for osg::GeoPositions.
Definition: PropertyT.hh:234
oPropertyT< osg::GeoPLengthsUI32 > GeoPLengthsUI32
Adaptor for osg::GeoPLengthsUI32.
Definition: PropertyT.hh:278
virtual size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block.
Definition: PropertyT.hh:170
oPropertyT< osg::GeoPositions2d > GeoPositions2d
Adaptor for osg::GeoPositions.
Definition: PropertyT.hh:232
oPropertyT< osg::GeoColors4f > GeoColors4f
Adaptor for osg::GeoColors.
Definition: PropertyT.hh:262
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: PropertyT.hh:139
void clear(void)
Clear all elements and free memory.
Definition: PropertyT.hh:179
oPropertyT< osg::GeoColors3f > GeoColors3f
Adaptor for osg::GeoColors.
Definition: PropertyT.hh:260
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:81
oPropertyT< osg::GeoPTypesUI8 > GeoPTypesUI8
Adaptor for osg::GeoPTypesUI8.
Definition: PropertyT.hh:274
virtual size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: PropertyT.hh:173
void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: PropertyT.hh:311
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: PropertyT.hh:137