Alembic Version 1.1
Loading...
Searching...
No Matches
ONuPatch.h
Go to the documentation of this file.
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>
46
47namespace Alembic {
48namespace AbcGeom {
49namespace ALEMBIC_VERSION_NS {
50
51//-*****************************************************************************
52// for default "null" values for the int scalar properties
54int32_t ABC_GEOM_NUPATCH_NULL_INT_VALUE( INT_MIN / 4 );
55
56//-*****************************************************************************
57class ALEMBIC_EXPORT ONuPatchSchema : public OGeomBaseSchema<NuPatchSchemaInfo>
58{
59public:
60 //-*************************************************************************
61 // NuPatch SCHEMA SAMPLE TYPE
62 //-*************************************************************************
63 class Sample
64 {
65 public:
68 Sample() { reset(); }
69
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 {}
102
103 // positions
104 const Abc::P3fArraySample &getPositions() const { return m_positions; }
106 { m_positions = iSmp; }
107
108 // position weights, if it isn't set, it's 1 for every point
110 { return m_positionWeights; }
112 { m_positionWeights = iSmp; }
113
114 // nu
115 int32_t getNu() const { return m_numU; }
116 void setNu( const int32_t iNu )
117 { m_numU = iNu; }
118
119 // nv
120 int32_t getNv() const { return m_numV; }
121 void setNv( const int32_t iNv )
122 { m_numV = iNv; }
123
124 // uOrder
125 int32_t getUOrder() const { return m_uOrder; }
126 void setUOrder( const int32_t iUOrder )
127 { m_uOrder = iUOrder; }
128
129 // vOrder
130 int32_t getVOrder() const { return m_vOrder; }
131 void setVOrder( const int32_t iVOrder )
132 { m_vOrder = iVOrder; }
133
134 // uKnot
135 const Abc::FloatArraySample &getUKnot() const { return m_uKnot; }
136 void setUKnot( const Abc::FloatArraySample &iUKnot )
137 { m_uKnot = iUKnot; }
138
139 // vKnot
140 const Abc::FloatArraySample &getVKnot() const { return m_vKnot; }
141 void setVKnot( const Abc::FloatArraySample &iVKnot )
142 { m_vKnot = iVKnot; }
143
144 // uvs
145 const OV2fGeomParam::Sample &getUVs() const { return m_uvs; }
146 void setUVs( const OV2fGeomParam::Sample &iUVs )
147 { m_uvs = iUVs; }
148
149 // normals
150 const ON3fGeomParam::Sample &getNormals() const { return m_normals; }
151 void setNormals( const ON3fGeomParam::Sample &iNormals )
152 { m_normals = iNormals; }
153
154 // bounds
155 const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
156 void setSelfBounds( const Abc::Box3d &iBnds )
157 { m_selfBounds = iBnds; }
158
159 // velocities accessor
160 const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
161 void setVelocities( const Abc::V3fArraySample &iVelocities )
162 { 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 {
176 m_trimNumLoops = i_trim_nLoops;
177 m_trimNumCurves = i_trim_nCurves;
178 m_trimNumVertices = i_trim_n;
179 m_trimOrder = i_trim_order;
180 m_trimKnot = i_trim_knot;
181 m_trimMin = i_trim_min;
182 m_trimMax = i_trim_max;
183 m_trimU = i_trim_u;
184 m_trimV = i_trim_v;
185 m_trimW = i_trim_w;
186
187 m_hasTrimCurve = true;
188 }
189
190 int32_t getTrimNumLoops() const { return m_trimNumLoops; }
192 { return m_trimNumCurves; }
194 { return m_trimNumVertices; }
196 { return m_trimOrder; }
197 const Abc::FloatArraySample &getTrimKnot() const { return m_trimKnot; }
198 const Abc::FloatArraySample &getTrimMin() const { return m_trimMin; }
199 const Abc::FloatArraySample &getTrimMax() const { return m_trimMax; }
200 const Abc::FloatArraySample &getTrimU() const { return m_trimU; }
201 const Abc::FloatArraySample &getTrimV() const { return m_trimV; }
202 const Abc::FloatArraySample &getTrimW() const { return m_trimW; }
203
204 bool hasTrimCurve() const
205 {
206 return m_hasTrimCurve;
207 }
208
209 void reset()
210 {
211 m_positions.reset();
212 m_velocities.reset();
217 m_uKnot.reset();
218 m_vKnot.reset();
219 m_positionWeights.reset();
220 m_normals.reset();
221 m_uvs.reset();
222 m_selfBounds.makeEmpty();
223
224 // reset trim curves
225 m_trimNumLoops = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
226 m_trimNumCurves.reset();
227 m_trimNumVertices.reset();
228 m_trimOrder.reset();
229 m_trimKnot.reset();
230 m_trimMin.reset();
231 m_trimMax.reset();
232 m_trimU.reset();
233 m_trimV.reset();
234 m_trimW.reset();
235 m_hasTrimCurve = false;
236 }
237
238 bool isPartialSample() const
239 {
240 if( !m_positions.getData() )
241 {
242 if( m_uvs.getVals() || m_normals.getVals() || m_velocities.getData() )
243 {
244 return true;
245 }
246 }
247
248 return false;
249 }
250
251 bool hasKnotSampleData() const
252 {
253 if( (m_numU != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
255 (m_uOrder != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
256 (m_vOrder != ABC_GEOM_NUPATCH_NULL_INT_VALUE) ||
257 m_uKnot || m_vKnot)
258 return true;
259 else
260 return false;
261 }
262
263 protected:
264
265 // required properties
268 int32_t m_numU;
269 int32_t m_numV;
270 int32_t m_uOrder;
271 int32_t m_vOrder;
274
275 // optional properties
277 ON3fGeomParam::Sample m_normals;
278 OV2fGeomParam::Sample m_uvs;
279
280 // optional trim curves
292
293 // bounds
294 Abc::Box3d m_selfBounds;
295 };
296
297 //-*************************************************************************
298 // NuPatch SCHEMA
299 //-*************************************************************************
300
301public:
302
307
308 //-*************************************************************************
309 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
310 //-*************************************************************************
311
315 {
316 m_selectiveExport = false;
317 m_numSamples = 0;
318 m_timeSamplingIndex = 0;
319 }
320
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
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
348 : OGeomBaseSchema<NuPatchSchemaInfo>()
349 {
350 *this = iCopy;
351 }
352
353 //-*************************************************************************
354 // SCHEMA STUFF
355 //-*************************************************************************
356
360 {
361 if( m_positionsProperty.valid() )
362 {
363 return m_positionsProperty.getTimeSampling();
364 }
365 else
366 {
367 return getObject().getArchive().getTimeSampling( 0 );
368 }
369 }
370
371 void setTimeSampling( uint32_t iIndex );
373
374 //-*************************************************************************
375 // SAMPLE STUFF
376 //-*************************************************************************
377
380 size_t getNumSamples() const
381 {
382 return m_numSamples;
383 }
384
386 void set( const sample_type &iSamp );
387
391
392 //-*************************************************************************
393 // ABC BASE MECHANISMS
394 // These functions are used by Abc to deal with errors, validity,
395 // and so on.
396 //-*************************************************************************
397
400 void reset()
401 {
402 m_positionsProperty.reset();
403 m_positionWeightsProperty.reset();
404 m_velocitiesProperty.reset();
405 m_numUProperty.reset();
406 m_numVProperty.reset();
407 m_uOrderProperty.reset();
408 m_vOrderProperty.reset();
409 m_uKnotProperty.reset();
410 m_vKnotProperty.reset();
411
412 m_normalsParam.reset();
413 m_uvsParam.reset();
414
415 // reset trim curve attributes
416 m_trimNumLoopsProperty.reset();
417 m_trimNumVerticesProperty.reset();
418 m_trimOrderProperty.reset();
419 m_trimKnotProperty.reset();
420 m_trimMinProperty.reset();
421 m_trimMaxProperty.reset();
422 m_trimUProperty.reset();
423 m_trimVProperty.reset();
424 m_trimWProperty.reset();
425
427 }
428
431 bool valid() const
432 {
434 m_positionsProperty.valid() ) ||
435 m_selectiveExport );
436 }
437
440 ALEMBIC_OVERRIDE_OPERATOR_BOOL( ONuPatchSchema::valid() );
441
442protected:
443 void init( const AbcA::index_t iTsIdx, bool isSparse );
444
448 void selectiveSet( const Sample &iSamp );
449
450 // Write out only some properties (UVs, normals).
451 // This is to export data to layer into another file later.
453
454 // Number of times OPolyMeshSchema::set() has been called
456
458
462 void createUVsProperty( const Sample &iSamp );
463 void createNormalsProperty( const Sample &iSamp );
466
467
468 // point data
470
471 // required properties
478
479 // optional properties
484
485 // optional trim curves
496
497};
498
499//-*****************************************************************************
500// SCHEMA OBJECT
501//-*****************************************************************************
503
504typedef Util::shared_ptr< ONuPatch > ONuPatchPtr;
505
506} // End namespace ALEMBIC_VERSION_NS
507
508using namespace ALEMBIC_VERSION_NS;
509
510} // End namespace AbcGeom
511} // End namespace Alembic
512
513#endif
#define ALEMBIC_EXPORT_CONST
Definition Export.h:53
#define ALEMBIC_EXPORT
Definition Export.h:51
#define ALEMBIC_VERSION_NS
Definition Foundation.h:105
const Abc::FloatArraySample & getUKnot() const
Definition ONuPatch.h:135
const Abc::Int32ArraySample & getTrimNumVertices() const
Definition ONuPatch.h:193
const Abc::FloatArraySample & getTrimMax() const
Definition ONuPatch.h:199
void setTrimCurve(const int32_t i_trim_nLoops, const Abc::Int32ArraySample &i_trim_nCurves, const Abc::Int32ArraySample &i_trim_n, const Abc::Int32ArraySample &i_trim_order, const Abc::FloatArraySample &i_trim_knot, const Abc::FloatArraySample &i_trim_min, const Abc::FloatArraySample &i_trim_max, const Abc::FloatArraySample &i_trim_u, const Abc::FloatArraySample &i_trim_v, const Abc::FloatArraySample &i_trim_w)
Definition ONuPatch.h:165
const Abc::V3fArraySample & getVelocities() const
Definition ONuPatch.h:160
void setVKnot(const Abc::FloatArraySample &iVKnot)
Definition ONuPatch.h:141
const Abc::FloatArraySample & getTrimMin() const
Definition ONuPatch.h:198
const Abc::FloatArraySample & getTrimV() const
Definition ONuPatch.h:201
const Abc::FloatArraySample & getTrimKnot() const
Definition ONuPatch.h:197
const ON3fGeomParam::Sample & getNormals() const
Definition ONuPatch.h:150
const Abc::P3fArraySample & getPositions() const
Definition ONuPatch.h:104
void setNormals(const ON3fGeomParam::Sample &iNormals)
Definition ONuPatch.h:151
const Abc::Int32ArraySample & getTrimNumCurves() const
Definition ONuPatch.h:191
Sample(const Abc::P3fArraySample &iPos, const int32_t &iNumU, const int32_t &iNumV, const int32_t &iUOrder, const int32_t &iVOrder, const Abc::FloatArraySample &iUKnot, const Abc::FloatArraySample &iVKnot, const ON3fGeomParam::Sample &iNormals=ON3fGeomParam::Sample(), const OV2fGeomParam::Sample &iUVs=OV2fGeomParam::Sample(), const Abc::FloatArraySample &iPosWeight=Abc::FloatArraySample())
Definition ONuPatch.h:70
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition ONuPatch.h:146
void setUKnot(const Abc::FloatArraySample &iUKnot)
Definition ONuPatch.h:136
const Abc::FloatArraySample & getTrimU() const
Definition ONuPatch.h:200
const Abc::FloatArraySample & getVKnot() const
Definition ONuPatch.h:140
const OV2fGeomParam::Sample & getUVs() const
Definition ONuPatch.h:145
void setPositions(const Abc::P3fArraySample &iSmp)
Definition ONuPatch.h:105
const Abc::FloatArraySample & getTrimW() const
Definition ONuPatch.h:202
const Abc::Int32ArraySample & getTrimOrder() const
Definition ONuPatch.h:195
void setPositionWeights(const Abc::FloatArraySample &iSmp)
Definition ONuPatch.h:111
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition ONuPatch.h:161
const Abc::FloatArraySample & getPositionWeights() const
Definition ONuPatch.h:109
void setTimeSampling(AbcA::TimeSamplingPtr iTime)
void set(const sample_type &iSamp)
Set a sample!
AbcA::TimeSamplingPtr getTimeSampling() const
Definition ONuPatch.h:359
ONuPatchSchema(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument(), const Abc::Argument &iArg3=Abc::Argument())
ONuPatchSchema(Abc::OCompoundProperty iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
ONuPatchSchema(const ONuPatchSchema &iCopy)
Copy constructor.
Definition ONuPatch.h:347
void init(const AbcA::index_t iTsIdx, bool isSparse)
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
static ALEMBIC_EXPORT_CONST int32_t ABC_GEOM_NUPATCH_NULL_INT_VALUE(INT_MIN/4)
Util::shared_ptr< ONuPatch > ONuPatchPtr
Definition ONuPatch.h:504
Alembic namespace ...
Definition ArchiveInfo.h:46