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);
36 
37  /// Clear the disk cache. This will clear the cache, but not dirty any
38  /// existing primitives. This is what gets invoked when calling
39  /// GU_PrimPacked::clearCachedGeometry(). The method returns the number of
40  /// items cleared.
41  static exint clearDiskCache();
42 
43  /// Install the procedural
44  static void install(GA_PrimitiveFactory *prim);
45 
46  /// Get the type ID for the GU_PackedDisk primitive type.
48  {
49  return theTypeId;
50  }
51 
52  /// @{
53  /// Implementation of GU_PackedImpl interface
54  GU_PackedFactory *getFactory() const override;
55  GU_PackedImpl *copy() const override;
56  void clearData() override;
57 
58  bool isValid() const override;
59  bool load(GU_PrimPacked *prim, const UT_Options &options,
60  const GA_LoadMap &map) override
61  { return loadFrom(prim, options, map); }
62  bool supportsJSONLoad() const override
63  { return true; }
65  GU_PrimPacked *prim,
66  const UT_JSONValueMap &options,
67  const GA_LoadMap &map) override
68  { return loadFrom(prim, options, map); }
69  void update(GU_PrimPacked *prim,
70  const UT_Options &options) override;
71  bool save(UT_Options &options,
72  const GA_SaveMap &map) const override;
73  bool getBounds(UT_BoundingBox &box) const override;
74  bool getRenderingBounds(UT_BoundingBox &box) const override;
75  void getVelocityRange(
76  UT_Vector3 &min,
77  UT_Vector3 &max) const override;
78  void getWidthRange(
79  fpreal &wmin,
80  fpreal &wmax) const override;
81  void getPrimitiveName(
82  const GU_PrimPacked *prim,
83  UT_WorkBuffer &wbuf) const override;
84 
85  bool unpack(GU_Detail &destgdp,
86  const UT_Matrix4D *transform) const override;
87  bool isLoaded() const override;
88 
90  GU_PackedContext *context = 0) const override;
91 
92  /// Report memory usage (includes all shared memory)
93  int64 getMemoryUsage(bool inclusive) const override;
94 
95  /// Count memory usage using a UT_MemoryCounter in order to count
96  /// shared memory correctly.
98  bool inclusive) const override;
99  /// @}
100 
101  /// @{
102  /// Member data accessors for intrinsics
103  UT_StringHolder filename() const { return myCache.filename(); }
104  UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const { return filename(); }
105  UT_StringHolder unexpanded() const { return myUnexpanded; }
106  UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const { return unexpanded(); }
108  {
109  myUnexpanded = f;
110  makeFilename(prim);
111  }
112  fpreal expandFrame() const { return myExpandFrame; }
114  { return expandFrame(); }
116  {
117  myExpandFrame = f;
118  makeFilename(prim);
119  }
120  bool expandFilename() const { return myExpandFilename; }
121  bool intrinsicExpandFilename(const GU_PrimPacked *prim) const { return expandFilename(); }
123  {
124  myExpandFilename = b;
125  makeFilename(prim);
126  }
127  /// @}
128 
129  static exint getCacheVersion();
130 
131  /// Load the point geometry into the given detail
132  GU_ConstDetailHandle getPointCloud() const;
133 
135  {
136  public:
138  : myFilename()
139  , myResolved(false)
140  {
141  }
142  CacheItem(const UT_StringHolder &filename)
143  : myFilename(filename)
144  , myResolved(false)
145  {
146  }
147  CacheItem(const CacheItem &src)
148  : myFilename(src.myFilename)
149  , myResolved(false)
150  {
151  }
153  {
154  clear();
155  }
156 
157  /// Assignment operator
159  {
160  if (&src != this)
161  {
162  clear();
163  setFilename(src.myFilename);
164  }
165  return *this;
166  }
167 
168  /// Clear the item (possibly releasing from the cache)
169  void clear()
170  {
171  if (myResolved)
172  {
173  releaseFromCache(myFilename);
174  myResolved = false;
175  }
176  }
177 
178  /// Check to see if the cache would be dirtied with the given filename
179  bool isDifferentFile(const char *filename) const;
180 
181  /// Change the filename. Returns true if the filename changed
182  void setFilename(const UT_StringHolder &filename)
183  {
184  if (filename != myFilename)
185  {
186  clear();
187  myFilename = filename;
188  }
189  }
190 
191  /// Access the file
192  GU_ConstDetailHandle get(const GU_PackedImpl &impl) const
193  {
194  return GU_PackedDisk::loadFromCache(myFilename, myResolved, impl);
195  }
196 
197  /// Get point cloud for file
199  {
200  return GU_PackedDisk::loadPointCloudFromCache(myFilename,
201  myResolved, impl);
202  }
203 
204  /// Get bounding box
205  bool getBounds(UT_BoundingBox &box) const
206  {
207  return GU_PackedDisk::loadBoxFromCache(myFilename, myResolved, box);
208  }
209  /// Get velocity range
210  bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
211  {
212  return GU_PackedDisk::loadVelocityRangeFromCache(myFilename,
213  myResolved, vmin, vmax);
214  }
215  /// Get width range
216  bool getWidthRange(fpreal &wmin, fpreal &wmax) const
217  {
218  return GU_PackedDisk::loadWidthRangeFromCache(myFilename,
219  myResolved, wmin, wmax);
220  }
221 
222  /// Check if cache has been loaded from disk
223  bool isLoaded() const { return GU_PackedDisk::checkIsLoaded(myFilename, myResolved); }
224 
225 
226  /// Accessors
227  const UT_StringHolder &filename() const { return myFilename; }
228 
229  private:
230  UT_StringHolder myFilename;
231  mutable bool myResolved;
232  };
233 protected:
234  template <typename T>
235  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
236 
237  /// Returns if the filename has changed
238  void makeFilename(GU_PrimPacked *prim);
239 
245 
246 private:
247  friend class CacheItem;
248  /// Resolve a disk file, using the shared cache for disk files
249  /// The bool passed in should be initialized to false. You @b must call @c
250  /// releaseFile() if you no longer reference the file (and the cache can
251  /// remove it). It's a good idea to use @c CacheItem
252  static GU_ConstDetailHandle loadFromCache(const UT_StringRef &filename,
253  bool &resolved,
254  const GU_PackedImpl &impl);
255 
256  /// Load point cloud from a disk file, using the shared disk cache.
257  /// The bool passed in should be initialized to false. You @b must call @c
258  /// releaseFile() if you no longer reference the file (and the cache can
259  /// remove it). It's a good idea to use @c CacheItem
260  static GU_ConstDetailHandle loadPointCloudFromCache(
261  const UT_StringRef &filename,
262  bool &resolved,
263  const GU_PackedImpl &impl);
264 
265  /// Resolve bounding box for a disk file using the shared disk cache.
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 bool loadBoxFromCache(const UT_StringRef &filename,
270  bool &resolved, UT_BoundingBox &box);
271 
272  /// Get the velocity range for a disk file using the shared disk.
273  /// The bool passed in should be initialized to false. You @b must call @c
274  /// releaseFile() if you no longer reference the file (and the cache can
275  /// remove it). It's a good idea to use @c CacheItem
276  static bool loadVelocityRangeFromCache(const UT_StringRef &filename,
277  bool &resolved,
278  UT_Vector3 &vmin, UT_Vector3 &vmax);
279 
280  /// Get the width attribute range for a disk file using the shared disk.
281  /// The bool passed in should be initialized to false. You @b must call @c
282  /// releaseFile() if you no longer reference the file (and the cache can
283  /// remove it). It's a good idea to use @c CacheItem
284  static bool loadWidthRangeFromCache(const UT_StringRef &filename,
285  bool &resolved,
286  fpreal &vmin, fpreal &vmax);
287 
288  /// Indicate you no longer need the item in the cache. It's a good idea to
289  /// use @c CacheItem
290  static void releaseFromCache(const UT_StringRef &filename);
291 
292  /// Checked if the cached file has been loaded
293  static bool checkIsLoaded(const UT_StringRef &filename, bool& resolved);
294 
295  static GA_PrimitiveTypeId theTypeId;
296 };
297 
298 #endif
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
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.
GLenum src
Definition: glew.h:2410
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:59
GLuint GLenum GLenum transform
Definition: glew.h:14742
static GA_PrimitiveTypeId typeId()
Get the type ID for the GU_PackedDisk primitive type.
Definition: GU_PackedDisk.h:47
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
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)
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
virtual bool isLoaded() const
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)
GLclampf f
Definition: glew.h:3499
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:64
virtual void update(GU_PrimPacked *prim, const UT_Options &options)=0
const UT_StringHolder & filename() const
Accessors.
UT_StringHolder unexpanded() const
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
virtual void getPrimitiveName(const GU_PrimPacked *prim, UT_WorkBuffer &wbuf) const
bool supportsJSONLoad() const override
Definition: GU_PackedDisk.h:62
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.
GLuint counter
Definition: glew.h:2740
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
CacheItem(const CacheItem &src)
UT_StringHolder filename() const
bool expandFilename() const
bool isLoaded() const
Check if cache has been loaded from disk.
fpreal myExpandFrame
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
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