HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_SopResolver.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: GU_SopResolver.h ( GU Library, C++)
7  *
8  * COMMENTS: Resolver class for resolving filenames like "op:/soppath"
9  */
10 
11 #ifndef __GU_SopResolver__
12 #define __GU_SopResolver__
13 
14 #include "GU_API.h"
15 #include <SYS/SYS_Types.h>
16 #include <UT/UT_ValArray.h>
17 #include <UT/UT_String.h>
18 #include <UT/UT_StringMap.h>
19 #include <UT/UT_Matrix4.h>
20 #include <VEX/VEX_GeoInputs.h>
21 #include "GU_DetailHandle.h"
22 
23 // Class to query an input on a VEX geometry
25 {
26 public:
28  ~GU_VexGeoInputs() override;
29 
30  /// Clear the geometry inputs. Note that this should be done before the
31  /// VEX_Instance is released (e.g. via CVEX_RunData::clear()) to avoid
32  /// reusing a VEX_Instance with stale geometry inputs.
33  void clear();
34 
35  // You can register this class as a callback for when geo inputs
36  // are destroyed.
38  {
39  public:
40  ClearCB() {}
41  virtual ~ClearCB() {}
42 
43  virtual void clear() {}
44  };
45 
46  /// When originally designed the idea was to allow delayed discovery
47  /// of VEX inputs. In practice this proves infeasible, so we mandate
48  /// all inputs are cooked & stored prior to execution. peekInput()
49  /// and getInput() thus become equivalent.
50  const GU_Detail *peekInput(int idx) const
51  {
52  return getInput(idx);
53  }
54  const GU_Detail *getInput(int idx) const
55  {
56  if (idx < minInputIdx() || idx > maxInputIdx())
57  return 0;
58  if (idx < 0)
59  return myNegInputCache(-(idx+1));
60  else
61  return myPosInputCache(idx);
62  }
63 
64  /// Does not gain ownership of gdp, the caller should keep
65  /// it in scope until destruction
66  void setInput(int idx, const GU_Detail *gdp)
67  {
68  if (idx < 0)
69  {
70  idx = - (idx + 1);
71  myNegInputCache.forcedRef(idx) = gdp;
72  myNegVexGeoCache.forcedRef(idx) = 0;
73  }
74  else
75  {
76  myPosInputCache.forcedRef(idx) = gdp;
77  myPosVexGeoCache.forcedRef(idx) = 0;
78  }
79  }
80 
81  /// Adds a callback to be invoked when the GU_VexGeoInputs
82  /// is destroyed.
83  void addClearCB(ClearCB *cb)
84  {
85  myClearCBList.append(cb);
86  }
87 
88  /// The GVEX layer stores the cache for the input in these structures,
89  /// this ensures each invocation of VEX will have its own
90  /// cache. The GU_VexGeoInputs should thus be shared across threads
91  /// to ensure separate threads use the same cache (so point clouds
92  /// are not built twice, etc)
93  void *getVexCache(int idx) const
94  {
95  if (idx < minInputIdx() || idx > maxInputIdx())
96  return 0;
97  if (idx < 0)
98  return myNegVexGeoCache(-(idx+1));
99  else
100  return myPosVexGeoCache(idx);
101  }
102 
103  void *getVexCache(const UT_StringRef &key) const
104  {
105  auto it = myVexGeoCacheMap.find(key);
106 
107  if( it == myVexGeoCacheMap.end() )
108  return NULL;
109 
110  return it->second;
111  }
112  void setVexCache(int idx, void *cache)
113  {
114  UT_ASSERT(idx >= minInputIdx() && idx <= maxInputIdx());
115  {
116  // Must either be clearing or setting the first time,
117  // setting an already set cache suggests this was not
118  // properly locked by the caller.
119  if (idx < 0)
120  {
121  idx = - (idx + 1);
122  UT_ASSERT(!myNegVexGeoCache(idx) || !cache);
123  myNegVexGeoCache(idx) = cache;
124  }
125  else
126  {
127  UT_ASSERT(!myPosVexGeoCache(idx) || !cache);
128  myPosVexGeoCache(idx) = cache;
129  }
130  }
131  }
132 
133  void setVexCache(const UT_StringRef &key, void *cache)
134  {
135  // Must either be clearing or setting the first time,
136  // setting an already set cache suggests this was not
137  // properly locked by the caller.
138  UT_ASSERT(!myVexGeoCacheMap.contains(key) || !cache );
139  myVexGeoCacheMap.insert( std::make_pair(key,cache ) );
140  }
141 
142 
143  /// Valid ranges are inclusive from minInputIdx to maXInputIdx.
144  /// Note this can be negative!
145  exint minInputIdx() const { return - myNegInputCache.entries(); }
146  exint maxInputIdx() const { return myPosInputCache.entries() - 1; }
147 
148 protected:
149  // We do not own these, they are assumed to be owned
150  // by the entity invoking setInput.
156 
157  // We own this list of callback objects.
159 };
160 
161 // Class to query a SOP's detail for the resolver
163 {
164 public:
166  {
167  myOpId = -1;
168  myFrameSpecified = false;
169  myTimeSpecified = false;
170  myIsDopData = false;
171  myXform.identity();
172  }
173  // If a detail has been locked, then it will be unlocked automatically on
174  // destruction.
175  ~GU_SopQuery() { clear(); }
176 
177  void clear();
178  void clearButLeaveTime();
179 
181  { myDetail = handle;
182  myDetail.addPreserveRequest();
183  }
184  void setXform(const UT_Matrix4D &xform)
185  { myXform = xform; }
186 
187  GU_ConstDetailHandle &getDetail(const char *fullpath, int relative_to=-1);
188  void getWorldTransform(UT_Matrix4D &xform,
189  const char *fullpath, int relative_to=-1);
190  int getOpId() const { return myOpId; }
191  bool getFlagInterest() const{ return myFlagInterest; }
192  int getSourceId() const { return mySourceOpId; }
193  bool isDopData() const { return myIsDopData; }
194  void setIsDopData(bool isdop) { myIsDopData = isdop; }
195  void addDopReference(int callerid);
196  bool getFrame(fpreal &frame) const
197  {
198  if (myFrameSpecified)
199  frame = myFrame;
200  return myFrameSpecified;
201  }
202 
203  void setFrame(fpreal frame)
204  {
205  myFrameSpecified = true;
206  myFrame = frame;
207  }
208 
209  bool getTime(fpreal &frame) const
210  {
211  if (myTimeSpecified)
212  frame = myTime;
213  return myTimeSpecified;
214  }
215 
216  void setTime(fpreal frame)
217  {
218  myTimeSpecified = true;
219  myTime = frame;
220  }
221 
222  const UT_String &getSubPath() const { return mySubPath; }
223 
224 private:
225  GU_ConstDetailHandle myDetail;
226  UT_Matrix4D myXform;
227  int myOpId;
228  bool myFlagInterest;
229  int mySourceOpId;
230  bool myFrameSpecified;
231  fpreal myFrame;
232  bool myTimeSpecified;
233  fpreal myTime;
234  UT_String mySubPath;
235  bool myIsDopData;
236  friend class GU_SopResolver;
237 };
238 
239 //
240 // Note: The GU_SopResolver class shouldn't be accessed directly. All access
241 // should be performed through the GU_SopQuery class.
242 //
244 {
245 public:
246  GU_SopResolver();
247  virtual ~GU_SopResolver();
248 
249  static void setResolver(GU_SopResolver *resolver);
250  static GU_SopResolver *getResolver();
251 
252  /// Stealing the resolver will give you a copy of the current resolver,
253  /// clearing out ownership of the resolver. The caller of @c stealResolver
254  /// is responsible for deleting the stolen resolver.
255  static GU_SopResolver *stealResolver();
256 
257  // Lookup a path to see if it's a path to something that has geometry
258  static bool lookup(const char *fullpath, GU_SopQuery &q);
259  static bool lookupXform(const char *fullpath, GU_SopQuery &q);
260 
261  // Sub-class responsibilities: These shouldn't be called directly. They
262  // are only public for the SopQuery class.
263 
264  // Given an operator path, return the unique ID associated with the Op.
265  // Otherwise, return -1.
266  virtual int resolveId(const char *fullpath,
267  int relative_to, bool &flaginterest) = 0;
268 
269  // The resolveDetail method should set the handle in the query
270  // appropriately.
271  virtual bool resolveDetail(GU_SopQuery &q) = 0;
272  virtual bool resolveXform(GU_SopQuery &q) = 0;
273 
274  virtual void addDopReference(GU_SopQuery &q, int callerid) = 0;
275 };
276 
277 #endif
278 
bool getFlagInterest() const
short * getInput(int size) override
void setInput(int idx, const GU_Detail *gdp)
void * getVexCache(const UT_StringRef &key) const
int64 exint
Definition: SYS_Types.h:125
void setVexCache(int idx, void *cache)
bool getTime(fpreal &frame) const
void setXform(const UT_Matrix4D &xform)
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
int getSourceId() const
void setFrame(fpreal frame)
UT_ValArray< ClearCB * > myClearCBList
bool isDopData() const
const UT_String & getSubPath() const
UT_Array< const GU_Detail * > myPosInputCache
UT_StringMap< void * > myVexGeoCacheMap
UT_Array< void * > myPosVexGeoCache
UT_Array< void * > myNegVexGeoCache
exint maxInputIdx() const
#define GU_API
Definition: GU_API.h:14
UT_Array< const GU_Detail * > myNegInputCache
const GU_Detail * peekInput(int idx) const
void setDetail(const GU_ConstDetailHandle &handle)
exint minInputIdx() const
fpreal64 fpreal
Definition: SYS_Types.h:277
void setVexCache(const UT_StringRef &key, void *cache)
const GU_Detail * getInput(int idx) const
void * getVexCache(int idx) const
void addClearCB(ClearCB *cb)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
void setIsDopData(bool isdop)
bool getFrame(fpreal &frame) const
int getOpId() const
void setTime(fpreal frame)