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 
20 
21 /// Geometry fragment procedural
23 {
24 public:
27  ~GU_PackedFragment() override;
28 
29  /// Convenience method to create a packed fragment primitive in the
30  /// destination detail. The packed fragment primitive will embed the
31  /// entire source detail but represent just the subset of the source detail
32  /// with primitive attribute "ref" having a value of "val". The source
33  /// detail will be copied into the embedded detail.
34  ///
35  /// The @c dest detail is the detail in which the packed fragment will be
36  /// created. The @c GU_ConstDetailHandle for the @c src will add a
37  /// reference to the detail handle (sharing it between multiple fragments).
38  /// The @c attrib refers to a primitive string attribute (i.e. "name")
39  /// which is used to specify the houdini primitives which compose the
40  /// fragment. The @c val is used to match the attribute to determine
41  /// selection of the primitives of the fragment. For example: @code
42  /// GU_DetailHandleAutoReadLock rlock(src);
43  /// const GU_Detail *srcgdp = rlock.getGdp();
44  /// GA_ROAttributeRef aref = srcgdp->findStringTuple(
45  /// GA_ATTRIB_PRIMITIVE, "name");
46  /// exint nstrings = srcgdp->getUniqueValueCount(aref);
47  /// for (exint i = 0; i < nstrings; ++i)
48  /// {
49  /// GU_PrimFragment *prim;
50  /// const char *val = srcgdp->getUniqueStringValue(aref, i);
51  /// // Create a primitive in the @c dest detail
52  /// prim = GU_PackedFragment::createFragment(dest, src, aref, val);
53  /// }
54  /// @endcode
55  ///
56  /// Returns a NULL pointer if the process fails.
57  ///
58  /// NOTE: The const char* overload is to try to avoid ambiguity if some code
59  /// passes nullptr.
60  /// @{
61  static GU_PrimPacked *createFragment(
62  GU_Detail &dest,
63  const GU_ConstDetailHandle &src,
64  const GA_Attribute *attrib,
65  const UT_StringHolder &val,
67  static GU_PrimPacked *createFragment(
68  GU_Detail &dest,
69  const GU_ConstDetailHandle &src,
70  const GA_Attribute *attrib,
71  const char *val,
73  static GU_PrimPacked *createFragment(
74  GU_Detail &dest,
75  const GU_ConstDetailHandle &src,
76  const GA_Attribute *attrib,
77  exint val,
79  /// @}
80 
81  /// Install the procedural
82  static void install(GA_PrimitiveFactory *prim);
83 
84  /// Get the type ID for the GU_PackedFragment primitive type.
86  {
87  return theTypeId;
88  }
89 
90  /// @{
91  /// Implementation of GU_PackedImpl interface
92  GU_PackedFactory *getFactory() const override;
93  GU_PackedImpl *copy() const override;
94 
95  bool isValid() const override;
96  void clearData() override;
97  bool load(GU_PrimPacked *prim, const UT_Options &options,
98  const GA_LoadMap &map) override
99  { return loadFrom(prim, options, map); }
100  bool supportsJSONLoad() const override { return true; }
102  GU_PrimPacked *prim,
103  const UT_JSONValueMap &options,
104  const GA_LoadMap &map) override
105  { return loadFrom(prim, options, map); }
106  void update(GU_PrimPacked *prim,
107  const UT_Options &options) override
108  { updateFrom(prim, options); }
109  bool save(UT_Options &options,
110  const GA_SaveMap &map) const override;
111  bool getBounds(UT_BoundingBox &box) const override;
112  bool getRenderingBounds(UT_BoundingBox &box) const override;
113  void getVelocityRange(
114  UT_Vector3 &min,
115  UT_Vector3 &max)const override;
116  void getWidthRange(
117  fpreal &min,
118  fpreal &max)const override;
119 
120  bool unpack(GU_Detail &destgdp,
121  const UT_Matrix4D *transform) const override;
122  void forceLoad() const override;
123  bool isLoaded() const override;
124 
126  GU_PackedContext *context = 0) const override;
128  int dtype,
129  const GA_SharedLoadData *it) override
130  {
131  UT_ASSERT(false && "Should not be called!");
132  return false;
133  }
134  bool saveSharedData(
135  UT_JSONWriter &w,
136  GA_SaveMap &map,
137  GA_GeometryIndex *geo_index) const override;
138 
139  /// Report memory usage (includes all shared memory)
140  int64 getMemoryUsage(bool inclusive) const override;
141 
142  /// Count memory usage using a UT_MemoryCounter in order to count
143  /// shared memory correctly.
144  void countMemory(UT_MemoryCounter &counter,
145  bool inclusive) const override;
146 
147  /// We will be saving the contents in the same file so we don't
148  /// have to worry about them changing. This avoids having
149  /// to seek & stat to restore as bbox.
150  bool saveCachedBBox() const override { return true; }
151 
152  /// @}
153 
154  /// @{
155  /// Member data accessors for intrinsics
156  UT_StringHolder attribute() const { return myAttribName; }
158  UT_StringHolder name() const { return myAttribValue; }
159  bool isIntValue() const { return myIsIntegerAttrib; }
160  exint intValue() const { return myAttribIntValue; }
161  UT_StringHolder intrinsicName(const GU_PrimPacked *prim) const { return name(); }
162  void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f) { myAttribName = f; }
164  {
165  myIsIntegerAttrib = false;
166  myAttribValue = f;
167  }
169  {
170  loadPackedGeometry();
171  GU_DetailHandleAutoReadLock gdl(myDetail);
172  const GU_Detail *gdp = gdl.getGdp();
173  return gdp ? gdp->getUniqueId() : -1;
174  }
176  {
177  return geometryId();
178  }
179  /// @}
180 
182  loadPackedGeometry();
183  return myDetail;
184  }
185  GA_Range getPrimitiveRange() const;
186  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const UT_StringHolder &name);
187  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const char *name);
188  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, exint id);
189 protected:
190  /// Returns if the filename has changed
191  void makeEmbeddedname();
192 
193  template <typename T>
194  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
195 
196  template <typename T>
197  void updateFrom(GU_PrimPacked *prim, const T &options);
198 
199  virtual bool loadPackedGeometry() const;
200 
207  mutable const GA_Attribute *myCachedAttrib;
211 
213 };
214 
215 #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
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
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:678
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:641
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:34
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:277
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
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0