HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PrimVDB.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_PrimVDB.h ( GU Library, C++)
7  *
8  * COMMENTS: Custom VDB primitive.
9  */
10 
11 #ifndef __GU_PrimVDB__
12 #define __GU_PrimVDB__
13 
14 #include "GU_API.h"
16 #include <GEO/GEO_PrimVDB.h>
17 #include "GU_Detail.h"
18 #include <UT/UT_Matrix4.h>
19 #include <UT/UT_VoxelArray.h>
20 #include <openvdb/Platform.h>
21 #include <stddef.h>
22 
23 
24 class GA_Attribute;
25 class GEO_PrimVolume;
26 class UT_MemoryCounter;
29 
30 
32 {
33 protected:
34  /// NOTE: Primitives should not be deleted directly. They are managed
35  /// by the GA_PrimitiveList and the stash.
36  ~GU_PrimVDB() override {}
37 
38 public:
39  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
41  : GEO_PrimVDB(gdp, offset)
42  {}
43 
44  /// Report approximate memory usage.
45  int64 getMemoryUsage() const override;
46 
47  /// Count memory usage using a UT_MemoryCounter in order to count
48  /// shared memory correctly.
49  /// NOTE: This should always include sizeof(*this).
50  void countMemory(UT_MemoryCounter &counter) const override;
51 
52 #if 0 //ndef SESI_OPENVDB
53  /// Allows you to find out what this primitive type was named.
54  static GA_PrimitiveTypeId theTypeId() { return theDefinition->getId(); }
55 
56  /// Must be invoked during the factory callback to add us to the
57  /// list of primitives
58  static void registerMyself(GA_PrimitiveFactory *factory);
59 #endif
60 
61  const GA_PrimitiveDefinition &getTypeDef() const override
62  {
63  UT_ASSERT(theDefinition);
64  return *theDefinition;
65  }
66 
67  // Conversion Methods
68 
70  GA_PointGroup *usedpts = 0) override;
71  GEO_Primitive *convertNew(GU_ConvertParms &parms) override;
72 
73  /// Convert all GEO_PrimVolume primitives in geometry to
74  /// GEO_PrimVDB, preserving prim/vertex/point attributes (and prim/point
75  /// groups if requested).
76  static void convertVolumesToVDBs(
77  GU_Detail &dst_geo,
78  const GU_Detail &src_geo,
79  GU_ConvertParms &parms,
80  bool flood_sdf,
81  bool prune,
82  fpreal tolerance,
83  bool keep_original,
84  bool activate_inside = true);
85 
86  /// Convert all GEO_PrimVDB primitives in geometry to parms.toType,
87  /// preserving prim/vertex/point attributes (and prim/point groups if
88  /// requested).
89  /// @{
90  static void convertVDBs(
91  GU_Detail &dst_geo,
92  const GU_Detail &src_geo,
93  GU_ConvertParms &parms,
94  fpreal adaptivity,
95  bool keep_original);
96  static void convertVDBs(
97  GU_Detail &dst_geo,
98  const GU_Detail &src_geo,
99  GU_ConvertParms &parms,
100  fpreal adaptivity,
101  bool keep_original,
102  bool split_disjoint_volumes);
103  /// @}
104 
105  // NOTE: For static member functions please call in the following
106  // manner. <ptrvalue> = GU_PrimVDB::<functname>
107  // i.e. partptr = GU_PrimVDB::build(params...);
108 
109  // Optional Build Method
110 
111  static GU_PrimVDB * build(GU_Detail *gdp, bool append_points = true);
112 
113  /// Store a VDB grid in a new VDB primitive and add the primitive
114  /// to a geometry detail.
115  /// @param gdp the detail to which to add the new primitive
116  /// @param grid a grid to be associated with the new primitive
117  /// @param src if non-null, copy attributes and groups from this primitive
118  /// @param name if non-null, set the new primitive's @c name attribute to
119  /// this string; otherwise, if @a src is non-null, use its name
120  static SYS_FORCE_INLINE
121  GU_PrimVDB* buildFromGrid(GU_Detail& gdp, openvdb::GridBase::Ptr grid,
122  const GEO_PrimVDB* src = NULL, const char* name = NULL)
123  {
124  return GU_PrimVDB::buildFromGridAdapter(gdp, &grid, src, name);
125  }
126 
127  /// Create new VDB primitive from the given native volume primitive
128  static GU_PrimVDB * buildFromPrimVolume(
129  GU_Detail &geo,
130  const GEO_PrimVolume &vol,
131  const char *name,
132  const bool flood_sdf = false,
133  const bool prune = false,
134  const float tolerance = 0.0,
135  const bool activate_inside_sdf = true);
136 
137  /// A fast method for converting a primitive volume to a polysoup via VDB
138  /// into the given gdp. It will _not_ copy attributes because this is a
139  /// special case used for display purposes only.
140  static void convertPrimVolumeToPolySoup(
141  GU_Detail &dst_geo,
142  const GEO_PrimVolume &src_vol);
143 
144  void normal(NormalComp &output) const override;
145  void normal(NormalCompD &output) const override;
146 
147  /// @brief Transfer any metadata associated with this primitive's
148  /// VDB grid to primitive attributes.
149  void syncAttrsFromMetadata();
150 
151  /// @brief Transfer any metadata associated with a VDB grid
152  /// to primitive attributes on a VDB primitive.
153  /// @param prim the primitive to be populated with attributes
154  /// @param grid the grid whose metadata should be transferred
155  /// @param gdp the detail to which to transfer attributes
156  static SYS_FORCE_INLINE
158  const GEO_PrimVDB& prim,
159  const openvdb::GridBase& grid,
160  GEO_Detail& gdp)
161  {
162  GU_PrimVDB::createGridAttrsFromMetadataAdapter(prim, &grid, gdp);
163  }
164 
165  /// @brief Transfer any metadata associated with the given MetaMap
166  /// to attributes on the given element specified by owner.
167  /// @param owner the type of element
168  /// @param element the offset of the element
169  /// @param meta_map the metadata that should be transferred
170  /// @param gdp the detail to which to transfer attributes
171  static SYS_FORCE_INLINE
173  GA_AttributeOwner owner,
174  GA_Offset element,
175  const openvdb::MetaMap& meta_map,
176  GEO_Detail& gdp)
177  {
178  GU_PrimVDB::createAttrsFromMetadataAdapter(owner, element, &meta_map, gdp);
179  }
180 
181  /// @brief Transfer a VDB primitive's attributes to a VDB grid as metadata.
182  /// @param grid the grid to be populated with metadata
183  /// @param prim the primitive whose attributes should be transferred
184  /// @param gdp the detail from which to retrieve primitive attributes
185  static SYS_FORCE_INLINE
187  openvdb::GridBase& grid,
188  const GEO_PrimVDB& prim,
189  const GEO_Detail& gdp)
190  {
191  GU_PrimVDB::createMetadataFromGridAttrsAdapter(&grid, prim, gdp);
192  }
193 
194  /// @brief Transfer attributes to VDB metadata.
195  /// @param meta_map the output metadata
196  /// @param owner the type of element
197  /// @param element the offset of the element
198  /// @param geo the detail from which to retrieve primitive attributes
199  static SYS_FORCE_INLINE
201  openvdb::MetaMap& meta_map,
202  GA_AttributeOwner owner,
203  GA_Offset element,
204  const GEO_Detail& geo)
205  {
206  GU_PrimVDB::createMetadataFromAttrsAdapter(&meta_map, owner, element, geo);
207  }
208 
209 private: // METHODS
210 
211  /// Add a border of the given radius by evaluating from the given volume.
212  /// It assumes that the VDB is a float grid and that the voxel array has
213  /// the same index space, so this can really only be safely called after
214  /// buildFromPrimVolume(). This is used to ensure that non-constant borders
215  /// can be converted at the expense of some extra memory.
216  void expandBorderFromPrimVolume(
217  const GEO_PrimVolume &vol,
218  int border_radius);
219 
220  GEO_Primitive * convertToNewPrim(
221  GEO_Detail &dst_geo,
222  GU_ConvertParms &parms,
223  fpreal adaptivity,
224  bool split_disjoint_volumes,
225  bool &success) const;
226  GEO_Primitive * convertToPrimVolume(
227  GEO_Detail &dst_geo,
228  GU_ConvertParms &parms,
229  bool split_disjoint_volumes) const;
230  GEO_Primitive * convertToPoly(
231  GEO_Detail &dst_geo,
232  GU_ConvertParms &parms,
233  fpreal adaptivity,
234  bool buildpolysoup,
235  bool &success) const;
236 
237  static GU_PrimVDB* buildFromGridAdapter(
238  GU_Detail& gdp,
239  void* grid,
240  const GEO_PrimVDB*,
241  const char* name);
242  static void createGridAttrsFromMetadataAdapter(
243  const GEO_PrimVDB& prim,
244  const void* grid,
245  GEO_Detail& gdp);
246  static void createMetadataFromGridAttrsAdapter(
247  void* grid,
248  const GEO_PrimVDB&,
249  const GEO_Detail&);
250 
251  static void createAttrsFromMetadataAdapter(
252  GA_AttributeOwner owner,
253  GA_Offset element,
254  const void* meta_map_ptr,
255  GEO_Detail& geo);
256 
257  static void createMetadataFromAttrsAdapter(
258  void* meta_map_ptr,
259  GA_AttributeOwner owner,
260  GA_Offset element,
261  const GEO_Detail& geo);
262 
263 private: // DATA
264 
265  static GA_PrimitiveDefinition *theDefinition;
266  friend class GU_PrimitiveFactory;
268 };
270 
271 
272 #if 0 //ndef SESI_OPENVDB
273 namespace openvdb_houdini {
274 using ::GU_PrimVDB;
275 } // namespace openvdb_houdini
276 #endif
277 
278 #endif // __GU_PrimVDB__
GU_PrimVDB(GU_Detail *gdp, GA_Offset offset=GA_INVALID_OFFSET)
NOTE: This constructor should only be called via GU_PrimitiveFactory.
Definition: GU_PrimVDB.h:40
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
virtual void normal(NormalComp &output) const =0
GA_Size GA_Offset
Definition: GA_Types.h:646
GLintptr offset
Definition: glcorearb.h:665
static SYS_FORCE_INLINE void createAttrsFromMetadata(GA_AttributeOwner owner, GA_Offset element, const openvdb::MetaMap &meta_map, GEO_Detail &gdp)
Transfer any metadata associated with the given MetaMap to attributes on the given element specified ...
Definition: GU_PrimVDB.h:172
static SYS_FORCE_INLINE void createMetadataFromGridAttrs(openvdb::GridBase &grid, const GEO_PrimVDB &prim, const GEO_Detail &gdp)
Transfer a VDB primitive's attributes to a VDB grid as metadata.
Definition: GU_PrimVDB.h:186
virtual void countMemory(UT_MemoryCounter &counter) const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
~GU_PrimVDB() override
Definition: GU_PrimVDB.h:36
long long int64
Definition: SYS_Types.h:116
static SYS_FORCE_INLINE void createMetadataFromAttrs(openvdb::MetaMap &meta_map, GA_AttributeOwner owner, GA_Offset element, const GEO_Detail &geo)
Transfer attributes to VDB metadata.
Definition: GU_PrimVDB.h:200
#define GU_API
Definition: GU_API.h:14
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_AttributeOwner
Definition: GA_Types.h:35
fpreal64 fpreal
Definition: SYS_Types.h:277
static SYS_FORCE_INLINE GU_PrimVDB * buildFromGrid(GU_Detail &gdp, openvdb::GridBase::Ptr grid, const GEO_PrimVDB *src=NULL, const char *name=NULL)
Definition: GU_PrimVDB.h:121
const GA_PrimitiveDefinition & getTypeDef() const override
Definition: GU_PrimVDB.h:61
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
static SYS_FORCE_INLINE void createGridAttrsFromMetadata(const GEO_PrimVDB &prim, const openvdb::GridBase &grid, GEO_Detail &gdp)
Transfer any metadata associated with a VDB grid to primitive attributes on a VDB primitive...
Definition: GU_PrimVDB.h:157
Definition of a geometric primitive.
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:335
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
GEO_ConvertParms GU_ConvertParms
Definition: GU_PrimVDB.h:27
GLenum src
Definition: glcorearb.h:1793