Skip to content

Commit

Permalink
refact: rename macro with prefix ZENO_
Browse files Browse the repository at this point in the history
  • Loading branch information
DarcJC committed Aug 9, 2023
1 parent 1a88d2e commit bc2e059
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 73 deletions.
40 changes: 20 additions & 20 deletions projects/Roads/nodes/src/cost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,48 @@ inline void RoadsAssert(const bool Expr, const std::string& InMsg = "[Roads] Ass
}

template <typename GridType = roads::Point>
roads::DynamicGrid<GridType> 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<int>(NxChannel);
const auto Ny = InPrimitive->userData().get2<int>(NyChannel);

RoadsAssert(Nx * Ny <= InPrimitive->verts.size());
roads::DynamicGrid<GridType> BuildGridFromPrimitive(const zeno::AttrVector<zeno::vec3f>& DataSource, int32_t Nx, int32_t Ny) {
RoadsAssert(Nx * Ny <= DataSource.size());

roads::DynamicGrid<GridType> 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<CalcPathCost_Simple> {
GENERATE_NODE_BODY(CalcPathCost_Simple);
ZENO_GENERATE_NODE_BODY(CalcPathCost_Simple);

std::shared_ptr<zeno::PrimitiveObject> 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<vec3f> Test2 {};
BINDING_PRIMITIVE_ATTRIBUTE(Primitive, Test2, "pos", zeno::reflect::EZenoPrimitiveAttr::VERT);
zeno::AttrVector<vec3f> 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);
}
};
}
6 changes: 4 additions & 2 deletions projects/Roads/utilities/include/roads/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace roads {
OBTUSE = 2,
};

struct Point : public Eigen::Vector3d {};
struct Point : public Eigen::Vector3d {
Point(const std::array<float, 3>& InArray) : Eigen::Vector3d(InArray[0], InArray[1], InArray[2]) {}
};

struct Triangle : public std::array<Point, 3> {
bool AnyAngleLargerThan(const double Degree) {
Expand All @@ -41,7 +43,7 @@ namespace roads {
size_t Nx, Ny;

DynamicGrid(const size_t InNx, const size_t InNy) : std::vector<GridPointType>(InNx * InNy), Nx(InNx), Ny(InNy) {}
DynamicGrid(DynamicGrid&& OtherGridToMove) noexcept : std::vector<GridPointType>(std::forward(OtherGridToMove)) {
DynamicGrid(DynamicGrid&& OtherGridToMove) noexcept : std::vector<GridPointType>(std::forward<std::vector<GridPointType>>(OtherGridToMove)) {
Nx = OtherGridToMove.Nx;
Ny = OtherGridToMove.Ny;
}
Expand Down
88 changes: 37 additions & 51 deletions zeno/include/zeno/utils/PropertyVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <type_traits>
#include <utility>
#include <zeno/PrimitiveObject.h>
#include <zeno/types/AttrVector.h>
#include <zeno/core/Descriptor.h>
#include <zeno/types/AttrVector.h>
#include <zeno/types/UserData.h>
#include <zeno/utils/logger.h>
#include <zeno/zeno.h>
Expand Down Expand Up @@ -345,10 +345,10 @@ namespace zeno {

struct IPrimitiveBindingField {
const std::shared_ptr<PrimitiveObject> &Primitive;
const std::string& KeyName;
const std::string &KeyName;
const bool bIsOptional;

IPrimitiveBindingField(std::shared_ptr<PrimitiveObject> &InPrimitive, const std::string& InKeyName, bool bInIsOptional) : Primitive(InPrimitive), KeyName(InKeyName), bIsOptional(bInIsOptional) {}
IPrimitiveBindingField(std::shared_ptr<PrimitiveObject> &InPrimitive, const std::string &InKeyName, bool bInIsOptional) : Primitive(InPrimitive), KeyName(InKeyName), bIsOptional(bInIsOptional) {}
};

template<typename ParentType, typename ValueType>
Expand All @@ -364,15 +364,18 @@ namespace zeno {

std::function<void()> ToCaptured() {
return [this]() {
if (Primitive) {
if constexpr (IsSharedPtr<ValueType>()) {
if (!bIsOptional || Primitive->userData().has<ValueType>(KeyName)) {
ValueRef = Primitive->userData().get<ValueType>(KeyName);
}
} else {
if (!bIsOptional || Primitive->userData().has<ValueType>(KeyName)) {
ValueRef = Primitive->userData().get2<ValueType>(KeyName);
}
if (!Primitive) {
zeno::log_error("Invalid primitive binding.");
return;
}

if constexpr (IsSharedPtr<ValueType>()) {
if (!bIsOptional || Primitive->userData().has<ValueType>(KeyName)) {
ValueRef = Primitive->userData().get<ValueType>(KeyName);
}
} else {
if (!bIsOptional || Primitive->userData().has<ValueType>(KeyName)) {
ValueRef = Primitive->userData().get2<ValueType>(KeyName);
}
}
};
Expand All @@ -392,93 +395,76 @@ namespace zeno {
};

template<typename ParentType, typename ValueType, EZenoPrimitiveAttr AttrType>
struct PrimitiveAttributeBindingField : public IPrimitiveBindingField { /** TODO [darc] : not implemented yet : */ };
struct PrimitiveAttributeBindingField : public IPrimitiveBindingField { /** TODO [darc] : not implemented yet : */
};

template<typename ParentType, typename ValueType, EZenoPrimitiveAttr AttrType>
struct PrimitiveAttributeBindingField<ParentType, zeno::AttrVector<ValueType>, AttrType> : public IPrimitiveBindingField {
using Type = ValueType;
using ArrayType = zeno::AttrVector<ValueType>;
using Parent = std::remove_cv_t<ParentType>;

ArrayType& ArrayRef;
ArrayType &ArrayRef;

PrimitiveAttributeBindingField(Parent &ParentRef, std::shared_ptr<PrimitiveObject> &InPrimitive, ArrayType &InArrayRef, const std::string &InKeyName, bool bIsOptional = false) : IPrimitiveBindingField(InPrimitive, InKeyName, bIsOptional), ArrayRef(InArrayRef) {
ParentRef.HookList.BindingHook.push_back(ToCaptured());
}

std::function<void()> 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<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::POINT)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::POINT) {
if (!bIsOptional || Primitive->points.has_attr(KeyName)) {
ArrayRef = Primitive->points.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::LINE)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::LINE) {
if (!bIsOptional || Primitive->lines.has_attr(KeyName)) {
ArrayRef = Primitive->lines.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::TRIANGLE)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::TRIANGLE) {
if (!bIsOptional || Primitive->tris.has_attr(KeyName)) {
ArrayRef = Primitive->tris.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::QUAD)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::QUAD) {
if (!bIsOptional || Primitive->quads.has_attr(KeyName)) {
ArrayRef = Primitive->quads.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::LOOP)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::LOOP) {
if (!bIsOptional || Primitive->loops.has_attr(KeyName)) {
ArrayRef = Primitive->loops.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::POLY)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::POLY) {
if (!bIsOptional || Primitive->polys.has_attr(KeyName)) {
ArrayRef = Primitive->polys.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::EDGE)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::EDGE) {
if (!bIsOptional || Primitive->edges.has_attr(KeyName)) {
ArrayRef = Primitive->edges.attr<Type>(KeyName);
}
}
else if constexpr (AttrType == EZenoPrimitiveAttr::UV)
{
} else if constexpr (AttrType == EZenoPrimitiveAttr::UV) {
if (!bIsOptional || Primitive->uvs.has_attr(KeyName)) {
ArrayRef = Primitive->uvs.attr<Type>(KeyName);
}
}
};
}
};

};

template<typename T>
reflect::INodeParameterObject<T>::INodeParameterObject(INode *Node) : NodeParameterBase(Node) {
}
}// 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(); \
Expand All @@ -489,15 +475,15 @@ 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(); \
RunBindingHooks(); \
} \
}

#define GENERATE_NODE_BODY(CLS) \
#define ZENO_GENERATE_NODE_BODY(CLS) \
CLS() : zeno::reflect::IParameterAutoNode<CLS>(nullptr) {} \
explicit CLS(INode *Node) : zeno::reflect::IParameterAutoNode<CLS>(Node) { \
if (nullptr != Node) { \
Expand All @@ -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<sizeof(x) - 1>::crc32(x))
#define ZENO_COMPILE_TIME_CRC32_STR(x) (zeno::reflect::MM<sizeof(x) - 1>::crc32(x))

#define DECLARE_FIELD(Type, FieldName, ...) zeno::reflect::Type<ThisType, decltype(FieldName), COMPILE_TIME_CRC32_STR(#FieldName)> 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<ThisType, decltype(FieldName), ZENO_COMPILE_TIME_CRC32_STR(#FieldName)> 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<ThisType, decltype(FieldName)> 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<ThisType, decltype(FieldName), Type> 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<ThisType, decltype(FieldName)> 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<ThisType, decltype(FieldName), Type> Internal##FieldName##Attr##In##PrimitiveName##_Do_not_use{*this, PrimitiveName, FieldName, ChannelName, __VA_ARGS__};

#endif//ZENO_PROPERTYVISITOR_H

0 comments on commit bc2e059

Please sign in to comment.