OpenVDB: openvdb_houdini/PointUtils.h Source File

OpenVDB 12.1.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
37namespace 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// forward declaration
67class 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
77 OPENVDB_HOUDINI_API
78float
79computeVoxelSizeFromHoudini(
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")
87 OPENVDB_HOUDINI_API
88float
89 computeVoxelSizeFromHoudini(
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
105 OPENVDB_HOUDINI_API
106 openvdb::points::PointDataGrid::Ptr
107convertHoudiniToPointDataGrid(
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
126 OPENVDB_HOUDINI_API
127void
128convertPointDataGridToHoudini(
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
142 OPENVDB_HOUDINI_API
143void
144populateMetadataFromHoudini(
145 openvdb::points::PointDataGrid& grid,
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
155 OPENVDB_HOUDINI_API
156void
157convertMetadataToHoudini(
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
164 OPENVDB_HOUDINI_API
165int16_t
166attributeTupleSize(const GA_Attribute* const attribute);
167
168
169/// @brief Returns supported Storage types for conversion from GA_Attribute
170 OPENVDB_HOUDINI_API
171GA_Storage
172attributeStorageType(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.
181 OPENVDB_HOUDINI_API
182void
183pointDataGridSpecificInfoText(std::ostream&, const openvdb::GridBase&);
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.
196 OPENVDB_HOUDINI_API
197void
198collectPointInfo(const openvdb::points::PointDataGrid& grid,
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
NullInterrupter.h
OPENVDB_HOUDINI_API
#define OPENVDB_HOUDINI_API
Definition Platform.h:299
OPENVDB_DEPRECATED_MESSAGE
#define OPENVDB_DEPRECATED_MESSAGE(msg)
Definition Platform.h:171
PointDataGrid.h
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Vec3.h
openvdb::v12_1::GridBase
Abstract base class for typed grids.
Definition Grid.h:78
openvdb::v12_1::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
openvdb_houdini::Interrupter
Deprecated wrapper class with the same interface as HoudiniInterrupter, however it does not derive fr...
Definition Utils.h:218
detail
Definition VoxToNanoVDB.h:15
openvdb::v12_1::Index
Index32 Index
Definition Types.h:54
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
openvdb
Definition Exceptions.h:13
std
Definition Coord.h:590
Types.h