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