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;
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,
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,
94  fpreal adaptivity,
95  bool keep_original);
96  static void convertVDBs(
97  GU_Detail &dst_geo,
98  const GU_Detail &src_geo,
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  // Builds a vdb directly from an IMX_VDB
128  static GEO_PrimVDB *buildFromVDB(GU_Detail *gdp,
130  static GEO_PrimVDB *buildFromVDB(GU_Detail *gdp,
132 
133 
134  /// Create new VDB primitive from the given native volume primitive
135  static GU_PrimVDB * buildFromPrimVolume(
136  GU_Detail &geo,
137  const GEO_PrimVolume &vol,
138  const char *name,
139  const bool flood_sdf = false,
140  const bool prune = false,
141  const float tolerance = 0.0,
142  const bool activate_inside_sdf = true);
143 
144  /// A fast method for converting a primitive volume to a polysoup via VDB
145  /// into the given gdp. It will _not_ copy attributes because this is a
146  /// special case used for display purposes only.
147  static void convertPrimVolumeToPolySoup(
148  GU_Detail &dst_geo,
149  const GEO_PrimVolume &src_vol);
150 
151  void normal(NormalComp &output) const override;
152  void normal(NormalCompD &output) const override;
153 
154  /// @brief Transfer any metadata associated with this primitive's
155  /// VDB grid to primitive attributes.
156  void syncAttrsFromMetadata();
157 
158  /// @brief Transfer any metadata associated with a VDB grid
159  /// to primitive attributes on a VDB primitive.
160  /// @param prim the primitive to be populated with attributes
161  /// @param grid the grid whose metadata should be transferred
162  /// @param gdp the detail to which to transfer attributes
163  static SYS_FORCE_INLINE
165  const GEO_PrimVDB& prim,
166  const openvdb::GridBase& grid,
167  GEO_Detail& gdp)
168  {
169  GU_PrimVDB::createGridAttrsFromMetadataAdapter(prim, &grid, gdp);
170  }
171 
172  /// @brief Transfer any metadata associated with the given MetaMap
173  /// to attributes on the given element specified by owner.
174  /// @param owner the type of element
175  /// @param element the offset of the element
176  /// @param meta_map the metadata that should be transferred
177  /// @param gdp the detail to which to transfer attributes
178  static SYS_FORCE_INLINE
180  GA_AttributeOwner owner,
181  GA_Offset element,
182  const openvdb::MetaMap& meta_map,
183  GEO_Detail& gdp)
184  {
185  GU_PrimVDB::createAttrsFromMetadataAdapter(owner, element, &meta_map, gdp);
186  }
187 
188  /// @brief Transfer a VDB primitive's attributes to a VDB grid as metadata.
189  /// @param grid the grid to be populated with metadata
190  /// @param prim the primitive whose attributes should be transferred
191  /// @param gdp the detail from which to retrieve primitive attributes
192  static SYS_FORCE_INLINE
194  openvdb::GridBase& grid,
195  const GEO_PrimVDB& prim,
196  const GEO_Detail& gdp)
197  {
198  GU_PrimVDB::createMetadataFromGridAttrsAdapter(&grid, prim, gdp);
199  }
200 
201  /// @brief Transfer attributes to VDB metadata.
202  /// @param meta_map the output metadata
203  /// @param owner the type of element
204  /// @param element the offset of the element
205  /// @param geo the detail from which to retrieve primitive attributes
206  static SYS_FORCE_INLINE
208  openvdb::MetaMap& meta_map,
209  GA_AttributeOwner owner,
210  GA_Offset element,
211  const GEO_Detail& geo)
212  {
213  GU_PrimVDB::createMetadataFromAttrsAdapter(&meta_map, owner, element, geo);
214  }
215 
216 private: // METHODS
217 
218  /// Add a border of the given radius by evaluating from the given volume.
219  /// It assumes that the VDB is a float grid and that the voxel array has
220  /// the same index space, so this can really only be safely called after
221  /// buildFromPrimVolume(). This is used to ensure that non-constant borders
222  /// can be converted at the expense of some extra memory.
223  void expandBorderFromPrimVolume(
224  const GEO_PrimVolume &vol,
225  int border_radius);
226 
227  GEO_Primitive * convertToNewPrim(
228  GEO_Detail &dst_geo,
230  fpreal adaptivity,
231  bool split_disjoint_volumes,
232  bool &success) const;
233  GEO_Primitive * convertToPrimVolume(
234  GEO_Detail &dst_geo,
236  bool split_disjoint_volumes) const;
237  GEO_Primitive * convertToPoly(
238  GEO_Detail &dst_geo,
240  fpreal adaptivity,
241  bool buildpolysoup,
242  bool &success) const;
243 
244  static GU_PrimVDB* buildFromGridAdapter(
245  GU_Detail& gdp,
246  void* grid,
247  const GEO_PrimVDB*,
248  const char* name);
249  static void createGridAttrsFromMetadataAdapter(
250  const GEO_PrimVDB& prim,
251  const void* grid,
252  GEO_Detail& gdp);
253  static void createMetadataFromGridAttrsAdapter(
254  void* grid,
255  const GEO_PrimVDB&,
256  const GEO_Detail&);
257 
258  static void createAttrsFromMetadataAdapter(
259  GA_AttributeOwner owner,
260  GA_Offset element,
261  const void* meta_map_ptr,
262  GEO_Detail& geo);
263 
264  static void createMetadataFromAttrsAdapter(
265  void* meta_map_ptr,
266  GA_AttributeOwner owner,
267  GA_Offset element,
268  const GEO_Detail& geo);
269 
270 private: // DATA
271 
272  static GA_PrimitiveDefinition *theDefinition;
273  friend class GU_PrimitiveFactory;
275 };
277 
278 
279 #if 0 //ndef SESI_OPENVDB
280 namespace openvdb_houdini {
281 using ::GU_PrimVDB;
282 } // namespace openvdb_houdini
283 #endif
284 
285 #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:179
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:193
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
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:207
#define GU_API
Definition: GU_API.h:14
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_AttributeOwner
Definition: GA_Types.h:35
GA_API const UT_StringHolder parms
fpreal64 fpreal
Definition: SYS_Types.h:278
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:164
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