OpenVDB 13.0.0

Loading...
Searching...
No Matches
PointUtils.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-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>
15#include <openvdb/util/NullInterrupter.h>
16#include <openvdb/points/PointDataGrid.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
56 enum POINT_COMPRESSION_TYPE
57{
58 COMPRESSION_NONE = 0,
59 COMPRESSION_TRUNCATE,
60 COMPRESSION_UNIT_VECTOR,
61 COMPRESSION_UNIT_FIXED_POINT_8,
62 COMPRESSION_UNIT_FIXED_POINT_16,
63};
64
65
66
67/// @brief Compute a voxel size from a Houdini detail
68///
69/// @param detail GU_Detail to compute the voxel size from
70/// @param pointsPerVoxel the target number of points per voxel, must be positive and non-zero
71/// @param matrix voxel size will be computed using this transform
72/// @param decimalPlaces for readability, truncate voxel size to this number of decimals
73/// @param interrupter a Houdini interrupter
74 OPENVDB_HOUDINI_API
75 float
76 computeVoxelSizeFromHoudini(
77 const GU_Detail& detail,
78 const openvdb::Index pointsPerVoxel,
79 const openvdb::math::Mat4d& matrix,
80 const openvdb::Index decimalPlaces,
81 openvdb::util::NullInterrupter& interrupter);
82
83
84/// @brief Convert a Houdini detail into a VDB Points grid
85///
86/// @param detail GU_Detail to convert the points and attributes from
87/// @param compression position compression to use
88/// @param attributes a vector of VDB Points attributes to be included
89/// (empty vector defaults to all)
90/// @param transform transform to use for the new point grid
91/// @param warnings list of warnings to be added to the SOP
92 OPENVDB_HOUDINI_API
93openvdb::points::PointDataGrid::Ptr
94 convertHoudiniToPointDataGrid(
95 const GU_Detail& detail,
96 const int compression,
97 const AttributeInfoMap& attributes,
98 const openvdb::math::Transform& transform,
99 const WarnFunc& warnings = [](const std::string&){});
100
101
102/// @brief Convert a VDB Points grid into Houdini points and append them to a Houdini Detail
103///
104/// @param detail GU_Detail to append the converted points and attributes to
105/// @param grid grid containing the points that will be converted
106/// @param attributes a vector of VDB Points attributes to be included
107/// (empty vector defaults to all)
108/// @param includeGroups a vector of VDB Points groups to be included
109/// (empty vector defaults to all)
110/// @param excludeGroups a vector of VDB Points groups to be excluded
111/// (empty vector defaults to none)
112/// @param inCoreOnly true if out-of-core leaf nodes are to be ignored
113 OPENVDB_HOUDINI_API
114 void
115 convertPointDataGridToHoudini(
116 GU_Detail& detail,
117 const openvdb::points::PointDataGrid& grid,
118 const std::vector<std::string>& attributes = {},
119 const std::vector<std::string>& includeGroups = {},
120 const std::vector<std::string>& excludeGroups = {},
121 const bool inCoreOnly = false);
122
123
124/// @brief Populate VDB Points grid metadata from Houdini detail attributes
125///
126/// @param grid grid to be populated with metadata
127/// @param detail GU_Detail to extract the detail attributes from
128/// @param warnings list of warnings to be added to the SOP
129 OPENVDB_HOUDINI_API
130 void
131 populateMetadataFromHoudini(
132 openvdb::points::PointDataGrid& grid,
133 const GU_Detail& detail,
134 const WarnFunc& warnings = [](const std::string&){});
135
136
137/// @brief Convert VDB Points grid metadata into Houdini detail attributes
138///
139/// @param detail GU_Detail to add the Houdini detail attributes
140/// @param metaMap the metamap to create the Houdini detail attributes from
141/// @param warnings list of warnings to be added to the SOP
142 OPENVDB_HOUDINI_API
143 void
144 convertMetadataToHoudini(
145 GU_Detail& detail,
146 const openvdb::MetaMap& metaMap,
147 const WarnFunc& warnings = [](const std::string&){});
148
149
150/// @brief Returns supported tuple sizes for conversion from GA_Attribute
151 OPENVDB_HOUDINI_API
152int16_t
153 attributeTupleSize(const GA_Attribute* const attribute);
154
155
156/// @brief Returns supported Storage types for conversion from GA_Attribute
157 OPENVDB_HOUDINI_API
158GA_Storage
159 attributeStorageType(const GA_Attribute* const attribute);
160
161
162///////////////////////////////////////
163
164
165/// @brief If the given grid is a PointDataGrid, add node specific info text to
166/// the stream provided. This is used to populate the MMB window in Houdini
167/// versions 15 and earlier, as well as the Operator Information Window.
168 OPENVDB_HOUDINI_API
169 void
170 pointDataGridSpecificInfoText(std::ostream&, const openvdb::GridBase&);
171
172/// @brief Populates string data with information about the provided OpenVDB
173/// Points grid.
174/// @param grid The OpenVDB Points grid to retrieve information from.
175/// @param countStr The total point count as a formatted integer.
176/// @param groupStr The list of comma separated groups (or "none" if no
177/// groups exist). Enclosed by parentheses.
178/// @param attributeStr The list of comma separated attributes (or "none" if
179/// no attributes exist). Enclosed by parentheses.
180/// Each attribute takes the form "name [type] [code]
181/// [stride]" where code and stride are added for non
182/// default attributes.
183 OPENVDB_HOUDINI_API
184 void
185 collectPointInfo(const openvdb::points::PointDataGrid& grid,
186 std::string& countStr,
187 std::string& groupStr,
188 std::string& attributeStr);
189
190
191///////////////////////////////////////
192
193
194// VDB Points group name drop-down menu
195
196 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput1;
197 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput2;
198 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput3;
199 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput4;
200
201/// @note Use this if you have more than 4 inputs, otherwise use
202/// the input specific menus instead which automatically
203/// handle the appropriate spare data settings.
204 OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenu;
205
206} // namespace openvdb_houdini
207
208#endif // OPENVDB_HOUDINI_POINT_UTILS_HAS_BEEN_INCLUDED
NullInterrupter.h
OPENVDB_HOUDINI_API
#define OPENVDB_HOUDINI_API
Definition Platform.h:299
PointDataGrid.h
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Vec3.h
openvdb::v13_0::GridBase
Abstract base class for typed grids.
Definition Grid.h:78
openvdb::v13_0::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
detail
Definition VoxToNanoVDB.h:15
openvdb::v13_0::Index
Index32 Index
Definition Types.h:34
openvdb_houdini
Definition AttributeTransferUtil.h:34
openvdb_houdini::convertPointDataGridToHoudini
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::attributeStorageType
OPENVDB_HOUDINI_API GA_Storage attributeStorageType(const GA_Attribute *const attribute)
Returns supported Storage types for conversion from GA_Attribute.
openvdb_houdini::VDBPointsGroupMenu
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenu
openvdb_houdini::OffsetListPtr
std::shared_ptr< OffsetList > OffsetListPtr
Definition PointUtils.h:40
openvdb_houdini::OffsetList
std::vector< GA_Offset > OffsetList
Definition PointUtils.h:39
openvdb_houdini::VDBPointsGroupMenuInput2
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput2
openvdb_houdini::computeVoxelSizeFromHoudini
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.
openvdb_houdini::OffsetPairListPtr
std::shared_ptr< OffsetPairList > OffsetPairListPtr
Definition PointUtils.h:44
openvdb_houdini::attributeTupleSize
OPENVDB_HOUDINI_API int16_t attributeTupleSize(const GA_Attribute *const attribute)
Returns supported tuple sizes for conversion from GA_Attribute.
openvdb_houdini::populateMetadataFromHoudini
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.
openvdb_houdini::WarnFunc
std::function< void(const std::string &)> WarnFunc
Definition PointUtils.h:49
openvdb_houdini::OffsetPairList
std::vector< OffsetPair > OffsetPairList
Definition PointUtils.h:43
openvdb_houdini::pointDataGridSpecificInfoText
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::convertHoudiniToPointDataGrid
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::VDBPointsGroupMenuInput4
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput4
openvdb_houdini::META_GROUP_VIEWPORT
const std::string META_GROUP_VIEWPORT
Metadata name for viewport groups.
Definition PointUtils.h:52
openvdb_houdini::OffsetPair
std::pair< GA_Offset, GA_Offset > OffsetPair
Definition PointUtils.h:42
openvdb_houdini::collectPointInfo
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.
openvdb_houdini::VDBPointsGroupMenuInput1
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput1
openvdb_houdini::convertMetadataToHoudini
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::AttributeInfoMap
std::map< openvdb::Name, std::pair< int, bool > > AttributeInfoMap
Definition PointUtils.h:47
openvdb_houdini::POINT_COMPRESSION_TYPE
POINT_COMPRESSION_TYPE
Enum to store available compression types for point grids.
Definition PointUtils.h:57
openvdb_houdini::COMPRESSION_UNIT_VECTOR
@ COMPRESSION_UNIT_VECTOR
Definition PointUtils.h:60
openvdb_houdini::COMPRESSION_UNIT_FIXED_POINT_8
@ COMPRESSION_UNIT_FIXED_POINT_8
Definition PointUtils.h:61
openvdb_houdini::COMPRESSION_TRUNCATE
@ COMPRESSION_TRUNCATE
Definition PointUtils.h:59
openvdb_houdini::COMPRESSION_NONE
@ COMPRESSION_NONE
Definition PointUtils.h:58
openvdb_houdini::COMPRESSION_UNIT_FIXED_POINT_16
@ COMPRESSION_UNIT_FIXED_POINT_16
Definition PointUtils.h:62
openvdb_houdini::VDBPointsGroupMenuInput3
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput3
Types.h