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