Coverage Report

Created: 2024-09-08 06:41

/src/alembic/lib/Alembic/AbcGeom/ISubD.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_ISubD_h
38
#define Alembic_AbcGeom_ISubD_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/IFaceSet.h>
45
#include <Alembic/AbcGeom/IGeomBase.h>
46
47
namespace Alembic {
48
namespace AbcGeom {
49
namespace ALEMBIC_VERSION_NS {
50
51
//-*****************************************************************************
52
class ALEMBIC_EXPORT ISubDSchema : public IGeomBaseSchema<SubDSchemaInfo>
53
{
54
public:
55
    //-*************************************************************************
56
    // SUBD SCHEMA SAMPLE TYPE
57
    //-*************************************************************************
58
    class Sample
59
    {
60
    public:
61
        typedef Sample this_type;
62
63
        //! Users never create this data directly
64
0
        Sample() { reset(); }
65
66
        // main stuff
67
0
        Abc::P3fArraySamplePtr getPositions() const { return m_positions; }
68
0
        Abc::Int32ArraySamplePtr getFaceIndices() const { return m_faceIndices; }
69
0
        Abc::Int32ArraySamplePtr getFaceCounts() const { return m_faceCounts; }
70
71
        // misc subd stuff
72
        int32_t getFaceVaryingInterpolateBoundary() const
73
0
        { return m_faceVaryingInterpolateBoundary; }
74
75
        int32_t getFaceVaryingPropagateCorners() const
76
0
        { return m_faceVaryingPropagateCorners; }
77
78
        int32_t getInterpolateBoundary() const
79
0
        { return m_interpolateBoundary; }
80
81
        // creases
82
        Abc::Int32ArraySamplePtr getCreaseIndices() const
83
0
        { return m_creaseIndices; }
84
85
        Abc::Int32ArraySamplePtr getCreaseLengths() const
86
0
        { return m_creaseLengths; }
87
88
        Abc::FloatArraySamplePtr getCreaseSharpnesses() const
89
0
        { return m_creaseSharpnesses; }
90
91
        // corners
92
        Abc::Int32ArraySamplePtr getCornerIndices() const
93
0
        { return m_cornerIndices; }
94
95
        Abc::FloatArraySamplePtr getCornerSharpnesses() const
96
0
        { return m_cornerSharpnesses; }
97
98
        // Holes
99
0
        Abc::Int32ArraySamplePtr getHoles() const { return m_holes; }
100
101
        // subdivision scheme
102
        std::string getSubdivisionScheme() const
103
0
        { return m_subdScheme; }
104
105
0
        Abc::V3fArraySamplePtr getVelocities() const { return m_velocities; }
106
107
        // bounds
108
0
        Abc::Box3d getSelfBounds() const { return m_selfBounds; }
109
110
        bool valid() const
111
0
        {
112
0
            return m_positions && m_faceIndices && m_faceCounts;
113
0
        }
114
115
        void reset()
116
0
        {
117
0
            m_positions.reset();
118
0
            m_velocities.reset();
119
0
            m_faceIndices.reset();
120
0
            m_faceCounts.reset();
121
0
122
0
            m_faceVaryingInterpolateBoundary = 0;
123
0
            m_faceVaryingPropagateCorners = 0;
124
0
            m_interpolateBoundary = 0;
125
0
126
0
            m_creaseIndices.reset();
127
0
            m_creaseLengths.reset();
128
0
            m_creaseSharpnesses.reset();
129
0
130
0
            m_cornerIndices.reset();
131
0
            m_cornerSharpnesses.reset();
132
0
133
0
            m_holes.reset();
134
0
135
0
            m_subdScheme = "catmull-clark";
136
0
137
0
            m_selfBounds.makeEmpty();
138
0
        }
139
140
        ALEMBIC_OPERATOR_BOOL( valid() );
141
142
    protected:
143
        friend class ISubDSchema;
144
145
        Abc::P3fArraySamplePtr m_positions;
146
        Abc::V3fArraySamplePtr m_velocities;
147
        Abc::Int32ArraySamplePtr m_faceIndices;
148
        Abc::Int32ArraySamplePtr m_faceCounts;
149
150
        int32_t m_faceVaryingInterpolateBoundary;
151
        int32_t m_faceVaryingPropagateCorners;
152
        int32_t m_interpolateBoundary;
153
154
        // Creases
155
        Abc::Int32ArraySamplePtr    m_creaseIndices;
156
        Abc::Int32ArraySamplePtr    m_creaseLengths;
157
        Abc::FloatArraySamplePtr  m_creaseSharpnesses;
158
159
        // Corners
160
        Abc::Int32ArraySamplePtr    m_cornerIndices;
161
        Abc::FloatArraySamplePtr  m_cornerSharpnesses;
162
163
        // Holes
164
        Abc::Int32ArraySamplePtr    m_holes;
165
166
        // subdivision scheme
167
        std::string m_subdScheme;
168
169
        // bounds
170
        Abc::Box3d m_selfBounds;
171
172
    }; // end ISubDSchema::Sample
173
174
    //-*************************************************************************
175
    // SUBD SCHEMA
176
    //-*************************************************************************
177
public:
178
    //! By convention we always define this_type in AbcGeom classes.
179
    //! Used by unspecified-bool-type conversion below
180
    typedef ISubDSchema this_type;
181
182
    //-*************************************************************************
183
    // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
184
    //-*************************************************************************
185
186
    //! The default constructor creates an empty ISubDSchema
187
    //! ...
188
    ISubDSchema()
189
0
    {
190
0
        m_faceSetsLoaded = false;
191
0
    }
192
193
    //! This constructor creates a new subd reader.
194
    //! The first argument is the parent ICompoundProperty, from which the
195
    //! error handler policy for is derived.  The second argument is the name
196
    //! of the ICompoundProperty that contains this schemas properties.  The
197
    //! remaining optional arguments can be used to override the
198
    //! ErrorHandlerPolicy and to specify schema interpretation matching.
199
    ISubDSchema( const ICompoundProperty &iParent,
200
                 const std::string &iName,
201
202
                 const Abc::Argument &iArg0 = Abc::Argument(),
203
                 const Abc::Argument &iArg1 = Abc::Argument() )
204
      : IGeomBaseSchema<SubDSchemaInfo>( iParent, iName, iArg0, iArg1 )
205
0
    {
206
0
        init(  iArg0, iArg1 );
207
0
    }
208
209
    //! This constructor wraps an existing ICompoundProperty as the subd
210
    //! reader, and the error handler policy is derived from it.
211
    //! The  remaining optional arguments can be used to override the
212
    //! ErrorHandlerPolicy and to specify schema interpretation matching.
213
    ISubDSchema( const ICompoundProperty &iProp,
214
                 const Abc::Argument &iArg0 = Abc::Argument(),
215
                 const Abc::Argument &iArg1 = Abc::Argument() )
216
      : IGeomBaseSchema<SubDSchemaInfo>( iProp, iArg0, iArg1 )
217
0
    {
218
0
        init( iArg0, iArg1 );
219
0
    }
220
221
    //! Default assignment operator used.
222
223
    //-*************************************************************************
224
    // SCHEMA STUFF
225
    //-*************************************************************************
226
227
228
    MeshTopologyVariance getTopologyVariance() const;
229
230
    //! if isConstant() is true, the mesh contains no time-varying values
231
0
    bool isConstant() const { return getTopologyVariance() == kConstantTopology; }
232
233
    //-*************************************************************************
234
    // SAMPLE STUFF
235
    //-*************************************************************************
236
237
    //! Get number of samples written so far.
238
    //! ...
239
    size_t getNumSamples() const;
240
241
    //! Return the time sampling
242
    AbcA::TimeSamplingPtr getTimeSampling() const
243
0
    {
244
0
        if ( m_positionsProperty.valid() )
245
0
        {
246
0
            return m_positionsProperty.getTimeSampling();
247
0
        }
248
0
        else
249
0
        {
250
0
            return getObject().getArchive().getTimeSampling( 0 );
251
0
        }
252
0
    }
253
254
    void get( Sample &iSamp,
255
              const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const;
256
257
    Sample getValue( const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const
258
0
    {
259
0
        Sample smp;
260
0
        get( smp, iSS );
261
0
        return smp;
262
0
    }
263
264
    Abc::IInt32ArrayProperty getFaceCountsProperty() const
265
0
    { return m_faceCountsProperty; }
266
    Abc::IInt32ArrayProperty getFaceIndicesProperty() const
267
0
    { return m_faceIndicesProperty; }
268
    Abc::IP3fArrayProperty getPositionsProperty() const
269
0
    { return m_positionsProperty; }
270
271
    Abc::IInt32Property getFaceVaryingInterpolateBoundaryProperty() const
272
0
    { return m_faceVaryingInterpolateBoundaryProperty; }
273
274
    Abc::IInt32Property getFaceVaryingPropagateCornersProperty() const
275
0
    { return m_faceVaryingPropagateCornersProperty; }
276
277
    Abc::IInt32Property getInterpolateBoundaryProperty() const
278
0
    { return m_interpolateBoundaryProperty; }
279
280
    Abc::IInt32ArrayProperty getCreaseIndicesProperty() const
281
0
    { return m_creaseIndicesProperty; }
282
    Abc::IInt32ArrayProperty getCreaseLengthsProperty() const
283
0
    { return m_creaseLengthsProperty; }
284
    Abc::IFloatArrayProperty getCreaseSharpnessesProperty() const
285
0
    { return m_creaseSharpnessesProperty; }
286
287
    Abc::IInt32ArrayProperty getCornerIndicesProperty() const
288
0
    { return m_cornerIndicesProperty; }
289
    Abc::IFloatArrayProperty getCornerSharpnessesProperty() const
290
0
    { return m_cornerSharpnessesProperty; }
291
292
0
    Abc::IInt32ArrayProperty getHolesProperty() const { return m_holesProperty; }
293
294
    Abc::IStringProperty getSubdivisionSchemeProperty() const
295
0
    { return m_subdSchemeProperty; }
296
297
    Abc::IV3fArrayProperty getVelocitiesProperty() const
298
0
    { return m_velocitiesProperty; }
299
300
    IV2fGeomParam getUVsParam() const
301
0
    {
302
0
        return m_uvsParam;
303
0
    }
304
305
    //-*************************************************************************
306
    // ABC BASE MECHANISMS
307
    // These functions are used by Abc to deal with errors, rewrapping,
308
    // and so on.
309
    //-*************************************************************************
310
311
    //! Reset returns this function set to an empty, default
312
    //! state.
313
    void reset()
314
0
    {
315
0
        m_positionsProperty.reset();
316
0
        m_velocitiesProperty.reset();
317
0
        m_faceIndicesProperty.reset();
318
0
        m_faceCountsProperty.reset();
319
320
0
        m_faceVaryingInterpolateBoundaryProperty.reset();
321
0
        m_faceVaryingPropagateCornersProperty.reset();
322
0
        m_interpolateBoundaryProperty.reset();
323
324
0
        m_creaseIndicesProperty.reset();
325
0
        m_creaseLengthsProperty.reset();
326
0
        m_creaseSharpnessesProperty.reset();
327
328
0
        m_cornerIndicesProperty.reset();
329
0
        m_cornerSharpnessesProperty.reset();
330
331
0
        m_holesProperty.reset();
332
333
0
        m_subdSchemeProperty.reset();
334
335
0
        m_uvsParam.reset();
336
337
0
        IGeomBaseSchema<SubDSchemaInfo>::reset();
338
0
    }
339
340
    //! Valid returns whether this function set is
341
    //! valid.
342
    bool valid() const
343
0
    {
344
0
        return ( IGeomBaseSchema<SubDSchemaInfo>::valid() &&
345
0
                 m_positionsProperty.valid() &&
346
0
                 m_faceIndicesProperty.valid() &&
347
0
                 m_faceCountsProperty.valid() );
348
0
    }
349
350
    // FaceSet related
351
    //! Appends the names of any FaceSets for this SubD.
352
    void getFaceSetNames( std::vector <std::string> &oFaceSetNames );
353
    IFaceSet getFaceSet( const std::string &iFaceSetName );
354
    bool hasFaceSet( const std::string &iFaceSetName );
355
356
    //! unspecified-bool-type operator overload.
357
    //! ...
358
    ALEMBIC_OVERRIDE_OPERATOR_BOOL( ISubDSchema::valid() );
359
360
    // Copy constructors
361
    ISubDSchema(const ISubDSchema& iCopy)
362
        : IGeomBaseSchema<SubDSchemaInfo>()
363
0
    {
364
0
        *this = iCopy;
365
0
    }
366
    const ISubDSchema & operator=(const ISubDSchema & rhs);
367
368
protected:
369
    void init( const Abc::Argument &iArg0, const Abc::Argument &iArg1 );
370
371
    Abc::IP3fArrayProperty   m_positionsProperty;
372
    Abc::IInt32ArrayProperty m_faceIndicesProperty;
373
    Abc::IInt32ArrayProperty m_faceCountsProperty;
374
375
    // misc
376
    Abc::IInt32Property m_faceVaryingInterpolateBoundaryProperty;
377
    Abc::IInt32Property m_faceVaryingPropagateCornersProperty;
378
    Abc::IInt32Property m_interpolateBoundaryProperty;
379
380
    // Creases
381
    Abc::IInt32ArrayProperty  m_creaseIndicesProperty;
382
    Abc::IInt32ArrayProperty  m_creaseLengthsProperty;
383
    Abc::IFloatArrayProperty  m_creaseSharpnessesProperty;
384
385
    // Corners
386
    Abc::IInt32ArrayProperty  m_cornerIndicesProperty;
387
    Abc::IFloatArrayProperty  m_cornerSharpnessesProperty;
388
389
    // Holes
390
    Abc::IInt32ArrayProperty  m_holesProperty;
391
392
    // subdivision scheme
393
    Abc::IStringProperty      m_subdSchemeProperty;
394
395
    // UVs
396
    IV2fGeomParam m_uvsParam;
397
398
    IV3fArrayProperty m_velocitiesProperty;
399
400
    // FaceSets, this starts as empty until client
401
    // code attempts to access facesets.
402
    bool                              m_faceSetsLoaded;
403
    std::map <std::string, IFaceSet>  m_faceSets;
404
    Alembic::Util::mutex              m_faceSetsMutex;
405
    void loadFaceSetNames();
406
407
};
408
409
//-*****************************************************************************
410
// SCHEMA OBJECT
411
//-*****************************************************************************
412
typedef Abc::ISchemaObject<ISubDSchema> ISubD;
413
414
typedef Util::shared_ptr< ISubD > ISubDPtr;
415
416
} // End namespace ALEMBIC_VERSION_NS
417
418
using namespace ALEMBIC_VERSION_NS;
419
420
} // End namespace AbcGeom
421
} // End namespace Alembic
422
423
#endif