HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_XformOrder.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: Utility Library (C++)
7  *
8  * COMMENTS:
9  * This class stores a transformation order of scales, rotates, and
10  * translates.
11  */
12 
13 #ifndef __UT_XformOrder_h__
14 #define __UT_XformOrder_h__
15 
16 #include "UT_API.h"
17 #include <iosfwd>
18 #include "UT_Assert.h"
19 
21 {
22 public:
23  // The xforms. Their values are used as indices in an array, so they
24  // should start at 0 and increase by 1.
25  enum xform { T=0, S=1, RX=2, RY=3, RZ=4};
26 
27  // Xform ordering for R,S,T and for the rotates respectively. If you
28  // change any of these, make sure you update the ...FromString()
29  // methods in the private section.
30  enum rstOrder { TRS, TSR, RTS, RST, STR, SRT };
31  enum xyzOrder { XYZ, XZY, YXZ, YZX, ZXY, ZYX };
32 
33  // Simple class constructors and destructor. The first constructor
34  // allows you to choose one of the RST permutations and one of the
35  // rotation permutation, while the second c-tor offers full flexibility
36  // in specifying the xform order (you could even have more xforms of
37  // the same type, but then the behaviour of mainOrder() and rotOrder()
38  // will be undefined).
41  {
42  reorder(rst, rot);
43  }
44 
46  xform xf3 = UT_XformOrder::RX,
49  {
50  reorder(xf1, xf2, xf3, xf4, xf5);
51  }
52 
53  // Constructor that takes strings specifying the xform order. Any
54  // combination of lower and uppercase is acceptable ("TsR", "XZY", "rst").
55  // We do NOT check the string lengths, but we do check for null pointers.
56  UT_XformOrder(const char *rst, const char *rot = "xyz");
57 
58  // Copy constructor (deep)
59  UT_XformOrder(const UT_XformOrder &xf);
60 
61  // Clas destructor -- trivial.
63 
64  // Shuffle the order of the xforms. If all you'll ever do is traverse the
65  // xform order to build a transformation matrix, you can even have more
66  // xforms of the same type in the argument list; then, however, the
67  // behaviour of mainOrder() and rotOrder() will be undefined.
68  void reorder(UT_XformOrder::xform xf1,
71  void reorder(UT_XformOrder::rstOrder rst,
73 
74  // Query or set the main xform order or the rotation order respectively.
75  // These methods assume the rotates are bundled together, and search for
76  // the position of the first rotate they find. The methods that take
77  // strings accept lower and uppercase combinations, check to see whether
78  // the argument is zero, but don't check its length.
79  UT_XformOrder::rstOrder mainOrder(void) const;
80  void mainOrder(UT_XformOrder::rstOrder rst);
81  bool mainOrder(const char *rst);
82  UT_XformOrder::xyzOrder rotOrder (void) const;
83  void rotOrder (UT_XformOrder::xyzOrder rot);
84  bool rotOrder (const char *rot);
85 
86  // Compute a mapping from the source to destination rotation order by
87  // filling in the given 'map' array.
88  static void getRotOrderMapping(xyzOrder src, xyzOrder dst,
89  int map[3]);
90 
91  // Swap two xforms:
93  {
94  if (xf1 != xf2)
95  {
96  unsigned short i1 = prefList[xf1];
97  unsigned short i2 = prefList[xf2];
98  prefList[xf1] = i2; permList[i1] = xf2;
99  prefList[xf2] = i1; permList[i2] = xf1;
100  }
101  }
102 
103  void invert();
104 
105  // Two operator: operator() returns the index of a given transform without
106  // having to check any bounds; operator[] returns the i'th transform and
107  // checks if it's between valid bounds.
108  unsigned short operator()(UT_XformOrder::xform xf) const
109  {
110  return prefList[xf];
111  }
112  UT_XformOrder::xform operator[](unsigned short i) const
113  {
114  UT_ASSERT_P(i < 5);
115  return (i<5)
116  ? (UT_XformOrder::xform)permList[i]
117  : (UT_XformOrder::xform)permList[4];
118  }
119 
120  // Return the number of transforms we store:
121  int count(void) const { return 5; }
122 
123  // Get a hard copy of the elements of xf.
124  UT_XformOrder &operator=(const UT_XformOrder &xf);
125 
126  // Save or load the xform order. We save the sequence of transforms in the
127  // order in which they appear in the permutation list.
128  int save(std::ostream &os, int binary=0) const;
129 
130  friend std::ostream &operator<<(std::ostream &os, const UT_XformOrder &t)
131  {
132  t.save(os);
133  return os;
134  }
135 
136  const char *mainOrderLabel() const;
137  const char *rotOrderLabel() const;
138 
139 private:
140  // The permulation list. Should be of type UT_XformOrder::xform, but chars
141  // are more compact.
142  char permList[5];
143 
144  // Permutation reference: stores the index of each transform in the
145  // permutation list. It's handy for locating and shuffling xforms fast.
146  unsigned short prefList[5];
147 
148  // Translate a string into an xform order, returning whether or not the
149  // conversion was successful. If the conversion wasn't successful,
150  // the xform order will be set to the "default" order.
151  static bool rstFromString(const char *rst,
152  UT_XformOrder::rstOrder &result);
153  static bool xyzFromString(const char *rot,
154  UT_XformOrder::xyzOrder &result);
155 
156  static const char * theXYZNames[6];
157  static const char * theXYZLabels[6];
158  static const char * theTRSLabels[6];
159 };
160 
161 #endif
unsigned short operator()(UT_XformOrder::xform xf) const
GLboolean invert
Definition: glcorearb.h:548
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GA_API const UT_StringHolder rot
#define UT_API
Definition: UT_API.h:12
png_uint_32 i
Definition: png.h:2877
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
void swap(UT_XformOrder::xform xf1, UT_XformOrder::xform xf2)
Definition: UT_XformOrder.h:92
int count(void) const
int save(std::ostream &os, int binary=0) const
UT_XformOrder(rstOrder rst=UT_XformOrder::TSR, xyzOrder rot=UT_XformOrder::XYZ)
Definition: UT_XformOrder.h:39
friend std::ostream & operator<<(std::ostream &os, const UT_XformOrder &t)
GLenum GLenum dst
Definition: glcorearb.h:1792
UT_XformOrder::xform operator[](unsigned short i) const
UT_XformOrder(xform xf1, xform xf2, xform xf3=UT_XformOrder::RX, xform xf4=UT_XformOrder::RY, xform xf5=UT_XformOrder::RZ)
Definition: UT_XformOrder.h:45
GLenum src
Definition: glcorearb.h:1792