HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PackedFragment.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_PackedFragment.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PackedFragment__
12 #define __GU_PackedFragment__
13 
14 #include "GU_PackedImpl.h"
15 #include "GU_DetailHandle.h"
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_UniquePtr.h>
18 #include <UT/UT_WorkBuffer.h>
19 
21 
22 /// Geometry fragment procedural
24 {
25 public:
28  ~GU_PackedFragment() override;
29 
30  /// Convenience method to create a packed fragment primitive in the
31  /// destination detail. The packed fragment primitive will embed the
32  /// entire source detail but represent just the subset of the source detail
33  /// with primitive attribute "ref" having a value of "val". The source
34  /// detail will be copied into the embedded detail.
35  ///
36  /// The @c dest detail is the detail in which the packed fragment will be
37  /// created. The @c GU_ConstDetailHandle for the @c src will add a
38  /// reference to the detail handle (sharing it between multiple fragments).
39  /// The @c attrib refers to a primitive string attribute (i.e. "name")
40  /// which is used to specify the houdini primitives which compose the
41  /// fragment. The @c val is used to match the attribute to determine
42  /// selection of the primitives of the fragment. For example: @code
43  /// GU_DetailHandleAutoReadLock rlock(src);
44  /// const GU_Detail *srcgdp = rlock.getGdp();
45  /// GA_ROAttributeRef aref = srcgdp->findStringTuple(
46  /// GA_ATTRIB_PRIMITIVE, "name");
47  /// exint nstrings = srcgdp->getUniqueValueCount(aref);
48  /// for (exint i = 0; i < nstrings; ++i)
49  /// {
50  /// GU_PrimFragment *prim;
51  /// const char *val = srcgdp->getUniqueStringValue(aref, i);
52  /// // Create a primitive in the @c dest detail
53  /// prim = GU_PackedFragment::createFragment(dest, src, aref, val);
54  /// }
55  /// @endcode
56  ///
57  /// Returns a NULL pointer if the process fails.
58  ///
59  /// NOTE: The const char* overload is to try to avoid ambiguity if some code
60  /// passes nullptr.
61  /// @{
62  static GU_PrimPacked *createFragment(
63  GU_Detail &dest,
64  const GU_ConstDetailHandle &src,
65  const GA_Attribute *attrib,
66  const UT_StringHolder &val,
68  static GU_PrimPacked *createFragment(
69  GU_Detail &dest,
70  const GU_ConstDetailHandle &src,
71  const GA_Attribute *attrib,
72  const char *val,
74  static GU_PrimPacked *createFragment(
75  GU_Detail &dest,
76  const GU_ConstDetailHandle &src,
77  const GA_Attribute *attrib,
78  exint val,
80  /// @}
81 
82  /// Install the procedural
83  static void install(GA_PrimitiveFactory *prim);
84 
85  /// Get the type ID for the GU_PackedFragment primitive type.
87  {
88  return theTypeId;
89  }
90 
91  /// @{
92  /// Implementation of GU_PackedImpl interface
93  GU_PackedFactory *getFactory() const override;
94  GU_PackedImpl *copy() const override;
95 
96  bool isValid() const override;
97  void clearData() override;
98  bool load(GU_PrimPacked *prim, const UT_Options &options,
99  const GA_LoadMap &map) override
100  { return loadFrom(prim, options, map); }
101  bool supportsJSONLoad() const override { return true; }
103  GU_PrimPacked *prim,
104  const UT_JSONValueMap &options,
105  const GA_LoadMap &map) override
106  { return loadFrom(prim, options, map); }
107  void update(GU_PrimPacked *prim,
108  const UT_Options &options) override
109  { updateFrom(prim, options); }
110  bool save(UT_Options &options,
111  const GA_SaveMap &map) const override;
112  bool getBounds(UT_BoundingBox &box) const override;
113  bool getRenderingBounds(UT_BoundingBox &box) const override;
114  void getVelocityRange(
115  UT_Vector3 &min,
116  UT_Vector3 &max)const override;
117  void getWidthRange(
118  fpreal &min,
119  fpreal &max)const override;
120 
121  bool unpack(GU_Detail &destgdp,
122  const UT_Matrix4D *transform) const override;
123  void forceLoad() const override;
124  bool isLoaded() const override;
125 
127  GU_PackedContext *context = 0) const override;
129  int dtype,
130  const GA_SharedLoadData *it) override
131  {
132  UT_ASSERT(false && "Should not be called!");
133  return false;
134  }
135  bool saveSharedData(
136  UT_JSONWriter &w,
137  GA_SaveMap &map,
138  GA_GeometryIndex *geo_index) const override;
139 
140  /// Report memory usage (includes all shared memory)
141  int64 getMemoryUsage(bool inclusive) const override;
142 
143  /// Count memory usage using a UT_MemoryCounter in order to count
144  /// shared memory correctly.
145  void countMemory(UT_MemoryCounter &counter,
146  bool inclusive) const override;
147 
148  /// We will be saving the contents in the same file so we don't
149  /// have to worry about them changing. This avoids having
150  /// to seek & stat to restore as bbox.
151  bool saveCachedBBox() const override { return true; }
152 
153  /// @}
154 
155  /// @{
156  /// Member data accessors for intrinsics
157  UT_StringHolder attribute() const { return myAttribName; }
160  {
161  if (myIsIntegerAttrib)
162  {
164  buf.itoa(myAttribIntValue);
165  return buf.buffer();
166  }
167 
168  return myAttribValue;
169  }
170  bool isIntValue() const { return myIsIntegerAttrib; }
171  exint intValue() const { return myAttribIntValue; }
172  UT_StringHolder intrinsicName(const GU_PrimPacked *prim) const { return name(); }
173  void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f) { myAttribName = f; }
175  {
176  myIsIntegerAttrib = false;
177  myAttribValue = f;
178  }
180  {
181  myIsIntegerAttrib = true;
182  myAttribIntValue = f;
183  }
185  {
186  loadPackedGeometry();
187  GU_DetailHandleAutoReadLock gdl(myDetail);
188  const GU_Detail *gdp = gdl.getGdp();
189  return gdp ? gdp->getUniqueId() : -1;
190  }
192  {
193  return geometryId();
194  }
195  /// @}
196 
198  loadPackedGeometry();
199  return myDetail;
200  }
201  GA_Range getPrimitiveRange() const;
202  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const UT_StringHolder &name);
203  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const char *name);
204  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, exint id);
205 protected:
206  /// Returns if the filename has changed
207  void makeEmbeddedname();
208 
209  template <typename T>
210  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
211 
212  template <typename T>
213  void updateFrom(GU_PrimPacked *prim, const T &options);
214 
215  virtual bool loadPackedGeometry() const;
216 
223  mutable const GA_Attribute *myCachedAttrib;
227 
229 };
230 
231 #endif
virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max) const =0
UT_StringHolder intrinsicName(const GU_PrimPacked *prim) const
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
const GU_ConstDetailHandle & detailPtr() const
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map) override
void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f)
UT_StringHolder attribute() const
int64 exint
Definition: SYS_Types.h:125
SYS_FORCE_INLINE const char * buffer() 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
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
A range of elements in an index-map.
Definition: GA_Range.h:42
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
virtual bool isLoaded() const
GA_Size GA_Offset
Definition: GA_Types.h:646
GLfloat f
Definition: glcorearb.h:1926
UT_UniquePtr< fpreal64[]> myBoundingBox
virtual void forceLoad() const
bool supportsJSONLoad() const override
virtual void clearData()=0
UT_StringHolder name() const
static GA_PrimitiveTypeId theTypeId
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
bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map) override
long long int64
Definition: SYS_Types.h:116
Options during loading.
Definition: GA_LoadMap.h:42
UT_StringHolder myAttribValue
#define GU_API
Definition: GU_API.h:14
exint intValue() const
GU_ConstDetailHandle myDetail
GLuint const GLchar * name
Definition: glcorearb.h:786
const GA_Attribute * myCachedAttrib
GA_API const UT_StringHolder transform
bool saveCachedBBox() const override
exint getUniqueId() const
Definition: GA_Detail.h:117
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
void update(GU_PrimPacked *prim, const UT_Options &options) override
bool loadSharedData(int dtype, const GA_SharedLoadData *it) override
GA_AttributeOwner
Definition: GA_Types.h:35
A map of string to various well defined value types.
Definition: UT_Options.h:84
bool isIntValue() const
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
exint geometryId() const
fpreal64 fpreal
Definition: SYS_Types.h:278
void itoa(int64 i)
bool unpack(GU_Detail &destgdp, const GU_PrimPacked *prim) const
UT_StringHolder intrinsicAttribute(const GU_PrimPacked *prim) const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint GLfloat * val
Definition: glcorearb.h:1608
UT_StringHolder myAttribName
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
virtual bool saveSharedData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex *geo_index) const
GA_AttributeOwner myAttribOwner
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Geometry fragment procedural.
virtual bool save(UT_Options &options, const GA_SaveMap &map) const =0
Copy the resolver data into the UT_Options for saving.
void setName(GU_PrimPacked *prim, const UT_StringHolder &f)
GA_SharedDataHandlePtr mySharedData
exint intrinsicGeometryId(const GU_PrimPacked *prim) const
const GU_Detail * getGdp() const
static GA_PrimitiveTypeId typeId()
Get the type ID for the GU_PackedFragment primitive type.
GLenum src
Definition: glcorearb.h:1793
void setName(GU_PrimPacked *prim, exint f)
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0