HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
42 #include <Alembic/AbcGeom/Basis.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)
54 int32_t ABC_GEOM_NUPATCH_NULL_INT_VALUE( -536870912 );
55 
56 //-*****************************************************************************
57 class ALEMBIC_EXPORT ONuPatchSchema : public OGeomBaseSchema<NuPatchSchemaInfo>
58 {
59 public:
60  //-*************************************************************************
61  // NuPatch SCHEMA SAMPLE TYPE
62  //-*************************************************************************
63  class Sample
64  {
65  public:
66  //! Creates a default sample with no data in it.
67  //! ...
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; }
105  void setPositions( const Abc::P3fArraySample &iSmp )
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();
213  m_numU = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
214  m_numV = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
215  m_uOrder = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
216  m_vOrder = ABC_GEOM_NUPATCH_NULL_INT_VALUE;
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) ||
254  (m_numV != 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
281  int32_t m_trimNumLoops;
292 
293  // bounds
295  };
296 
297  //-*************************************************************************
298  // NuPatch SCHEMA
299  //-*************************************************************************
300 
301 public:
302 
303  //! By convention we always define this_type in AbcGeom classes.
304  //! Used by unspecified-bool-type conversion below
307 
308  //-*************************************************************************
309  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
310  //-*************************************************************************
311 
312  //! The default constructor creates an empty ONuPatchSchema
313  //! ...
315  {
316  m_selectiveExport = false;
317  m_numSamples = 0;
318  m_timeSamplingIndex = 0;
319  }
320 
321  //! This constructor creates a new poly mesh writer.
322  //! The first argument is an CompoundPropertyWriterPtr to use as a parent.
323  //! The next is the name to give the schema which is usually the default
324  //! name given by OFaceSet (.geom) The remaining optional arguments
325  //! can be used to override the ErrorHandlerPolicy, to specify
326  //! MetaData, specify sparse sampling and to set TimeSampling.
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 
334  //! This constructor creates a new poly mesh writer.
335  //! The first argument is an OCompundProperty to use as a parent, and from
336  //! which the ErrorHandlerPolicy is derived. The next is the name to give
337  //! the schema which is usually the default name given by OFaceSet (.geom)
338  //! The remaining optional arguments can be used to specify MetaData,
339  //! specify sparse sampling and to set TimeSampling.
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 
346  //! Copy constructor.
348  : OGeomBaseSchema<NuPatchSchemaInfo>()
349  {
350  *this = iCopy;
351  }
352 
353  //-*************************************************************************
354  // SCHEMA STUFF
355  //-*************************************************************************
356 
357  //! Return the time sampling type, which is stored on each of the
358  //! sub properties.
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 );
372  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
373 
374  //-*************************************************************************
375  // SAMPLE STUFF
376  //-*************************************************************************
377 
378  //! Get number of samples written so far.
379  //! ...
380  size_t getNumSamples() const
381  {
382  return m_numSamples;
383  }
384 
385  //! Set a sample!
386  void set( const sample_type &iSamp );
387 
388  //! Set from previous sample. Will apply to each of positions,
389  //! indices, and counts.
390  void setFromPrevious();
391 
392  //-*************************************************************************
393  // ABC BASE MECHANISMS
394  // These functions are used by Abc to deal with errors, validity,
395  // and so on.
396  //-*************************************************************************
397 
398  //! Reset returns this function set to an empty, default
399  //! state.
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 
429  //! Valid returns whether this function set is
430  //! valid.
431  bool valid() const
432  {
434  m_positionsProperty.valid() ) ||
435  m_selectiveExport );
436  }
437 
438  //! unspecified-bool-type operator overload.
439  //! ...
441 
442 protected:
443  void init( const AbcA::index_t iTsIdx, bool isSparse );
444 
445  //! Set only some property data. Does not need to be a valid schema sample
446  //! This is to be used when created a file which will be layered in to
447  //! another file.
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
455  size_t m_numSamples;
456 
458 
459  void createPositionProperties();
460  void createKnotProperties();
461  void createVelocityProperty();
462  void createUVsProperty( const Sample &iSamp );
463  void createNormalsProperty( const Sample &iSamp );
464  void createPositionWeightsProperty();
465  void createTrimPropreties();
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 
504 typedef Util::shared_ptr< ONuPatch > ONuPatchPtr;
505 
506 } // End namespace ALEMBIC_VERSION_NS
507 
508 using namespace ALEMBIC_VERSION_NS;
509 
510 } // End namespace AbcGeom
511 } // End namespace Alembic
512 
513 #endif
const Abc::FloatArraySample & getPositionWeights() const
Definition: ONuPatch.h:109
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
const Abc::V3fArraySample & getVelocities() const
Definition: ONuPatch.h:160
const Abc::FloatArraySample & getTrimV() const
Definition: ONuPatch.h:201
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: ONuPatch.h:359
#define ALEMBIC_EXPORT
Definition: Export.h:51
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: ONuPatch.h:161
const Abc::FloatArraySample & getVKnot() const
Definition: ONuPatch.h:140
const Abc::FloatArraySample & getTrimKnot() const
Definition: ONuPatch.h:197
const Abc::FloatArraySample & getTrimMin() const
Definition: ONuPatch.h:198
Abc::OSchemaObject< ONuPatchSchema > ONuPatch
Definition: ONuPatch.h:502
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
void setNormals(const ON3fGeomParam::Sample &iNormals)
Definition: ONuPatch.h:151
GLboolean reset
Definition: glad.h:5138
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: ONuPatch.h:105
Abc::OInt32ArrayProperty m_trimNumVerticesProperty
Definition: ONuPatch.h:488
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: ONuPatch.h:146
#define ALEMBIC_EXPORT_CONST
Definition: Export.h:53
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
const Abc::FloatArraySample & getTrimMax() const
Definition: ONuPatch.h:199
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 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::FloatArraySample & getTrimW() const
Definition: ONuPatch.h:202
const Abc::Int32ArraySample & getTrimNumCurves() const
Definition: ONuPatch.h:191
const ON3fGeomParam::Sample & getNormals() const
Definition: ONuPatch.h:150
Box< V3d > Box3d
3D box of base type double.
Definition: ImathBox.h:167
const Abc::P3fArraySample & getPositions() const
Definition: ONuPatch.h:104
Util::shared_ptr< ONuPatch > ONuPatchPtr
Definition: ONuPatch.h:504
const OV2fGeomParam::Sample & getUVs() const
Definition: ONuPatch.h:145
const Abc::FloatArraySample & getTrimU() const
Definition: ONuPatch.h:200
void setPositionWeights(const Abc::FloatArraySample &iSmp)
Definition: ONuPatch.h:111
const Abc::FloatArraySample & getUKnot() const
Definition: ONuPatch.h:135
const Abc::Int32ArraySample & getTrimNumVertices() const
Definition: ONuPatch.h:193
const Abc::Int32ArraySample & getTrimOrder() const
Definition: ONuPatch.h:195
void setVKnot(const Abc::FloatArraySample &iVKnot)
Definition: ONuPatch.h:141
ONuPatchSchema(const ONuPatchSchema &iCopy)
Copy constructor.
Definition: ONuPatch.h:347
Abc::OFloatArrayProperty m_positionWeightsProperty
Definition: ONuPatch.h:480
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
void setUKnot(const Abc::FloatArraySample &iUKnot)
Definition: ONuPatch.h:136
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr