44 #ifndef OPENMESH_KERNEL_OSG_PROPERTYT_HH 45 #define OPENMESH_KERNEL_OSG_PROPERTYT_HH 51 #include <OpenMesh/Core/Mesh/BaseKernel.hh> 52 #include <OpenMesh/Core/Utils/GenProg.hh> 53 #include <OpenMesh/Core/Utils/Property.hh> 55 #include <osg/Geometry> 64 namespace Kernel_OSG {
86 template <
typename GeoProperty>
92 typedef GeoProperty property_t;
93 typedef typename property_t::PtrType property_ptr_t;
95 typedef typename property_t::StoredFieldType field_t;
96 typedef typename field_t::StoredType element_t;
97 typedef typename field_t::StoredType value_type;
103 const std::string& _name =
"<unknown>" )
110 oPropertyT(
const std::string& _name =
"<unknown>" )
113 data_ = property_t::create();
138 virtual void reserve(
size_t _n) { data_->getField().reserve( _n ); }
139 virtual void resize(
size_t _n) { data_->resize( _n ); }
140 virtual void push_back() { data_->resize( data_->size()+1 ); }
141 virtual void swap(
size_t _i0,
size_t _i1)
142 { std::swap( data_->getField()[_i0], data_->getField()[_i1] ); }
151 element_t *begin =
const_cast<element_t*
>(data());
153 element_t *dst =
const_cast<element_t*
>(dolly->data());
154 std::copy( begin, end, dst );
163 check_and_set_persistent<element_t>(_yn);
167 {
return data_==osg::NullFC ?
UnknownSize : data_->getSize(); }
172 virtual size_t store( std::ostream& _ostr,
bool _swap )
const 175 virtual size_t restore( std::istream& _istr,
bool _swap )
181 void clear(
void) { data_->clear(); }
186 property_ptr_t& osg_ptr()
189 const property_ptr_t& osg_ptr()
const 193 const element_t *data()
const 194 {
return &( (*this)[ 0 ] ); }
196 element_t& operator[](
size_t idx)
197 {
return data_->getField()[ idx ]; }
199 const element_t& operator[](
size_t idx)
const 200 {
return data_->getField()[ idx ]; }
205 property_ptr_t data_;
210 void osg_init_check(
void)
214 if ( data_ == osg::NullFC )
215 throw std::logic_error(
"OpenSG Runtime Environment is not initialized: " \
216 "Use osg::osgInit()");
287 template <
typename IsTriMesh >
293 typedef typename inherited_t::property_ptr_t property_ptr_t;
298 GeoPTypesUI8& _types,
299 GeoPLengthsUI32& _lengths)
300 : inherited_t( _geo_prop ), types_(_types), length_(_lengths)
304 GeoPLengthsUI32& _lengths)
305 : inherited_t(), types_(_types), length_(_lengths)
313 void swap(
size_t _i0,
size_t _i1) { _swap( _i0, _i1, IsTriMesh() ); }
314 virtual void reserve(
size_t _n) { _reserve( _n, IsTriMesh() ); }
315 virtual void resize(
size_t _n) { _resize( _n, IsTriMesh() ); }
319 void _swap(
size_t _i0,
size_t _i1, GenProg::False )
321 omerr() <<
"Unsupported mesh type!" << std::endl;
325 void _swap(
size_t _i0,
size_t _i1, GenProg::True )
327 size_t j0 = _i0 + _i0 + _i0;
328 size_t j1 = _i1 + _i1 + _i1;
330 inherited_t::swap( j0, j1 );
331 inherited_t::swap( ++j0, ++j1 );
332 inherited_t::swap( ++j0, ++j1 );
335 virtual void _reserve(
size_t _n, GenProg::True )
336 { inherited_t::reserve( _n + _n + _n ); }
338 virtual void _reserve(
size_t _n, GenProg::False )
341 virtual void _resize(
size_t _n, GenProg::True )
342 { inherited_t::resize( _n + _n + _n ); }
344 virtual void _resize(
size_t _n, GenProg::False )
350 GeoPTypesUI8 &types_;
351 GeoPLengthsUI32 &length_;
360 #ifndef DOXY_IGNORE_THIS 362 template <
typename T>
struct _t2vp;
363 template <>
struct _t2vp< osg::Pnt2f >
366 template <>
struct _t2vp< osg::Pnt3f >
369 template <>
struct _t2vp< osg::Pnt4f >
372 template <>
struct _t2vp< osg::Pnt2d >
374 template <>
struct _t2vp< osg::Pnt3d >
376 template <>
struct _t2vp< osg::Pnt4d >
379 template <
typename T>
struct _t2vn;
380 template <>
struct _t2vn< osg::
Vec3f >
383 template <
typename T>
struct _t2vc;
384 template <>
struct _t2vc< osg::Color3f >
387 template <>
struct _t2vc< osg::
Color4f >
390 template <>
struct _t2vc< osg::Color3ub >
393 template <>
struct _t2vc< osg::Color4ub >
396 template <
typename T>
struct _t2vtc;
397 template <>
struct _t2vtc< osg::
Vec2f >
400 template <>
struct _t2vtc< osg::
Vec3f >
409 #endif // OPENMESH_PROPERTYT_HH defined virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
virtual void set_persistent(bool _yn)
virtual void push_back()
Extend the number of elements by one.
void clear(void)
Clear all elements and free memory.
virtual oPropertyT< property_t > * clone() const
Return a deep copy of self.
BaseProperty(const std::string &_name="<unknown>", const std::string &_internal_type_name="<unknown>")
Default constructor.
virtual void resize(size_t _n)
Resize storage to hold n elements.
Adaptor for osg::GeoIndicesUI32.
virtual void reserve(size_t _n)
Reserve memory for n elements.
void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
virtual size_t restore(std::istream &_istr, bool _swap)
virtual size_t n_elements() const
Number of elements in property.
virtual void resize(size_t _n)
Resize storage to hold n elements.
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
virtual void reserve(size_t _n)
Reserve memory for n elements.
virtual size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block.