HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  bool isPartialSample() const
132  {
133  if( !m_positions.getData() && !m_indices.getData() && !m_counts.getData() )
134  {
135  if( m_uvs.getVals() || m_normals.getVals() || m_velocities.getData() )
136  {
137  return true;
138  }
139  }
140 
141  return false;
142  }
143 
144  protected:
148 
150 
152  OV2fGeomParam::Sample m_uvs;
153  ON3fGeomParam::Sample m_normals;
154 
155  };
156  //-*************************************************************************
157  // POLY MESH SCHEMA
158  //-*************************************************************************
159 public:
160  //! By convention we always define this_type in AbcGeom classes.
161  //! Used by unspecified-bool-type conversion below
163 
164  //-*************************************************************************
165  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
166  //-*************************************************************************
167 
168  //! The default constructor creates an empty OPolyMeshSchema
169  //! ...
171  {
172  m_selectiveExport = false;
173  m_numSamples = 0;
174  m_timeSamplingIndex = 0;
175  }
176 
177  //! This constructor creates a new poly mesh writer.
178  //! The first argument is an CompoundPropertyWriterPtr to use as a parent.
179  //! The next is the name to give the schema which is usually the default
180  //! name given by OPolyMesh (.geom) The remaining optional arguments
181  //! can be used to override the ErrorHandlerPolicy, to specify
182  //! MetaData, specify sparse sampling and to set TimeSampling.
184  const std::string &iName,
185  const Abc::Argument &iArg0 = Abc::Argument(),
186  const Abc::Argument &iArg1 = Abc::Argument(),
187  const Abc::Argument &iArg2 = Abc::Argument(),
188  const Abc::Argument &iArg3 = Abc::Argument() );
189 
190  //! This constructor creates a new poly mesh writer.
191  //! The first argument is an OCompundProperty to use as a parent, and from
192  //! which the ErrorHandlerPolicy is derived. The next is the name to give
193  //! the schema which is usually the default name given by OPolyMesh (.geom)
194  //! The remaining optional arguments can be used to specify MetaData,
195  //! specify sparse sampling and to set TimeSampling.
197  const std::string &iName,
198  const Abc::Argument &iArg0 = Abc::Argument(),
199  const Abc::Argument &iArg1 = Abc::Argument(),
200  const Abc::Argument &iArg2 = Abc::Argument() );
201 
202  //! Copy constructor.
204  : OGeomBaseSchema<PolyMeshSchemaInfo>()
205  {
206  *this = iCopy;
207  }
208 
209  //! Default assignment operator used.
210 
211  //-*************************************************************************
212  // SCHEMA STUFF
213  //-*************************************************************************
214 
215  //! Return the time sampling type, which is stored on each of the
216  //! sub properties.
218  {
219  if( m_positionsProperty.valid() )
220  {
221  return m_positionsProperty.getTimeSampling();
222  }
223  else
224  {
225  return getObject().getArchive().getTimeSampling( 0 );
226  }
227  }
228 
229  //-*************************************************************************
230  // SAMPLE STUFF
231  //-*************************************************************************
232 
233  //! Get number of samples written so far.
234  //! ...
235  size_t getNumSamples() const
236  { return m_numSamples; }
237 
238  //! Set a sample! Sample zero has to have non-degenerate
239  //! positions, indices and counts.
240  void set( const Sample &iSamp );
241 
242  //! Set from previous sample. Will apply to each of positions,
243  //! indices, and counts.
244  void setFromPrevious();
245 
246  void setTimeSampling( uint32_t iIndex );
247  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
248 
249  //-*************************************************************************
250  // ABC BASE MECHANISMS
251  // These functions are used by Abc to deal with errors, validity,
252  // and so on.
253  //-*************************************************************************
254 
255  //! Reset returns this function set to an empty, default
256  //! state.
257  void reset()
258  {
259  m_positionsProperty.reset();
260  m_velocitiesProperty.reset();
261  m_indicesProperty.reset();
262  m_countsProperty.reset();
263  m_uvsParam.reset();
264  m_normalsParam.reset();
265 
266  m_faceSets.clear();
267 
269  }
270 
271  //! Valid returns whether this function set is
272  //! valid.
273  bool valid() const
274  {
276  m_positionsProperty.valid() &&
277  m_indicesProperty.valid() &&
278  m_countsProperty.valid() ) ) ||
279  m_selectiveExport;
280  }
281 
282  // FaceSet stuff
283  OFaceSet & createFaceSet( const std::string &iFaceSetName );
284  //! Appends the names of any FaceSets for this PolyMesh.
285  void getFaceSetNames (std::vector <std::string> & oFaceSetNames);
286  OFaceSet getFaceSet( const std::string &iFaceSetName );
287  bool hasFaceSet( const std::string &iFaceSetName );
288 
289  //! Optional source name for the UV param.
290  //! Must be set before the first UV sample is set.
291  void setUVSourceName(const std::string & iName);
292 
293  //! unspecified-bool-type operator overload.
294  //! ...
296 
297 private:
298  void init( uint32_t iTsIdx, bool isSparse );
299 
300  //! Set only some property data. Does not need to be a valid schema sample
301  //! This is to be used when created a file which will be layered in to
302  //! another file.
303  void selectiveSet( const Sample &iSamp );
304 
305  Abc::OP3fArrayProperty m_positionsProperty;
306  Abc::OV3fArrayProperty m_velocitiesProperty;
307  Abc::OInt32ArrayProperty m_indicesProperty;
308  Abc::OInt32ArrayProperty m_countsProperty;
309 
310  // FaceSets created on this PolyMesh
311  std::map <std::string, OFaceSet> m_faceSets;
312 
313  OV2fGeomParam m_uvsParam;
314  ON3fGeomParam m_normalsParam;
315 
316  // optional source name for the UVs
317  std::string m_uvSourceName;
318 
319  // Write out only some properties (UVs, normals).
320  // This is to export data to layer into another file later.
321  bool m_selectiveExport;
322 
323  // Number of times OPolyMeshSchema::set() has been called
324  size_t m_numSamples;
325 
326  uint32_t m_timeSamplingIndex;
327 
328  void createPositionsProperty();
329 
330  void createVelocitiesProperty();
331 
332  void createUVsProperty( const Sample &iSamp );
333 
334  void createNormalsProperty( const Sample &iSamp );
335 
336  // self and child bounds and ArbGeomParams and UserProperties
337  // all come from OGeomBaseSchema
338 };
339 
340 //-*****************************************************************************
341 // SCHEMA OBJECT
342 //-*****************************************************************************
344 
345 typedef Util::shared_ptr< OPolyMesh > OPolyMeshPtr;
346 
347 } // End namespace ALEMBIC_VERSION_NS
348 
349 using namespace ALEMBIC_VERSION_NS;
350 
351 } // End namespace AbcGeom
352 } // End namespace Alembic
353 
354 #endif
void setFaceIndices(const Abc::Int32ArraySample &iSmp)
Definition: OPolyMesh.h:99
Util::shared_ptr< OPolyMesh > OPolyMeshPtr
Definition: OPolyMesh.h:345
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
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
OPolyMeshSchema(const OPolyMeshSchema &iCopy)
Copy constructor.
Definition: OPolyMesh.h:203
const Abc::P3fArraySample & getPositions() const
Definition: OPolyMesh.h:89
void setFaceCounts(const Abc::Int32ArraySample &iCnt)
Definition: OPolyMesh.h:103
const Abc::V3fArraySample & getVelocities() const
Definition: OPolyMesh.h:94
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: OPolyMesh.h:111
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment operator used.
Definition: OPolyMesh.h:217
#define ALEMBIC_EXPORT
Definition: Export.h:51
const OV2fGeomParam::Sample & getUVs() const
Definition: OPolyMesh.h:110
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Abc::OSchemaObject< OPolyMeshSchema > OPolyMesh
Definition: OPolyMesh.h:343
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: OPolyMesh.h:95
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr