feat: add grid operator
This commit is contained in:
@@ -66,7 +66,7 @@ enzo::geo::Geometry& enzo::geo::Geometry::operator=(const enzo::geo::Geometry& r
|
||||
return *this;
|
||||
}
|
||||
|
||||
void geo::Geometry::addFace(std::vector<ga::Offset> pointOffsets, bool closed)
|
||||
void geo::Geometry::addFace(const std::vector<ga::Offset>& pointOffsets, bool closed)
|
||||
{
|
||||
const ga::Offset primNum = vertexCountHandlePrim_.getSize();
|
||||
for(ga::Offset pointOffset : pointOffsets)
|
||||
|
||||
@@ -43,7 +43,16 @@ public:
|
||||
|
||||
std::vector<bt::Vector3> derivePointNormals();
|
||||
HeMesh computeHalfEdgeMesh();
|
||||
void addFace(std::vector<ga::Offset> pointOffsets, bool closed=true);
|
||||
|
||||
// build geometry
|
||||
void addFace(const std::vector<ga::Offset>& pointOffsets, bool closed=true);
|
||||
template <typename... Args>
|
||||
void addFace(Args... args)
|
||||
{
|
||||
std::vector<ga::Offset> pointOffsets = { static_cast<ga::Offset>(args)... };
|
||||
addFace(pointOffsets);
|
||||
|
||||
}
|
||||
void addPoint(const bt::Vector3& pos);
|
||||
|
||||
std::set<ga::Offset>::const_iterator soloPointsBegin();
|
||||
|
||||
@@ -24,6 +24,7 @@ add_library(${libName} SHARED
|
||||
GopHouse.cpp
|
||||
GopTestCube.cpp
|
||||
GopGeometryImport.cpp
|
||||
GopGrid.cpp
|
||||
)
|
||||
target_link_libraries(${libName} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb)
|
||||
|
||||
|
||||
65
src/OpDefs/GopGrid.cpp
Normal file
65
src/OpDefs/GopGrid.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "OpDefs/GopGrid.h"
|
||||
#include "Engine/Types.h"
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <oneapi/tbb/parallel_for.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
GopGrid::GopGrid(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
||||
: GeometryOpDef(network, opInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GopGrid::cookOp(enzo::op::Context context)
|
||||
{
|
||||
using namespace enzo;
|
||||
|
||||
if(outputRequested(0))
|
||||
{
|
||||
geo::Geometry geo;
|
||||
bt::floatT width = context.evalFloatParm("width");
|
||||
bt::floatT height = context.evalFloatParm("height");
|
||||
|
||||
const bt::intT columns = context.evalFloatParm("columns");
|
||||
const bt::intT rows = context.evalFloatParm("rows");
|
||||
if(columns==0 || rows==0)
|
||||
{
|
||||
setOutputGeometry(0, geo);
|
||||
return;
|
||||
}
|
||||
|
||||
const bt::floatT centerOffsetX = (columns-1)*width/2.0;
|
||||
const bt::floatT centerOffsetY = (rows-1)*height/2.0;
|
||||
|
||||
for(int i=0;i<columns;i++)
|
||||
{
|
||||
for(int j=0;j<rows;++j)
|
||||
{
|
||||
geo.addPoint(bt::Vector3(i*width-centerOffsetX, sin(i+j), j*height-centerOffsetY));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<std::floor((columns-1)*(rows)-1);i++)
|
||||
{
|
||||
const int endOffset = (i+1)%rows==0;
|
||||
const ga::Offset startPt = i+endOffset;
|
||||
geo.addFace(startPt,startPt+rows,startPt+rows+1,startPt+1);
|
||||
}
|
||||
|
||||
|
||||
setOutputGeometry(0, geo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enzo::prm::Template GopGrid::parameterList[] =
|
||||
{
|
||||
enzo::prm::Template(enzo::prm::Type::FLOAT, "width", enzo::prm::Default(1)),
|
||||
enzo::prm::Template(enzo::prm::Type::FLOAT, "height", enzo::prm::Default(1)),
|
||||
enzo::prm::Template(enzo::prm::Type::FLOAT, "rows", enzo::prm::Default(10)),
|
||||
enzo::prm::Template(enzo::prm::Type::FLOAT, "columns", enzo::prm::Default(10)),
|
||||
enzo::prm::Terminator
|
||||
};
|
||||
18
src/OpDefs/GopGrid.h
Normal file
18
src/OpDefs/GopGrid.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Engine/Operator/GeometryOpDef.h"
|
||||
#include "Engine/Parameter/Template.h"
|
||||
|
||||
class GopGrid
|
||||
: public enzo::nt::GeometryOpDef
|
||||
{
|
||||
public:
|
||||
GopGrid(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
|
||||
virtual void cookOp(enzo::op::Context context);
|
||||
static enzo::nt::GeometryOpDef* ctor(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
|
||||
{
|
||||
return new GopGrid(network, opInfo);
|
||||
}
|
||||
|
||||
static BOOST_SYMBOL_EXPORT enzo::prm::Template parameterList[];
|
||||
|
||||
};
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "GopHouse.h"
|
||||
#include "GopTestCube.h"
|
||||
#include "OpDefs/GopTransform.hpp"
|
||||
#include "OpDefs/GopGrid.h"
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/dll.hpp>
|
||||
|
||||
@@ -55,6 +56,17 @@ extern "C"
|
||||
1,
|
||||
}
|
||||
);
|
||||
addOperator(
|
||||
enzo::op::OpInfo {
|
||||
"grid",
|
||||
"Grid",
|
||||
&GopGrid::ctor,
|
||||
GopGrid::parameterList,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user