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