HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OGeomBase.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_OGeometrySchema_h
38 #define Alembic_AbcGeom_OGeometrySchema_h
39 
40 #include <Alembic/Abc/OSchema.h>
43 
44 namespace Alembic {
45 namespace AbcGeom {
46 namespace ALEMBIC_VERSION_NS {
47 
48 
49 //! This class holds properties common to all classes with a physical volume.
50 //! - selfBounds
51 //! - childBounds (optional)
52 //! - GeomParams (optional)
53 //! - UserProperties (optional)
54 //!
55 //! This class is used to encapsulate common functionality of the
56 //! real Geometry schema classes, like OPoints and OPolyMesh and so on
57 template <class INFO>
58 class OGeomBaseSchema : public Abc::OSchema<INFO>
59 {
60 public:
61  //-*************************************************************************
62  // TYPEDEFS AND IDENTIFIERS
63  //-*************************************************************************
64 
65  typedef INFO info_type;
66 
67 
68  //-*************************************************************************
69  // Constructors that pass through to OSchema
70  //-*************************************************************************
71  //
72  //! The default constructor creates an empty OSchema.
73  //! Used to create "NULL/invalid" instances.
75 
76  //! Delegates to Abc/OSchema, and then creates always-present
77  //! properties
79  const std::string &iName,
80  const Argument &iArg0 = Argument(),
81  const Argument &iArg1 = Argument(),
82  const Argument &iArg2 = Argument(),
83  const Argument &iArg3 = Argument() )
84  : Abc::OSchema<info_type>( iParent, iName, iArg0, iArg1, iArg2, iArg3 )
85  {
86  AbcA::TimeSamplingPtr tsPtr =
87  Abc::GetTimeSampling( iArg0, iArg1, iArg2, iArg3 );
88  uint32_t tsIndex =
89  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2, iArg3 );
90 
91  // if we specified a valid TimeSamplingPtr, use it to determine the
92  // index otherwise use the default index of 0 - uniform.
93  if ( tsPtr )
94  {
95  tsIndex = iParent->getObject()->getArchive()->addTimeSampling(
96  *tsPtr );
97  }
98 
99  // Create our always present property
100  init( tsIndex, Abc::IsSparse( iArg0, iArg1, iArg2, iArg3 ) );
101  }
102 
103  //! Copy constructor
105  : Abc::OSchema<info_type>()
106  {
107  *this = iCopy;
108  }
109 
110  virtual void reset ()
111  {
117  }
118 
119  virtual bool valid() const
120  {
121  return ( Abc::OSchema<info_type>::valid() );
122  }
123 
125  {
126  // Accessing the ArbGeomParams will create its compound
127  // property if needed.
128  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::getArbGeomParams()" );
129 
130  if ( ! m_arbGeomParams )
131  {
133  ".arbGeomParams" );
134  }
135 
136  return m_arbGeomParams;
137 
139 
141  return ret;
142  }
143 
145  {
146  // Accessing UserProperties will create its compound
147  // property if needed.
148  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::getUserProperties()" );
149 
150  if ( ! m_userProperties )
151  {
153  ".userProperties" );
154  }
155 
156  return m_userProperties;
157 
159 
161  return ret;
162  }
163 
165  {
166  // Accessing Child Bounds Property will create it if needed
168  "OGeomBaseSchema::getChildBoundsProperty()" );
169 
170  if ( ! m_childBoundsProperty )
171  {
172  AbcA::CompoundPropertyWriterPtr _this = this->getPtr();
173 
174  // for now, use the self bounds time sampling, this
175  // can and should be changed depending on how the children
176  // are sampled
178  ".childBnds", m_selfBoundsProperty.getTimeSampling() );
179 
180  }
181 
183  return m_childBoundsProperty;
184  }
185 
186 protected:
187 
188  void init( uint32_t iTsIndex, bool isSparse)
189  {
190  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::init()" );
191 
192  if( !isSparse )
193  {
194  createSelfBoundsProperty(iTsIndex, 0);
195  }
196 
198  }
199 
200  //! Creates the self bounds
201  void createSelfBoundsProperty(uint32_t iTsIndex, size_t iNumSamples)
202  {
203  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::createSelfBoundsProperty()" );
204 
205  if ( m_selfBoundsProperty.valid() )
206  {
207  return;
208  }
209 
210  m_selfBoundsProperty = Abc::OBox3dProperty( this->getPtr(), ".selfBnds",
211  iTsIndex );
212 
213  Abc::Box3d bnds;
214  for ( size_t i = 0; i < iNumSamples; ++i )
215  {
216  m_selfBoundsProperty.set( bnds );
217  }
219  }
220 
221  // Only selfBounds is required, all others are optional
224 
227 
228 };
229 
230 
231 } // End namespace ALEMBIC_VERSION_NS
232 
233 using namespace ALEMBIC_VERSION_NS;
234 
235 } // End namespace AbcGeom
236 } // End namespace Alembic
237 
238 #endif
AbcA::TimeSamplingPtr getTimeSampling() const
OGeomBaseSchema(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: OGeomBase.h:78
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
OTypedScalarProperty< Box3dTPTraits > OBox3dProperty
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
bool IsSparse(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:333
void init(uint32_t iTsIndex, bool isSparse)
Definition: OGeomBase.h:188
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:288
OGeomBaseSchema(const OGeomBaseSchema &iCopy)
Copy constructor.
Definition: OGeomBase.h:104
Box< V3d > Box3d
3D box of base type double.
Definition: ImathBox.h:167
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:303
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
void createSelfBoundsProperty(uint32_t iTsIndex, size_t iNumSamples)
Creates the self bounds.
Definition: OGeomBase.h:201
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr