Skip to content

Commit

Permalink
switching initial_polygon_iedge_intersections and calculate_edge_inte…
Browse files Browse the repository at this point in the history
…rsection_time to epeck

resolving potential non-convex partitions
  • Loading branch information
soesau committed Nov 28, 2024
1 parent 3f1759d commit dbe38ed
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using Timer = CGAL::Real_timer;
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::string input_filename = (argc > 1 ? argv[1] : "data/issue_8624 - Copy.off");
std::ifstream input_file(input_filename);

std::vector<Point_3> input_vertices;
Expand All @@ -35,7 +35,7 @@ int main(int argc, char** argv)
std::cout << "--- INPUT STATS: \n* number of polygons: " << input_faces.size() << std::endl;

// Parameters.
const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 1);
const unsigned int k = (argc > 2 ? std::atoi(argv[2]) : 2);

// Initialization of Kinetic_space_partition_3 object.
// 'debug' set to true exports intermediate results into files in the working directory.
Expand All @@ -45,6 +45,7 @@ int main(int argc, char** argv)
// Providing input polygons.
ksp.insert(input_vertices, input_faces);


Timer timer;
timer.start();

Expand Down
151 changes: 82 additions & 69 deletions Kinetic_space_partition/include/CGAL/KSP/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ get_idx_color(std::size_t idx) {
static_cast<unsigned char>(rand.get_int(32, 192)));
}

CGAL::IO::Color get_color(std::size_t idx) {
CGAL::Random rand(static_cast<unsigned int>(idx));
return CGAL::IO::Color(rand.get_int(32, 192), rand.get_int(32, 192), rand.get_int(32, 192));
}

template<typename DS>
void dump_intersection_edges(const DS& data, const std::string tag = std::string()) {

Expand Down Expand Up @@ -110,12 +115,12 @@ void dump_2d_surface_mesh(
using Mesh = CGAL::Surface_mesh<Point_3>;
using Face_index = typename Mesh::Face_index;
using Vertex_index = typename Mesh::Vertex_index;
using Int_map = typename Mesh::template Property_map<Face_index, int>;
using Int_map = typename Mesh::template Property_map<Face_index, unsigned char>;

Mesh mesh;
Int_map red = mesh.template add_property_map<Face_index, int>("red", 0).first;
Int_map green = mesh.template add_property_map<Face_index, int>("green", 0).first;
Int_map blue = mesh.template add_property_map<Face_index, int>("blue", 0).first;
Int_map red = mesh.template add_property_map<Face_index, unsigned char>("red", 0).first;
Int_map green = mesh.template add_property_map<Face_index, unsigned char>("green", 0).first;
Int_map blue = mesh.template add_property_map<Face_index, unsigned char>("blue", 0).first;

std::vector<Vertex_index> vertices;
std::vector<Vertex_index> map_vertices;
Expand Down Expand Up @@ -332,7 +337,7 @@ class Saver {
{ }

void initialize(std::stringstream& stream) const {
stream.precision(20);
stream.precision(17);
}

void export_points_2(
Expand Down Expand Up @@ -495,7 +500,8 @@ class Saver {
stream << polygon.size() << " ";
for (std::size_t j = 0; j < polygon.size(); ++j)
stream << i++ << " ";
stream << get_idx_color(polygon_id) << std::endl;
auto col = get_idx_color(polygon_id);
stream << int(col.r()) << " " << int(col.g()) << " " << int(col.b()) << std::endl;
++polygon_id;
}
save(stream, file_name + ".ply");
Expand Down Expand Up @@ -528,7 +534,8 @@ class Saver {
stream << polygon.size() << " ";
for (std::size_t j = 0; j < polygon.size(); ++j)
stream << i++ << " ";
stream << get_idx_color(region_id) << std::endl;
auto col = get_idx_color(region_id);
stream << int(col.r()) << " " << int(col.g()) << " " << int(col.b()) << std::endl;
}
++region_id;
}
Expand Down Expand Up @@ -700,55 +707,53 @@ class Saver {
const std::size_t size) const {

stream <<
"ply" + std::string(_NL_) + "" <<
"format ascii 1.0" + std::string(_NL_) + "" <<
"element vertex " << size << "" + std::string(_NL_) + "" <<
"property double x" + std::string(_NL_) + "" <<
"property double y" + std::string(_NL_) + "" <<
"property double z" + std::string(_NL_) + "" <<
"property uchar red" + std::string(_NL_) + "" <<
"property uchar green" + std::string(_NL_) + "" <<
"property uchar blue" + std::string(_NL_) + "" <<
"property uchar alpha" + std::string(_NL_) + "" <<
"end_header" + std::string(_NL_) + "";
"ply" << std::endl <<
"format ascii 1.0" << std::endl <<
"element vertex " << size << std::endl <<
"property double x" << std::endl <<
"property double y" << std::endl <<
"property double z" << std::endl <<
"property uchar red" << std::endl <<
"property uchar green" << std::endl <<
"property uchar blue" << std::endl <<
"end_header" << std::endl;
}

void add_ply_header_normals(
std::stringstream& stream,
const std::size_t size) const {

stream <<
"ply" + std::string(_NL_) + "" <<
"format ascii 1.0" + std::string(_NL_) + "" <<
"element vertex " << size << "" + std::string(_NL_) + "" <<
"property double x" + std::string(_NL_) + "" <<
"property double y" + std::string(_NL_) + "" <<
"property double z" + std::string(_NL_) + "" <<
"property double nx" + std::string(_NL_) + "" <<
"property double ny" + std::string(_NL_) + "" <<
"property double nz" + std::string(_NL_) + "" <<
"end_header" + std::string(_NL_) + "";
"ply" << std::endl <<
"format ascii 1.0" << std::endl <<
"element vertex " << size << std::endl <<
"property double x" << std::endl <<
"property double y" << std::endl <<
"property double z" << std::endl <<
"property double nx" << std::endl <<
"property double ny" << std::endl <<
"property double nz" << std::endl <<
"end_header" << std::endl;
}

void add_ply_header_normals_colors(
std::stringstream& stream,
const std::size_t size) const {

stream <<
"ply" + std::string(_NL_) + "" <<
"format ascii 1.0" + std::string(_NL_) + "" <<
"element vertex " << size << "" + std::string(_NL_) + "" <<
"property double x" + std::string(_NL_) + "" <<
"property double y" + std::string(_NL_) + "" <<
"property double z" + std::string(_NL_) + "" <<
"property double nx" + std::string(_NL_) + "" <<
"property double ny" + std::string(_NL_) + "" <<
"property double nz" + std::string(_NL_) + "" <<
"property uchar red" + std::string(_NL_) + "" <<
"property uchar green" + std::string(_NL_) + "" <<
"property uchar blue" + std::string(_NL_) + "" <<
"property uchar alpha" + std::string(_NL_) + "" <<
"end_header" + std::string(_NL_) + "";
"ply" << std::endl <<
"format ascii 1.0" << std::endl <<
"element vertex " << size << std::endl <<
"property double x" << std::endl <<
"property double y" << std::endl <<
"property double z" << std::endl <<
"property double nx" << std::endl <<
"property double ny" << std::endl <<
"property double nz" << std::endl <<
"property uchar red" << std::endl <<
"property uchar green" << std::endl <<
"property uchar blue" << std::endl <<
"end_header" << std::endl;
}

void add_ply_header_regions(
Expand All @@ -775,19 +780,19 @@ class Saver {
const std::size_t num_faces) const {

stream <<
"ply" + std::string(_NL_) + "" <<
"format ascii 1.0" + std::string(_NL_) + "" <<
"element vertex " << num_vertices << "" + std::string(_NL_) + "" <<
"property double x" + std::string(_NL_) + "" <<
"property double y" + std::string(_NL_) + "" <<
"property double z" + std::string(_NL_) + "" <<
"element face " << num_faces << "" + std::string(_NL_) + "" <<
"property list uchar int vertex_indices" + std::string(_NL_) + "" <<
"property uchar red" + std::string(_NL_) + "" <<
"property uchar green" + std::string(_NL_) + "" <<
"property uchar blue" + std::string(_NL_) + "" <<
"property uchar alpha" + std::string(_NL_) + "" <<
"end_header" + std::string(_NL_) + "";
"ply" << std::endl <<
"format ascii 1.0" << std::endl <<
"element vertex " << num_vertices << std::endl <<
"property double x" << std::endl <<
"property double y" << std::endl <<
"property double z" << std::endl <<
"element face " << num_faces << std::endl <<
"property list uchar int vertex_indices" << std::endl <<
"property uchar red" << std::endl <<
"property uchar green" << std::endl <<
"property uchar blue" << std::endl <<
"property uchar alpha" << std::endl <<
"end_header" << std::endl;
}

void add_ply_header_mesh_no_color(
Expand All @@ -796,15 +801,15 @@ class Saver {
const std::size_t num_faces) const {

stream <<
"ply" + std::string(_NL_) + "" <<
"format ascii 1.0" + std::string(_NL_) + "" <<
"element vertex " << num_vertices << "" + std::string(_NL_) + "" <<
"property double x" + std::string(_NL_) + "" <<
"property double y" + std::string(_NL_) + "" <<
"property double z" + std::string(_NL_) + "" <<
"element face " << num_faces << "" + std::string(_NL_) + "" <<
"property list ushort int vertex_indices" + std::string(_NL_) + "" <<
"end_header" + std::string(_NL_) + "";
"ply" << std::endl <<
"format ascii 1.0" << std::endl <<
"element vertex " << num_vertices << std::endl <<
"property double x" << std::endl <<
"property double y" << std::endl <<
"property double z" << std::endl <<
"element face " << num_faces << std::endl <<
"property list ushort int vertex_indices" << std::endl <<
"end_header" << std::endl;
}
};

Expand Down Expand Up @@ -1015,14 +1020,22 @@ void dump_points(const std::vector<CGAL::Epick::Point_3>& pts, const std::vector

template<typename DS>
void dump_ifaces(const DS& data, const std::string tag = std::string()) {

using From_exact = CGAL::Cartesian_converter<typename DS::Intersection_kernel, typename DS::Kernel>;
From_exact from_exact;
// write all polygons into a separate ply with support plane index and iface index
for (std::size_t sp_idx = data.number_of_support_planes(); sp_idx++;) {
for (std::size_t sp_idx = 0; sp_idx < data.number_of_support_planes(); sp_idx++) {
for (typename DS::IFace f : data.support_plane(sp_idx).ifaces()) {
Saver<typename DS::Kernel> saver;
std::vector<std::vector<typename DS::Kernel::Point_3> > pts(1);
for (auto v : data.igraph().face(f).vertices)
pts.back().push_back(data.igraph().point_3(v));
saver.export_polygon_soup_3(pts, tag + "-" + std::to_string(sp_idx) + "-" + std::to_string(f));
std::vector<CGAL::IO::Color> cols;
cols.push_back(get_color(std::size_t(f)));
Saver<typename DS::Kernel> saver;
for (auto v : data.igraph().face(f).vertices) {
typename DS::IkPoint_3 ip = data.igraph().point_3(v);
Point_3 p = from_exact(ip);
pts.back().push_back(p);
}
saver.export_polygon_soup_3(pts, cols, tag + "-" + std::to_string(sp_idx) + "-" + std::to_string(f));
}
}
}
Expand Down
Loading

0 comments on commit dbe38ed

Please sign in to comment.