OpenVDB  8.2.0
PointUtils.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 /// @file PointUtils.h
5 ///
6 /// @authors Dan Bailey, Nick Avramoussis, Richard Kwok
7 ///
8 /// @brief Utility classes and functions for OpenVDB Points Houdini plugins
9 
10 #ifndef OPENVDB_HOUDINI_POINT_UTILS_HAS_BEEN_INCLUDED
11 #define OPENVDB_HOUDINI_POINT_UTILS_HAS_BEEN_INCLUDED
12 
13 #include <openvdb/math/Vec3.h>
14 #include <openvdb/Types.h>
16 
17 #include <GA/GA_Attribute.h>
18 #include <GU/GU_Detail.h>
19 #include <PRM/PRM_ChoiceList.h>
20 
21 #include <iosfwd>
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 
28 #ifdef SESI_OPENVDB
29  #ifdef OPENVDB_HOUDINI_API
30  #undef OPENVDB_HOUDINI_API
31  #define OPENVDB_HOUDINI_API
32  #endif
33 #endif
34 
35 
36 namespace openvdb_houdini {
37 
38 using OffsetList = std::vector<GA_Offset>;
39 using OffsetListPtr = std::shared_ptr<OffsetList>;
40 
41 using OffsetPair = std::pair<GA_Offset, GA_Offset>;
42 using OffsetPairList = std::vector<OffsetPair>;
43 using OffsetPairListPtr = std::shared_ptr<OffsetPairList>;
44 
45 // note that the bool parameter here for toggling in-memory compression is now deprecated
46 using AttributeInfoMap = std::map<openvdb::Name, std::pair<int, bool>>;
47 
48 using WarnFunc = std::function<void (const std::string&)>;
49 
50 /// Metadata name for viewport groups
51 const std::string META_GROUP_VIEWPORT = "group_viewport";
52 
53 
54 /// Enum to store available compression types for point grids
56 {
62 };
63 
64 
65 // forward declaration
66 class Interrupter;
67 
68 
69 /// @brief Compute a voxel size from a Houdini detail
70 ///
71 /// @param detail GU_Detail to compute the voxel size from
72 /// @param pointsPerVoxel the target number of points per voxel, must be positive and non-zero
73 /// @param matrix voxel size will be computed using this transform
74 /// @param decimalPlaces for readability, truncate voxel size to this number of decimals
75 /// @param interrupter a Houdini interrupter
77 float
79  const GU_Detail& detail,
80  const openvdb::Index pointsPerVoxel,
81  const openvdb::math::Mat4d& matrix,
82  const openvdb::Index decimalPlaces,
83  Interrupter& interrupter);
84 
85 
86 /// @brief Convert a Houdini detail into a VDB Points grid
87 ///
88 /// @param detail GU_Detail to convert the points and attributes from
89 /// @param compression position compression to use
90 /// @param attributes a vector of VDB Points attributes to be included
91 /// (empty vector defaults to all)
92 /// @param transform transform to use for the new point grid
93 /// @param warnings list of warnings to be added to the SOP
95 openvdb::points::PointDataGrid::Ptr
97  const GU_Detail& detail,
98  const int compression,
99  const AttributeInfoMap& attributes,
100  const openvdb::math::Transform& transform,
101  const WarnFunc& warnings = [](const std::string&){});
102 
103 
104 /// @brief Convert a VDB Points grid into Houdini points and append them to a Houdini Detail
105 ///
106 /// @param detail GU_Detail to append the converted points and attributes to
107 /// @param grid grid containing the points that will be converted
108 /// @param attributes a vector of VDB Points attributes to be included
109 /// (empty vector defaults to all)
110 /// @param includeGroups a vector of VDB Points groups to be included
111 /// (empty vector defaults to all)
112 /// @param excludeGroups a vector of VDB Points groups to be excluded
113 /// (empty vector defaults to none)
114 /// @param inCoreOnly true if out-of-core leaf nodes are to be ignored
116 void
118  GU_Detail& detail,
119  const openvdb::points::PointDataGrid& grid,
120  const std::vector<std::string>& attributes = {},
121  const std::vector<std::string>& includeGroups = {},
122  const std::vector<std::string>& excludeGroups = {},
123  const bool inCoreOnly = false);
124 
125 
126 /// @brief Populate VDB Points grid metadata from Houdini detail attributes
127 ///
128 /// @param grid grid to be populated with metadata
129 /// @param detail GU_Detail to extract the detail attributes from
130 /// @param warnings list of warnings to be added to the SOP
132 void
135  const GU_Detail& detail,
136  const WarnFunc& warnings = [](const std::string&){});
137 
138 
139 /// @brief Convert VDB Points grid metadata into Houdini detail attributes
140 ///
141 /// @param detail GU_Detail to add the Houdini detail attributes
142 /// @param metaMap the metamap to create the Houdini detail attributes from
143 /// @param warnings list of warnings to be added to the SOP
145 void
147  GU_Detail& detail,
148  const openvdb::MetaMap& metaMap,
149  const WarnFunc& warnings = [](const std::string&){});
150 
151 
152 /// @brief Returns supported tuple sizes for conversion from GA_Attribute
154 int16_t
155 attributeTupleSize(const GA_Attribute* const attribute);
156 
157 
158 /// @brief Returns supported Storage types for conversion from GA_Attribute
160 GA_Storage
161 attributeStorageType(const GA_Attribute* const attribute);
162 
163 
164 ///////////////////////////////////////
165 
166 
167 /// @brief If the given grid is a PointDataGrid, add node specific info text to
168 /// the stream provided. This is used to populate the MMB window in Houdini
169 /// versions 15 and earlier, as well as the Operator Information Window.
171 void
173 
174 /// @brief Populates string data with information about the provided OpenVDB
175 /// Points grid.
176 /// @param grid The OpenVDB Points grid to retrieve information from.
177 /// @param countStr The total point count as a formatted integer.
178 /// @param groupStr The list of comma separated groups (or "none" if no
179 /// groups exist). Enclosed by parentheses.
180 /// @param attributeStr The list of comma separated attributes (or "none" if
181 /// no attributes exist). Enclosed by parentheses.
182 /// Each attribute takes the form "name [type] [code]
183 /// [stride]" where code and stride are added for non
184 /// default attributes.
186 void
188  std::string& countStr,
189  std::string& groupStr,
190  std::string& attributeStr);
191 
192 
193 ///////////////////////////////////////
194 
195 
196 // VDB Points group name drop-down menu
197 
198 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput1;
199 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput2;
200 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput3;
201 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput4;
202 
203 /// @note Use this if you have more than 4 inputs, otherwise use
204 /// the input specific menus instead which automatically
205 /// handle the appropriate spare data settings.
206 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenu;
207 
208 } // namespace openvdb_houdini
209 
210 #endif // OPENVDB_HOUDINI_POINT_UTILS_HAS_BEEN_INCLUDED
#define OPENVDB_HOUDINI_API
Definition: Platform.h:248
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Abstract base class for typed grids.
Definition: Grid.h:78
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:20
Wrapper class that adapts a Houdini UT_Interrupt object for use with OpenVDB library routines.
Definition: Utils.h:174
Mat4< double > Mat4d
Definition: Mat4.h:1368
Grid< PointDataTree > PointDataGrid
Point data grid.
Definition: PointDataGrid.h:194
Index32 Index
Definition: Types.h:54
Definition: AttributeTransferUtil.h:33
OPENVDB_HOUDINI_API openvdb::points::PointDataGrid::Ptr convertHoudiniToPointDataGrid(const GU_Detail &detail, const int compression, const AttributeInfoMap &attributes, const openvdb::math::Transform &transform, const WarnFunc &warnings=[](const std::string &){})
Convert a Houdini detail into a VDB Points grid.
OPENVDB_HOUDINI_API int16_t attributeTupleSize(const GA_Attribute *const attribute)
Returns supported tuple sizes for conversion from GA_Attribute.
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenu
OPENVDB_HOUDINI_API void collectPointInfo(const openvdb::points::PointDataGrid &grid, std::string &countStr, std::string &groupStr, std::string &attributeStr)
Populates string data with information about the provided OpenVDB Points grid.
std::map< openvdb::Name, std::pair< int, bool > > AttributeInfoMap
Definition: PointUtils.h:46
OPENVDB_HOUDINI_API float computeVoxelSizeFromHoudini(const GU_Detail &detail, const openvdb::Index pointsPerVoxel, const openvdb::math::Mat4d &matrix, const openvdb::Index decimalPlaces, Interrupter &interrupter)
Compute a voxel size from a Houdini detail.
OPENVDB_HOUDINI_API GA_Storage attributeStorageType(const GA_Attribute *const attribute)
Returns supported Storage types for conversion from GA_Attribute.
OPENVDB_HOUDINI_API void convertPointDataGridToHoudini(GU_Detail &detail, const openvdb::points::PointDataGrid &grid, const std::vector< std::string > &attributes={}, const std::vector< std::string > &includeGroups={}, const std::vector< std::string > &excludeGroups={}, const bool inCoreOnly=false)
Convert a VDB Points grid into Houdini points and append them to a Houdini Detail.
std::shared_ptr< OffsetList > OffsetListPtr
Definition: PointUtils.h:39
std::vector< GA_Offset > OffsetList
Definition: PointUtils.h:38
OPENVDB_HOUDINI_API void pointDataGridSpecificInfoText(std::ostream &, const openvdb::GridBase &)
If the given grid is a PointDataGrid, add node specific info text to the stream provided....
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput2
std::shared_ptr< OffsetPairList > OffsetPairListPtr
Definition: PointUtils.h:43
std::function< void(const std::string &)> WarnFunc
Definition: PointUtils.h:48
std::vector< OffsetPair > OffsetPairList
Definition: PointUtils.h:42
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput4
const std::string META_GROUP_VIEWPORT
Metadata name for viewport groups.
Definition: PointUtils.h:51
std::pair< GA_Offset, GA_Offset > OffsetPair
Definition: PointUtils.h:41
OPENVDB_HOUDINI_API void convertMetadataToHoudini(GU_Detail &detail, const openvdb::MetaMap &metaMap, const WarnFunc &warnings=[](const std::string &){})
Convert VDB Points grid metadata into Houdini detail attributes.
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput1
POINT_COMPRESSION_TYPE
Enum to store available compression types for point grids.
Definition: PointUtils.h:56
@ COMPRESSION_UNIT_VECTOR
Definition: PointUtils.h:59
@ COMPRESSION_UNIT_FIXED_POINT_8
Definition: PointUtils.h:60
@ COMPRESSION_TRUNCATE
Definition: PointUtils.h:58
@ COMPRESSION_NONE
Definition: PointUtils.h:57
@ COMPRESSION_UNIT_FIXED_POINT_16
Definition: PointUtils.h:61
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput3
OPENVDB_HOUDINI_API void populateMetadataFromHoudini(openvdb::points::PointDataGrid &grid, const GU_Detail &detail, const WarnFunc &warnings=[](const std::string &){})
Populate VDB Points grid metadata from Houdini detail attributes.