From bc2e05967175354b49ab7315eef2623365670f8c Mon Sep 17 00:00:00 2001 From: DarcJC Date: Wed, 9 Aug 2023 17:06:17 +0800 Subject: [PATCH] refact: rename macro with prefix ZENO_ --- projects/Roads/nodes/src/cost.cpp | 40 ++++----- projects/Roads/utilities/include/roads/data.h | 6 +- zeno/include/zeno/utils/PropertyVisitor.h | 88 ++++++++----------- 3 files changed, 61 insertions(+), 73 deletions(-) diff --git a/projects/Roads/nodes/src/cost.cpp b/projects/Roads/nodes/src/cost.cpp index 20f06a14d2..73261c2fab 100644 --- a/projects/Roads/nodes/src/cost.cpp +++ b/projects/Roads/nodes/src/cost.cpp @@ -13,48 +13,48 @@ inline void RoadsAssert(const bool Expr, const std::string& InMsg = "[Roads] Ass } template -roads::DynamicGrid BuildGridFromPrimitive(zeno::PrimitiveObject* InPrimitive, const std::string& NxChannel, const std::string& NyChannel) { - RoadsAssert(nullptr != InPrimitive, "[Roads] InPrimitive shouldn't be nullptr !"); - - const auto Nx = InPrimitive->userData().get2(NxChannel); - const auto Ny = InPrimitive->userData().get2(NyChannel); - - RoadsAssert(Nx * Ny <= InPrimitive->verts.size()); +roads::DynamicGrid BuildGridFromPrimitive(const zeno::AttrVector& DataSource, int32_t Nx, int32_t Ny) { + RoadsAssert(Nx * Ny <= DataSource.size()); roads::DynamicGrid Grid(Nx, Ny); for (size_t i = 0; i < Nx * Ny; ++i) { - Grid[i] = InPrimitive->verts[i]; + Grid[i] = roads::Point { DataSource[i][0], DataSource[i][0], DataSource[i][0] }; } + + return Grid; } namespace { using namespace zeno; struct CalcPathCost_Simple : public zeno::reflect::IParameterAutoNode { - GENERATE_NODE_BODY(CalcPathCost_Simple); + ZENO_GENERATE_NODE_BODY(CalcPathCost_Simple); std::shared_ptr Primitive; - DECLARE_INPUT_FIELD(Primitive, "Prim"); - DECLARE_OUTPUT_FIELD(Primitive, "Prim"); + ZENO_DECLARE_INPUT_FIELD(Primitive, "Prim"); + ZENO_DECLARE_OUTPUT_FIELD(Primitive, "Prim"); std::string OutputChannel; - DECLARE_INPUT_FIELD(OutputChannel, "OutputChannel", false, "", "path_cost"); + ZENO_DECLARE_INPUT_FIELD(OutputChannel, "OutputChannel", false, "", "path_cost"); std::string SizeXChannel; - DECLARE_INPUT_FIELD(SizeXChannel, "UserData_NxChannel", false, "", "nx"); + ZENO_DECLARE_INPUT_FIELD(SizeXChannel, "UserData_NxChannel", false, "", "nx"); std::string SizeYChannel; - DECLARE_INPUT_FIELD(SizeYChannel, "UserData_NyChannel", false, "", "ny"); + ZENO_DECLARE_INPUT_FIELD(SizeYChannel, "UserData_NyChannel", false, "", "ny"); + + int Nx = 0; + ZENO_BINDING_PRIMITIVE_USERDATA(Primitive, Nx, SizeXChannel, false); - int Nx = 1; - BINDING_PRIMITIVE_USERDATA(Primitive, Nx, SizeXChannel, true); + int Ny = 0; + ZENO_BINDING_PRIMITIVE_USERDATA(Primitive, Ny, SizeYChannel, false); - zeno::AttrVector Test2 {}; - BINDING_PRIMITIVE_ATTRIBUTE(Primitive, Test2, "pos", zeno::reflect::EZenoPrimitiveAttr::VERT); + zeno::AttrVector PositionList {}; + ZENO_BINDING_PRIMITIVE_ATTRIBUTE(Primitive, PositionList, "pos", zeno::reflect::EZenoPrimitiveAttr::VERT); void apply() override { - zeno::log_info("aaaa: {}", AutoParameter->Nx); - zeno::log_info("bbbb: {}", AutoParameter->Test2.size()); +// BuildGridFromPrimitive(PositionList, Nx, Ny); + zeno::log_info("aaa: {} {}", AutoParameter->Nx, AutoParameter->Ny); } }; } diff --git a/projects/Roads/utilities/include/roads/data.h b/projects/Roads/utilities/include/roads/data.h index 795e8c0cba..3168ef99b9 100644 --- a/projects/Roads/utilities/include/roads/data.h +++ b/projects/Roads/utilities/include/roads/data.h @@ -15,7 +15,9 @@ namespace roads { OBTUSE = 2, }; - struct Point : public Eigen::Vector3d {}; + struct Point : public Eigen::Vector3d { + Point(const std::array& InArray) : Eigen::Vector3d(InArray[0], InArray[1], InArray[2]) {} + }; struct Triangle : public std::array { bool AnyAngleLargerThan(const double Degree) { @@ -41,7 +43,7 @@ namespace roads { size_t Nx, Ny; DynamicGrid(const size_t InNx, const size_t InNy) : std::vector(InNx * InNy), Nx(InNx), Ny(InNy) {} - DynamicGrid(DynamicGrid&& OtherGridToMove) noexcept : std::vector(std::forward(OtherGridToMove)) { + DynamicGrid(DynamicGrid&& OtherGridToMove) noexcept : std::vector(std::forward>(OtherGridToMove)) { Nx = OtherGridToMove.Nx; Ny = OtherGridToMove.Ny; } diff --git a/zeno/include/zeno/utils/PropertyVisitor.h b/zeno/include/zeno/utils/PropertyVisitor.h index f1e9b9d9fb..2a5d74c0e0 100644 --- a/zeno/include/zeno/utils/PropertyVisitor.h +++ b/zeno/include/zeno/utils/PropertyVisitor.h @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -345,10 +345,10 @@ namespace zeno { struct IPrimitiveBindingField { const std::shared_ptr &Primitive; - const std::string& KeyName; + const std::string &KeyName; const bool bIsOptional; - IPrimitiveBindingField(std::shared_ptr &InPrimitive, const std::string& InKeyName, bool bInIsOptional) : Primitive(InPrimitive), KeyName(InKeyName), bIsOptional(bInIsOptional) {} + IPrimitiveBindingField(std::shared_ptr &InPrimitive, const std::string &InKeyName, bool bInIsOptional) : Primitive(InPrimitive), KeyName(InKeyName), bIsOptional(bInIsOptional) {} }; template @@ -364,15 +364,18 @@ namespace zeno { std::function ToCaptured() { return [this]() { - if (Primitive) { - if constexpr (IsSharedPtr()) { - if (!bIsOptional || Primitive->userData().has(KeyName)) { - ValueRef = Primitive->userData().get(KeyName); - } - } else { - if (!bIsOptional || Primitive->userData().has(KeyName)) { - ValueRef = Primitive->userData().get2(KeyName); - } + if (!Primitive) { + zeno::log_error("Invalid primitive binding."); + return; + } + + if constexpr (IsSharedPtr()) { + if (!bIsOptional || Primitive->userData().has(KeyName)) { + ValueRef = Primitive->userData().get(KeyName); + } + } else { + if (!bIsOptional || Primitive->userData().has(KeyName)) { + ValueRef = Primitive->userData().get2(KeyName); } } }; @@ -392,7 +395,8 @@ namespace zeno { }; template - struct PrimitiveAttributeBindingField : public IPrimitiveBindingField { /** TODO [darc] : not implemented yet : */ }; + struct PrimitiveAttributeBindingField : public IPrimitiveBindingField { /** TODO [darc] : not implemented yet : */ + }; template struct PrimitiveAttributeBindingField, AttrType> : public IPrimitiveBindingField { @@ -400,69 +404,52 @@ namespace zeno { using ArrayType = zeno::AttrVector; using Parent = std::remove_cv_t; - ArrayType& ArrayRef; + ArrayType &ArrayRef; PrimitiveAttributeBindingField(Parent &ParentRef, std::shared_ptr &InPrimitive, ArrayType &InArrayRef, const std::string &InKeyName, bool bIsOptional = false) : IPrimitiveBindingField(InPrimitive, InKeyName, bIsOptional), ArrayRef(InArrayRef) { ParentRef.HookList.BindingHook.push_back(ToCaptured()); } std::function ToCaptured() { - return [this] () { + return [this]() { if (!Primitive) { zeno::log_error("Invalid primitive binding."); return; } - if constexpr (AttrType == EZenoPrimitiveAttr::VERT) - { + if constexpr (AttrType == EZenoPrimitiveAttr::VERT) { if (!bIsOptional || Primitive->verts.has_attr(KeyName)) { ArrayRef = Primitive->verts.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::POINT) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::POINT) { if (!bIsOptional || Primitive->points.has_attr(KeyName)) { ArrayRef = Primitive->points.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::LINE) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::LINE) { if (!bIsOptional || Primitive->lines.has_attr(KeyName)) { ArrayRef = Primitive->lines.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::TRIANGLE) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::TRIANGLE) { if (!bIsOptional || Primitive->tris.has_attr(KeyName)) { ArrayRef = Primitive->tris.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::QUAD) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::QUAD) { if (!bIsOptional || Primitive->quads.has_attr(KeyName)) { ArrayRef = Primitive->quads.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::LOOP) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::LOOP) { if (!bIsOptional || Primitive->loops.has_attr(KeyName)) { ArrayRef = Primitive->loops.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::POLY) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::POLY) { if (!bIsOptional || Primitive->polys.has_attr(KeyName)) { ArrayRef = Primitive->polys.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::EDGE) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::EDGE) { if (!bIsOptional || Primitive->edges.has_attr(KeyName)) { ArrayRef = Primitive->edges.attr(KeyName); } - } - else if constexpr (AttrType == EZenoPrimitiveAttr::UV) - { + } else if constexpr (AttrType == EZenoPrimitiveAttr::UV) { if (!bIsOptional || Primitive->uvs.has_attr(KeyName)) { ArrayRef = Primitive->uvs.attr(KeyName); } @@ -470,7 +457,6 @@ namespace zeno { }; } }; - }; template @@ -478,7 +464,7 @@ namespace zeno { } }// namespace zeno -#define GENERATE_AUTONODE_BODY(CLS) \ +#define ZENO_GENERATE_AUTONODE_BODY(CLS) \ inline static struct R_Do_not_use { \ R_Do_not_use() { \ const ParamType &PDO = ParamType::GetDefaultObject(); \ @@ -489,7 +475,7 @@ namespace zeno { } \ } AutoStaticRegisterInstance_Do_not_use; -#define GENERATE_PARAMETER_BODY(CLS) \ +#define ZENO_GENERATE_PARAMETER_BODY(CLS) \ explicit CLS(INode *Node) : Super(Node) { \ if (nullptr != Node) { \ RunInputHooks(); \ @@ -497,7 +483,7 @@ namespace zeno { } \ } -#define GENERATE_NODE_BODY(CLS) \ +#define ZENO_GENERATE_NODE_BODY(CLS) \ CLS() : zeno::reflect::IParameterAutoNode(nullptr) {} \ explicit CLS(INode *Node) : zeno::reflect::IParameterAutoNode(Node) { \ if (nullptr != Node) { \ @@ -516,13 +502,13 @@ namespace zeno { } AutoStaticRegisterInstance_Do_not_use; // This don't take into account the nul char -#define COMPILE_TIME_CRC32_STR(x) (zeno::reflect::MM::crc32(x)) +#define ZENO_COMPILE_TIME_CRC32_STR(x) (zeno::reflect::MM::crc32(x)) -#define DECLARE_FIELD(Type, FieldName, ...) zeno::reflect::Type FieldName##Type##_Do_not_use{*this, FieldName, __VA_ARGS__}; -#define DECLARE_INPUT_FIELD(FieldName, KeyName, ...) DECLARE_FIELD(InputField, FieldName, KeyName, __VA_ARGS__) -#define DECLARE_OUTPUT_FIELD(FieldName, KeyName, ...) DECLARE_FIELD(OutputField, FieldName, KeyName, __VA_ARGS__) +#define ZENO_DECLARE_FIELD(Type, FieldName, ...) zeno::reflect::Type FieldName##Type##_Do_not_use{*this, FieldName, __VA_ARGS__}; +#define ZENO_DECLARE_INPUT_FIELD(FieldName, KeyName, ...) ZENO_DECLARE_FIELD(InputField, FieldName, KeyName, __VA_ARGS__) +#define ZENO_DECLARE_OUTPUT_FIELD(FieldName, KeyName, ...) ZENO_DECLARE_FIELD(OutputField, FieldName, KeyName, __VA_ARGS__) -#define BINDING_PRIMITIVE_USERDATA(PrimitiveName, FieldName, ChannelName, ...) zeno::reflect::PrimitiveUserDataBindingField Internal##FieldName##BindingWith##PrimitiveName##ChannelName##_Do_not_use { *this, PrimitiveName, FieldName, ChannelName, __VA_ARGS__ }; -#define BINDING_PRIMITIVE_ATTRIBUTE(PrimitiveName, FieldName, ChannelName, Type, ...) zeno::reflect::PrimitiveAttributeBindingField Internal##FieldName##Attr##In##PrimitiveName##_Do_not_use { *this, PrimitiveName, FieldName, ChannelName, __VA_ARGS__ }; +#define ZENO_BINDING_PRIMITIVE_USERDATA(PrimitiveName, FieldName, ChannelName, ...) zeno::reflect::PrimitiveUserDataBindingField Internal##FieldName##BindingWith##PrimitiveName##ChannelName##_Do_not_use{*this, PrimitiveName, FieldName, ChannelName, __VA_ARGS__}; +#define ZENO_BINDING_PRIMITIVE_ATTRIBUTE(PrimitiveName, FieldName, ChannelName, Type, ...) zeno::reflect::PrimitiveAttributeBindingField Internal##FieldName##Attr##In##PrimitiveName##_Do_not_use{*this, PrimitiveName, FieldName, ChannelName, __VA_ARGS__}; #endif//ZENO_PROPERTYVISITOR_H