HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IPolyMesh.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_IPolyMesh_h_
38 #define _Alembic_AbcGeom_IPolyMesh_h_
39 
40 #include <Alembic/Util/Export.h>
46 
47 namespace Alembic {
48 namespace AbcGeom {
49 namespace ALEMBIC_VERSION_NS {
50 
51 //-*****************************************************************************
53  : public IGeomBaseSchema<PolyMeshSchemaInfo>
54 {
55 public:
56  class Sample
57  {
58  public:
59  typedef Sample this_type;
60 
61  // Users don't ever create this data directly.
62  Sample() { reset(); }
63 
64  Abc::P3fArraySamplePtr getPositions() const { return m_positions; }
65  Abc::V3fArraySamplePtr getVelocities() const { return m_velocities; }
66  Abc::Int32ArraySamplePtr getFaceIndices() const { return m_indices; }
67  Abc::Int32ArraySamplePtr getFaceCounts() const { return m_counts; }
68  Abc::Box3d getSelfBounds() const { return m_selfBounds; }
69 
70  bool valid() const
71  {
72  return m_positions && m_indices && m_counts;
73  }
74 
75  void reset()
76  {
77  m_positions.reset();
78  m_velocities.reset();
79  m_indices.reset();
80  m_counts.reset();
81  m_selfBounds.makeEmpty();
82  }
83 
84  ALEMBIC_OPERATOR_BOOL( valid() );
85 
86  protected:
87  friend class IPolyMeshSchema;
93  };
94 
95  //-*************************************************************************
96  // POLY MESH SCHEMA
97  //-*************************************************************************
98 public:
99  //! By convention we always define this_type in AbcGeom classes.
100  //! Used by unspecified-bool-type conversion below
102 
103  //-*************************************************************************
104  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
105  //-*************************************************************************
106 
107  //! The default constructor creates an empty OPolyMeshSchema
108  //! ...
110 
111  //! This templated, explicit function creates a new scalar property reader.
112  //! The first argument is any Abc (or AbcCoreAbstract) object
113  //! which can intrusively be converted to an CompoundPropertyReaderPtr
114  //! to use as a parent, from which the error handler policy for
115  //! inheritance is also derived. The remaining optional arguments
116  //! can be used to override the ErrorHandlerPolicy and to specify
117  //! schema interpretation matching.
118  template <class CPROP_PTR>
119  IPolyMeshSchema( CPROP_PTR iParent,
120  const std::string &iName,
121 
122  const Abc::Argument &iArg0 = Abc::Argument(),
123  const Abc::Argument &iArg1 = Abc::Argument() )
124  : IGeomBaseSchema<PolyMeshSchemaInfo>( iParent, iName,
125  iArg0, iArg1 )
126  {
127  init( iArg0, iArg1 );
128  }
129 
130  //! This constructor is the same as above, but with default
131  //! schema name used.
132  template <class CPROP_PTR>
133  explicit IPolyMeshSchema( CPROP_PTR iParent,
134  const Abc::Argument &iArg0 = Abc::Argument(),
135  const Abc::Argument &iArg1 = Abc::Argument() )
136  : IGeomBaseSchema<PolyMeshSchemaInfo>( iParent,
137  iArg0, iArg1 )
138  {
139  init( iArg0, iArg1 );
140  }
141 
142  //! Wrap an existing schema object
143  template <class CPROP_PTR>
144  IPolyMeshSchema( CPROP_PTR iThis,
145  Abc::WrapExistingFlag iFlag,
146 
147  const Abc::Argument &iArg0 = Abc::Argument(),
148  const Abc::Argument &iArg1 = Abc::Argument() )
149  : IGeomBaseSchema<PolyMeshSchemaInfo>( iThis, iFlag, iArg0, iArg1 )
150  {
151  init( iArg0, iArg1 );
152  }
153 
154  //! Copy constructor.
156  : IGeomBaseSchema<PolyMeshSchemaInfo>()
157  {
158  *this = iCopy;
159  }
160  const IPolyMeshSchema & operator=(const IPolyMeshSchema & rhs);
161 
162 
163  //! Return the number of samples contained in the property.
164  //! This can be any number, including zero.
165  //! This returns the number of samples that were written, independently
166  //! of whether or not they were constant.
167  size_t getNumSamples() const
168  { return m_positionsProperty.getNumSamples(); }
169 
170  //! Return the topological variance.
171  //! This indicates how the mesh may change.
172  MeshTopologyVariance getTopologyVariance() const;
173 
174  //! Ask if we're constant - no change in value amongst samples,
175  //! regardless of the time sampling.
176  bool isConstant() const { return getTopologyVariance() == kConstantTopology; }
177 
178  //! Time information.
179  //! Any of the properties could be the bearer of the time
180  //! sampling information, which otherwise defaults to Identity.
182  {
183  if ( m_positionsProperty.valid() )
184  {
185  return m_positionsProperty.getTimeSampling();
186  }
187  else
188  {
189  return getObject().getArchive().getTimeSampling( 0 );
190  }
191  }
192 
193  //-*************************************************************************
194  void get( Sample &oSample,
195  const Abc::ISampleSelector &iSS = Abc::ISampleSelector() ) const
196  {
197  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IPolyMeshSchema::get()" );
198 
199  m_positionsProperty.get( oSample.m_positions, iSS );
200  m_indicesProperty.get( oSample.m_indices, iSS );
201  m_countsProperty.get( oSample.m_counts, iSS );
202 
203  m_selfBoundsProperty.get( oSample.m_selfBounds, iSS );
204 
205  if ( m_velocitiesProperty && m_velocitiesProperty.getNumSamples() > 0 )
206  {
207  m_velocitiesProperty.get( oSample.m_velocities, iSS );
208  }
209 
210  // Could error check here.
211 
213  }
214 
216  {
217  Sample smp;
218  get( smp, iSS );
219  return smp;
220  }
221 
223  {
224  return m_uvsParam;
225  }
226 
228  {
229  return m_normalsParam;
230  }
231 
233  {
234  return m_countsProperty;
235  }
236 
238  {
239  return m_indicesProperty;
240  }
241 
243  {
244  return m_positionsProperty;
245  }
246 
248  {
249  return m_velocitiesProperty;
250  }
251 
252  //-*************************************************************************
253  // ABC BASE MECHANISMS
254  // These functions are used by Abc to deal with errors, rewrapping,
255  // and so on.
256  //-*************************************************************************
257 
258  //! Reset returns this function set to an empty, default
259  //! state.
260  void reset()
261  {
262  m_positionsProperty.reset();
263  m_velocitiesProperty.reset();
264  m_indicesProperty.reset();
265  m_countsProperty.reset();
266 
267  m_uvsParam.reset();
268  m_normalsParam.reset();
269 
271  }
272 
273  //! Valid returns whether this function set is
274  //! valid.
275  bool valid() const
276  {
278  m_positionsProperty.valid() &&
279  m_indicesProperty.valid() &&
280  m_countsProperty.valid() );
281  }
282 
283  // FaceSet related
284  //! Appends the names of any FaceSets for this PolyMesh.
285  void getFaceSetNames (std::vector <std::string> & oFaceSetNames);
286  IFaceSet getFaceSet( const std::string &iFaceSetName );
287  bool hasFaceSet( const std::string &iFaceSetName );
288 
289  //! unspecified-bool-type operator overload.
290  //! ...
292 
293 protected:
294  void init( const Abc::Argument &iArg0,
295  const Abc::Argument &iArg1 );
296 
301 
304 
305  // FaceSets, this starts as empty until client
306  // code attempts to access facesets.
308  std::map <std::string, IFaceSet> m_faceSets;
310  void loadFaceSetNames();
311 };
312 
313 //-*****************************************************************************
315 
316 typedef Util::shared_ptr< IPolyMesh > IPolyMeshPtr;
317 
318 } // End namespace ALEMBIC_VERSION_NS
319 
320 using namespace ALEMBIC_VERSION_NS;
321 
322 } // End namespace AbcGeom
323 } // End namespace Alembic
324 
325 #endif
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: IPolyMesh.h:181
Alembic::Util::shared_ptr< Int32ArraySample > Int32ArraySamplePtr
IPolyMeshSchema(CPROP_PTR iThis, Abc::WrapExistingFlag iFlag, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Wrap an existing schema object.
Definition: IPolyMesh.h:144
Alembic::Util::shared_ptr< V3fArraySample > V3fArraySamplePtr
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
IPolyMeshSchema(CPROP_PTR iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition: IPolyMesh.h:119
Sample getValue(const Abc::ISampleSelector &iSS=Abc::ISampleSelector()) const
Definition: IPolyMesh.h:215
Abc::IInt32ArrayProperty getFaceCountsProperty() const
Definition: IPolyMesh.h:232
Abc::IV3fArrayProperty getVelocitiesProperty() const
Definition: IPolyMesh.h:247
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
Abc::IInt32ArrayProperty getFaceIndicesProperty() const
Definition: IPolyMesh.h:237
std::map< std::string, IFaceSet > m_faceSets
Definition: IPolyMesh.h:308
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
Abc::ISchemaObject< IPolyMeshSchema > IPolyMesh
Definition: IPolyMesh.h:314
Box< V3d > Box3d
Definition: ImathBox.h:139
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
Abc::IP3fArrayProperty getPositionsProperty() const
Definition: IPolyMesh.h:242
Util::shared_ptr< IPolyMesh > IPolyMeshPtr
Definition: IPolyMesh.h:316
#define ALEMBIC_EXPORT
Definition: Export.h:51
IPolyMeshSchema(CPROP_PTR iParent, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument())
Definition: IPolyMesh.h:133
IPolyMeshSchema(const IPolyMeshSchema &iCopy)
Copy constructor.
Definition: IPolyMesh.h:155
Alembic::Util::shared_ptr< P3fArraySample > P3fArraySamplePtr
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104