Commit 6a2965a1 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[python][occ] add getter functions for sub-shapes

parent 04ba796e
......@@ -19,9 +19,13 @@
#ifndef FRACKIT_PYTHON_BREP_UTILITIES_HH
#define FRACKIT_PYTHON_BREP_UTILITIES_HH
#include <vector>
#include <string>
#include <type_traits>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <BRepTools.hxx>
#include <frackit/geometry/point.hh>
......@@ -53,6 +57,84 @@ namespace OCCUtilities {
return WrapperType(Frackit::OCCUtilities::getShape(geometry));
}
template<class ShapeWrapper>
std::vector<VertexWrapper> getVertices(const ShapeWrapper& wrappedShape)
{
auto vertices = Frackit::OCCUtilities::getVertices(wrappedShape.get());
std::vector< VertexWrapper > result;
result.reserve(vertices.size());
for (auto& v : vertices)
result.emplace_back( std::move(v) );
return result;
}
template<class ShapeWrapper>
std::vector<EdgeWrapper> getEdges(const ShapeWrapper& wrappedShape)
{
auto edges = Frackit::OCCUtilities::getEdges(wrappedShape.get());
std::vector< EdgeWrapper > result;
result.reserve(edges.size());
for (auto& e : edges)
result.emplace_back( std::move(e) );
return result;
}
template<class ShapeWrapper>
std::vector<FaceWrapper> getFaces(const ShapeWrapper& wrappedShape)
{
auto faces = Frackit::OCCUtilities::getFaces(wrappedShape.get());
std::vector< FaceWrapper > result;
result.reserve(faces.size());
for (auto& f : faces)
result.emplace_back( std::move(f) );
return result;
}
template<class ShapeWrapper>
std::vector<WireWrapper> getWires(const ShapeWrapper& wrappedShape)
{
auto wires = Frackit::OCCUtilities::getWires(wrappedShape.get());
std::vector< WireWrapper > result;
result.reserve(wires.size());
for (auto& w : wires)
result.emplace_back( std::move(w) );
return result;
}
template<class ShapeWrapper>
std::vector<ShellWrapper> getShells(const ShapeWrapper& wrappedShape)
{
auto shells = Frackit::OCCUtilities::getShells(wrappedShape.get());
std::vector< ShellWrapper > result;
result.reserve(shells.size());
for (auto& s : shells)
result.emplace_back( std::move(s) );
return result;
}
template<class ShapeWrapper>
std::vector<SolidWrapper> getSolids(const ShapeWrapper& wrappedShape)
{
auto solids = Frackit::OCCUtilities::getSolids(wrappedShape.get());
std::vector< SolidWrapper > result;
result.reserve(solids.size());
for (auto& s : solids)
result.emplace_back( std::move(s) );
return result;
}
ShapeWrapper readShape(const std::string& fileName)
{ return ShapeWrapper(Frackit::OCCUtilities::readShape(fileName)); }
......@@ -64,6 +146,53 @@ namespace OCCUtilities {
} // end namespace OCCUtilities
namespace Detail {
void registerSubShapeGetterFunctions(pybind11::module& module)
{
using namespace Frackit::Python::OCCUtilities;
module.def("getVertices", &getVertices<ShapeWrapper>, "returns the vertices of a wrapped shape");
module.def("getVertices", &getVertices<VertexWrapper>, "returns the vertices of a wrapped vertex");
module.def("getVertices", &getVertices<EdgeWrapper>, "returns the vertices of a wrapped edge");
module.def("getVertices", &getVertices<WireWrapper>, "returns the vertices of a wrapped wire");
module.def("getVertices", &getVertices<FaceWrapper>, "returns the vertices of a wrapped face");
module.def("getVertices", &getVertices<ShellWrapper>, "returns the vertices of a wrapped shell");
module.def("getVertices", &getVertices<SolidWrapper>, "returns the vertices of a wrapped solid");
module.def("getVertices", &getVertices<CompoundWrapper>, "returns the vertices of a wrapped compound");
module.def("getEdges", &getEdges<ShapeWrapper>, "returns the edges of a wrapped shape");
module.def("getEdges", &getEdges<EdgeWrapper>, "returns the edges of a wrapped edge");
module.def("getEdges", &getEdges<WireWrapper>, "returns the edges of a wrapped wire");
module.def("getEdges", &getEdges<FaceWrapper>, "returns the edges of a wrapped face");
module.def("getEdges", &getEdges<ShellWrapper>, "returns the edges of a wrapped shell");
module.def("getEdges", &getEdges<SolidWrapper>, "returns the edges of a wrapped solid");
module.def("getEdges", &getEdges<CompoundWrapper>, "returns the edges of a wrapped compound");
module.def("getWires", &getWires<ShapeWrapper>, "returns the wires of a wrapped shape");
module.def("getWires", &getWires<WireWrapper>, "returns the wires of a wrapped wire");
module.def("getWires", &getWires<FaceWrapper>, "returns the wires of a wrapped face");
module.def("getWires", &getWires<ShellWrapper>, "returns the wires of a wrapped shell");
module.def("getWires", &getWires<SolidWrapper>, "returns the wires of a wrapped solid");
module.def("getWires", &getWires<CompoundWrapper>, "returns the wires of a wrapped compound");
module.def("getFaces", &getFaces<ShapeWrapper>, "returns the faces of a wrapped shape");
module.def("getFaces", &getFaces<FaceWrapper>, "returns the faces of a wrapped face");
module.def("getFaces", &getFaces<ShellWrapper>, "returns the faces of a wrapped shell");
module.def("getFaces", &getFaces<SolidWrapper>, "returns the faces of a wrapped solid");
module.def("getFaces", &getFaces<CompoundWrapper>, "returns the faces of a wrapped compound");
module.def("getShells", &getShells<ShapeWrapper>, "returns the shells of a wrapped shape");
module.def("getShells", &getShells<ShellWrapper>, "returns the shells of a wrapped shell");
module.def("getShells", &getShells<SolidWrapper>, "returns the shells of a wrapped solid");
module.def("getShells", &getShells<CompoundWrapper>, "returns the shells of a wrapped compound");
module.def("getSolids", &getSolids<ShapeWrapper>, "returns the solids of a wrapped shape");
module.def("getSolids", &getSolids<SolidWrapper>, "returns the solids of a wrapped solid");
module.def("getSolids", &getSolids<CompoundWrapper>, "returns the solids of a wrapped compound");
}
} // end namespace Detail
template<class ctype>
void registerBRepUtilities(pybind11::module& module)
{
......@@ -93,6 +222,9 @@ void registerBRepUtilities(pybind11::module& module)
module.def("getShape", &OCCUtilities::getShape<Cylinder<ctype>>, "Returns the OCC BRep of a cylinder");
module.def("getShape", &OCCUtilities::getShape<CylinderSurface<ctype>>, "Returns the OCC BRep of the lateral surface of a cylinder");
// register getter functions for (sub-)shapes of a wrapped shape
Detail::registerSubShapeGetterFunctions(module);
// register read-in of shapes from a file
module.def("readShape", &OCCUtilities::readShape, "Reads in the shapes from a file");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment