From 7916f1430ba1c96cfd1c22fc51b1bb02a4b3b5e7 Mon Sep 17 00:00:00 2001 From: Dmitry Anisimov Date: Tue, 1 Dec 2020 19:33:38 +0100 Subject: [PATCH] added new occupied edge check --- .../include/CGAL/KSR_3/Data_structure.h | 437 +++++++++++++++--- .../CGAL/Kinetic_shape_reconstruction_3.h | 5 +- 2 files changed, 364 insertions(+), 78 deletions(-) diff --git a/Kinetic_shape_reconstruction/include/CGAL/KSR_3/Data_structure.h b/Kinetic_shape_reconstruction/include/CGAL/KSR_3/Data_structure.h index 2302053e3af..08e158c5fa9 100644 --- a/Kinetic_shape_reconstruction/include/CGAL/KSR_3/Data_structure.h +++ b/Kinetic_shape_reconstruction/include/CGAL/KSR_3/Data_structure.h @@ -1161,8 +1161,61 @@ public: const std::pair is_occupied( const PVertex& pvertex, + const IVertex& ivertex, const IEdge& query_iedge) { + const auto pair = is_occupied(pvertex, query_iedge); + const bool has_polygon = pair.first; + const bool is_bbox_reached = pair.second; + + if (is_bbox_reached) return std::make_pair(true, true); + CGAL_assertion(!is_bbox_reached); + if (!has_polygon) { + // std::cout << "NO POLYGON DETECTED" << std::endl; + return std::make_pair(false, false); + } + CGAL_assertion(has_polygon); + + CGAL_assertion(ivertex != null_ivertex()); + std::set pedges; + get_occupied_pedges(pvertex, query_iedge, pedges); + for (const auto& pedge : pedges) { + CGAL_assertion(pedge != null_pedge()); + // std::cout << "PEDGE: " << segment_3(pedge) << std::endl; + + const auto source = this->source(pedge); + const auto target = this->target(pedge); + if (this->ivertex(source) == ivertex || this->ivertex(target) == ivertex) { + return std::make_pair(true, false); + } + } + return std::make_pair(false, false); + } + + void get_occupied_pedges( + const PVertex& pvertex, + const IEdge& query_iedge, + std::set& pedges) { + + pedges.clear(); + for (const auto plane_idx : intersected_planes(query_iedge)) { + if (plane_idx == pvertex.first) continue; // current plane + if (plane_idx < 6) continue; // bbox plane + + for (const auto pedge : this->pedges(plane_idx)) { + if (iedge(pedge) == query_iedge) { + pedges.insert(pedge); + } + } + } + CGAL_assertion(pedges.size() > 0); + } + + const std::pair is_occupied( + const PVertex& pvertex, + const IEdge& query_iedge) { + + CGAL_assertion(query_iedge != null_iedge()); // std::cout << str(query_iedge) << " " << segment_3(query_iedge) << std::endl; KSR::size_t num_adjacent_faces = 0; for (const auto plane_idx : intersected_planes(query_iedge)) { @@ -1170,6 +1223,8 @@ public: if (plane_idx < 6) return std::make_pair(true, true); // bbox plane for (const auto pedge : pedges(plane_idx)) { + if (!has_iedge(pedge)) continue; + // std::cout << str(iedge(pedge)) << std::endl; if (iedge(pedge) == query_iedge) { const auto& m = mesh(plane_idx); @@ -1448,7 +1503,8 @@ public: IEdge prev_iedge = null_iedge(), next_iedge = null_iedge(); - // std::ofstream("came_from.polylines.txt") + // std::cout << "start from: " << segment_3(iedge(pvertices[1])) << std::endl; + // std::ofstream("start_from.polylines.txt") // << "2 " << segment_3(iedge(pvertices[1])) << std::endl; std::cout << "came from: " << @@ -1611,7 +1667,7 @@ public: const auto tmp_prev = pp_curr - dirp / FT(10); const Direction_2 tmp_dir(tmp_prev - point_2(pvertex.first, ivertex)); - // std::cout << to_3d(prev.first, tmp_prev) << std::endl; + // std::cout << "tmp_dir: " << to_3d(prev.first, tmp_prev) << std::endl; std::reverse(iedges.begin(), iedges.end()); @@ -1630,6 +1686,7 @@ public: } } + // std::cout << "first: " << segment_3(iedges[first_idx].first) << std::endl; // std::ofstream("first.polylines.txt") // << "2 " << segment_3(iedges[first_idx].first) << std::endl; @@ -1640,41 +1697,71 @@ public: std::size_t iter = 0; while (true) { const IEdge& iedge = iedges[iedge_idx].first; - bool collision, bbox_reached; std::tie(collision, bbox_reached) = collision_occured(pvertex, iedge); - bool limit_reached = (line_idx(iedge) == other_side_limit); + const bool limit_reached = (line_idx(iedge) == other_side_limit); std::cout << "limit/bbox: " << limit_reached << "/" << bbox_reached << std::endl; + // std::cout << "next: " << segment_3(iedge) << std::endl; // std::ofstream("next" + std::to_string(iter) + ".polylines.txt") // << "2 " << segment_3(iedge) << std::endl; crossed.push_back(iedge); - if (limit_reached || bbox_reached) { break; } - iedge_idx = (iedge_idx + 1) % iedges.size(); - if (iter == 100) { - CGAL_assertion_msg(false, "ERROR: BACK WHY SO MANY ITERATIONS?"); + CGAL_assertion_msg(false, "ERROR: BACK STD WHY SO MANY ITERATIONS?"); + } ++iter; + } + + std::vector all_crossed; + iedge_idx = first_idx; iter = 0; + while (true) { + const IEdge& iedge = iedges[iedge_idx].first; + bool limit_reached, bbox_reached; + std::tie(limit_reached, bbox_reached) = is_occupied(pvertex, iedge); + all_crossed.push_back(iedge); + if (limit_reached || bbox_reached) { + break; } - ++iter; + iedge_idx = (iedge_idx + 1) % iedges.size(); + if (iter == 100) { + CGAL_assertion_msg(false, "ERROR: BACK LIMIT WHY SO MANY ITERATIONS?"); + } ++iter; } CGAL_assertion(crossed.size() != 0); std::cerr << "IEdges crossed = " << crossed.size() << std::endl; for (const auto& iedge : crossed) std::cout << segment_3(iedge) << std::endl; + CGAL_assertion(crossed[0] == all_crossed[0]); - std::vector future_points(crossed.size()); - std::vector future_directions(crossed.size()); - for (std::size_t i = 0; i < crossed.size(); ++i) { - const bool is_parallel = compute_future_point_and_direction( - i, back, prev, crossed[i], future_points[i], future_directions[i]); - if (is_parallel) { - if (is_intersecting_iedge(min_time, max_time, prev, crossed[i])) { - prev_iedge = crossed[i]; + std::vector future_points; + std::vector future_directions; + + if (crossed.size() > all_crossed.size()) { + future_points.resize(crossed.size()); + future_directions.resize(crossed.size()); + for (std::size_t i = 0; i < crossed.size(); ++i) { + const bool is_parallel = compute_future_point_and_direction( + i, back, prev, crossed[i], future_points[i], future_directions[i]); + if (is_parallel) { + if (is_intersecting_iedge(min_time, max_time, prev, crossed[i])) { + prev_iedge = crossed[i]; + } + } + } + } else { + future_points.resize(all_crossed.size()); + future_directions.resize(all_crossed.size()); + for (std::size_t i = 0; i < all_crossed.size(); ++i) { + const bool is_parallel = compute_future_point_and_direction( + i, back, prev, all_crossed[i], future_points[i], future_directions[i]); + if (is_parallel) { + if (is_intersecting_iedge(min_time, max_time, prev, all_crossed[i])) { + prev_iedge = all_crossed[i]; + } } } } @@ -1684,21 +1771,24 @@ public: if (i == 0) // crop { std::cout << "Cropping" << std::endl; - PVertex cropped; Point_2 future_point; Vector_2 future_direction; + PVertex cropped; if (prev_iedge != null_iedge() && prev_iedge == crossed[i]) { std::cout << "prev parallel case" << std::endl; cropped = prev; + Point_2 future_point; Vector_2 future_direction; const auto pair = this->border_prev_and_next(prev); const auto pprev = pair.first; compute_future_point_and_direction( i, prev, pprev, prev_iedge, future_point, future_direction); + future_points[i] = future_point; + future_directions[i] = future_direction; } else { std::cout << "standard case" << std::endl; cropped = PVertex(support_plane_idx, support_plane(pvertex).split_edge(pvertex.second, prev.second)); - future_point = future_points[i]; - future_direction = future_directions[i]; + // future_point = future_points[i]; + // future_direction = future_directions[i]; } const PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, cropped.second)); @@ -1707,16 +1797,18 @@ public: connect(pedge, crossed[i]); connect(cropped, crossed[i]); - support_plane(cropped).set_point(cropped.second, future_point); - direction(cropped) = future_direction; + support_plane(cropped).set_point(cropped.second, future_points[i]); + direction(cropped) = future_directions[i]; previous = cropped; // std::cerr << "cropped point -> direction: " << point_2 (cropped) << " -> " << direction(cropped) << std::endl; std::cout << "cropped: " << point_3(cropped) << std::endl; } else // create triangle face { + CGAL_assertion_msg(i == 1, + "TODO: CAN WE HAVE MORE THAN 1 NEW FACE IN THE BACK CASE? IF YES, I SHOULD CHECK K FOR EACH!"); bool is_occupied_edge, bbox_reached; - std::tie(is_occupied_edge, bbox_reached) = is_occupied(pvertex, crossed[0]); + std::tie(is_occupied_edge, bbox_reached) = is_occupied(pvertex, ivertex, crossed[i - 1]); // std::tie(is_occupied_edge, bbox_reached) = collision_occured(pvertex, crossed[0]); std::cout << "is already occupied / bbox: " << is_occupied_edge << "/" << bbox_reached << std::endl; @@ -1742,22 +1834,51 @@ public: } CGAL_assertion(this->k(pface) >= 1); - PVertex propagated = add_pvertex(pvertex.first, future_points[i]); + const PVertex propagated = add_pvertex(pvertex.first, future_points[i]); direction(propagated) = future_directions[i]; new_vertices.push_back(propagated); std::cout << "propagated: " << point_3(propagated) << std::endl; - - PFace new_pface = add_pface(std::array{pvertex, propagated, previous}); - // this->k(new_pface) = k; + const PFace new_pface = add_pface(std::array{pvertex, propagated, previous}); this->k(new_pface) = this->k(pface); previous = propagated; - PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, propagated.second)); + const PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, propagated.second)); connect(pedge, crossed[i]); connect(propagated, crossed[i]); } } + + if (crossed.size() < all_crossed.size()) { + if (crossed.size() == all_crossed.size() - 1) { + + std::cout << "adding extra face!" << std::endl; + PVertex propagated = find_opposite_pvertex(pvertex, ivertex, all_crossed.back()); + if (propagated == null_pvertex()) { + CGAL_assertion_msg(false, "TODO: BACK NULL PROPAGATED CASE!"); + } else { + + std::cout << "propagated: " << point_3(propagated) << std::endl; + const PFace pface = pface_of_pvertex(pvertex); + const PFace new_pface = add_pface(std::array{pvertex, propagated, previous}); + this->k(new_pface) = this->k(pface); + previous = propagated; + } + } else { + CGAL_assertion_msg(false, "TODO: BACK CROSSED < LIMIT MULTIPLE FACES!"); + } + } + + if (crossed.size() == all_crossed.size()) { + // continue... + } + + if (crossed.size() > all_crossed.size()) { + // continue .. + // std::cout << "crossed size: " << crossed.size() << std::endl; + // std::cout << "all crossed size: " << all_crossed.size() << std::endl; + // CGAL_assertion_msg(false, "TODO: BACK CROSSED > LIMIT!"); + } } else if (front_constrained) // Border case { @@ -1780,7 +1901,7 @@ public: const auto tmp_next = pn_curr - dirn / FT(10); const Direction_2 tmp_dir(tmp_next - point_2(pvertex.first, ivertex)); - // std::cout << to_3d(next.first, tmp_next) << std::endl; + // std::cout << "tmp_dir: " << to_3d(next.first, tmp_next) << std::endl; if (was_swapped) { std::reverse(iedges.begin(), iedges.end()); @@ -1809,6 +1930,7 @@ public: } } + // std::cout << "first: " << segment_3(iedges[first_idx].first) << std::endl; // std::ofstream("first.polylines.txt") // << "2 " << segment_3(iedges[first_idx].first) << std::endl; @@ -1819,42 +1941,73 @@ public: std::size_t iter = 0; while (true) { const IEdge& iedge = iedges[iedge_idx].first; - bool collision, bbox_reached; std::tie(collision, bbox_reached) = collision_occured(pvertex, iedge); - bool limit_reached = (line_idx(iedge) == other_side_limit); + const bool limit_reached = (line_idx(iedge) == other_side_limit); std::cout << "limit/bbox: " << limit_reached << "/" << bbox_reached << std::endl; + // std::cout << "next: " << segment_3(iedge) << std::endl; // std::ofstream("next" + std::to_string(iter) + ".polylines.txt") // << "2 " << segment_3(iedge) << std::endl; crossed.push_back(iedge); - if (limit_reached || bbox_reached) { break; } - iedge_idx = (iedge_idx + 1) % iedges.size(); - if (iter == 100) { - CGAL_assertion_msg(false, "ERROR: FRONT WHY SO MANY ITERATIONS?"); + CGAL_assertion_msg(false, "ERROR: FRONT STD WHY SO MANY ITERATIONS?"); + } ++iter; + } + + std::vector all_crossed; + iedge_idx = first_idx; iter = 0; + while (true) { + const IEdge& iedge = iedges[iedge_idx].first; + bool limit_reached, bbox_reached; + std::tie(limit_reached, bbox_reached) = is_occupied(pvertex, iedge); + all_crossed.push_back(iedge); + if (limit_reached || bbox_reached) { + break; } - ++iter; + iedge_idx = (iedge_idx + 1) % iedges.size(); + if (iter == 100) { + CGAL_assertion_msg(false, "ERROR: FRONT LIMIT WHY SO MANY ITERATIONS?"); + } ++iter; } CGAL_assertion(crossed.size() != 0); std::cerr << "IEdges crossed = " << crossed.size() << std::endl; for (const auto& iedge : crossed) std::cout << segment_3(iedge) << std::endl; + CGAL_assertion(crossed[0] == all_crossed[0]); - std::vector future_points(crossed.size()); - std::vector future_directions(crossed.size()); - for (std::size_t i = 0; i < crossed.size(); ++i) { - const bool is_parallel = compute_future_point_and_direction( - i, front, next, crossed[i], future_points[i], future_directions[i]); + std::vector future_points; + std::vector future_directions; - if (is_parallel) { - if (is_intersecting_iedge(min_time, max_time, next, crossed[i])) { - next_iedge = crossed[i]; + if (crossed.size() > all_crossed.size()) { + future_points.resize(crossed.size()); + future_directions.resize(crossed.size()); + for (std::size_t i = 0; i < crossed.size(); ++i) { + const bool is_parallel = compute_future_point_and_direction( + i, front, next, crossed[i], future_points[i], future_directions[i]); + + if (is_parallel) { + if (is_intersecting_iedge(min_time, max_time, next, crossed[i])) { + next_iedge = crossed[i]; + } + } + } + } else { + future_points.resize(all_crossed.size()); + future_directions.resize(all_crossed.size()); + for (std::size_t i = 0; i < all_crossed.size(); ++i) { + const bool is_parallel = compute_future_point_and_direction( + i, front, next, all_crossed[i], future_points[i], future_directions[i]); + + if (is_parallel) { + if (is_intersecting_iedge(min_time, max_time, next, all_crossed[i])) { + next_iedge = all_crossed[i]; + } } } } @@ -1864,21 +2017,24 @@ public: if (i == 0) // crop { std::cout << "Cropping" << std::endl; - PVertex cropped; Point_2 future_point; Vector_2 future_direction; + PVertex cropped; if (next_iedge != null_iedge() && next_iedge == crossed[i]) { std::cout << "next parallel case" << std::endl; cropped = next; + Point_2 future_point; Vector_2 future_direction; const auto pair = this->border_prev_and_next(next); const auto nnext = pair.second; compute_future_point_and_direction( i, next, nnext, next_iedge, future_point, future_direction); + future_points[i] = future_point; + future_directions[i] = future_direction; } else { std::cout << "standard case" << std::endl; cropped = PVertex(support_plane_idx, support_plane(pvertex).split_edge(pvertex.second, next.second)); - future_point = future_points[i]; - future_direction = future_directions[i]; + // future_point = future_points[i]; + // future_direction = future_directions[i]; } const PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, cropped.second)); @@ -1888,15 +2044,17 @@ public: connect(pedge, crossed[i]); connect(cropped, crossed[i]); - support_plane(cropped).set_point(cropped.second, future_point); - direction(cropped) = future_direction; + support_plane(cropped).set_point(cropped.second, future_points[i]); + direction(cropped) = future_directions[i]; previous = cropped; // std::cerr << point_2 (cropped) << " -> " << direction(cropped) << std::endl; } else // create triangle face { + CGAL_assertion_msg(i == 1, + "TODO: CAN WE HAVE MORE THAN 1 NEW FACE IN THE FRONT CASE? IF YES, I SHOULD CHECK K FOR EACH!"); bool is_occupied_edge, bbox_reached; - std::tie(is_occupied_edge, bbox_reached) = is_occupied(pvertex, crossed[0]); + std::tie(is_occupied_edge, bbox_reached) = is_occupied(pvertex, ivertex, crossed[i - 1]); // std::tie(is_occupied_edge, bbox_reached) = collision_occured(pvertex, crossed[0]); std::cout << "is already occupied / bbox: " << is_occupied_edge << "/" << bbox_reached << std::endl; @@ -1922,22 +2080,71 @@ public: } CGAL_assertion(this->k(pface) >= 1); - PVertex propagated = add_pvertex(pvertex.first, future_points[i]); + const PVertex propagated = add_pvertex(pvertex.first, future_points[i]); direction(propagated) = future_directions[i]; new_vertices.push_back(propagated); std::cout << "propagated: " << point_3(propagated) << std::endl; - - PFace new_pface = add_pface(std::array{pvertex, previous, propagated}); - // this->k(new_pface) = k; + const PFace new_pface = add_pface(std::array{pvertex, previous, propagated}); this->k(new_pface) = this->k(pface); previous = propagated; - PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, propagated.second)); + const PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, propagated.second)); connect(pedge, crossed[i]); connect(propagated, crossed[i]); } } + + if (crossed.size() < all_crossed.size()) { + if (crossed.size() == all_crossed.size() - 1) { + + // CGAL_assertion_msg(false, "TODO: FRONT CROSSED < LIMIT 1 FACE!"); + + std::cout << "adding extra face!" << std::endl; + PVertex propagated = find_opposite_pvertex(pvertex, ivertex, all_crossed.back()); + if (propagated == null_pvertex()) { + + CGAL_assertion(future_points.size() == all_crossed.size()); + CGAL_assertion(future_directions.size() == all_crossed.size()); + propagated = add_pvertex(pvertex.first, future_points.back()); + direction(propagated) = future_directions.back(); + new_vertices.push_back(propagated); + + std::cout << "propagated: " << point_3(propagated) << std::endl; + const PFace pface = pface_of_pvertex(pvertex); + const PFace new_pface = add_pface(std::array{pvertex, previous, propagated}); + this->k(new_pface) = this->k(pface); + previous = propagated; + + const PEdge pedge(support_plane_idx, support_plane(pvertex).edge(pvertex.second, propagated.second)); + connect(pedge, all_crossed.back()); + connect(propagated, all_crossed.back()); + + // CGAL_assertion_msg(false, "TODO: FRONT NULL PROPAGATED CASE!"); + + } else { + + std::cout << "propagated: " << point_3(propagated) << std::endl; + const PFace pface = pface_of_pvertex(pvertex); + const PFace new_pface = add_pface(std::array{pvertex, previous, propagated}); + this->k(new_pface) = this->k(pface); + previous = propagated; + } + } else { + CGAL_assertion_msg(false, "TODO: FRONT CROSSED < LIMIT MULTIPLE FACES!"); + } + } + + if (crossed.size() == all_crossed.size()) { + // continue... + } + + if (crossed.size() > all_crossed.size()) { + // continue .. + // std::cout << "crossed size: " << crossed.size() << std::endl; + // std::cout << "all crossed size: " << all_crossed.size() << std::endl; + // CGAL_assertion_msg(false, "TODO: FRONT CROSSED > LIMIT!"); + } } else // Open case { @@ -1987,6 +2194,7 @@ public: CGAL_assertion(first_idx != KSR::no_element()); crossed.clear(); + // std::cout << "first: " << segment_3(iedges[first_idx].first) << std::endl; // std::ofstream("first.polylines.txt") // << "2 " << segment_3(iedges[first_idx].first) << std::endl; @@ -2000,6 +2208,7 @@ public: if (!dir.counterclockwise_in_between (dir_next, dir_prev)) break; + // std::cout << "next: " << segment_3(iedge) << std::endl; // std::ofstream("next" + std::to_string(iter) + ".polylines.txt") // << "2 " << segment_3(iedge) << std::endl; crossed.push_back(iedge); @@ -2105,12 +2314,12 @@ public: std::cerr << new_vertices.size() << " new vertice(s)" << std::endl; bool is_occupied_edge_back, bbox_reached_back; - std::tie(is_occupied_edge_back, bbox_reached_back) = is_occupied(pvertex, crossed.back()); + std::tie(is_occupied_edge_back, bbox_reached_back) = is_occupied(pvertex, ivertex, crossed.back()); // std::tie(is_occupied_edge_back, bbox_reached_back) = collision_occured(pvertex, crossed.back()); std::cout << "is already occupied back / bbox: " << is_occupied_edge_back << "/" << bbox_reached_back << std::endl; bool is_occupied_edge_front, bbox_reached_front; - std::tie(is_occupied_edge_front, bbox_reached_front) = is_occupied(pvertex, crossed.front()); + std::tie(is_occupied_edge_front, bbox_reached_front) = is_occupied(pvertex, ivertex, crossed.front()); // std::tie(is_occupied_edge_front, bbox_reached_front) = collision_occured(pvertex, crossed.front()); std::cout << "is already occupied front / bbox: " << is_occupied_edge_front << "/" << bbox_reached_front << std::endl; @@ -2128,36 +2337,27 @@ public: } else if ((is_occupied_edge_back && is_occupied_edge_front) && this->k(pface) == 1) { - add_new_faces(this->k(pface), pvertex, new_vertices, pface); - std::cout << "back && front k = 1" << std::endl; + std::cout << "stop back && front k = 1" << std::endl; } else if ((is_occupied_edge_back && is_occupied_edge_front) && this->k(pface) > 1) { - // this->k(pface)--; - // CGAL_assertion(this->k(pface) >= 1); + this->k(pface)--; + CGAL_assertion(this->k(pface) >= 1); add_new_faces(this->k(pface), pvertex, new_vertices, pface); - std::cout << "back && front k > 1" << std::endl; + std::cout << "continue back && front k > 1" << std::endl; } else if ((!is_occupied_edge_back && !is_occupied_edge_front)) { add_new_faces(this->k(pface), pvertex, new_vertices, pface); - std::cout << "!back && !front" << std::endl; + std::cout << "continue !back && !front" << std::endl; - } else if (is_occupied_edge_back && !is_occupied_edge_front) { + } else if (is_occupied_edge_back || is_occupied_edge_front) { add_new_faces(this->k(pface), pvertex, new_vertices, pface); - std::cout << "back && !front" << std::endl; + std::cout << "continue back || front" << std::endl; - } else if (!is_occupied_edge_back && is_occupied_edge_front) { - - add_new_faces(this->k(pface), pvertex, new_vertices, pface); - std::cout << "!back && front" << std::endl; - - // if (this->k(pface) > 1) { - // this->k(pface)--; - // CGAL_assertion(this->k(pface) >= 1); - // add_new_faces(this->k(pface), pvertex, new_vertices, pface); - // } + // std::cout << "centroid pface: " << centroid_of_pface(pface) << std::endl; + // CGAL_assertion_msg(false, "TEST THIS CASE: BACK || FRONT!"); } else { CGAL_assertion_msg(false, "TODO: ADD NEW OPEN CASE! DO NOT FORGET TO UPDATE K!"); @@ -2209,11 +2409,76 @@ public: const PFace& pface) { CGAL_assertion(new_vertices.size() >= 2); + std::size_t num_added_faces = 0; for (std::size_t i = 0; i < new_vertices.size() - 1; ++i) { - std::cout << "adding a new face" << std::endl; + std::cout << "adding new face" << std::endl; const PFace new_pface = add_pface(std::array{new_vertices[i], new_vertices[i + 1], pvertex}); this->k(new_pface) = k; + ++num_added_faces; } + CGAL_assertion(num_added_faces > 0); + CGAL_assertion_msg(num_added_faces == 1, + "TODO: CAN WE HAVE MORE THAN 1 NEW FACE IN THE OPEN CASE? IF YES, I SHOULD CHECK K FOR EACH!"); + } + + const PVertex find_opposite_pvertex( + const PVertex& pvertex, + const IVertex& ivertex, + const IEdge& iedge) const { + + std::set pedges; + const KSR::size_t support_plane_idx = pvertex.first; + for (const auto pedge : this->pedges(support_plane_idx)) { + if (this->iedge(pedge) == iedge) { + pedges.insert(pedge); + } + } + + for (const auto& pedge : pedges) { + CGAL_assertion(pedge != null_pedge()); + + const PVertex source = this->source(pedge); + const PVertex target = this->target(pedge); + + if (source == pvertex) { + // std::cout << "here1" << std::endl; + return target; + } + if (target == pvertex) { + // std::cout << "here2" << std::endl; + return source; + } + CGAL_assertion(source != pvertex && target != pvertex); + + if (this->ivertex(source) == ivertex) { + // std::cout << "here3" << std::endl; + return target; + } + if (this->ivertex(target) == ivertex) { + // std::cout << "here4" << std::endl; + return source; + } + CGAL_assertion(this->ivertex(source) != ivertex); + CGAL_assertion(this->ivertex(target) != ivertex); + + CGAL_assertion_msg(false, "TODO: CAN WE HAVE THIS CASE?"); + + // const auto s = point_2(source); + // const auto t = point_2(target); + // const auto ipoint = point_2(support_plane_idx, ivertex); + // Vector_2 vec1(s, t); + // Vector_2 vec2(s, ipoint); + // vec1 = KSR::normalize(vec1); + // vec2 = KSR::normalize(vec2); + + // const FT dot_product = vec1 * vec2; + // if (dot_product < FT(0)) { + // return target; + // } else { + // return source; + // } + } + return null_pvertex(); } void check_bbox() { @@ -2231,6 +2496,24 @@ public: } } + void check_interior() { + + for (KSR::size_t i = 6; i < number_of_support_planes(); ++i) { + const auto pfaces = this->pfaces(i); + for (const auto pface : pfaces) { + for (const auto pedge : pedges_of_pface(pface)) { + if (!has_iedge(pedge)) { + dump_pedge(pedge, "debug-pedge"); + } + CGAL_assertion_msg(has_iedge(pedge), "ERROR: INTERIOR EDGE IS MISSING AN IEDGE!"); + } + for (const auto pvertex : pvertices_of_pface(pface)) { + CGAL_assertion_msg(has_ivertex(pvertex), "ERROR: INTERIOR VERTEX IS MISSING AN IVERTEX!"); + } + } + } + } + void check_vertices() { for (const auto vertex : m_intersection_graph.vertices()) { @@ -2277,6 +2560,7 @@ public: // std::cout << "num faces sp " << i << ": " << pfaces(i).size() << std::endl; check_bbox(); + check_interior(); check_vertices(); check_edges(); create_volumes(); @@ -3306,6 +3590,7 @@ private: } else { std::cout << "back/front intersected lines" << std::endl; future_point = KSR::intersection(future_line_next, iedge_line); + // std::cout << to_3d(pvertex.first, future_point) << std::endl; } direction = Vector_2(pinit, future_point); diff --git a/Kinetic_shape_reconstruction/include/CGAL/Kinetic_shape_reconstruction_3.h b/Kinetic_shape_reconstruction/include/CGAL/Kinetic_shape_reconstruction_3.h index 07323818182..5b302f837f5 100644 --- a/Kinetic_shape_reconstruction/include/CGAL/Kinetic_shape_reconstruction_3.h +++ b/Kinetic_shape_reconstruction/include/CGAL/Kinetic_shape_reconstruction_3.h @@ -405,8 +405,8 @@ private: ++ iter; - // if (iter == 50) { - // exit(0); + // if (iter == 200) { + // exit(EXIT_FAILURE); // } apply(k, ev); @@ -625,6 +625,7 @@ private: remove_events (pvertices[i]); // Merge them and get the newly created vertices. + // std::cout << "came from: " << m_data.segment_3(m_data.iedge(ev.pvertex())) << std::endl; std::vector crossed; std::vector new_pvertices = m_data.merge_pvertices_on_ivertex(m_min_time, m_max_time, pvertices, ev.ivertex(), crossed);