HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OPolyMesh.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_OPolyMesh_h_
38 #define _Alembic_AbcGeom_OPolyMesh_h_
39 
40 #include <Alembic/Util/Export.h>
46 
47 namespace Alembic {
48 namespace AbcGeom {
49 namespace ALEMBIC_VERSION_NS {
50 
51 //-*****************************************************************************
53  : public OGeomBaseSchema<PolyMeshSchemaInfo>
54 {
55 public:
56  //-*************************************************************************
57  // POLY MESH SCHEMA SAMPLE TYPE
58  //-*************************************************************************
59  class Sample
60  {
61  public:
62  //! Creates a default sample with no data in it.
63  //! ...
64  Sample() { reset(); }
65 
66  //! Creates a sample with position data but no index
67  //! or count data. For specifying samples after the first one
68  Sample( const Abc::P3fArraySample &iPos )
69  : m_positions( iPos ) {}
70 
71 
72  //! Creates a sample with position data, index data, count data,
73  //! and optional UV and Normals data.
74  //! For specifying samples with an explicit topology. The first
75  //! sample must be full like this. Subsequent samples may also
76  //! be full like this, which would indicate a change of topology
78  const Abc::Int32ArraySample &iInd,
79  const Abc::Int32ArraySample &iCnt,
80  const OV2fGeomParam::Sample &iUVs = OV2fGeomParam::Sample(),
81  const ON3fGeomParam::Sample &iNormals = ON3fGeomParam::Sample() )
82  : m_positions( iPos )
83  , m_indices( iInd )
84  , m_counts( iCnt )
85  , m_uvs( iUVs )
86  , m_normals( iNormals )
87  {}
88 
89  const Abc::P3fArraySample &getPositions() const { return m_positions; }
90  void setPositions( const Abc::P3fArraySample &iSmp )
91  { m_positions = iSmp; }
92 
93  // velocities accessor
94  const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
95  void setVelocities( const Abc::V3fArraySample &iVelocities )
96  { m_velocities = iVelocities; }
97 
98  const Abc::Int32ArraySample &getFaceIndices() const { return m_indices; }
100  { m_indices = iSmp; }
101 
102  const Abc::Int32ArraySample &getFaceCounts() const { return m_counts; }
104  { m_counts = iCnt; }
105 
106  const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
107  void setSelfBounds( const Abc::Box3d &iBnds )
108  { m_selfBounds = iBnds; }
109 
110  const OV2fGeomParam::Sample &getUVs() const { return m_uvs; }
111  void setUVs( const OV2fGeomParam::Sample &iUVs )
112  { m_uvs = iUVs; }
113 
114  const ON3fGeomParam::Sample &getNormals() const { return m_normals; }
115  void setNormals( const ON3fGeomParam::Sample &iNormals )
116  { m_normals = iNormals; }
117 
118  void reset()
119  {
120  m_positions.reset();
121  m_indices.reset();
122  m_counts.reset();
123 
124  m_selfBounds.makeEmpty();
125 
126  m_velocities.reset();
127  m_uvs.reset();
128  m_normals.reset();
129  }
130 
131 
132  protected:
136 
138 
140  OV2fGeomParam::Sample m_uvs;
141  ON3fGeomParam::Sample m_normals;
142 
143  };
144 
145  //-*************************************************************************
146  // POLY MESH SCHEMA
147  //-*************************************************************************
148 public:
149  //! By convention we always define this_type in AbcGeom classes.
150  //! Used by unspecified-bool-type conversion below
152 
153  //-*************************************************************************
154  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
155  //-*************************************************************************
156 
157  //! The default constructor creates an empty OPolyMeshSchema
158  //! ...
160 
161  //! This templated, primary constructor creates a new poly mesh writer.
162  //! The first argument is any Abc (or AbcCoreAbstract) object
163  //! which can intrusively be converted to an CompoundPropertyWriterPtr
164  //! to use as a parent, from which the error handler policy for
165  //! inheritance is also derived. The remaining optional arguments
166  //! can be used to override the ErrorHandlerPolicy, to specify
167  //! MetaData, and to set TimeSamplingType.
168  template <class CPROP_PTR>
169  OPolyMeshSchema( CPROP_PTR iParent,
170  const std::string &iName,
171 
172  const Abc::Argument &iArg0 = Abc::Argument(),
173  const Abc::Argument &iArg1 = Abc::Argument(),
174  const Abc::Argument &iArg2 = Abc::Argument() )
175  : OGeomBaseSchema<PolyMeshSchemaInfo>(
176  GetCompoundPropertyWriterPtr( iParent ),
177  iName, iArg0, iArg1, iArg2 )
178  {
179 
180  AbcA::TimeSamplingPtr tsPtr =
181  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
182  uint32_t tsIndex =
183  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
184 
185  // if we specified a valid TimeSamplingPtr, use it to determine the
186  // index otherwise we'll use the index, which defaults to the intrinsic
187  // 0 index
188  if (tsPtr)
189  {
190  tsIndex = GetCompoundPropertyWriterPtr(iParent)->getObject(
191  )->getArchive()->addTimeSampling(*tsPtr);
192  }
193 
194  // Meta data and error handling are eaten up by
195  // the super type, so all that's left is time sampling.
196  init( tsIndex );
197  }
198 
199  template <class CPROP_PTR>
200  explicit OPolyMeshSchema( CPROP_PTR iParent,
201  const Abc::Argument &iArg0 = Abc::Argument(),
202  const Abc::Argument &iArg1 = Abc::Argument(),
203  const Abc::Argument &iArg2 = Abc::Argument() )
204  : OGeomBaseSchema<PolyMeshSchemaInfo>(
205  GetCompoundPropertyWriterPtr( iParent ),
206  iArg0, iArg1, iArg2 )
207  {
208 
209  AbcA::TimeSamplingPtr tsPtr =
210  Abc::GetTimeSampling( iArg0, iArg1, iArg2 );
211  uint32_t tsIndex =
212  Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2 );
213 
214  // if we specified a valid TimeSamplingPtr, use it to determine the
215  // index otherwise we'll use the index, which defaults to the intrinsic
216  // 0 index
217  if (tsPtr)
218  {
219  tsIndex = GetCompoundPropertyWriterPtr( iParent )->getObject(
220  )->getArchive()->addTimeSampling(*tsPtr);
221  }
222 
223  // Meta data and error handling are eaten up by
224  // the super type, so all that's left is time sampling.
225  init( tsIndex );
226  }
227 
228  //! Copy constructor.
230  : OGeomBaseSchema<PolyMeshSchemaInfo>()
231  {
232  *this = iCopy;
233  }
234 
235  //! Default assignment operator used.
236 
237  //-*************************************************************************
238  // SCHEMA STUFF
239  //-*************************************************************************
240 
241  //! Return the time sampling type, which is stored on each of the
242  //! sub properties.
244  { return m_positionsProperty.getTimeSampling(); }
245 
246  //-*************************************************************************
247  // SAMPLE STUFF
248  //-*************************************************************************
249 
250  //! Get number of samples written so far.
251  //! ...
252  size_t getNumSamples() const
253  { return m_positionsProperty.getNumSamples(); }
254 
255  //! Set a sample! Sample zero has to have non-degenerate
256  //! positions, indices and counts.
257  void set( const Sample &iSamp );
258 
259  //! Set from previous sample. Will apply to each of positions,
260  //! indices, and counts.
261  void setFromPrevious();
262 
263  void setTimeSampling( uint32_t iIndex );
264  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
265 
266  //-*************************************************************************
267  // ABC BASE MECHANISMS
268  // These functions are used by Abc to deal with errors, validity,
269  // and so on.
270  //-*************************************************************************
271 
272  //! Reset returns this function set to an empty, default
273  //! state.
274  void reset()
275  {
276  m_positionsProperty.reset();
277  m_velocitiesProperty.reset();
278  m_indicesProperty.reset();
279  m_countsProperty.reset();
280  m_uvsParam.reset();
281  m_normalsParam.reset();
282 
283  m_faceSets.clear();
284 
286  }
287 
288  //! Valid returns whether this function set is
289  //! valid.
290  bool valid() const
291  {
293  m_positionsProperty.valid() &&
294  m_indicesProperty.valid() &&
295  m_countsProperty.valid() );
296  }
297 
298  // FaceSet stuff
299  OFaceSet & createFaceSet( const std::string &iFaceSetName );
300  //! Appends the names of any FaceSets for this PolyMesh.
301  void getFaceSetNames (std::vector <std::string> & oFaceSetNames);
302  OFaceSet getFaceSet( const std::string &iFaceSetName );
303  bool hasFaceSet( const std::string &iFaceSetName );
304 
305  //! Optional source name for the UV param.
306  //! Must be set before the first UV sample is set.
307  void setUVSourceName(const std::string & iName);
308 
309  //! unspecified-bool-type operator overload.
310  //! ...
312 
313 protected:
314  void init( uint32_t iTsIdx );
315 
320 
321  // FaceSets created on this PolyMesh
322  std::map <std::string, OFaceSet> m_faceSets;
323 
326 
327  // optional source name for the UVs
329 
330  // self and child bounds and ArbGeomParams and UserProperties
331  // all come from OGeomBaseSchema
332 };
333 
334 //-*****************************************************************************
335 // SCHEMA OBJECT
336 //-*****************************************************************************
338 
339 typedef Util::shared_ptr< OPolyMesh > OPolyMeshPtr;
340 
341 } // End namespace ALEMBIC_VERSION_NS
342 
343 using namespace ALEMBIC_VERSION_NS;
344 
345 } // End namespace AbcGeom
346 } // End namespace Alembic
347 
348 #endif
OPolyMeshSchema(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: OPolyMesh.h:169
void setFaceIndices(const Abc::Int32ArraySample &iSmp)
Definition: OPolyMesh.h:99
Util::shared_ptr< OPolyMesh > OPolyMeshPtr
Definition: OPolyMesh.h:339
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
const Abc::Int32ArraySample & getFaceIndices() const
Definition: OPolyMesh.h:98
Sample(const Abc::P3fArraySample &iPos, const Abc::Int32ArraySample &iInd, const Abc::Int32ArraySample &iCnt, const OV2fGeomParam::Sample &iUVs=OV2fGeomParam::Sample(), const ON3fGeomParam::Sample &iNormals=ON3fGeomParam::Sample())
Definition: OPolyMesh.h:77
const ON3fGeomParam::Sample & getNormals() const
Definition: OPolyMesh.h:114
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: OPolyMesh.h:90
const Abc::Int32ArraySample & getFaceCounts() const
Definition: OPolyMesh.h:102
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OPolyMeshSchema(CPROP_PTR iParent, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Definition: OPolyMesh.h:200
void setNormals(const ON3fGeomParam::Sample &iNormals)
Definition: OPolyMesh.h:115
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
Box< V3d > Box3d
Definition: ImathBox.h:139
std::map< std::string, OFaceSet > m_faceSets
Definition: OPolyMesh.h:322
OPolyMeshSchema(const OPolyMeshSchema &iCopy)
Copy constructor.
Definition: OPolyMesh.h:229
const Abc::P3fArraySample & getPositions() const
Definition: OPolyMesh.h:89
AbcA::TimeSamplingPtr GetTimeSampling(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:259
void setFaceCounts(const Abc::Int32ArraySample &iCnt)
Definition: OPolyMesh.h:103
const Abc::V3fArraySample & getVelocities() const
Definition: OPolyMesh.h:94
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: OPolyMesh.h:111
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment operator used.
Definition: OPolyMesh.h:243
#define ALEMBIC_EXPORT
Definition: Export.h:51
const OV2fGeomParam::Sample & getUVs() const
Definition: OPolyMesh.h:110
uint32_t GetTimeSamplingIndex(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:272
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
Abc::OSchemaObject< OPolyMeshSchema > OPolyMesh
Definition: OPolyMesh.h:337
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: OPolyMesh.h:95