Coverage Report

Created: 2023-09-25 06:10

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