From b8483143368516632d1c0eecdec6b11f4b86d938 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 19 Mar 2018 16:36:03 +0100 Subject: [PATCH] Improve method --- .../CGAL/Creation_of_test_cases_for_paths.h | 104 ++++++++++++ .../include/CGAL/Path_generators.h | 33 +++- .../include/CGAL/Path_on_surface.h | 25 ++- .../Linear_cell_complex/compute_example.cpp | 155 ++++++++++++------ .../include/CGAL/LCC_with_paths.h | 89 +++++++--- 5 files changed, 318 insertions(+), 88 deletions(-) create mode 100644 Combinatorial_map/include/CGAL/Creation_of_test_cases_for_paths.h diff --git a/Combinatorial_map/include/CGAL/Creation_of_test_cases_for_paths.h b/Combinatorial_map/include/CGAL/Creation_of_test_cases_for_paths.h new file mode 100644 index 00000000000..e15931d61d9 --- /dev/null +++ b/Combinatorial_map/include/CGAL/Creation_of_test_cases_for_paths.h @@ -0,0 +1,104 @@ +// Copyright (c) 2017 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_CREATION_OF_TEST_CASES_FOR_PATHS_H +#define CGAL_CREATION_OF_TEST_CASES_FOR_PATHS_H 1 + +#include + +namespace CGAL { + +template +void generate_one_positive_spur(Path& p) +{ + p.clear(); + p.push_back(p.get_map().darts().iterator_to(p.get_map().darts()[5])); // 6th dart of the map + extend_straight_positive(p, 6); + extend_uturn_positive(p); + extend_uturn_half_turn(p); + extend_straight_positive(p, 4); +} + +template +void generate_one_negative_spur(Path& p) +{ + p.clear(); + p.push_back(p.get_map().darts().iterator_to(p.get_map().darts()[5])); // 6th dart of the map + extend_straight_negative(p, 6); + extend_uturn_negative(p); + extend_uturn_half_turn(p); + extend_straight_negative(p, 4); +} + +template +void generate_cyclic_spur(Path& p) +{ + p.clear(); + p.push_back(p.get_map().darts().iterator_to(p.get_map().darts()[5])); // 6th dart of the map + extend_uturn_half_turn(p); +} + +template +void generate_one_positive_bracket(Path& p) +{ + p.clear(); + p.push_back(p.get_map().darts().iterator_to(p.get_map().darts()[5])); // 6th dart of the map + extend_straight_positive(p, 3); + extend_uturn_negative(p); + extend_uturn_positive(p); + extend_straight_positive(p, 6); + extend_uturn_positive(p); + extend_uturn_negative(p); + extend_straight_positive(p, 2); +} + +template +void generate_one_negative_bracket(Path& p) +{ + p.clear(); + p.push_back(p.get_map().darts().iterator_to(p.get_map().darts()[5])); // 6th dart of the map + extend_straight_negative(p, 3); + extend_uturn_positive(p); + extend_uturn_negative(p); + extend_straight_negative(p, 6); + extend_uturn_negative(p); + extend_uturn_positive(p); + extend_straight_negative(p, 2); +} + +template +void generate_positive_bracket_special1(Path& p) +{ // Case (x, 1, 2^r, 1) + p.clear(); + // p.push_back(p.get_map().template beta<2>(p.get_map().darts().iterator_to(p.get_map().darts()[5]))); // 6th dart of the map + p.push_back(p.get_map().darts().iterator_to(p.get_map().darts()[12])); // 6th dart of the map + extend_uturn_positive(p, 4); + extend_straight_positive(p, 1); + /*extend_uturn_positive(p); + extend_straight_positive(p, 1); + extend_straight_positive(p, 8);*/ + //extend_uturn_negative(p); +} + + +} // namespace CGAL + +#endif // CGAL_CREATION_OF_TEST_CASES_FOR_PATHS_H // +// EOF // diff --git a/Combinatorial_map/include/CGAL/Path_generators.h b/Combinatorial_map/include/CGAL/Path_generators.h index b7340b107b6..09dbe6a716b 100644 --- a/Combinatorial_map/include/CGAL/Path_generators.h +++ b/Combinatorial_map/include/CGAL/Path_generators.h @@ -102,7 +102,7 @@ bool extend_path_randomly(Path& p, bool allow_half_turn=false) template void extend_straight_positive(Path& p, std::size_t nb=1) { - if (p.is_empty()) + if (p.is_empty() || nb==0) { return; } for (std::size_t i=0; i void extend_straight_negative(Path& p, std::size_t nb=1) { - if (p.is_empty()) + if (p.is_empty() || nb==0) { return; } for (std::size_t i=0; i -void extend_uturn_positive(Path& p) +void extend_uturn_positive(Path& p, std::size_t nb=1) { - if (p.is_empty()) + if (p.is_empty() || nb==0) { return; } - + typename Path::Dart_const_handle d2=p.get_map().template beta<1>(p.back()); + for (std::size_t i=1; i(d2); } + if (d2!=p.get_map().null_dart_handle) { p.push_back(d2); } } template -void extend_uturn_negative(Path& p) +void extend_uturn_negative(Path& p, std::size_t nb=1) { if (p.is_empty()) { return; } - typename Path::Dart_const_handle d2=p.get_map().template beta<2,0,2>(p.back()); + typename Path::Dart_const_handle d2=p.get_map().template beta<2>(p.back()); + for (std::size_t i=0; i(d2); } + if (d2!=p.get_map().null_dart_handle) { p.push_back(d2); } } -template +template +void extend_uturn_half_turn(Path& p) +{ + if (p.is_empty()) + { return; } + + typename Path::Dart_const_handle d2=p.get_map().template beta<2>(p.back()); + if (d2!=p.get_map().null_dart_handle) + { p.push_back(d2); } +} + +template void create_braket_positive(Path& p, std::size_t length, CGAL::Random& random) { if (p.is_empty()) diff --git a/Combinatorial_map/include/CGAL/Path_on_surface.h b/Combinatorial_map/include/CGAL/Path_on_surface.h index 2dd7e3eca72..de83ef20a8d 100644 --- a/Combinatorial_map/include/CGAL/Path_on_surface.h +++ b/Combinatorial_map/include/CGAL/Path_on_surface.h @@ -259,6 +259,8 @@ public: bool bracket_flattening_one_step() { + if (is_empty()) return false; + bool res=false; std::vector new_path; std::size_t i; @@ -312,6 +314,8 @@ public: bool remove_spurs_one_step() { + if (is_empty()) return false; + bool res=false; std::size_t i; std::vector new_path; @@ -328,6 +332,9 @@ public: ++i; } } + if (i==m_path.size()-1) + { new_path.push_back(m_path[m_path.size()-1]); } + new_path.swap(m_path); return res; } @@ -344,15 +351,21 @@ public: { assert(next_turn(begin)!=2); std::size_t end=begin+1; - if (end==m_path.size()-1) + if (end==m_path.size()-1 && !is_closed()) { return begin; } // begin is the before last dart - while (next_turn(end)==2) + while (next_turn(end)==2 && end!=begin) { ++end; if (is_closed() && end==m_path.size()) { end=0; } } + if (begin==end) + { // Case of a path having only 2 turns + // TODO SOMETHING + std::cout<<"TODO TODO !!"< #include +#include typedef CGAL::Linear_cell_complex_for_combinatorial_map<2,3> LCC_3_cmap; typedef CGAL::Linear_cell_complex_for_generalized_map<2,3> LCC_3_gmap; +void simplify_path(CGAL::Path_on_surface& path, + bool draw=false) +{ + std::vector*> v; + if (draw) + { + v.push_back(&path); + display(path.get_map(), v); + } + + CGAL::Path_on_surface* prevp=&path; + CGAL::Path_on_surface* curp=NULL; + do + { + curp=new CGAL::Path_on_surface(*prevp); + if (curp->bracket_flattening_one_step()) + { + if (draw) { v.push_back(curp); } + prevp=curp; + } + else + { + delete curp; + curp=NULL; + } + // if (nbtest==1) + // display(lcc, v); + } + while(curp!=NULL); + + curp=new CGAL::Path_on_surface(*prevp); + if (curp->remove_spurs()) + { + if (draw) { v.push_back(curp); } + prevp=curp; + } + else + { + delete curp; + curp=NULL; + } + + if (draw) + { display(path.get_map(), v); } +} + void test_file(int argc, char** argv) { if (argc!=2) @@ -60,14 +107,14 @@ void test_file(int argc, char** argv) pp1=cmt.transform_original_path_into_quad_surface(p1); std::cout<<"Original path has "<*> v; - v.push_back(&path); - // display(lcc, v); - - CGAL::Path_on_surface* prevp=&path; - CGAL::Path_on_surface* curp=NULL; - do - { - curp=new CGAL::Path_on_surface(*prevp); - if (curp->bracket_flattening_one_step()) - { - v.push_back(curp); - prevp=curp; - } - else - { - delete curp; - curp=NULL; - } - // if (nbtest==1) - // display(lcc, v); - } - while(curp!=NULL); - - curp=new CGAL::Path_on_surface(*prevp); - if (curp->remove_spurs()) - { - v.push_back(curp); - prevp=curp; - } - else - { - delete curp; - curp=NULL; - } - - if (draw) - { display(lcc, v); } + simplify_path(path, draw); std::cout<<"[END] TEST "<key()==::Qt::Key_D) && (modifiers==::Qt::NoButton)) + { + m_current_dart=(m_current_dart+1)%(lcc.number_of_darts()+1); + if (m_current_dart==lcc.number_of_darts()) + { + displayMessage(QString("Draw all darts.")); + } + else + { + displayMessage(QString("Draw dart=%1.").arg((m_current_dart))); + } compute_elements(); initialize_buffers(); compile_shaders(); @@ -227,6 +271,7 @@ protected: const ColorFunctor& m_fcolor; const std::vector*>& m_paths; unsigned int m_current_path; + unsigned int m_current_dart; }; template