Coverage Report

Created: 2025-08-25 06:16

/src/alembic/lib/Alembic/AbcGeom/ICurves.h
Line
Count
Source (jump to first uncovered line)
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.
62
0
        Sample() { reset(); }
63
64
0
        Abc::P3fArraySamplePtr getPositions() const { return m_positions; }
65
66
        std::size_t getNumCurves() const
67
0
        {
68
0
            if ( m_nVertices ) { return m_nVertices->size(); }
69
0
            else { return 0; }
70
0
        }
71
72
        Abc::Int32ArraySamplePtr getCurvesNumVertices() const
73
0
        { return m_nVertices; }
74
75
0
        CurveType getType() const { return m_type; }
76
0
        CurvePeriodicity getWrap() const { return m_wrap; }
77
0
        BasisType getBasis() const { return m_basis; }
78
79
        // the should not be null if the curve type is kVariableOrder
80
0
        Abc::UcharArraySamplePtr getOrders() const { return m_orders; }
81
0
        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
85
        Abc::FloatArraySamplePtr getPositionWeights() const
86
0
        { return m_positionWeights; }
87
88
0
        Abc::Box3d getSelfBounds() const { return m_selfBounds; }
89
0
        Abc::V3fArraySamplePtr getVelocities() const { return m_velocities; }
90
91
        bool valid() const
92
0
        {
93
0
            return m_positions.get() != 0 &&
94
0
                (m_type != kVariableOrder || m_orders);
95
0
        }
96
97
        void reset()
98
0
        {
99
0
            m_positions.reset();
100
0
            m_nVertices.reset();
101
0
            m_positionWeights.reset();
102
0
103
0
            m_type = kCubic;
104
0
            m_wrap = kNonPeriodic;
105
0
            m_basis = kBezierBasis;
106
0
107
0
            m_orders.reset();
108
0
            m_knots.reset();
109
0
110
0
            m_selfBounds.makeEmpty();
111
0
        }
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
    //! ...
149
0
    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
0
      : IGeomBaseSchema<CurvesSchemaInfo>( iParent, iName, iArg0, iArg1 )
162
0
    {
163
0
        init( iArg0, iArg1 );
164
0
    }
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
0
    {
175
0
        init( iArg0, iArg1 );
176
0
    }
177
178
    //! Default assignment and copy operator used.
179
180
    size_t getNumSamples() const
181
0
    { return m_positionsProperty.getNumSamples(); }
182
183
    //! Return the topological variance.
184
    //! This indicates how the mesh may change.
185
    MeshTopologyVariance getTopologyVariance() const;
186
187
    //! Ask if we're constant - no change in value amongst samples,
188
    //! regardless of the time sampling.
189
    bool isConstant() const
190
0
    { return getTopologyVariance() == kConstantTopology; }
191
192
    //! Time sampling type.
193
    //!
194
    AbcA::TimeSamplingPtr getTimeSampling() const
195
0
    {
196
0
        return m_positionsProperty.getTimeSampling();
197
0
    }
198
199
    //-*************************************************************************
200
    void get( sample_type &oSample,
201
              const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
202
203
    sample_type getValue( const Abc::ISampleSelector &iSS =
204
                          Abc::ISampleSelector() ) const
205
0
    {
206
0
        sample_type smp;
207
0
        get( smp, iSS );
208
0
        return smp;
209
0
    }
210
211
    Abc::IV3fArrayProperty getVelocitiesProperty() const
212
0
    {
213
0
        return m_velocitiesProperty;
214
0
    }
215
216
    Abc::IP3fArrayProperty getPositionsProperty() const
217
0
    {
218
0
        return m_positionsProperty;
219
0
    }
220
221
    Abc::IInt32ArrayProperty getNumVerticesProperty() const
222
0
    {
223
0
        return m_nVerticesProperty;
224
0
    }
225
226
    // if this property is invalid then the weight for every point is 1
227
    Abc::IFloatArrayProperty getPositionWeightsProperty() const
228
0
    {
229
0
        return m_positionWeightsProperty;
230
0
    }
231
232
    IV2fGeomParam getUVsParam() const
233
0
    {
234
0
        return m_uvsParam;
235
0
    }
236
237
    IN3fGeomParam getNormalsParam() const
238
0
    {
239
0
        return m_normalsParam;
240
0
    }
241
242
    IFloatGeomParam getWidthsParam() const
243
0
    {
244
0
        return m_widthsParam;
245
0
    }
246
247
    Abc::IUcharArrayProperty getOrdersProperty() const
248
0
    {
249
0
        return m_ordersProperty;
250
0
    }
251
252
    Abc::IFloatArrayProperty getKnotsProperty() const
253
0
    {
254
0
        return m_knotsProperty;
255
0
    }
256
257
    //-*************************************************************************
258
    // ABC BASE MECHANISMS
259
    // These functions are used by Abc to deal with errors, rewrapping,
260
    // and so on.
261
    //-*************************************************************************
262
263
    //! Reset returns this function set to an empty, default
264
    //! state.
265
    void reset()
266
0
    {
267
0
        m_positionsProperty.reset();
268
0
        m_velocitiesProperty.reset();
269
0
        m_nVerticesProperty.reset();
270
271
0
        m_positionWeightsProperty.reset();
272
0
        m_ordersProperty.reset();
273
0
        m_knotsProperty.reset();
274
275
0
        m_uvsParam.reset();
276
0
        m_normalsParam.reset();
277
0
        m_widthsParam.reset();
278
279
0
        m_basisAndTypeProperty.reset();
280
281
0
        IGeomBaseSchema<CurvesSchemaInfo>::reset();
282
0
    }
283
284
    //! Valid returns whether this function set is
285
    //! valid.
286
    bool valid() const
287
0
    {
288
0
        return ( IGeomBaseSchema<CurvesSchemaInfo>::valid() &&
289
0
                 m_positionsProperty.valid() && m_nVerticesProperty.valid() );
290
0
    }
291
292
    //! unspecified-bool-type operator overload.
293
    //! ...
294
    ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
295
296
protected:
297
    void init( const Abc::Argument &iArg0, const Abc::Argument &iArg1 );
298
299
    Abc::IP3fArrayProperty m_positionsProperty;
300
    Abc::IV3fArrayProperty m_velocitiesProperty;
301
    Abc::IInt32ArrayProperty m_nVerticesProperty;
302
303
    // contains type, wrap, ubasis, and vbasis.
304
    Abc::IScalarProperty m_basisAndTypeProperty;
305
306
    IFloatGeomParam m_widthsParam;
307
    IV2fGeomParam m_uvsParam;
308
    IN3fGeomParam m_normalsParam;
309
310
    // optional
311
    Abc::IFloatArrayProperty m_positionWeightsProperty;
312
    Abc::IUcharArrayProperty m_ordersProperty;
313
    Abc::IFloatArrayProperty m_knotsProperty;
314
};
315
316
//-*****************************************************************************
317
typedef Abc::ISchemaObject<ICurvesSchema> ICurves;
318
319
typedef Util::shared_ptr< ICurves > ICurvesPtr;
320
321
} // End namespace ALEMBIC_VERSION_NS
322
323
using namespace ALEMBIC_VERSION_NS;
324
325
} // End namespace AbcGeom
326
} // End namespace Alembic
327
328
#endif