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_IXform_h
38 #define Alembic_AbcGeom_IXform_h
39 
40 #include <Alembic/Util/Export.h>
41 #include <Alembic/AbcGeom/Foundation.h>
42 #include <Alembic/AbcGeom/SchemaInfoDeclarations.h>
43 
44 #include <Alembic/AbcGeom/XformSample.h>
45 
46 namespace Alembic {
47 namespace AbcGeom {
48 namespace ALEMBIC_VERSION_NS {
49 
50 //-*****************************************************************************
51 class ALEMBIC_EXPORT IXformSchema : public Abc::ISchema<XformSchemaInfo>
52 {
53     //-*************************************************************************
54     // XFORM SCHEMA
55     //-*************************************************************************
56 public:
57 
58     //! By convention we always define this_type in AbcGeom classes.
59     //! Used by unspecified-bool-type conversion below
60     typedef Abc::ISchema<XformSchemaInfo> super_type;
61     typedef IXformSchema this_type;
62     typedef XformSample sample_type;
63 
64     //-*************************************************************************
65     // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
66     //-*************************************************************************
67 
68     //! The default constructor creates an empty OPolyMeshSchema
69     //! ...
IXformSchema()70     IXformSchema()
71     {
72         m_useArrayProp = false;
73         m_isConstant = true;
74         m_isConstantIdentity = true;
75     }
76 
77     //! This constructor creates a new xform reader.
78     //! The first argument is the parent ICompoundProperty, from which the
79     //! error handler policy for is derived.  The second argument is the name
80     //! of the ICompoundProperty that contains this schemas properties.  The
81     //! remaining optional arguments can be used to override the
82     //! ErrorHandlerPolicy and to specify schema interpretation matching.
83     IXformSchema( const ICompoundProperty &iParent,
84                   const std::string &iName,
85                   const Abc::Argument &iArg0 = Abc::Argument(),
86                   const Abc::Argument &iArg1 = Abc::Argument() )
87       : Abc::ISchema<XformSchemaInfo>( iParent, iName, iArg0, iArg1 )
88     {
89         // Meta data and error handling are eaten up by
90         // the super type, so all that's left is SchemaInterpMatching.
91         init( iArg0, iArg1 );
92     }
93 
94     //! This constructor wraps an existing ICompoundProperty as the xform
95     //! reader, and the error handler policy is derived from it.
96     //! The  remaining optional arguments can be used to override the
97     //! ErrorHandlerPolicy and to specify schema interpretation matching.
98     IXformSchema( const ICompoundProperty &iProp,
99                   const Abc::Argument &iArg0 = Abc::Argument(),
100                   const Abc::Argument &iArg1 = Abc::Argument() )
101       : Abc::ISchema<XformSchemaInfo>( iProp, iArg0, iArg1 )
102     {
103         init( iArg0, iArg1 );
104     }
105 
106     //! explicit copy constructor to work around Windows compiler bug
IXformSchema(const IXformSchema & iCopy)107     IXformSchema( const IXformSchema &iCopy )
108         : Abc::ISchema<XformSchemaInfo>()
109     {
110         *this = iCopy;
111     }
112 
113     AbcA::TimeSamplingPtr getTimeSampling() const;
114 
isConstant()115     bool isConstant() const { return m_isConstant; }
116 
117     //! is this xform both constant and identity?
isConstantIdentity()118     bool isConstantIdentity() const { return m_isConstantIdentity; }
119 
120     size_t getNumSamples() const;
121 
122     //! fill the supplied sample reference with values
123     void get( XformSample &oSamp,
124               const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
125 
126     XformSample getValue( const Abc::ISampleSelector &iSS =
127                           Abc::ISampleSelector() ) const;
128 
getChildBoundsProperty()129     Abc::IBox3dProperty getChildBoundsProperty() const
130     {
131         return m_childBoundsProperty;
132     }
133 
134     // lightweight get to avoid constructing a sample
135     // see XformSample.h for explanation of this property
136     bool getInheritsXforms( const Abc::ISampleSelector &iSS =
137                             Abc::ISampleSelector() ) const;
138 
getNumOps()139     size_t getNumOps() const { return m_sample.getNumOps(); }
140 
141     //! Reset returns this function set to an empty, default
142     //! state.
reset()143     void reset()
144     {
145         m_childBoundsProperty.reset();
146         m_sample = XformSample();
147         m_inheritsProperty.reset();
148         m_isConstant = true;
149         m_isConstantIdentity = true;
150 
151         m_arbGeomParams.reset();
152         m_userProperties.reset();
153 
154         super_type::reset();
155     }
156 
157     //! Valid returns whether this function set is valid.
valid()158     bool valid() const
159     {
160         return ( super_type::valid() );
161     }
162 
getArbGeomParams()163     ICompoundProperty getArbGeomParams() const { return m_arbGeomParams; }
164 
getUserProperties()165     ICompoundProperty getUserProperties() const { return m_userProperties; }
166 
167     //! unspecified-bool-type operator overload.
168     //! ...
169     ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
170 
171 
172 protected:
173     Abc::IBox3dProperty m_childBoundsProperty;
174 
175     AbcA::BasePropertyReaderPtr m_valsProperty;
176 
177     Abc::IBoolProperty m_inheritsProperty;
178 
179     Abc::ICompoundProperty m_arbGeomParams;
180     Abc::ICompoundProperty m_userProperties;
181 
182     bool m_isConstant;
183 
184     bool m_isConstantIdentity;
185 
186     XformSample m_sample;
187 
188 private:
189     void init( const Abc::Argument &iArg0, const Abc::Argument &iArg1 );
190 
191     // is m_vals an ArrayProperty, or a ScalarProperty?
192     bool m_useArrayProp;
193 
194     // fills m_valVec with data
195     void getChannelValues( const AbcA::index_t iSampleIndex,
196                            XformSample & oSamp ) const;
197 };
198 
199 //-*****************************************************************************
200 // SCHEMA OBJECT
201 //-*****************************************************************************
202 typedef Abc::ISchemaObject<IXformSchema> IXform;
203 
204 typedef Util::shared_ptr< IXform > IXformPtr;
205 
206 } // End namespace ALEMBIC_VERSION_NS
207 
208 using namespace ALEMBIC_VERSION_NS;
209 
210 } // End namespace AbcGeom
211 } // End namespace Alembic
212 
213 #endif
214