Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano committed Oct 24, 2024
1 parent 42fa3ef commit 49492e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/algorithm/alphaShapes3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

#include "SFCGAL/algorithm/alphaShapes3D.h"
#include "SFCGAL/detail/GetPointsVisitor.h"
#include "SFCGAL/detail/transform/ForceOrderPoints.h"

#include <CGAL/Alpha_shape_3.h>
#include <CGAL/Alpha_shape_cell_base_3.h>
#include <CGAL/Alpha_shape_vertex_base_3.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>

namespace SFCGAL::algorithm {

Expand Down Expand Up @@ -64,44 +66,47 @@ auto
alphaShape3D_to_polyhedralSurface(const Alpha_shape_3 &alphaShape)
-> std::unique_ptr<PolyhedralSurface>
{
auto resultSurface = std::make_unique<PolyhedralSurface>();

// Iterate through all facets of the alpha shape
std::vector<Point_3> points;
std::vector<std::array<std::size_t, 3>> polygons;
for (auto facetIterator = alphaShape.alpha_shape_facets_begin();
facetIterator != alphaShape.alpha_shape_facets_end(); ++facetIterator) {

if (alphaShape.classify(*facetIterator) == Alpha_shape_3::REGULAR) {
// Get facet vertices
auto cell = facetIterator->first;
int idx = facetIterator->second;
auto cell = facetIterator->first;
int facetIdx = facetIterator->second;

const Point_3 pt1 = cell->vertex((idx + 1) & 3)->point();
const Point_3 pt2 = cell->vertex((idx + 2) & 3)->point();
const Point_3 pt3 = cell->vertex((idx + 3) & 3)->point();
const size_t currentIdx = points.size();
polygons.push_back({currentIdx, currentIdx + 1, currentIdx + 2});
points.push_back(cell->vertex((facetIdx + 1) & 3)->point());
points.push_back(cell->vertex((facetIdx + 2) & 3)->point());
points.push_back(cell->vertex((facetIdx + 3) & 3)->point());

// Create triangle polygon
auto poly = std::make_unique<Polygon>();
auto ring = std::make_unique<LineString>();
// // Create triangle polygon
// auto poly = std::make_unique<Polygon>();
// auto ring = std::make_unique<LineString>();

// create a closed ring
ring->addPoint(Point(pt1));
ring->addPoint(Point(pt2));
ring->addPoint(Point(pt3));
ring->addPoint(Point(pt1));
// // create a closed ring
// ring->addPoint(Point(pt1));
// ring->addPoint(Point(pt2));
// ring->addPoint(Point(pt3));
// ring->addPoint(Point(pt1));

poly->setExteriorRing(ring.release());
// poly->setExteriorRing(ring.release());

// SFCGAL::transform::ForceOrderPoints force(false);
// poly->accept(force);

resultSurface->addPolygon(poly.release());
// resultSurface->addPolygon(poly.release());
}
}

// SFCGAL::transform::ForceOrderPoints force(true);
// resultSurface->accept(force);
CGAL::Polygon_mesh_processing::repair_polygon_soup(points, polygons);
CGAL::Polygon_mesh_processing::orient_polygon_soup(points, polygons);
CGAL::Surface_mesh<Point_3> surfaceMesh;
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, polygons,
surfaceMesh);

return resultSurface;
return std::make_unique<PolyhedralSurface>(PolyhedralSurface(surfaceMesh));
}

auto
Expand Down
3 changes: 3 additions & 0 deletions test/unit/SFCGAL/algorithm/AlphaShapes3DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ BOOST_AUTO_TEST_CASE(testAlphaShapes3D_MultiPoint)
inputWkt << bunnyFS.rdbuf();

std::unique_ptr<Geometry> geomInput(io::readWkt(inputWkt.str()));
BOOST_REQUIRE(geomInput->is3D());

std::unique_ptr<Geometry> alphaShapesGeneral(algorithm::alphaShapes3D(geomInput->as<const SFCGAL::Geometry>()));

// std::cout << alphaShapesGeneral->asText(17);

// check
try {
const SFCGAL::Validity validity = SFCGAL::algorithm::isValid(*alphaShapesGeneral);
Expand Down

0 comments on commit 49492e8

Please sign in to comment.