00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef OPENMESH_KERNEL_OSG_PROPERTYT_HH
00027 #define OPENMESH_KERNEL_OSG_PROPERTYT_HH
00028
00029
00030
00031
00032 #include <OpenMesh/Core/Attributes/Attributes.hh>
00033 #include <OpenMesh/Core/Mesh/Kernels/Common/BaseKernel.hh>
00034 #include <OpenMesh/Core/Utils/GenProg.hh>
00035 #include <OpenMesh/Core/Utils/Property.hh>
00036
00037 #include <OpenSG/OSGGeometry.h>
00038
00039 #include <stdexcept>
00040 #include <vector>
00041
00042
00043
00044
00045 namespace OpenMesh {
00046 namespace Kernel_OSG {
00047
00048
00049
00050
00051
00052
00053
00068 template <typename GeoProperty>
00069 class oPropertyT : public BaseProperty
00070 {
00071 public:
00072
00073
00074 typedef GeoProperty property_t;
00075 typedef typename property_t::PtrType property_ptr_t;
00076
00077 typedef typename property_t::StoredFieldType field_t;
00078 typedef typename field_t::StoredType element_t;
00079 typedef typename field_t::StoredType value_type;
00080
00081 public:
00082
00083
00084 oPropertyT( property_ptr_t _geo_prop,
00085 const std::string& _name = "<unknown>" )
00086 : BaseProperty(_name), data_( _geo_prop )
00087 {
00088 osg_init_check();
00089 }
00090
00091
00092 oPropertyT( const std::string& _name = "<unknown>" )
00093 : BaseProperty(_name), data_(NULL)
00094 {
00095 data_ = property_t::create();
00096
00097
00098
00099 osg_init_check();
00100 }
00101
00103 virtual ~oPropertyT()
00104 { }
00105
00106 public:
00107
00108 oPropertyT& operator = (const oPropertyT& _rhs )
00109 {
00110
00111
00112 data_ = _rhs.data_;
00113 return *this;
00114
00115 }
00116
00117
00118 public:
00119
00120 virtual void reserve(size_t _n) { data_->getField().reserve( _n ); }
00121 virtual void resize(size_t _n) { data_->resize( _n ); }
00122 virtual void push_back() { data_->resize( data_->size()+1 ); }
00123 virtual void swap(size_t _i0, size_t _i1)
00124 { std::swap( data_->getField()[_i0], data_->getField()[_i1] ); }
00125
00126 virtual oPropertyT<property_t>* clone() const
00127 {
00128 oPropertyT<property_t> *dolly = new oPropertyT<property_t>();
00129 if (n_elements() > 0)
00130 {
00131
00132 dolly->resize(n_elements());
00133 element_t *begin = const_cast<element_t*>(data());
00134 element_t *end = begin+n_elements();
00135 element_t *dst = const_cast<element_t*>(dolly->data());
00136 std::copy( begin, end, dst );
00137 }
00138 return dolly;
00139 }
00140
00141 public:
00142
00143 virtual void set_persistent( bool _yn )
00144 {
00145 check_and_set_persistent<element_t>(_yn);
00146 }
00147
00148 virtual size_t n_elements() const
00149 { return data_==osg::NullFC ? UnknownSize : data_->getSize(); }
00150
00151 virtual size_t element_size() const
00152 { return UnknownSize; }
00153
00154 virtual size_t store( std::ostream& _ostr, bool _swap ) const
00155 { return 0; }
00156
00157 virtual size_t restore( std::istream& _istr, bool _swap )
00158 { return 0; }
00159
00160
00161 public:
00162
00163 void clear(void) { data_->clear(); }
00164
00165
00166 public:
00167
00168 property_ptr_t& osg_ptr()
00169 { return data_; }
00170
00171 const property_ptr_t& osg_ptr() const
00172 { return data_; }
00173
00174
00175 const element_t *data() const
00176 { return &( (*this)[ 0 ] ); }
00177
00178 element_t& operator[](size_t idx)
00179 { return data_->getField()[ idx ]; }
00180
00181 const element_t& operator[](size_t idx) const
00182 { return data_->getField()[ idx ]; }
00183
00184
00185 protected:
00186
00187 property_ptr_t data_;
00188
00189
00190 private:
00191
00192 void osg_init_check(void)
00193 {
00194
00195
00196 if ( data_ == osg::NullFC )
00197 throw std::logic_error("OpenSG Runtime Environment is not initialized: " \
00198 "Use osg::osgInit()");
00199 }
00200
00201 oPropertyT( const oPropertyT& );
00202 };
00203
00204
00205
00206
00207
00208
00210 namespace VP {
00211
00212
00214
00215
00216
00217 typedef oPropertyT< osg::GeoPositions2f > GeoPositions2f;
00218 typedef oPropertyT< osg::GeoPositions3d > GeoPositions3d;
00219 typedef oPropertyT< osg::GeoPositions3f > GeoPositions3f;
00220 typedef oPropertyT< osg::GeoPositions4d > GeoPositions4d;
00221 typedef oPropertyT< osg::GeoPositions4f > GeoPositions4f;
00223
00224
00226
00227
00228
00230
00231
00233
00234
00235
00236 typedef oPropertyT< osg::GeoTexCoords2f > GeoTexCoords2f;
00237 typedef oPropertyT< osg::GeoTexCoords3f > GeoTexCoords3f;
00239
00240
00242
00243
00244
00245 typedef oPropertyT< osg::GeoColors3ub > GeoColors3ub;
00246 typedef oPropertyT< osg::GeoColors4f > GeoColors4f;
00247 typedef oPropertyT< osg::GeoColors4ub > GeoColors4ub;
00249
00250 }
00251
00252
00254 namespace FP {
00255
00256
00258
00259
00260
00262
00263
00264
00265
00266 typedef oPropertyT< osg::GeoIndicesUI32 > _GeoIndicesUI32;
00267
00269 template < typename IsTriMesh >
00270 class GeoIndicesUI32 : public _GeoIndicesUI32
00271 {
00272 public:
00273
00274 typedef _GeoIndicesUI32 inherited_t;
00275 typedef typename inherited_t::property_ptr_t property_ptr_t;
00276
00277 public:
00278
00279 GeoIndicesUI32( property_ptr_t _geo_prop,
00280 GeoPTypesUI8& _types,
00281 GeoPLengthsUI32& _lengths)
00282 : inherited_t( _geo_prop ), types_(_types), length_(_lengths)
00283 { }
00284
00285 GeoIndicesUI32( GeoPTypesUI8& _types,
00286 GeoPLengthsUI32& _lengths)
00287 : inherited_t(), types_(_types), length_(_lengths)
00288 { }
00289
00290 virtual ~GeoIndicesUI32()
00291 { }
00292
00293 public:
00294
00295 void swap(size_t _i0, size_t _i1) { _swap( _i0, _i1, IsTriMesh() ); }
00296 virtual void reserve(size_t _n) { _reserve( _n, IsTriMesh() ); }
00297 virtual void resize(size_t _n) { _resize( _n, IsTriMesh() ); }
00298
00299 protected:
00300
00301 void _swap(size_t _i0, size_t _i1, GenProg::False )
00302 {
00303 omerr << "Unsupported mesh type!" << std::endl;
00304 assert(0);
00305 }
00306
00307 void _swap(size_t _i0, size_t _i1, GenProg::True )
00308 {
00309 size_t j0 = _i0 + _i0 + _i0;
00310 size_t j1 = _i1 + _i1 + _i1;
00311
00312 inherited_t::swap( j0, j1 );
00313 inherited_t::swap( ++j0, ++j1 );
00314 inherited_t::swap( ++j0, ++j1 );
00315 }
00316
00317 virtual void _reserve(size_t _n, GenProg::True )
00318 { inherited_t::reserve( _n + _n + _n ); }
00319
00320 virtual void _reserve(size_t _n, GenProg::False )
00321 { assert( false ); }
00322
00323 virtual void _resize(size_t _n, GenProg::True )
00324 { inherited_t::resize( _n + _n + _n ); }
00325
00326 virtual void _resize(size_t _n, GenProg::False )
00327 { assert( false ); }
00328
00329
00330 protected:
00331
00332 GeoPTypesUI8 &types_;
00333 GeoPLengthsUI32 &length_;
00334
00335 };
00336
00337 }
00338
00339
00340
00341
00342 #ifndef DOXY_IGNORE_THIS
00343
00344 template <typename T> struct _t2vp;
00345 template <> struct _t2vp< osg::Pnt2f >
00346 { typedef osg::GeoPositions2f type; typedef VP::GeoPositions2f prop; };
00347
00348 template <> struct _t2vp< osg::Pnt3f >
00349 { typedef osg::GeoPositions3f type; typedef VP::GeoPositions3f prop; };
00350
00351 template <> struct _t2vp< osg::Pnt4f >
00352 { typedef osg::GeoPositions4f type; typedef VP::GeoPositions4f prop; };
00353
00354 template <> struct _t2vp< osg::Pnt2d >
00355 { typedef osg::GeoPositions2d type; typedef VP::GeoPositions2d prop; };
00356 template <> struct _t2vp< osg::Pnt3d >
00357 { typedef osg::GeoPositions3d type; typedef VP::GeoPositions3d prop; };
00358 template <> struct _t2vp< osg::Pnt4d >
00359 { typedef osg::GeoPositions4d type; typedef VP::GeoPositions4d prop; };
00360
00361 template <typename T> struct _t2vn;
00362 template <> struct _t2vn< osg::Vec3f >
00363 { typedef osg::GeoNormals3f type; typedef VP::GeoNormals3f prop; };
00364
00365 template <typename T> struct _t2vc;
00366 template <> struct _t2vc< osg::Color3f >
00367 { typedef osg::GeoColors3f type; typedef VP::GeoColors3f prop; };
00368
00369 template <> struct _t2vc< osg::Color4f >
00370 { typedef osg::GeoColors4f type; typedef VP::GeoColors4f prop; };
00371
00372 template <> struct _t2vc< osg::Color3ub >
00373 { typedef osg::GeoColors3ub type; typedef VP::GeoColors3ub prop; };
00374
00375 template <> struct _t2vc< osg::Color4ub >
00376 { typedef osg::GeoColors4ub type; typedef VP::GeoColors3ub prop; };
00377
00378 template <typename T> struct _t2vtc;
00379 template <> struct _t2vtc< osg::Vec2f >
00380 { typedef osg::GeoTexCoords2f type; typedef VP::GeoTexCoords2f prop; };
00381
00382 template <> struct _t2vtc< osg::Vec3f >
00383 { typedef osg::GeoTexCoords3f type; typedef VP::GeoTexCoords3f prop; };
00384
00385 #endif
00386
00387
00388 }
00389 }
00390
00391 #endif // OPENMESH_PROPERTYT_HH defined
00392
00393