27 #include "../cgal_types.h" 28 #include "utility/utils/misc_utils/matem.h" 29 #include "utility/geom/proximity.h" 30 #include <boost/python.hpp> 31 #include "utility/utils/misc_utils/colormod.h" 40 typedef std::deque<pos> deque_pos;
42 static GEOM_FT g(GEOM_FT v1, GEOM_FT v2)
43 {
return (sqr(v1) + v1 * v2 + sqr(v2)); }
45 typedef typename deque_pos::iterator iterator;
46 typedef typename deque_pos::const_iterator const_iterator;
47 typedef typename pos::vector vector;
50 void simplify_select(GEOM_FT epsilon, iterator it1, iterator it2, std::set<const_iterator> &selected);
52 void select_repeated(std::set<const_iterator> &selected,
const GEOM_FT &tol= 0.0);
60 : std::deque<pos>(n) {}
63 : std::deque<pos>(n, p) {}
65 explicit PolyPos(
const std::deque<pos> &dq_pos)
66 : std::deque<pos>(dq_pos) {}
68 pos getFromPoint(
void)
const 69 {
return this->front(); }
71 pos getToPoint(
void)
const 72 {
return this->back(); }
76 return ( (
const deque_pos &) (*
this) == (
const deque_pos &) other );
78 inline pos *Agrega(
const pos &p)
80 deque_pos::push_back(p);
81 return &(this->back());
88 template <
class InputIterator>
89 void extend(InputIterator first, InputIterator last)
91 for(InputIterator i= first;i!=last; i++)
94 void AgregaSiNuevo(
const pos &);
95 const_iterator find(
const pos &p)
const 96 {
return std::find(this->begin(),this->end(),p); }
97 iterator find(
const pos &p)
98 {
return std::find(this->begin(),this->end(),p); }
99 bool In(
const pos &p)
const;
101 bool isClosed(
const GEOM_FT &tol= 1e-6)
const;
110 GEOM_FT
GetMax(
unsigned short i)
const;
111 GEOM_FT
GetMin(
unsigned short i)
const;
112 PolyPos GetMayores(
unsigned short int i,
const GEOM_FT &d)
const;
113 PolyPos GetMenores(
unsigned short int i,
const GEOM_FT &d)
const;
127 void simplify(GEOM_FT epsilon, iterator it1, iterator it2);
134 template <
class inputIterator>
135 void Cat(inputIterator begin, inputIterator end);
142 {
return (find(p)!=this->end()); }
158 const pos &first= this->front();
159 this->push_back(first);
169 const pos &first= this->front();
170 const pos &last= this->back();
171 if(dist(first,last)<treshold)
188 if(this->size()<2)
return 0.0;
190 const_iterator last= this->end();
194 for(const_iterator i=this->begin(); i != last; i++)
197 if (j!=this->end()) temp += dist(*i,*j);
206 const size_t sz= this->size();
207 std::vector<GEOM_FT> retval(sz, 0.0);
211 const_iterator last= this->end();
214 for(const_iterator i=this->begin(); i != std::prev(last); i++, count++)
228 const std::vector<GEOM_FT> lengths= this->
getLengths();
229 boost::python::list retval;
230 for(std::vector<GEOM_FT>::const_iterator i= lengths.begin(); i!=lengths.end(); i++)
242 const_iterator retval= this->end();
243 const size_t sz= this->size();
246 std::cerr << Color::red <<
"PolyPos<>::" << __FUNCTION__
247 <<
";ERROR: no segments, so no length." 248 << Color::def << std::endl;
254 retval= this->begin();
256 std::clog << Color::yellow <<
"PolyPos<>::" << __FUNCTION__
257 <<
";WARNING: length argument: " << s
258 <<
" negative. First segment returned." 259 << Color::def << std::endl;
267 retval= this->begin();
269 for(const_iterator i=this->begin(); i != this->end(); i++)
285 std::clog << Color::yellow <<
"PolyPos<>::" << __FUNCTION__
286 <<
";WARNING: length argument: " << s
287 <<
" greater than total length: " << totalLength
288 << Color::def << std::endl;
289 retval= this->end()-2;
304 return std::distance(this->begin(), i);
319 boost::python::list retval;
322 for(const_iterator i=this->begin();i!=this->end(); i++)
324 const GEOM_FT value= (*i)[j];
325 retval.append(value);
338 const_iterator i=this->begin();
340 for(; i != this->end(); i++)
341 retval= std::max(retval,(*i)(j));
353 const_iterator i=this->begin();
355 for(; i != this->end(); i++)
356 retval= std::min(retval,(*i)(j));
365 const size_t sz= this->size();
366 const pos org= pos();
368 if(sz<2)
return *(this->begin());
369 const_iterator i= this->begin();
370 vector vpos_center_of_mass((*i).VectorPos());
372 for(; i != this->end(); i++)
373 vpos_center_of_mass= vpos_center_of_mass + (*i).VectorPos();
374 vpos_center_of_mass= vpos_center_of_mass * (1.0/sz);
375 return org+ vpos_center_of_mass;
383 const size_t sz= this->size();
386 assert(sz==areas.size());
388 retval= *(this->begin());
391 std::deque<GEOM_FT>::const_iterator iArea= areas.begin();
392 GEOM_FT areaTot(0.0);
393 const_iterator i= this->begin();
394 vector vpos_center_of_mass((*i).VectorPos()*(*iArea));
397 for(; i != this->end(); i++)
399 vpos_center_of_mass= vpos_center_of_mass + (*i).VectorPos()*(*iArea);
404 vpos_center_of_mass= vpos_center_of_mass * (1.0/areaTot);
405 retval= pos()+vpos_center_of_mass;
417 const size_t sz= this->size();
418 if (sz<2)
return retval;
419 for(
size_t i=0; i<sz; i++)
420 retval[sz-i-1]= (*
this)[i];
428 const size_t sz= this->size();
429 static std::deque<GEOM_FT> retval;
431 const GEOM_FT grande= 10.0*getBnd((*
this)).Diagonal().
GetModulus();
432 for(
size_t i= 0;i<sz;i++)
437 for(
size_t i= 0;i<sz;i++)
439 const pos &pi= (*this)[i];
440 for(
size_t j= 0;j<sz;j++)
443 const pos &pj= (*this)[j];
445 if(d<retval[i] && d>0.0)
458 const size_t sz= this->size();
462 for(
size_t i= 0;i<sz;i++)
473 for(const_iterator j=this->begin();j != this->end();j++)
474 if ((*j)(i) > d) retval.push_back(*j);
482 for(const_iterator j=this->begin();j != this->end();j++)
483 if ((*j)(i) < d) retval.push_back(*j);
490 {
return nearest(this->begin(), this->end(),p); }
495 {
return nearest(this->begin(), this->end(),p); }
501 iterator i= this->begin();
502 iterator retval= i; i++;
503 GEOM_FT maxDist= dist(p,*retval);
505 for(;i!= this->end();i++)
534 std::cerr << Color::red <<
"PolyPos<>::" << __FUNCTION__
535 <<
";must be redefined in derived classes." 536 << Color::def << std::endl;
537 return this->begin();
548 GEOM_FT localTol= 10*DBL_EPSILON;
551 const size_t sz= this->size();
554 iterator i= this->begin();
556 for(; i!= this->end(); i++)
559 const GEOM_FT d= dist(p1, p0);
575 const size_t sz= this->size();
578 iterator i= this->begin();
581 vector iVector0= (p1-p0).getNormalized();
583 for(; i!= this->end(); i++)
588 vector iVector1= (p1-p0).getNormalized();
589 dot= iVector1.GetDot(iVector0);
596 if(10*selected.size()>2*sz)
597 std::clog << Color::yellow <<
"PolyPos<>::" << __FUNCTION__
598 <<
";WARNING: many backwards segments (" << selected.size()
599 <<
"/" << sz <<
"), check input data." 600 << Color::def << std::endl;
610 std::set<const_iterator> repeated;
622 std::set<const_iterator> backwards;
638 if (distance(it1, it2) <= 1)
return;
655 for(; it < it2; it++)
667 static std::deque<pos> tmp;
669 for(const_iterator i= this->begin(); i!= this->end(); i++)
670 if(selected.find(i)==selected.end())
673 this->assign(tmp.begin(), tmp.end());
686 if (distance(it1, it2) <= 1)
return;
688 std::set<const_iterator> selected;
702 const bool closed= this->
isClosed();
705 std::set<const_iterator> selected;
706 iterator i= this->begin();
717 iterator i= this->begin();
718 iterator j= this->end(); --j;
739 for(
typename PolyPos<pos>::const_iterator k= l.begin();k!=l.end();k++)
740 this->AgregaSiNuevo(*k);
746 for(
typename PolyPos<pos>::const_iterator k= l.begin();k!=l.end();k++)
751 template <
class pos>
template<
class inputIterator>
754 for(inputIterator i= begin;i!=end;i++)
759 std::ostream &operator<<(std::ostream &os,const PolyPos<pos> &l)
761 if(l.size()<1)
return os;
762 typedef typename PolyPos<pos>::const_iterator c_iterator;
763 c_iterator i= l.begin();
765 for(;i!= l.end();i++)
bool In(const pos &p) const
Return true if the points is on en la lista.
Definition: PolyPos.h:141
bool isClosed(const GEOM_FT &tol=1e-6) const
True if dist(lastPoint,firstPoint)< tol*length.
Definition: PolyPos.h:165
void simplify_select(GEOM_FT epsilon, iterator it1, iterator it2, std::set< const_iterator > &selected)
Douglas Peucker algorithm implementation.
Definition: PolyPos.h:636
std::vector< GEOM_FT > getLengths(void) const
Return the lengths corresponding to each vertex.
Definition: PolyPos.h:204
PolyPos< pos > getSwap(void) const
Return a list with the elements in reverse order.
Definition: PolyPos.h:414
Base class for position lists.
Definition: PolyPos.h:37
void remove_selected(std::set< const_iterator > &selected)
Removes the selected items.
Definition: PolyPos.h:665
virtual GEOM_FT GetModulus(void) const
Return el módulo del vector.
Definition: Vector2d.cc:248
GEOM_FT GetSeparacionMedia(void) const
Return the average distance between points.
Definition: PolyPos.h:455
void close(void)
Close the point list (insert the first point as its last one)
Definition: PolyPos.h:154
pos getCenterOfMass(void) const
Return the center of mass del polígono.
Definition: PolyPos.h:363
iterator getNearestPoint(const pos &)
Returns the nearest point from those of the list.
Definition: PolyPos.h:489
virtual iterator getFarthestPointFromSegment(iterator it1, iterator it2, GEOM_FT &pMaxDist)
Definition: PolyPos.h:532
void select_backward_segments(std::set< const_iterator > &selected, const GEOM_FT &tol)
Select backward segments.
Definition: PolyPos.h:573
const_iterator getSegmentAtLength(const GEOM_FT &s) const
Return an iterator pointing to the vertex that is just before the point at a distance "s" measured al...
Definition: PolyPos.h:240
void removeBackwardSegments(const GEOM_FT &tol)
remove backward segments.
Definition: PolyPos.h:620
int getIndexOfSegmentAtLength(const GEOM_FT &s) const
Return the index of the segment that lies at the point at a distance "s" measured along the polyline ...
Definition: PolyPos.h:301
iterator getFarthestPoint(const pos &)
Returns the farthest point from those of the list.
Definition: PolyPos.h:499
std::deque< GEOM_FT > & GetSeparaciones(void) const
Compute the distance from each point to the nearest one.
Definition: PolyPos.h:426
boost::python::list getIthCoordinates(unsigned short i) const
Return the list of values for j-th coordinate.
Definition: PolyPos.h:317
GEOM_FT GetMin(unsigned short i) const
Return the minimum value of j-th coordinate.
Definition: PolyPos.h:348
PolyPos< pos > getSimplified(GEOM_FT epsilon) const
!
Definition: PolyPos.h:729
int getIndexOfSegmentAtParam(const GEOM_FT &lambda) const
Return the index of the segment that lies at the point at a distance "lambda*L" measured along the po...
Definition: PolyPos.h:312
GEOM_FT getLengthUntilVertex(const_iterator) const
Return the length of the PolyPos until the vertex pointed by the iterator.
Definition: PolyPos.h:186
pos getWeightedCenterOfMass(const std::deque< GEOM_FT > &) const
Return the center of mass del polígono.
Definition: PolyPos.h:380
GEOM_FT getLength(void) const
Return the length of the PolyPos.
Definition: PolyPos.h:178
GEOM_FT GetMax(unsigned short i) const
Return the maximum value of j-th coordinate.
Definition: PolyPos.h:333
void removeRepeated(const GEOM_FT &tol=0.0)
remove repeated vertexes.
Definition: PolyPos.h:608
boost::python::list getLengthsPy(void) const
Return the lengths corresponding to each vertex in a Python list.
Definition: PolyPos.h:226
void simplify(GEOM_FT epsilon, iterator it1, iterator it2)
Douglas Peucker algorithm implementation.
Definition: PolyPos.h:684
void select_repeated(std::set< const_iterator > &selected, const GEOM_FT &tol=0.0)
Select repeated vertexes.
Definition: PolyPos.h:546
void extend(InputIterator first, InputIterator last)
Append the vertices between [first,last) to thebefore end of the list.
Definition: PolyPos.h:89