mirror of https://github.com/CGAL/cgal
Seems ok for bracket flatering and spurs removal.
This commit is contained in:
parent
1d97d27ba9
commit
d3f1a4c703
|
|
@ -63,10 +63,10 @@ public:
|
||||||
{ m_path.clear(); }
|
{ m_path.clear(); }
|
||||||
|
|
||||||
std::size_t next_index(std::size_t i) const
|
std::size_t next_index(std::size_t i) const
|
||||||
{ return (i==m_path.size()-1?0:i+1); }
|
{ return (is_closed() && i==m_path.size()-1?0:i+1); }
|
||||||
|
|
||||||
std::size_t prev_index(std::size_t i) const
|
std::size_t prev_index(std::size_t i) const
|
||||||
{ return (i==0?m_path.size()-1:i-1); }
|
{ return (is_closed() && i==0?m_path.size()-1:i-1); }
|
||||||
|
|
||||||
Dart_const_handle get_ith_dart(std::size_t i) const
|
Dart_const_handle get_ith_dart(std::size_t i) const
|
||||||
{
|
{
|
||||||
|
|
@ -284,24 +284,32 @@ public:
|
||||||
{ transform_negative_bracket(begin, end, new_path); }
|
{ transform_negative_bracket(begin, end, new_path); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy all darts starting from begin and going to the dart before end
|
||||||
|
// from this path to new_path.
|
||||||
|
void copy_rest_of_path(std::size_t begin, std::size_t end,
|
||||||
|
std::vector<Dart_const_handle>& new_path)
|
||||||
|
{
|
||||||
|
assert(end<=length());
|
||||||
|
assert(begin<=end);
|
||||||
|
while(begin!=end)
|
||||||
|
{
|
||||||
|
new_path.push_back(get_ith_dart(begin));
|
||||||
|
++begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool bracket_flattening_one_step()
|
bool bracket_flattening_one_step()
|
||||||
{
|
{
|
||||||
if (is_empty()) return false;
|
if (is_empty()) return false;
|
||||||
|
|
||||||
bool res=false;
|
|
||||||
std::vector<Dart_const_handle> new_path;
|
std::vector<Dart_const_handle> new_path;
|
||||||
std::size_t i;
|
std::size_t i;
|
||||||
bool positive=false;
|
bool positive=false;
|
||||||
|
|
||||||
for (i=0; i<m_path.size()-1; )
|
for (i=0; i<m_path.size()-1; ++i)
|
||||||
{
|
{
|
||||||
positive=(next_turn(i)==1);
|
positive=(next_turn(i)==1);
|
||||||
if (!positive && next_negative_turn(i)!=1)
|
if (positive || next_negative_turn(i)==1)
|
||||||
{
|
|
||||||
new_path.push_back(m_path[i]); // We copy this dart
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// i is maybe the beginning of a bracket
|
// i is maybe the beginning of a bracket
|
||||||
std::size_t begin=i;
|
std::size_t begin=i;
|
||||||
|
|
@ -310,27 +318,32 @@ public:
|
||||||
{
|
{
|
||||||
/* std::cout<<"Bracket: ["<<begin<<"; "<<end<<"] "
|
/* std::cout<<"Bracket: ["<<begin<<"; "<<end<<"] "
|
||||||
<<(positive?"+":"-")<<std::endl; */
|
<<(positive?"+":"-")<<std::endl; */
|
||||||
if (end<begin)
|
if (next_index(begin)==end) // Special case of (1 2^r)
|
||||||
{ i=m_path.size(); }
|
{
|
||||||
else if (next_index(begin)==end) // Special case of (1 2^r)
|
new_path.clear(); // TODO BETTER; MOREOVER THERE IS A POSSIBLE BUG IF END<BEGIN; in this case I already copied some darts which must be not copied
|
||||||
{ i=m_path.size(); }
|
i=m_path.size(); }
|
||||||
else // Normal case
|
else // Normal case
|
||||||
{ i=end+1; }
|
{ i=end+1; }
|
||||||
|
if (end<begin)
|
||||||
|
{ // Necessarily a closed path !
|
||||||
|
assert(is_closed());
|
||||||
|
copy_rest_of_path(end+1, begin, new_path);
|
||||||
|
}
|
||||||
|
else if (next_index(begin)!=end) // Special case of (1 2^r)
|
||||||
|
{ copy_rest_of_path(0, begin, new_path); }
|
||||||
|
|
||||||
transform_bracket(begin, end, new_path, positive);
|
transform_bracket(begin, end, new_path, positive);
|
||||||
res=true;
|
|
||||||
}
|
if (begin<end && next_index(begin)!=end && end<length()-1)
|
||||||
else
|
{ copy_rest_of_path(end+1, length(), new_path); }
|
||||||
{
|
|
||||||
new_path.push_back(m_path[i]); // We copy this dart
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i==m_path.size()-1)
|
|
||||||
{ new_path.push_back(m_path[m_path.size()-1]); }
|
|
||||||
|
|
||||||
new_path.swap(m_path);
|
new_path.swap(m_path);
|
||||||
return res;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bracket_flattening()
|
bool bracket_flattening()
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ void simplify_path(CGAL::Path_on_surface<LCC_3_cmap>& path,
|
||||||
if (draw)
|
if (draw)
|
||||||
{
|
{
|
||||||
v.push_back(&path);
|
v.push_back(&path);
|
||||||
display(path.get_map(), v);
|
// display(path.get_map(), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL::Path_on_surface<LCC_3_cmap>* prevp=&path;
|
CGAL::Path_on_surface<LCC_3_cmap>* prevp=&path;
|
||||||
|
|
@ -31,32 +31,41 @@ void simplify_path(CGAL::Path_on_surface<LCC_3_cmap>& path,
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
curp=new CGAL::Path_on_surface<LCC_3_cmap>(*prevp);
|
curp=new CGAL::Path_on_surface<LCC_3_cmap>(*prevp);
|
||||||
|
/* std::cout<<"+ "; curp->display_negative_turns();
|
||||||
|
std::cout<<"- "; curp->display_positive_turns();
|
||||||
|
std::cout<<" -> "<<std::flush; */
|
||||||
|
|
||||||
if (curp->bracket_flattening_one_step())
|
if (curp->bracket_flattening_one_step())
|
||||||
{
|
{
|
||||||
if (draw) { v.push_back(curp); }
|
if (draw) { v.push_back(curp); }
|
||||||
prevp=curp;
|
prevp=curp;
|
||||||
|
|
||||||
|
/* std::cout<<"+ "; curp->display_negative_turns();
|
||||||
|
std::cout<<"- "; curp->display_positive_turns();
|
||||||
|
std::cout<<std::endl; */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete curp;
|
|
||||||
curp=NULL;
|
|
||||||
}
|
|
||||||
if (draw /* && nbtest==1*/)
|
|
||||||
display(path.get_map(), v);
|
|
||||||
}
|
|
||||||
while(curp!=NULL);
|
|
||||||
|
|
||||||
curp=new CGAL::Path_on_surface<LCC_3_cmap>(*prevp);
|
|
||||||
if (curp->remove_spurs())
|
if (curp->remove_spurs())
|
||||||
{
|
{
|
||||||
if (draw) { v.push_back(curp); }
|
if (draw) { v.push_back(curp); }
|
||||||
prevp=curp;
|
prevp=curp;
|
||||||
|
|
||||||
|
/* std::cout<<"+ "; curp->display_negative_turns();
|
||||||
|
std::cout<<"- "; curp->display_positive_turns();
|
||||||
|
std::cout<<std::endl; */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete curp;
|
delete curp;
|
||||||
curp=NULL;
|
curp=NULL;
|
||||||
|
// std::cout<<"unchanged."<<std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// if (draw /* && nbtest==1*/)
|
||||||
|
// display(path.get_map(), v);
|
||||||
|
}
|
||||||
|
while(curp!=NULL);
|
||||||
|
|
||||||
if (draw)
|
if (draw)
|
||||||
{ display(path.get_map(), v); }
|
{ display(path.get_map(), v); }
|
||||||
|
|
@ -245,7 +254,7 @@ void test_all_cases_spurs_and_bracket()
|
||||||
generate_negative_bracket_special2(path);
|
generate_negative_bracket_special2(path);
|
||||||
std::cout<<"Negative special case 1 (-1 -2^10): "<<std::flush;
|
std::cout<<"Negative special case 1 (-1 -2^10): "<<std::flush;
|
||||||
path.display_negative_turns();
|
path.display_negative_turns();
|
||||||
simplify_path(path, true);
|
simplify_path(path, false);
|
||||||
std::cout<<" -> +"; path.display_positive_turns();
|
std::cout<<" -> +"; path.display_positive_turns();
|
||||||
std::cout<<" -"; path.display_negative_turns(); std::cout<<std::endl;
|
std::cout<<" -"; path.display_negative_turns(); std::cout<<std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@
|
||||||
#ifndef CGAL_LINEAR_CELL_COMPLEX_CONSTRUCTORS_H
|
#ifndef CGAL_LINEAR_CELL_COMPLEX_CONSTRUCTORS_H
|
||||||
#define CGAL_LINEAR_CELL_COMPLEX_CONSTRUCTORS_H 1
|
#define CGAL_LINEAR_CELL_COMPLEX_CONSTRUCTORS_H 1
|
||||||
|
|
||||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
|
||||||
#include <CGAL/IO/File_header_OFF.h>
|
#include <CGAL/IO/File_header_OFF.h>
|
||||||
#include <CGAL/IO/File_scanner_OFF.h>
|
#include <CGAL/IO/File_scanner_OFF.h>
|
||||||
|
#include <CGAL/IO/File_writer_OFF.h>
|
||||||
#include <CGAL/Linear_cell_complex_incremental_builder.h>
|
#include <CGAL/Linear_cell_complex_incremental_builder.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue