HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OXform.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_OXform_h_
38 #define _Alembic_AbcGeom_OXform_h_
39 
40 #include <Alembic/Util/Export.h>
43 
45 
46 namespace Alembic {
47 namespace AbcGeom {
48 namespace ALEMBIC_VERSION_NS {
49 
50 //! The default value for determining whether a property is actually
51 //! different from the default.
52 static ALEMBIC_EXPORT_CONST double kXFORM_DELTA_TOLERANCE = 1.0e-12;
53 
54 //-*****************************************************************************
55 class ALEMBIC_EXPORT OXformSchema : public Abc::OSchema<XformSchemaInfo>
56 {
57  //-*************************************************************************
58  // XFORM SCHEMA
59  //-*************************************************************************
60 public:
61 
62  //! By convention we always define this_type in AbcGeom classes.
63  //! Used by unspecified-bool-type conversion below
67 
68  //-*************************************************************************
69  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
70  //-*************************************************************************
71 
72  //! The default constructor creates an empty OPolyMeshSchema
73  //! ...
75 
76  //! This templated, primary constructor creates a new xform writer.
77  //! The first argument is any Abc (or AbcCoreAbstract) object
78  //! which can intrusively be converted to an CompoundPropertyWriterPtr
79  //! to use as a parent, from which the error handler policy for
80  //! inheritance is also derived. The remaining optional arguments
81  //! can be used to override the ErrorHandlerPolicy, to specify
82  //! MetaData, and to set TimeSampling.
83  template <class CPROP_PTR>
84  OXformSchema( CPROP_PTR iParent,
85  const std::string &iName,
86  const Abc::Argument &iArg0 = Abc::Argument(),
87  const Abc::Argument &iArg1 = Abc::Argument(),
88  const Abc::Argument &iArg2 = Abc::Argument() )
89  : Abc::OSchema<XformSchemaInfo>( iParent, iName,
90  iArg0, iArg1, iArg2 )
91  {
92  // Meta data and error handling are eaten up by
93  // the super type, so all that's left is time sampling.
94  AbcA::TimeSamplingPtr tsPtr =
95  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
96 
97  AbcA::index_t tsIndex =
98  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
99 
100  if ( tsPtr )
101  {
102  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
103  )->getArchive()->addTimeSampling( *tsPtr );
104  }
105 
106  init( tsIndex );
107  }
108 
109  //! This constructor does the same as the above, but uses the default
110  //! name from the XformSchemaInfo struct.
111  template <class CPROP_PTR>
112  explicit OXformSchema( CPROP_PTR iParent,
113  const Abc::Argument &iArg0 = Abc::Argument(),
114  const Abc::Argument &iArg1 = Abc::Argument(),
115  const Abc::Argument &iArg2 = Abc::Argument() )
116  : Abc::OSchema<XformSchemaInfo>( iParent,
117  iArg0, iArg1, iArg2 )
118  {
119  // Meta data and error handling are eaten up by
120  // the super type, so all that's left is time sampling.
121  AbcA::TimeSamplingPtr tsPtr =
122  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
123 
124  AbcA::index_t tsIndex =
125  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
126 
127  if ( tsPtr )
128  {
129  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
130  )->getArchive()->addTimeSampling( *tsPtr );
131  }
132 
133  init( tsIndex );
134  }
135 
136  //! Explicit copy constructor to work around MSVC bug
137  OXformSchema( const OXformSchema &iCopy )
138  : Abc::OSchema<XformSchemaInfo>()
139  { *this = iCopy; }
140 
141  //! Default assignment operator used.
142 
143  //-*************************************************************************
144  // SCHEMA STUFF
145  //-*************************************************************************
146 
147  AbcA::TimeSamplingPtr getTimeSampling() const;
148 
149  //-*************************************************************************
150  // SAMPLE STUFF
151  //-*************************************************************************
152 
153  //! Get number of samples written so far.
154  //! ...
155  size_t getNumSamples() const;
156 
157  //! Set an animated sample. On first call to set, the sample is modified,
158  //! so it can't be const.
159  void set( XformSample &ioSamp );
160 
161  //! Set from previous sample. Will hold the animated channels.
162  void setFromPrevious();
163 
164  void setTimeSampling( uint32_t iIndex );
165  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
166 
167  Abc::OCompoundProperty getArbGeomParams();
168  Abc::OCompoundProperty getUserProperties();
169  Abc::OBox3dProperty getChildBoundsProperty();
170 
171  //-*************************************************************************
172  // ABC BASE MECHANISMS
173  // These functions are used by Abc to deal with errors, validity,
174  // and so on.
175  //-*************************************************************************
176 
177  //! Reset returns this function set to an empty, default
178  //! state.
179  void reset()
180  {
181  m_childBoundsProperty.reset();
182  m_inheritsProperty.reset();
183  m_opsPWPtr.reset();
184  m_valsPWPtr.reset();
185  m_protoSample.reset();
186  m_data.reset();
187 
188  m_arbGeomParams.reset();
189  m_userProperties.reset();
190 
191  super_type::reset();
192  }
193 
194  //! Valid returns whether this function set is valid.
195  bool valid() const
196  {
197  return ( m_opsPWPtr && super_type::valid() );
198  }
199 
200  //! unspecified-bool-type operator overload.
201  //! ...
202  ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
203 
204 
205 private:
206  void init( const AbcA::index_t iTSIndex );
207 
208  // not technically needed as the m_protoSample can return this info
209  std::size_t m_numChannels;
210  std::size_t m_numOps;
211 
212  // should we store are channel values in an ArrayProperty,
213  // or in a ScalarProperty with some Dimension > 0 and < MAX_SCALAR_CHANS
214  bool m_useArrayProp;
215 
216  AbcA::DataType m_arrayValuesDataType;
217  Alembic::Util::Dimensions m_arraySampleDimensions;
218 
219  void setChannelValues( const std::vector<double> &iVals );
220 
221 protected:
222 
224 
226 
228 
230 
232 
233  // ensure that our sample's topology is unchanging between
234  // calls to set; see usage in OXformSchema::set()
236 
238 
240 
242 
243  class Data;
244 
245  // shared and not scoped because we want this to be shared across copies
246  Util::shared_ptr< Data > m_data;
247 };
248 
249 //-*****************************************************************************
250 // SCHEMA OBJECT
251 //-*****************************************************************************
253 
254 typedef Util::shared_ptr< OXform > OXformPtr;
255 
256 } // End namespace ALEMBIC_VERSION_NS
257 
258 using namespace ALEMBIC_VERSION_NS;
259 
260 } // End namespace AbcGeom
261 } // End namespace Alembic
262 
263 #endif
bool valid() const
Valid returns whether this function set is valid.
Definition: OXform.h:195
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
AbcA::ScalarPropertyWriterPtr m_opsPWPtr
Definition: OXform.h:225
AbcA::BasePropertyWriterPtr m_valsPWPtr
Definition: OXform.h:227
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OXformSchema(CPROP_PTR iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: OXform.h:84
Alembic::Util::shared_ptr< BasePropertyWriter > BasePropertyWriterPtr
Abc::OSchema< XformSchemaInfo > super_type
Definition: OXform.h:64
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
Alembic::Util::shared_ptr< ScalarPropertyWriter > ScalarPropertyWriterPtr
Abc::OSchemaObject< OXformSchema > OXform
Definition: OXform.h:252
OXformSchema(CPROP_PTR iParent, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: OXform.h:112
#define ALEMBIC_EXPORT_CONST
Definition: Export.h:53
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:259
Util::shared_ptr< OXform > OXformPtr
Definition: OXform.h:254
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
#define ALEMBIC_EXPORT
Definition: Export.h:51
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:272
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
OXformSchema(const OXformSchema &iCopy)
Explicit copy constructor to work around MSVC bug.
Definition: OXform.h:137