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 #ifndef _Alembic_AbcGeom_IGeomParam_h_
00038 #define _Alembic_AbcGeom_IGeomParam_h_
00039
00040 #include <Alembic/AbcGeom/Foundation.h>
00041 #include <Alembic/AbcGeom/GeometryScope.h>
00042
00043 #include <boost/lexical_cast.hpp>
00044
00045 namespace Alembic {
00046 namespace AbcGeom {
00047 namespace ALEMBIC_VERSION_NS {
00048
00049
00050 template <class TRAITS>
00051 class ITypedGeomParam
00052 {
00053 public:
00054 typedef typename TRAITS::value_type value_type;
00055 typedef Abc::ITypedArrayProperty<TRAITS> prop_type;
00056
00057 class Sample
00058 {
00059 public:
00060 typedef Sample this_type;
00061 typedef boost::shared_ptr< Abc::TypedArraySample<TRAITS> > samp_ptr_type;
00062
00063 Sample()
00064 {}
00065
00066 Abc::UInt32ArraySamplePtr getIndices() { return m_indices; }
00067 samp_ptr_type getVals() { return m_vals; }
00068 GeometryScope getScope() { return m_scope; }
00069 bool isIndexed() { return m_isIndexed; }
00070
00071 void reset()
00072 {
00073 m_vals.reset();
00074 m_indices.reset();
00075 m_scope = kUnknownScope;
00076 m_isIndexed = false;
00077 }
00078
00079 bool valid()
00080 { return m_vals; }
00081
00082 ALEMBIC_OPERATOR_BOOL( valid() );
00083
00084 protected:
00085 friend class ITypedGeomParam<TRAITS>;
00086 samp_ptr_type m_vals;
00087 Abc::UInt32ArraySamplePtr m_indices;
00088 GeometryScope m_scope;
00089 bool m_isIndexed;
00090 };
00091
00092
00093 typedef ITypedGeomParam<TRAITS> this_type;
00094 typedef typename this_type::Sample sample_type;
00095
00096 static const std::string &getInterpretation()
00097 {
00098 static std::string sInterpretation = TRAITS::interpretation();
00099 return sInterpretation;
00100 }
00101
00102 static bool matches( const AbcA::MetaData &iMetaData,
00103 SchemaInterpMatching iMatching = kStrictMatching )
00104 {
00105 if ( iMatching == kStrictMatching )
00106 {
00107 return ( iMetaData.get( "isGeomParam" ) == "true" &&
00108 iMetaData.get( "interpretation" ) == getInterpretation() );
00109 }
00110 return true;
00111 }
00112
00113 static bool matches( const AbcA::PropertyHeader &iHeader,
00114 SchemaInterpMatching iMatching = kStrictMatching )
00115 {
00116 if ( iHeader.isCompound() )
00117 {
00118 return ( iHeader.getMetaData().get( "podName" ) ==
00119 Alembic::Util::PODName( TRAITS::dataType().getPod() ) &&
00120 ( getInterpretation() == "" ||
00121 boost::lexical_cast<uint32_t>(
00122 iHeader.getMetaData().get( "podExtent" ) ) ==
00123 TRAITS::dataType().getExtent() ) ) &&
00124 matches( iHeader.getMetaData(), iMatching );
00125 }
00126 else if ( iHeader.isArray() )
00127 {
00128 return ( iHeader.getDataType().getPod() ==
00129 TRAITS::dataType().getPod() &&
00130 ( iHeader.getDataType().getExtent() ==
00131 TRAITS::dataType().getExtent() ||
00132 getInterpretation() == "" ) ) &&
00133 matches( iHeader.getMetaData(), iMatching );
00134 }
00135
00136 return false;
00137 }
00138
00139 ITypedGeomParam() {m_isIndexed = false;}
00140
00141 template <class CPROP>
00142 ITypedGeomParam( CPROP iParent,
00143 const std::string &iName,
00144 const Abc::Argument &iArg0 = Abc::Argument(),
00145 const Abc::Argument &iArg1 = Abc::Argument() );
00146
00147 template <class PROP>
00148 ITypedGeomParam( PROP iThis,
00149 WrapExistingFlag iWrapFlag,
00150 const Abc::Argument &iArg0 = Abc::Argument(),
00151 const Abc::Argument &iArg1 = Abc::Argument() );
00152
00153 void getIndexed( sample_type &oSamp,
00154 const Abc::ISampleSelector &iSS = Abc::ISampleSelector() );
00155
00156 void getExpanded( sample_type &oSamp,
00157 const Abc::ISampleSelector &iSS = Abc::ISampleSelector() );
00158
00159 sample_type getIndexedValue( const Abc::ISampleSelector &iSS = \
00160 Abc::ISampleSelector() )
00161 {
00162 sample_type ret;
00163 getIndexed( ret, iSS );
00164 return ret;
00165 }
00166
00167 sample_type getExpandedValue( const Abc::ISampleSelector &iSS = \
00168 Abc::ISampleSelector() )
00169 {
00170 sample_type ret;
00171 getExpanded( ret, iSS );
00172 return ret;
00173 }
00174
00175 size_t getNumSamples();
00176
00177 AbcA::DataType getDataType() { return TRAITS::dataType(); }
00178
00179 size_t getArrayExtent()
00180 {
00181 std::string e = m_valProp.getMetaData().get( "arrayExtent" );
00182 if ( e == "" ) { return 1; }
00183 else { return boost::lexical_cast<size_t>( e ); }
00184 }
00185
00186 bool isIndexed() { return m_isIndexed; }
00187
00188 GeometryScope getScope()
00189 { return GetGeometryScope( m_valProp.getMetaData() ); }
00190
00191 AbcA::TimeSamplingPtr getTimeSampling();
00192
00193 const std::string &getName();
00194
00195 Abc::ICompoundProperty getParent();
00196
00197 const AbcA::PropertyHeader &getHeader();
00198
00199 const AbcA::MetaData &getMetaData();
00200
00201 bool isConstant();
00202
00203 void reset()
00204 {
00205 m_valProp.reset();
00206 m_indicesProperty.reset();
00207 m_cprop.reset();
00208 m_isIndexed = false;
00209 }
00210
00211 bool valid() const
00212 {
00213 return ( m_valProp.valid()
00214 && ( ( ! m_cprop ) || m_indicesProperty ) );
00215 }
00216
00217 ALEMBIC_OPERATOR_BOOL( this_type::valid() );
00218
00219 prop_type getValueProperty() { return m_valProp; }
00220
00221 Abc::IUInt32ArrayProperty getIndexProperty() { return m_indicesProperty; }
00222
00223 private:
00224 Abc::ErrorHandler &getErrorHandler() const
00225 { return m_valProp.getErrorHandler(); }
00226
00227 protected:
00228 prop_type m_valProp;
00229
00230
00231 Abc::IUInt32ArrayProperty m_indicesProperty;
00232 Abc::ICompoundProperty m_cprop;
00233
00234 bool m_isIndexed;
00235 };
00236
00237
00238
00239
00240 template <class TRAITS>
00241 template <class CPROP>
00242 ITypedGeomParam<TRAITS>::ITypedGeomParam( CPROP iParent,
00243 const std::string &iName,
00244 const Abc::Argument &iArg0,
00245 const Abc::Argument &iArg1 )
00246 {
00247 Arguments args( GetErrorHandlerPolicy( iParent ) );
00248 iArg0.setInto( args );
00249 iArg1.setInto( args );
00250
00251 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
00252
00253 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::ITypedGeomParam()" );
00254
00255 AbcA::CompoundPropertyReaderPtr parent =
00256 GetCompoundPropertyReaderPtr( iParent );
00257 ABCA_ASSERT( parent != NULL,
00258 "NULL CompoundPropertyReader passed into "
00259 << "ITypedGeomParam ctor" );
00260
00261 const AbcA::PropertyHeader *pheader =
00262 parent->getPropertyHeader( iName );
00263 ABCA_ASSERT( pheader != NULL,
00264 "Nonexistent GeomParam: " << iName );
00265
00266 if ( pheader->isCompound() )
00267 {
00268
00269 m_cprop = ICompoundProperty( iParent, iName,
00270 args.getErrorHandlerPolicy() );
00271 m_indicesProperty = IUInt32ArrayProperty( m_cprop, ".indices", iArg0,
00272 iArg1 );
00273 m_valProp = ITypedArrayProperty<TRAITS>( m_cprop, ".vals", iArg0,
00274 iArg1 );
00275 m_isIndexed = true;
00276 }
00277 else if ( pheader->isArray() )
00278 {
00279
00280 m_valProp = ITypedArrayProperty<TRAITS>( iParent, iName, iArg0,
00281 iArg1 );
00282 m_isIndexed = false;
00283 }
00284 else
00285 {
00286 ABCA_ASSERT( false, "Invalid ITypedGeomParam: " << iName );
00287 }
00288
00289 ALEMBIC_ABC_SAFE_CALL_END();
00290 }
00291
00292
00293 template <class TRAITS>
00294 template <class PROP>
00295 ITypedGeomParam<TRAITS>::ITypedGeomParam( PROP iThis,
00296 WrapExistingFlag iWrapFlag,
00297 const Abc::Argument &iArg0,
00298 const Abc::Argument &iArg1 )
00299 {
00300 Arguments args( GetErrorHandlerPolicy( iThis ) );
00301 iArg0.setInto( args );
00302 iArg1.setInto( args );
00303
00304 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
00305
00306 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::ITypedGeomParam( wrap )" );
00307
00308 const AbcA::PropertyHeader &ph = iThis.getHeader();
00309
00310 ABCA_ASSERT( matches( ph,
00311 Abc::GetSchemaInterpMatching( iArg0, iArg1 ) ),
00312 "Property " << ph.getName() << " is not an "
00313 << "ITypedGeomParam" );
00314
00315 ABCA_ASSERT( ! ph.isScalar(), "Property " << ph.getName()
00316 << " cannot be an ITypedGeomParam" );
00317
00318 if ( ph.isCompound() )
00319 {
00320
00321 m_cprop = ICompoundProperty( iThis, iWrapFlag, iArg0, iArg1 );
00322 m_indicesProperty = IUInt32ArrayProperty( m_cprop, ".indices", iArg0,
00323 iArg1 );
00324 m_valProp = ITypedArrayProperty<TRAITS>( m_cprop, ".vals", iArg0,
00325 iArg1 );
00326 m_isIndexed = true;
00327 }
00328 else
00329 {
00330
00331 m_valProp = ITypedArrayProperty<TRAITS>( iThis, iWrapFlag, iArg0,
00332 iArg1 );
00333 m_isIndexed = false;
00334 }
00335
00336 ALEMBIC_ABC_SAFE_CALL_END_RESET();
00337 }
00338
00339
00340 template <class TRAITS>
00341 void
00342 ITypedGeomParam<TRAITS>::getIndexed( typename ITypedGeomParam<TRAITS>::Sample &oSamp,
00343 const Abc::ISampleSelector &iSS )
00344 {
00345 m_valProp.get( oSamp.m_vals, iSS );
00346 if ( m_indicesProperty ) { m_indicesProperty.get( oSamp.m_indices, iSS ); }
00347 else
00348 {
00349 uint32_t size = static_cast< uint32_t > ( oSamp.m_vals->size() );
00350
00351 uint32_t *v = new uint32_t[size];
00352
00353 for ( uint32_t i = 0 ; i < size ; ++i )
00354 {
00355 v[i] = i;
00356 }
00357
00358 const Alembic::Util::Dimensions dims( size );
00359
00360 oSamp.m_indices.reset( new Abc::UInt32ArraySample( v, dims ),
00361 AbcA::TArrayDeleter<uint32_t>() );
00362 }
00363
00364 oSamp.m_scope = this->getScope();
00365 oSamp.m_isIndexed = m_isIndexed;
00366 }
00367
00368
00369
00370 template <class TRAITS>
00371 void
00372 ITypedGeomParam<TRAITS>::getExpanded( typename ITypedGeomParam<TRAITS>::Sample &oSamp,
00373 const Abc::ISampleSelector &iSS )
00374 {
00375 typedef typename TRAITS::value_type value_type;
00376
00377 oSamp.m_scope = this->getScope();
00378 oSamp.m_isIndexed = m_isIndexed;
00379
00380 if ( ! m_indicesProperty )
00381 {
00382 m_valProp.get( oSamp.m_vals, iSS );
00383 }
00384 else
00385 {
00386 boost::shared_ptr< Abc::TypedArraySample<TRAITS> > valPtr = \
00387 m_valProp.getValue( iSS );
00388 Abc::UInt32ArraySamplePtr idxPtr = m_indicesProperty.getValue( iSS );
00389
00390 size_t size = idxPtr->size();
00391
00392 value_type *v = new value_type[size];
00393
00394 for ( size_t i = 0 ; i < size ; ++i )
00395 {
00396 v[i] = (*valPtr)[ (*idxPtr)[i] ];
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406 const Alembic::Util::Dimensions dims( size );
00407
00408 oSamp.m_vals.reset( new Abc::TypedArraySample<TRAITS>( v, dims ),
00409 AbcA::TArrayDeleter<value_type>() );
00410 }
00411
00412 }
00413
00414
00415 template <class TRAITS>
00416 size_t ITypedGeomParam<TRAITS>::getNumSamples()
00417 {
00418 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::getNumSamples()" );
00419
00420 if ( m_isIndexed )
00421 {
00422 return std::max( m_indicesProperty.getNumSamples(),
00423 m_valProp.getNumSamples() );
00424 }
00425 else
00426 {
00427 if ( m_valProp ) { return m_valProp.getNumSamples(); }
00428 else { return 0; }
00429 }
00430
00431 ALEMBIC_ABC_SAFE_CALL_END();
00432
00433 return 0;
00434 }
00435
00436
00437 template <class TRAITS>
00438 bool ITypedGeomParam<TRAITS>::isConstant()
00439 {
00440 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::isConstant()" );
00441
00442 if ( m_isIndexed )
00443 {
00444 return m_valProp.isConstant() && m_indicesProperty.isConstant();
00445 }
00446 else
00447 {
00448 return m_valProp.isConstant();
00449 }
00450
00451 ALEMBIC_ABC_SAFE_CALL_END();
00452
00453 return false;
00454 }
00455
00456
00457 template <class TRAITS>
00458 const std::string &ITypedGeomParam<TRAITS>::getName()
00459 {
00460 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::getName()" );
00461
00462 if ( m_isIndexed ) { return m_cprop.getName(); }
00463 else { return m_valProp.getName(); }
00464
00465 ALEMBIC_ABC_SAFE_CALL_END();
00466
00467 static const std::string ret( "" );
00468 return ret;
00469 }
00470
00471
00472 template <class TRAITS>
00473 Abc::ICompoundProperty ITypedGeomParam<TRAITS>::getParent()
00474 {
00475 if ( m_isIndexed ) { return m_cprop.getParent(); }
00476 else { return m_valProp.getParent(); }
00477 }
00478
00479
00480 template <class TRAITS>
00481 const AbcA::PropertyHeader &ITypedGeomParam<TRAITS>::getHeader()
00482 {
00483 if ( m_isIndexed ) { return m_cprop.getHeader(); }
00484 else { return m_valProp.getHeader(); }
00485 }
00486
00487
00488 template <class TRAITS>
00489 const AbcA::MetaData &ITypedGeomParam<TRAITS>::getMetaData()
00490 {
00491 if ( m_isIndexed ) { return m_cprop.getMetaData(); }
00492 else { return m_valProp.getMetaData(); }
00493 }
00494
00495
00496 template <class TRAITS>
00497 AbcA::TimeSamplingPtr ITypedGeomParam<TRAITS>::getTimeSampling()
00498 {
00499 if ( m_valProp )
00500 {
00501 return m_valProp.getTimeSampling();
00502 }
00503 else if ( m_indicesProperty )
00504 {
00505 return m_indicesProperty.getTimeSampling();
00506 }
00507
00508 return AbcA::TimeSamplingPtr();
00509 }
00510
00511
00512
00513
00514
00515 typedef ITypedGeomParam<BooleanTPTraits> IBoolGeomParam;
00516 typedef ITypedGeomParam<Uint8TPTraits> IUcharGeomParam;
00517 typedef ITypedGeomParam<Int8TPTraits> ICharGeomParam;
00518 typedef ITypedGeomParam<Uint16TPTraits> IUInt16GeomParam;
00519 typedef ITypedGeomParam<Int16TPTraits> IInt16GeomParam;
00520 typedef ITypedGeomParam<Uint32TPTraits> IUInt32GeomParam;
00521 typedef ITypedGeomParam<Int32TPTraits> IInt32GeomParam;
00522 typedef ITypedGeomParam<Uint64TPTraits> IUInt64GeomParam;
00523 typedef ITypedGeomParam<Int64TPTraits> IInt64GeomParam;
00524 typedef ITypedGeomParam<Float16TPTraits> IHalfGeomParam;
00525 typedef ITypedGeomParam<Float32TPTraits> IFloatGeomParam;
00526 typedef ITypedGeomParam<Float64TPTraits> IDoubleGeomParam;
00527 typedef ITypedGeomParam<StringTPTraits> IStringGeomParam;
00528 typedef ITypedGeomParam<WstringTPTraits> IWstringGeomParam;
00529
00530 typedef ITypedGeomParam<V2sTPTraits> IV2sGeomParam;
00531 typedef ITypedGeomParam<V2iTPTraits> IV2iGeomParam;
00532 typedef ITypedGeomParam<V2fTPTraits> IV2fGeomParam;
00533 typedef ITypedGeomParam<V2dTPTraits> IV2dGeomParam;
00534
00535 typedef ITypedGeomParam<V3sTPTraits> IV3sGeomParam;
00536 typedef ITypedGeomParam<V3iTPTraits> IV3iGeomParam;
00537 typedef ITypedGeomParam<V3fTPTraits> IV3fGeomParam;
00538 typedef ITypedGeomParam<V3dTPTraits> IV3dGeomParam;
00539
00540 typedef ITypedGeomParam<P2sTPTraits> IP2sGeomParam;
00541 typedef ITypedGeomParam<P2iTPTraits> IP2iGeomParam;
00542 typedef ITypedGeomParam<P2fTPTraits> IP2fGeomParam;
00543 typedef ITypedGeomParam<P2dTPTraits> IP2dGeomParam;
00544
00545 typedef ITypedGeomParam<P3sTPTraits> IP3sGeomParam;
00546 typedef ITypedGeomParam<P3iTPTraits> IP3iGeomParam;
00547 typedef ITypedGeomParam<P3fTPTraits> IP3fGeomParam;
00548 typedef ITypedGeomParam<P3dTPTraits> IP3dGeomParam;
00549
00550 typedef ITypedGeomParam<Box2sTPTraits> IBox2sGeomParam;
00551 typedef ITypedGeomParam<Box2iTPTraits> IBox2iGeomParam;
00552 typedef ITypedGeomParam<Box2fTPTraits> IBox2fGeomParam;
00553 typedef ITypedGeomParam<Box2dTPTraits> IBox2dGeomParam;
00554
00555 typedef ITypedGeomParam<Box3sTPTraits> IBox3sGeomParam;
00556 typedef ITypedGeomParam<Box3iTPTraits> IBox3iGeomParam;
00557 typedef ITypedGeomParam<Box3fTPTraits> IBox3fGeomParam;
00558 typedef ITypedGeomParam<Box3dTPTraits> IBox3dGeomParam;
00559
00560 typedef ITypedGeomParam<M33fTPTraits> IM33fGeomParam;
00561 typedef ITypedGeomParam<M33dTPTraits> IM33dGeomParam;
00562 typedef ITypedGeomParam<M44fTPTraits> IM44fGeomParam;
00563 typedef ITypedGeomParam<M44dTPTraits> IM44dGeomParam;
00564
00565 typedef ITypedGeomParam<QuatfTPTraits> IQuatfGeomParam;
00566 typedef ITypedGeomParam<QuatdTPTraits> IQuatdGeomParam;
00567
00568 typedef ITypedGeomParam<C3hTPTraits> IC3hGeomParam;
00569 typedef ITypedGeomParam<C3fTPTraits> IC3fGeomParam;
00570 typedef ITypedGeomParam<C3cTPTraits> IC3cGeomParam;
00571
00572 typedef ITypedGeomParam<C4hTPTraits> IC4hGeomParam;
00573 typedef ITypedGeomParam<C4fTPTraits> IC4fGeomParam;
00574 typedef ITypedGeomParam<C4cTPTraits> IC4cGeomParam;
00575
00576 typedef ITypedGeomParam<N2fTPTraits> IN2fGeomParam;
00577 typedef ITypedGeomParam<N2dTPTraits> IN2dGeomParam;
00578
00579 typedef ITypedGeomParam<N3fTPTraits> IN3fGeomParam;
00580 typedef ITypedGeomParam<N3dTPTraits> IN3dGeomParam;
00581
00582 }
00583
00584 using namespace ALEMBIC_VERSION_NS;
00585
00586 }
00587 }
00588
00589 #endif