HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XformOp.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_XformOp_h
38 #define Alembic_AbcGeom_XformOp_h
39 
40 #include <Alembic/Util/Export.h>
42 
43 #include <set>
44 
45 namespace Alembic {
46 namespace AbcGeom {
47 namespace ALEMBIC_VERSION_NS {
48 
49 //! \brief The Matrix identifier hint.
50 //! Some 3d packages (like Maya) may have certain transformation operations
51 //! that aren't supported in other packages. MatrixHint is meant to
52 //! help with reading back into applications that natively support the type.
54 {
55  //! Regular Matrix
57 
58  //! Matrix represents Maya's version of Shear
60 };
61 
62 //! \brief The Rotate identifier hint.
63 //! Some 3d packages (like Maya) have multiple rotation operations
64 //! that are mathmatically of the same type. RotateHint is meant to
65 //! help disambiguate these similiar mathmatical types when reading back
66 //! into applications that natively support the type.
68 {
69  //! Default regular rotation
71 
72  //! Rotation that goes along with the rotate pivot to help
73  //! orient the local rotation space.
75 };
76 
77 //! \brief The Scale identifier hint.
78 //! Some 3d packages (like Maya) have multiple transformation operations
79 //! that are mathmatically of the same type. ScaleHint is meant to
80 //! help disambiguate these similiar mathmatical types when reading back
81 //! into applications that natively support that type.
83 {
84  //! Default, regular scale.
86 };
87 
88 
89 //! \brief The Translation identifier hint.
90 //! Some 3d packages (like Maya) have multiple transformation operations
91 //! that are mathmatically of the same type. TranslateHint is meant to
92 //! help disambiguate these similiar mathmatical types when reading back
93 //! into applications that natively support the type.
95 {
96  //! Default, regular translation.
98 
99  //! Translation used for scaling around a pivot point.
101 
102  //! Translation which is used to help preserve existing scale
103  //! transformations when moving the pivot.
105 
106  //! Translation used for rotating around the pivot point.
108 
109  //! Translation which is used to help preserve existing rotate
110  //! transformations when moving the pivot.
112 };
113 
114 //! \brief Xform Operation
115 //! This class holds the data about a particular transform operation, but does
116 //! not hold the actual data to calculate a 4x4 matrix. It holds the type of
117 //! operation (Translate, Rotate, Scale, Matrix), a hint about the type which
118 //! can be interpreted by packages like Maya, and what particular parts of the
119 //! operations can change over time.
121 {
122 public:
123  XformOp();
124 
125  XformOp( const XformOperationType iType,
126  const Alembic::Util::uint8_t iHint = 0 );
127 
128  XformOp( const Alembic::Util::uint8_t iEncodedOp );
129 
130  //! Get the type of transform operation. (Translate, Rotate, Scale, Matrix)
131  XformOperationType getType() const;
132 
133  //! Set the type of transform operation. (Translate, Rotate, Scale, Matrix)
134  //! Setting the type resets the hint, and sets all the channels to static.
135  void setType( const XformOperationType iType );
136 
137  //! Get the MatrixHint, RotateHint, TranslateHint, or ScaleHint to help
138  //! disambiguate certain options that may have the same type.
139  Alembic::Util::uint8_t getHint() const;
140 
141  //! Set the hint, if it is an illegal value for the type, then the hint
142  //! is set to the default, 0.
143  void setHint( const Alembic::Util::uint8_t iHint );
144 
145  //! Returns whether the x component (index 0) is animated.
146  //! Only meaningful on read.
147  bool isXAnimated() const;
148 
149  //! Returns whether the y component (index 1) is animated.
150  //! Only meaningful on read.
151  bool isYAnimated() const;
152 
153  //! Returns whether the z component (index 2) is animated.
154  //! Only meaningful on read.
155  bool isZAnimated() const;
156 
157  //! Returns whether the angle component (index 3) is animated.
158  //! Since Scale and Translate do not have an angle component,
159  //! false is returned for those types.
160  //! Only meaningful on read.
161  bool isAngleAnimated() const;
162 
163  //! Returns whether a particular channel is animated.
164  //! Scale and Translate only have 3 channels, Rotate has 4, and
165  //! Matrix has 16. Indices greater than the number of channels will
166  //! return false.
167  //! Only meaningful on read.
168  bool isChannelAnimated( std::size_t iIndex ) const;
169 
170  //! Get the number of components that this operation has based on the type.
171  //! Translate and Scale have 3, Rotate has 4 and Matrix has 16, and
172  //! single-axis rotate ops (rotateX, rotateY, rotateZ) have 1.
173  std::size_t getNumChannels() const;
174 
175  //! For every channel, there's a default value. Typically, for each op
176  //! type, it's the same across channels. But matrix ops have different
177  //! defaults to allow the identity matrix to be defaulted (most channels
178  //! there are 0.0, the determinant channels are 1.0).
179  double getDefaultChannelValue( std::size_t iIndex ) const;
180 
181  double getChannelValue( std::size_t iIndex ) const;
182 
183  //! Set a single channel; will throw if iIndex is greater than
184  //! numchannels - 1.
185  void setChannelValue( std::size_t iIndex, double iVal );
186 
187  void setVector( const Abc::V3d &iVec );
188  void setTranslate( const Abc::V3d &iTrans );
189  void setScale( const Abc::V3d &iScale );
190  void setAxis( const Abc::V3d &iAxis );
191  void setAngle( const double iAngle );
192  void setMatrix( const Abc::M44d &iMatrix );
193 
194  void setXRotation( const double iAngle );
195  void setYRotation( const double iAngle );
196  void setZRotation( const double iAngle );
197 
198  // synthetic getters return by value
199  Abc::V3d getVector() const;
200  Abc::V3d getTranslate() const;
201  Abc::V3d getScale() const;
202  Abc::V3d getAxis() const;
203  double getAngle() const;
204  Abc::M44d getMatrix() const;
205 
206  double getXRotation() const;
207  double getYRotation() const;
208  double getZRotation() const;
209 
210  bool isTranslateOp() const;
211 
212  bool isScaleOp() const;
213 
214  bool isRotateOp() const;
215 
216  bool isMatrixOp() const;
217 
218  bool isRotateXOp() const;
219  bool isRotateYOp() const;
220  bool isRotateZOp() const;
221 
222  //! Function for returning the combined encoded type and hint.
223  //! The type is in the first four bits, the hint in the second.
224  //!
225  //! This is not really intended for use by human clients of this class.
226  Alembic::Util::uint8_t getOpEncoding() const;
227 
228 
229 private:
230  XformOperationType m_type;
231  Alembic::Util::uint8_t m_hint;
232 
233  std::vector<double> m_channels;
234 
235  std::set<Alembic::Util::uint32_t> m_animChannels;
236 
237 private:
238  //! The IXform can tell the op if its channels are animated
239  //! by directly inserting keys into the m_animChannels set.
240  friend class IXformSchema;
241 
242 };
243 
244 typedef std::vector < XformOp > XformOpVec;
245 
246 } // End namespace ALEMBIC_VERSION_NS
247 
248 using namespace ALEMBIC_VERSION_NS;
249 
250 } // End namespace AbcGeom
251 } // End namespace Alembic
252 
253 #endif
std::vector< XformOp > XformOpVec
Definition: XformOp.h:244
#define ALEMBIC_EXPORT
Definition: Export.h:51
Translation used for rotating around the pivot point.
Definition: XformOp.h:107
Matrix44< double > M44d
4x4 matrix of double
Definition: ImathMatrix.h:1140
Vec3< double > V3d
Vec3 of double.
Definition: ImathVec.h:852
MatrixHint
The Matrix identifier hint. Some 3d packages (like Maya) may have certain transformation operations t...
Definition: XformOp.h:53
TranslateHint
The Translation identifier hint. Some 3d packages (like Maya) have multiple transformation operations...
Definition: XformOp.h:94
XformOperationType
Enum that indicates the type of transformational operation. This enum is used when encoding and decod...
Definition: Foundation.h:70
ScaleHint
The Scale identifier hint. Some 3d packages (like Maya) have multiple transformation operations that ...
Definition: XformOp.h:82
RotateHint
The Rotate identifier hint. Some 3d packages (like Maya) have multiple rotation operations that are m...
Definition: XformOp.h:67
Translation used for scaling around a pivot point.
Definition: XformOp.h:100
Xform Operation This class holds the data about a particular transform operation, but does not hold t...
Definition: XformOp.h:120
Vec3< typename MatType::value_type > getScale(const MatType &mat)
Return a Vec3 representing the lengths of the passed matrix's upper 3×3's rows.
Definition: Mat.h:633
Matrix represents Maya's version of Shear.
Definition: XformOp.h:59
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88