OpenVDB: openvdb_houdini/SOP_VDBVerbUtils.h Source File

OpenVDB 9.1.0

SOP_VDBVerbUtils.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4/*
5 * Copyright (c)
6 * Side Effects Software Inc. All rights reserved.
7 */
8
9#ifndef OPENVDB_HOUDINI_SOP_VDBVERBUTILS_HAS_BEEN_INCLUDED
10#define OPENVDB_HOUDINI_SOP_VDBVERBUTILS_HAS_BEEN_INCLUDED
11
12#include <GOP/GOP_Manager.h>
13#include <SOP/SOP_NodeParmsOptions.h> // for SOP_NodeCacheOptions
14#include <openvdb/Types.h>
15#include <string>
16
17
18////////////////////////////////////////
19
20
21/// @brief SOP_NodeCacheOptions subclass that adds methods specific to SOP_NodeVDB
22 class SOP_VDBCacheOptions: public SOP_NodeCacheOptions
23{
24public:
25 SOP_VDBCacheOptions() {}
26 ~SOP_VDBCacheOptions() override {}
27
28 openvdb::Vec3f evalVec3f(const char* name, fpreal time) const
29 {
30 return openvdb::Vec3f(static_cast<float>(evalFloat(name, 0, time)),
31 static_cast<float>(evalFloat(name, 1, time)),
32 static_cast<float>(evalFloat(name, 2, time)));
33 }
34 openvdb::Vec3R evalVec3R(const char* name, fpreal time) const
35 {
36 return openvdb::Vec3R(evalFloat(name, 0, time),
37 evalFloat(name, 1, time),
38 evalFloat(name, 2, time));
39 }
40 openvdb::Vec3i evalVec3i(const char* name, fpreal time) const
41 {
42 using IntT = openvdb::Vec3i::ValueType;
43 return openvdb::Vec3i(static_cast<IntT>(evalInt(name, 0, time)),
44 static_cast<IntT>(evalInt(name, 1, time)),
45 static_cast<IntT>(evalInt(name, 2, time)));
46 }
47 openvdb::Vec2R evalVec2R(const char* name, fpreal time) const
48 {
49 return openvdb::Vec2R(evalFloat(name, 0, time),
50 evalFloat(name, 1, time));
51 }
52 openvdb::Vec2i evalVec2i(const char* name, fpreal time) const
53 {
54 using IntT = openvdb::Vec2i::ValueType;
55 return openvdb::Vec2i(static_cast<IntT>(evalInt(name, 0, time)),
56 static_cast<IntT>(evalInt(name, 1, time)));
57 }
58
59 std::string evalStdString(const char* name, fpreal time, int index = 0) const
60 {
61 UT_String str;
62 evalString(str, name, index, time);
63 return str.toStdString();
64 }
65
66 const GA_PrimitiveGroup *matchGroup(const GU_Detail &gdp, const UT_StringRef &groupname)
67 {
68 const GA_PrimitiveGroup *group = 0;
69 if (groupname.isstring())
70 {
71 bool success = false;
72 group = gop.parseOrderedPrimitiveDetached(groupname, &gdp, false, success);
73 if (!success)
74 {
75 UT_StringHolder error;
76 error = "Invalid group (";
77 error += groupname;
78 error += ")";
79 throw std::runtime_error(error.c_str());
80 }
81 }
82 return group;
83 }
84
85 const GA_PrimitiveGroup *
86 parsePrimitiveGroups(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
87 {
88 return gop.parsePrimitiveGroups(maskStr, maskGeo);
89 }
90
91 GA_PrimitiveGroup *
92 parsePrimitiveGroupsCopy(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
93 {
94 return gop.parsePrimitiveGroupsCopy(maskStr, maskGeo);
95 }
96
97 const GA_PointGroup *
98 parsePointGroups(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
99 {
100 return gop.parsePointGroups(maskStr, maskGeo);
101 }
102
103 const GA_PointGroup *
104 parsePointGroups(const UT_StringRef &maskStr, const GU_Detail *gdp)
105 {
106 return parsePointGroups(maskStr, GroupCreator(gdp));
107 }
108
109protected:
110 OP_ERROR cook(OP_Context &context) override final
111 {
112 auto result = cookMySop(context);
113 gop.destroyAdhocGroups();
114 return result;
115 }
116
117 virtual OP_ERROR cookVDBSop(OP_Context&) = 0;
118 OP_ERROR cookMySop(OP_Context& context) { return cookVDBSop(context); }
119
120 // Handles ad-hoc group creation.
121 GOP_Manager gop;
122}; // class SOP_VDBCacheOptions
123
124#endif // OPENVDB_HOUDINI_SOP_VDBVERBUTILS_HAS_BEEN_INCLUDED
SOP_VDBCacheOptions
SOP_NodeCacheOptions subclass that adds methods specific to SOP_NodeVDB.
Definition: SOP_VDBVerbUtils.h:23
SOP_VDBCacheOptions::evalStdString
std::string evalStdString(const char *name, fpreal time, int index=0) const
Definition: SOP_VDBVerbUtils.h:59
SOP_VDBCacheOptions::~SOP_VDBCacheOptions
~SOP_VDBCacheOptions() override
Definition: SOP_VDBVerbUtils.h:26
SOP_VDBCacheOptions::cook
OP_ERROR cook(OP_Context &context) override final
Definition: SOP_VDBVerbUtils.h:110
SOP_VDBCacheOptions::parsePointGroups
const GA_PointGroup * parsePointGroups(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
Definition: SOP_VDBVerbUtils.h:98
SOP_VDBCacheOptions::evalVec3R
openvdb::Vec3R evalVec3R(const char *name, fpreal time) const
Definition: SOP_VDBVerbUtils.h:34
SOP_VDBCacheOptions::evalVec3f
openvdb::Vec3f evalVec3f(const char *name, fpreal time) const
Definition: SOP_VDBVerbUtils.h:28
SOP_VDBCacheOptions::gop
GOP_Manager gop
Definition: SOP_VDBVerbUtils.h:121
SOP_VDBCacheOptions::SOP_VDBCacheOptions
SOP_VDBCacheOptions()
Definition: SOP_VDBVerbUtils.h:25
SOP_VDBCacheOptions::evalVec2R
openvdb::Vec2R evalVec2R(const char *name, fpreal time) const
Definition: SOP_VDBVerbUtils.h:47
SOP_VDBCacheOptions::parsePrimitiveGroups
const GA_PrimitiveGroup * parsePrimitiveGroups(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
Definition: SOP_VDBVerbUtils.h:86
SOP_VDBCacheOptions::evalVec2i
openvdb::Vec2i evalVec2i(const char *name, fpreal time) const
Definition: SOP_VDBVerbUtils.h:52
SOP_VDBCacheOptions::cookMySop
OP_ERROR cookMySop(OP_Context &context)
Definition: SOP_VDBVerbUtils.h:118
SOP_VDBCacheOptions::parsePrimitiveGroupsCopy
GA_PrimitiveGroup * parsePrimitiveGroupsCopy(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
Definition: SOP_VDBVerbUtils.h:92
SOP_VDBCacheOptions::parsePointGroups
const GA_PointGroup * parsePointGroups(const UT_StringRef &maskStr, const GU_Detail *gdp)
Definition: SOP_VDBVerbUtils.h:104
SOP_VDBCacheOptions::evalVec3i
openvdb::Vec3i evalVec3i(const char *name, fpreal time) const
Definition: SOP_VDBVerbUtils.h:40
SOP_VDBCacheOptions::cookVDBSop
virtual OP_ERROR cookVDBSop(OP_Context &)=0
SOP_VDBCacheOptions::matchGroup
const GA_PrimitiveGroup * matchGroup(const GU_Detail &gdp, const UT_StringRef &groupname)
Definition: SOP_VDBVerbUtils.h:66
openvdb::v9_1::math::Vec2
Definition: Vec2.h:24
openvdb::v9_1::math::Vec3
Definition: Vec3.h:24
openvdb::v9_1::math::Vec2i
Vec2< int32_t > Vec2i
Definition: Vec2.h:534
openvdb::v9_1::math::Vec3i
Vec3< int32_t > Vec3i
Definition: Vec3.h:665
openvdb::v9_1::Vec2R
math::Vec2< Real > Vec2R
Definition: Types.h:63
openvdb::v9_1::Vec3R
math::Vec3< Real > Vec3R
Definition: Types.h:72
Types.h