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_ICurves_h
38 #define Alembic_AbcGeom_ICurves_h
39 
40 #include <Alembic/Util/Export.h>
41 #include <Alembic/AbcGeom/Foundation.h>
42 #include <Alembic/AbcGeom/Basis.h>
43 #include <Alembic/AbcGeom/CurveType.h>
44 #include <Alembic/AbcGeom/SchemaInfoDeclarations.h>
45 #include <Alembic/AbcGeom/IGeomParam.h>
46 #include <Alembic/AbcGeom/IGeomBase.h>
47 
48 namespace Alembic {
49 namespace AbcGeom {
50 namespace ALEMBIC_VERSION_NS {
51 
52 //-*****************************************************************************
53 class ALEMBIC_EXPORT ICurvesSchema : public IGeomBaseSchema<CurvesSchemaInfo>
54 {
55 public:
56     class Sample
57     {
58     public:
59         typedef Sample this_type;
60 
61         // Users don't ever create this data directly.
Sample()62         Sample() { reset(); }
63 
getPositions()64         Abc::P3fArraySamplePtr getPositions() const { return m_positions; }
65 
getNumCurves()66         std::size_t getNumCurves() const
67         {
68             if ( m_nVertices ) { return m_nVertices->size(); }
69             else { return 0; }
70         }
71 
getCurvesNumVertices()72         Abc::Int32ArraySamplePtr getCurvesNumVertices() const
73         { return m_nVertices; }
74 
getType()75         CurveType getType() const { return m_type; }
getWrap()76         CurvePeriodicity getWrap() const { return m_wrap; }
getBasis()77         BasisType getBasis() const { return m_basis; }
78 
79         // the should not be null if the curve type is kVariableOrder
getOrders()80         Abc::UcharArraySamplePtr getOrders() const { return m_orders; }
getKnots()81         Abc::FloatArraySamplePtr getKnots() const { return m_knots; }
82 
83         // if this is NULL then the weight value of the position for each
84         // point is 1
getPositionWeights()85         Abc::FloatArraySamplePtr getPositionWeights() const
86         { return m_positionWeights; }
87 
getSelfBounds()88         Abc::Box3d getSelfBounds() const { return m_selfBounds; }
getVelocities()89         Abc::V3fArraySamplePtr getVelocities() const { return m_velocities; }
90 
valid()91         bool valid() const
92         {
93             return m_positions.get() != 0 &&
94                 (m_type != kVariableOrder || m_orders);
95         }
96 
reset()97         void reset()
98         {
99             m_positions.reset();
100             m_nVertices.reset();
101             m_positionWeights.reset();
102 
103             m_type = kCubic;
104             m_wrap = kNonPeriodic;
105             m_basis = kBezierBasis;
106 
107             m_orders.reset();
108             m_knots.reset();
109 
110             m_selfBounds.makeEmpty();
111         }
112 
113         ALEMBIC_OPERATOR_BOOL( valid() );
114 
115     protected:
116         friend class ICurvesSchema;
117         Abc::P3fArraySamplePtr m_positions;
118         Abc::V3fArraySamplePtr m_velocities;
119         Abc::FloatArraySamplePtr m_positionWeights;
120 
121         Abc::Box3d m_selfBounds;
122 
123         // type, wrap, and nVertices
124         Abc::Int32ArraySamplePtr m_nVertices;
125         Abc::UcharArraySamplePtr m_orders;
126         Abc::FloatArraySamplePtr m_knots;
127 
128         CurveType m_type;
129         BasisType m_basis;
130         CurvePeriodicity m_wrap;
131     };
132 
133     //-*************************************************************************
134     // CURVE SCHEMA
135     //-*************************************************************************
136 public:
137     //! By convention we always define this_type in AbcGeom classes.
138     //! Used by unspecified-bool-type conversion below
139     typedef ICurvesSchema this_type;
140 
141     typedef ICurvesSchema::Sample sample_type;
142 
143     //-*************************************************************************
144     // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
145     //-*************************************************************************
146 
147     //! The default constructor creates an empty ICurvesSchema
148     //! ...
ICurvesSchema()149     ICurvesSchema() {}
150 
151     //! This constructor creates a new curves reader.
152     //! The first argument is the parent ICompoundProperty, from which the
153     //! error handler policy for is derived.  The second argument is the name
154     //! of the ICompoundProperty that contains this schemas properties.  The
155     //! remaining optional arguments can be used to override the
156     //! ErrorHandlerPolicy and to specify schema interpretation matching.
157     ICurvesSchema( const ICompoundProperty & iParent,
158                    const std::string &iName,
159                    const Abc::Argument &iArg0 = Abc::Argument(),
160                    const Abc::Argument &iArg1 = Abc::Argument() )
161       : IGeomBaseSchema<CurvesSchemaInfo>( iParent, iName, iArg0, iArg1 )
162     {
163         init( iArg0, iArg1 );
164     }
165 
166     //! This constructor wraps an existing ICompoundProperty as the curves
167     //! reader, and the error handler policy is derived from it.
168     //! The  remaining optional arguments can be used to override the
169     //! ErrorHandlerPolicy and to specify schema interpretation matching.
170     ICurvesSchema( const ICompoundProperty & iProp,
171                    const Abc::Argument &iArg0 = Abc::Argument(),
172                    const Abc::Argument &iArg1 = Abc::Argument() )
173       : IGeomBaseSchema<CurvesSchemaInfo>( iProp, iArg0, iArg1 )
174     {
175         init( iArg0, iArg1 );
176     }
177 
178     //! Default assignment operator used.
179 
ICurvesSchema(const ICurvesSchema & iCopy)180     ICurvesSchema( const ICurvesSchema &iCopy )
181       : IGeomBaseSchema<CurvesSchemaInfo>()
182     {
183         *this = iCopy;
184     }
185 
getNumSamples()186     size_t getNumSamples() const
187     { return m_positionsProperty.getNumSamples(); }
188 
189     //! Return the topological variance.
190     //! This indicates how the mesh may change.
191     MeshTopologyVariance getTopologyVariance() const;
192 
193     //! Ask if we're constant - no change in value amongst samples,
194     //! regardless of the time sampling.
isConstant()195     bool isConstant() const
196     { return getTopologyVariance() == kConstantTopology; }
197 
198     //! Time sampling type.
199     //!
getTimeSampling()200     AbcA::TimeSamplingPtr getTimeSampling() const
201     {
202         return m_positionsProperty.getTimeSampling();
203     }
204 
205     //-*************************************************************************
206     void get( sample_type &oSample,
207               const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
208 
209     sample_type getValue( const Abc::ISampleSelector &iSS =
210                           Abc::ISampleSelector() ) const
211     {
212         sample_type smp;
213         get( smp, iSS );
214         return smp;
215     }
216 
getVelocitiesProperty()217     Abc::IV3fArrayProperty getVelocitiesProperty() const
218     {
219         return m_velocitiesProperty;
220     }
221 
getPositionsProperty()222     Abc::IP3fArrayProperty getPositionsProperty() const
223     {
224         return m_positionsProperty;
225     }
226 
getNumVerticesProperty()227     Abc::IInt32ArrayProperty getNumVerticesProperty() const
228     {
229         return m_nVerticesProperty;
230     }
231 
232     // if this property is invalid then the weight for every point is 1
getPositionWeightsProperty()233     Abc::IFloatArrayProperty getPositionWeightsProperty() const
234     {
235         return m_positionWeightsProperty;
236     }
237 
getUVsParam()238     IV2fGeomParam getUVsParam() const
239     {
240         return m_uvsParam;
241     }
242 
getNormalsParam()243     IN3fGeomParam getNormalsParam() const
244     {
245         return m_normalsParam;
246     }
247 
getWidthsParam()248     IFloatGeomParam getWidthsParam() const
249     {
250         return m_widthsParam;
251     }
252 
getOrdersProperty()253     Abc::IUcharArrayProperty getOrdersProperty() const
254     {
255         return m_ordersProperty;
256     }
257 
getKnotsProperty()258     Abc::IFloatArrayProperty getKnotsProperty() const
259     {
260         return m_knotsProperty;
261     }
262 
263     //-*************************************************************************
264     // ABC BASE MECHANISMS
265     // These functions are used by Abc to deal with errors, rewrapping,
266     // and so on.
267     //-*************************************************************************
268 
269     //! Reset returns this function set to an empty, default
270     //! state.
reset()271     void reset()
272     {
273         m_positionsProperty.reset();
274         m_velocitiesProperty.reset();
275         m_nVerticesProperty.reset();
276 
277         m_positionWeightsProperty.reset();
278         m_ordersProperty.reset();
279         m_knotsProperty.reset();
280 
281         m_uvsParam.reset();
282         m_normalsParam.reset();
283         m_widthsParam.reset();
284 
285         m_basisAndTypeProperty.reset();
286 
287         IGeomBaseSchema<CurvesSchemaInfo>::reset();
288     }
289 
290     //! Valid returns whether this function set is
291     //! valid.
valid()292     bool valid() const
293     {
294         return ( IGeomBaseSchema<CurvesSchemaInfo>::valid() &&
295                  m_positionsProperty.valid() && m_nVerticesProperty.valid() );
296     }
297 
298     //! unspecified-bool-type operator overload.
299     //! ...
300     ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
301 
302 protected:
303     void init( const Abc::Argument &iArg0, const Abc::Argument &iArg1 );
304 
305     Abc::IP3fArrayProperty m_positionsProperty;
306     Abc::IV3fArrayProperty m_velocitiesProperty;
307     Abc::IInt32ArrayProperty m_nVerticesProperty;
308 
309     // contains type, wrap, ubasis, and vbasis.
310     Abc::IScalarProperty m_basisAndTypeProperty;
311 
312     IFloatGeomParam m_widthsParam;
313     IV2fGeomParam m_uvsParam;
314     IN3fGeomParam m_normalsParam;
315 
316     // optional
317     Abc::IFloatArrayProperty m_positionWeightsProperty;
318     Abc::IUcharArrayProperty m_ordersProperty;
319     Abc::IFloatArrayProperty m_knotsProperty;
320 };
321 
322 //-*****************************************************************************
323 typedef Abc::ISchemaObject<ICurvesSchema> ICurves;
324 
325 typedef Util::shared_ptr< ICurves > ICurvesPtr;
326 
327 } // End namespace ALEMBIC_VERSION_NS
328 
329 using namespace ALEMBIC_VERSION_NS;
330 
331 } // End namespace AbcGeom
332 } // End namespace Alembic
333 
334 #endif
335