HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OPoints.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_OPoints_h
38 #define Alembic_AbcGeom_OPoints_h
39 
40 #include <Alembic/Util/Export.h>
45 
46 namespace Alembic {
47 namespace AbcGeom {
48 namespace ALEMBIC_VERSION_NS {
49 
50 //-*****************************************************************************
51 class ALEMBIC_EXPORT OPointsSchema : public OGeomBaseSchema<PointsSchemaInfo>
52 {
53 public:
54  //-*************************************************************************
55  // POINTS SCHEMA SAMPLE TYPE
56  //-*************************************************************************
57  class Sample
58  {
59  public:
60  //! Creates a default sample with no data in it.
61  //! ...
62  Sample() { reset(); }
63 
64  //! Creates a sample with position data but no id
65  //! data. For specifying samples after the first one
67  const Abc::V3fArraySample &iVelocities = Abc::V3fArraySample(),
68  const OFloatGeomParam::Sample &iWidths = \
69  OFloatGeomParam::Sample() )
70  : m_positions( iPos )
71  , m_velocities( iVelocities )
72  , m_widths( iWidths )
73  {}
74 
75  //! Creates a sample with position data and id data. The first
76  //! sample must be full like this. Subsequent samples may also
77  //! be full like this, which would indicate a change of topology
79  const Abc::UInt64ArraySample &iId,
80  const Abc::V3fArraySample &iVelocities = Abc::V3fArraySample(),
81  const OFloatGeomParam::Sample &iWidths = \
82  OFloatGeomParam::Sample() )
83  : m_positions( iPos )
84  , m_velocities( iVelocities )
85  , m_ids( iId )
86  , m_widths( iWidths )
87  {}
88 
89  // positions accessor
90  const Abc::P3fArraySample &getPositions() const { return m_positions; }
91  void setPositions( const Abc::P3fArraySample &iSmp )
92  { m_positions = iSmp; }
93 
94  // ids accessor
95  const Abc::UInt64ArraySample &getIds() const { return m_ids; }
96  void setIds( const Abc::UInt64ArraySample &iSmp )
97  { m_ids = iSmp; }
98 
99  // velocities accessor
100  const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
101  void setVelocities( const Abc::V3fArraySample &iVelocities )
102  { m_velocities = iVelocities; }
103 
104  // widths accessor
105  const OFloatGeomParam::Sample &getWidths() const { return m_widths; }
106  void setWidths( const OFloatGeomParam::Sample &iWidths )
107  { m_widths = iWidths; }
108 
109  const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
110  void setSelfBounds( const Abc::Box3d &iBnds )
111  { m_selfBounds = iBnds; }
112 
113  void reset()
114  {
115  m_positions.reset();
116  m_velocities.reset();
117  m_ids.reset();
118  m_widths.reset();
119 
120  m_selfBounds.makeEmpty();
121  }
122 
123  bool isPartialSample() const
124  {
125  if( !m_positions.getData() )
126  {
127  return true;
128  }
129 
130  return false;
131  }
132 
133  protected:
137  OFloatGeomParam::Sample m_widths;
138 
140  };
141 
142  //-*************************************************************************
143  // POINTS SCHEMA
144  //-*************************************************************************
145 public:
146  //! By convention we always define this_type in AbcGeom classes.
147  //! Used by unspecified-bool-type conversion below
149 
150  //-*************************************************************************
151  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
152  //-*************************************************************************
153 
154  //! The default constructor creates an empty OPointsSchema
155  //! ...
157  {
158  m_selectiveExport = false;
159  m_numSamples = 0;
160  m_timeSamplingIndex = 0;
161  }
162 
163  //! This constructor creates a new poly mesh writer.
164  //! The first argument is an CompoundPropertyWriterPtr to use as a parent.
165  //! The next is the name to give the schema which is usually the default
166  //! name given by OFaceSet (.geom) The remaining optional arguments
167  //! can be used to override the ErrorHandlerPolicy, to specify
168  //! MetaData, specify sparse sampling and to set TimeSampling.
170  const std::string &iName,
171  const Abc::Argument &iArg0 = Abc::Argument(),
172  const Abc::Argument &iArg1 = Abc::Argument(),
173  const Abc::Argument &iArg2 = Abc::Argument(),
174  const Abc::Argument &iArg3 = Abc::Argument() );
175 
176  //! This constructor creates a new poly mesh writer.
177  //! The first argument is an OCompundProperty to use as a parent, and from
178  //! which the ErrorHandlerPolicy is derived. The next is the name to give
179  //! the schema which is usually the default name given by OFaceSet (.geom)
180  //! The remaining optional arguments can be used to specify MetaData,
181  //! specify sparse sampling and to set TimeSampling.
183  const std::string &iName,
184  const Abc::Argument &iArg0 = Abc::Argument(),
185  const Abc::Argument &iArg1 = Abc::Argument(),
186  const Abc::Argument &iArg2 = Abc::Argument() );
187 
188  //! Copy constructor.
190  : OGeomBaseSchema<PointsSchemaInfo>()
191  {
192  *this = iCopy;
193  }
194 
195  //! Default assignment operator used.
196 
197  //-*************************************************************************
198  // SCHEMA STUFF
199  //-*************************************************************************
200 
201  //! Return the time sampling
203  {
204  if( m_positionsProperty.valid() )
205  {
206  return m_positionsProperty.getTimeSampling();
207  }
208  else
209  {
210  return getObject().getArchive().getTimeSampling( 0 );
211  }
212  }
213 
214  //-*************************************************************************
215  // SAMPLE STUFF
216  //-*************************************************************************
217 
218  //! Get number of samples written so far.
219  //! ...
220  size_t getNumSamples() const { return m_numSamples; }
221 
222  //! Set a sample
223  void set( const Sample &iSamp );
224 
225  //! Set from previous sample. Will apply to each of positions,
226  //! ids, velocities, and widths
227  void setFromPrevious( );
228 
229  void setTimeSampling( uint32_t iIndex );
230  void setTimeSampling( AbcA::TimeSamplingPtr iTime );
231 
232  //-*************************************************************************
233  // ABC BASE MECHANISMS
234  // These functions are used by Abc to deal with errors, validity,
235  // and so on.
236  //-*************************************************************************
237 
238  //! Reset returns this function set to an empty, default
239  //! state.
240  void reset()
241  {
242  m_positionsProperty.reset();
243  m_idsProperty.reset();
244  m_velocitiesProperty.reset();
245  m_widthsParam.reset();
246 
248  }
249 
250  //! Valid returns whether this function set is
251  //! valid.
252  bool valid() const
253  {
255  m_positionsProperty.valid() &&
256  m_idsProperty.valid() )
257  || m_selectiveExport );
258  }
259 
260  //! unspecified-bool-type operator overload.
261  //! ...
263 
264 private:
265  void init( uint32_t iTsIdx, bool isSparse );
266 
267  //! Set only some property data. Does not need to be a valid schema sample
268  //! This is to be used when created a file which will be layered in to
269  //! another file.
270  void selectiveSet( const Sample &iSamp );
271 
272  void createPositionProperty();
273  void createIdProperty();
274  void createVelocityProperty();
275  void createWidthsProperty( const Sample &iSamp );
276 
277  Abc::OP3fArrayProperty m_positionsProperty;
278  Abc::OUInt64ArrayProperty m_idsProperty;
279  Abc::OV3fArrayProperty m_velocitiesProperty;
280  OFloatGeomParam m_widthsParam;
281 
282  // Write out only some properties (UVs, normals).
283  // This is to export data to layer into another file later.
284  bool m_selectiveExport;
285 
286  // Number of times OPolyMeshSchema::set() has been called
287  size_t m_numSamples;
288 
289  uint32_t m_timeSamplingIndex;
290 
291 };
292 
293 //-*****************************************************************************
294 // SCHEMA OBJECT
295 //-*****************************************************************************
297 
298 typedef Util::shared_ptr< OPoints > OPointsPtr;
299 
300 } // End namespace ALEMBIC_VERSION_NS
301 
302 using namespace ALEMBIC_VERSION_NS;
303 
304 } // End namespace AbcGeom
305 } // End namespace Alembic
306 
307 #endif
Sample(const Abc::P3fArraySample &iPos, const Abc::V3fArraySample &iVelocities=Abc::V3fArraySample(), const OFloatGeomParam::Sample &iWidths=OFloatGeomParam::Sample())
Definition: OPoints.h:66
void setWidths(const OFloatGeomParam::Sample &iWidths)
Definition: OPoints.h:106
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
void setIds(const Abc::UInt64ArraySample &iSmp)
Definition: OPoints.h:96
#define ALEMBIC_EXPORT
Definition: Export.h:51
const Abc::V3fArraySample & getVelocities() const
Definition: OPoints.h:100
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: OPoints.h:101
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment operator used.
Definition: OPoints.h:202
const OFloatGeomParam::Sample & getWidths() const
Definition: OPoints.h:105
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
GLboolean reset
Definition: glad.h:5138
Abc::OSchemaObject< OPointsSchema > OPoints
Definition: OPoints.h:296
OPointsSchema(const OPointsSchema &iCopy)
Copy constructor.
Definition: OPoints.h:189
#define ALEMBIC_OVERRIDE_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:56
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: OPoints.h:91
const Abc::P3fArraySample & getPositions() const
Definition: OPoints.h:90
Box< V3d > Box3d
3D box of base type double.
Definition: ImathBox.h:167
Util::shared_ptr< OPoints > OPointsPtr
Definition: OPoints.h:298
Sample(const Abc::P3fArraySample &iPos, const Abc::UInt64ArraySample &iId, const Abc::V3fArraySample &iVelocities=Abc::V3fArraySample(), const OFloatGeomParam::Sample &iWidths=OFloatGeomParam::Sample())
Definition: OPoints.h:78
const Abc::UInt64ArraySample & getIds() const
Definition: OPoints.h:95
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr