HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
147  const std::string &iName,
148  bool iIsIndexed,
149  GeometryScope iScope,
150  size_t iArrayExtent,
151  const Argument &iArg0 = Argument(),
152  const Argument &iArg1 = Argument(),
153  const Argument &iArg2 = Argument()
154  )
155  : m_name( iName )
156  , m_isIndexed( iIsIndexed )
157  , m_scope( iScope )
158  {
159  *this = OTypedGeomParam( iParent.getPtr(), iName, iIsIndexed, iScope,
160  iArrayExtent, iArg0, iArg1, iArg2 );
161  }
162 
164  const std::string &iName,
165  bool iIsIndexed,
166  GeometryScope iScope,
167  size_t iArrayExtent,
168  const Argument &iArg0 = Argument(),
169  const Argument &iArg1 = Argument(),
170  const Argument &iArg2 = Argument()
171  )
172  : m_name( iName )
173  , m_isIndexed( iIsIndexed )
174  , m_scope( iScope )
175  {
176  Arguments args( Abc::GetErrorHandlerPolicy( iParent ) );
177  iArg0.setInto( args );
178  iArg1.setInto( args );
179  iArg2.setInto( args );
180 
181  AbcA::MetaData md = args.getMetaData();
182 
183  SetGeometryScope( md, iScope );
184 
185  md.set( "isGeomParam", "true" );
186 
188  TRAITS::dataType().getPod() ) );
189 
190  size_t extent = TRAITS::dataType().getExtent();
191 
192  md.set( "podName", podName );
193 
194  std::ostringstream extentStrm;
195  extentStrm << extent;
196  std::string extentStr = extentStrm.str();
197  md.set( "podExtent", extentStr );
198 
199  std::ostringstream arrayExtentStrm;
200  arrayExtentStrm << iArrayExtent;
201  std::string arrayExtentStr = arrayExtentStrm.str();
202  md.set( "arrayExtent", arrayExtentStr );
203 
204  md.set( "interpretation", TRAITS::interpretation() );
205 
207 
208  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
209  uint32_t tsIndex = args.getTimeSamplingIndex();
210 
211  // if we specified a valid TimeSamplingPtr, use it to determine the
212  // index otherwise we'll use the index, which defaults to the
213  // intrinsic 0 index
214  if (tsPtr)
215  {
217  GetCompoundPropertyWriterPtr( iParent );
218  tsIndex =
219  parent->getObject()->getArchive()->addTimeSampling(*tsPtr);
220  }
221 
222  if ( m_isIndexed )
223  {
224  m_cprop = Abc::OCompoundProperty( iParent, iName, md, ehp );
225 
226  m_valProp = prop_type( m_cprop, ".vals", md, ehp, tsIndex );
227 
229  tsIndex );
230  }
231  else
232  {
233  m_valProp = prop_type( iParent, iName, md, ehp, tsIndex );
234  }
235  }
236 
237 public:
238 
239  void set( const sample_type &iSamp )
240  {
241  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam::set()" );
242 
243  if ( m_valProp.getNumSamples() == 0 )
244  {
245  m_valProp.set( iSamp.getVals() );
246  if ( m_isIndexed ) { m_indicesProperty.set( iSamp.getIndices() ); }
247  }
248  else
249  {
250  SetPropUsePrevIfNull( m_valProp, iSamp.getVals() );
251  if ( m_isIndexed )
252  {
253  SetPropUsePrevIfNull( m_indicesProperty, iSamp.getIndices() );
254  }
255  }
256 
258  }
259 
261  {
262  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam::setFromPrevious()" );
263 
265 
267 
269  }
270 
271  void setTimeSampling( uint32_t iIndex )
272  {
274  "OTypedGeomParam::setTimeSampling( uint32_t )" );
275 
276  m_valProp.setTimeSampling( iIndex );
277 
278  if ( m_isIndexed ) { m_indicesProperty.setTimeSampling( iIndex ); }
279 
281  }
282 
284  {
286  "OTypedGeomParam::setTimeSampling( TimeSamplingPtr )" );
287 
288  if (iTime)
289  {
290  uint32_t tsIndex =
292  *iTime);
293  setTimeSampling( tsIndex );
294  }
295 
297  }
298 
299  size_t getNumSamples() const
300  {
301  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedGeomParam::getNumSamples()" );
302 
303  if ( m_isIndexed )
304  {
305  if ( m_indicesProperty )
306  {
309  }
310  else { return 0; }
311  }
312  else
313  {
314  if ( m_valProp ) { return m_valProp.getNumSamples(); }
315  else { return 0; }
316  }
317 
319 
320  return 0;
321  }
322 
323  AbcA::DataType getDataType() const { return TRAITS::dataType(); }
324 
325  bool isIndexed() const { return m_isIndexed; }
326 
327  GeometryScope getScope() const { return m_scope; }
328 
330  {
331  return m_valProp.getTimeSampling();
332  }
333 
334  const std::string &getName() const { return m_name; }
335 
336  bool valid() const
337  {
338  return ( m_valProp.valid()
339  && ( ( ! m_isIndexed ) || m_indicesProperty ) );
340  }
341 
343 
344  void reset()
345  {
346  m_name = "";
347  m_valProp.reset();
349  m_cprop.reset();
351  m_isIndexed = false;
352  }
353 
355 
357 
358 private:
359  Abc::ErrorHandler &getErrorHandler() const
360  { return m_valProp.getErrorHandler(); }
361 
362 protected:
364 
368 
370 
371  // if the GeomParam is not indexed, this will not exist.
373 };
374 
375 //-*****************************************************************************
376 // TYPEDEFS
377 //-*****************************************************************************
378 
393 
398 
403 
408 
413 
418 
423 
428 
431 
435 
439 
442 
445 
446 } // End namespace ALEMBIC_VERSION_NS
447 
448 using namespace ALEMBIC_VERSION_NS;
449 
450 } // End namespace AbcGeom
451 } // End namespace Alembic
452 
453 #endif
OTypedGeomParam< V2dTPTraits > OV2dGeomParam
Definition: OGeomParam.h:397
AbcA::TimeSamplingPtr getTimeSampling() const
OTypedGeomParam< V2sTPTraits > OV2sGeomParam
Definition: OGeomParam.h:394
void setTimeSampling(AbcA::TimeSamplingPtr iTime)
Definition: OGeomParam.h:283
OTypedGeomParam< Box3dTPTraits > OBox3dGeomParam
Definition: OGeomParam.h:422
OTypedGeomParam< V2iTPTraits > OV2iGeomParam
Definition: OGeomParam.h:395
const Abc::UInt32ArraySample & getIndices() const
Definition: OGeomParam.h:88
OTypedGeomParam(OCompoundProperty 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:146
OTypedGeomParam< QuatfTPTraits > OQuatfGeomParam
Definition: OGeomParam.h:429
OTypedGeomParam< P2fTPTraits > OP2fGeomParam
Definition: OGeomParam.h:406
void setIndices(const Abc::UInt32ArraySample &iIndices)
Definition: OGeomParam.h:86
uint32_t addTimeSampling(const AbcA::TimeSampling &iTs)
OTypedGeomParam< P2iTPTraits > OP2iGeomParam
Definition: OGeomParam.h:405
OTypedGeomParam< Box3sTPTraits > OBox3sGeomParam
Definition: OGeomParam.h:419
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
OTypedGeomParam< Float32TPTraits > OFloatGeomParam
Definition: OGeomParam.h:389
OTypedGeomParam< P3sTPTraits > OP3sGeomParam
Definition: OGeomParam.h:409
OTypedGeomParam< BooleanTPTraits > OBoolGeomParam
Definition: OGeomParam.h:379
OTypedGeomParam< Box2sTPTraits > OBox2sGeomParam
Definition: OGeomParam.h:414
OTypedGeomParam< C4fTPTraits > OC4fGeomParam
Definition: OGeomParam.h:437
void setVals(const Abc::TypedArraySample< TRAITS > &iVals)
Definition: OGeomParam.h:81
OTypedGeomParam< P3dTPTraits > OP3dGeomParam
Definition: OGeomParam.h:412
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:89
uint64 value_type
Definition: GA_PrimCompat.h:29
OTypedGeomParam< Float64TPTraits > ODoubleGeomParam
Definition: OGeomParam.h:390
OTypedGeomParam< V3iTPTraits > OV3iGeomParam
Definition: OGeomParam.h:400
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: OGeomParam.h:329
OTypedGeomParam< M44fTPTraits > OM44fGeomParam
Definition: OGeomParam.h:426
OTypedGeomParam< C4hTPTraits > OC4hGeomParam
Definition: OGeomParam.h:436
OTypedGeomParam< Box3iTPTraits > OBox3iGeomParam
Definition: OGeomParam.h:420
const Abc::TypedArraySample< TRAITS > & getVals() const
Definition: OGeomParam.h:83
OTypedGeomParam< Box3fTPTraits > OBox3fGeomParam
Definition: OGeomParam.h:421
OTypedGeomParam< Box2fTPTraits > OBox2fGeomParam
Definition: OGeomParam.h:416
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OTypedGeomParam< N3fTPTraits > ON3fGeomParam
Definition: OGeomParam.h:443
OTypedGeomParam< M44dTPTraits > OM44dGeomParam
Definition: OGeomParam.h:427
OTypedGeomParam< N2dTPTraits > ON2dGeomParam
Definition: OGeomParam.h:441
OTypedGeomParam< P2sTPTraits > OP2sGeomParam
Definition: OGeomParam.h:404
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OGeomParam.h:122
OUInt32ArrayProperty getIndexProperty() const
Definition: OGeomParam.h:356
OTypedGeomParam< Uint64TPTraits > OUInt64GeomParam
Definition: OGeomParam.h:386
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
void SetPropUsePrevIfNull(PROP iProp, SAMP iSamp)
Definition: Foundation.h:96
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
OTypedGeomParam< Float16TPTraits > OHalfGeomParam
Definition: OGeomParam.h:388
OTypedGeomParam< Uint32TPTraits > OUInt32GeomParam
Definition: OGeomParam.h:384
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:391
const char * PODName(PlainOldDataType pod)
OTypedGeomParam< Box2iTPTraits > OBox2iGeomParam
Definition: OGeomParam.h:415
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
OTypedGeomParam< C3hTPTraits > OC3hGeomParam
Definition: OGeomParam.h:432
OTypedGeomParam< P3iTPTraits > OP3iGeomParam
Definition: OGeomParam.h:410
OTypedGeomParam< M33dTPTraits > OM33dGeomParam
Definition: OGeomParam.h:425
void set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
OTypedGeomParam< C4cTPTraits > OC4cGeomParam
Definition: OGeomParam.h:438
OTypedGeomParam< Int32TPTraits > OInt32GeomParam
Definition: OGeomParam.h:385
OTypedGeomParam< V3sTPTraits > OV3sGeomParam
Definition: OGeomParam.h:399
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
OTypedGeomParam< C3cTPTraits > OC3cGeomParam
Definition: OGeomParam.h:434
OTypedGeomParam< V2fTPTraits > OV2fGeomParam
Definition: OGeomParam.h:396
OTypedGeomParam< Int8TPTraits > OCharGeomParam
Definition: OGeomParam.h:381
OTypedGeomParam< V3dTPTraits > OV3dGeomParam
Definition: OGeomParam.h:402
OTypedGeomParam(AbcA::CompoundPropertyWriterPtr 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:163
OTypedGeomParam< Int64TPTraits > OInt64GeomParam
Definition: OGeomParam.h:387
OTypedGeomParam< WstringTPTraits > OWstringGeomParam
Definition: OGeomParam.h:392
OTypedGeomParam< P3fTPTraits > OP3fGeomParam
Definition: OGeomParam.h:411
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:383
OTypedGeomParam< QuatdTPTraits > OQuatdGeomParam
Definition: OGeomParam.h:430
OTypedArrayProperty< Uint32TPTraits > OUInt32ArrayProperty
OTypedGeomParam< P2dTPTraits > OP2dGeomParam
Definition: OGeomParam.h:407
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:174
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
OTypedGeomParam< V3fTPTraits > OV3fGeomParam
Definition: OGeomParam.h:401
OTypedGeomParam< C3fTPTraits > OC3fGeomParam
Definition: OGeomParam.h:433
OTypedGeomParam< Uint8TPTraits > OUcharGeomParam
Definition: OGeomParam.h:380
OTypedGeomParam< N3dTPTraits > ON3dGeomParam
Definition: OGeomParam.h:444
OTypedGeomParam< Box2dTPTraits > OBox2dGeomParam
Definition: OGeomParam.h:417
OTypedGeomParam< Uint16TPTraits > OUInt16GeomParam
Definition: OGeomParam.h:382
OTypedGeomParam< N2fTPTraits > ON2fGeomParam
Definition: OGeomParam.h:440
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
OTypedGeomParam< M33fTPTraits > OM33fGeomParam
Definition: OGeomParam.h:424
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
Sample(const Abc::TypedArraySample< TRAITS > &iVals, GeometryScope iScope)
Definition: OGeomParam.h:67