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 getRenderingBounds(UT_BoundingBox &box) const override;
76  void getVelocityRange(
77  UT_Vector3 &min,
78  UT_Vector3 &max) const override;
79  void getWidthRange(
80  fpreal &wmin,
81  fpreal &wmax) const override;
82  void getPrimitiveName(
83  const GU_PrimPacked *prim,
84  UT_WorkBuffer &wbuf) const override;
85 
86  bool unpack(GU_Detail &destgdp,
87  const UT_Matrix4D *transform) const override;
88  bool isLoaded() const override;
89 
91  GU_PackedContext *context = 0) const override;
92 
93  /// Report memory usage (includes all shared memory)
94  int64 getMemoryUsage(bool inclusive) const override;
95 
96  /// Count memory usage using a UT_MemoryCounter in order to count
97  /// shared memory correctly.
99  bool inclusive) const override;
100  /// @}
101 
102  /// @{
103  /// Member data accessors for intrinsics
104  UT_StringHolder filename() const { return myCache.filename(); }
105  UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const { return filename(); }
106  UT_StringHolder unexpanded() const { return myUnexpanded; }
107  UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const { return unexpanded(); }
109  {
110  myUnexpanded = f;
111  makeFilename(prim);
112  }
113  fpreal expandFrame() const { return myExpandFrame; }
115  { return expandFrame(); }
117  {
118  myExpandFrame = f;
119  makeFilename(prim);
120  }
121  bool expandFilename() const { return myExpandFilename; }
122  bool intrinsicExpandFilename(const GU_PrimPacked *prim) const { return expandFilename(); }
124  {
125  myExpandFilename = b;
126  makeFilename(prim);
127  }
128  /// @}
129 
130  static exint getCacheVersion();
131 
132  /// Load the point geometry into the given detail
133  GU_ConstDetailHandle getPointCloud() const;
134 
136  {
137  public:
139  : myFilename()
140  , myResolved(false)
141  {
142  }
143  CacheItem(const UT_StringHolder &filename)
144  : myFilename(filename)
145  , myResolved(false)
146  {
147  }
148  CacheItem(const CacheItem &src)
149  : myFilename(src.myFilename)
150  , myResolved(false)
151  {
152  }
154  {
155  clear();
156  }
157 
158  /// Assignment operator
160  {
161  if (&src != this)
162  {
163  clear();
164  setFilename(src.myFilename);
165  }
166  return *this;
167  }
168 
169  /// Clear the item (possibly releasing from the cache)
170  void clear()
171  {
172  if (myResolved)
173  {
174  releaseFromCache(myFilename);
175  myResolved = false;
176  }
177  }
178 
179  /// Check to see if the cache would be dirtied with the given filename
180  bool isDifferentFile(const char *filename) const;
181 
182  /// Change the filename. Returns true if the filename changed
183  void setFilename(const UT_StringHolder &filename)
184  {
185  if (filename != myFilename)
186  {
187  clear();
188  myFilename = filename;
189  }
190  }
191 
192  /// Access the file
193  GU_ConstDetailHandle get(const GU_PackedImpl &impl) const
194  {
195  return GU_PackedDisk::loadFromCache(myFilename, myResolved, impl);
196  }
197 
198  /// Get point cloud for file
200  {
201  return GU_PackedDisk::loadPointCloudFromCache(myFilename,
202  myResolved, impl);
203  }
204 
205  /// Get bounding box
207  {
208  return GU_PackedDisk::loadBoxFromCache(myFilename, myResolved, box);
209  }
210  /// Get velocity range
211  bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
212  {
213  return GU_PackedDisk::loadVelocityRangeFromCache(myFilename,
214  myResolved, vmin, vmax);
215  }
216  /// Get width range
217  bool getWidthRange(fpreal &wmin, fpreal &wmax) const
218  {
219  return GU_PackedDisk::loadWidthRangeFromCache(myFilename,
220  myResolved, wmin, wmax);
221  }
222 
223  /// Check if cache has been loaded from disk
224  bool isLoaded() const { return GU_PackedDisk::checkIsLoaded(myFilename, myResolved); }
225 
226 
227  /// Accessors
228  const UT_StringHolder &filename() const { return myFilename; }
229 
230  private:
231  UT_StringHolder myFilename;
232  mutable bool myResolved;
233  };
234 protected:
235  template <typename T>
236  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
237 
238  /// Returns if the filename has changed
239  void makeFilename(GU_PrimPacked *prim);
240 
246 
247 private:
248  friend class CacheItem;
249  /// Resolve a disk file, using the shared cache for disk files
250  /// The bool passed in should be initialized to false. You @b must call @c
251  /// releaseFile() if you no longer reference the file (and the cache can
252  /// remove it). It's a good idea to use @c CacheItem
253  static GU_ConstDetailHandle loadFromCache(const UT_StringRef &filename,
254  bool &resolved,
255  const GU_PackedImpl &impl);
256 
257  /// Load point cloud from a disk file, using the shared disk cache.
258  /// The bool passed in should be initialized to false. You @b must call @c
259  /// releaseFile() if you no longer reference the file (and the cache can
260  /// remove it). It's a good idea to use @c CacheItem
261  static GU_ConstDetailHandle loadPointCloudFromCache(
262  const UT_StringRef &filename,
263  bool &resolved,
264  const GU_PackedImpl &impl);
265 
266  /// Resolve bounding box for a disk file using the shared disk cache.
267  /// The bool passed in should be initialized to false. You @b must call @c
268  /// releaseFile() if you no longer reference the file (and the cache can
269  /// remove it). It's a good idea to use @c CacheItem
270  static bool loadBoxFromCache(const UT_StringRef &filename,
271  bool &resolved, UT_BoundingBox &box);
272 
273  /// Get the velocity range for a disk file using the shared disk.
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 bool loadVelocityRangeFromCache(const UT_StringRef &filename,
278  bool &resolved,
279  UT_Vector3 &vmin, UT_Vector3 &vmax);
280 
281  /// Get the width attribute range for a disk file using the shared disk.
282  /// The bool passed in should be initialized to false. You @b must call @c
283  /// releaseFile() if you no longer reference the file (and the cache can
284  /// remove it). It's a good idea to use @c CacheItem
285  static bool loadWidthRangeFromCache(const UT_StringRef &filename,
286  bool &resolved,
287  fpreal &vmin, fpreal &vmax);
288 
289  /// Indicate you no longer need the item in the cache. It's a good idea to
290  /// use @c CacheItem
291  static void releaseFromCache(const UT_StringRef &filename);
292 
293  /// Checked if the cached file has been loaded
294  static bool checkIsLoaded(const UT_StringRef &filename, bool& resolved);
295 
296  static GA_PrimitiveTypeId theTypeId;
297 };
298 
299 #endif
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const =0
Geometry File procedural.
Definition: GU_PackedDisk.h:21
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GT_API const UT_StringHolder filename
GLuint counter
Definition: glew.h:2745
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 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
bool getBounds(UT_BoundingBox &box) const
Get bounding box.
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)
GLenum src
Definition: glcorearb.h:1793
#define GA_INVALID_OFFSET
Definition: GA_Types.h:677
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
GLuint GLenum GLenum transform
Definition: glew.h:15055
virtual bool isLoaded() const
GA_Size GA_Offset
Definition: GA_Types.h:640
void setFilename(const UT_StringHolder &filename)
Change the filename. Returns true if the filename changed.
void clear()
Clear the item (possibly releasing from the cache)
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
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.
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.
GLsizei const GLint box[]
Definition: glew.h:11654
UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
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)
GLfloat f
Definition: glcorearb.h:1926
UT_StringHolder filename() const
bool expandFilename() const
bool isLoaded() const
Check if cache has been loaded from disk.
fpreal myExpandFrame
UT_StringHolder myUnexpanded
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)
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0