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