Loading...
Searching...
No Matches
SOP_VDBVerbUtils.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
/*
* Copyright (c)
* Side Effects Software Inc. All rights reserved.
*/
#ifndef OPENVDB_HOUDINI_SOP_VDBVERBUTILS_HAS_BEEN_INCLUDED
#define OPENVDB_HOUDINI_SOP_VDBVERBUTILS_HAS_BEEN_INCLUDED
#include <GOP/GOP_Manager.h>
#include <SOP/SOP_NodeParmsOptions.h> // for SOP_NodeCacheOptions
#include <openvdb/Types.h>
#include <string>
////////////////////////////////////////
/// @brief SOP_NodeCacheOptions subclass that adds methods specific to SOP_NodeVDB
class SOP_VDBCacheOptions: public SOP_NodeCacheOptions
{
public:
SOP_VDBCacheOptions() {}
~SOP_VDBCacheOptions() override {}
openvdb::Vec3f evalVec3f(const char* name, fpreal time) const
{
return openvdb::Vec3f(static_cast<float>(evalFloat(name, 0, time)),
static_cast<float>(evalFloat(name, 1, time)),
static_cast<float>(evalFloat(name, 2, time)));
}
openvdb::Vec3R evalVec3R(const char* name, fpreal time) const
{
return openvdb::Vec3R(evalFloat(name, 0, time),
evalFloat(name, 1, time),
evalFloat(name, 2, time));
}
openvdb::Vec3i evalVec3i(const char* name, fpreal time) const
{
using IntT = openvdb::Vec3i::ValueType;
return openvdb::Vec3i(static_cast<IntT>(evalInt(name, 0, time)),
static_cast<IntT>(evalInt(name, 1, time)),
static_cast<IntT>(evalInt(name, 2, time)));
}
openvdb::Vec2R evalVec2R(const char* name, fpreal time) const
{
return openvdb::Vec2R(evalFloat(name, 0, time),
evalFloat(name, 1, time));
}
openvdb::Vec2i evalVec2i(const char* name, fpreal time) const
{
using IntT = openvdb::Vec2i::ValueType;
return openvdb::Vec2i(static_cast<IntT>(evalInt(name, 0, time)),
static_cast<IntT>(evalInt(name, 1, time)));
}
std::string evalStdString(const char* name, fpreal time, int index = 0) const
{
UT_String str;
evalString(str, name, index, time);
return str.toStdString();
}
const GA_PrimitiveGroup *matchGroup(const GU_Detail &gdp, const UT_StringRef &groupname)
{
const GA_PrimitiveGroup *group = 0;
if (groupname.isstring())
{
bool success = false;
group = gop.parseOrderedPrimitiveDetached(groupname, &gdp, false, success);
if (!success)
{
UT_StringHolder error;
error = "Invalid group (";
error += groupname;
error += ")";
throw std::runtime_error(error.c_str());
}
}
return group;
}
const GA_PrimitiveGroup *
parsePrimitiveGroups(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
{
return gop.parsePrimitiveGroups(maskStr, maskGeo);
}
GA_PrimitiveGroup *
parsePrimitiveGroupsCopy(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
{
return gop.parsePrimitiveGroupsCopy(maskStr, maskGeo);
}
const GA_PointGroup *
parsePointGroups(const UT_StringRef &maskStr, const GroupCreator &maskGeo)
{
return gop.parsePointGroups(maskStr, maskGeo);
}
const GA_PointGroup *
parsePointGroups(const UT_StringRef &maskStr, const GU_Detail *gdp)
{
return parsePointGroups(maskStr, GroupCreator(gdp));
}
protected:
OP_ERROR cook(OP_Context &context) override final
{
auto result = cookMySop(context);
gop.destroyAdhocGroups();
return result;
}
virtual OP_ERROR cookVDBSop(OP_Context&) = 0;
OP_ERROR cookMySop(OP_Context& context) { return cookVDBSop(context); }
// Handles ad-hoc group creation.
GOP_Manager gop;
}; // class SOP_VDBCacheOptions
#endif // OPENVDB_HOUDINI_SOP_VDBVERBUTILS_HAS_BEEN_INCLUDED
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::v10_0::math::Vec2< int32_t >::ValueType
int32_t ValueType
Definition Vec2.h:27
openvdb::v10_0::math::Vec3< int32_t >::ValueType
int32_t ValueType
Definition Vec3.h:27
openvdb::v10_0::math::Vec2i
Vec2< int32_t > Vec2i
Definition Vec2.h:530
openvdb::v10_0::math::Vec3i
Vec3< int32_t > Vec3i
Definition Vec3.h:661
openvdb::v10_0::Vec2R
math::Vec2< Real > Vec2R
Definition Types.h:63
openvdb::v10_0::Vec3f
math::Vec3< float > Vec3f
Definition Types.h:74
openvdb::v10_0::Vec3R
math::Vec3< Real > Vec3R
Definition Types.h:72
Types.h