Coverage Report

Created: 2025-07-11 06:05

/src/alembic/lib/Alembic/AbcGeom/OPoints.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_OPoints_h
38
#define Alembic_AbcGeom_OPoints_h
39
40
#include <Alembic/Util/Export.h>
41
#include <Alembic/AbcGeom/Foundation.h>
42
#include <Alembic/AbcGeom/SchemaInfoDeclarations.h>
43
#include <Alembic/AbcGeom/OGeomParam.h>
44
#include <Alembic/AbcGeom/OGeomBase.h>
45
46
namespace Alembic {
47
namespace AbcGeom {
48
namespace ALEMBIC_VERSION_NS {
49
50
//-*****************************************************************************
51
class ALEMBIC_EXPORT OPointsSchema : public OGeomBaseSchema<PointsSchemaInfo>
52
{
53
public:
54
    //-*************************************************************************
55
    // POINTS SCHEMA SAMPLE TYPE
56
    //-*************************************************************************
57
    class Sample
58
    {
59
    public:
60
        //! Creates a default sample with no data in it.
61
        //! ...
62
0
        Sample() { reset(); }
63
64
        //! Creates a sample with position data but no id
65
        //! data. For specifying samples after the first one
66
        Sample( const Abc::P3fArraySample &iPos,
67
                const Abc::V3fArraySample &iVelocities = Abc::V3fArraySample(),
68
                const OFloatGeomParam::Sample &iWidths = \
69
                OFloatGeomParam::Sample() )
70
          : m_positions( iPos )
71
          , m_velocities( iVelocities )
72
          , m_widths( iWidths )
73
0
        {}
74
75
        //! Creates a sample with position data and id data. The first
76
        //! sample must be full like this. Subsequent samples may also
77
        //! be full like this, which would indicate a change of topology
78
        Sample( const Abc::P3fArraySample &iPos,
79
                const Abc::UInt64ArraySample &iId,
80
                const Abc::V3fArraySample &iVelocities = Abc::V3fArraySample(),
81
                const OFloatGeomParam::Sample &iWidths = \
82
                OFloatGeomParam::Sample() )
83
          : m_positions( iPos )
84
          , m_velocities( iVelocities )
85
          , m_ids( iId )
86
          , m_widths( iWidths )
87
0
        {}
88
89
        // positions accessor
90
0
        const Abc::P3fArraySample &getPositions() const { return m_positions; }
91
        void setPositions( const Abc::P3fArraySample &iSmp )
92
0
        { m_positions = iSmp; }
93
94
        // ids accessor
95
0
        const Abc::UInt64ArraySample &getIds() const { return m_ids; }
96
        void setIds( const Abc::UInt64ArraySample &iSmp )
97
0
        { m_ids = iSmp; }
98
99
        // velocities accessor
100
0
        const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
101
        void setVelocities( const Abc::V3fArraySample &iVelocities )
102
0
        { m_velocities = iVelocities; }
103
104
        // widths accessor
105
0
        const OFloatGeomParam::Sample &getWidths() const { return m_widths; }
106
        void setWidths( const OFloatGeomParam::Sample &iWidths )
107
0
        { m_widths = iWidths; }
108
109
0
        const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
110
        void setSelfBounds( const Abc::Box3d &iBnds )
111
0
        { m_selfBounds = iBnds; }
112
113
        void reset()
114
0
        {
115
0
            m_positions.reset();
116
0
            m_velocities.reset();
117
0
            m_ids.reset();
118
0
            m_widths.reset();
119
0
120
0
            m_selfBounds.makeEmpty();
121
0
        }
122
123
        bool isPartialSample() const
124
0
        {
125
0
            if( !m_positions.getData() )
126
0
            {
127
0
                return true;
128
0
            }
129
0
130
0
            return false;
131
0
        }
132
133
    protected:
134
        Abc::P3fArraySample m_positions;
135
        Abc::V3fArraySample m_velocities;
136
        Abc::UInt64ArraySample m_ids;
137
        OFloatGeomParam::Sample m_widths;
138
139
        Abc::Box3d m_selfBounds;
140
    };
141
142
    //-*************************************************************************
143
    // POINTS SCHEMA
144
    //-*************************************************************************
145
public:
146
    //! By convention we always define this_type in AbcGeom classes.
147
    //! Used by unspecified-bool-type conversion below
148
    typedef OPointsSchema this_type;
149
150
    //-*************************************************************************
151
    // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
152
    //-*************************************************************************
153
154
    //! The default constructor creates an empty OPointsSchema
155
    //! ...
156
    OPointsSchema()
157
0
    {
158
0
        m_selectiveExport = false;
159
0
        m_numSamples = 0;
160
0
        m_timeSamplingIndex = 0;
161
0
    }
162
163
    //! This constructor creates a new poly mesh writer.
164
    //! The first argument is an CompoundPropertyWriterPtr to use as a parent.
165
    //! The next is the name to give the schema which is usually the default
166
    //! name given by OFaceSet (.geom)   The remaining optional arguments
167
    //! can be used to override the ErrorHandlerPolicy, to specify
168
    //! MetaData, specify sparse sampling and to set TimeSampling.
169
    OPointsSchema( AbcA::CompoundPropertyWriterPtr iParent,
170
                     const std::string &iName,
171
                     const Abc::Argument &iArg0 = Abc::Argument(),
172
                     const Abc::Argument &iArg1 = Abc::Argument(),
173
                     const Abc::Argument &iArg2 = Abc::Argument(),
174
                     const Abc::Argument &iArg3 = Abc::Argument() );
175
176
    //! This constructor creates a new poly mesh writer.
177
    //! The first argument is an OCompundProperty to use as a parent, and from
178
    //! which the ErrorHandlerPolicy is derived.  The next is the name to give
179
    //! the schema which is usually the default name given by OFaceSet (.geom)
180
    //! The remaining optional arguments can be used to specify MetaData,
181
    //! specify sparse sampling and to set TimeSampling.
182
    OPointsSchema( Abc::OCompoundProperty iParent,
183
                     const std::string &iName,
184
                     const Abc::Argument &iArg0 = Abc::Argument(),
185
                     const Abc::Argument &iArg1 = Abc::Argument(),
186
                     const Abc::Argument &iArg2 = Abc::Argument() );
187
188
    //! Default assignment and copy operator used.
189
190
    //-*************************************************************************
191
    // SCHEMA STUFF
192
    //-*************************************************************************
193
194
    //! Return the time sampling
195
    AbcA::TimeSamplingPtr getTimeSampling() const
196
0
    {
197
0
        if( m_positionsProperty.valid() )
198
0
        {
199
0
            return m_positionsProperty.getTimeSampling();
200
0
        }
201
0
        else
202
0
        {
203
0
            return getObject().getArchive().getTimeSampling( 0 );
204
0
        }
205
0
    }
206
207
    //-*************************************************************************
208
    // SAMPLE STUFF
209
    //-*************************************************************************
210
211
    //! Get number of samples written so far.
212
    //! ...
213
0
    size_t getNumSamples() const { return m_numSamples; }
214
215
    //! Set a sample
216
    void set( const Sample &iSamp );
217
218
    //! Set from previous sample. Will apply to each of positions,
219
    //! ids, velocities, and widths
220
    void setFromPrevious( );
221
222
    void setTimeSampling( uint32_t iIndex );
223
    void setTimeSampling( AbcA::TimeSamplingPtr iTime );
224
225
    //-*************************************************************************
226
    // ABC BASE MECHANISMS
227
    // These functions are used by Abc to deal with errors, validity,
228
    // and so on.
229
    //-*************************************************************************
230
231
    //! Reset returns this function set to an empty, default
232
    //! state.
233
    void reset()
234
0
    {
235
0
        m_positionsProperty.reset();
236
0
        m_idsProperty.reset();
237
0
        m_velocitiesProperty.reset();
238
0
        m_widthsParam.reset();
239
0
240
0
        OGeomBaseSchema<PointsSchemaInfo>::reset();
241
0
    }
242
243
    //! Valid returns whether this function set is
244
    //! valid.
245
    bool valid() const
246
0
    {
247
0
        return ( ( OGeomBaseSchema<PointsSchemaInfo>::valid() &&
248
0
                 m_positionsProperty.valid() &&
249
0
                 m_idsProperty.valid() )
250
0
                 || m_selectiveExport );
251
0
    }
252
253
    //! unspecified-bool-type operator overload.
254
    //! ...
255
    ALEMBIC_OVERRIDE_OPERATOR_BOOL( OPointsSchema::valid() );
256
257
private:
258
    void init( uint32_t iTsIdx, bool isSparse );
259
260
    //! Set only some property data. Does not need to be a valid schema sample
261
    //! This is to be used when created a file which will be layered in to
262
    //! another file.
263
    void selectiveSet( const Sample &iSamp );
264
265
    void createPositionProperty();
266
    void createIdProperty();
267
    void createVelocityProperty();
268
    void createWidthsProperty( const Sample &iSamp );
269
270
    Abc::OP3fArrayProperty m_positionsProperty;
271
    Abc::OUInt64ArrayProperty m_idsProperty;
272
    Abc::OV3fArrayProperty m_velocitiesProperty;
273
    OFloatGeomParam m_widthsParam;
274
275
    // Write out only some properties (UVs, normals).
276
    // This is to export data to layer into another file later.
277
    bool m_selectiveExport;
278
279
    // Number of times OPolyMeshSchema::set() has been called
280
    size_t m_numSamples;
281
282
    uint32_t m_timeSamplingIndex;
283
284
};
285
286
//-*****************************************************************************
287
// SCHEMA OBJECT
288
//-*****************************************************************************
289
typedef Abc::OSchemaObject<OPointsSchema> OPoints;
290
291
typedef Util::shared_ptr< OPoints > OPointsPtr;
292
293
} // End namespace ALEMBIC_VERSION_NS
294
295
using namespace ALEMBIC_VERSION_NS;
296
297
} // End namespace AbcGeom
298
} // End namespace Alembic
299
300
#endif