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);
66  static GU_PrimPacked *createFragment(
67  GU_Detail &dest,
68  const GU_ConstDetailHandle &src,
69  const GA_Attribute *attrib,
70  const char *val);
71  static GU_PrimPacked *createFragment(
72  GU_Detail &dest,
73  const GU_ConstDetailHandle &src,
74  const GA_Attribute *attrib,
75  exint val);
76  /// @}
77 
78  /// Install the procedural
79  static void install(GA_PrimitiveFactory *prim);
80 
81  /// Get the type ID for the GU_PackedFragment primitive type.
83  {
84  return theTypeId;
85  }
86 
87  /// @{
88  /// Implementation of GU_PackedImpl interface
89  GU_PackedFactory *getFactory() const override;
90  GU_PackedImpl *copy() const override;
91 
92  bool isValid() const override;
93  void clearData() override;
94  bool load(GU_PrimPacked *prim, const UT_Options &options,
95  const GA_LoadMap &map) override
96  { return loadFrom(prim, options, map); }
97  bool supportsJSONLoad() const override { return true; }
99  GU_PrimPacked *prim,
100  const UT_JSONValueMap &options,
101  const GA_LoadMap &map) override
102  { return loadFrom(prim, options, map); }
103  void update(GU_PrimPacked *prim,
104  const UT_Options &options) override
105  { updateFrom(prim, options); }
106  bool save(UT_Options &options,
107  const GA_SaveMap &map) const override;
108  bool getBounds(UT_BoundingBox &box) const override;
109  bool getRenderingBounds(UT_BoundingBox &box) const override;
110  void getVelocityRange(
111  UT_Vector3 &min,
112  UT_Vector3 &max)const override;
113  void getWidthRange(
114  fpreal &min,
115  fpreal &max)const override;
116 
117  bool unpack(GU_Detail &destgdp,
118  const UT_Matrix4D *transform) const override;
119  void forceLoad() const override;
120  bool isLoaded() const override;
121 
123  GU_PackedContext *context = 0) const override;
125  int dtype,
126  const GA_SharedLoadData *it) override
127  {
128  UT_ASSERT(false && "Should not be called!");
129  return false;
130  }
131  bool saveSharedData(
132  UT_JSONWriter &w,
133  GA_SaveMap &map,
134  GA_GeometryIndex *geo_index) const override;
135 
136  /// Report memory usage (includes all shared memory)
137  int64 getMemoryUsage(bool inclusive) const override;
138 
139  /// Count memory usage using a UT_MemoryCounter in order to count
140  /// shared memory correctly.
142  bool inclusive) const override;
143 
144  /// We will be saving the contents in the same file so we don't
145  /// have to worry about them changing. This avoids having
146  /// to seek & stat to restore as bbox.
147  bool saveCachedBBox() const override { return true; }
148 
149  /// @}
150 
151  /// @{
152  /// Member data accessors for intrinsics
153  UT_StringHolder attribute() const { return myAttribName; }
155  UT_StringHolder name() const { return myAttribValue; }
156  UT_StringHolder intrinsicName(const GU_PrimPacked *prim) const { return name(); }
157  void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f) { myAttribName = f; }
159  {
160  myIsIntegerAttrib = false;
161  myAttribValue = f;
162  }
164  {
165  loadPackedGeometry();
166  GU_DetailHandleAutoReadLock gdl(myDetail);
167  const GU_Detail *gdp = gdl.getGdp();
168  return gdp ? gdp->getUniqueId() : -1;
169  }
171  {
172  return geometryId();
173  }
174  /// @}
175 
177  loadPackedGeometry();
178  return myDetail;
179  }
180  GA_Range getPrimitiveRange() const;
181  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const UT_StringHolder &name);
182  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const char *name);
183  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, exint id);
184 protected:
185  /// Returns if the filename has changed
186  void makeEmbeddedname();
187 
188  template <typename T>
189  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
190 
191  template <typename T>
192  void updateFrom(GU_PrimPacked *prim, const T &options);
193 
194  virtual bool loadPackedGeometry() const;
195 
202  mutable const GA_Attribute *myCachedAttrib;
206 
208 };
209 
210 #endif
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
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:196
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
GLenum src
Definition: glew.h:2410
const GU_ConstDetailHandle & detailPtr() const
GLuint const GLchar * name
Definition: glew.h:1814
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
GLuint GLenum GLenum transform
Definition: glew.h:14742
GLuint const GLfloat * val
Definition: glew.h:2794
void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f)
UT_StringHolder attribute() const
int64 exint
Definition: SYS_Types.h:125
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:34
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
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:33
virtual bool getRenderingBounds(UT_BoundingBox &box) const =0
virtual bool isLoaded() const
UT_UniquePtr< fpreal64[]> myBoundingBox
GLclampf f
Definition: glew.h:3499
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)
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
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
GU_ConstDetailHandle myDetail
const GA_Attribute * myCachedAttrib
bool saveCachedBBox() const override
exint getUniqueId() const
Definition: GA_Detail.h:116
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:33
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.
GLuint counter
Definition: glew.h:2740
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
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
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
Geometry fragment procedural.
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
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.
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0