HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IGeomBase.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2011,
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_IGeometrySchema_h_
38 #define _Alembic_AbcGeom_IGeometrySchema_h_
39 
40 #include <Alembic/Abc/ISchema.h>
44 
45 namespace Alembic {
46 namespace AbcGeom {
47 namespace ALEMBIC_VERSION_NS {
48 
49 
50 //! This class holds properties common to all geometric classes that have a
51 //! physical volume.
52 //! - selfBounds
53 //! - childBounds (optional)
54 //! - GeomParams (optional)
55 //! - UserProperties (optional)
56 //!
57 //! This class is used to encapsulate common functionality of the
58 //! real Geometry schema classes, like IPoints and IPolyMesh and so on
59 template <class INFO>
60 class IGeomBaseSchema : public Abc::ISchema<INFO>
61 {
62 public:
63  //-*************************************************************************
64  // TYPEDEFS AND IDENTIFIERS
65  //-*************************************************************************
66 
67  typedef INFO info_type;
68 
69 
70  //-*************************************************************************
71  // Constructors that pass through to ISchema
72  //-*************************************************************************
73  //
74  //! The default constructor creates an empty ISchema.
75  //! Used to create "NULL/invalid" instances.
77 
78  //! Delegates to Abc/ISchema, and then creates
79  //! properties that are present.
80  template <class CPROP_PTR>
81  IGeomBaseSchema( CPROP_PTR iParentCompound,
82  const std::string &iName,
83 
84  const Argument &iArg0 = Argument(),
85  const Argument &iArg1 = Argument() )
86  : Abc::ISchema<info_type>( iParentCompound, iName, iArg0, iArg1 )
87  {
88  init( iArg0, iArg1 );
89  }
90 
91  template <class CPROP_PTR>
92  explicit IGeomBaseSchema( CPROP_PTR iParentCompound,
93 
94  const Argument &iArg0 = Argument(),
95  const Argument &iArg1 = Argument() )
96  : Abc::ISchema<info_type>( iParentCompound, iArg0, iArg1 )
97  {
98  init( iArg0, iArg1 );
99  }
100 
101  //! Wrap an existing schema object
102  template <class CPROP_PTR>
103  IGeomBaseSchema( CPROP_PTR iThis,
104  Abc::WrapExistingFlag iFlag,
105  const Abc::Argument &iArg0 = Abc::Argument(),
106  const Abc::Argument &iArg1 = Abc::Argument() )
107  : Abc::ISchema<info_type>( iThis, iFlag, iArg0, iArg1 )
108  {
109  init( iArg0, iArg1 );
110  }
111 
112  //! Copy constructor
114  : Abc::ISchema<info_type>()
115  {
116  *this = iCopy;
117  }
118 
119  void init( const Abc::Argument &iArg0, const Abc::Argument &iArg1 )
120  {
121  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IGeomBaseSchema::init()" );
122 
123  Abc::Arguments args;
124  iArg0.setInto( args );
125  iArg1.setInto( args );
126 
127  AbcA::CompoundPropertyReaderPtr _this = this->getPtr();
128 
129  m_selfBoundsProperty = Abc::IBox3dProperty( _this, ".selfBnds",
130  iArg0, iArg1 );
131  if ( this->getPropertyHeader( ".childBnds" ) != NULL )
132  {
134  ".childBnds", iArg0, iArg1 );
135  }
136 
137  if ( this->getPropertyHeader( ".arbGeomParams" ) != NULL )
138  {
139  m_arbGeomParams = Abc::ICompoundProperty( _this, ".arbGeomParams",
140  args.getErrorHandlerPolicy() );
141  }
142  if ( this->getPropertyHeader( ".userProperties" ) != NULL )
143  {
144  m_userProperties = Abc::ICompoundProperty( _this, ".userProperties",
145  args.getErrorHandlerPolicy() );
146  }
147 
149  }
150 
151  virtual void reset ()
152  {
158  }
159 
160  virtual bool valid() const
161  {
162  // Only selfBounds is required, all others are optional
163  return ( Abc::ISchema<info_type>::valid() &&
165  }
166 
168  {
169  return m_selfBoundsProperty;
170  }
171 
173  {
174  return m_childBoundsProperty;
175  }
176 
177  // compound property to use as parent for any arbitrary GeomParams
178  // underneath it
180 
181  // compound property to use as parent for any user workflow specific
182  // properties
184 
185 protected:
186  // Only selfBounds is required, all others are optional
189 
192 
193 };
194 
195 //-*****************************************************************************
196 //! IGeomBase - A generic base set of properties and methods that encapsulate
197 //! things common to AbcGeom types that have a physical volume.
198 //! - self bounds
199 //! - children bounds (optional)
200 //! - argbGeomParams (optional)
201 //! - userProperties (optional)
202 //! This class is a concrete instantiation of IGeomBaseSchema.
203 //! Your archive might contain PolyMesh and SubD and Curves
204 //! and Points objects etc. This class, IGeomBase, gives you
205 //! access to the generic parts of those objects. For example, if you
206 //! just wish to iterate through an archive's hierarchy to examine bounding
207 //! regions this class could be helpful to you. Then when you actually
208 //! need to access the real data in the geometric type you can
209 //! always create the needed type of I<geom type> object> via kWrapExisting.
210 class IGeomBase : public IGeomBaseSchema<GeomBaseSchemaInfo>
211 {
212 public:
214 
215  class Sample
216  {
217  public:
218  typedef Sample this_type;
219 
220  // Users don't ever create this data directly.
221  Sample() { reset(); }
222 
224 
225  void reset()
226  {
227  m_selfBounds.makeEmpty();
228  }
229 
230  protected:
231  friend class IGeomBase;
233  };
234 
235 public:
236  //! By convention we always define this_type in AbcGeom classes.
237  //! Used by unspecified-bool-type conversion below
238 
239  //-*************************************************************************
240  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
241  //-*************************************************************************
242 
243  //! The default constructor creates an empty GeomBase
245 
246  template <class CPROP_PTR>
247  IGeomBase( CPROP_PTR iParent,
248  const std::string &iName,
249  const Abc::Argument &iArg0 = Abc::Argument(),
250  const Abc::Argument &iArg1 = Abc::Argument() )
251 
252  // We don't want strict matching of the title because the real schema
253  // is going to be something like "AbcGeom_<type>_vX"
254  : IGeomBaseSchema<GeomBaseSchemaInfo>( iParent, iName, kNoMatching )
255  {
256  init( iArg0, iArg1 );
257  }
258 
259  template <class CPROP_PTR>
260  explicit IGeomBase( CPROP_PTR iThis,
261  const Abc::Argument &iArg0 = Abc::Argument(),
262  const Abc::Argument &iArg1 = Abc::Argument() )
263  // We don't want strict matching of the title because the real schema
264  // is going to be something like "AbcGeom_<type>_vX"
265  : IGeomBaseSchema<GeomBaseSchemaInfo>( iThis, kNoMatching )
266  {
267  init( iArg0, iArg1 );
268  }
269 
270  template <class CPROP_PTR>
271  explicit IGeomBase( CPROP_PTR iThis,
272  Abc::WrapExistingFlag iFlag,
273  const Abc::Argument &iArg0 = Abc::Argument(),
274  const Abc::Argument &iArg1 = Abc::Argument() )
275  // We don't want strict matching of the title because the real schema
276  // is going to be something like "AbcGeom_<type>_vX"
277  : IGeomBaseSchema<GeomBaseSchemaInfo>( iThis, iFlag, kNoMatching )
278  {
279  init( iArg0, iArg1 );
280  }
281 
282  //! Copy constructor.
283  IGeomBase(const IGeomBase & iCopy)
284  : IGeomBaseSchema<GeomBaseSchemaInfo>()
285  {
286  *this = iCopy;
287  }
288 
289  //! Default assignment operator used.
290 
291  //-*************************************************************************
292  // SCALAR PROPERTY READER FUNCTIONALITY
293  //-*************************************************************************
294 
295  //! Return the number of samples contained in the property.
296  //! This can be any number, including zero.
297  //! This returns the number of samples that were written, independently
298  //! of whether or not they were constant.
299  size_t getNumSamples() const
300  { return m_selfBoundsProperty.getNumSamples(); }
301 
302  //! Ask if we're constant - no change in value amongst samples,
303  //! regardless of the time sampling.
304  bool isConstant() const
305  { return m_selfBoundsProperty.isConstant(); }
306 
307  //! Time sampling Information.
308  //!
310  {
311  if ( m_selfBoundsProperty.valid() )
312  {
314  }
315  else
316  {
317  return getObject().getArchive().getTimeSampling( 0 );
318  }
319  }
320 
321  //-*************************************************************************
322  void get( Sample &oSample,
323  const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const
324  {
325  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IGeomBase::get()" );
326 
327  m_selfBoundsProperty.get( oSample.m_selfBounds, iSS );
328 
330  }
331 
332  //-*************************************************************************
334  {
335  Sample smp;
336  get( smp, iSS );
337  return smp;
338  }
339 
340  //-*************************************************************************
342 
343  //-*************************************************************************
345 
346  //-*************************************************************************
347  //! Reset returns this function set to an empty, default
348  //! state.
349  void reset()
350  {
352  }
353 
354  //-*************************************************************************
355  //! Valid returns whether this function set is
356  //! valid.
357  bool valid() const
358  {
360  }
361 
362  //-*************************************************************************
363  //! unspecified-bool-type operator overload.
364  //! ...
366 
367  //-*************************************************************************
368  //! This will check whether or not a given entity (as represented by
369  //! metadata) strictly matches the interpretation of this
370  //! schema object.
371  static bool matches( const AbcA::MetaData &iMetaData,
373  {
374  if ( iMatching == kNoMatching )
375  { return true; }
376 
377  if ( iMatching == kStrictMatching || iMatching == kSchemaTitleMatching )
378  {
379  return iMetaData.get( "schemaBaseType" ) ==
380  GeomBaseSchemaInfo::title();
381  }
382 
383  return false;
384  }
385 
386  //-*************************************************************************
387  //! This will check whether or not a given object (as represented by
388  //! an object header) strictly matches the interpretation of this
389  //! schema object, as well as the data type.
390  static bool matches( const AbcA::PropertyHeader &iHeader,
392  {
393  return matches( iHeader.getMetaData(), iMatching );
394  }
395 
396 };
397 
398 //-*****************************************************************************
400 
401 } // End namespace ALEMBIC_VERSION_NS
402 
403 using namespace ALEMBIC_VERSION_NS;
404 
405 } // End namespace AbcGeom
406 } // End namespace Alembic
407 
408 #endif
IGeomBaseSchema(CPROP_PTR iParentCompound, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: IGeomBase.h:81
IGeomBase(CPROP_PTR iThis, Abc::WrapExistingFlag iFlag, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition: IGeomBase.h:271
Abc::ICompoundProperty getUserProperties() const
Definition: IGeomBase.h:344
const AbcA::PropertyHeader & getPropertyHeader(size_t i) const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Abc::ICompoundProperty getArbGeomParams() const
Definition: IGeomBase.h:341
void get(value_type &iVal, const ISampleSelector &iSS=ISampleSelector()) const
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: IGeomBase.h:309
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
Abc::IBox3dProperty getSelfBoundsProperty() const
Definition: IGeomBase.h:167
Abc::IBox3dProperty getChildBoundsProperty() const
Definition: IGeomBase.h:172
IGeomBase()
The default constructor creates an empty GeomBase.
Definition: IGeomBase.h:244
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
IGeomBase(CPROP_PTR iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition: IGeomBase.h:247
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
size_t getNumSamples() const
Default assignment operator used.
Definition: IGeomBase.h:299
IGeomBase(const IGeomBase &iCopy)
Copy constructor.
Definition: IGeomBase.h:283
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
IGeomBaseSchema(CPROP_PTR iThis, Abc::WrapExistingFlag iFlag, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Wrap an existing schema object.
Definition: IGeomBase.h:103
AbcA::TimeSamplingPtr getTimeSampling() const
AbcA::TimeSamplingPtr getTimeSampling(uint32_t iIndex)
Returns the TimeSampling at a given index.
Box< V3d > Box3d
Definition: ImathBox.h:139
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
IGeomBase(CPROP_PTR iThis, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition: IGeomBase.h:260
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: IGeomBase.h:371
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: IGeomBase.h:390
IGeomBaseSchema(const IGeomBaseSchema &iCopy)
Copy constructor.
Definition: IGeomBase.h:113
IGeomBaseSchema(CPROP_PTR iParentCompound, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: IGeomBase.h:92
Abc::ISchemaObject< IGeomBase > IGeomBaseObject
Definition: IGeomBase.h:399
Sample getValue(const Abc::ISampleSelector &iSS=Abc::ISampleSelector()) const
Definition: IGeomBase.h:333
ITypedScalarProperty< Box3dTPTraits > IBox3dProperty
void init(const Abc::Argument &iArg0, const Abc::Argument &iArg1)
Definition: IGeomBase.h:119
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104