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 <VEX/VEX_PodTypes.h>
16 #include <UT/UT_Array.h>
17 #include <UT/UT_IntArray.h>
18 #include <UT/UT_Matrix4.h>
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_OpCaller.h>
21 #include <UT/UT_SharedPtr.h>
22 
23 class VEX_TransformContext;
24 class UT_OpCaller;
25 class UT_OpGraphProxy;
26 class UT_StringHolder;
27 class cvex_TransformData;
28 template <VEX_Precision PREC> class CVEX_ContextT;
29 
30 /// Each VEX shader can have a transform bound to it. This transform is used
31 /// by the ptransform(), ntransform(), etc. functions to look up "world" or
32 /// "object" space.
33 ///
34 /// Variables in the shader are defined to be in "current" space. The CVEX
35 /// context allows you to specify various transforms from the current space to
36 /// another space. The other spaces are defined by the built-in VEX spaces:
37 /// - "space:world": Transform current space to "world" space
38 /// - "space:camera": Transform current to "camera" space
39 /// - "space:object": Transform current to "object" space
40 /// - "space:light": Transform current to "light" space
41 ///
42 /// It's also possible to specify a "lookup" helper class which can be used to
43 /// look up user defined spaces.
45 {
46 public:
48  ~CVEX_Transform();
49 
51 
52  /// Resets the transform so it can be re-used by different
53  /// contexts.
54  void clear();
55 
56  /// Class that passes information about context of transform lookup
57  /// The @c cwd is the current node id (i.e. very likely the node associated
58  /// with the OpCaller. The @c worldId is the node id associated with the
59  /// current transform. That is, the object containing the node. If the
60  /// @c worldId isn't defined, the @c cwd will be used.
62  {
63  public:
64  LookupContext();
65  ~LookupContext();
66 
68 
69  void clear();
70 
71  UT_OpCaller *opCaller() const { return myOpCaller; }
72  const UT_OpGraphProxy *opGraphProxy() const { return myOpGraphProxy; }
73  fpreal time() const { return myTime; }
74  /// Specifies the node for relative path searching
75  int cwdId() const
76  {
77  if (myCwdId < 0 && myOpCaller)
78  return myOpCaller->getOpId();
79  return myCwdId;
80  }
81  /// The node index in the graph proxy for searching, kept separate
82  /// to avoid confusing old code that assumes direct proxies.
83  int graphCwdId() const
84  {
85  return myGraphCwdId;
86  }
87  /// Specifies the node that defines the transform space
88  int worldId() const
89  {
90  if (myWorldId < 0)
91  {
92  // We want to give precedence to the cwd
93  // rather than the caller.
94  return cwdId();
95  }
96  return myWorldId;
97  }
98 
99  void setOpCaller(UT_OpCaller *c) { myOpCaller = c; }
100  void setOpGraphProxy(const UT_OpGraphProxy *graph) { myOpGraphProxy = graph; }
101  void setTime(fpreal t) { myTime = t; }
102  void setCwdId(int id) { myCwdId = id; }
103  void setGraphCwdId(int id) { myGraphCwdId = id; }
104  void setWorldId(int id) { myWorldId = id; }
105 
106  void setInputXform(int input, const UT_Matrix4D &xform);
107  void getInputXform(int input, UT_Matrix4D &xform) const;
108  void setInputXformId(int input, int nodeid);
109  int getInputXformId(int input) const;
110 
111  /// The user data is set by the Lookup class (if set). This allows the
112  /// lookup to keep per-instantiation data.
113  void *getUserData() const { return myUserData; }
114 
115  private:
116  void *myUserData = nullptr;
117  UT_OpCaller *myOpCaller = nullptr;
118  const UT_OpGraphProxy *myOpGraphProxy = nullptr;
119  fpreal myTime = 0;
120  int myCwdId = -1;
121  int myGraphCwdId = -1;
122  int myWorldId = -1;
123  UT_Array<UT_Matrix4D> myInputXform;
124  UT_IntArray myInputXformId;
125  };
126 
127  /// Class to look-up user defined spaces
129  {
130  public:
131  Lookup() {}
132  virtual ~Lookup();
133 
135 
136  /// Allocate user data for the lookup context
137  virtual void *allocateUserData() const;
138  /// Delete the user data that was allocated for the lookup context
139  virtual void freeUserData(void *) const;
140  /// Reset the user data so it can be re-used later
141  virtual void clearUserData(void *) const;
142 
143  /// Look up a matrix which will transform the "current" space into the
144  /// named space.
145  virtual bool lookup(const char *name, UT_Matrix4D &m,
146  const LookupContext &context) = 0;
147 
148  /// Look up a matrix which transforms the named space into "current"
149  /// space. By default, this will call @c lookup() and compute the
150  /// inverse. If you have the inverse available, you may want to make
151  /// this more efficient by using it.
152  virtual bool lookupInverse(const char *name, UT_Matrix4D &m,
153  const LookupContext &context);
154 
155  /// Lookup NDC space given a name
156  virtual bool lookupToNDC(const char *name,
157  UT_Matrix4D &m,
158  const LookupContext &context,
159  bool &ortho) const;
160  virtual bool lookupFromNDC(const char *name,
161  UT_Matrix4D &m,
162  const LookupContext &context,
163  bool &ortho) const;
164 
165  /// Path functions
166  virtual bool abspath(UT_StringHolder &result,
167  const UT_StringHolder &relpath,
168  const LookupContext &context) const;
169  virtual int idFromPath(const UT_StringHolder &relpath,
170  const LookupContext &context) const;
171  virtual bool pathFromId(UT_StringHolder &result, int id,
172  const LookupContext &context) const;
173  };
174 
175  /// Set the lookup object for arbitrary spaces.
176  static void setLookup(const UT_SharedPtr<Lookup> &lookup);
177 
178  /// @{
179  /// Get information about the context
180  UT_OpCaller *opCaller() const { return myContext.opCaller(); }
181  const UT_OpGraphProxy *opGraphProxy() const { return myContext.opGraphProxy(); }
182  fpreal time() const { return myContext.time(); }
183  int cwdId() const { return myContext.cwdId(); }
184  int graphCwdId() const { return myContext.graphCwdId(); }
185  int worldId() const { return myContext.worldId(); }
186  void getInputXform(int input, UT_Matrix4D &xform) const { myContext.getInputXform(input, xform); }
187  int getInputXformId(int input) const { return myContext.getInputXformId(input); }
188  /// @}
189 
190  /// @{
191  /// Set information about the context
192  void setOpCaller(UT_OpCaller *c) { myContext.setOpCaller(c); }
193  void setOpGraphProxy(const UT_OpGraphProxy *graph) { myContext.setOpGraphProxy(graph); }
194  void setTime(fpreal t) { myContext.setTime(t); }
195  void setCwdId(int id) { myContext.setCwdId(id); }
196  void setGraphCwdId(int id) { myContext.setGraphCwdId(id); }
197  void setWorldId(int id) { myContext.setWorldId(id); }
198  void setInputXform(int id, const UT_Matrix4D &xform) { myContext.setInputXform(id, xform); }
199  void setInputXformId(int id, int nodeid) { myContext.setInputXformId(id, nodeid); }
200  /// @}
201 
202 private:
203  // Note: The LookupContext must remain in scope during the lifetime of
204  // this object.
205  VEX_TransformContext *context() const;
206 
207  cvex_TransformData *myData;
208  LookupContext myContext;
209 
210  template <VEX_Precision ALLPREC>
211  friend class CVEX_ContextT;
212 };
213 
214 #endif
int getInputXformId(int input) const
void setOpGraphProxy(const UT_OpGraphProxy *graph)
void setInputXformId(int id, int nodeid)
Class to look-up user defined spaces.
const UT_OpGraphProxy * opGraphProxy() const
**But if you need a result
Definition: thread.h:622
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:36
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint id
Definition: glcorearb.h:655
int graphCwdId() const
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_OpCaller * opCaller() const
GLdouble t
Definition: glad.h:2397
const UT_OpGraphProxy * opGraphProxy() const
int worldId() const
void setInputXform(int id, const UT_Matrix4D &xform)
void setOpCaller(UT_OpCaller *c)
int cwdId() const
void setCwdId(int id)
fpreal64 fpreal
Definition: SYS_Types.h:283
#define CVEX_API
Definition: CVEX_API.h:12
GU_API void xform(CE_Context &context, bool recompile, int npts, const cl::Buffer &outPos, const cl::Buffer &inPos, const cl::Buffer &surfacexform, const cl::Buffer *grp=nullptr)
void setOpGraphProxy(const UT_OpGraphProxy *graph)
int cwdId() const
Specifies the node for relative path searching.
Call VEX from C++.
Definition: CVEX_Context.h:223
void setTime(fpreal t)
void setWorldId(int id)
void setGraphCwdId(int id)