HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GT_Transform.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GT_Transform.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_Transform__
12 #define __GT_Transform__
13 
14 #include "GT_API.h"
15 #include <UT/UT_IntrusivePtr.h>
16 #include <UT/UT_Matrix4.h>
17 #include "GT_Handles.h"
18 
19 class UT_JSONWriter;
20 
21 /// A simple interface to provide multiple-segments of transforms.
23  : public UT_IntrusiveRefCounter<GT_Transform>
24 {
25 public:
26  /// Default c-tor
27  GT_Transform();
28  /// Copy c-tor
30  /// Initialize with single precision transforms
31  GT_Transform(const UT_Matrix4F *xforms, int nsegments);
32  /// Initialize with double precision transforms
33  GT_Transform(const UT_Matrix4D *xforms, int nsegments);
34  ~GT_Transform();
35 
36  /// Assignment operator
38 
39  /// Equality operation
40  bool operator==(const GT_Transform &other) const;
41  bool operator!=(const GT_Transform &other) const
42  { return !(*this == other); }
43 
44  /// Get the identity transform (as a handle)
45  static const GT_TransformHandle &identity();
46 
47  /// @{
48  /// Initialize the matrix
49  void alloc(int nsegments);
50  void setMatrix(const UT_Matrix4F &xform, int segment);
51  void setMatrix(const UT_Matrix4D &xform, int segment);
52  /// @}
53 
54  /// @{
55  /// Multiply this transform by a single matrix. This applies the matrix to
56  /// all the embedded transforms.
57  GT_Transform *preMultiply(const UT_Matrix4D &xform) const;
58  GT_Transform *multiply(const UT_Matrix4D &xform) const;
59  GT_Transform *preMultiply(const UT_Matrix4F &xform) const;
60  GT_Transform *multiply(const UT_Matrix4F &xform) const;
61  GT_TransformHandle preMultiply(const GT_Transform &x) const;
62  GT_TransformHandle multiply(const GT_Transform &x) const;
63  /// @}
64 
65  /// @{
66  /// Multiply by the 3x3 transform (not including translates)
67  GT_Transform *preMultiply(const UT_Matrix3D &xform) const;
68  GT_Transform *multiply(const UT_Matrix3D &xform) const;
69  GT_Transform *preMultiply(const UT_Matrix3F &xform) const;
70  GT_Transform *multiply(const UT_Matrix3F &xform) const;
71  /// @}
72 
73  /// Compute inverse transforms. This will be done lazily when getting
74  /// inverse transforms.
75  void computeInverse();
76 
77  /// Return approximate memory usage.
78  int64 getMemoryUsage() const;
79 
80  /// Return motion segments
81  int getSegments() const { return myMotionSegments; }
82 
83  /// @{
84  /// Extract a matrix
85  void getMatrix(UT_Matrix4F &xform, int segment=0) const;
86  void getMatrix(UT_Matrix4D &xform, int segment=0) const;
87  /// @}
88  /// @{
89  /// Extract a matrix
90  void getInverse(UT_Matrix4F &xform, int segment=0) const;
91  void getInverse(UT_Matrix4D &xform, int segment=0) const;
92  /// @}
93 
94  /// @{
95  /// Transform a data array (using the type info on the array)
97  int segment=0) const;
98  /// @}
99 
100  /// Return the inverse transform
101  GT_TransformHandle invert() const;
102 
103  /// Test whether the transform is an identity matrix
104  bool isIdentity() const { return myIdentity; }
105 
106  /// Save to a JSON stream/value
107  bool save(UT_JSONWriter &w) const;
108 
109  /// Load from a JSON stream/value
110  static bool load(GT_TransformHandle &x, UT_JSONParser &p);
111 
112  /// Save the transform to stdout
113  void dump(const char *msg="") const;
114 
115 private:
116  void clear();
117  void clearInverse();
118  void checkIdentity();
119 
120  // Keep the 32 bit int first in the structure. Since we inherit from
121  // GA_IntrusiveRefCounter, this alignment makes the object smaller.
122  int myMotionSegments;
123  UT_Matrix4D *myMatrix;
124  UT_Matrix4D *myInverse;
125  UT_Matrix4D mySingleMatrix;
126  bool myIdentity;
127 };
128 
129 #endif
GLboolean invert
Definition: glcorearb.h:548
#define GT_API
Definition: GT_API.h:11
A simple interface to provide multiple-segments of transforms.
Definition: GT_Transform.h:22
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
int getSegments() const
Return motion segments.
Definition: GT_Transform.h:81
A reference counter base class for use with UT_IntrusivePtr.
UT_IntrusiveRefCounter & operator=(const UT_IntrusiveRefCounter &)
Assignment operator: Does not modify counter.
bool operator!=(const GT_Transform &other) const
Definition: GT_Transform.h:41
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
long long int64
Definition: SYS_Types.h:106
bool isIdentity() const
Test whether the transform is an identity matrix.
Definition: GT_Transform.h:104
GA_API const UT_StringHolder transform
GLint GLenum GLint x
Definition: glcorearb.h:408
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GLenum src
Definition: glcorearb.h:1792