HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PackedGeometry.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_PackedGeometry.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PackedGeometry__
12 #define __GU_PackedGeometry__
13 
14 #include "GU_PackedImpl.h"
15 #include "GU_DetailHandle.h"
16 #include <GA/GA_Stat.h>
17 
19 
20 /// Geometry Embedded procedural
22 {
23 public:
26  ~GU_PackedGeometry() override;
27 
28  /// Convenience method to create a packed primitive in the destination
29  /// detail which embeds the source detail. The source detail will be
30  /// copied into the embedded detail.
31  /// The source detail's bounding box will be computed. (But then
32  /// cached in the source detail, so multple packs should only
33  /// compute the first time)
34  ///
35  /// Returns a NULL pointer if the process fails.
36  /// @{
37  static GU_PrimPacked *packGeometry(GU_Detail &dest,
38  const GU_ConstDetailHandle &gdh);
39  static GU_PrimPacked *packGeometry(
40  GU_Detail &dest,
41  const GU_ConstDetailHandle &gdh,
42  GA_Offset ptoff);
43  /// @}
44 
45  /// Provide a bounding box of the gdh, compatible with gdh.getBBox()
46  /// useful if you already had to compute it while building gdh.
47  /// An invalid bounding box will generate a recompute later,
48  /// so can be used if you must delay computation, but this is
49  /// not recommended as many readers may demand it simultanesously
50  /// leading to performance problems.
51  /// @{
52  static GU_PrimPacked *packGeometry(GU_Detail &dest,
53  const GU_ConstDetailHandle &gdh,
54  const UT_BoundingBox &bbox);
55  static GU_PrimPacked *packGeometry(GU_Detail &dest,
56  const GU_ConstDetailHandle &gdh,
57  const UT_BoundingBox &bbox,
58  GA_Offset ptoff);
59  /// @}
60 
61  /// Install the procedural
62  static void install(GA_PrimitiveFactory *prim);
63 
64  /// Get the type ID for the GU_PackedGeometry primitive type.
66  {
67  return theTypeId;
68  }
69 
70  /// @{
71  /// Implementation of GU_PackedImpl interface
72  GU_PackedFactory *getFactory() const override;
73  GU_PackedImpl *copy() const override;
74 
75  bool isValid() const override;
76  void clearData() override;
77  bool load(GU_PrimPacked *prim, const UT_Options &options,
78  const GA_LoadMap &map) override
79  { return loadFrom(options, map); }
80  bool supportsJSONLoad() const override { return true; }
82  GU_PrimPacked *prim,
83  const UT_JSONValueMap &options,
84  const GA_LoadMap &map) override
85  { return loadFrom(options, map); }
86  void update(GU_PrimPacked *prim,
87  const UT_Options &options) override;
88  bool save(UT_Options &options,
89  const GA_SaveMap &map) const override;
90  bool getBounds(UT_BoundingBox &box) const override;
91  bool getVisibleBounds(UT_BoundingBox &box) const override;
92  bool getRenderingBounds(UT_BoundingBox &box) const override;
94  UT_Vector3 &max) const override;
95  void getWidthRange(fpreal &min,
96  fpreal &max) const override;
97 
98  bool unpackWithContext(
99  GU_Detail &destgdp,
100  GU_PackedContext &context,
101  const GU_PrimPacked *prim) const override;
102  bool unpack(GU_Detail &destgdp,
103  const UT_Matrix4D *transform) const override;
104  void forceLoad() const override;
105  bool isLoaded() const override;
107  GU_PackedContext *context = 0) const override;
109  int dtype,
110  const GA_SharedLoadData *it) override
111  {
112  UT_ASSERT(0 && "Should not be called!");
113  return false;
114  }
115  bool saveSharedData(
116  UT_JSONWriter &w,
117  GA_SaveMap &map,
118  GA_GeometryIndex *geo_index) const override;
119 
120  /// Report memory usage (includes all shared memory)
121  int64 getMemoryUsage(bool inclusive) const override;
122 
123  /// Count memory usage using a UT_MemoryCounter in order to count
124  /// shared memory correctly.
125  void countMemory(UT_MemoryCounter &counter,
126  bool inclusive) const override;
127 
128  /// We will be saving the contents in the same file so we don't
129  /// have to worry about them changing. This avoids having
130  /// to seek & stat to restore as bbox.
131  bool saveCachedBBox() const override { return true; }
132 
133  /// @}
134 
135  /// Treat as folder gives hint to UI that this packed geometry primitive
136  /// should be treated as a "folder"/"directory".
137  /// @{
138  bool treatAsFolder() const { return myTreatAsFolder; }
139  void setTreatAsFolder(bool b) { myTreatAsFolder = b; }
140  /// @}
141 
142  /// @{
143  /// Member data accessors for intrinsics
145  {
146  loadPackedGeometry();
147  GU_DetailHandleAutoReadLock gdl(myDetail);
148  const GU_Detail *gdp = gdl.getGdp();
149  return gdp ? gdp->getUniqueId() : -1;
150  }
152  {
153  return geometryId();
154  }
155  bool intrinsicTreatAsFolder(const GU_PrimPacked *prim) const
156  {
157  return treatAsFolder();
158  }
160  {
161  setTreatAsFolder(b);
162  }
163  /// @}
164 
165  const GU_ConstDetailHandle &detailPtr() const;
166 
167  void setDetailPtr(const GU_DetailHandle &d);
168  void setDetailPtr(const GU_ConstDetailHandle &d);
169  void cloneDetailPtr(const GU_ConstDetailHandle &d,
170  bool copy_unique_id, bool bump_count, bool copy_detail);
171 
172 protected:
173  template <typename T>
174  bool loadFrom(const T &options, const GA_LoadMap &map);
175 
176  bool loadPackedGeometry(GU_PackedContext *context = 0) const;
177 
178  bool statPackedGeometry() const;
179 
184 
186 
188 
189 private:
191 
192  template <bool VISIBLE_ONLY>
193  bool getBoundsImpl(UT_BoundingBox &box) const;
194 };
195 
196 #endif
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const =0
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
UT_BoundingBox myStatBounds
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
bool supportsJSONLoad() const override
virtual bool unpackWithContext(GU_Detail &destgdp, GU_PackedContext &context, const GU_PrimPacked *prim) const
int64 exint
Definition: SYS_Types.h:125
exint geometryId() const
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
virtual bool getBounds(UT_BoundingBox &box) const =0
Get the bounding box for the geometry (not including transforms)
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
Geometry Embedded procedural.
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
GU_PackedImpl & operator=(const GU_PackedImpl &src)=default
virtual bool isLoaded() const
GA_Size GA_Offset
Definition: GA_Types.h:646
bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map) override
virtual bool getVisibleBounds(UT_BoundingBox &box) const
virtual void forceLoad() const
virtual void clearData()=0
void setTreatAsFolder(bool b)
virtual int64 getMemoryUsage(bool inclusive) const =0
Report memory usage (includes all shared memory)
bool treatAsFolder() const
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
bool loadSharedData(int dtype, const GA_SharedLoadData *it) override
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
GA_SharedDataHandlePtr mySharedData
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_API const UT_StringHolder transform
void intrinsicSetTreatAsFolder(GU_PrimPacked *prim, bool b)
exint getUniqueId() const
Definition: GA_Detail.h:117
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
bool intrinsicTreatAsFolder(const GU_PrimPacked *prim) const
virtual void update(GU_PrimPacked *prim, const UT_Options &options)=0
A map of string to various well defined value types.
Definition: UT_Options.h:84
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
GU_ConstDetailHandle myDetail
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
virtual bool saveSharedData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex *geo_index) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
virtual bool save(UT_Options &options, const GA_SaveMap &map) const =0
Copy the resolver data into the UT_Options for saving.
exint intrinsicGeometryId(const GU_PrimPacked *prim) const
bool saveCachedBBox() const override
const GU_Detail * getGdp() const
bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map) override
static GA_PrimitiveTypeId typeId()
Get the type ID for the GU_PackedGeometry primitive type.
GLenum src
Definition: glcorearb.h:1793
static GA_PrimitiveTypeId theTypeId
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0