OpenVDB 13.0.1
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>
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
39using OffsetList = std::vector<GA_Offset>;
40using OffsetListPtr = std::shared_ptr<OffsetList>;
41
42using OffsetPair = std::pair<GA_Offset, GA_Offset>;
43using OffsetPairList = std::vector<OffsetPair>;
44using OffsetPairListPtr = std::shared_ptr<OffsetPairList>;
45
46// note that the bool parameter here for toggling in-memory compression is now deprecated
47using AttributeInfoMap = std::map<openvdb::Name, std::pair<int, bool>>;
48
49using WarnFunc = std::function<void (const std::string&)>;
50
51/// Metadata name for viewport groups
52const std::string META_GROUP_VIEWPORT = "group_viewport";
53
54
55/// Enum to store available compression types for point grids
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
75float
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
93openvdb::points::PointDataGrid::Ptr
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
114void
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
130void
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
143void
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
152int16_t
153attributeTupleSize(const GA_Attribute* const attribute);
154
155
156/// @brief Returns supported Storage types for conversion from GA_Attribute
158GA_Storage
159attributeStorageType(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.
169void
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.
184void
185collectPointInfo(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
196OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput1;
197OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput2;
198OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenuInput3;
199OPENVDB_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.
204OPENVDB_HOUDINI_API extern const PRM_ChoiceList VDBPointsGroupMenu;
205
206} // namespace openvdb_houdini
207
208#endif // OPENVDB_HOUDINI_POINT_UTILS_HAS_BEEN_INCLUDED
#define OPENVDB_HOUDINI_API
Definition Platform.h:299
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
Definition VoxToNanoVDB.h:15
Index32 Index
Definition Types.h:34
Definition AttributeTransferUtil.h:34
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 GA_Storage attributeStorageType(const GA_Attribute *const attribute)
Returns supported Storage types for conversion from GA_Attribute.
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenu
std::shared_ptr< OffsetList > OffsetListPtr
Definition PointUtils.h:40
std::vector< GA_Offset > OffsetList
Definition PointUtils.h:39
OPENVDB_HOUDINI_API const PRM_ChoiceList VDBPointsGroupMenuInput2
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< OffsetPairList > OffsetPairListPtr
Definition PointUtils.h:44
OPENVDB_HOUDINI_API int16_t attributeTupleSize(const GA_Attribute *const attribute)
Returns supported tuple sizes for conversion from GA_Attribute.
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.
std::function< void(const std::string &)> WarnFunc
Definition PointUtils.h:49
std::vector< OffsetPair > OffsetPairList
Definition PointUtils.h:43
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 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 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 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_API const PRM_ChoiceList VDBPointsGroupMenuInput1
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.
std::map< openvdb::Name, std::pair< int, bool > > AttributeInfoMap
Definition PointUtils.h:47
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