OpenVDB: openvdb_houdini/SOP_NodeVDB.h Source File

OpenVDB 13.0.0

Loading...
Searching...
No Matches
SOP_NodeVDB.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 SOP_NodeVDB.h
5/// @author FX R&D OpenVDB team
6/// @brief Base class for OpenVDB plugins
7
8#ifndef OPENVDB_HOUDINI_SOP_NODEVDB_HAS_BEEN_INCLUDED
9#define OPENVDB_HOUDINI_SOP_NODEVDB_HAS_BEEN_INCLUDED
10
11#include <houdini_utils/ParmFactory.h>
12#include <openvdb/openvdb.h>
13#include <openvdb/Platform.h>
14#include <SOP/SOP_Node.h>
15#ifndef SESI_OPENVDB
16#include <UT/UT_DSOVersion.h>
17#endif
18#include "SOP_VDBVerbUtils.h"
19#include <iosfwd>
20#include <string>
21
22
23class GU_Detail;
24
25namespace openvdb_houdini {
26
27/// @brief Use this class to register a new OpenVDB operator (SOP, POP, etc.)
28/// @details This class ensures that the operator uses the appropriate OpPolicy.
29/// @sa houdini_utils::OpFactory, houdini_utils::OpPolicy
30 class OPENVDB_HOUDINI_API OpenVDBOpFactory: public houdini_utils::OpFactory
31{
32public:
33 /// Construct an OpFactory that on destruction registers a new OpenVDB operator type.
34 OpenVDBOpFactory(const std::string& english, OP_Constructor, houdini_utils::ParmList&,
35 OP_OperatorTable&, houdini_utils::OpFactory::OpFlavor = SOP);
36
37 /// @brief Set the name of the equivalent native operator as shipped with Houdini.
38 /// @details This is only needed where the native name policy doesn't provide the correct name.
39 /// Pass an empty string to indicate that there is no equivalent native operator.
40 OpenVDBOpFactory& setNativeName(const std::string& name);
41
42private:
43 std::string mNativeName;
44};
45
46
47////////////////////////////////////////
48
49
50/// @brief Base class from which to derive OpenVDB-related Houdini SOPs
51 class OPENVDB_HOUDINI_API SOP_NodeVDB: public SOP_Node
52{
53public:
54 SOP_NodeVDB(OP_Network*, const char*, OP_Operator*);
55 ~SOP_NodeVDB() override = default;
56
57 void fillInfoTreeNodeSpecific(UT_InfoTree&, const OP_NodeInfoTreeParms&) override;
58 void getNodeSpecificInfoText(OP_Context&, OP_NodeInfoParms&) override;
59
60 /// @brief Return this node's registered verb.
61 const SOP_NodeVerb* cookVerb() const override;
62
63 /// @brief Retrieve a group from a geometry detail by parsing a pattern
64 /// (typically, the value of a Group parameter belonging to this node).
65 /// @throw std::runtime_error if the pattern is nonempty but doesn't match any group.
66 /// @todo This is a wrapper for SOP_Node::parsePrimitiveGroups(), so it needs access
67 /// to a SOP_Node instance. But it probably doesn't need to be a SOP_NodeVDB method.
68 /// @{
69 const GA_PrimitiveGroup* matchGroup(GU_Detail&, const std::string& pattern);
70 const GA_PrimitiveGroup* matchGroup(const GU_Detail&, const std::string& pattern);
71 /// @}
72
73 /// @name Parameter evaluation
74 /// @{
75
76 /// @brief Evaluate a vector-valued parameter.
77 openvdb::Vec3f evalVec3f(const char* name, fpreal time) const;
78 /// @brief Evaluate a vector-valued parameter.
79 openvdb::Vec3R evalVec3R(const char* name, fpreal time) const;
80 /// @brief Evaluate a vector-valued parameter.
81 openvdb::Vec3i evalVec3i(const char* name, fpreal time) const;
82 /// @brief Evaluate a vector-valued parameter.
83 openvdb::Vec2R evalVec2R(const char* name, fpreal time) const;
84 /// @brief Evaluate a vector-valued parameter.
85 openvdb::Vec2i evalVec2i(const char* name, fpreal time) const;
86
87 /// @brief Evaluate a string-valued parameter as an STL string.
88 /// @details This method facilitates string parameter evaluation in expressions.
89 /// For example,
90 /// @code
91 /// matchGroup(*gdp, evalStdString("group", time));
92 /// @endcode
93 std::string evalStdString(const char* name, fpreal time, int index = 0) const;
94
95 /// @}
96
97protected:
98 /// @{
99 /// @brief To facilitate compilable SOPs, cookMySop() is now final.
100 /// Instead, either override SOP_NodeVDB::cookVDBSop() (for a non-compilable SOP)
101 /// or override SOP_VDBCacheOptions::cookVDBSop() (for a compilable SOP).
102 OP_ERROR cookMySop(OP_Context&) override final;
103
104 virtual OP_ERROR cookVDBSop(OP_Context&) { return UT_ERROR_NONE; }
105 /// @}
106
107 OP_ERROR cookMyGuide1(OP_Context&) override;
108 //OP_ERROR cookMyGuide2(OP_Context&) override;
109
110 /// @brief Transfer the value of an obsolete parameter that was renamed
111 /// to the parameter with the new name.
112 /// @details This convenience method is intended to be called from
113 /// @c resolveObsoleteParms(), when that function is implemented.
114 void resolveRenamedParm(PRM_ParmList& obsoleteParms,
115 const char* oldName, const char* newName);
116
117}; // class SOP_NodeVDB
118
119
120////////////////////////////////////////
121
122
123/// @brief Namespace to hold functionality for registering info text callbacks. Whenever
124/// getNodeSpecificInfoText() is called, the default info text is added to MMB output unless
125/// a valid callback has been registered for the grid type.
126///
127/// @details Use node_info_text::registerGridSpecificInfoText<> to register a grid type to
128/// a function pointer which matches the ApplyGridSpecificInfoText signature.
129///
130/// void floatGridText(std::ostream&, const openvdb::GridBase&);
131///
132/// node_info_text::registerGridSpecificInfoText<openvdb::FloatGrid>(&floatGridText);
133///
134 namespace node_info_text
135{
136 // The function pointer signature expected when registering an grid type text
137 // callback. The grid is passed untyped but is guaranteed to match the registered
138 // type.
139 using ApplyGridSpecificInfoText = void (*)(std::ostream&, const openvdb::GridBase&);
140
141 /// @brief Register an info text callback to a specific grid type.
142 /// @note Does not add the callback if the grid type already has a registered callback.
143 /// @param gridType the grid type as a unique string (see templated
144 /// registerGridSpecificInfoText<>)
145 /// @param callback a pointer to the callback function to execute
146 void registerGridSpecificInfoText(const std::string& gridType,
147 ApplyGridSpecificInfoText callback);
148
149 /// @brief Register an info text callback to a templated grid type.
150 /// @note Does not add the callback if the grid type already has a registered callback.
151 /// @param callback a pointer to the callback function to execute
152 template<typename GridType>
153 inline void registerGridSpecificInfoText(ApplyGridSpecificInfoText callback)
154 {
155 registerGridSpecificInfoText(GridType::gridType(), callback);
156 }
157
158} // namespace node_info_text
159
160
161} // namespace openvdb_houdini
162
163#endif // OPENVDB_HOUDINI_SOP_NODEVDB_HAS_BEEN_INCLUDED
Platform.h
OPENVDB_HOUDINI_API
#define OPENVDB_HOUDINI_API
Definition Platform.h:299
SOP_VDBVerbUtils.h
houdini_utils::OpFactory
Helper class to simplify operator registration.
Definition ParmFactory.h:376
houdini_utils::OpFactory::name
const std::string & name() const
Return the new operator's type name.
houdini_utils::OpFactory::english
const std::string & english() const
Return the new operator's UI name.
houdini_utils::OpFactory::OpFlavor
OpFlavor
Definition ParmFactory.h:378
houdini_utils::OpFactory::SOP
@ SOP
Definition ParmFactory.h:378
houdini_utils::ParmList
Parameter template list that is always terminated.
Definition ParmFactory.h:74
openvdb::v13_0::GridBase
Abstract base class for typed grids.
Definition Grid.h:78
openvdb_houdini::OpenVDBOpFactory::setNativeName
OpenVDBOpFactory & setNativeName(const std::string &name)
Set the name of the equivalent native operator as shipped with Houdini.
openvdb_houdini::OpenVDBOpFactory::OpenVDBOpFactory
OpenVDBOpFactory(const std::string &english, OP_Constructor, houdini_utils::ParmList &, OP_OperatorTable &, houdini_utils::OpFactory::OpFlavor=SOP)
Construct an OpFactory that on destruction registers a new OpenVDB operator type.
openvdb_houdini::SOP_NodeVDB::getNodeSpecificInfoText
void getNodeSpecificInfoText(OP_Context &, OP_NodeInfoParms &) override
openvdb_houdini::SOP_NodeVDB::evalStdString
std::string evalStdString(const char *name, fpreal time, int index=0) const
Evaluate a string-valued parameter as an STL string.
openvdb_houdini::SOP_NodeVDB::matchGroup
const GA_PrimitiveGroup * matchGroup(GU_Detail &, const std::string &pattern)
Retrieve a group from a geometry detail by parsing a pattern (typically, the value of a Group paramet...
openvdb_houdini::SOP_NodeVDB::fillInfoTreeNodeSpecific
void fillInfoTreeNodeSpecific(UT_InfoTree &, const OP_NodeInfoTreeParms &) override
openvdb_houdini::SOP_NodeVDB::SOP_NodeVDB
SOP_NodeVDB(OP_Network *, const char *, OP_Operator *)
openvdb_houdini::SOP_NodeVDB::evalVec3R
openvdb::Vec3R evalVec3R(const char *name, fpreal time) const
Evaluate a vector-valued parameter.
openvdb_houdini::SOP_NodeVDB::cookVerb
const SOP_NodeVerb * cookVerb() const override
Return this node's registered verb.
openvdb_houdini::SOP_NodeVDB::resolveRenamedParm
void resolveRenamedParm(PRM_ParmList &obsoleteParms, const char *oldName, const char *newName)
Transfer the value of an obsolete parameter that was renamed to the parameter with the new name.
openvdb_houdini::SOP_NodeVDB::evalVec3f
openvdb::Vec3f evalVec3f(const char *name, fpreal time) const
Evaluate a vector-valued parameter.
openvdb_houdini::SOP_NodeVDB::matchGroup
const GA_PrimitiveGroup * matchGroup(const GU_Detail &, const std::string &pattern)
Retrieve a group from a geometry detail by parsing a pattern (typically, the value of a Group paramet...
openvdb_houdini::SOP_NodeVDB::evalVec2R
openvdb::Vec2R evalVec2R(const char *name, fpreal time) const
Evaluate a vector-valued parameter.
openvdb_houdini::SOP_NodeVDB::cookVDBSop
virtual OP_ERROR cookVDBSop(OP_Context &)
To facilitate compilable SOPs, cookMySop() is now final. Instead, either override SOP_NodeVDB::cookVD...
Definition SOP_NodeVDB.h:104
openvdb_houdini::SOP_NodeVDB::~SOP_NodeVDB
~SOP_NodeVDB() override=default
openvdb_houdini::SOP_NodeVDB::evalVec2i
openvdb::Vec2i evalVec2i(const char *name, fpreal time) const
Evaluate a vector-valued parameter.
openvdb_houdini::SOP_NodeVDB::cookMyGuide1
OP_ERROR cookMyGuide1(OP_Context &) override
openvdb_houdini::SOP_NodeVDB::evalVec3i
openvdb::Vec3i evalVec3i(const char *name, fpreal time) const
Evaluate a vector-valued parameter.
openvdb_houdini::SOP_NodeVDB::cookMySop
OP_ERROR cookMySop(OP_Context &) override final
To facilitate compilable SOPs, cookMySop() is now final. Instead, either override SOP_NodeVDB::cookVD...
openvdb::v13_0::math::Vec2i
Vec2< int32_t > Vec2i
Definition Vec2.h:530
openvdb::v13_0::math::Vec3i
Vec3< int32_t > Vec3i
Definition Vec3.h:662
openvdb::v13_0::Vec2R
math::Vec2< Real > Vec2R
Definition Types.h:44
openvdb::v13_0::Vec3f
math::Vec3< float > Vec3f
Definition Types.h:55
openvdb::v13_0::Vec3R
math::Vec3< Real > Vec3R
Definition Types.h:53
openvdb_houdini::node_info_text
Namespace to hold functionality for registering info text callbacks. Whenever getNodeSpecificInfoText...
Definition SOP_NodeVDB.h:135
openvdb_houdini::node_info_text::ApplyGridSpecificInfoText
void(*)(std::ostream &, const openvdb::GridBase &) ApplyGridSpecificInfoText
Definition SOP_NodeVDB.h:139
openvdb_houdini::node_info_text::registerGridSpecificInfoText
void registerGridSpecificInfoText(const std::string &gridType, ApplyGridSpecificInfoText callback)
Register an info text callback to a specific grid type.
openvdb_houdini
Definition AttributeTransferUtil.h:34
openvdb.h