Modify test

This commit is contained in:
Thien Hoang 2019-07-29 02:04:17 +07:00
parent fb8956d3fa
commit 08b2fb99e9
3 changed files with 83 additions and 75 deletions

View File

@ -130,7 +130,7 @@ public:
if (m_shortest_noncontractible_cycle==nullptr)
{ m_shortest_noncontractible_cycle = new Shortest_noncontractible_cycle(m_original_map); }
return m_shortest_noncontractible_cycle->compute_cycle(dh, NULL);
return m_shortest_noncontractible_cycle->compute_cycle(dh);
}
protected:

View File

@ -134,6 +134,13 @@ public:
CGAL_assertion(i<m_path.size());
return m_path[i];
}
/// @return true iff the ith dart is flipped
bool get_ith_flip(std::size_t i) const
{
CGAL_assertion(i<m_path.size());
return m_flip[i];
}
/// @return the ith dart of the path.
Dart_const_handle operator[] (std::size_t i) const

View File

@ -9,7 +9,7 @@
#include <CGAL/squared_distance_3.h>
#include <iostream>
#include <cstdlib>
#include <CGAL/Shortest_noncontractible_cycle.h>
#include <CGAL/Curves_on_surface_topology.h>
/*
Test the following cases:
@ -30,7 +30,7 @@ using Polyhedron = CGAL::Polyhedron_3<Kernel>;
struct Weight_functor_for_GM {
using Weight_t = unsigned int;
Weight_functor_for_GM(const GMap_2& gm, GMap_2::size_type amark) : m_gm(gm), m_mark(amark) {}
unsigned int operator() (GMap_2::Dart_handle dh) const {
unsigned int operator() (GMap_2::Dart_const_handle dh) const {
if (m_gm.is_marked(dh, m_mark)) return 3;
else return 4;
}
@ -65,14 +65,14 @@ private:
};
bool get_data(Surface_mesh& sm) {
std::ifstream in("./data/3torus-smooth.off");
std::ifstream in("./data/3torus.off");
if (in.fail()) return false;
in >> sm;
return true;
}
bool get_data(Polyhedron& sm) {
std::ifstream in("./data/3torus-smooth.off");
std::ifstream in("./data/3torus.off");
if (in.fail()) return false;
in >> sm;
return true;
@ -80,7 +80,7 @@ bool get_data(Polyhedron& sm) {
template <class T>
bool get_data(T& lcc) {
std::ifstream in("./data/3torus-smooth.off");
std::ifstream in("./data/3torus.off");
if (in.fail()) return false;
CGAL::load_off(lcc, in);
return true;
@ -92,29 +92,23 @@ bool find_cycle_in_unweighted_cmap_and_polyhedron() {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: Cannot locate file data/3torus.off\n";
return false;
}
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_for_CMap_2> snc1(lcc);
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_for_CMap_2>::Path cycle1;
unsigned int cycle_length1;
CGAL::Surface_mesh_topology::Curves_on_surface_topology<LCC_for_CMap_2> cst1(lcc);
LCC_for_CMap_2::Dart_handle root1 = lcc.darts().begin();
Point R = lcc.point_of_vertex_attribute(lcc.vertex_attribute(root1));
snc1.find_cycle(root1, cycle1, &cycle_length1);
if (cycle1.size() != cycle_length1) {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: cycle1.size() != cycle_length1\n";
return false;
}
for (auto e : cycle1)
CGAL::Surface_mesh_topology::Path_on_surface<LCC_for_CMap_2> cycle1 = cst1.compute_shortest_noncontractible_cycle_with_basepoint(root1);
for (int i = 0; i < cycle1.length(); ++i) {
auto e = cycle1[i];
if (e == NULL) {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: NULL dart handle found in cycle1\n";
return false;
}
}
Polyhedron p;
if (!get_data(p)) {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: Cannot locate file data/3torus.off\n";
return false;
}
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<Polyhedron> snc2(p);
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<Polyhedron>::Path cycle2;
unsigned int cycle_length2;
CGAL::Surface_mesh_topology::Curves_on_surface_topology<Polyhedron> cst2(p);
boost::graph_traits<Polyhedron>::halfedge_iterator root2 = p.halfedges_begin(), endit = p.halfedges_end();
for (; root2 != endit; ++root2) {
if ((*root2)->vertex()->point() == R) break;
@ -123,17 +117,15 @@ bool find_cycle_in_unweighted_cmap_and_polyhedron() {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: Cannot find CMap's root in the Polyhedron\n";
return false;
}
snc2.find_cycle(*root2, cycle2, &cycle_length2);
if (cycle2.size() != cycle_length2) {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: cycle.size() != cycle_length\n";
return false;
}
for (auto e : cycle2)
CGAL::Surface_mesh_topology::Path_on_surface<Polyhedron> cycle2 = cst2.compute_shortest_noncontractible_cycle_with_basepoint(*root2);
for (int i = 0; i < cycle2.length(); ++i) {
auto e = cycle2[i];
if (e == NULL) {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: NULL dart handle found in cycle\n";
return false;
}
if (cycle_length1 != cycle_length2) {
}
if (cycle1.length() != cycle2.length()) {
std::cerr << "Fail find_cycle_in_unweighted_cmap_and_polyhedron: Inconsistency in cycle length\n";
return false;
}
@ -146,19 +138,15 @@ bool edge_width_in_unweighted_polyhedron() {
std::cerr << "Fail edge_width_in_unweighted_polyhedron: Cannot locate file data/3torus.off\n";
return false;
}
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<Polyhedron> snc(p);
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<Polyhedron>::Path cycle;
unsigned int cycle_length;
snc.edge_width(cycle, &cycle_length);
if (cycle.size() != cycle_length) {
std::cerr << "Fail edge_width_in_unweighted_polyhedron: cycle.size() != cycle_length\n";
return false;
}
for (auto e : cycle)
CGAL::Surface_mesh_topology::Curves_on_surface_topology<Polyhedron> cst(p);
CGAL::Surface_mesh_topology::Path_on_surface<Polyhedron> cycle = cst.compute_edgewidth();
for (int i = 0; i < cycle.length(); ++i) {
auto e = cycle[i];
if (e == NULL) {
std::cerr << "Fail edge_width_in_unweighted_polyhedron: NULL dart handle found in cycle\n";
return false;
}
}
return true;
}
@ -189,14 +177,10 @@ bool find_cycle_in_nonorientable_gmap() { // Make a non-oriented case here
GMap_2::size_type chosen_cycle = gm.get_new_mark(), smallest_edge = gm.get_new_mark();
gm.mark_cell<1>(gm.alpha<0,1>(faces[5]), smallest_edge); // 9-4
typedef CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<GMap_2, Weight_functor_for_GM> SNC;
Weight_functor_for_GM wf (gm, smallest_edge);
SNC snc(gm, wf);
SNC::Path cycle;
SNC::Distance_type cycle_length;
CGAL::Surface_mesh_topology::Curves_on_surface_topology<GMap_2> cst(gm);
snc.find_cycle(faces[0], cycle, &cycle_length);
CGAL::Surface_mesh_topology::Path_on_surface<GMap_2> cycle = cst.compute_shortest_noncontractible_cycle_with_basepoint(faces[0]);
gm.mark_cell<1>(gm.alpha<1>(faces[1]), chosen_cycle); // 1-6
gm.mark_cell<1>(gm.alpha<1,0,1>(faces[1]), chosen_cycle); // 6-9
@ -204,11 +188,16 @@ bool find_cycle_in_nonorientable_gmap() { // Make a non-oriented case here
gm.mark_cell<1>(gm.alpha<1,0,1,0>(faces[0]), chosen_cycle); // 4-5
gm.mark_cell<1>(gm.alpha<0>(faces[2]), chosen_cycle); // 5-1
for (GMap_2::Dart_handle dh : cycle)
unsigned int cycle_length = 0;
for (int i = 0; i < cycle.length(); ++i) {
cycle_length += wf(cycle[i]);
auto dh = cycle[i];
if (!gm.is_marked(dh, chosen_cycle)) {
std::cerr << "Fail find_cycle_in_nonorientable_gmap: Cycle found is not the same as expected cycle.\n";
return false;
}
}
if (cycle_length != 19) {
std::cerr << "Fail find_cycle_in_nonorientable_gmap: Cycle length (" << cycle_length << ") is not as expected (should be 19).\n";
return false;
@ -227,27 +216,24 @@ bool edge_width_in_weighted_cmap_gmap_mesh() {
Weight_functor_for_LCC<LCC_for_CMap_2> wf_cm(lcc_cm);
Weight_functor_for_LCC<LCC_for_GMap_2> wf_gm(lcc_gm);
Weight_functor_for_SM wf_sm(sm);
typedef CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_for_CMap_2, Weight_functor_for_LCC<LCC_for_CMap_2> > SNC_1;
typedef CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_for_GMap_2, Weight_functor_for_LCC<LCC_for_GMap_2> > SNC_2;
typedef CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<Surface_mesh, Weight_functor_for_SM> SNC_3;
SNC_1 snc1(lcc_cm, wf_cm);
SNC_2 snc2(lcc_gm, wf_gm);
SNC_3 snc3(sm, wf_sm);
SNC_1::Path cycle1;
SNC_2::Path cycle2;
SNC_3::Path cycle3;
CGAL::Surface_mesh_topology::Curves_on_surface_topology<LCC_for_CMap_2> cst1(lcc_cm);
CGAL::Surface_mesh_topology::Curves_on_surface_topology<LCC_for_GMap_2> cst2(lcc_gm);
CGAL::Surface_mesh_topology::Curves_on_surface_topology<Surface_mesh> cst3(sm);
CGAL::Surface_mesh_topology::Path_on_surface<LCC_for_CMap_2> cycle1 = cst1.compute_edgewidth(wf_cm);
CGAL::Surface_mesh_topology::Path_on_surface<LCC_for_GMap_2> cycle2 = cst2.compute_edgewidth(wf_gm);
CGAL::Surface_mesh_topology::Path_on_surface<Surface_mesh> cycle3 = cst3.compute_edgewidth(wf_sm);
double cycle_length1, cycle_length2, cycle_length3;
snc1.edge_width(cycle1, &cycle_length1);
snc2.edge_width(cycle2, &cycle_length2);
snc3.edge_width(cycle3, &cycle_length3);
std::vector<Point> v1, v2, v3;
for (auto e : cycle1) {
for (int i = 0; i < cycle1.length(); ++i) {
auto e = cycle1[i];
if (e == NULL) {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: NULL dart handle found in cycle\n";
return false;
}
cycle_length1 += wf_cm(e);
Point a = lcc_cm.point_of_vertex_attribute(lcc_cm.vertex_attribute(e));
Point b = lcc_cm.point_of_vertex_attribute(lcc_cm.vertex_attribute(lcc_cm.next(e)));
if (cycle1.get_ith_flip(i)) std::swap(a, b);
if (v1.empty()) {
v1.push_back(a);
v1.push_back(b);
@ -255,18 +241,23 @@ bool edge_width_in_weighted_cmap_gmap_mesh() {
if (a == v1.back()) v1.push_back(b);
else if (b == v1.back()) v1.push_back(a);
else {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: The cycle is ill-formed\n";
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: cycle1 is ill-formed\n";
for (Point x : v1) std::cerr << x << ' ';
std::cerr << '\n' << a << '\n' << b << '\n';
return false;
}
}
}
for (auto e : cycle2) {
for (int i = 0; i < cycle2.length(); ++i) {
auto e = cycle2[i];
if (e == NULL) {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: NULL dart handle found in cycle\n";
return false;
}
cycle_length2 += wf_gm(e);
Point a = lcc_gm.point_of_vertex_attribute(lcc_gm.vertex_attribute(e));
Point b = lcc_gm.point_of_vertex_attribute(lcc_gm.vertex_attribute(lcc_gm.next(e)));
if (cycle2.get_ith_flip(i)) std::swap(a, b);
if (v2.empty()) {
v2.push_back(a);
v2.push_back(b);
@ -274,16 +265,19 @@ bool edge_width_in_weighted_cmap_gmap_mesh() {
if (a == v2.back()) v2.push_back(b);
else if (b == v2.back()) v2.push_back(a);
else {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: The cycle is ill-formed\n";
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: cycle2 is ill-formed\n";
for (Point x : v2) std::cerr << x << ' ';
std::cerr << '\n' << a << '\n' << b << '\n';
return false;
}
}
}
// It is observed that reversing v2 will make it identical to v1 and v3
std::reverse(v2.begin(), v2.end());
for (auto e : cycle3) {
for (int i = 0; i < cycle3.length(); ++i) {
auto e = cycle3[i];
cycle_length3 += wf_sm(e);
Point a = sm.point(sm.vertex(sm.edge(e), 0));
Point b = sm.point(sm.vertex(sm.edge(e), 1));
if (cycle3.get_ith_flip(i)) std::swap(a, b);
if (v3.empty()) {
v3.push_back(a);
v3.push_back(b);
@ -291,30 +285,32 @@ bool edge_width_in_weighted_cmap_gmap_mesh() {
if (a == v3.back()) v3.push_back(b);
else if (b == v3.back()) v3.push_back(a);
else {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: The cycle is ill-formed\n";
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: cycle3 is ill-formed\n";
for (Point x : v3) std::cerr << x << ' ';
std::cerr << '\n' << a << '\n' << b << '\n';
return false;
}
}
}
// for (Point x : v1) std::cout << x << " --- ";
// std::cout << '\n';
// for (Point x : v2) std::cout << x << " --- ";
// std::cout << '\n';
// for (Point x : v3) std::cout << x << " --- ";
// std::cout << '\n';
if (v1.size() != v2.size() || v1.size() != v3.size()) {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: Inconsistency in number of edges of the edge-width "
<< "(" << cycle1.size() << ", " << cycle2.size() << ", " << cycle3.size() << ").\n";
<< "(" << v1.size() << ", " << v2.size() << ", " << v3.size() << ").\n";
return false;
}
for (int i = 0; i < v1.size(); ++i) {
if (v1[i] != v2[i] || v1[i] != v3[i]) {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: Inconsistency in the vertex ordering";
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: Inconsistency in the vertex ordering.\n";
for (int i = 0; i < v1.size(); ++i) std::cerr << v1[i] << ", ";
std::cerr << '\n';
for (int i = 0; i < v2.size(); ++i) std::cerr << v2[i] << ", ";
std::cerr << '\n';
for (int i = 0; i < v3.size(); ++i) std::cerr << v3[i] << ", ";
std::cerr << '\n';
return false;
}
}
if (v1[0] != v1.back()) {
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: The path is not a cycle";
std::cerr << "Fail edge_width_in_weighted_cmap_gmap_mesh: The path is not a cycle.\n";
return false;
}
if (cycle_length1 - cycle_length2 > 1e-5 || cycle_length1 - cycle_length3 > 1e-5) {
@ -335,16 +331,21 @@ bool unsew_edge_width_repeatedly_in_unweighted_gmap() {
std::vector<unsigned int> cycle_lengths;
unsigned int length;
do {
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_for_GMap_2> snc(lcc_gm);
CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_for_GMap_2>::Path cycle;
snc.edge_width(cycle, &length);
for (auto e : cycle) {
CGAL::Surface_mesh_topology::Curves_on_surface_topology<LCC_for_GMap_2> cst(lcc_gm);
CGAL::Surface_mesh_topology::Path_on_surface<LCC_for_GMap_2> cycle = cst.compute_edgewidth();
length = cycle.length();
LCC_for_GMap_2::size_type belong_to_cycle = lcc_gm.get_new_mark();
for (int i = 0; i < cycle.length(); ++i) {
auto e = cycle[i];
if (e == NULL) {
std::cerr << "Fail unsew_edge_width_repeatedly_in_unweighted_gmap: NULL dart handle found in cycle\n";
return false;
}
lcc_gm.unsew<2>(e);
lcc_gm.mark(e, belong_to_cycle);
}
for (auto dh = lcc_gm.darts().begin(), dhend = lcc_gm.darts().end(); dh != dhend; ++dh)
if (lcc_gm.is_marked(dh, belong_to_cycle))
lcc_gm.unsew<2>(dh);
cycle_lengths.push_back(length);
} while (length != 0);
for (int i = 1; i < cycle_lengths.size(); ++i)