HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OSubD.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2014,
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_OSubD_h_
38 #define _Alembic_AbcGeom_OSubD_h_
39 
40 #include <map>
41 #include <Alembic/Util/Export.h>
47 
48 namespace Alembic {
49 namespace AbcGeom {
50 namespace ALEMBIC_VERSION_NS {
51 
52 //-*****************************************************************************
53 // for default values for int scalar properties here
55 int32_t ABC_GEOM_SUBD_NULL_INT_VALUE( INT_MIN / 2 );
56 
57 //-*****************************************************************************
58 class ALEMBIC_EXPORT OSubDSchema : public OGeomBaseSchema<SubDSchemaInfo>
59 {
60 public:
61  //-*************************************************************************
62  // SUBD SCHEMA SAMPLE TYPE
63  //-*************************************************************************
64  class Sample
65  {
66  public:
67  //! Creates a default sample with no data in it.
68  //! ...
69  Sample() { reset(); }
70 
71  //! Creates a sample with position data, index data, and count data.
72  //! For specifying samples with an explicit topology. The first
73  //! sample must be full like this. Subsequent samples may also
74  //! be full like this, which would indicate a change of topology
75  Sample( const Abc::P3fArraySample &iPositions,
76  const Abc::Int32ArraySample &iFaceIndices,
77  const Abc::Int32ArraySample &iFaceCounts,
78 
79  const Abc::Int32ArraySample &iCreaseIndices =
81  const Abc::Int32ArraySample &iCreaseLengths =
83  const Abc::FloatArraySample &iCreaseSharpnesses =
85 
86  const Abc::Int32ArraySample &iCornerIndices =
88  const Abc::FloatArraySample &iCornerSharpnesses =
90 
92  )
93 
94  : m_positions( iPositions )
95  , m_faceIndices( iFaceIndices )
96  , m_faceCounts( iFaceCounts )
97  , m_faceVaryingInterpolateBoundary( ABC_GEOM_SUBD_NULL_INT_VALUE )
98  , m_faceVaryingPropagateCorners( ABC_GEOM_SUBD_NULL_INT_VALUE )
99  , m_interpolateBoundary( ABC_GEOM_SUBD_NULL_INT_VALUE )
100  , m_creaseIndices ( iCreaseIndices )
101  , m_creaseLengths ( iCreaseLengths )
102  , m_creaseSharpnesses ( iCreaseSharpnesses )
103  , m_cornerIndices ( iCornerIndices )
104  , m_cornerSharpnesses ( iCornerSharpnesses )
105  , m_holes ( iHoles )
106  , m_subdScheme ( "catmull-clark" )
107  {}
108 
109  // main stuff
110  const Abc::P3fArraySample &getPositions() const { return m_positions; }
111  void setPositions( const Abc::P3fArraySample &iSmp )
112  { m_positions = iSmp; }
113 
114  const Abc::Int32ArraySample &getFaceIndices() const { return m_faceIndices; }
116  { m_faceIndices = iSmp; }
117 
118  const Abc::Int32ArraySample &getFaceCounts() const { return m_faceCounts; }
120  { m_faceCounts = iCnt; }
121 
122 
123  // misc subd stuff
125  { return m_faceVaryingInterpolateBoundary; }
127  { m_faceVaryingInterpolateBoundary = i; }
128 
130  { return m_faceVaryingPropagateCorners; }
132  { m_faceVaryingPropagateCorners = i; }
133 
134  int32_t getInterpolateBoundary() const
135  { return m_interpolateBoundary; }
136  void setInterpolateBoundary( int32_t i )
137  { m_interpolateBoundary = i; }
138 
139  // creases
141  { return m_creaseIndices; }
142  void setCreaseIndices( const Abc::Int32ArraySample &iCreaseIndices )
143  { m_creaseIndices = iCreaseIndices; }
144 
146  { return m_creaseLengths; }
147  void setCreaseLengths( const Abc::Int32ArraySample &iCreaseLengths )
148  { m_creaseLengths = iCreaseLengths; }
149 
151  { return m_creaseSharpnesses; }
153  &iCreaseSharpnesses )
154  { m_creaseSharpnesses = iCreaseSharpnesses; }
155 
156  void setCreases( const Abc::Int32ArraySample &iCreaseIndices,
157  const Abc::Int32ArraySample &iCreaseLengths )
158  {
159  m_creaseIndices = iCreaseIndices;
160  m_creaseLengths = iCreaseLengths;
161  }
162 
163  void setCreases( const Abc::Int32ArraySample &iCreaseIndices,
164  const Abc::Int32ArraySample &iCreaseLengths,
165  const Abc::FloatArraySample &iCreaseSharpnesses )
166  {
167  m_creaseIndices = iCreaseIndices;
168  m_creaseLengths = iCreaseLengths;
169  m_creaseSharpnesses = iCreaseSharpnesses;
170  }
171 
172  // corners
174  { return m_cornerIndices; }
175  void setCornerIndices( const Abc::Int32ArraySample &iCornerIndices )
176  { m_cornerIndices = iCornerIndices; }
177 
179  { return m_cornerSharpnesses; }
181  &iCornerSharpnesses )
182  { m_cornerSharpnesses = iCornerSharpnesses; }
183 
184  void setCorners( const Abc::Int32ArraySample &iCornerIndices,
185  const Abc::FloatArraySample &iCornerSharpnesses )
186  {
187  m_cornerIndices = iCornerIndices;
188  m_cornerSharpnesses = iCornerSharpnesses;
189  }
190 
191  // Holes
193  { return m_holes; }
194  void setHoles( const Abc::Int32ArraySample &iHoles )
195  { m_holes = iHoles; }
196 
197  // subdivision scheme
199  { return m_subdScheme; }
200  void setSubdivisionScheme( const std::string &iScheme )
201  { m_subdScheme = iScheme; }
202 
203  // bounding boxes
204  const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
205  void setSelfBounds( const Abc::Box3d &iBnds )
206  { m_selfBounds = iBnds; }
207 
208  // velocities accessor
209  const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
210  void setVelocities( const Abc::V3fArraySample &iVelocities )
211  { m_velocities = iVelocities; }
212 
213  // UVs; need to set these outside the Sample constructor
214  const OV2fGeomParam::Sample &getUVs() const { return m_uvs; }
215  void setUVs( const OV2fGeomParam::Sample &iUVs )
216  { m_uvs = iUVs; }
217 
218  void reset()
219  {
220  m_positions.reset();
221  m_faceIndices.reset();
222  m_faceCounts.reset();
223 
224  m_faceVaryingInterpolateBoundary = 0;
225  m_faceVaryingPropagateCorners = 0;
226  m_interpolateBoundary = 0;
227 
228  m_creaseIndices.reset();
229  m_creaseLengths.reset();
230  m_creaseSharpnesses.reset();
231 
232  m_cornerIndices.reset();
233  m_cornerSharpnesses.reset();
234 
235  m_holes.reset();
236 
237  m_subdScheme = "catmull-clark";
238 
239  m_velocities.reset();
240 
241  m_selfBounds.makeEmpty();
242 
243  m_uvs.reset();
244  }
245 
246  protected:
247  friend class OSubDSchema;
248 
252 
256 
257  // Creases
261 
262  // Corners
265 
266  // Holes
268 
269  // subdivision scheme
271 
272  // bounds
274 
276 
277  // UVs
278  OV2fGeomParam::Sample m_uvs;
279 
280  }; // end OSubDSchema::Sample
281 
282  //-*************************************************************************
283  // SUBD SCHEMA
284  //-*************************************************************************
285 public:
286  //! By convention we always define this_type in AbcGeom classes.
287  //! Used by unspecified-bool-type conversion below
289 
290  //-*************************************************************************
291  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
292  //-*************************************************************************
293 
294  //! The default constructor creates an empty OSubDSchema
295  //! ...
297 
298  //! This templated, primary constructor creates a new poly mesh writer.
299  //! The first argument is any Abc (or AbcCoreAbstract) object
300  //! which can intrusively be converted to an CompoundPropertyWriterPtr
301  //! to use as a parent, from which the error handler policy for
302  //! inheritance is also derived. The remaining optional arguments
303  //! can be used to override the ErrorHandlerPolicy, to specify
304  //! MetaData, and to set TimeSamplingType.
305  template <class CPROP_PTR>
306  OSubDSchema( CPROP_PTR iParent,
307  const std::string &iName,
308 
309  const Abc::Argument &iArg0 = Abc::Argument(),
310  const Abc::Argument &iArg1 = Abc::Argument(),
311  const Abc::Argument &iArg2 = Abc::Argument() )
312  : OGeomBaseSchema<SubDSchemaInfo>(
313  GetCompoundPropertyWriterPtr( iParent ),
314  iName, iArg0, iArg1, iArg2 )
315  {
316 
317  AbcA::TimeSamplingPtr tsPtr =
318  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
319  uint32_t tsIndex =
320  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
321 
322  // if we specified a valid TimeSamplingPtr, use it to determine the
323  // index otherwise we'll use the index, which defaults to the intrinsic
324  // 0 index
325  if (tsPtr)
326  {
327  tsIndex = GetCompoundPropertyWriterPtr( iParent )
328  ->getObject()->getArchive()->addTimeSampling(*tsPtr);
329  }
330 
331  // Meta data and error handling are eaten up by
332  // the super type, so all that's left is time sampling.
333  init( tsIndex );
334  }
335 
336  template <class CPROP_PTR>
337  explicit OSubDSchema( CPROP_PTR iParent,
338  const Abc::Argument &iArg0 = Abc::Argument(),
339  const Abc::Argument &iArg1 = Abc::Argument(),
340  const Abc::Argument &iArg2 = Abc::Argument() )
341  : OGeomBaseSchema<SubDSchemaInfo>(
342  GetCompoundPropertyWriterPtr( iParent ),
343  iArg0, iArg1, iArg2 )
344  {
345  AbcA::TimeSamplingPtr tsPtr =
346  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
347  uint32_t tsIndex =
348  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
349 
350  // if we specified a valid TimeSamplingPtr, use it to determine the
351  // index otherwise we'll use the index, which defaults to the intrinsic
352  // 0 index
353  if (tsPtr)
354  {
355  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
356  )->getArchive()->addTimeSampling(*tsPtr);
357  }
358 
359  // Meta data and error handling are eaten up by
360  // the super type, so all that's left is time sampling.
361  init( tsIndex );
362  }
363 
364  //! Copy constructor.
365  OSubDSchema(const OSubDSchema& iCopy)
366  : OGeomBaseSchema<SubDSchemaInfo>()
367  {
368  *this = iCopy;
369  }
370 
371  //! Default assignment operator used.
372 
373  //-*************************************************************************
374  // SCHEMA STUFF
375  //-*************************************************************************
376 
377  //! Return the time sampling, which is stored on each of the
378  //! sub properties.
380  { return m_positionsProperty.getTimeSampling(); }
381 
382  //-*************************************************************************
383  // SAMPLE STUFF
384  //-*************************************************************************
385 
386  //! Get number of samples written so far.
387  //! ...
388  size_t getNumSamples() const
389  { return m_positionsProperty.getNumSamples(); }
390 
391  //! Set a sample! Sample zero has to have non-degenerate
392  //! positions, indices and counts.
393  void set( const Sample &iSamp );
394 
395  //! Set from previous sample. Will apply to each of positions,
396  //! indices, and counts.
397  void setFromPrevious( );
398 
399  void setTimeSampling( uint32_t iIndex );
400  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
401 
402  //-*************************************************************************
403  // ABC BASE MECHANISMS
404  // These functions are used by Abc to deal with errors, validity,
405  // and so on.
406  //-*************************************************************************
407 
408  //! Reset returns this function set to an empty, default
409  //! state.
410  void reset()
411  {
412  m_positionsProperty.reset();
413  m_faceIndicesProperty.reset();
414  m_faceCountsProperty.reset();
415 
416  m_faceVaryingInterpolateBoundaryProperty.reset();
417  m_faceVaryingPropagateCornersProperty.reset();
418  m_interpolateBoundaryProperty.reset();
419 
420  m_creaseIndicesProperty.reset();
421  m_creaseLengthsProperty.reset();
422  m_creaseSharpnessesProperty.reset();
423 
424  m_cornerIndicesProperty.reset();
425  m_cornerSharpnessesProperty.reset();
426 
427  m_holesProperty.reset();
428 
429  m_subdSchemeProperty.reset();
430 
431  m_velocitiesProperty.reset();
432 
433  m_uvsParam.reset();
434 
435  m_faceSets.clear ();
436 
438  }
439 
440  //! Valid returns whether this function set is
441  //! valid.
442  bool valid() const
443  {
445  m_positionsProperty.valid() &&
446  m_faceIndicesProperty.valid() &&
447  m_faceCountsProperty.valid() );
448  }
449 
450  // FaceSet stuff
451  OFaceSet & createFaceSet( const std::string &iFaceSetName );
452  //! Appends the names of any FaceSets for this SubD.
453  void getFaceSetNames( std::vector <std::string> & oFaceSetNames );
454  OFaceSet getFaceSet( const std::string &iFaceSetName );
455  bool hasFaceSet( const std::string &iFaceSetName );
456 
457 
458  //! Optional source name for the UV param.
459  //! Must be set before the first UV sample is set.
460  void setUVSourceName(const std::string & iName);
461 
462  //! unspecified-bool-type operator overload.
463  //! ...
465 
466 protected:
467  void init( uint32_t iTsIdx );
468 
472 
473  // misc
477 
478  // Creases
482 
483  // Corners
486 
487  // Holes
489 
490  // subdivision scheme
492 
494 
495  // UVs
497 
498 
499  // optional source name for the UVs
501 
502 private:
503  void initCreases(uint32_t iNumSamples);
504  void initCorners(uint32_t iNumSamples);
505  void initHoles(uint32_t iNumSamples);
506 
507  // FaceSets created on this SubD
508  std::map <std::string, OFaceSet> m_faceSets;
509 
510  friend class OFaceSetSchema;;
511 };
512 
513 //-*****************************************************************************
514 // SCHEMA OBJECT
515 //-*****************************************************************************
517 
518 typedef Util::shared_ptr< OSubD > OSubDPtr;
519 
520 } // End namespace ALEMBIC_VERSION_NS
521 
522 using namespace ALEMBIC_VERSION_NS;
523 
524 } // End namespace AbcGeom
525 } // End namespace Alembic
526 
527 #endif
void setFaceCounts(const Abc::Int32ArraySample &iCnt)
Definition: OSubD.h:119
OSubDSchema(CPROP_PTR iParent, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: OSubD.h:337
void setHoles(const Abc::Int32ArraySample &iHoles)
Definition: OSubD.h:194
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Abc::OV3fArrayProperty m_velocitiesProperty
Definition: OSubD.h:493
Util::shared_ptr< OSubD > OSubDPtr
Definition: OSubD.h:518
Abc::OInt32Property m_faceVaryingPropagateCornersProperty
Definition: OSubD.h:475
const Abc::FloatArraySample & getCornerSharpnesses() const
Definition: OSubD.h:178
Abc::OFloatArrayProperty m_creaseSharpnessesProperty
Definition: OSubD.h:481
const Abc::V3fArraySample & getVelocities() const
Definition: OSubD.h:209
png_uint_32 i
Definition: png.h:2877
Sample(const Abc::P3fArraySample &iPositions, const Abc::Int32ArraySample &iFaceIndices, const Abc::Int32ArraySample &iFaceCounts, const Abc::Int32ArraySample &iCreaseIndices=Abc::Int32ArraySample(), const Abc::Int32ArraySample &iCreaseLengths=Abc::Int32ArraySample(), const Abc::FloatArraySample &iCreaseSharpnesses=Abc::FloatArraySample(), const Abc::Int32ArraySample &iCornerIndices=Abc::Int32ArraySample(), const Abc::FloatArraySample &iCornerSharpnesses=Abc::FloatArraySample(), const Abc::Int32ArraySample &iHoles=Abc::Int32ArraySample())
Definition: OSubD.h:75
Abc::OInt32ArrayProperty m_creaseIndicesProperty
Definition: OSubD.h:479
Abc::OInt32ArrayProperty m_faceCountsProperty
Definition: OSubD.h:471
const Abc::Int32ArraySample & getCreaseIndices() const
Definition: OSubD.h:140
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: OSubD.h:215
const Abc::P3fArraySample & getPositions() const
Definition: OSubD.h:110
const Abc::Int32ArraySample & getHoles() const
Definition: OSubD.h:192
const Abc::Int32ArraySample & getCornerIndices() const
Definition: OSubD.h:173
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
void setFaceIndices(const Abc::Int32ArraySample &iSmp)
Definition: OSubD.h:115
Abc::OInt32ArrayProperty m_faceIndicesProperty
Definition: OSubD.h:470
Abc::OFloatArrayProperty m_cornerSharpnessesProperty
Definition: OSubD.h:485
void setCreases(const Abc::Int32ArraySample &iCreaseIndices, const Abc::Int32ArraySample &iCreaseLengths)
Definition: OSubD.h:156
Abc::OP3fArrayProperty m_positionsProperty
Definition: OSubD.h:469
void setCorners(const Abc::Int32ArraySample &iCornerIndices, const Abc::FloatArraySample &iCornerSharpnesses)
Definition: OSubD.h:184
void setCornerIndices(const Abc::Int32ArraySample &iCornerIndices)
Definition: OSubD.h:175
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
void setSubdivisionScheme(const std::string &iScheme)
Definition: OSubD.h:200
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment operator used.
Definition: OSubD.h:379
void setCreaseIndices(const Abc::Int32ArraySample &iCreaseIndices)
Definition: OSubD.h:142
const Abc::Int32ArraySample & getCreaseLengths() const
Definition: OSubD.h:145
Box< V3d > Box3d
Definition: ImathBox.h:139
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: OSubD.h:210
#define ALEMBIC_EXPORT_CONST
Definition: Export.h:53
Abc::OInt32ArrayProperty m_creaseLengthsProperty
Definition: OSubD.h:480
void setCreases(const Abc::Int32ArraySample &iCreaseIndices, const Abc::Int32ArraySample &iCreaseLengths, const Abc::FloatArraySample &iCreaseSharpnesses)
Definition: OSubD.h:163
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:259
const Abc::Int32ArraySample & getFaceCounts() const
Definition: OSubD.h:118
void setCreaseSharpnesses(const Abc::FloatArraySample &iCreaseSharpnesses)
Definition: OSubD.h:152
Abc::OInt32Property m_interpolateBoundaryProperty
Definition: OSubD.h:476
Abc::OInt32Property m_faceVaryingInterpolateBoundaryProperty
Definition: OSubD.h:474
const Abc::FloatArraySample & getCreaseSharpnesses() const
Definition: OSubD.h:150
Abc::OSchemaObject< OSubDSchema > OSubD
Definition: OSubD.h:516
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: OSubD.h:111
void setCornerSharpnesses(const Abc::FloatArraySample &iCornerSharpnesses)
Definition: OSubD.h:180
void setCreaseLengths(const Abc::Int32ArraySample &iCreaseLengths)
Definition: OSubD.h:147
OSubDSchema(const OSubDSchema &iCopy)
Copy constructor.
Definition: OSubD.h:365
Abc::OInt32ArrayProperty m_cornerIndicesProperty
Definition: OSubD.h:484
#define ALEMBIC_EXPORT
Definition: Export.h:51
const Abc::Int32ArraySample & getFaceIndices() const
Definition: OSubD.h:114
Abc::OInt32ArrayProperty m_holesProperty
Definition: OSubD.h:488
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:272
const OV2fGeomParam::Sample & getUVs() const
Definition: OSubD.h:214
OSubDSchema(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: OSubD.h:306
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104