HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GU_PackedDisk();
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  virtual GU_PackedFactory *getFactory() const;
55  virtual GU_PackedImpl *copy() const;
56  virtual void clearData();
57 
58  virtual bool isValid() const;
59  virtual bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map)
60  { return loadFrom(prim, options, map); }
61  virtual bool supportsJSONLoad() const { return true; }
62  virtual bool loadFromJSON(
63  GU_PrimPacked *prim,
64  const UT_JSONValueMap &options,
65  const GA_LoadMap &map)
66  { return loadFrom(prim, options, map); }
67  virtual void update(GU_PrimPacked *prim, const UT_Options &options);
68  virtual bool save(UT_Options &options, const GA_SaveMap &map) const;
69  virtual bool getBounds(UT_BoundingBox &box) const;
70  virtual bool getRenderingBounds(UT_BoundingBox &box) const;
71  virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max)const;
72  virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const;
73  virtual void getPrimitiveName(const GU_PrimPacked *prim, UT_WorkBuffer &wbuf) const;
74 
75  virtual bool unpack(GU_Detail &destgdp) const;
76  virtual bool isLoaded() const;
77  virtual GU_ConstDetailHandle getPackedDetail(GU_PackedContext *context = 0) const;
78 
79  /// Report memory usage (includes all shared memory)
80  virtual int64 getMemoryUsage(bool inclusive) const;
81 
82  /// Count memory usage using a UT_MemoryCounter in order to count
83  /// shared memory correctly.
84  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
85  /// @}
86 
87  /// @{
88  /// Member data accessors for intrinsics
89  UT_StringHolder filename() const { return myCache.filename(); }
90  UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const { return filename(); }
91  UT_StringHolder unexpanded() const { return myUnexpanded; }
92  UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const { return unexpanded(); }
94  {
95  myUnexpanded = f;
96  makeFilename(prim);
97  }
98  fpreal expandFrame() const { return myExpandFrame; }
100  { return expandFrame(); }
102  {
103  myExpandFrame = f;
104  makeFilename(prim);
105  }
106  bool expandFilename() const { return myExpandFilename; }
107  bool intrinsicExpandFilename(const GU_PrimPacked *prim) const { return expandFilename(); }
109  {
110  myExpandFilename = b;
111  makeFilename(prim);
112  }
113  /// @}
114 
115  static exint getCacheVersion();
116 
117  /// Load the point geometry into the given detail
118  GU_ConstDetailHandle getPointCloud() const;
119 
121  {
122  public:
124  : myFilename()
125  , myResolved(false)
126  {
127  }
128  CacheItem(const UT_StringHolder &filename)
129  : myFilename(filename)
130  , myResolved(false)
131  {
132  }
133  CacheItem(const CacheItem &src)
134  : myFilename(src.myFilename)
135  , myResolved(false)
136  {
137  }
139  {
140  clear();
141  }
142 
143  /// Assignment operator
145  {
146  if (&src != this)
147  {
148  clear();
149  setFilename(src.myFilename);
150  }
151  return *this;
152  }
153 
154  /// Clear the item (possibly releasing from the cache)
155  void clear()
156  {
157  if (myResolved)
158  {
159  releaseFromCache(myFilename);
160  myResolved = false;
161  }
162  }
163 
164  /// Check to see if the cache would be dirtied with the given filename
165  bool isDifferentFile(const char *filename) const;
166 
167  /// Change the filename. Returns true if the filename changed
168  void setFilename(const UT_StringHolder &filename)
169  {
170  if (filename != myFilename)
171  {
172  clear();
173  myFilename = filename;
174  }
175  }
176 
177  /// Access the file
178  GU_ConstDetailHandle get(const GU_PackedImpl &impl) const
179  {
180  return GU_PackedDisk::loadFromCache(myFilename, myResolved, impl);
181  }
182 
183  /// Get point cloud for file
185  {
186  return GU_PackedDisk::loadPointCloudFromCache(myFilename,
187  myResolved, impl);
188  }
189 
190  /// Get bounding box
191  bool getBounds(UT_BoundingBox &box) const
192  {
193  return GU_PackedDisk::loadBoxFromCache(myFilename, myResolved, box);
194  }
195  /// Get velocity range
196  bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
197  {
198  return GU_PackedDisk::loadVelocityRangeFromCache(myFilename,
199  myResolved, vmin, vmax);
200  }
201  /// Get width range
202  bool getWidthRange(fpreal &wmin, fpreal &wmax) const
203  {
204  return GU_PackedDisk::loadWidthRangeFromCache(myFilename,
205  myResolved, wmin, wmax);
206  }
207 
208  /// Check if cache has been loaded from disk
209  bool isLoaded() const { return GU_PackedDisk::checkIsLoaded(myFilename, myResolved); }
210 
211 
212  /// Accessors
213  const UT_StringHolder &filename() const { return myFilename; }
214 
215  private:
216  UT_StringHolder myFilename;
217  mutable bool myResolved;
218  };
219 protected:
220  template <typename T>
221  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
222 
223  /// Returns if the filename has changed
224  void makeFilename(GU_PrimPacked *prim);
225 
230 
231 private:
232  friend class CacheItem;
233  /// Resolve a disk file, using the shared cache for disk files
234  /// The bool passed in should be initialized to false. You @b must call @c
235  /// releaseFile() if you no longer reference the file (and the cache can
236  /// remove it). It's a good idea to use @c CacheItem
237  static GU_ConstDetailHandle loadFromCache(const UT_StringRef &filename,
238  bool &resolved,
239  const GU_PackedImpl &impl);
240 
241  /// Load point cloud from a disk file, using the shared disk cache.
242  /// The bool passed in should be initialized to false. You @b must call @c
243  /// releaseFile() if you no longer reference the file (and the cache can
244  /// remove it). It's a good idea to use @c CacheItem
245  static GU_ConstDetailHandle loadPointCloudFromCache(
246  const UT_StringRef &filename,
247  bool &resolved,
248  const GU_PackedImpl &impl);
249 
250  /// Resolve bounding box for a disk file using the shared disk cache.
251  /// The bool passed in should be initialized to false. You @b must call @c
252  /// releaseFile() if you no longer reference the file (and the cache can
253  /// remove it). It's a good idea to use @c CacheItem
254  static bool loadBoxFromCache(const UT_StringRef &filename,
255  bool &resolved, UT_BoundingBox &box);
256 
257  /// Get the velocity range for a disk file using the shared disk.
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 bool loadVelocityRangeFromCache(const UT_StringRef &filename,
262  bool &resolved,
263  UT_Vector3 &vmin, UT_Vector3 &vmax);
264 
265  /// Get the width attribute range for a disk file using the shared disk.
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 loadWidthRangeFromCache(const UT_StringRef &filename,
270  bool &resolved,
271  fpreal &vmin, fpreal &vmax);
272 
273  /// Indicate you no longer need the item in the cache. It's a good idea to
274  /// use @c CacheItem
275  static void releaseFromCache(const UT_StringRef &filename);
276 
277  /// Checked if the cached file has been loaded
278  static bool checkIsLoaded(const UT_StringRef &filename, bool& resolved);
279 
280  static GA_PrimitiveTypeId theTypeId;
281 };
282 
283 #endif
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const =0
Geometry File procedural.
Definition: GU_PackedDisk.h:21
virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map)
Definition: GU_PackedDisk.h:62
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)
Definition: GU_PackedDisk.h:93
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
virtual bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map)
Definition: GU_PackedDisk.h:59
virtual bool supportsJSONLoad() const
Definition: GU_PackedDisk.h:61
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
static GA_PrimitiveTypeId typeId()
Get the type ID for the GU_PackedDisk primitive type.
Definition: GU_PackedDisk.h:47
fpreal expandFrame() const
Definition: GU_PackedDisk.h:98
bool intrinsicExpandFilename(const GU_PrimPacked *prim) const
bool getBounds(UT_BoundingBox &box) const
Get bounding box.
fpreal intrinsicExpandFrame(const GU_PrimPacked *prim) const
Definition: GU_PackedDisk.h:99
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)
3D Vector class.
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
virtual bool isLoaded() const
long long int64
Definition: SYS_Types.h:100
void setFilename(const UT_StringHolder &filename)
Change the filename. Returns true if the filename changed.
GLfloat f
Definition: glcorearb.h:1925
void clear()
Clear the item (possibly releasing from the cache)
void setExpandFrame(GU_PrimPacked *prim, fpreal f)
int64 exint
Definition: SYS_Types.h:109
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
Options during loading.
Definition: GA_LoadMap.h:42
#define GU_API
Definition: GU_API.h:11
GU_ConstDetailHandle getPointCloud(const GU_PackedImpl &impl) const
Get point cloud for file.
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
virtual void update(GU_PrimPacked *prim, const UT_Options &options)=0
const UT_StringHolder & filename() const
Accessors.
UT_StringHolder unexpanded() const
Definition: GU_PackedDisk.h:91
virtual void getPrimitiveName(const GU_PrimPacked *prim, UT_WorkBuffer &wbuf) const
double fpreal
Definition: SYS_Types.h:263
A map of string to various well defined value types.
Definition: UT_Options.h:42
bool getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const
Get velocity range.
UT_StringHolder intrinsicUnexpanded(const GU_PrimPacked *prim) const
Definition: GU_PackedDisk.h:92
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
UT_StringHolder intrinsicFilename(const GU_PrimPacked *prim) const
Definition: GU_PackedDisk.h:90
CacheItem(const CacheItem &src)
virtual bool unpack(GU_Detail &destgdp) const =0
UT_StringHolder filename() const
Definition: GU_PackedDisk.h:89
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)
GLenum src
Definition: glcorearb.h:1792
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0