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 
88 
89  bool unpack(GU_Detail &destgdp,
90  const UT_Matrix4D *transform) const override;
91  bool isLoaded() const override;
92 
94  GU_PackedContext *context = 0) const override;
95 
96  /// Report memory usage (includes all shared memory)
97  int64 getMemoryUsage(bool inclusive) const override;
98 
99  /// Count memory usage using a UT_MemoryCounter in order to count
100  /// shared memory correctly.
101  void countMemory(UT_MemoryCounter &counter,
102  bool inclusive) const override;
103  /// @}
104 
105  /// Treat as folder gives hint to UI that this packed geometry primitive
106  /// should be treated as a "folder"/"directory".
107  /// @{
108  bool treatAsFolder() const { return myTreatAsFolder; }
109  void setTreatAsFolder(bool b) { myTreatAsFolder = b; }
110  /// @}
111 
112  /// @{
113  /// Member data accessors for intrinsics
114  UT_StringHolder filename() const { return myCache.filename(); }
115  UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const { return filename(); }
116  UT_StringHolder unexpanded() const { return myUnexpanded; }
117  UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const { return unexpanded(); }
119  {
120  myUnexpanded = f;
121  makeFilename(prim);
122  }
123  fpreal expandFrame() const { return myExpandFrame; }
125  { return expandFrame(); }
127  {
128  myExpandFrame = f;
129  makeFilename(prim);
130  }
131  bool expandFilename() const { return myExpandFilename; }
132  bool intrinsicExpandFilename(const GU_PrimPacked *prim) const { return expandFilename(); }
134  {
135  myExpandFilename = b;
136  makeFilename(prim);
137  }
138  bool intrinsicTreatAsFolder(const GU_PrimPacked *prim) const
139  {
140  return treatAsFolder();
141  }
143  {
144  setTreatAsFolder(b);
145  }
146  /// @}
147 
148  static exint getCacheVersion();
149 
150  /// Load the point geometry into the given detail
151  GU_ConstDetailHandle getPointCloud() const;
152 
154  {
155  public:
157  : myFilename()
158  , myResolved(false)
159  {
160  }
161  CacheItem(const UT_StringHolder &filename)
162  : myFilename(filename)
163  , myResolved(false)
164  {
165  }
166  CacheItem(const CacheItem &src)
167  : myFilename(src.myFilename)
168  , myResolved(false)
169  {
170  }
172  {
173  clear();
174  }
175 
176  /// Assignment operator
178  {
179  if (&src != this)
180  {
181  clear();
182  setFilename(src.myFilename);
183  }
184  return *this;
185  }
186 
187  /// Clear the item (possibly releasing from the cache)
188  void clear()
189  {
190  if (myResolved)
191  {
192  releaseFromCache(myFilename);
193  myResolved = false;
194  }
195  }
196 
197  /// Check to see if the cache would be dirtied with the given filename
198  bool isDifferentFile(const char *filename) const;
199 
200  /// Change the filename. Returns true if the filename changed
201  void setFilename(const UT_StringHolder &filename)
202  {
203  if (filename != myFilename)
204  {
205  clear();
206  myFilename = filename;
207  }
208  }
209 
210  /// Access the file
211  GU_ConstDetailHandle get(const GU_PackedImpl &impl) const
212  {
213  return GU_PackedDisk::loadFromCache(myFilename, myResolved, impl);
214  }
215 
216  /// Get point cloud for file
218  {
219  return GU_PackedDisk::loadPointCloudFromCache(myFilename,
220  myResolved, impl);
221  }
222 
223  /// Get bounding box
224  bool getBounds(UT_BoundingBox &box) const;
225  /// Get visible bounding box
226  bool getVisibleBounds(UT_BoundingBox &box) const;
227  /// Get velocity range
228  bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
229  {
230  return GU_PackedDisk::loadVelocityRangeFromCache(myFilename,
231  myResolved, vmin, vmax);
232  }
233  /// Get width range
234  bool getWidthRange(fpreal &wmin, fpreal &wmax) const
235  {
236  return GU_PackedDisk::loadWidthRangeFromCache(myFilename,
237  myResolved, wmin, wmax);
238  }
239 
240  exint getNumPackedPrims() const;
241 
242  /// Check if cache has been loaded from disk
243  bool isLoaded() const { return GU_PackedDisk::checkIsLoaded(myFilename, myResolved); }
244 
245 
246  /// Accessors
247  const UT_StringHolder &filename() const { return myFilename; }
248 
249  private:
250  UT_StringHolder myFilename;
251  mutable bool myResolved;
252  };
253 protected:
254  template <typename T>
255  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
256 
257  /// Returns if the filename has changed
258  void makeFilename(GU_PrimPacked *prim);
259 
266 
267 private:
268  friend class CacheItem;
269  /// Resolve a disk file, using the shared cache for disk files
270  /// The bool passed in should be initialized to false. You @b must call @c
271  /// releaseFile() if you no longer reference the file (and the cache can
272  /// remove it). It's a good idea to use @c CacheItem
273  static GU_ConstDetailHandle loadFromCache(const UT_StringRef &filename,
274  bool &resolved,
275  const GU_PackedImpl &impl);
276 
277  /// Load point cloud from a disk file, using the shared disk cache.
278  /// The bool passed in should be initialized to false. You @b must call @c
279  /// releaseFile() if you no longer reference the file (and the cache can
280  /// remove it). It's a good idea to use @c CacheItem
281  static GU_ConstDetailHandle loadPointCloudFromCache(
282  const UT_StringRef &filename,
283  bool &resolved,
284  const GU_PackedImpl &impl);
285 
286  /// Resolve bounding box for a disk file using the shared disk cache.
287  /// The bool passed in should be initialized to false. You @b must call @c
288  /// releaseFile() if you no longer reference the file (and the cache can
289  /// remove it). It's a good idea to use @c CacheItem
290  template <bool VISIBLE_ONLY>
291  static bool loadBoxFromCache(const UT_StringRef &filename,
292  bool &resolved, UT_BoundingBox &box);
293 
294  /// Get the velocity range for a disk file using the shared disk.
295  /// The bool passed in should be initialized to false. You @b must call @c
296  /// releaseFile() if you no longer reference the file (and the cache can
297  /// remove it). It's a good idea to use @c CacheItem
298  static bool loadVelocityRangeFromCache(const UT_StringRef &filename,
299  bool &resolved,
300  UT_Vector3 &vmin, UT_Vector3 &vmax);
301 
302  /// Get the width attribute range for a disk file using the shared disk.
303  /// The bool passed in should be initialized to false. You @b must call @c
304  /// releaseFile() if you no longer reference the file (and the cache can
305  /// remove it). It's a good idea to use @c CacheItem
306  static bool loadWidthRangeFromCache(const UT_StringRef &filename,
307  bool &resolved,
308  fpreal &vmin, fpreal &vmax);
309 
310  /// Indicate you no longer need the item in the cache. It's a good idea to
311  /// use @c CacheItem
312  static void releaseFromCache(const UT_StringRef &filename);
313 
314  /// Checked if the cached file has been loaded
315  static bool checkIsLoaded(const UT_StringRef &filename, bool& resolved);
316 
317  /// Resolve the number of packed prims contained in the geometry by parsing
318  /// the file metadata.
319  static bool loadNumPackedPrimsFromCache(const UT_StringRef &filename,
320  bool &resolved,
321  exint &num_out);
322 
323  static GA_PrimitiveTypeId theTypeId;
324 };
325 
326 #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
UT_Optional< exint > getNumPackedPrims(const GU_PrimPacked *prim) const
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:694
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
virtual bool isLoaded() const
GA_Size GA_Offset
Definition: GA_Types.h:653
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:87
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:283
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