HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OGeomParam.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
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_OGeomParam_h_
38 #define _Alembic_AbcGeom_OGeomParam_h_
39 
42 
43 namespace Alembic {
44 namespace AbcGeom {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
48 template <class TRAITS>
50 {
51 public:
52  typedef typename TRAITS::value_type value_type;
54 
55 
56  //-*************************************************************************
57  // inner class for setting
58  class Sample
59  {
60  public:
61  typedef Sample this_type;
62 
65  {}
66 
68  GeometryScope iScope )
69  : m_vals( iVals )
70  , m_scope( iScope )
71  {}
72 
74  const Abc::UInt32ArraySample &iIndices,
75  GeometryScope iScope )
76  : m_vals( iVals )
77  , m_indices( iIndices )
78  , m_scope ( iScope )
79  {}
80 
82  { m_vals = iVals; }
84  { return m_vals; }
85 
86  void setIndices( const Abc::UInt32ArraySample &iIndices )
87  { m_indices = iIndices; }
89  { return m_indices; }
90 
91  void setScope( GeometryScope iScope )
92  { m_scope = iScope; }
94  { return m_scope; }
95 
96  void reset()
97  {
98  m_vals.reset();
99  m_indices.reset();
101  }
102 
103  bool valid() const { return m_vals; }
104 
106 
107  protected:
111  };
112 
113  //-*************************************************************************
115  typedef typename this_type::Sample sample_type;
116 
117  static const char * getInterpretation()
118  {
119  return TRAITS::interpretation();
120  }
121 
122  static bool matches( const AbcA::PropertyHeader &iHeader,
124  {
125  if ( iHeader.isCompound() )
126  {
127  return ( iHeader.getMetaData().get( "podName" ) ==
128  Alembic::Util::PODName( TRAITS::dataType().getPod() ) &&
129  ( std::string() == getInterpretation() ||
130  atoi(
131  iHeader.getMetaData().get( "podExtent" ).c_str() ) ==
132  TRAITS::dataType().getExtent() ) ) &&
133  prop_type::matches( iHeader.getMetaData(), iMatching );
134  }
135  else if ( iHeader.isArray() )
136  {
137  return prop_type::matches( iHeader, iMatching );
138  }
139 
140  return false;
141 
142  }
143 
145 
146  template <class CPROP>
147  OTypedGeomParam( CPROP iParent,
148  const std::string &iName,
149  bool iIsIndexed,
150  GeometryScope iScope,
151  size_t iArrayExtent,
152  const Argument &iArg0 = Argument(),
153  const Argument &iArg1 = Argument(),
154  const Argument &iArg2 = Argument()
155  )
156  : m_name( iName )
157  , m_isIndexed( iIsIndexed )
158  , m_scope( iScope )
159  {
160  Arguments args( Abc::GetErrorHandlerPolicy( iParent ) );
161  iArg0.setInto( args );
162  iArg1.setInto( args );
163  iArg2.setInto( args );
164 
165  AbcA::MetaData md = args.getMetaData();
166 
167  SetGeometryScope( md, iScope );
168 
169  md.set( "isGeomParam", "true" );
170 
172  TRAITS::dataType().getPod() ) );
173 
174  size_t extent = TRAITS::dataType().getExtent();
175 
176  md.set( "podName", podName );
177 
178  std::ostringstream extentStrm;
179  extentStrm << extent;
180  std::string extentStr = extentStrm.str();
181  md.set( "podExtent", extentStr );
182 
183  std::ostringstream arrayExtentStrm;
184  arrayExtentStrm << iArrayExtent;
185  std::string arrayExtentStr = arrayExtentStrm.str();
186  md.set( "arrayExtent", arrayExtentStr );
187 
188  md.set( "interpretation", TRAITS::interpretation() );
189 
191 
192  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
193  uint32_t tsIndex = args.getTimeSamplingIndex();
194 
195  // if we specified a valid TimeSamplingPtr, use it to determine the
196  // index otherwise we'll use the index, which defaults to the
197  // intrinsic 0 index
198  if (tsPtr)
199  {
202  tsIndex =
203  parent->getObject()->getArchive()->addTimeSampling(*tsPtr);
204  }
205 
206  if ( m_isIndexed )
207  {
208  m_cprop = Abc::OCompoundProperty( iParent, iName, md, ehp );
209 
210  m_valProp = prop_type( m_cprop, ".vals", md, ehp, tsIndex );
211 
213  tsIndex );
214  }
215  else
216  {
217  m_valProp = prop_type( iParent, iName, md, ehp, tsIndex );
218  }
219  }
220 
221  template <class PROP>
222  OTypedGeomParam( PROP iThis,
223  WrapExistingFlag iWrapFlag,
224  const Abc::Argument &iArg0 = Abc::Argument(),
225  const Abc::Argument &iArg1 = Abc::Argument() )
226  {
227  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam( wrap )" );
228 
229  const AbcA::PropertyHeader &ph = iThis.getHeader();
230 
231  ABCA_ASSERT( matches( ph,
232  Abc::GetSchemaInterpMatching( iArg0, iArg1 ) ),
233  "Property " << ph.getName() << " is not an "
234  << "OTypedGeomParam" );
235 
236  ABCA_ASSERT( ! ph.isScalar(), "Property " << ph.getName()
237  << " cannot be an OTypedGeomParam" );
238 
239  if ( ph.isCompound() )
240  {
241  m_cprop = Abc::OCompoundProperty( iThis, iWrapFlag, iArg0, iArg1 );
242  m_valProp = prop_type( m_cprop, ".vals" );
244 
245  m_isIndexed = true;
246  }
247  else
248  {
249  m_valProp = prop_type( iThis, iWrapFlag, iArg0, iArg1 );
250  m_isIndexed = false;
251  }
252 
254  }
255 
256  void set( const sample_type &iSamp )
257  {
258  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam::set()" );
259 
260  if ( m_valProp.getNumSamples() == 0 )
261  {
262  m_valProp.set( iSamp.getVals() );
263  if ( m_isIndexed ) { m_indicesProperty.set( iSamp.getIndices() ); }
264  }
265  else
266  {
267  SetPropUsePrevIfNull( m_valProp, iSamp.getVals() );
268  if ( m_isIndexed )
269  {
270  SetPropUsePrevIfNull( m_indicesProperty, iSamp.getIndices() );
271  }
272  }
273 
275  }
276 
278  {
279  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam::setFromPrevious()" );
280 
282 
284 
286  }
287 
288  void setTimeSampling( uint32_t iIndex )
289  {
291  "OTypedGeomParam::setTimeSampling( uint32_t )" );
292 
293  m_valProp.setTimeSampling( iIndex );
294 
295  if ( m_isIndexed ) { m_indicesProperty.setTimeSampling( iIndex ); }
296 
298  }
299 
301  {
303  "OTypedGeomParam::setTimeSampling( TimeSamplingPtr )" );
304 
305  if (iTime)
306  {
307  uint32_t tsIndex =
309  *iTime);
310  setTimeSampling( tsIndex );
311  }
312 
314  }
315 
316  size_t getNumSamples() const
317  {
318  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam::getNumSamples()" );
319 
320  if ( m_isIndexed )
321  {
322  if ( m_indicesProperty )
323  {
326  }
327  else { return 0; }
328  }
329  else
330  {
331  if ( m_valProp ) { return m_valProp.getNumSamples(); }
332  else { return 0; }
333  }
334 
336 
337  return 0;
338  }
339 
340  AbcA::DataType getDataType() const { return TRAITS::dataType(); }
341 
342  bool isIndexed() const { return m_isIndexed; }
343 
344  GeometryScope getScope() const { return m_scope; }
345 
347  {
348  return m_valProp.getTimeSampling();
349  }
350 
351  const std::string &getName() const { return m_name; }
352 
353  bool valid() const
354  {
355  return ( m_valProp.valid()
356  && ( ( ! m_isIndexed ) || m_indicesProperty ) );
357  }
358 
360 
361  void reset()
362  {
363  m_name = "";
364  m_valProp.reset();
366  m_cprop.reset();
368  m_isIndexed = false;
369  }
370 
372 
374 
375 private:
376  Abc::ErrorHandler &getErrorHandler() const
377  { return m_valProp.getErrorHandler(); }
378 
379 protected:
381 
385 
387 
388  // if the GeomParam is not indexed, this will not exist.
390 };
391 
392 //-*****************************************************************************
393 // TYPEDEFS
394 //-*****************************************************************************
395 
410 
415 
420 
425 
430 
435 
440 
445 
448 
452 
456 
459 
462 
463 } // End namespace ALEMBIC_VERSION_NS
464 
465 using namespace ALEMBIC_VERSION_NS;
466 
467 } // End namespace AbcGeom
468 } // End namespace Alembic
469 
470 #endif
OTypedGeomParam< V2dTPTraits > OV2dGeomParam
Definition: OGeomParam.h:414
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
AbcA::TimeSamplingPtr getTimeSampling() const
OTypedGeomParam< V2sTPTraits > OV2sGeomParam
Definition: OGeomParam.h:411
void setTimeSampling(AbcA::TimeSamplingPtr iTime)
Definition: OGeomParam.h:300
OTypedGeomParam< Box3dTPTraits > OBox3dGeomParam
Definition: OGeomParam.h:439
OTypedGeomParam< V2iTPTraits > OV2iGeomParam
Definition: OGeomParam.h:412
const Abc::UInt32ArraySample & getIndices() const
Definition: OGeomParam.h:88
OTypedGeomParam< QuatfTPTraits > OQuatfGeomParam
Definition: OGeomParam.h:446
OTypedGeomParam< P2fTPTraits > OP2fGeomParam
Definition: OGeomParam.h:423
void setIndices(const Abc::UInt32ArraySample &iIndices)
Definition: OGeomParam.h:86
uint32_t addTimeSampling(const AbcA::TimeSampling &iTs)
OTypedGeomParam< P2iTPTraits > OP2iGeomParam
Definition: OGeomParam.h:422
OTypedGeomParam< Box3sTPTraits > OBox3sGeomParam
Definition: OGeomParam.h:436
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
OTypedGeomParam< Float32TPTraits > OFloatGeomParam
Definition: OGeomParam.h:406
OTypedGeomParam(PROP iThis, WrapExistingFlag iWrapFlag, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition: OGeomParam.h:222
OTypedGeomParam< P3sTPTraits > OP3sGeomParam
Definition: OGeomParam.h:426
OTypedGeomParam< BooleanTPTraits > OBoolGeomParam
Definition: OGeomParam.h:396
OTypedGeomParam< Box2sTPTraits > OBox2sGeomParam
Definition: OGeomParam.h:431
OTypedGeomParam< C4fTPTraits > OC4fGeomParam
Definition: OGeomParam.h:454
void setVals(const Abc::TypedArraySample< TRAITS > &iVals)
Definition: OGeomParam.h:81
OTypedGeomParam< P3dTPTraits > OP3dGeomParam
Definition: OGeomParam.h:429
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:84
uint64 value_type
Definition: GA_PrimCompat.h:29
OTypedGeomParam< Float64TPTraits > ODoubleGeomParam
Definition: OGeomParam.h:407
OTypedGeomParam< V3iTPTraits > OV3iGeomParam
Definition: OGeomParam.h:417
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: OGeomParam.h:346
OTypedGeomParam< M44fTPTraits > OM44fGeomParam
Definition: OGeomParam.h:443
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
OTypedGeomParam< C4hTPTraits > OC4hGeomParam
Definition: OGeomParam.h:453
OTypedGeomParam< Box3iTPTraits > OBox3iGeomParam
Definition: OGeomParam.h:437
const Abc::TypedArraySample< TRAITS > & getVals() const
Definition: OGeomParam.h:83
OTypedGeomParam< Box3fTPTraits > OBox3fGeomParam
Definition: OGeomParam.h:438
OTypedGeomParam< Box2fTPTraits > OBox2fGeomParam
Definition: OGeomParam.h:433
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OTypedGeomParam< N3fTPTraits > ON3fGeomParam
Definition: OGeomParam.h:460
OTypedGeomParam< M44dTPTraits > OM44dGeomParam
Definition: OGeomParam.h:444
OTypedGeomParam< N2dTPTraits > ON2dGeomParam
Definition: OGeomParam.h:458
OTypedGeomParam< P2sTPTraits > OP2sGeomParam
Definition: OGeomParam.h:421
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OGeomParam.h:122
OUInt32ArrayProperty getIndexProperty() const
Definition: OGeomParam.h:373
OTypedGeomParam(CPROP iParent, const std::string &iName, bool iIsIndexed, GeometryScope iScope, size_t iArrayExtent, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: OGeomParam.h:147
OTypedGeomParam< Uint64TPTraits > OUInt64GeomParam
Definition: OGeomParam.h:403
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
void SetPropUsePrevIfNull(PROP iProp, SAMP iSamp)
Definition: Foundation.h:96
OTypedGeomParam< Float16TPTraits > OHalfGeomParam
Definition: OGeomParam.h:405
OTypedGeomParam< Uint32TPTraits > OUInt32GeomParam
Definition: OGeomParam.h:401
Sample(const Abc::TypedArraySample< TRAITS > &iVals, const Abc::UInt32ArraySample &iIndices, GeometryScope iScope)
Definition: OGeomParam.h:73
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
OTypedGeomParam< StringTPTraits > OStringGeomParam
Definition: OGeomParam.h:408
const char * PODName(PlainOldDataType pod)
OTypedGeomParam< Box2iTPTraits > OBox2iGeomParam
Definition: OGeomParam.h:432
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
OTypedGeomParam< C3hTPTraits > OC3hGeomParam
Definition: OGeomParam.h:449
OTypedGeomParam< P3iTPTraits > OP3iGeomParam
Definition: OGeomParam.h:427
OTypedGeomParam< M33dTPTraits > OM33dGeomParam
Definition: OGeomParam.h:442
void set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
OTypedGeomParam< C4cTPTraits > OC4cGeomParam
Definition: OGeomParam.h:455
OTypedGeomParam< Int32TPTraits > OInt32GeomParam
Definition: OGeomParam.h:402
OTypedGeomParam< V3sTPTraits > OV3sGeomParam
Definition: OGeomParam.h:416
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
OTypedGeomParam< C3cTPTraits > OC3cGeomParam
Definition: OGeomParam.h:451
OTypedGeomParam< V2fTPTraits > OV2fGeomParam
Definition: OGeomParam.h:413
OTypedGeomParam< Int8TPTraits > OCharGeomParam
Definition: OGeomParam.h:398
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:285
OTypedGeomParam< V3dTPTraits > OV3dGeomParam
Definition: OGeomParam.h:419
OTypedGeomParam< Int64TPTraits > OInt64GeomParam
Definition: OGeomParam.h:404
OTypedGeomParam< WstringTPTraits > OWstringGeomParam
Definition: OGeomParam.h:409
OTypedGeomParam< P3fTPTraits > OP3fGeomParam
Definition: OGeomParam.h:428
void SetGeometryScope(AbcA::MetaData &ioMetaData, GeometryScope iScope)
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
OTypedGeomParam< Int16TPTraits > OInt16GeomParam
Definition: OGeomParam.h:400
OTypedGeomParam< QuatdTPTraits > OQuatdGeomParam
Definition: OGeomParam.h:447
OTypedArrayProperty< Uint32TPTraits > OUInt32ArrayProperty
OTypedGeomParam< P2dTPTraits > OP2dGeomParam
Definition: OGeomParam.h:424
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:81
OTypedGeomParam< V3fTPTraits > OV3fGeomParam
Definition: OGeomParam.h:418
OTypedGeomParam< C3fTPTraits > OC3fGeomParam
Definition: OGeomParam.h:450
OTypedGeomParam< Uint8TPTraits > OUcharGeomParam
Definition: OGeomParam.h:397
OTypedGeomParam< N3dTPTraits > ON3dGeomParam
Definition: OGeomParam.h:461
OTypedGeomParam< Box2dTPTraits > OBox2dGeomParam
Definition: OGeomParam.h:434
OTypedGeomParam< Uint16TPTraits > OUInt16GeomParam
Definition: OGeomParam.h:399
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
OTypedGeomParam< N2fTPTraits > ON2fGeomParam
Definition: OGeomParam.h:457
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
OTypedGeomParam< M33fTPTraits > OM33fGeomParam
Definition: OGeomParam.h:441
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
Sample(const Abc::TypedArraySample< TRAITS > &iVals, GeometryScope iScope)
Definition: OGeomParam.h:67