37#ifndef Alembic_AbcGeom_IGeomParam_h
38#define Alembic_AbcGeom_IGeomParam_h
40#include <Alembic/AbcGeom/Foundation.h>
41#include <Alembic/AbcGeom/GeometryScope.h>
45namespace ALEMBIC_VERSION_NS {
48template <
class TRAITS>
52 typedef typename TRAITS::value_type value_type;
58 typedef Sample this_type;
59 typedef Alembic::Util::shared_ptr< Abc::TypedArraySample<TRAITS> > samp_ptr_type;
64 Abc::UInt32ArraySamplePtr getIndices()
const {
return m_indices; }
65 samp_ptr_type getVals()
const {
return m_vals; }
66 GeometryScope getScope()
const {
return m_scope; }
67 bool isIndexed()
const {
return m_isIndexed; }
73 m_scope = kUnknownScope;
77 bool valid()
const {
return m_vals.get() != NULL; }
79 ALEMBIC_OPERATOR_BOOL( valid() );
82 friend class ITypedGeomParam<TRAITS>;
84 Abc::UInt32ArraySamplePtr m_indices;
85 GeometryScope m_scope;
90 typedef ITypedGeomParam<TRAITS> this_type;
93 static const char * getInterpretation()
95 return TRAITS::interpretation();
98 static bool matches(
const AbcA::PropertyHeader &iHeader,
99 SchemaInterpMatching iMatching = kStrictMatching )
101 if ( iHeader.isCompound() )
103 return ( iHeader.getMetaData().get(
"podName" ) ==
104 Alembic::Util::PODName( TRAITS::dataType().getPod() ) &&
105 ( std::string() == getInterpretation() ||
107 iHeader.getMetaData().get(
"podExtent" ).c_str() ) ==
108 TRAITS::dataType().getExtent() ) ) &&
111 else if ( iHeader.isArray() )
119 ITypedGeomParam() {m_isIndexed =
false;}
121 template <
class CPROP>
122 ITypedGeomParam( CPROP iParent,
123 const std::string &iName,
124 const Abc::Argument &iArg0 = Abc::Argument(),
125 const Abc::Argument &iArg1 = Abc::Argument() );
127 template <
class PROP>
128 ITypedGeomParam( PROP iThis,
129 WrapExistingFlag iWrapFlag,
130 const Abc::Argument &iArg0 = Abc::Argument(),
131 const Abc::Argument &iArg1 = Abc::Argument() );
133 void getIndexed( sample_type &oSamp,
134 const Abc::ISampleSelector &iSS = Abc::ISampleSelector() )
const;
136 void getExpanded( sample_type &oSamp,
137 const Abc::ISampleSelector &iSS = Abc::ISampleSelector() )
const;
139 sample_type getIndexedValue(
const Abc::ISampleSelector &iSS = \
140 Abc::ISampleSelector() )
const
143 getIndexed( ret, iSS );
147 sample_type getExpandedValue(
const Abc::ISampleSelector &iSS = \
148 Abc::ISampleSelector() )
const
151 getExpanded( ret, iSS );
155 size_t getNumSamples()
const;
157 AbcA::DataType getDataType()
const {
return TRAITS::dataType(); }
159 size_t getArrayExtent()
const
161 std::string e = m_valProp.getMetaData().get(
"arrayExtent" );
162 if ( e ==
"" ) {
return 1; }
163 else {
return atoi( e.c_str() ); }
166 bool isIndexed()
const {
return m_isIndexed; }
168 GeometryScope getScope()
const
169 {
return GetGeometryScope( m_valProp.getMetaData() ); }
171 AbcA::TimeSamplingPtr getTimeSampling()
const;
173 const std::string &getName()
const;
175 Abc::ICompoundProperty getParent()
const;
177 const AbcA::PropertyHeader &getHeader()
const;
179 const AbcA::MetaData &getMetaData()
const;
181 bool isConstant()
const;
186 m_indicesProperty.reset();
193 return ( m_valProp.valid()
194 && ( ( ! m_cprop ) || m_indicesProperty ) );
197 ALEMBIC_OPERATOR_BOOL( this_type::valid() );
199 prop_type getValueProperty() {
return m_valProp; }
201 Abc::IUInt32ArrayProperty getIndexProperty() {
return m_indicesProperty; }
204 Abc::ErrorHandler &getErrorHandler()
const
205 {
return m_valProp.getErrorHandler(); }
211 Abc::IUInt32ArrayProperty m_indicesProperty;
212 Abc::ICompoundProperty m_cprop;
220template <
class TRAITS>
221template <
class CPROP>
222ITypedGeomParam<TRAITS>::ITypedGeomParam( CPROP iParent,
223 const std::string &iName,
227 Arguments args( GetErrorHandlerPolicy( iParent ) );
228 iArg0.setInto( args );
229 iArg1.setInto( args );
231 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
233 ALEMBIC_ABC_SAFE_CALL_BEGIN(
"ITypedGeomParam::ITypedGeomParam()" );
235 AbcA::CompoundPropertyReaderPtr parent =
236 GetCompoundPropertyReaderPtr( iParent );
237 ABCA_ASSERT( parent != NULL,
238 "NULL CompoundPropertyReader passed into "
239 <<
"ITypedGeomParam ctor" );
241 const AbcA::PropertyHeader *pheader =
242 parent->getPropertyHeader( iName );
243 ABCA_ASSERT( pheader != NULL,
244 "Nonexistent GeomParam: " << iName );
246 if ( pheader->isCompound() )
250 args.getErrorHandlerPolicy() );
251 m_indicesProperty = IUInt32ArrayProperty( m_cprop,
".indices", iArg0,
257 else if ( pheader->isArray() )
266 ABCA_ASSERT(
false,
"Invalid ITypedGeomParam: " << iName );
269 ALEMBIC_ABC_SAFE_CALL_END();
273template <
class TRAITS>
275ITypedGeomParam<TRAITS>::ITypedGeomParam( PROP iThis,
276 WrapExistingFlag iWrapFlag,
280 Arguments args( GetErrorHandlerPolicy( iThis ) );
281 iArg0.setInto( args );
282 iArg1.setInto( args );
284 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
286 ALEMBIC_ABC_SAFE_CALL_BEGIN(
"ITypedGeomParam::ITypedGeomParam( wrap )" );
288 const AbcA::PropertyHeader &ph = iThis.getHeader();
290 ABCA_ASSERT( matches( ph,
291 Abc::GetSchemaInterpMatching( iArg0, iArg1 ) ),
292 "Property " << ph.getName() <<
" is not an "
293 <<
"ITypedGeomParam" );
295 ABCA_ASSERT( ! ph.isScalar(),
"Property " << ph.getName()
296 <<
" cannot be an ITypedGeomParam" );
298 if ( ph.isCompound() )
302 m_indicesProperty = IUInt32ArrayProperty( m_cprop,
".indices", iArg0,
316 ALEMBIC_ABC_SAFE_CALL_END_RESET();
320template <
class TRAITS>
325 m_valProp.get( oSamp.m_vals, iSS );
326 if ( m_indicesProperty ) { m_indicesProperty.get( oSamp.m_indices, iSS ); }
329 uint32_t size =
static_cast< uint32_t
> ( oSamp.m_vals->size() );
331 uint32_t *v =
new uint32_t[size];
333 for ( uint32_t i = 0 ; i < size ; ++i )
338 const Alembic::Util::Dimensions dims( size );
340 oSamp.m_indices.reset(
new Abc::UInt32ArraySample( v, dims ),
341 AbcA::TArrayDeleter<uint32_t>() );
344 oSamp.m_scope = this->getScope();
345 oSamp.m_isIndexed = m_isIndexed;
350template <
class TRAITS>
355 oSamp.m_scope = this->getScope();
356 oSamp.m_isIndexed = m_isIndexed;
358 if ( ! m_indicesProperty )
360 m_valProp.get( oSamp.m_vals, iSS );
364 Abc::UInt32ArraySamplePtr idxPtr = m_indicesProperty.getValue( iSS );
366 size_t size = idxPtr->size();
371 m_valProp.get( oSamp.m_vals, iSS );
375 Alembic::Util::shared_ptr< Abc::TypedArraySample<TRAITS> > valPtr = \
376 m_valProp.getValue( iSS );
378 typename TRAITS::value_type *v =
new typename TRAITS::value_type[size];
380 for (
size_t i = 0 ; i < size ; ++i )
382 v[i] = (*valPtr)[ (*idxPtr)[i] ];
392 const Alembic::Util::Dimensions dims( size );
395 AbcA::TArrayDeleter<typename TRAITS::value_type>());
401template <
class TRAITS>
402size_t ITypedGeomParam<TRAITS>::getNumSamples()
const
404 ALEMBIC_ABC_SAFE_CALL_BEGIN(
"ITypedGeomParam::getNumSamples()" );
408 return std::max( m_indicesProperty.getNumSamples(),
409 m_valProp.getNumSamples() );
413 if ( m_valProp ) {
return m_valProp.getNumSamples(); }
417 ALEMBIC_ABC_SAFE_CALL_END();
423template <
class TRAITS>
424bool ITypedGeomParam<TRAITS>::isConstant()
const
426 ALEMBIC_ABC_SAFE_CALL_BEGIN(
"ITypedGeomParam::isConstant()" );
430 return m_valProp.isConstant() && m_indicesProperty.isConstant();
434 return m_valProp.isConstant();
437 ALEMBIC_ABC_SAFE_CALL_END();
443 const std::string g_emptyStr;
446template <
class TRAITS>
447const std::string &ITypedGeomParam<TRAITS>::getName()
const
449 ALEMBIC_ABC_SAFE_CALL_BEGIN(
"ITypedGeomParam::getName()" );
451 if ( m_isIndexed ) {
return m_cprop.getName(); }
452 else {
return m_valProp.getName(); }
454 ALEMBIC_ABC_SAFE_CALL_END();
460template <
class TRAITS>
463 if ( m_isIndexed ) {
return m_cprop.getParent(); }
464 else {
return m_valProp.getParent(); }
468template <
class TRAITS>
469const AbcA::PropertyHeader &ITypedGeomParam<TRAITS>::getHeader()
const
471 if ( m_isIndexed ) {
return m_cprop.getHeader(); }
472 else {
return m_valProp.getHeader(); }
476template <
class TRAITS>
477const AbcA::MetaData &ITypedGeomParam<TRAITS>::getMetaData()
const
479 if ( m_isIndexed ) {
return m_cprop.getMetaData(); }
480 else {
return m_valProp.getMetaData(); }
484template <
class TRAITS>
485AbcA::TimeSamplingPtr ITypedGeomParam<TRAITS>::getTimeSampling()
const
489 return m_valProp.getTimeSampling();
491 else if ( m_indicesProperty )
493 return m_indicesProperty.getTimeSampling();
496 return AbcA::TimeSamplingPtr();
572using namespace ALEMBIC_VERSION_NS;
Definition Argument.h:120
void reset()
Definition IBaseProperty.h:160
Definition ICompoundProperty.h:53
Definition ISampleSelector.h:49
Definition ITypedArrayProperty.h:51
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition ITypedArrayProperty.h:72
Definition TypedArraySample.h:52
Definition IGeomParam.h:56
Definition IGeomParam.h:50
Alembic namespace ...
Definition ArchiveInfo.cpp:39