Alembic 1.8.11

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