OpenVDB  9.1.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>
17 
18 #include <GA/GA_Attribute.h>
19 #include <GU/GU_Detail.h>
20 #include <PRM/PRM_ChoiceList.h>
21 
22 #include <iosfwd>
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 
29 #ifdef SESI_OPENVDB
30  #ifdef OPENVDB_HOUDINI_API
31  #undef OPENVDB_HOUDINI_API
32  #define OPENVDB_HOUDINI_API
33  #endif
34 #endif
35 
36 
37 namespace openvdb_houdini {
38 
39 using OffsetList = std::vector<GA_Offset>;
40 using OffsetListPtr = std::shared_ptr<OffsetList>;
41 
42 using OffsetPair = std::pair<GA_Offset, GA_Offset>;
43 using OffsetPairList = std::vector<OffsetPair>;
44 using OffsetPairListPtr = std::shared_ptr<OffsetPairList>;
45 
46 // note that the bool parameter here for toggling in-memory compression is now deprecated
47 using AttributeInfoMap = std::map<openvdb::Name, std::pair<int, bool>>;
48 
49 using WarnFunc = std::function<void (const std::string&)>;
50 
51 /// Metadata name for viewport groups
52 const std::string META_GROUP_VIEWPORT = "group_viewport";
53 
54 
55 /// Enum to store available compression types for point grids
57 {
63 };
64 
65 
66 // forward declaration
67 class Interrupter;
68 
69 
70 /// @brief Compute a voxel size from a Houdini detail
71 ///
72 /// @param detail GU_Detail to compute the voxel size from
73 /// @param pointsPerVoxel the target number of points per voxel, must be positive and non-zero
74 /// @param matrix voxel size will be computed using this transform
75 /// @param decimalPlaces for readability, truncate voxel size to this number of decimals
76 /// @param interrupter a Houdini interrupter
78 float
80  const GU_Detail& detail,
81  const openvdb::Index pointsPerVoxel,
82  const openvdb::math::Mat4d& matrix,
83  const openvdb::Index decimalPlaces,
84  openvdb::util::NullInterrupter& interrupter);
85 
86 OPENVDB_DEPRECATED_MESSAGE("openvdb_houdini::Interrupter has been deprecated, use openvdb_houdini::HoudiniInterrupter")
88 float
90  const GU_Detail& detail,
91  const openvdb::Index pointsPerVoxel,
92  const openvdb::math::Mat4d& matrix,
93  const openvdb::Index decimalPlaces,
94  Interrupter& interrupter);
95 
96 
97 /// @brief Convert a Houdini detail into a VDB Points grid
98 ///
99 /// @param detail GU_Detail to convert the points and attributes from
100 /// @param compression position compression to use
101 /// @param attributes a vector of VDB Points attributes to be included
102 /// (empty vector defaults to all)
103 /// @param transform transform to use for the new point grid
104 /// @param warnings list of warnings to be added to the SOP
106 openvdb::points::PointDataGrid::Ptr
108  const GU_Detail& detail,
109  const int compression,
110  const AttributeInfoMap& attributes,
111  const openvdb::math::Transform& transform,
112  const WarnFunc& warnings = [](const std::string&){});
113 
114 
115 /// @brief Convert a VDB Points grid into Houdini points and append them to a Houdini Detail
116 ///
117 /// @param detail GU_Detail to append the converted points and attributes to
118 /// @param grid grid containing the points that will be converted
119 /// @param attributes a vector of VDB Points attributes to be included
120 /// (empty vector defaults to all)
121 /// @param includeGroups a vector of VDB Points groups to be included
122 /// (empty vector defaults to all)
123 /// @param excludeGroups a vector of VDB Points groups to be excluded
124 /// (empty vector defaults to none)
125 /// @param inCoreOnly true if out-of-core leaf nodes are to be ignored
127 void
129  GU_Detail& detail,
130  const openvdb::points::PointDataGrid& grid,
131  const std::vector<std::string>& attributes = {},
132  const std::vector<std::string>& includeGroups = {},
133  const std::vector<std::string>& excludeGroups = {},
134  const bool inCoreOnly = false);
135 
136 
137 /// @brief Populate VDB Points grid metadata from Houdini detail attributes
138 ///
139 /// @param grid grid to be populated with metadata
140 /// @param detail GU_Detail to extract the detail attributes from
141 /// @param warnings list of warnings to be added to the SOP
143 void
146  const GU_Detail& detail,
147  const WarnFunc& warnings = [](const std::string&){});
148 
149 
150 /// @brief Convert VDB Points grid metadata into Houdini detail attributes
151 ///
152 /// @param detail GU_Detail to add the Houdini detail attributes
153 /// @param metaMap the metamap to create the Houdini detail attributes from
154 /// @param warnings list of warnings to be added to the SOP
156 void
158  GU_Detail& detail,
159  const openvdb::MetaMap& metaMap,
160  const WarnFunc& warnings = [](const std::string&){});
161 
162 
163 /// @brief Returns supported tuple sizes for conversion from GA_Attribute
165 int16_t
166 attributeTupleSize(const GA_Attribute* const attribute);
167 
168 
169 /// @brief Returns supported Storage types for conversion from GA_Attribute
171 GA_Storage
172 attributeStorageType(const GA_Attribute* const attribute);
173 
174 
175 ///////////////////////////////////////
176 
177 
178 /// @brief If the given grid is a PointDataGrid, add node specific info text to
179 /// the stream provided. This is used to populate the MMB window in Houdini
180 /// versions 15 and earlier, as well as the Operator Information Window.
182 void
184 
185 /// @brief Populates string data with information about the provided OpenVDB
186 /// Points grid.
187 /// @param grid The OpenVDB Points grid to retrieve information from.
188 /// @param countStr The total point count as a formatted integer.
189 /// @param groupStr The list of comma separated groups (or "none" if no
190 /// groups exist). Enclosed by parentheses.
191 /// @param attributeStr The list of comma separated attributes (or "none" if
192 /// no attributes exist). Enclosed by parentheses.
193 /// Each attribute takes the form "name [type] [code]
194 /// [stride]" where code and stride are added for non
195 /// default attributes.
197 void
199  std::string& countStr,
200  std::string& groupStr,
201  std::string& attributeStr);
202 
203 
204 ///////////////////////////////////////
205 
206 
207 // VDB Points group name drop-down menu
208 
209 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput1;
210 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput2;
211 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput3;
212 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput4;
213 
214 /// @note Use this if you have more than 4 inputs, otherwise use
215 /// the input specific menus instead which automatically
216 /// handle the appropriate spare data settings.
217 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenu;
218 
219 } // namespace openvdb_houdini
220 
221 #endif // OPENVDB_HOUDINI_POINT_UTILS_HAS_BEEN_INCLUDED
#define OPENVDB_HOUDINI_API
Definition: Platform.h:257
#define OPENVDB_DEPRECATED_MESSAGE(msg)
Definition: Platform.h:123
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
Deprecated wrapper class with the same interface as HoudiniInterrupter, however it does not derive fr...
Definition: Utils.h:209
Definition: VoxToNanoVDB.h:14
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:34
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:47
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.
OPENVDB_HOUDINI_API float computeVoxelSizeFromHoudini(const GU_Detail &detail, const openvdb::Index pointsPerVoxel, const openvdb::math::Mat4d &matrix, const openvdb::Index decimalPlaces, openvdb::util::NullInterrupter &interrupter)
Compute a voxel size from a Houdini detail.
std::shared_ptr< OffsetList > OffsetListPtr
Definition: PointUtils.h:40
std::vector< GA_Offset > OffsetList
Definition: PointUtils.h:39
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:44
std::function< void(const std::string &)> WarnFunc
Definition: PointUtils.h:49
std::vector< OffsetPair > OffsetPairList
Definition: PointUtils.h:43
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput4
const std::string META_GROUP_VIEWPORT
Metadata name for viewport groups.
Definition: PointUtils.h:52
std::pair< GA_Offset, GA_Offset > OffsetPair
Definition: PointUtils.h:42
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:57
@ COMPRESSION_UNIT_VECTOR
Definition: PointUtils.h:60
@ COMPRESSION_UNIT_FIXED_POINT_8
Definition: PointUtils.h:61
@ COMPRESSION_TRUNCATE
Definition: PointUtils.h:59
@ COMPRESSION_NONE
Definition: PointUtils.h:58
@ COMPRESSION_UNIT_FIXED_POINT_16
Definition: PointUtils.h:62
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.
Definition: Exceptions.h:13
Definition: Coord.h:587