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

[occ][brep] add getshape overload for hollow cyl

parent dbc8e809
......@@ -27,6 +27,7 @@
#ifndef FRACKIT_BREP_UTILITIES_HH
#define FRACKIT_BREP_UTILITIES_HH
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdexcept>
......@@ -39,6 +40,9 @@
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Elips.hxx>
#include <gp_Trsf.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
// shape classes from TopoDS package
#include <TopoDS.hxx>
......@@ -77,6 +81,8 @@
// BRep primitives and operations
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
// internal geometry classes
......@@ -88,6 +94,7 @@
#include <frackit/geometry/quadrilateral.hh>
#include <frackit/geometry/polygon.hh>
#include <frackit/geometry/cylinder.hh>
#include <frackit/geometry/hollowcylinder.hh>
#include <frackit/geometry/cylindersurface.hh>
#include <frackit/geometry/box.hh>
#include <frackit/geometry/boundingbox.hh>
......@@ -171,49 +178,6 @@ namespace OCCUtilities {
TopoDS_Edge getShape(const Segment<ctype, worldDim>& segment)
{ return makeEdge(segment.source(), segment.target()); }
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a cylinder.
*/
template<class ctype>
TopoDS_Solid getShape(const Cylinder<ctype>& cylinder)
{
const auto& lateral = cylinder.lateralFace();
const auto& bottom = lateral.lowerBoundingCircle();
auto axis = direction(bottom.normal());
auto base1 = direction(bottom.base1());
auto center = point(bottom.center());
BRepPrimAPI_MakeCylinder makeCylinder(gp_Ax2(center, axis, base1),
bottom.radius(),
lateral.height(),
2.0*M_PI);
makeCylinder.Build();
if (!makeCylinder.IsDone())
throw std::runtime_error("Could not build cylinder");
return TopoDS::Solid(makeCylinder.Shape());
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a cylinder surface.
*/
template<class ctype>
TopoDS_Face getShape(const CylinderSurface<ctype>& cylSurface)
{
const auto& bottom = cylSurface.lowerBoundingCircle();
auto axis = direction(bottom.normal());
auto base1 = direction(bottom.base1());
auto center = point(bottom.center());
BRepPrimAPI_MakeCylinder makeCylinder(gp_Ax2(center, axis, base1),
bottom.radius(),
cylSurface.height(),
2.0*M_PI);
makeCylinder.Build();
if (!makeCylinder.IsDone())
throw std::runtime_error("Could not build cylinder");
return makeCylinder.Cylinder().LateralFace();
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of an ellipse in 3d space.
......@@ -321,6 +285,27 @@ namespace OCCUtilities {
return BRepBuilderAPI_MakeFace(wire);
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a cylinder surface.
*/
template<class ctype>
TopoDS_Face getShape(const CylinderSurface<ctype>& cylSurface)
{
const auto& bottom = cylSurface.lowerBoundingCircle();
auto axis = direction(bottom.normal());
auto base1 = direction(bottom.base1());
auto center = point(bottom.center());
BRepPrimAPI_MakeCylinder makeCylinder(gp_Ax2(center, axis, base1),
bottom.radius(),
cylSurface.height(),
2.0*M_PI);
makeCylinder.Build();
if (!makeCylinder.IsDone())
throw std::runtime_error("Could not build cylinder");
return makeCylinder.Cylinder().LateralFace();
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a box.
......@@ -355,6 +340,59 @@ namespace OCCUtilities {
return TopoDS::Solid(makeBox.Shape());
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a cylinder.
*/
template<class ctype>
TopoDS_Solid getShape(const Cylinder<ctype>& cylinder)
{
const auto& lateral = cylinder.lateralFace();
const auto& bottom = lateral.lowerBoundingCircle();
auto axis = direction(bottom.normal());
auto base1 = direction(bottom.base1());
auto center = point(bottom.center());
BRepPrimAPI_MakeCylinder makeCylinder(gp_Ax2(center, axis, base1),
bottom.radius(),
lateral.height(),
2.0*M_PI);
makeCylinder.Build();
if (!makeCylinder.IsDone())
throw std::runtime_error("Could not build cylinder");
return TopoDS::Solid(makeCylinder.Shape());
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a hollow cylinder.
*/
template<class ctype>
TopoDS_Solid getShape(const HollowCylinder<ctype>& hollowCyl)
{
const auto bottomCenter = hollowCyl.bottomInnerCircle().center();
auto p1 = bottomCenter; p1 += hollowCyl.base1()*hollowCyl.innerRadius();
auto p2 = p1; p2 += hollowCyl.base1()*(hollowCyl.outerRadius() - hollowCyl.innerRadius());
// make side segment and rotate around axis
const auto& segShape = getShape(Segment<ctype, 3>{p1, p2});
const gp_Ax1 cylAxis(point(bottomCenter), direction(hollowCyl.axis()));
BRepPrimAPI_MakeRevol makeBottom(segShape, cylAxis, 2.0*M_PI);
makeBottom.Build();
if (!makeBottom.IsDone())
throw std::runtime_error("Could not build hollow cylinder bottom");
const auto& bottomShape = makeBottom.Shape();
// extrude bottom
const auto& cylAxisSeg = hollowCyl.centerSegment();
const auto& v = vector(Vector<ctype, 3>{cylAxisSeg.source(), cylAxisSeg.target()});
BRepPrimAPI_MakePrism makeExtrusion(bottomShape, v);
makeExtrusion.Build();
if (!makeExtrusion.IsDone())
throw std::runtime_error("Could not extrude hollow cylinder bottom");
return TopoDS::Solid(makeExtrusion.Shape());
}
/*!
* \ingroup OpenCascade
* \brief Get the BRep of a sphere.
......
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