HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GU_PackedFragment();
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  /// int nstrings = srcgdp->getUniqueValueCount(aref);
47  /// for (int 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  virtual GU_PackedFactory *getFactory() const;
90  virtual GU_PackedImpl *copy() const;
91 
92  virtual bool isValid() const;
93  virtual void clearData();
94  virtual bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map)
95  { return loadFrom(prim, options, map); }
96  virtual bool supportsJSONLoad() const { return true; }
97  virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options,
98  const GA_LoadMap &map)
99  { return loadFrom(prim, options, map); }
100  virtual void update(GU_PrimPacked *prim, const UT_Options &options)
101  { updateFrom(prim, options); }
102  virtual bool save(UT_Options &options, const GA_SaveMap &map) const;
103  virtual bool getBounds(UT_BoundingBox &box) const;
104  virtual bool getRenderingBounds(UT_BoundingBox &box) const;
105  virtual void getVelocityRange(UT_Vector3 &min, UT_Vector3 &max)const;
106  virtual void getWidthRange(fpreal &min, fpreal &max)const;
107 
108  virtual bool unpack(GU_Detail &destgdp) const;
109  virtual void forceLoad() const;
110  virtual bool isLoaded() const;
111  virtual GU_ConstDetailHandle getPackedDetail(GU_PackedContext *context = 0) const;
112  virtual bool loadSharedData(int dtype, const GA_SharedLoadData *it)
113  {
114  UT_ASSERT(false && "Should not be called!");
115  return false;
116  }
117  virtual bool saveSharedData(UT_JSONWriter &w,
118  GA_SaveMap &map, GA_GeometryIndex* geometryIndex) const;
119 
120  /// Report memory usage (includes all shared memory)
121  virtual int64 getMemoryUsage(bool inclusive) const;
122 
123  /// Count memory usage using a UT_MemoryCounter in order to count
124  /// shared memory correctly.
125  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
126 
127  /// We will be saving the contents in the same file so we don't
128  /// have to worry about them changing. This avoids having
129  /// to seek & stat to restore as bbox.
130  virtual bool saveCachedBBox() const { return true; }
131 
132  /// @}
133 
134  /// @{
135  /// Member data accessors for intrinsics
136  UT_StringHolder attribute() const { return myAttribName; }
137  UT_StringHolder intrinsicAttribute(const GU_PrimPacked *prim) const { return attribute(); }
138  UT_StringHolder name() const { return myAttribValue; }
139  UT_StringHolder intrinsicName(const GU_PrimPacked *prim) const { return name(); }
140  void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f) { myAttribName = f; }
142  {
143  myIsIntegerAttrib = false;
144  myAttribValue = f;
145  }
147  {
148  loadPackedGeometry();
149  GU_DetailHandleAutoReadLock gdl(myDetail);
150  const GU_Detail *gdp = gdl.getGdp();
151  return gdp ? gdp->getUniqueId() : -1;
152  }
154  {
155  return geometryId();
156  }
157  /// @}
158 
160  loadPackedGeometry();
161  return myDetail;
162  }
163  GA_Range getPrimitiveRange() const;
164  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const UT_StringHolder &name);
165  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, const char *name);
166  void setDetails(GU_PrimPacked *prim, const GU_ConstDetailHandle &d, const GA_Attribute *attrib, exint id);
167 protected:
168  /// Returns if the filename has changed
169  void makeEmbeddedname();
170 
171  template <typename T>
172  bool loadFrom(GU_PrimPacked *prim, const T &options, const GA_LoadMap &map);
173 
174  template <typename T>
175  void updateFrom(GU_PrimPacked *prim, const T &options);
176 
177  virtual bool loadPackedGeometry() const;
178 
185  mutable const GA_Attribute *myCachedAttrib;
189 
191 };
192 
193 #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:189
virtual bool saveSharedData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex *geometryIndex) const
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
const GU_ConstDetailHandle & detailPtr() const
virtual bool loadFromJSON(GU_PrimPacked *prim, const UT_JSONValueMap &options, const GA_LoadMap &map)
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
void setAttribute(GU_PrimPacked *prim, const UT_StringHolder &f)
UT_StringHolder attribute() const
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:32
3D Vector class.
A range of elements in an index-map.
Definition: GA_Range.h:42
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
GLfloat f
Definition: glcorearb.h:1925
UT_UniquePtr< fpreal64[]> myBoundingBox
virtual bool load(GU_PrimPacked *prim, const UT_Options &options, const GA_LoadMap &map)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
virtual void forceLoad() const
int64 exint
Definition: SYS_Types.h:109
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
Options during loading.
Definition: GA_LoadMap.h:42
virtual void update(GU_PrimPacked *prim, const UT_Options &options)
UT_StringHolder myAttribValue
virtual bool loadSharedData(int dtype, const GA_SharedLoadData *it)
#define GU_API
Definition: GU_API.h:11
GU_ConstDetailHandle myDetail
GLuint const GLchar * name
Definition: glcorearb.h:785
const GA_Attribute * myCachedAttrib
virtual bool saveCachedBBox() const
exint getUniqueId() const
Definition: GA_Detail.h:117
virtual bool isValid() const =0
Test whether the deferred load primitive data is valid.
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:263
A map of string to various well defined value types.
Definition: UT_Options.h:42
virtual bool supportsJSONLoad() const
virtual GU_PackedImpl * copy() const =0
Create a copy of this resolver.
exint geometryId() const
UT_StringHolder intrinsicAttribute(const GU_PrimPacked *prim) const
GLuint GLfloat * val
Definition: glcorearb.h:1607
UT_StringHolder myAttribName
virtual bool unpack(GU_Detail &destgdp) const =0
GA_AttributeOwner myAttribOwner
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
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:1792
virtual void getWidthRange(fpreal &wmin, fpreal &wmax) const =0