Skip to content

Commit

Permalink
Merge remote-tracking branch 'soesau/Kinetic_shape_reconstruction-new…
Browse files Browse the repository at this point in the history
…_package-soesau' into HEAD
  • Loading branch information
sloriot committed Apr 29, 2024
2 parents 584bb51 + 69cd6ef commit acff6ac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ using Surface_mesh = CGAL::Surface_mesh<Point_3>;
using KSP = CGAL::Kinetic_space_partition_3<EPICK>;
using Timer = CGAL::Real_timer;

int main(const int argc, const char** argv) {
int main(int argc, char** argv)
{
// Reading polygons from file
std::string input_filename = (argc > 1 ? argv[1] : "data/test-4-rnd-polygons-4-6.off");
std::ifstream input_file(input_filename);
Expand Down
41 changes: 24 additions & 17 deletions Kinetic_space_partition/include/CGAL/KSP_3/Finalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Finalizer {
using Tetrahedron_3 = typename Kernel::Tetrahedron_3;

using From_exact = CGAL::Cartesian_converter<IntersectionKernel, Kernel>;
using To_exact = CGAL::Cartesian_converter<Kernel, IntersectionKernel>;

using Data_structure = CGAL::KSP_3::internal::Data_structure<Kernel, IntersectionKernel>;

Expand Down Expand Up @@ -422,16 +423,23 @@ class Finalizer {
// take 2d directions orthogonal to edge
// sort and take neighbors to current face

const Segment_3 segment = m_data.segment_3(pedge);
Vector_3 norm(segment.source(), segment.target());
To_exact to_exact;

// const Segment_3 segment = m_data.segment_3(pedge);
IEdge ie = m_data.iedge(pedge);
typename Intersection_kernel::Point_3 source = m_data.point_3(m_data.igraph().source(ie));
typename Intersection_kernel::Vector_3 norm(source, m_data.point_3(m_data.igraph().target(ie)));

norm = KSP::internal::normalize(norm);
const Plane_3 plane(segment.source(), norm);
Point_2 source2d = plane.to_2d(segment.source());

std::vector< std::pair<Direction_2, PFace> > dir_edges;
const typename Intersection_kernel::Plane_3 plane(source, norm);
typename Intersection_kernel::Point_2 source2d = plane.to_2d(source);

std::vector< std::pair<typename Intersection_kernel::Direction_2, PFace> > dir_edges;

// Get orientation towards edge of current face
Point_2 v2d = plane.to_2d(m_data.centroid_of_pface(pface));
dir_edges.push_back(std::make_pair(Direction_2(source2d - v2d), pface));
typename Intersection_kernel::Point_2 v2d = plane.to_2d(to_exact(m_data.centroid_of_pface(pface)));
dir_edges.push_back(std::make_pair(typename Intersection_kernel::Direction_2(source2d - v2d), pface));

// Get orientation towards edge of other faces
for (const PFace& face : neighbor_faces) {
Expand All @@ -444,31 +452,30 @@ class Finalizer {
auto h = mesh.halfedge(face.second);
auto first = h;

Point_3 point;
FT dist = 0;
typename Intersection_kernel::Point_3 point;
typename Intersection_kernel::FT dist = 0;
do {
Point_3 p = sp.to_3d(mesh.point(mesh.target(h)));
Vector_3 dist_in_plane = (p - segment.source());
typename Intersection_kernel::Point_3 p = m_data.point_3(m_data.ivertex(PVertex(face.first, mesh.target(h))));
typename Intersection_kernel::Vector_3 dist_in_plane = (p - source);
dist_in_plane -= norm * (dist_in_plane * norm);
FT d = dist_in_plane.squared_length();
typename Intersection_kernel::FT d = dist_in_plane.squared_length();

if (d > dist) {
dist = d;
point = p;
}
h = mesh.next(h);
} while (first != h);

Point_2 p = plane.to_2d(point);

dir_edges.push_back(std::make_pair(Direction_2(source2d - p), face));
dir_edges.push_back(std::make_pair(typename Intersection_kernel::Direction_2(source2d - plane.to_2d(point)), face));
}

CGAL_assertion(dir_edges.size() == neighbor_faces.size());

// Sort directions
std::sort(dir_edges.begin(), dir_edges.end(), [&](
const std::pair<Direction_2, PFace>& p,
const std::pair<Direction_2, PFace>& q) -> bool {
const std::pair<typename Intersection_kernel::Direction_2, PFace>& p,
const std::pair<typename Intersection_kernel::Direction_2, PFace>& q) -> bool {
return p.first < q.first;
}
);
Expand Down
16 changes: 10 additions & 6 deletions Kinetic_space_partition/include/CGAL/Kinetic_space_partition_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,12 @@ class Kinetic_space_partition_3 {
if (!added_volumes[i])
std::cout << "volume " << i << " has not been added" << std::endl;

std::cout << "lcc #volumes: " << lcc.template one_dart_per_cell<3>().size() << " ksp #volumes: " << number_of_volumes() << std::endl;
std::cout << "lcc #faces: " << lcc.template one_dart_per_cell<2>().size() << " ksp #faces: " << num_faces << std::endl;
std::cout << "lcc #n-edges: " << lcc.template one_dart_per_cell<1>().size() << std::endl;
std::cout << "lcc #vtx: " << lcc.template one_dart_per_cell<0>().size() << " ksp #vtx: " << vtx.size() << std::endl;
if (m_parameters.verbose) {
std::cout << "lcc #volumes: " << lcc.template one_dart_per_cell<3>().size() << " ksp #volumes: " << number_of_volumes() << std::endl;
std::cout << "lcc #faces: " << lcc.template one_dart_per_cell<2>().size() << " ksp #faces: " << num_faces << std::endl;
std::cout << "lcc #n-edges: " << lcc.template one_dart_per_cell<1>().size() << std::endl;
std::cout << "lcc #vtx: " << lcc.template one_dart_per_cell<0>().size() << " ksp #vtx: " << vtx.size() << std::endl;
}

// Verification
// Check attributes in each dart
Expand All @@ -1012,7 +1014,8 @@ class Kinetic_space_partition_3 {
}
}

lcc.display_characteristics(std::cout) << std::endl;
if (m_parameters.verbose)
lcc.display_characteristics(std::cout) << std::endl;

if (!lcc.is_valid())
std::cout << "LCC is not valid" << std::endl;
Expand Down Expand Up @@ -2391,7 +2394,8 @@ class Kinetic_space_partition_3 {
idx++;
}

std::cout << "input split into " << m_partition_nodes.size() << " partitions" << std::endl;
if (m_parameters.verbose)
std::cout << "input split into " << m_partition_nodes.size() << " partitions" << std::endl;
}
};

Expand Down

0 comments on commit acff6ac

Please sign in to comment.