hyporo-cpp/source/hpr/csg/shell.hpp

62 lines
1.2 KiB
C++
Raw Normal View History

2023-03-13 22:27:09 +05:00
#pragma once
#include <hpr/csg/shape.hpp>
#include <hpr/csg/face.hpp>
namespace hpr::csg
{
class Shell : public Shape
{
public:
Shell() = default;
~Shell() override = default;
explicit
Shell(const Shape& shape) :
Shape {shape.type() == Type::Shell ? shape : throw std::runtime_error("")}
{}
explicit
2023-04-10 22:01:56 +05:00
Shell(const darray<Face>& faces) :
2023-03-13 22:27:09 +05:00
Shape {}
{
BRep_Builder builder;
TopoDS_Shell shell;
builder.MakeShell(shell);
for (auto& shape : faces)
switch (shape.type())
{
case Type::Face:
builder.Add(shell, Face(shape).tcast());
break;
default:
throw std::runtime_error("");
}
p_shape = shell;
}
[[nodiscard]]
TopoDS_Shell tcast() const
{
return TopoDS::Shell(p_shape);
}
2023-04-10 22:01:56 +05:00
static
Shell sew(const darray<Face>& faces)
{
BRepBuilderAPI_Sewing builder;
for (const auto& face : faces)
builder.Add(face.tshape());
builder.Perform();
return Shell(builder.SewedShape());
}
2023-03-13 22:27:09 +05:00
};
}