HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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
54 int32_t ABC_GEOM_NUPATCH_NULL_INT_VALUE( INT_MIN / 4 );
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  protected:
239 
240  // required properties
243  int32_t m_numU;
244  int32_t m_numV;
245  int32_t m_uOrder;
246  int32_t m_vOrder;
249 
250  // optional properties
252  ON3fGeomParam::Sample m_normals;
253  OV2fGeomParam::Sample m_uvs;
254 
255  // optional trim curves
256  int32_t m_trimNumLoops;
267 
268  // bounds
270  };
271 
272  //-*************************************************************************
273  // NuPatch SCHEMA
274  //-*************************************************************************
275 
276 public:
277 
278  //! By convention we always define this_type in AbcGeom classes.
279  //! Used by unspecified-bool-type conversion below
282 
283  //-*************************************************************************
284  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
285  //-*************************************************************************
286 
287  //! The default constructor creates an empty ONuPatchSchema
288  //! ...
290 
291  //! This templated, primary constructor creates a new poly mesh writer.
292  //! The first argument is any Abc (or AbcCoreAbstract) object
293  //! which can intrusively be converted to an CompoundPropertyWriterPtr
294  //! to use as a parent, from which the error handler policy for
295  //! inheritance is also derived. The remaining optional arguments
296  //! can be used to override the ErrorHandlerPolicy, to specify
297  //! MetaData, and to set TimeSamplingType.
298  template <class CPROP_PTR>
299  ONuPatchSchema( CPROP_PTR iParent,
300  const std::string &iName,
301  const Abc::Argument &iArg0 = Abc::Argument(),
302  const Abc::Argument &iArg1 = Abc::Argument(),
303  const Abc::Argument &iArg2 = Abc::Argument() )
304  : OGeomBaseSchema<NuPatchSchemaInfo>( iParent, iName,
305  iArg0, iArg1, iArg2 )
306  {
307 
308  // Meta data and error handling are eaten up by
309  // the super type, so all that's left is time sampling.
310  AbcA::TimeSamplingPtr tsPtr =
311  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
312 
313  AbcA::index_t tsIndex =
314  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
315 
316  if ( tsPtr )
317  {
318  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
319  )->getArchive()->addTimeSampling( *tsPtr );
320  }
321 
322  m_timeSamplingIndex = tsIndex;
323 
324  init( tsIndex );
325  }
326 
327  template <class CPROP_PTR>
328  explicit ONuPatchSchema( CPROP_PTR iParent,
329  const Abc::Argument &iArg0 = Abc::Argument(),
330  const Abc::Argument &iArg1 = Abc::Argument(),
331  const Abc::Argument &iArg2 = Abc::Argument() )
332  : OGeomBaseSchema<NuPatchSchemaInfo>( iParent, iArg0, iArg1, iArg2 )
333  {
334  // Meta data and error handling are eaten up by
335  // the super type, so all that's left is time sampling.
336  AbcA::TimeSamplingPtr tsPtr =
337  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
338 
339  AbcA::index_t tsIndex =
340  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
341 
342  if ( tsPtr )
343  {
344  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
345  )->getArchive()->addTimeSampling( *tsPtr );
346  }
347 
348  m_timeSamplingIndex = tsIndex;
349 
350  init( tsIndex );
351  }
352 
353  //! Copy constructor.
355  : OGeomBaseSchema<NuPatchSchemaInfo>()
356  {
357  *this = iCopy;
358  }
359 
360  //-*************************************************************************
361  // SCHEMA STUFF
362  //-*************************************************************************
363 
364  //! Return the time sampling type, which is stored on each of the
365  //! sub properties.
367  { return m_positionsProperty.getTimeSampling(); }
368 
369  void setTimeSampling( uint32_t iIndex );
370  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
371 
372  //-*************************************************************************
373  // SAMPLE STUFF
374  //-*************************************************************************
375 
376  //! Get number of samples written so far.
377  //! ...
378  size_t getNumSamples() const
379  { return m_positionsProperty.getNumSamples(); }
380 
381  //! Set a sample!
382  void set( const sample_type &iSamp );
383 
384  //! Set from previous sample. Will apply to each of positions,
385  //! indices, and counts.
386  void setFromPrevious();
387 
388  //-*************************************************************************
389  // ABC BASE MECHANISMS
390  // These functions are used by Abc to deal with errors, validity,
391  // and so on.
392  //-*************************************************************************
393 
394  //! Reset returns this function set to an empty, default
395  //! state.
396  void reset()
397  {
398  m_positionsProperty.reset();
399  m_positionWeightsProperty.reset();
400  m_velocitiesProperty.reset();
401  m_numUProperty.reset();
402  m_numVProperty.reset();
403  m_uOrderProperty.reset();
404  m_vOrderProperty.reset();
405  m_uKnotProperty.reset();
406  m_vKnotProperty.reset();
407 
408  m_normalsParam.reset();
409  m_uvsParam.reset();
410 
411  // reset trim curve attributes
412  m_trimNumLoopsProperty.reset();
413  m_trimNumVerticesProperty.reset();
414  m_trimOrderProperty.reset();
415  m_trimKnotProperty.reset();
416  m_trimMinProperty.reset();
417  m_trimMaxProperty.reset();
418  m_trimUProperty.reset();
419  m_trimVProperty.reset();
420  m_trimWProperty.reset();
421 
423  }
424 
425  //! Valid returns whether this function set is
426  //! valid.
427  bool valid() const
428  {
430  m_positionsProperty.valid() );
431  }
432 
433  //! unspecified-bool-type operator overload.
434  //! ...
436 
437 protected:
438  void init( const AbcA::index_t iTsIdx );
439 
441 
442  // point data
444 
445  // required properties
452 
453  // optional properties
458 
459  // optional trim curves
470 
471 };
472 
473 //-*****************************************************************************
474 // SCHEMA OBJECT
475 //-*****************************************************************************
477 
478 typedef Util::shared_ptr< ONuPatch > ONuPatchPtr;
479 
480 } // End namespace ALEMBIC_VERSION_NS
481 
482 using namespace ALEMBIC_VERSION_NS;
483 
484 } // End namespace AbcGeom
485 } // End namespace Alembic
486 
487 #endif
const Abc::FloatArraySample & getPositionWeights() const
Definition: ONuPatch.h:109
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
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:366
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:476
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
void setNormals(const ON3fGeomParam::Sample &iNormals)
Definition: ONuPatch.h:151
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: ONuPatch.h:105
Abc::OInt32ArrayProperty m_trimNumVerticesProperty
Definition: ONuPatch.h:462
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: ONuPatch.h:146
#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
ONuPatchSchema(CPROP_PTR iParent, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: ONuPatch.h:328
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
Definition: ImathBox.h:139
#define ALEMBIC_EXPORT_CONST
Definition: Export.h:53
const Abc::P3fArraySample & getPositions() const
Definition: ONuPatch.h:104
Util::shared_ptr< ONuPatch > ONuPatchPtr
Definition: ONuPatch.h:478
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:259
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
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
const Abc::Int32ArraySample & getTrimOrder() const
Definition: ONuPatch.h:195
void setVKnot(const Abc::FloatArraySample &iVKnot)
Definition: ONuPatch.h:141
#define ALEMBIC_EXPORT
Definition: Export.h:51
ONuPatchSchema(const ONuPatchSchema &iCopy)
Copy constructor.
Definition: ONuPatch.h:354
ONuPatchSchema(CPROP_PTR iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: ONuPatch.h:299
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:272
Abc::OFloatArrayProperty m_positionWeightsProperty
Definition: ONuPatch.h:454
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
void setUKnot(const Abc::FloatArraySample &iUKnot)
Definition: ONuPatch.h:136