Skip to content

Commit

Permalink
Revert "adding inner and outer offsets"
Browse files Browse the repository at this point in the history
This reverts commit 4310a02.
  • Loading branch information
romanarust committed Jul 5, 2024
1 parent 4310a02 commit 7a232fe
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 139 deletions.
36 changes: 0 additions & 36 deletions docs/examples/straight_skeleton_offset.py

This file was deleted.

15 changes: 0 additions & 15 deletions src/compas_cgal/straight_skeleton_2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
from compas.geometry import normal_polygon
from compas.geometry import Polygon
from compas.tolerance import TOL

from compas_cgal._cgal import straight_skeleton_2
Expand Down Expand Up @@ -67,17 +66,3 @@ def create_interior_straight_skeleton_with_holes(points, holes) -> PolylinesNump
hole = np.asarray(points, dtype=np.float64)
H.append(hole)
return straight_skeleton_2.create_interior_straight_skeleton_with_holes(V, H)


def create_offset_polygons_2(points, offset) -> PolylinesNumpy:
points = list(points)
if not TOL.is_allclose(normal_polygon(points, True), [0, 0, 1]):
raise ValueError("Please pass a polygon with a normal vector of [0, 0, 1].")
V = np.asarray(points, dtype=np.float64)
offset = float(offset)
if offset < 0: # outside
offset_polygons = straight_skeleton_2.create_offset_polygons_2_outer(V, abs(offset))[1:] # first one is box
else: # inside
offset_polygons = straight_skeleton_2.create_offset_polygons_2_inner(V, offset)
return [Polygon(points.tolist()) for points in offset_polygons]

61 changes: 0 additions & 61 deletions src/straight_skeleton_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <CGAL/Polygon_2.h>
#include <CGAL/create_straight_skeleton_2.h>
#include <CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
#include <CGAL/create_offset_polygons_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point;
Expand All @@ -13,8 +12,6 @@ typedef CGAL::Straight_skeleton_2<K> Ss;
typedef boost::shared_ptr<Ss> SsPtr;
typedef CGAL::Straight_skeleton_2<K>::Halfedge_const_handle Halfedge_const_handle;
typedef CGAL::Straight_skeleton_2<K>::Vertex_const_handle Vertex_const_handle;
typedef boost::shared_ptr<Polygon_2> PolygonPtr;
typedef std::vector<PolygonPtr> PolygonPtrVector;

compas::Edges pmp_create_interior_straight_skeleton(
Eigen::Ref<const compas::RowMatrixXd> &V)
Expand Down Expand Up @@ -89,52 +86,6 @@ compas::Edges pmp_create_interior_straight_skeleton_with_holes(

}

std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_inner(Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
Polygon_2 poly;
for (int i = 0; i < V.rows(); i++){
poly.push_back(Point(V(i, 0), V(i, 1)));
}
PolygonPtrVector offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_2(offset, poly);

std::vector<compas::RowMatrixXd> result;
for(auto pi = offset_polygons.begin(); pi != offset_polygons.end(); ++pi){
std::size_t n = (*pi)->size();
compas::RowMatrixXd points(n, 3);
int j = 0;
for (auto vi = (*pi)->vertices_begin(); vi != (*pi)->vertices_end(); ++vi){
points(j, 0) = (double)(*vi).x();
points(j, 1) = (double)(*vi).y();
points(j, 2) = 0;
j++;
}
result.push_back(points);
}
return result;
}

std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_outer(Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
Polygon_2 poly;
for (int i = 0; i < V.rows(); i++){
poly.push_back(Point(V(i, 0), V(i, 1)));
}
PolygonPtrVector offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_2(offset, poly);

std::vector<compas::RowMatrixXd> result;
for(auto pi = offset_polygons.begin(); pi != offset_polygons.end(); ++pi){
std::size_t n = (*pi)->size();
compas::RowMatrixXd points(n, 3);
int j = 0;
for (auto vi = (*pi)->vertices_begin(); vi != (*pi)->vertices_end(); ++vi){
points(j, 0) = (double)(*vi).x();
points(j, 1) = (double)(*vi).y();
points(j, 2) = 0;
j++;
}
result.push_back(points);
}
return result;
}

// ===========================================================================
// PyBind11
// ===========================================================================
Expand All @@ -153,16 +104,4 @@ void init_straight_skeleton_2(pybind11::module &m)
&pmp_create_interior_straight_skeleton_with_holes,
pybind11::arg("V").noconvert(),
pybind11::arg("holes").noconvert());

submodule.def(
"create_offset_polygons_2_inner",
&pmp_create_offset_polygons_2_inner,
pybind11::arg("V").noconvert(),
pybind11::arg("offset").noconvert());

submodule.def(
"create_offset_polygons_2_outer",
&pmp_create_offset_polygons_2_outer,
pybind11::arg("V").noconvert(),
pybind11::arg("offset").noconvert());
};
9 changes: 1 addition & 8 deletions src/straight_skeleton_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@
compas::Edges pmp_create_interior_straight_skeleton(
Eigen::Ref<const compas::RowMatrixXd> &V);


compas::Edges pmp_create_interior_straight_skeleton_with_holes(
Eigen::Ref<const compas::RowMatrixXd> &V,
std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes);

std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_inner(
Eigen::Ref<const compas::RowMatrixXd> &V,
double &offset);

std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_outer(
Eigen::Ref<const compas::RowMatrixXd> &V,
double &offset);

#endif /* COMPAS_STRAIGHT_SKELETON_2_H */
20 changes: 1 addition & 19 deletions tests/test_straight_skeleton_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from compas_cgal.straight_skeleton_2 import create_interior_straight_skeleton
from compas_cgal.straight_skeleton_2 import create_interior_straight_skeleton_with_holes
from compas_cgal.straight_skeleton_2 import create_offset_polygons_2


def test_straight_polygon():
points = [
Expand Down Expand Up @@ -73,21 +73,3 @@ def test_straight_polygon_2_compare():
# the line direction sometimes changes ...
assert TOL.is_allclose(sa, se) or TOL.is_allclose(sa, ee)
assert TOL.is_allclose(ea, ee) or TOL.is_allclose(ea, se)


def test_offset():
points = [
(-1, -1, 0),
(0, -12, 0),
(1, -1, 0),
(12, 0, 0),
(1, 1, 0),
(0, 12, 0),
(-1, 1, 0),
(-12, 0, 0),
]
offset = 0.5
polygons = create_offset_polygons_2(points, offset)
assert len(polygons) == 1, len(polygons)
polygons = create_offset_polygons_2(points, -offset)
assert len(polygons) == 1, len(polygons)

0 comments on commit 7a232fe

Please sign in to comment.