Simplify examples

This commit is contained in:
Thien Hoang 2019-07-08 17:33:44 +07:00
parent 70899a877d
commit 16703f777c
3 changed files with 44 additions and 127 deletions

View File

@ -25,22 +25,28 @@ using SNC = CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<Mesh, We
int main(int argc, char* argv[]) {
std::cout << "Program edgewidth_surface_mesh started.\n";
Mesh sm;
std::ifstream in ((argc > 1) ? argv[1] : "data/3torus-smooth.off");
in >> sm;
std::ifstream inp ((argc > 1) ? argv[1] : "../../examples/Surface_mesh_topology/data/3torus-smooth.off");
if (inp.fail()) {
std::cout << "Cannot read file. Exiting program\n";
return EXIT_FAILURE;
}
inp >> sm;
std::cout << "File loaded. Running the main program...\n";
Weight_functor wf(sm);
SNC snc(sm, wf);
SNC::Path cycle;
SNC::Distance_type x;
SNC::Distance_type cycle_length;
std::cout << "Finding edge-width of the mesh...\n";
snc.edge_width(cycle, &x);
snc.edge_width(cycle, &cycle_length);
if (cycle.size() == 0) {
std::cout << " Cannot find edge-width. Stop.\n";
return 0;
}
std::cout << " Number of edges in cycle: " << cycle.size() << std::endl;
std::cout << " Cycle length: " << x << std::endl;
std::cout << " Cycle length: " << cycle_length << std::endl;
std::cout << " Root: " << sm.point(sm.vertex(sm.edge(cycle[0]), 0)) << std::endl;
return EXIT_SUCCESS;

View File

@ -9,23 +9,8 @@
#include <CGAL/squared_distance_3.h>
#define CGAL_USE_BASIC_VIEWER 1
struct Myitem
{
template<class LCC>
struct Dart_wrapper
{
typedef CGAL::Cell_attribute_with_point<LCC, CGAL::Color, CGAL::Tag_true> Vertex_attribute;
typedef CGAL::Cell_attribute_with_point<LCC, CGAL::Color, CGAL::Tag_true> Edge_attribute;
typedef CGAL::cpp11::tuple<Vertex_attribute, Edge_attribute> Attributes;
};
};
using Traits = CGAL::Linear_cell_complex_traits<3>;
using LCC_3 = CGAL::Linear_cell_complex_for_generalized_map<2, 3, Traits, Myitem>;
using Dart_handle = LCC_3::Dart_handle;
using LCC_3 = CGAL::Linear_cell_complex_for_generalized_map<2, 3>;
using Dart_const_handle = LCC_3::Dart_const_handle;
using Dart_container = std::vector<Dart_handle>;
struct Weight_functor {
Weight_functor(const LCC_3& lcc) : m_lcc(lcc) { }
@ -43,71 +28,33 @@ using SNC = CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_3, W
LCC_3 lcc;
struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC {
Draw_functor() {}
template<typename LCC>
bool colored_vertex(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return alcc.template info<0>(dh) != CGAL::Color();}
template<typename LCC>
CGAL::Color vertex_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return alcc.template info<0>(dh);}
template<typename LCC>
bool colored_edge(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return true; }
template<typename LCC>
CGAL::Color edge_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return alcc.template info<1>(dh);}
template<typename LCC>
bool colored_face(const LCC& alcc, typename LCC::Dart_const_handle dh) const {return true;}
template<typename LCC>
CGAL::Color face_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return CGAL::Color(211, 211, 211);}
template<typename LCC>
bool colored_volume(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return false; }
};
int main(int argc, char* argv[]) {
int main(int argc, char* argv[])
{
std::cout << "Program shortest_noncontractible_cycle_through_a_vertex started.\n";
std::ifstream inp;
if (argc == 1) inp = std::ifstream("../../examples/Surface_mesh_topology/data/3torus.off");
else inp = std::ifstream(argv[1]);
CGAL::load_off(lcc, inp);
for (auto it = lcc.darts().begin(), itend = lcc.darts().end(); it != itend; ++it) {
lcc.set_attribute<1>(it, lcc.create_attribute<1>());
lcc.set_attribute<0>(it, lcc.create_attribute<0>());
if (inp.fail()) {
std::cout << "Cannot load file. Exiting program...\n";
return EXIT_FAILURE;
}
CGAL::load_off(lcc, inp);
std::cout << "File loaded. Running the main program...\n";
Draw_functor df;
Weight_functor wf(lcc);
SNC snc(lcc, wf);
SNC::Path cycle;
SNC::Distance_type x;
/// CHANGE THE VALUE OF `root` TO TEST THE ALGORITHM AT ANOTHER VERTEX
SNC::Distance_type cycle_length;
/// Change the value of `root` to test the algorithm at another vertex
auto root = lcc.darts().begin();
std::cout << "Finding the shortest noncontractible cycle...\n";
snc.find_cycle(root, cycle, &x);
snc.find_cycle(root, cycle, &cycle_length);
if (cycle.size() == 0) {
std::cout << " Cannot find such cycle. Stop.\n";
return 0;
}
LCC_3::size_type m = lcc.get_new_mark();
for (auto e : cycle) {
lcc.mark_cell<1>(e, m);
}
lcc.info<0>(root) = CGAL::Color(255, 0, 0);
for (auto dh = lcc.one_dart_per_cell<1>().begin(), dhend = lcc.one_dart_per_cell<1>().end(); dh != dhend; ++dh)
if (lcc.is_marked(dh, m)) {
lcc.info<1>(dh) = CGAL::Color(0, 0, 255);
}
lcc.free_mark(m);
std::cout << " Number of edges in cycle: " << cycle.size() << std::endl;
std::cout << " Cycle length: " << x << std::endl;
std::cout << " Cycle length: " << cycle_length << std::endl;
std::cout << " Root: " << lcc.point_of_vertex_attribute(lcc.vertex_attribute(root)) << std::endl;
CGAL::draw(lcc, "Hello", false, df);
}

View File

@ -10,72 +10,36 @@
#define CGAL_USE_BASIC_VIEWER 1
using LCC_3 = CGAL::Linear_cell_complex_for_combinatorial_map<2, 3>;
using size_type = LCC_3::size_type;
using SNC = CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle<LCC_3>;
LCC_3 lcc;
struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC {
Draw_functor(size_type edge_mark, size_type vertex_mark) : m_edge_mark(edge_mark), m_vertex_mark(vertex_mark) {}
template<typename LCC>
bool colored_vertex(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return alcc.is_marked(dh, m_vertex_mark);}
template<typename LCC>
CGAL::Color vertex_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return CGAL::Color(255, 0, 0);}
template<typename LCC>
bool colored_edge(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{ return alcc.is_marked(dh, m_edge_mark); }
template<typename LCC>
CGAL::Color edge_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return CGAL::Color(0, 0, 255);}
template<typename LCC>
bool colored_face(const LCC& alcc, typename LCC::Dart_const_handle dh) const {return true;}
template<typename LCC>
CGAL::Color face_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const
{return CGAL::Color(211, 211, 211);}
template<typename LCC>
bool colored_volume(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return false; }
private:
size_type m_edge_mark, m_vertex_mark;
};
int main(int argc, char* argv[]) {
int main(int argc, char* argv[])
{
std::cout << "Program shortest_noncontractible_cycle_using_BFS started.\n";
std::ifstream inp;
if (argc == 1) inp = std::ifstream("data/3torus-smooth.off");
if (argc == 1) inp = std::ifstream("../../examples/Surface_mesh_topology/data/3torus-smooth.off");
else inp = std::ifstream(argv[1]);
if (inp.fail()) {
std::cout << "Cannot read file. Exiting program\n";
return EXIT_FAILURE;
}
CGAL::load_off(lcc, inp);
std::cout << "File loaded. Running the main program...\n";
SNC snc(lcc);
SNC::Path cycle;
SNC::Distance_type x;
SNC::Distance_type cycle_length;
/// Change the value of `root` to test the algorithm at another vertex
auto root = lcc.darts().begin();
std::cout << "Finding the shortest noncontractible cycle...\n";
snc.find_cycle(root, cycle, &x);
snc.find_cycle(root, cycle, &cycle_length);
if (cycle.size() == 0) {
std::cout << " Cannot find such cycle. Stop.\n";
return 0;
}
size_type m = lcc.get_new_mark(), is_root = lcc.get_new_mark();
for (auto e : cycle) {
lcc.mark_cell<1>(e, m);
}
lcc.mark_cell<0>(root, is_root);
std::cout << " Number of edges in cycle: " << cycle.size() << std::endl;
std::cout << " Cycle length: " << x << std::endl;
std::cout << " Cycle length: " << cycle_length << std::endl;
std::cout << " Root: " << lcc.point_of_vertex_attribute(lcc.vertex_attribute(root)) << std::endl;
Draw_functor df(m, is_root);
CGAL::draw(lcc, "Hello", false, df);
lcc.free_mark(m);
lcc.free_mark(is_root);
}