Alembic Version 1.1
Loading...
Searching...
No Matches
IGeomParam.h
Go to the documentation of this file.
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2014,
4// Sony Pictures Imageworks Inc. and
5// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6//
7// All rights reserved.
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14// * Redistributions in binary form must reproduce the above
15// copyright notice, this list of conditions and the following disclaimer
16// in the documentation and/or other materials provided with the
17// distribution.
18// * Neither the name of Sony Pictures Imageworks, nor
19// Industrial Light & Magic, nor the names of their contributors may be used
20// to endorse or promote products derived from this software without specific
21// prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34//
35//-*****************************************************************************
36
37#ifndef Alembic_AbcGeom_IGeomParam_h
38#define Alembic_AbcGeom_IGeomParam_h
39
42
43namespace Alembic {
44namespace AbcGeom {
45namespace ALEMBIC_VERSION_NS {
46
47//-*****************************************************************************
48template <class TRAITS>
50{
51public:
52 typedef typename TRAITS::value_type value_type;
54
55 class Sample
56 {
57 public:
59 typedef Alembic::Util::shared_ptr< Abc::TypedArraySample<TRAITS> > samp_ptr_type;
60
62 {}
63
65 samp_ptr_type getVals() const { return m_vals; }
66 GeometryScope getScope() const { return m_scope; }
67 bool isIndexed() const { return m_isIndexed; }
68
69 void reset()
70 {
71 m_vals.reset();
72 m_indices.reset();
74 m_isIndexed = false;
75 }
76
77 bool valid() const { return m_vals.get() != NULL; }
78
80
81 protected:
82 friend class ITypedGeomParam<TRAITS>;
87 };
88
89 //-*************************************************************************
92
93 static const char * getInterpretation()
94 {
95 return TRAITS::interpretation();
96 }
97
98 static bool matches( const AbcA::PropertyHeader &iHeader,
100 {
101 if ( iHeader.isCompound() )
102 {
103 return ( iHeader.getMetaData().get( "podName" ) ==
104 Alembic::Util::PODName( TRAITS::dataType().getPod() ) &&
105 ( std::string() == getInterpretation() ||
106 atoi(
107 iHeader.getMetaData().get( "podExtent" ).c_str() ) ==
108 TRAITS::dataType().getExtent() ) ) &&
109 prop_type::matches( iHeader.getMetaData(), iMatching );
110 }
111 else if ( iHeader.isArray() )
112 {
113 return prop_type::matches( iHeader, iMatching );
114 }
115
116 return false;
117 }
118
120
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() );
126
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() );
132
134 const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
135
137 const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
138
140 Abc::ISampleSelector() ) const
141 {
142 sample_type ret;
143 getIndexed( ret, iSS );
144 return ret;
145 }
146
148 Abc::ISampleSelector() ) const
149 {
150 sample_type ret;
151 getExpanded( ret, iSS );
152 return ret;
153 }
154
155 size_t getNumSamples() const;
156
157 AbcA::DataType getDataType() const { return TRAITS::dataType(); }
158
159 size_t getArrayExtent() const
160 {
161 std::string e = m_valProp.getMetaData().get( "arrayExtent" );
162 if ( e == "" ) { return 1; }
163 else { return atoi( e.c_str() ); }
164 }
165
166 bool isIndexed() const { return m_isIndexed; }
167
170
172
173 const std::string &getName() const;
174
176
178
180
181 bool isConstant() const;
182
183 void reset()
184 {
187 m_cprop.reset();
188 m_isIndexed = false;
189 }
190
191 bool valid() const
192 {
193 return ( m_valProp.valid()
194 && ( ( ! m_cprop ) || m_indicesProperty ) );
195 }
196
198
200
202
203private:
204 Abc::ErrorHandler &getErrorHandler() const
205 { return m_valProp.getErrorHandler(); }
206
207protected:
209
210 // if the GeomParam is not indexed, these will not exist.
213
215};
216
217//-*****************************************************************************
218// TEMPLATED METHODS AND CONSTRUCTORS
219//-*****************************************************************************
220template <class TRAITS>
221template <class CPROP>
223 const std::string &iName,
224 const Abc::Argument &iArg0,
225 const Abc::Argument &iArg1 )
226{
227 Arguments args( GetErrorHandlerPolicy( iParent ) );
228 iArg0.setInto( args );
229 iArg1.setInto( args );
230
231 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
232
233 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::ITypedGeomParam()" );
234
237 ABCA_ASSERT( parent != NULL,
238 "NULL CompoundPropertyReader passed into "
239 << "ITypedGeomParam ctor" );
240
241 const AbcA::PropertyHeader *pheader =
242 parent->getPropertyHeader( iName );
243 ABCA_ASSERT( pheader != NULL,
244 "Nonexistent GeomParam: " << iName );
245
246 if ( pheader->isCompound() )
247 {
248 // we're indexed
249 m_cprop = ICompoundProperty( iParent, iName,
250 args.getErrorHandlerPolicy() );
251 m_indicesProperty = IUInt32ArrayProperty( m_cprop, ".indices", iArg0,
252 iArg1 );
253 m_valProp = ITypedArrayProperty<TRAITS>( m_cprop, ".vals", iArg0,
254 iArg1 );
255 m_isIndexed = true;
256 }
257 else if ( pheader->isArray() )
258 {
259 // not indexed
260 m_valProp = ITypedArrayProperty<TRAITS>( iParent, iName, iArg0,
261 iArg1 );
262 m_isIndexed = false;
263 }
264 else
265 {
266 ABCA_ASSERT( false, "Invalid ITypedGeomParam: " << iName );
267 }
268
270}
271
272//-*****************************************************************************
273template <class TRAITS>
274template <class PROP>
276 WrapExistingFlag iWrapFlag,
277 const Abc::Argument &iArg0,
278 const Abc::Argument &iArg1 )
279{
280 Arguments args( GetErrorHandlerPolicy( iThis ) );
281 iArg0.setInto( args );
282 iArg1.setInto( args );
283
284 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
285
286 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::ITypedGeomParam( wrap )" );
287
288 const AbcA::PropertyHeader &ph = iThis.getHeader();
289
290 ABCA_ASSERT( matches( ph,
291 Abc::GetSchemaInterpMatching( iArg0, iArg1 ) ),
292 "Property " << ph.getName() << " is not an "
293 << "ITypedGeomParam" );
294
295 ABCA_ASSERT( ! ph.isScalar(), "Property " << ph.getName()
296 << " cannot be an ITypedGeomParam" );
297
298 if ( ph.isCompound() )
299 {
300 // we're indexed
301 m_cprop = ICompoundProperty( iThis, iWrapFlag, iArg0, iArg1 );
302 m_indicesProperty = IUInt32ArrayProperty( m_cprop, ".indices", iArg0,
303 iArg1 );
304 m_valProp = ITypedArrayProperty<TRAITS>( m_cprop, ".vals", iArg0,
305 iArg1 );
306 m_isIndexed = true;
307 }
308 else
309 {
310 // not indexed
311 m_valProp = ITypedArrayProperty<TRAITS>( iThis, iWrapFlag, iArg0,
312 iArg1 );
313 m_isIndexed = false;
314 }
315
317}
318
319//-*****************************************************************************
320template <class TRAITS>
321void
323 const Abc::ISampleSelector &iSS ) const
324{
325 m_valProp.get( oSamp.m_vals, iSS );
326 if ( m_indicesProperty ) { m_indicesProperty.get( oSamp.m_indices, iSS ); }
327 else
328 {
329 uint32_t size = static_cast< uint32_t > ( oSamp.m_vals->size() );
330
331 uint32_t *v = new uint32_t[size];
332
333 for ( uint32_t i = 0 ; i < size ; ++i )
334 {
335 v[i] = i;
336 }
337
338 const Alembic::Util::Dimensions dims( size );
339
340 oSamp.m_indices.reset( new Abc::UInt32ArraySample( v, dims ),
342 }
343
344 oSamp.m_scope = this->getScope();
345 oSamp.m_isIndexed = m_isIndexed;
346}
347
348
349//-*****************************************************************************
350template <class TRAITS>
351void
353 const Abc::ISampleSelector &iSS ) const
354{
355 oSamp.m_scope = this->getScope();
356 oSamp.m_isIndexed = m_isIndexed;
357
358 if ( ! m_indicesProperty )
359 {
360 m_valProp.get( oSamp.m_vals, iSS );
361 }
362 else
363 {
364 Abc::UInt32ArraySamplePtr idxPtr = m_indicesProperty.getValue( iSS );
365
366 size_t size = idxPtr->size();
367
368 // no indices? just return what we have in our values
369 if (size == 0)
370 {
371 m_valProp.get( oSamp.m_vals, iSS );
372 return;
373 }
374
375 Alembic::Util::shared_ptr< Abc::TypedArraySample<TRAITS> > valPtr = \
376 m_valProp.getValue( iSS );
377
378 typename TRAITS::value_type *v = new typename TRAITS::value_type[size];
379
380 for ( size_t i = 0 ; i < size ; ++i )
381 {
382 v[i] = (*valPtr)[ (*idxPtr)[i] ];
383 }
384
385 // NOTE: we could create an ArraySampleKey and insert this into the
386 // cache. If it were in the cache, we'd return the shared pointer
387 // from there and call delete[] on v, thus preventing potentially
388 // unbounded heap growth. We should probably do this, but for now,
389 // we'll assume that we don't have too many of these, and we're not
390 // tightly memory-constrained. Ha!
391
392 const Alembic::Util::Dimensions dims( size );
393
394 oSamp.m_vals.reset( new Abc::TypedArraySample<TRAITS>( v, dims ),
396 }
397
398}
399
400//-*****************************************************************************
401template <class TRAITS>
403{
404 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::getNumSamples()" );
405
406 if ( m_isIndexed )
407 {
408 return std::max( m_indicesProperty.getNumSamples(),
409 m_valProp.getNumSamples() );
410 }
411 else
412 {
413 if ( m_valProp ) { return m_valProp.getNumSamples(); }
414 else { return 0; }
415 }
416
418
419 return 0;
420}
421
422//-*****************************************************************************
423template <class TRAITS>
425{
426 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::isConstant()" );
427
428 if ( m_isIndexed )
429 {
430 return m_valProp.isConstant() && m_indicesProperty.isConstant();
431 }
432 else
433 {
434 return m_valProp.isConstant();
435 }
436
438
439 return false;
440}
441
442namespace {
443 const std::string g_emptyStr;
444}
445//-*****************************************************************************
446template <class TRAITS>
447const std::string &ITypedGeomParam<TRAITS>::getName() const
448{
449 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ITypedGeomParam::getName()" );
450
451 if ( m_isIndexed ) { return m_cprop.getName(); }
452 else { return m_valProp.getName(); }
453
455
456 return g_emptyStr;
457}
458
459//-*****************************************************************************
460template <class TRAITS>
462{
463 if ( m_isIndexed ) { return m_cprop.getParent(); }
464 else { return m_valProp.getParent(); }
465}
466
467//-*****************************************************************************
468template <class TRAITS>
470{
471 if ( m_isIndexed ) { return m_cprop.getHeader(); }
472 else { return m_valProp.getHeader(); }
473}
474
475//-*****************************************************************************
476template <class TRAITS>
478{
479 if ( m_isIndexed ) { return m_cprop.getMetaData(); }
480 else { return m_valProp.getMetaData(); }
481}
482
483//-*****************************************************************************
484template <class TRAITS>
486{
487 if ( m_valProp )
488 {
489 return m_valProp.getTimeSampling();
490 }
491 else if ( m_indicesProperty )
492 {
493 return m_indicesProperty.getTimeSampling();
494 }
495
496 return AbcA::TimeSamplingPtr();
497}
498
499//-*****************************************************************************
500// TYPEDEFS
501//-*****************************************************************************
502
517
522
527
532
537
542
547
552
555
559
563
566
569
570} // End namespace ALEMBIC_VERSION_NS
571
572using namespace ALEMBIC_VERSION_NS;
573
574} // End namespace AbcGeom
575} // End namespace Alembic
576
577#endif
#define ABCA_ASSERT(COND, TEXT)
Definition Foundation.h:99
#define ALEMBIC_ABC_SAFE_CALL_END()
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
#define ALEMBIC_VERSION_NS
Definition Foundation.h:105
std::string get(const std::string &iKey) const
Definition MetaData.h:192
Alembic::Util::shared_ptr< Abc::TypedArraySample< TRAITS > > samp_ptr_type
Definition IGeomParam.h:59
sample_type getExpandedValue(const Abc::ISampleSelector &iSS=Abc::ISampleSelector()) const
Definition IGeomParam.h:147
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition IGeomParam.h:98
ITypedGeomParam(CPROP iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition IGeomParam.h:222
sample_type getIndexedValue(const Abc::ISampleSelector &iSS=Abc::ISampleSelector()) const
Definition IGeomParam.h:139
void getIndexed(sample_type &oSamp, const Abc::ISampleSelector &iSS=Abc::ISampleSelector()) const
Definition IGeomParam.h:322
ITypedGeomParam(PROP iThis, WrapExistingFlag iWrapFlag, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition IGeomParam.h:275
Abc::ITypedArrayProperty< TRAITS > prop_type
Definition IGeomParam.h:53
void getExpanded(sample_type &oSamp, const Abc::ISampleSelector &iSS=Abc::ISampleSelector()) const
Definition IGeomParam.h:352
const AbcA::PropertyHeader & getHeader() const
Definition IGeomParam.h:469
void setInto(Arguments &iArgs) const
Definition Argument.h:149
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition Argument.h:83
ErrorHandler & getErrorHandler() const
Definition Base.h:76
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
ITypedGeomParam< BooleanTPTraits > IBoolGeomParam
Definition IGeomParam.h:503
GeometryScope GetGeometryScope(const AbcA::MetaData &iMetaData)
ITypedGeomParam< C3hTPTraits > IC3hGeomParam
Definition IGeomParam.h:556
ITypedGeomParam< C4cTPTraits > IC4cGeomParam
Definition IGeomParam.h:562
ITypedGeomParam< P3sTPTraits > IP3sGeomParam
Definition IGeomParam.h:533
ITypedGeomParam< P3iTPTraits > IP3iGeomParam
Definition IGeomParam.h:534
ITypedGeomParam< Box3iTPTraits > IBox3iGeomParam
Definition IGeomParam.h:544
ITypedGeomParam< P3fTPTraits > IP3fGeomParam
Definition IGeomParam.h:535
ITypedGeomParam< Box2sTPTraits > IBox2sGeomParam
Definition IGeomParam.h:538
ITypedGeomParam< M44dTPTraits > IM44dGeomParam
Definition IGeomParam.h:551
ITypedGeomParam< QuatfTPTraits > IQuatfGeomParam
Definition IGeomParam.h:553
ITypedGeomParam< Uint8TPTraits > IUcharGeomParam
Definition IGeomParam.h:504
ITypedGeomParam< M44fTPTraits > IM44fGeomParam
Definition IGeomParam.h:550
ITypedGeomParam< StringTPTraits > IStringGeomParam
Definition IGeomParam.h:515
ITypedGeomParam< Int16TPTraits > IInt16GeomParam
Definition IGeomParam.h:507
ITypedGeomParam< V3fTPTraits > IV3fGeomParam
Definition IGeomParam.h:525
ITypedGeomParam< N2dTPTraits > IN2dGeomParam
Definition IGeomParam.h:565
ITypedGeomParam< Box2dTPTraits > IBox2dGeomParam
Definition IGeomParam.h:541
ITypedGeomParam< Int64TPTraits > IInt64GeomParam
Definition IGeomParam.h:511
ITypedGeomParam< V2iTPTraits > IV2iGeomParam
Definition IGeomParam.h:519
ITypedGeomParam< P2iTPTraits > IP2iGeomParam
Definition IGeomParam.h:529
ITypedGeomParam< Box2iTPTraits > IBox2iGeomParam
Definition IGeomParam.h:539
ITypedGeomParam< Box3fTPTraits > IBox3fGeomParam
Definition IGeomParam.h:545
ITypedGeomParam< V3sTPTraits > IV3sGeomParam
Definition IGeomParam.h:523
ITypedGeomParam< V2dTPTraits > IV2dGeomParam
Definition IGeomParam.h:521
ITypedGeomParam< C4fTPTraits > IC4fGeomParam
Definition IGeomParam.h:561
ITypedGeomParam< P3dTPTraits > IP3dGeomParam
Definition IGeomParam.h:536
ITypedGeomParam< WstringTPTraits > IWstringGeomParam
Definition IGeomParam.h:516
ITypedGeomParam< Uint32TPTraits > IUInt32GeomParam
Definition IGeomParam.h:508
ITypedGeomParam< N2fTPTraits > IN2fGeomParam
Definition IGeomParam.h:564
ITypedGeomParam< P2sTPTraits > IP2sGeomParam
Definition IGeomParam.h:528
ITypedGeomParam< C3fTPTraits > IC3fGeomParam
Definition IGeomParam.h:557
ITypedGeomParam< P2dTPTraits > IP2dGeomParam
Definition IGeomParam.h:531
ITypedGeomParam< V2sTPTraits > IV2sGeomParam
Definition IGeomParam.h:518
ITypedGeomParam< P2fTPTraits > IP2fGeomParam
Definition IGeomParam.h:530
ITypedGeomParam< Int8TPTraits > ICharGeomParam
Definition IGeomParam.h:505
ITypedGeomParam< QuatdTPTraits > IQuatdGeomParam
Definition IGeomParam.h:554
ITypedGeomParam< Float64TPTraits > IDoubleGeomParam
Definition IGeomParam.h:514
ITypedGeomParam< V3iTPTraits > IV3iGeomParam
Definition IGeomParam.h:524
ITypedGeomParam< N3dTPTraits > IN3dGeomParam
Definition IGeomParam.h:568
ITypedGeomParam< Int32TPTraits > IInt32GeomParam
Definition IGeomParam.h:509
ITypedGeomParam< Box2fTPTraits > IBox2fGeomParam
Definition IGeomParam.h:540
ITypedGeomParam< C3cTPTraits > IC3cGeomParam
Definition IGeomParam.h:558
ITypedGeomParam< Box3dTPTraits > IBox3dGeomParam
Definition IGeomParam.h:546
ITypedGeomParam< V3dTPTraits > IV3dGeomParam
Definition IGeomParam.h:526
ITypedGeomParam< M33dTPTraits > IM33dGeomParam
Definition IGeomParam.h:549
ITypedGeomParam< Box3sTPTraits > IBox3sGeomParam
Definition IGeomParam.h:543
ITypedGeomParam< Float16TPTraits > IHalfGeomParam
Definition IGeomParam.h:512
ITypedGeomParam< Uint16TPTraits > IUInt16GeomParam
Definition IGeomParam.h:506
ITypedGeomParam< C4hTPTraits > IC4hGeomParam
Definition IGeomParam.h:560
ITypedGeomParam< Uint64TPTraits > IUInt64GeomParam
Definition IGeomParam.h:510
ITypedGeomParam< M33fTPTraits > IM33fGeomParam
Definition IGeomParam.h:548
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition Argument.h:242
AbcA::CompoundPropertyReaderPtr GetCompoundPropertyReaderPtr(AbcA::CompoundPropertyReaderPtr iPtr)
Definition Foundation.h:181
ITypedArrayProperty< Uint32TPTraits > IUInt32ArrayProperty
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition Argument.h:318
Alembic::Util::shared_ptr< UInt32ArraySample > UInt32ArraySamplePtr
const char * PODName(PlainOldDataType pod)
Alembic namespace ...
Definition ArchiveInfo.h:46