Coverage Report

Created: 2025-08-29 06:10

/src/alembic/lib/Alembic/AbcGeom/INuPatch.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_INuPatch_h
38
#define Alembic_AbcGeom_INuPatch_h
39
40
#include <Alembic/Util/Export.h>
41
#include <Alembic/AbcGeom/Foundation.h>
42
#include <Alembic/AbcGeom/SchemaInfoDeclarations.h>
43
#include <Alembic/AbcGeom/IGeomParam.h>
44
#include <Alembic/AbcGeom/IGeomBase.h>
45
46
namespace Alembic {
47
namespace AbcGeom {
48
namespace ALEMBIC_VERSION_NS {
49
50
//-*****************************************************************************
51
class ALEMBIC_EXPORT INuPatchSchema : public IGeomBaseSchema<NuPatchSchemaInfo>
52
{
53
public:
54
    class Sample
55
    {
56
    public:
57
        typedef Sample this_type;
58
59
        // Users don't ever create this data directly.
60
0
        Sample() { reset(); }
61
62
0
        Abc::P3fArraySamplePtr getPositions() const { return m_positions; }
63
0
        Abc::V3fArraySamplePtr getVelocities() const { return m_velocities; }
64
0
        int32_t getNumU() const { return m_numU; }
65
0
        int32_t getNumV() const { return m_numV; }
66
0
        int32_t getUOrder() const { return m_uOrder; }
67
0
        int32_t getVOrder() const { return m_vOrder; }
68
0
        Abc::FloatArraySamplePtr getUKnot() const { return m_uKnot; }
69
0
        Abc::FloatArraySamplePtr getVKnot() const { return m_vKnot; }
70
71
        // if this is NULL then the weight value of the position for each
72
        // point is 1
73
0
        Abc::FloatArraySamplePtr getPositionWeights() const { return m_positionWeights; }
74
75
        // trim curve
76
0
        int32_t getTrimNumLoops() const { return m_trimNumLoops; }
77
0
        Abc::Int32ArraySamplePtr getTrimNumVertices() const { return m_trimNumVertices; }
78
0
        Abc::Int32ArraySamplePtr getTrimNumCurves() const { return m_trimNumCurves; }
79
0
        Abc::Int32ArraySamplePtr getTrimOrders() const { return m_trimOrder; }
80
0
        Abc::FloatArraySamplePtr getTrimKnots() const { return m_trimKnot; }
81
0
        Abc::FloatArraySamplePtr getTrimMins() const { return m_trimMin; }
82
0
        Abc::FloatArraySamplePtr getTrimMaxes() const { return m_trimMax; }
83
0
        Abc::FloatArraySamplePtr getTrimU() const { return m_trimU; }
84
0
        Abc::FloatArraySamplePtr getTrimV() const { return m_trimV; }
85
0
        Abc::FloatArraySamplePtr getTrimW() const { return m_trimW; }
86
87
0
        bool hasTrimCurve() const { return m_trimNumLoops != 0; }
88
89
        bool valid() const
90
0
        {
91
0
            return m_positions && m_numU && m_numV && m_uOrder && m_vOrder &&
92
0
                m_uKnot && m_vKnot;
93
0
        }
94
95
0
        Abc::Box3d getSelfBounds() const { return m_selfBounds; }
96
97
        void reset()
98
0
        {
99
0
            m_positions.reset();
100
0
            m_velocities.reset();
101
0
            m_numU = 0;
102
0
            m_numV = 0;
103
0
            m_uOrder = 0;
104
0
            m_vOrder = 0;
105
0
            m_uKnot.reset();
106
0
            m_vKnot.reset();
107
0
            m_positionWeights.reset();
108
0
109
0
            m_selfBounds.makeEmpty();
110
0
111
0
            // trim curve
112
0
            m_trimNumLoops = 0;
113
0
            m_trimNumCurves.reset();
114
0
            m_trimNumVertices.reset();
115
0
            m_trimOrder.reset();
116
0
            m_trimKnot.reset();
117
0
            m_trimMin.reset();
118
0
            m_trimMax.reset();
119
0
            m_trimU.reset();
120
0
            m_trimV.reset();
121
0
            m_trimW.reset();
122
0
        }
123
124
        ALEMBIC_OPERATOR_BOOL( valid() );
125
126
    protected:
127
128
        friend class INuPatchSchema;
129
130
        Abc::P3fArraySamplePtr m_positions;
131
        Abc::V3fArraySamplePtr m_velocities;
132
        int32_t m_numU;
133
        int32_t m_numV;
134
        int32_t m_uOrder;
135
        int32_t m_vOrder;
136
        Abc::FloatArraySamplePtr m_uKnot;
137
        Abc::FloatArraySamplePtr m_vKnot;
138
        Abc::FloatArraySamplePtr m_positionWeights;
139
140
        // trim curve
141
        int32_t m_trimNumLoops;
142
        Abc::Int32ArraySamplePtr m_trimNumCurves;
143
        Abc::Int32ArraySamplePtr m_trimNumVertices;
144
        Abc::Int32ArraySamplePtr m_trimOrder;
145
        Abc::FloatArraySamplePtr m_trimKnot;
146
        Abc::FloatArraySamplePtr m_trimMin;
147
        Abc::FloatArraySamplePtr m_trimMax;
148
        Abc::FloatArraySamplePtr m_trimU;
149
        Abc::FloatArraySamplePtr m_trimV;
150
        Abc::FloatArraySamplePtr m_trimW;
151
        bool m_hasTrimCurve;
152
153
        // bounds
154
        Abc::Box3d m_selfBounds;
155
156
    };
157
158
    //-*************************************************************************
159
    // NuPatch Schema
160
    //-*************************************************************************
161
public:
162
    //! By convention we always define this_type in AbcGeom classes.
163
    //! Used by unspecified-bool-type conversion below
164
    typedef INuPatchSchema this_type;
165
    typedef Sample sample_type;
166
167
    //-*************************************************************************
168
    // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
169
    //-*************************************************************************
170
171
    //! The default constructor
172
    INuPatchSchema()
173
0
    {
174
0
        m_hasTrimCurve = false;
175
0
    }
176
177
    //! This constructor creates a new nurbs patch reader.
178
    //! The first argument is the parent ICompoundProperty, from which the
179
    //! error handler policy for is derived.  The second argument is the name
180
    //! of the ICompoundProperty that contains this schemas properties.  The
181
    //! remaining optional arguments can be used to override the
182
    //! ErrorHandlerPolicy and to specify schema interpretation matching.
183
    INuPatchSchema( const ICompoundProperty &iParent,
184
                    const std::string &iName,
185
                    const Abc::Argument &iArg0 = Abc::Argument(),
186
                    const Abc::Argument &iArg1 = Abc::Argument() )
187
      : IGeomBaseSchema<NuPatchSchemaInfo>( iParent, iName, iArg0, iArg1 )
188
0
    {
189
0
        init( iArg0, iArg1 );
190
0
    }
191
192
    //! This constructor wraps an existing ICompoundProperty as the nurbs
193
    //! reader, and the error handler policy is derived from it.
194
    //! The  remaining optional arguments can be used to override the
195
    //! ErrorHandlerPolicy and to specify schema interpretation matching.
196
    explicit INuPatchSchema( const ICompoundProperty &iProp,
197
                             const Abc::Argument &iArg0 = Abc::Argument(),
198
                             const Abc::Argument &iArg1 = Abc::Argument() )
199
200
      : IGeomBaseSchema<NuPatchSchemaInfo>( iProp, iArg0, iArg1 )
201
0
    {
202
0
        init( iArg0, iArg1 );
203
0
    }
204
205
    //! Return the number of samples contained in the property.
206
    //! This can be any number, including zero.
207
    //! This returns the number of samples that were written, independently
208
    //! of whether or not they were constant.
209
    size_t getNumSamples() const
210
0
    { return m_positionsProperty.getNumSamples(); }
211
212
    //! Return the topological variance.
213
    //! This indicates how the mesh may change.
214
    MeshTopologyVariance getTopologyVariance() const;
215
216
    //! Ask if we're constant - no change in value amongst samples,
217
    //! regardless of the time sampling.
218
0
    bool isConstant() const { return getTopologyVariance() == kConstantTopology; }
219
220
    //! Time information.
221
    AbcA::TimeSamplingPtr getTimeSampling() const
222
0
    {
223
0
        return m_positionsProperty.getTimeSampling();
224
0
    }
225
226
    void get( sample_type &oSample,
227
              const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
228
229
    Sample getValue( const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const
230
0
    {
231
0
        Sample smp;
232
0
        get( smp, iSS );
233
0
        return smp;
234
0
    }
235
236
0
    Abc::IP3fArrayProperty getPositionsProperty() const { return m_positionsProperty; }
237
0
    Abc::IFloatArrayProperty getUKnotsProperty() const { return m_uKnotProperty; }
238
0
    Abc::IFloatArrayProperty getVKnotsProperty() const { return m_vKnotProperty; }
239
240
    Abc::IV3fArrayProperty getVelocitiesProperty() const
241
0
    {
242
0
        return m_velocitiesProperty;
243
0
    }
244
245
    // if this property is invalid then the weight for every point is 1
246
    Abc::IFloatArrayProperty getPositionWeightsProperty() const
247
0
    {
248
0
        return m_positionWeightsProperty;
249
0
    }
250
251
    IN3fGeomParam getNormalsParam() const
252
0
    {
253
0
        return m_normalsParam;
254
0
    }
255
256
    IV2fGeomParam getUVsParam() const
257
0
    {
258
0
        return m_uvsParam;
259
0
    }
260
261
262
0
    bool hasTrimCurve() const { return m_hasTrimCurve; }
263
    bool trimCurveTopologyIsHomogenous() const;
264
    bool trimCurveTopologyIsConstant() const;
265
266
267
    //-*************************************************************************
268
    // ABC BASE MECHANISMS
269
    // These functions are used by Abc to deal with errors, rewrapping,
270
    // and so on.
271
    //-*************************************************************************
272
273
    //! Reset returns this function set to an empty, default
274
    //! state.
275
    void reset()
276
0
    {
277
0
        m_positionsProperty.reset();
278
0
        m_velocitiesProperty.reset();
279
0
        m_numUProperty.reset();
280
0
        m_numVProperty.reset();
281
0
        m_uOrderProperty.reset();
282
0
        m_vOrderProperty.reset();
283
0
        m_uKnotProperty.reset();
284
0
        m_vKnotProperty.reset();
285
0
        m_positionWeightsProperty.reset();
286
0
287
0
        m_normalsParam.reset();
288
0
        m_uvsParam.reset();
289
0
290
0
        // reset trim curve attributes
291
0
        m_trimNumLoopsProperty.reset();
292
0
        m_trimNumCurvesProperty.reset();
293
0
        m_trimNumVerticesProperty.reset();
294
0
        m_trimOrderProperty.reset();
295
0
        m_trimKnotProperty.reset();
296
0
        m_trimMinProperty.reset();
297
0
        m_trimMaxProperty.reset();
298
0
        m_trimUProperty.reset();
299
0
        m_trimVProperty.reset();
300
0
        m_trimWProperty.reset();
301
0
302
0
        IGeomBaseSchema<NuPatchSchemaInfo>::reset();
303
0
    }
304
305
    //! Valid returns whether this function set is
306
    //! valid.
307
    bool valid() const
308
0
    {
309
0
        return ( IGeomBaseSchema<NuPatchSchemaInfo>::valid() &&
310
0
                 m_positionsProperty.valid() &&
311
0
                 m_numUProperty.valid() &&
312
0
                 m_numVProperty.valid() &&
313
0
                 m_uOrderProperty.valid() &&
314
0
                 m_vOrderProperty.valid() &&
315
0
                 m_uKnotProperty.valid() &&
316
0
                 m_vKnotProperty.valid() );
317
0
    }
318
319
    //! unspecified-bool-type operator overload.
320
    //! ...
321
    ALEMBIC_OVERRIDE_OPERATOR_BOOL( INuPatchSchema::valid() );
322
323
protected:
324
    bool hasTrimProps() const;
325
326
protected:
327
    void init( const Abc::Argument &iArg0,
328
               const Abc::Argument &iArg1 );
329
330
    // required properties
331
    Abc::IP3fArrayProperty m_positionsProperty;
332
    Abc::IInt32Property m_numUProperty;
333
    Abc::IInt32Property m_numVProperty;
334
    Abc::IInt32Property m_uOrderProperty;
335
    Abc::IInt32Property m_vOrderProperty;
336
    Abc::IFloatArrayProperty m_uKnotProperty;
337
    Abc::IFloatArrayProperty m_vKnotProperty;
338
339
    // optional
340
    Abc::IV3fArrayProperty m_velocitiesProperty;
341
    Abc::IFloatArrayProperty m_positionWeightsProperty;
342
    IN3fGeomParam m_normalsParam;
343
    IV2fGeomParam m_uvsParam;
344
345
    // optional trim curve properties
346
    Abc::IInt32Property m_trimNumLoopsProperty;
347
    Abc::IInt32ArrayProperty m_trimNumVerticesProperty;
348
    Abc::IInt32ArrayProperty m_trimNumCurvesProperty;
349
    Abc::IInt32ArrayProperty m_trimOrderProperty;
350
    Abc::IFloatArrayProperty m_trimKnotProperty;
351
    Abc::IFloatArrayProperty m_trimMinProperty;
352
    Abc::IFloatArrayProperty m_trimMaxProperty;
353
    Abc::IFloatArrayProperty m_trimUProperty;
354
    Abc::IFloatArrayProperty m_trimVProperty;
355
    Abc::IFloatArrayProperty m_trimWProperty;
356
357
    bool m_hasTrimCurve;
358
};
359
360
//-*****************************************************************************
361
typedef Abc::ISchemaObject<INuPatchSchema> INuPatch;
362
363
typedef Util::shared_ptr< INuPatch > INuPatchPtr;
364
365
} // End namespace ALEMBIC_VERSION_NS
366
367
using namespace ALEMBIC_VERSION_NS;
368
369
} // End namespace AbcGeom
370
} // End namespace Alembic
371
372
#endif