Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(occara): various improvements and fixes #35

Merged
merged 11 commits into from
Oct 6, 2024
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
- name: Build
run: cargo build --verbose --workspace --all-features
- name: Run tests
run: cargo test --verbose --workspace --all-features
run: cargo test --verbose --workspace --all-features -- --include-ignored
28 changes: 28 additions & 0 deletions crates/occara/cpp/geom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Direction Direction::create(Standard_Real x, Standard_Real y, Standard_Real z) {

Direction Direction::clone() const { return *this; }

void Direction::get_components(Standard_Real &x, Standard_Real &y,
Standard_Real &z) const {
x = direction.X();
y = direction.Y();
z = direction.Z();
}

// Direction2D

Direction2D Direction2D::create(Standard_Real x, Standard_Real y) {
Expand All @@ -62,6 +69,11 @@ Direction2D Direction2D::create(Standard_Real x, Standard_Real y) {

Direction2D Direction2D::clone() const { return *this; }

void Direction2D::get_components(Standard_Real &x, Standard_Real &y) const {
x = direction.X();
y = direction.Y();
}

// Axis

Axis Axis::create(const Point &origin, const Direction &direction) {
Expand All @@ -70,6 +82,10 @@ Axis Axis::create(const Point &origin, const Direction &direction) {

Axis Axis::clone() const { return *this; }

Point Axis::location() const { return Point{axis.Location()}; }

Direction Axis::direction() const { return Direction{axis.Direction()}; }

// Axis2D

Axis2D Axis2D::create(const Point2D &origin, const Direction2D &direction) {
Expand All @@ -78,6 +94,10 @@ Axis2D Axis2D::create(const Point2D &origin, const Direction2D &direction) {

Axis2D Axis2D::clone() const { return *this; }

Point2D Axis2D::location() const { return Point2D{axis.Location()}; }

Direction2D Axis2D::direction() const { return Direction2D{axis.Direction()}; }

// PlaneAxis

PlaneAxis PlaneAxis::create(const Point &origin, const Direction &direction) {
Expand All @@ -86,6 +106,10 @@ PlaneAxis PlaneAxis::create(const Point &origin, const Direction &direction) {

PlaneAxis PlaneAxis::clone() const { return *this; }

Point PlaneAxis::location() const { return Point{axis.Location()}; }

Direction PlaneAxis::direction() const { return Direction{axis.Direction()}; }

// SpaceAxis

SpaceAxis SpaceAxis::create(const Point &origin, const Direction &direction) {
Expand All @@ -94,6 +118,10 @@ SpaceAxis SpaceAxis::create(const Point &origin, const Direction &direction) {

SpaceAxis SpaceAxis::clone() const { return *this; }

Point SpaceAxis::location() const { return Point{axis.Location()}; }

Direction SpaceAxis::direction() const { return Direction{axis.Direction()}; }

// TrimmedCurve

TrimmedCurve TrimmedCurve::arc_of_circle(const Point &p1, const Point &p2,
Expand Down
29 changes: 26 additions & 3 deletions crates/occara/cpp/shape.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "shape.hpp"
#include "BRepAlgoAPI_Common.hxx"
#include "BRepAlgoAPI_Cut.hxx"
#include "BRepAlgoAPI_Fuse.hxx"
#include "BRepPrimAPI_MakeCylinder.hxx"
#include <BRepGProp.hxx>
#include <BRepLib.hxx>
#include <GProp_GProps.hxx>

namespace occara::shape {

Expand Down Expand Up @@ -64,6 +68,14 @@ Shape Shape::fuse(const Shape &other) const {
return Shape{BRepAlgoAPI_Fuse(shape, other.shape).Shape()};
}

Shape Shape::subtract(const Shape &other) const {
return Shape{BRepAlgoAPI_Cut(shape, other.shape).Shape()};
}

Shape Shape::intersect(const Shape &other) const {
return Shape{BRepAlgoAPI_Common(shape, other.shape).Shape()};
}

Shape Shape::cylinder(const occara::geom::PlaneAxis &axis, Standard_Real radius,
Standard_Real height) {
BRepPrimAPI_MakeCylinder cylinder(axis.axis, radius, height);
Expand All @@ -86,7 +98,6 @@ Mesh Shape::mesh() const {

// Perform meshing
BRepMesh_IncrementalMesh mesher(shape, meshParams);
std::cout << "Mesh called\n";

// Collect vertices and indices
std::vector<geom::Point> vertices;
Expand All @@ -95,13 +106,11 @@ Mesh Shape::mesh() const {
TopExp_Explorer faceExplorer(shape, TopAbs_FACE);
for (; faceExplorer.More(); faceExplorer.Next()) {
TopoDS_Face face = TopoDS::Face(faceExplorer.Current());
std::cerr << "Face\n";
TopLoc_Location loc;
Handle(Poly_Triangulation) triangulation =
BRep_Tool::Triangulation(face, loc);

if (triangulation.IsNull()) {
std::cerr << "Triangulation is null for face\n";
continue;
}

Expand All @@ -127,6 +136,20 @@ Mesh Shape::mesh() const {
};
}

ShapeType Shape::shape_type() const {
return static_cast<ShapeType>(shape.ShapeType());
}

Standard_Boolean Shape::is_null() const { return shape.IsNull(); }

Standard_Boolean Shape::is_closed() const { return shape.Closed(); }

Standard_Real Shape::mass() const {
GProp_GProps props;
BRepGProp::VolumeProperties(shape, props);
return props.Mass();
}

// Edge

Edge Edge::from_curve(const occara::geom::TrimmedCurve &curve) {
Expand Down
17 changes: 17 additions & 0 deletions crates/occara/include/geom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,58 @@ struct Direction {

static Direction create(Standard_Real x, Standard_Real y, Standard_Real z);
Direction clone() const;

void get_components(Standard_Real &x, Standard_Real &y,
Standard_Real &z) const;
};

struct Direction2D {
gp_Dir2d direction;

static Direction2D create(Standard_Real x, Standard_Real y);
Direction2D clone() const;

void get_components(Standard_Real &x, Standard_Real &y) const;
};

struct Axis {
gp_Ax1 axis;

static Axis create(const Point &origin, const Direction &direction);
Axis clone() const;

Point location() const;
Direction direction() const;
};

struct Axis2D {
gp_Ax2d axis;

static Axis2D create(const Point2D &origin, const Direction2D &direction);
Axis2D clone() const;

Point2D location() const;
Direction2D direction() const;
};

struct PlaneAxis {
gp_Ax2 axis;

static PlaneAxis create(const Point &origin, const Direction &direction);
PlaneAxis clone() const;

Point location() const;
Direction direction() const;
};

struct SpaceAxis {
gp_Ax3 axis;

static SpaceAxis create(const Point &origin, const Direction &direction);
SpaceAxis clone() const;

Point location() const;
Direction direction() const;
};

struct TrimmedCurve {
Expand Down
19 changes: 19 additions & 0 deletions crates/occara/include/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,35 @@ struct ShellBuilder {
Shape build();
};

// This is equal to TopAbs_ShapeEnum
enum class ShapeType {
Compound,
CompoundSolid,
Solid,
Shell,
Face,
Wire,
Edge,
Vertex,
Shape
};

struct Shape {
TopoDS_Shape shape;

Shape clone() const;

FilletBuilder fillet() const;
Shape fuse(const Shape &other) const;
Shape subtract(const Shape &other) const;
Shape intersect(const Shape &other) const;
static Shape cylinder(const occara::geom::PlaneAxis &axis,
Standard_Real radius, Standard_Real height);
Mesh mesh() const;
ShapeType shape_type() const;
Standard_Boolean is_null() const;
Standard_Boolean is_closed() const;
Standard_Real mass() const;
};

struct Edge {
Expand Down
Loading
Loading