HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OCurves.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2013,
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_OCurves_h_
38 #define _Alembic_AbcGeom_OCurves_h_
39 
40 #include <Alembic/Util/Export.h>
42 #include <Alembic/AbcGeom/Basis.h>
47 
48 namespace Alembic {
49 namespace AbcGeom {
50 namespace ALEMBIC_VERSION_NS {
51 
52 //-*****************************************************************************
53 // Curves definition - Similar in form to the Geometric primitive used to
54 // specify curves in renderman.
55 // "type" - linear or cubic, one type for all curves
56 // "wrap" - periodic or nonperiodic, one mode for all curves
57 // ---
58 // "P" - vertexes for the curves being written
59 // "width" - can be constant or can vary
60 // "N" - (just like PolyMesh, via a geom parameter) Normals
61 // "uv" - (just like PolyMesh, via a geom parameter) u-v coordinates
62 class ALEMBIC_EXPORT OCurvesSchema : public OGeomBaseSchema<CurvesSchemaInfo>
63 {
64 public:
65  //-*************************************************************************
66  // CURVE SCHEMA SAMPLE TYPE
67  //-*************************************************************************
68  class Sample
69  {
70  public:
71  //! Creates a default sample with no data in it.
72  //! ...
74  {
75  // even though this might not be written out
76  // (unless curvesNumVertices and points is set) give some reasonable
77  // and predictable defaults
78  reset();
79  m_type = kCubic;
80  m_wrap = kNonPeriodic;
81  m_basis = kBezierBasis;
82  }
83 
84  //! Creates a sample with position data but no index
85  //! or count data. For specifying samples after the first one
86  Sample( const Abc::P3fArraySample &iPos )
87  : m_positions( iPos )
88  {
89  // even though this might not be written out
90  // (unless curvesNumVertices is set) give some reasonable
91  // and predictable defaults
92  m_type = kCubic;
93  m_wrap = kNonPeriodic;
94  m_basis = kBezierBasis;
95  }
96 
97 
98  //! Creates a sample with position data, index data, count data,
99  //! and optional UV and Normals data.
100  //! For specifying samples with an explicit topology. The first
101  //! sample must be full like this. Subsequent samples may also
102  //! be full like this, which would indicate a change of topology
104  const Abc::P3fArraySample &iPos,
105  const Abc::Int32ArraySample &iNVertices,
106  const CurveType &iType = kCubic,
107  const CurvePeriodicity iWrap = kNonPeriodic,
108  const OFloatGeomParam::Sample &iWidths = \
109  OFloatGeomParam::Sample(),
110  const OV2fGeomParam::Sample &iUVs = OV2fGeomParam::Sample(),
111  const ON3fGeomParam::Sample &iNormals = ON3fGeomParam::Sample(),
112  const BasisType &iBasis = kBezierBasis,
113  const Abc::FloatArraySample &iPosWeight = \
115  const Abc::UcharArraySample &iOrders = Abc::UcharArraySample(),
117  ): m_positions( iPos ),
118  m_nVertices( iNVertices ),
119  m_type( iType ),
120  m_wrap( iWrap ),
121  m_widths( iWidths ),
122  m_uvs( iUVs ),
123  m_normals( iNormals ),
124  m_basis( iBasis ),
125  m_positionWeights( iPosWeight ),
126  m_orders( iOrders ),
127  m_knots( iKnots ) {}
128 
129  // widths accessor
130  const OFloatGeomParam::Sample &getWidths() const { return m_widths; }
131  void setWidths( const OFloatGeomParam::Sample &iWidths )
132  { m_widths = iWidths; }
133 
134  // positions accessor
135  const Abc::P3fArraySample &getPositions() const { return m_positions; }
136  void setPositions( const Abc::P3fArraySample &iSmp )
137  { m_positions = iSmp; }
138 
139  // position weights, if it isn't set, it's 1 for every point
141  { return m_positionWeights; }
142 
143  // type accessors
144  void setType( const CurveType &iType )
145  { m_type = iType; }
146  CurveType getType() const { return m_type; }
147 
148  // wrap accessors
149  void setWrap( const CurvePeriodicity &iWrap )
150  { m_wrap = iWrap; }
151  CurvePeriodicity getWrap() const { return m_wrap; }
152 
153  std::size_t getNumCurves() const { return m_nVertices.size(); }
154 
155  //! an array of ints that corresponds to the number
156  //! of vertices per curve
158  { m_nVertices = iNVertices; }
160  { return m_nVertices; }
161 
162  // UVs
163  const OV2fGeomParam::Sample &getUVs() const { return m_uvs; }
164  void setUVs( const OV2fGeomParam::Sample &iUVs )
165  { m_uvs = iUVs; }
166 
167  // bounding box accessors
168  const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
169  void setSelfBounds( const Abc::Box3d &iBnds )
170  { m_selfBounds = iBnds; }
171 
172  // velocities accessor
173  const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
174  void setVelocities( const Abc::V3fArraySample &iVelocities )
175  { m_velocities = iVelocities; }
176 
177  // normal accessors
178  const ON3fGeomParam::Sample &getNormals() const { return m_normals; }
179  void setNormals( const ON3fGeomParam::Sample &iNormals )
180  { m_normals = iNormals; }
181 
182  // basis accessors
183  BasisType getBasis() const { return m_basis; }
184  void setBasis( const BasisType &iBasis )
185  { m_basis = iBasis; }
186 
187  // orders accessors
188  const Abc::UcharArraySample &getOrders() const { return m_orders; }
189  void setOrders( const Abc::UcharArraySample &iOrders)
190  { m_orders = iOrders; }
191 
192  // knot accessors
193  const Abc::FloatArraySample &getKnots() const { return m_knots; }
194  void setKnots( const Abc::FloatArraySample &iKnots)
195  { m_knots = iKnots; }
196 
197  void reset()
198  {
199  m_positions.reset();
200  m_positionWeights.reset();
201  m_velocities.reset();
202  m_uvs.reset();
203  m_normals.reset();
204  m_widths.reset();
205 
206  m_nVertices.reset();
207 
208  m_orders.reset();
209  m_knots.reset();
210 
211  m_selfBounds.makeEmpty();
212 
213  m_type = kCubic;
214  m_wrap = kNonPeriodic;
215  m_basis = kBezierBasis;
216  }
217 
218  protected:
219 
220  // properties
224 
227 
228  OFloatGeomParam::Sample m_widths;
229  OV2fGeomParam::Sample m_uvs;
230  ON3fGeomParam::Sample m_normals;
231 
233 
234  // optional properties
238 
239  // bounding box attributes
241 
242  };
243 
244  //-*************************************************************************
245  // CURVE SCHEMA
246  //-*************************************************************************
247 
248 public:
249 
250  //! By convention we always define this_type in AbcGeom classes.
251  //! Used by unspecified-bool-type conversion below
254 
255  //-*************************************************************************
256  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
257  //-*************************************************************************
258 
259  //! The default constructor creates an empty OCurvesSchema
260  //! ...
262 
263  //! This templated, primary constructor creates a new poly mesh writer.
264  //! The first argument is any Abc (or AbcCoreAbstract) object
265  //! which can intrusively be converted to an CompoundPropertyWriterPtr
266  //! to use as a parent, from which the error handler policy for
267  //! inheritance is also derived. The remaining optional arguments
268  //! can be used to override the ErrorHandlerPolicy, to specify
269  //! MetaData, and to set TimeSamplingType.
270  template <class CPROP_PTR>
271  OCurvesSchema( CPROP_PTR iParent,
272  const std::string &iName,
273  const Abc::Argument &iArg0 = Abc::Argument(),
274  const Abc::Argument &iArg1 = Abc::Argument(),
275  const Abc::Argument &iArg2 = Abc::Argument() )
276  : OGeomBaseSchema<CurvesSchemaInfo>( iParent, iName,
277  iArg0, iArg1, iArg2 )
278  {
279  // Meta data and error handling are eaten up by
280  // the super type, so all that's left is time sampling.
281  AbcA::TimeSamplingPtr tsPtr =
282  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
283 
284  AbcA::index_t tsIndex =
285  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
286 
287  if ( tsPtr )
288  {
289  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
290  )->getArchive()->addTimeSampling( *tsPtr );
291  }
292 
293  init( tsIndex );
294  }
295 
296  template <class CPROP_PTR>
297  explicit OCurvesSchema( CPROP_PTR iParent,
298  const Abc::Argument &iArg0 = Abc::Argument(),
299  const Abc::Argument &iArg1 = Abc::Argument(),
300  const Abc::Argument &iArg2 = Abc::Argument() )
301  : OGeomBaseSchema<CurvesSchemaInfo>( iParent,
302  iArg0, iArg1, iArg2 )
303  {
304  // Meta data and error handling are eaten up by
305  // the super type, so all that's left is time sampling.
306  AbcA::TimeSamplingPtr tsPtr =
307  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
308 
309  AbcA::index_t tsIndex =
310  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
311 
312  if ( tsPtr )
313  {
314  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
315  )->getArchive()->addTimeSampling( *tsPtr );
316  }
317 
318  init( tsIndex );
319  }
320 
321  OCurvesSchema( const OCurvesSchema& iCopy )
322  : OGeomBaseSchema<CurvesSchemaInfo>()
323  {
324  *this = iCopy;
325  }
326 
327  //! Default assignment operator used.
328 
329  //-*************************************************************************
330  // SCHEMA STUFF
331  //-*************************************************************************
332 
333  //! Return the time sampling type, which is stored on each of the
334  //! sub properties.
336  { return m_positionsProperty.getTimeSampling(); }
337 
338  void setTimeSampling( uint32_t iIndex );
339  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
340 
341  //-*************************************************************************
342  // SAMPLE STUFF
343  //-*************************************************************************
344 
345  //! Get number of samples written so far.
346  //! ...
347  size_t getNumSamples() const
348  { return m_positionsProperty.getNumSamples(); }
349 
350  //! Set a sample! Sample zero has to have non-degenerate
351  //! positions, indices and counts.
352  void set( const sample_type &iSamp );
353 
354  //! Set from previous sample. Will apply to each of positions,
355  //! indices, and counts.
356  void setFromPrevious();
357 
358  //-*************************************************************************
359  // ABC BASE MECHANISMS
360  // These functions are used by Abc to deal with errors, validity,
361  // and so on.
362  //-*************************************************************************
363 
364  //! Reset returns this function set to an empty, default
365  //! state.
366  void reset()
367  {
368  m_positionsProperty.reset();
369  m_positionWeightsProperty.reset();
370  m_uvsParam.reset();
371  m_normalsParam.reset();
372  m_widthsParam.reset();
373  m_nVerticesProperty.reset();
374  m_ordersProperty.reset();
375  m_knotsProperty.reset();
376 
377  m_basisAndTypeProperty.reset();
378 
380  }
381 
382  //! Valid returns whether this function set is
383  //! valid.
384  bool valid() const
385  {
387  m_positionsProperty.valid() );
388  }
389 
390  //! unspecified-bool-type operator overload.
391  //! ...
392  ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
393 
394 protected:
395  void init( const AbcA::index_t iTsIdx );
396 
397  // point data
400 
401  // optional data
409 
411 };
412 
413 //-*****************************************************************************
414 // SCHEMA OBJECT
415 //-*****************************************************************************
417 
418 typedef Util::shared_ptr< OCurves > OCurvesPtr;
419 
420 } // End namespace ALEMBIC_VERSION_NS
421 
422 using namespace ALEMBIC_VERSION_NS;
423 
424 } // End namespace AbcGeom
425 } // End namespace Alembic
426 
427 #endif
OCurvesSchema(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: OCurves.h:271
void setKnots(const Abc::FloatArraySample &iKnots)
Definition: OCurves.h:194
const OV2fGeomParam::Sample & getUVs() const
Definition: OCurves.h:163
Abc::OSchemaObject< OCurvesSchema > OCurves
Definition: OCurves.h:416
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Util::shared_ptr< OCurves > OCurvesPtr
Definition: OCurves.h:418
void setOrders(const Abc::UcharArraySample &iOrders)
Definition: OCurves.h:189
const Abc::V3fArraySample & getVelocities() const
Definition: OCurves.h:173
void setWidths(const OFloatGeomParam::Sample &iWidths)
Definition: OCurves.h:131
const Abc::Int32ArraySample & getCurvesNumVertices() const
Definition: OCurves.h:159
const ON3fGeomParam::Sample & getNormals() const
Definition: OCurves.h:178
const Abc::P3fArraySample & getPositions() const
Definition: OCurves.h:135
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: OCurves.h:174
OCurvesSchema(const OCurvesSchema &iCopy)
Definition: OCurves.h:321
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: OCurves.h:164
const Abc::FloatArraySample & getKnots() const
Definition: OCurves.h:193
void setWrap(const CurvePeriodicity &iWrap)
Definition: OCurves.h:149
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
Box< V3d > Box3d
Definition: ImathBox.h:139
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment operator used.
Definition: OCurves.h:335
const Abc::FloatArraySample & getPositionWeights() const
Definition: OCurves.h:140
OCurvesSchema(CPROP_PTR iParent, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: OCurves.h:297
void setCurvesNumVertices(const Abc::Int32ArraySample &iNVertices)
Definition: OCurves.h:157
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:259
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: OCurves.h:136
const OFloatGeomParam::Sample & getWidths() const
Definition: OCurves.h:130
void setNormals(const ON3fGeomParam::Sample &iNormals)
Definition: OCurves.h:179
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
Abc::OFloatArrayProperty m_positionWeightsProperty
Definition: OCurves.h:406
#define ALEMBIC_EXPORT
Definition: Export.h:51
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:272
const Abc::UcharArraySample & getOrders() const
Definition: OCurves.h:188
Sample(const Abc::P3fArraySample &iPos, const Abc::Int32ArraySample &iNVertices, const CurveType &iType=kCubic, const CurvePeriodicity iWrap=kNonPeriodic, const OFloatGeomParam::Sample &iWidths=OFloatGeomParam::Sample(), const OV2fGeomParam::Sample &iUVs=OV2fGeomParam::Sample(), const ON3fGeomParam::Sample &iNormals=ON3fGeomParam::Sample(), const BasisType &iBasis=kBezierBasis, const Abc::FloatArraySample &iPosWeight=Abc::FloatArraySample(), const Abc::UcharArraySample &iOrders=Abc::UcharArraySample(), const Abc::FloatArraySample &iKnots=Abc::FloatArraySample())
Definition: OCurves.h:103
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104