HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CVEX_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: CVEX_Transform.h (CVEX Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __CVEX_Transform__
12 #define __CVEX_Transform__
13 
14 #include "CVEX_API.h"
15 #include <UT/UT_Matrix4.h>
16 #include <UT/UT_Array.h>
17 #include <UT/UT_IntArray.h>
18 #include <UT/UT_SharedPtr.h>
19 #include <UT/UT_OpCaller.h>
20 #include <VEX/VEX_PodTypes.h>
21 
22 class VEX_TransformContext;
23 class UT_OpCaller;
24 class UT_StringHolder;
25 class cvex_TransformData;
26 template <VEX_Precision PREC> class CVEX_ContextT;
27 
28 /// Each VEX shader can have a transform bound to it. This transform is used
29 /// by the ptransform(), ntransform(), etc. functions to look up "world" or
30 /// "object" space.
31 ///
32 /// Variables in the shader are defined to be in "current" space. The CVEX
33 /// context allows you to specify various transforms from the current space to
34 /// another space. The other spaces are defined by the built-in VEX spaces:
35 /// - "space:world": Transform current space to "world" space
36 /// - "space:camera": Transform current to "camera" space
37 /// - "space:object": Transform current to "object" space
38 /// - "space:light": Transform current to "light" space
39 ///
40 /// It's also possible to specify a "lookup" helper class which can be used to
41 /// look up user defined spaces.
43 {
44 public:
46  ~CVEX_Transform();
47 
48  /// Resets the transform so it can be re-used by different
49  /// contexts.
50  void clear();
51 
52  /// Class that passes information about context of transform lookup
53  /// The @c cwd is the current node id (i.e. very likely the node associated
54  /// with the OpCaller. The @c worldId is the node id associated with the
55  /// current transform. That is, the object containing the node. If the
56  /// @c worldId isn't defined, the @c cwd will be used.
58  {
59  public:
60  LookupContext();
61  ~LookupContext();
62 
63  void clear();
64 
65  UT_OpCaller *opCaller() const { return myOpCaller; }
66  fpreal time() const { return myTime; }
67  /// Specifies the node for relative path searching
68  int cwdId() const
69  {
70  if (myCwdId < 0 && myOpCaller)
71  return myOpCaller->getOpId();
72  return myCwdId;
73  }
74  /// Specifies the node that defines the transform space
75  int worldId() const
76  {
77  if (myWorldId < 0)
78  {
79  // We want to give precedence to the cwd
80  // rather than the caller.
81  return cwdId();
82  }
83  return myWorldId;
84  }
85 
86  void setOpCaller(UT_OpCaller *c) { myOpCaller = c; }
87  void setTime(fpreal t) { myTime = t; }
88  void setCwdId(int id) { myCwdId = id; }
89  void setWorldId(int id) { myWorldId = id; }
90 
91  void setInputXform(int input, const UT_Matrix4D &xform);
92  void getInputXform(int input, UT_Matrix4D &xform) const;
93  void setInputXformId(int input, int nodeid);
94  int getInputXformId(int input) const;
95 
96  /// The user data is set by the Lookup class (if set). This allows the
97  /// lookup to keep per-instantiation data.
98  void *getUserData() const { return myUserData; }
99 
100  private:
101  void *myUserData;
102  UT_OpCaller *myOpCaller;
103  fpreal myTime;
104  int myCwdId;
105  int myWorldId;
106  UT_Array<UT_Matrix4D> myInputXform;
107  UT_IntArray myInputXformId;
108  };
109 
110  /// Class to look-up user defined spaces
112  {
113  public:
114  Lookup() {}
115  virtual ~Lookup();
116 
117  /// Allocate user data for the lookup context
118  virtual void *allocateUserData() const;
119  /// Delete the user data that was allocated for the lookup context
120  virtual void freeUserData(void *) const;
121  /// Reset the user data so it can be re-used later
122  virtual void clearUserData(void *) const;
123 
124  /// Look up a matrix which will transform the "current" space into the
125  /// named space.
126  virtual bool lookup(const char *name, UT_Matrix4D &m,
127  const LookupContext &context) = 0;
128 
129  /// Look up a matrix which transforms the named space into "current"
130  /// space. By default, this will call @c lookup() and compute the
131  /// inverse. If you have the inverse available, you may want to make
132  /// this more efficient by using it.
133  virtual bool lookupInverse(const char *name, UT_Matrix4D &m,
134  const LookupContext &context);
135 
136  /// Lookup NDC space given a name
137  virtual bool lookupToNDC(const char *name,
138  UT_Matrix4D &m,
139  const LookupContext &context,
140  bool &ortho) const;
141  virtual bool lookupFromNDC(const char *name,
142  UT_Matrix4D &m,
143  const LookupContext &context,
144  bool &ortho) const;
145 
146  /// Path functions
147  virtual bool abspath(UT_StringHolder &result,
148  const UT_StringHolder &relpath,
149  const LookupContext &context) const;
150  virtual int idFromPath(const UT_StringHolder &relpath,
151  const LookupContext &context) const;
152  virtual bool pathFromId(UT_StringHolder &result, int id,
153  const LookupContext &context) const;
154  };
155 
156  /// Set the lookup object for arbitrary spaces.
157  static void setLookup(const UT_SharedPtr<Lookup> &lookup);
158 
159  /// @{
160  /// Get information about the context
161  UT_OpCaller *opCaller() const { return myContext.opCaller(); }
162  fpreal time() const { return myContext.time(); }
163  int cwdId() const { return myContext.cwdId(); }
164  int worldId() const { return myContext.worldId(); }
165  void getInputXform(int input, UT_Matrix4D &xform) const { myContext.getInputXform(input, xform); }
166  int getInputXformId(int input) const { return myContext.getInputXformId(input); }
167  /// @}
168 
169  /// @{
170  /// Set information about the context
171  void setOpCaller(UT_OpCaller *c) { myContext.setOpCaller(c); }
172  void setTime(fpreal t) { myContext.setTime(t); }
173  void setCwdId(int id) { myContext.setCwdId(id); }
174  void setWorldId(int id) { myContext.setWorldId(id); }
175  void setInputXform(int id, const UT_Matrix4D &xform) { myContext.setInputXform(id, xform); }
176  void setInputXformId(int id, int nodeid) { myContext.setInputXformId(id, nodeid); }
177  /// @}
178 
179 private:
180  // Note: The LookupContext must remain in scope during the lifetime of
181  // this object.
182  VEX_TransformContext *context() const;
183 
184  cvex_TransformData *myData;
185  LookupContext myContext;
186 
187  template <VEX_Precision ALLPREC>
188  friend class CVEX_ContextT;
189 };
190 
191 #endif
GLenum GLenum GLenum input
Definition: glew.h:13879
GLuint id
Definition: glew.h:1679
int getInputXformId(int input) const
GLuint const GLchar * name
Definition: glew.h:1814
void setInputXformId(int id, int nodeid)
Class to look-up user defined spaces.
const GLdouble * m
Definition: glew.h:9124
fpreal time() const
void getInputXform(int input, UT_Matrix4D &xform) const
void setOpCaller(UT_OpCaller *c)
int worldId() const
Specifies the node that defines the transform space.
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
const GLfloat * c
Definition: glew.h:16296
UT_OpCaller * opCaller() const
int worldId() const
void setInputXform(int id, const UT_Matrix4D &xform)
void setOpCaller(UT_OpCaller *c)
int cwdId() const
basic_printf_context_t< buffer >::type context
Definition: printf.h:631
void setCwdId(int id)
fpreal64 fpreal
Definition: SYS_Types.h:277
#define CVEX_API
Definition: CVEX_API.h:12
GLuint64EXT * result
Definition: glew.h:14007
int cwdId() const
Specifies the node for relative path searching.
Call VEX from C++.
Definition: CVEX_Context.h:175
UT_OpCaller * opCaller() const
GLdouble GLdouble t
Definition: glew.h:1398
void setTime(fpreal t)
void setWorldId(int id)