HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PackedDisk.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_PackedDisk.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PackedDisk__
12 #define __GU_PackedDisk__
13 
14 #include "GU_PackedImpl.h"
15 #include <UT/UT_StringHolder.h>
16 
18 class UT_MemoryCounter;
19 
20 /// Geometry File procedural
22 {
23 public:
24  GU_PackedDisk();
26  ~GU_PackedDisk() override;
27 
28  /// Convenience method to create a packed primitive in the destination
29  /// detail.
30  ///
31  /// Returns a NULL pointer if the process fails.
32  static GU_PrimPacked *packedDisk(GU_Detail &dest,
33  const char *filename,
34  bool do_expanding,
35  fpreal expand_frame,
37 
38  /// Clear the disk cache. This will clear the cache, but not dirty any
39  /// existing primitives. This is what gets invoked when calling
40  /// GU_PrimPacked::clearCachedGeometry(). The method returns the number of
41  /// items cleared.
42  static exint clearDiskCache();
43 
44  /// Install the procedural
45  static void install(GA_PrimitiveFactory *prim);
46 
47  /// Get the type ID for the GU_PackedDisk primitive type.
49  {
50  return theTypeId;
51  }
52 
53  /// @{
54  /// Implementation of GU_PackedImpl interface
55  GU_PackedFactory *getFactory() const override;
56  GU_PackedImpl *copy() const override;
57  void clearData() override;
58 
59  bool isValid() const override;
60  bool load(GU_PrimPacked *prim, const UT_Options &options,
61  const GA_LoadMap &map) override
62  { return loadFrom(prim, options, map); }
63  bool supportsJSONLoad() const override
64  { return true; }
66  GU_PrimPacked *prim,
67  const UT_JSONValueMap &options,
68  const GA_LoadMap &map) override
69  { return loadFrom(prim, options, map); }
70  void update(GU_PrimPacked *prim,
71  const UT_Options &options) override;
72  bool save(UT_Options &options,
73  const GA_SaveMap &map) const override;
74  bool getBounds(UT_BoundingBox &box) const override;
75  bool getVisibleBounds(UT_BoundingBox &box) const override;
76  bool getRenderingBounds(UT_BoundingBox &box) const override;
77  void getVelocityRange(
78  UT_Vector3 &min,
79  UT_Vector3 &max) const override;
80  void getWidthRange(
81  fpreal &wmin,
82  fpreal &wmax) const override;
83  void getPrimitiveName(
84  const GU_PrimPacked *prim,
85  UT_WorkBuffer &wbuf) const override;
86 
87  bool unpack(GU_Detail &destgdp,
88  const UT_Matrix4D *transform) const override;
89  bool isLoaded() const override;
90 
92  GU_PackedContext *context = 0) const override;
93 
94  /// Report memory usage (includes all shared memory)
95  int64 getMemoryUsage(bool inclusive) const override;
96 
97  /// Count memory usage using a UT_MemoryCounter in order to count
98  /// shared memory correctly.
99  void countMemory(UT_MemoryCounter &counter,
100  bool inclusive) const override;
101  /// @}
102 
103  /// Treat as folder gives hint to UI that this packed geometry primitive
104  /// should be treated as a "folder"/"directory".
105  /// @{
106  bool treatAsFolder() const { return myTreatAsFolder; }
107  void setTreatAsFolder(bool b) { myTreatAsFolder = b; }
108  /// @}
109 
110  /// @{
111  /// Member data accessors for intrinsics
112  UT_StringHolder filename() const { return myCache.filename(); }
113  UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const { return filename(); }
114  UT_StringHolder unexpanded() const { return myUnexpanded; }
115  UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const { return unexpanded(); }
117  {
118  myUnexpanded = f;
119  makeFilename(prim);
120  }
121  fpreal expandFrame() const { return myExpandFrame; }
123  { return expandFrame(); }
125  {
126  myExpandFrame = f;
127  makeFilename(prim);
128  }
129  bool expandFilename() const { return myExpandFilename; }
130  bool intrinsicExpandFilename(const GU_PrimPacked *prim) const { return expandFilename(); }
132  {
133  myExpandFilename = b;
134  makeFilename(prim);
135  }
136  bool intrinsicTreatAsFolder(const GU_PrimPacked *prim) const
137  {
138  return treatAsFolder();
139  }
141  {
142  setTreatAsFolder(b);
143  }
144  /// @}
145 
146  static exint getCacheVersion();
147 
148  /// Load the point geometry into the given detail
149  GU_ConstDetailHandle getPointCloud() const;
150 
152  {
153  public:
155  : myFilename()
156  , myResolved(false)
157  {
158  }
159  CacheItem(const UT_StringHolder &filename)
160  : myFilename(filename)
161  , myResolved(false)
162  {
163  }
164  CacheItem(const CacheItem &src)
165  : myFilename(src.myFilename)
166  , myResolved(false)
167  {
168  }
170  {
171  clear();
172  }
173 
174  /// Assignment operator
176  {
177  if (&src != this)
178  {
179  clear();
180  setFilename(src.myFilename);
181  }
182  return *this;
183  }
184 
185  /// Clear the item (possibly releasing from the cache)
186  void clear()
187  {
188  if (myResolved)
189  {
190  releaseFromCache(myFilename);
191  myResolved = false;
192  }
193  }
194 
195  /// Check to see if the cache would be dirtied with the given filename
196  bool isDifferentFile(const char *filename) const;
197 
198  /// Change the filename. Returns true if the filename changed
199  void setFilename(const UT_StringHolder &filename)
200  {
201  if (filename != myFilename)
202  {
203  clear();
204  myFilename = filename;
205  }
206  }
207 
208  /// Access the file
209  GU_ConstDetailHandle get(const GU_PackedImpl &impl) const
210  {
211  return GU_PackedDisk::loadFromCache(myFilename, myResolved, impl);
212  }
213 
214  /// Get point cloud for file
216  {
217  return GU_PackedDisk::loadPointCloudFromCache(myFilename,
218  myResolved, impl);
219  }
220 
221  /// Get bounding box
222  bool getBounds(UT_BoundingBox &box) const;
223  /// Get visible bounding box
224  bool getVisibleBounds(UT_BoundingBox &box) const;
225  /// Get velocity range
226  bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
227  {
228  return GU_PackedDisk::loadVelocityRangeFromCache(myFilename,
229  myResolved, vmin, vmax);
230  }
231  /// Get width range
232  bool getWidthRange(fpreal &wmin, fpreal &wmax) const
233  {
234  return GU_PackedDisk::loadWidthRangeFromCache(myFilename,
235  myResolved, wmin, wmax);
236  }
237 
238  /// Check if cache has been loaded from disk
239  bool isLoaded() const { return GU_PackedDisk::checkIsLoaded(myFilename, myResolved); }
240 
241 
242  /// Accessors
243  const UT_StringHolder &filename() const { return myFilename; }
244 
245  private:
246  UT_StringHolder myFilename;
247  mutable bool myResolved;
248  };
249 protected:
250  template <typename T>
251  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
252 
253  /// Returns if the filename has changed
254  void makeFilename(GU_PrimPacked *prim);
255 
262 
263 private:
264  friend class CacheItem;
265  /// Resolve a disk file, using the shared cache for disk files
266  /// The bool passed in should be initialized to false. You @b must call @c
267  /// releaseFile() if you no longer reference the file (and the cache can
268  /// remove it). It's a good idea to use @c CacheItem
269  static GU_ConstDetailHandle loadFromCache(const UT_StringRef &filename,
270  bool &resolved,
271  const GU_PackedImpl &impl);
272 
273  /// Load point cloud from a disk file, using the shared disk cache.
274  /// The bool passed in should be initialized to false. You @b must call @c
275  /// releaseFile() if you no longer reference the file (and the cache can
276  /// remove it). It's a good idea to use @c CacheItem
277  static GU_ConstDetailHandle loadPointCloudFromCache(
278  const UT_StringRef &filename,
279  bool &resolved,
280  const GU_PackedImpl &impl);
281 
282  /// Resolve bounding box for a disk file using the shared disk cache.
283  /// The bool passed in should be initialized to false. You @b must call @c
284  /// releaseFile() if you no longer reference the file (and the cache can
285  /// remove it). It's a good idea to use @c CacheItem
286  template <bool VISIBLE_ONLY>
287  static bool loadBoxFromCache(const UT_StringRef &filename,
288  bool &resolved, UT_BoundingBox &box);
289 
290  /// Get the velocity range for a disk file using the shared disk.
291  /// The bool passed in should be initialized to false. You @b must call @c
292  /// releaseFile() if you no longer reference the file (and the cache can
293  /// remove it). It's a good idea to use @c CacheItem
294  static bool loadVelocityRangeFromCache(const UT_StringRef &filename,
295  bool &resolved,
296  UT_Vector3 &vmin, UT_Vector3 &vmax);
297 
298  /// Get the width attribute range for a disk file using the shared disk.
299  /// The bool passed in should be initialized to false. You @b must call @c
300  /// releaseFile() if you no longer reference the file (and the cache can
301  /// remove it). It's a good idea to use @c CacheItem
302  static bool loadWidthRangeFromCache(const UT_StringRef &filename,
303  bool &resolved,
304  fpreal &vmin, fpreal &vmax);
305 
306  /// Indicate you no longer need the item in the cache. It's a good idea to
307  /// use @c CacheItem
308  static void releaseFromCache(const UT_StringRef &filename);
309 
310  /// Checked if the cached file has been loaded
311  static bool checkIsLoaded(const UT_StringRef &filename, bool& resolved);
312 
313  static GA_PrimitiveTypeId theTypeId;
314 };
315 
316 #endif
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const =0
Geometry File procedural.
Definition: GU_PackedDisk.h:21
GT_API const UT_StringHolder filename
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
void setExpandFilename(GU_PrimPacked *prim, bool b)
void setUnexpanded(GU_PrimPacked *prim, const UT_StringHolder &f)
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
bool intrinsicTreatAsFolder(const GU_PrimPacked *prim) const
bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map) override
Definition: GU_PackedDisk.h:60
static GA_PrimitiveTypeId typeId()
Get the type ID for the GU_PackedDisk primitive type.
Definition: GU_PackedDisk.h:48
int64 exint
Definition: SYS_Types.h:125
fpreal expandFrame() const
bool intrinsicExpandFilename(const GU_PrimPacked *prim) const
fpreal intrinsicExpandFrame(const GU_PrimPacked *prim) const
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool getWidthRange(fpreal &wmin, fpreal &wmax) const
Get width range.
virtual bool getBounds(UT_BoundingBox &box) const =0
Get the bounding box for the geometry (not including transforms)
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
virtual bool isLoaded() const
GA_Size GA_Offset
Definition: GA_Types.h:646
void setFilename(const UT_StringHolder &filename)
Change the filename. Returns true if the filename changed.
GLfloat f
Definition: glcorearb.h:1926
void clear()
Clear the item (possibly releasing from the cache)
virtual bool getVisibleBounds(UT_BoundingBox &box) const
void setExpandFrame(GU_PrimPacked *prim, fpreal f)
virtual void clearData()=0
virtual int64 getMemoryUsage(bool inclusive) const =0
Report memory usage (includes all shared memory)
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
bool treatAsFolder() const
virtual GU_PackedFactory * getFactory() const =0
Get the factory associated with this procedural.
virtual GU_ConstDetailHandle getPackedDetail(GU_PackedContext *context=0) const
long long int64
Definition: SYS_Types.h:116
Options during loading.
Definition: GA_LoadMap.h:42
#define GU_API
Definition: GU_API.h:14
GU_ConstDetailHandle getPointCloud(const GU_PackedImpl &impl) const
Get point cloud for file.
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_API const UT_StringHolder transform
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map) override
Definition: GU_PackedDisk.h:65
virtual void update(GU_PrimPacked *prim, const UT_Options &options)=0
const UT_StringHolder & filename() const
Accessors.
UT_StringHolder unexpanded() const
virtual void getPrimitiveName(const GU_PrimPacked *prim, UT_WorkBuffer &wbuf) const
bool supportsJSONLoad() const override
Definition: GU_PackedDisk.h:63
A map of string to various well defined value types.
Definition: UT_Options.h:84
bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
Get velocity range.
UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
void intrinsicSetTreatAsFolder(GU_PrimPacked *prim, bool b)
fpreal64 fpreal
Definition: SYS_Types.h:277
bool unpack(GU_Detail &destgdp, const GU_PrimPacked *prim) const
UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
CacheItem(const CacheItem &src)
UT_StringHolder filename() const
bool expandFilename() const
bool isLoaded() const
Check if cache has been loaded from disk.
fpreal myExpandFrame
UT_StringHolder myUnexpanded
void setTreatAsFolder(bool b)
virtual bool save(UT_Options &options, const GA_SaveMap &map) const =0
Copy the resolver data into the UT_Options for saving.
CacheItem & operator=(const CacheItem &src)
Assignment operator.
CacheItem myCache
CacheItem(const UT_StringHolder &filename)
GLenum src
Definition: glcorearb.h:1793
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0