Coverage Report

Created: 2025-08-25 06:16

/src/alembic/lib/Alembic/AbcGeom/ONuPatch.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_ONuPatch_h
38
#define Alembic_AbcGeom_ONuPatch_h
39
40
#include <Alembic/Util/Export.h>
41
#include <Alembic/AbcGeom/Foundation.h>
42
#include <Alembic/AbcGeom/Basis.h>
43
#include <Alembic/AbcGeom/SchemaInfoDeclarations.h>
44
#include <Alembic/AbcGeom/OGeomParam.h>
45
#include <Alembic/AbcGeom/OGeomBase.h>
46
47
namespace Alembic {
48
namespace AbcGeom {
49
namespace ALEMBIC_VERSION_NS {
50
51
//-*****************************************************************************
52
// for default "null" values for the int scalar properties (INT_MIN/4)
53
static const int32_t ABC_GEOM_NUPATCH_NULL_INT_VALUE( -536870912 );
54
55
//-*****************************************************************************
56
class ALEMBIC_EXPORT ONuPatchSchema : public OGeomBaseSchema<NuPatchSchemaInfo>
57
{
58
public:
59
    //-*************************************************************************
60
    // NuPatch SCHEMA SAMPLE TYPE
61
    //-*************************************************************************
62
    class Sample
63
    {
64
    public:
65
        //! Creates a default sample with no data in it.
66
        //! ...
67
0
        Sample() { reset(); }
68
69
        Sample(
70
                const Abc::P3fArraySample &iPos,
71
                const int32_t &iNumU,
72
                const int32_t &iNumV,
73
                const int32_t &iUOrder,
74
                const int32_t &iVOrder,
75
                const Abc::FloatArraySample &iUKnot,
76
                const Abc::FloatArraySample &iVKnot,
77
                const ON3fGeomParam::Sample &iNormals = ON3fGeomParam::Sample(),
78
                const OV2fGeomParam::Sample &iUVs = OV2fGeomParam::Sample(),
79
                const Abc::FloatArraySample & iPosWeight = Abc::FloatArraySample()
80
              ): m_positions( iPos )
81
               , m_numU( iNumU )
82
               , m_numV( iNumV )
83
               , m_uOrder( iUOrder )
84
               , m_vOrder( iVOrder )
85
               , m_uKnot( iUKnot )
86
               , m_vKnot( iVKnot )
87
               , m_positionWeights( iPosWeight )
88
               , m_normals( iNormals )
89
               , m_uvs( iUVs )
90
               , m_trimNumLoops( ABC_GEOM_NUPATCH_NULL_INT_VALUE )
91
               , m_trimNumVertices( Abc::Int32ArraySample() )
92
               , m_trimOrder( Abc::Int32ArraySample() )
93
               , m_trimKnot( Abc::FloatArraySample() )
94
               , m_trimMin( Abc::FloatArraySample() )
95
               , m_trimMax( Abc::FloatArraySample() )
96
               , m_trimU( Abc::FloatArraySample() )
97
               , m_trimV( Abc::FloatArraySample() )
98
               , m_trimW( Abc::FloatArraySample() )
99
               , m_hasTrimCurve( false )
100
0
            {}
101
102
        // positions
103
0
        const Abc::P3fArraySample &getPositions() const { return m_positions; }
104
        void setPositions( const Abc::P3fArraySample &iSmp )
105
0
        { m_positions = iSmp; }
106
107
        // position weights, if it isn't set, it's 1 for every point
108
        const Abc::FloatArraySample &getPositionWeights() const
109
0
        { return m_positionWeights; }
110
        void setPositionWeights( const Abc::FloatArraySample &iSmp )
111
0
        { m_positionWeights = iSmp; }
112
113
        // nu
114
0
        int32_t getNu() const { return m_numU; }
115
        void setNu( const int32_t iNu )
116
0
        { m_numU = iNu; }
117
118
        // nv
119
0
        int32_t getNv() const { return m_numV; }
120
        void setNv( const int32_t iNv )
121
0
        { m_numV = iNv; }
122
123
        // uOrder
124
0
        int32_t getUOrder() const { return m_uOrder; }
125
        void setUOrder( const int32_t iUOrder )
126
0
        { m_uOrder = iUOrder; }
127
128
        // vOrder
129
0
        int32_t getVOrder() const { return m_vOrder; }
130
        void setVOrder( const int32_t iVOrder )
131
0
        { m_vOrder = iVOrder; }
132
133
        // uKnot
134
0
        const Abc::FloatArraySample &getUKnot() const { return m_uKnot; }
135
        void setUKnot( const Abc::FloatArraySample &iUKnot )
136
0
        { m_uKnot = iUKnot; }
137
138
        // vKnot
139
0
        const Abc::FloatArraySample &getVKnot() const { return m_vKnot; }
140
        void setVKnot( const Abc::FloatArraySample &iVKnot )
141
0
        { m_vKnot = iVKnot; }
142
143
        // uvs
144
0
        const OV2fGeomParam::Sample &getUVs() const { return m_uvs; }
145
        void setUVs( const OV2fGeomParam::Sample &iUVs )
146
0
        { m_uvs = iUVs; }
147
148
        // normals
149
0
        const ON3fGeomParam::Sample &getNormals() const { return m_normals; }
150
        void setNormals( const ON3fGeomParam::Sample &iNormals )
151
0
        { m_normals = iNormals; }
152
153
        // bounds
154
0
        const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
155
        void setSelfBounds( const Abc::Box3d &iBnds )
156
0
        { m_selfBounds = iBnds; }
157
158
        // velocities accessor
159
0
        const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
160
        void setVelocities( const Abc::V3fArraySample &iVelocities )
161
0
        { m_velocities = iVelocities; }
162
163
        // trim curves
164
        void setTrimCurve( const int32_t i_trim_nLoops,
165
                           const Abc::Int32ArraySample &i_trim_nCurves,
166
                           const Abc::Int32ArraySample &i_trim_n,
167
                           const Abc::Int32ArraySample &i_trim_order,
168
                           const Abc::FloatArraySample &i_trim_knot,
169
                           const Abc::FloatArraySample &i_trim_min,
170
                           const Abc::FloatArraySample &i_trim_max,
171
                           const Abc::FloatArraySample &i_trim_u,
172
                           const Abc::FloatArraySample &i_trim_v,
173
                           const Abc::FloatArraySample &i_trim_w )
174
0
        {
175
0
            m_trimNumLoops = i_trim_nLoops;
176
0
            m_trimNumCurves = i_trim_nCurves;
177
0
            m_trimNumVertices = i_trim_n;
178
0
            m_trimOrder = i_trim_order;
179
0
            m_trimKnot = i_trim_knot;
180
0
            m_trimMin = i_trim_min;
181
0
            m_trimMax = i_trim_max;
182
0
            m_trimU = i_trim_u;
183
0
            m_trimV = i_trim_v;
184
0
            m_trimW = i_trim_w;
185
0
186
0
            m_hasTrimCurve = true;
187
0
        }
188
189
0
        int32_t getTrimNumLoops() const { return m_trimNumLoops; }
190
        const Abc::Int32ArraySample &getTrimNumCurves() const
191
0
        { return m_trimNumCurves; }
192
        const Abc::Int32ArraySample &getTrimNumVertices() const
193
0
        { return m_trimNumVertices; }
194
        const Abc::Int32ArraySample &getTrimOrder() const
195
0
        { return m_trimOrder; }
196
0
        const Abc::FloatArraySample &getTrimKnot() const { return m_trimKnot; }
197
0
        const Abc::FloatArraySample &getTrimMin() const { return m_trimMin; }
198
0
        const Abc::FloatArraySample &getTrimMax() const { return m_trimMax; }
199
0
        const Abc::FloatArraySample &getTrimU() const { return m_trimU; }
200
0
        const Abc::FloatArraySample &getTrimV() const { return m_trimV; }
201
0
        const Abc::FloatArraySample &getTrimW() const { return m_trimW; }
202
203
        bool hasTrimCurve() const
204
0
        {
205
0
            return m_hasTrimCurve;
206
0
        }
207
208
        void reset()
209
0
        {
210
0
            m_positions.reset();
211
0
            m_velocities.reset();
212
0
            m_numU = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
213
0
            m_numV = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
214
0
            m_uOrder = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
215
0
            m_vOrder = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
216
0
            m_uKnot.reset();
217
0
            m_vKnot.reset();
218
0
            m_positionWeights.reset();
219
0
            m_normals.reset();
220
0
            m_uvs.reset();
221
0
            m_selfBounds.makeEmpty();
222
0
223
0
            // reset trim curves
224
0
            m_trimNumLoops = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
225
0
            m_trimNumCurves.reset();
226
0
            m_trimNumVertices.reset();
227
0
            m_trimOrder.reset();
228
0
            m_trimKnot.reset();
229
0
            m_trimMin.reset();
230
0
            m_trimMax.reset();
231
0
            m_trimU.reset();
232
0
            m_trimV.reset();
233
0
            m_trimW.reset();
234
0
            m_hasTrimCurve = false;
235
0
        }
236
237
        bool isPartialSample() const
238
0
        {
239
0
            if( !m_positions.getData() )
240
0
            {
241
0
                if( m_uvs.getVals() || m_normals.getVals() || m_velocities.getData() )
242
0
                {
243
0
                    return true;
244
0
                }
245
0
            }
246
0
247
0
            return false;
248
0
        }
249
250
        bool hasKnotSampleData() const
251
0
        {
252
0
            if( (m_numU != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
253
0
                (m_numV != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
254
0
                (m_uOrder != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
255
0
                (m_vOrder != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
256
0
                 m_uKnot || m_vKnot)
257
0
                 return true;
258
0
            else
259
0
                return false;
260
0
        }
261
262
    protected:
263
264
        // required properties
265
        Abc::P3fArraySample m_positions;
266
        Abc::V3fArraySample m_velocities;
267
        int32_t m_numU;
268
        int32_t m_numV;
269
        int32_t m_uOrder;
270
        int32_t m_vOrder;
271
        Abc::FloatArraySample m_uKnot;
272
        Abc::FloatArraySample m_vKnot;
273
274
        // optional properties
275
        Abc::FloatArraySample m_positionWeights;
276
        ON3fGeomParam::Sample m_normals;
277
        OV2fGeomParam::Sample m_uvs;
278
279
        // optional trim curves
280
        int32_t m_trimNumLoops;
281
        Abc::Int32ArraySample m_trimNumCurves;
282
        Abc::Int32ArraySample m_trimNumVertices;
283
        Abc::Int32ArraySample m_trimOrder;
284
        Abc::FloatArraySample m_trimKnot;
285
        Abc::FloatArraySample m_trimMin;
286
        Abc::FloatArraySample m_trimMax;
287
        Abc::FloatArraySample m_trimU;
288
        Abc::FloatArraySample m_trimV;
289
        Abc::FloatArraySample m_trimW;
290
        bool m_hasTrimCurve;
291
292
        // bounds
293
        Abc::Box3d m_selfBounds;
294
    };
295
296
    //-*************************************************************************
297
    // NuPatch SCHEMA
298
    //-*************************************************************************
299
300
public:
301
302
    //! By convention we always define this_type in AbcGeom classes.
303
    //! Used by unspecified-bool-type conversion below
304
    typedef ONuPatchSchema this_type;
305
    typedef ONuPatchSchema::Sample sample_type;
306
307
    //-*************************************************************************
308
    // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
309
    //-*************************************************************************
310
311
    //! The default constructor creates an empty ONuPatchSchema
312
    //! ...
313
    ONuPatchSchema()
314
0
    {
315
0
        m_selectiveExport = false;
316
0
        m_numSamples = 0;
317
0
        m_timeSamplingIndex = 0;
318
0
    }
319
320
    //! This constructor creates a new poly mesh writer.
321
    //! The first argument is an CompoundPropertyWriterPtr to use as a parent.
322
    //! The next is the name to give the schema which is usually the default
323
    //! name given by OFaceSet (.geom)   The remaining optional arguments
324
    //! can be used to override the ErrorHandlerPolicy, to specify
325
    //! MetaData, specify sparse sampling and to set TimeSampling.
326
    ONuPatchSchema( AbcA::CompoundPropertyWriterPtr iParent,
327
                     const std::string &iName,
328
                     const Abc::Argument &iArg0 = Abc::Argument(),
329
                     const Abc::Argument &iArg1 = Abc::Argument(),
330
                     const Abc::Argument &iArg2 = Abc::Argument(),
331
                     const Abc::Argument &iArg3 = Abc::Argument() );
332
333
    //! This constructor creates a new poly mesh writer.
334
    //! The first argument is an OCompundProperty to use as a parent, and from
335
    //! which the ErrorHandlerPolicy is derived.  The next is the name to give
336
    //! the schema which is usually the default name given by OFaceSet (.geom)
337
    //! The remaining optional arguments can be used to specify MetaData,
338
    //! specify sparse sampling and to set TimeSampling.
339
    ONuPatchSchema( Abc::OCompoundProperty iParent,
340
                     const std::string &iName,
341
                     const Abc::Argument &iArg0 = Abc::Argument(),
342
                     const Abc::Argument &iArg1 = Abc::Argument(),
343
                     const Abc::Argument &iArg2 = Abc::Argument() );
344
345
    //-*************************************************************************
346
    // SCHEMA STUFF
347
    //-*************************************************************************
348
349
    //! Return the time sampling type, which is stored on each of the
350
    //! sub properties.
351
    AbcA::TimeSamplingPtr getTimeSampling() const
352
0
    {
353
0
        if( m_positionsProperty.valid() )
354
0
        {
355
0
            return m_positionsProperty.getTimeSampling();
356
0
        }
357
0
        else
358
0
        {
359
0
            return getObject().getArchive().getTimeSampling( 0 );
360
0
        }
361
0
    }
362
363
    void setTimeSampling( uint32_t iIndex );
364
    void setTimeSampling( AbcA::TimeSamplingPtr iTime );
365
366
    //-*************************************************************************
367
    // SAMPLE STUFF
368
    //-*************************************************************************
369
370
    //! Get number of samples written so far.
371
    //! ...
372
    size_t getNumSamples() const
373
0
    {
374
0
        return m_numSamples;
375
0
    }
376
377
    //! Set a sample!
378
    void set( const sample_type &iSamp );
379
380
    //! Set from previous sample. Will apply to each of positions,
381
    //! indices, and counts.
382
    void setFromPrevious();
383
384
    //-*************************************************************************
385
    // ABC BASE MECHANISMS
386
    // These functions are used by Abc to deal with errors, validity,
387
    // and so on.
388
    //-*************************************************************************
389
390
    //! Reset returns this function set to an empty, default
391
    //! state.
392
    void reset()
393
0
    {
394
0
        m_positionsProperty.reset();
395
0
        m_positionWeightsProperty.reset();
396
0
        m_velocitiesProperty.reset();
397
0
        m_numUProperty.reset();
398
0
        m_numVProperty.reset();
399
0
        m_uOrderProperty.reset();
400
0
        m_vOrderProperty.reset();
401
0
        m_uKnotProperty.reset();
402
0
        m_vKnotProperty.reset();
403
0
404
0
        m_normalsParam.reset();
405
0
        m_uvsParam.reset();
406
0
407
0
        // reset trim curve attributes
408
0
        m_trimNumLoopsProperty.reset();
409
0
        m_trimNumVerticesProperty.reset();
410
0
        m_trimOrderProperty.reset();
411
0
        m_trimKnotProperty.reset();
412
0
        m_trimMinProperty.reset();
413
0
        m_trimMaxProperty.reset();
414
0
        m_trimUProperty.reset();
415
0
        m_trimVProperty.reset();
416
0
        m_trimWProperty.reset();
417
0
418
0
        OGeomBaseSchema<NuPatchSchemaInfo>::reset();
419
0
    }
420
421
    //! Valid returns whether this function set is
422
    //! valid.
423
    bool valid() const
424
0
    {
425
0
        return ( ( OGeomBaseSchema<NuPatchSchemaInfo>::valid() &&
426
0
                     m_positionsProperty.valid() ) ||
427
0
                 m_selectiveExport );
428
0
    }
429
430
    //! unspecified-bool-type operator overload.
431
    //! ...
432
    ALEMBIC_OVERRIDE_OPERATOR_BOOL( ONuPatchSchema::valid() );
433
434
protected:
435
    void init( const AbcA::index_t iTsIdx, bool isSparse );
436
437
    //! Set only some property data. Does not need to be a valid schema sample
438
    //! This is to be used when created a file which will be layered in to
439
    //! another file.
440
    void selectiveSet( const Sample &iSamp );
441
442
    // Write out only some properties (UVs, normals).
443
    // This is to export data to layer into another file later.
444
    bool m_selectiveExport;
445
446
    // Number of times OPolyMeshSchema::set() has been called
447
    size_t m_numSamples;
448
449
    AbcA::index_t m_timeSamplingIndex;
450
451
    void createPositionProperties();
452
    void createKnotProperties();
453
    void createVelocityProperty();
454
    void createUVsProperty( const Sample &iSamp );
455
    void createNormalsProperty( const Sample &iSamp );
456
    void createPositionWeightsProperty();
457
    void createTrimPropreties();
458
459
460
    // point data
461
    Abc::OP3fArrayProperty m_positionsProperty;
462
463
    // required properties
464
    Abc::OInt32Property m_numUProperty;
465
    Abc::OInt32Property m_numVProperty;
466
    Abc::OInt32Property m_uOrderProperty;
467
    Abc::OInt32Property m_vOrderProperty;
468
    Abc::OFloatArrayProperty m_uKnotProperty;
469
    Abc::OFloatArrayProperty m_vKnotProperty;
470
471
    // optional properties
472
    Abc::OFloatArrayProperty m_positionWeightsProperty;
473
    ON3fGeomParam m_normalsParam;
474
    OV2fGeomParam m_uvsParam;
475
    Abc::OV3fArrayProperty m_velocitiesProperty;
476
477
    // optional trim curves
478
    Abc::OInt32Property m_trimNumLoopsProperty;
479
    Abc::OInt32ArrayProperty m_trimNumCurvesProperty;
480
    Abc::OInt32ArrayProperty m_trimNumVerticesProperty;
481
    Abc::OInt32ArrayProperty m_trimOrderProperty;
482
    Abc::OFloatArrayProperty m_trimKnotProperty;
483
    Abc::OFloatArrayProperty m_trimMinProperty;
484
    Abc::OFloatArrayProperty m_trimMaxProperty;
485
    Abc::OFloatArrayProperty m_trimUProperty;
486
    Abc::OFloatArrayProperty m_trimVProperty;
487
    Abc::OFloatArrayProperty m_trimWProperty;
488
489
};
490
491
//-*****************************************************************************
492
// SCHEMA OBJECT
493
//-*****************************************************************************
494
typedef Abc::OSchemaObject<ONuPatchSchema> ONuPatch;
495
496
typedef Util::shared_ptr< ONuPatch > ONuPatchPtr;
497
498
} // End namespace ALEMBIC_VERSION_NS
499
500
using namespace ALEMBIC_VERSION_NS;
501
502
} // End namespace AbcGeom
503
} // End namespace Alembic
504
505
#endif