Coverage Report

Created: 2023-09-25 06:10

/src/alembic/lib/Alembic/AbcGeom/IGeomBase.h
Line
Count
Source (jump to first uncovered line)
1
//-*****************************************************************************
2
//
3
// Copyright (c) 2009-2011,
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_IGeometrySchema_h
38
#define Alembic_AbcGeom_IGeometrySchema_h
39
40
#include <Alembic/Abc/ISchema.h>
41
#include <Alembic/AbcGeom/Foundation.h>
42
#include <Alembic/AbcGeom/IGeomParam.h>
43
#include <Alembic/AbcGeom/SchemaInfoDeclarations.h>
44
45
namespace Alembic {
46
namespace AbcGeom {
47
namespace ALEMBIC_VERSION_NS {
48
49
50
//! This class holds properties common to all geometric classes that have a
51
//! physical volume.
52
//! - selfBounds
53
//! - childBounds (optional)
54
//! - GeomParams (optional)
55
//! - UserProperties (optional)
56
//!
57
//! This class is used to encapsulate common functionality of the
58
//! real Geometry schema classes, like IPoints and IPolyMesh and so on
59
template <class INFO>
60
class IGeomBaseSchema : public Abc::ISchema<INFO>
61
{
62
public:
63
    //-*************************************************************************
64
    // TYPEDEFS AND IDENTIFIERS
65
    //-*************************************************************************
66
67
    typedef INFO info_type;
68
69
70
    //-*************************************************************************
71
    // Constructors that pass through to ISchema
72
    //-*************************************************************************
73
    //
74
    //! The default constructor creates an empty ISchema.
75
    //! Used to create "NULL/invalid" instances.
76
0
    IGeomBaseSchema() {}
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::IGeomBaseSchema()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::IGeomBaseSchema()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::IGeomBaseSchema()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::IGeomBaseSchema()
77
78
    //! Delegates to Abc/ISchema, and then creates
79
    //! properties that are present.
80
    IGeomBaseSchema( const ICompoundProperty & iParent,
81
                     const std::string &iName,
82
                     const Argument &iArg0 = Argument(),
83
                     const Argument &iArg1 = Argument() )
84
    : Abc::ISchema<info_type>( iParent, iName, iArg0, iArg1 )
85
0
    {
86
0
        init( iArg0, iArg1 );
87
0
    }
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::IGeomBaseSchema(Alembic::Abc::v12::ICompoundProperty const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::IGeomBaseSchema(Alembic::Abc::v12::ICompoundProperty const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::IGeomBaseSchema(Alembic::Abc::v12::ICompoundProperty const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::IGeomBaseSchema(Alembic::Abc::v12::ICompoundProperty const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
88
89
    //! Wrap an existing schema object
90
    IGeomBaseSchema( const ICompoundProperty & iProp,
91
                     const Abc::Argument &iArg0 = Abc::Argument(),
92
                     const Abc::Argument &iArg1 = Abc::Argument() )
93
      : Abc::ISchema<info_type>( iProp, iArg0, iArg1 )
94
    {
95
        init( iArg0, iArg1 );
96
    }
97
98
    // Deprecated in favor of the constructor above
99
    IGeomBaseSchema( const ICompoundProperty & iProp,
100
                     Abc::WrapExistingFlag iFlag,
101
                     const Abc::Argument &iArg0 = Abc::Argument(),
102
                     const Abc::Argument &iArg1 = Abc::Argument() )
103
      : Abc::ISchema<info_type>( iProp, iArg0, iArg1 )
104
    {
105
        init( iArg0, iArg1 );
106
    }
107
108
    void init( const Abc::Argument &iArg0, const Abc::Argument &iArg1 )
109
0
    {
110
0
        ALEMBIC_ABC_SAFE_CALL_BEGIN( "IGeomBaseSchema::init()" );
111
112
0
        Abc::Arguments args;
113
0
        iArg0.setInto( args );
114
0
        iArg1.setInto( args );
115
116
0
        AbcA::CompoundPropertyReaderPtr _this = this->getPtr();
117
118
0
        m_selfBoundsProperty = Abc::IBox3dProperty( _this, ".selfBnds",
119
0
            iArg0, iArg1 );
120
0
        if ( this->getPropertyHeader( ".childBnds" ) != NULL )
121
0
        {
122
0
            m_childBoundsProperty = Abc::IBox3dProperty( _this,
123
0
                ".childBnds", iArg0, iArg1 );
124
0
        }
125
126
0
        if ( this->getPropertyHeader( ".arbGeomParams" ) != NULL )
127
0
        {
128
0
            m_arbGeomParams = Abc::ICompoundProperty( _this, ".arbGeomParams",
129
0
                args.getErrorHandlerPolicy() );
130
0
        }
131
0
        if ( this->getPropertyHeader( ".userProperties" ) != NULL )
132
0
        {
133
0
            m_userProperties = Abc::ICompoundProperty( _this, ".userProperties",
134
0
                args.getErrorHandlerPolicy() );
135
0
        }
136
137
0
        ALEMBIC_ABC_SAFE_CALL_END();
138
0
    }
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::GeomBaseSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::NuPatchSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PointsSchemaInfo>::init(Alembic::Abc::v12::Argument const&, Alembic::Abc::v12::Argument const&)
139
140
    virtual void reset ()
141
0
    {
142
0
        m_selfBoundsProperty.reset();
143
0
        m_childBoundsProperty.reset();
144
0
        m_arbGeomParams.reset();
145
0
        m_userProperties.reset();
146
0
        Abc::ISchema<info_type>::reset();
147
0
    }
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::reset()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::reset()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::reset()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::reset()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::GeomBaseSchemaInfo>::reset()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::NuPatchSchemaInfo>::reset()
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PointsSchemaInfo>::reset()
148
149
    virtual bool valid() const
150
0
    {
151
        // Only selfBounds is required, all others are optional
152
0
        return ( Abc::ISchema<info_type>::valid() &&
153
0
                m_selfBoundsProperty.valid() );
154
0
    }
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::valid() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::valid() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::valid() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::valid() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::GeomBaseSchemaInfo>::valid() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::NuPatchSchemaInfo>::valid() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PointsSchemaInfo>::valid() const
155
156
    Abc::IBox3dProperty getSelfBoundsProperty() const
157
    {
158
        return m_selfBoundsProperty;
159
    }
160
161
    Abc::IBox3dProperty getChildBoundsProperty() const
162
    {
163
        return m_childBoundsProperty;
164
    }
165
166
    // compound property to use as parent for any arbitrary GeomParams
167
    // underneath it
168
0
    ICompoundProperty getArbGeomParams() const { return m_arbGeomParams; }
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::getArbGeomParams() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::getArbGeomParams() const
Unexecuted instantiation: Alembic::AbcGeom::v12::IGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::getArbGeomParams() const
169
170
    // compound property to use as parent for any user workflow specific
171
    // properties
172
    ICompoundProperty getUserProperties() const { return m_userProperties; }
173
174
protected:
175
    // Only selfBounds is required, all others are optional
176
    Abc::IBox3dProperty m_selfBoundsProperty;
177
    Abc::IBox3dProperty m_childBoundsProperty;
178
179
    Abc::ICompoundProperty m_arbGeomParams;
180
    Abc::ICompoundProperty m_userProperties;
181
182
};
183
184
//-*****************************************************************************
185
//! IGeomBase - A generic base set of properties and methods that encapsulate
186
//! things common to AbcGeom types that have a physical volume.
187
//! - self bounds
188
//! - children bounds (optional)
189
//! - argbGeomParams (optional)
190
//! - userProperties (optional)
191
//! This class is a concrete instantiation of IGeomBaseSchema.
192
//! Your archive might contain PolyMesh and SubD and Curves
193
//! and Points objects etc. This class, IGeomBase, gives you
194
//! access to the generic parts of those objects. For example, if you
195
//! just wish to iterate through an archive's hierarchy to examine bounding
196
//! regions this class could be helpful to you. Then when you actually
197
//! need to access the real data in the geometric type you can
198
//! always create the needed type of I<geom type> object>.
199
class IGeomBase : public IGeomBaseSchema<GeomBaseSchemaInfo>
200
{
201
public:
202
    typedef IGeomBase this_type;
203
204
    class Sample
205
    {
206
    public:
207
        typedef Sample this_type;
208
209
        // Users don't ever create this data directly.
210
0
        Sample() { reset(); }
211
212
0
        Abc::Box3d getSelfBounds() const { return m_selfBounds; }
213
214
        void reset()
215
0
        {
216
0
            m_selfBounds.makeEmpty();
217
0
        }
218
219
    protected:
220
        friend class IGeomBase;
221
        Abc::Box3d m_selfBounds;
222
    };
223
224
public:
225
    //! By convention we always define this_type in AbcGeom classes.
226
    //! Used by unspecified-bool-type conversion below
227
228
    //-*************************************************************************
229
    // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
230
    //-*************************************************************************
231
232
    //! The default constructor creates an empty GeomBase
233
0
    IGeomBase() {}
234
235
    IGeomBase( const ICompoundProperty &iParent,
236
               const std::string &iName,
237
               const Abc::Argument &iArg0 = Abc::Argument(),
238
               const Abc::Argument &iArg1 = Abc::Argument() )
239
240
        // We don't want strict matching of the title because the real schema
241
        // is going to be something like "AbcGeom_<type>_vX"
242
      : IGeomBaseSchema<GeomBaseSchemaInfo>( iParent, iName, kNoMatching )
243
0
    {
244
0
        init( iArg0, iArg1 );
245
0
    }
246
247
    IGeomBase( const ICompoundProperty & iThis,
248
               const Abc::Argument &iArg0 = Abc::Argument(),
249
               const Abc::Argument &iArg1 = Abc::Argument() )
250
        // We don't want strict matching of the title because the real schema
251
        // is going to be something like "AbcGeom_<type>_vX"
252
    : IGeomBaseSchema<GeomBaseSchemaInfo>( iThis, kNoMatching )
253
0
    {
254
0
        init( iArg0, iArg1 );
255
0
    }
256
257
    IGeomBase( const ICompoundProperty & iThis,
258
               Abc::WrapExistingFlag iFlag,
259
               const Abc::Argument &iArg0 = Abc::Argument(),
260
               const Abc::Argument &iArg1 = Abc::Argument() )
261
    : IGeomBaseSchema<GeomBaseSchemaInfo>( iThis, kNoMatching )
262
0
    {
263
0
        init( iArg0, iArg1 );
264
0
    }
265
266
    //! Default assignment and copy operator used.
267
268
    //-*************************************************************************
269
    // SCALAR PROPERTY READER FUNCTIONALITY
270
    //-*************************************************************************
271
272
    //! Return the number of samples contained in the property.
273
    //! This can be any number, including zero.
274
    //! This returns the number of samples that were written, independently
275
    //! of whether or not they were constant.
276
    size_t getNumSamples() const
277
0
    { return m_selfBoundsProperty.getNumSamples(); }
278
279
    //! Ask if we're constant - no change in value amongst samples,
280
    //! regardless of the time sampling.
281
    bool isConstant() const
282
0
    { return m_selfBoundsProperty.isConstant(); }
283
284
    //! Time sampling Information.
285
    //!
286
    AbcA::TimeSamplingPtr getTimeSampling() const
287
0
    {
288
0
        if ( m_selfBoundsProperty.valid() )
289
0
        {
290
0
            return m_selfBoundsProperty.getTimeSampling();
291
0
        }
292
0
        else
293
0
        {
294
0
            return getObject().getArchive().getTimeSampling( 0 );
295
0
        }
296
0
    }
297
298
    //-*************************************************************************
299
    void get( Sample &oSample,
300
              const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const
301
0
    {
302
0
        ALEMBIC_ABC_SAFE_CALL_BEGIN( "IGeomBase::get()" );
303
0
304
0
        m_selfBoundsProperty.get( oSample.m_selfBounds, iSS );
305
0
306
0
        ALEMBIC_ABC_SAFE_CALL_END();
307
0
    }
308
309
    //-*************************************************************************
310
    Sample getValue( const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const
311
0
    {
312
0
        Sample smp;
313
0
        get( smp, iSS );
314
0
        return smp;
315
0
    }
316
317
    //-*************************************************************************
318
0
    Abc::ICompoundProperty getArbGeomParams() const { return m_arbGeomParams; }
319
320
    //-*************************************************************************
321
0
    Abc::ICompoundProperty getUserProperties() const { return m_userProperties; }
322
323
    //-*************************************************************************
324
    //! Reset returns this function set to an empty, default
325
    //! state.
326
    void reset()
327
0
    {
328
0
        IGeomBaseSchema<GeomBaseSchemaInfo>::reset();
329
0
    }
330
331
    //-*************************************************************************
332
    //! Valid returns whether this function set is
333
    //! valid.
334
    bool valid() const
335
0
    {
336
0
        return ( IGeomBaseSchema<GeomBaseSchemaInfo>::valid() );
337
0
    }
338
339
    //-*************************************************************************
340
    //! unspecified-bool-type operator overload.
341
    //! ...
342
    ALEMBIC_OVERRIDE_OPERATOR_BOOL( IGeomBase::valid() );
343
344
    //-*************************************************************************
345
    //! This will check whether or not a given entity (as represented by
346
    //! metadata) strictly matches the interpretation of this
347
    //! schema object.
348
    static bool matches( const AbcA::MetaData &iMetaData,
349
                         SchemaInterpMatching iMatching = kStrictMatching )
350
0
    {
351
0
        if ( iMatching == kNoMatching )
352
0
        { return true; }
353
0
354
0
        if ( iMatching == kStrictMatching || iMatching == kSchemaTitleMatching )
355
0
        {
356
0
            return iMetaData.get( "schemaBaseType" ) ==
357
0
                GeomBaseSchemaInfo::title();
358
0
        }
359
0
360
0
        return false;
361
0
    }
362
363
    //-*************************************************************************
364
    //! This will check whether or not a given object (as represented by
365
    //! an object header) strictly matches the interpretation of this
366
    //! schema object, as well as the data type.
367
    static bool matches( const AbcA::PropertyHeader &iHeader,
368
                         SchemaInterpMatching iMatching = kStrictMatching )
369
0
    {
370
0
        return matches( iHeader.getMetaData(), iMatching );
371
0
    }
372
373
};
374
375
//-*****************************************************************************
376
typedef Abc::ISchemaObject<IGeomBase> IGeomBaseObject;
377
378
} // End namespace ALEMBIC_VERSION_NS
379
380
using namespace ALEMBIC_VERSION_NS;
381
382
} // End namespace AbcGeom
383
} // End namespace Alembic
384
385
#endif