27 #include "../cgal_types.h" 28 #include "utility/utils/misc_utils/matem.h" 29 #include "utility/geom/proximity.h" 38 typedef std::deque<pos> deque_pos;
40 static GEOM_FT g(GEOM_FT v1, GEOM_FT v2)
41 {
return (sqr(v1) + v1 * v2 + sqr(v2)); }
43 typedef typename deque_pos::iterator iterator;
44 typedef typename deque_pos::const_iterator const_iterator;
45 typedef typename pos::vector vector;
48 void simplify_select(GEOM_FT epsilon, iterator it1, iterator it2, std::set<const_iterator> &selected);
50 void select_repeated(std::set<const_iterator> &selected,
const GEOM_FT &tol= 0.0);
56 explicit PolyPos(
const std::deque<pos> &dq_pos)
57 : std::deque<pos>(dq_pos) {}
59 pos getFromPoint(
void)
const 60 {
return this->front(); }
62 pos getToPoint(
void)
const 63 {
return this->back(); }
67 return ( (
const deque_pos &) (*
this) == (
const deque_pos &) other );
69 inline pos *Agrega(
const pos &p)
71 deque_pos::push_back(p);
72 return &(this->back());
79 template <
class InputIterator>
80 void extend(InputIterator first, InputIterator last)
82 for(InputIterator i= first;i!=last; i++)
85 void AgregaSiNuevo(
const pos &);
86 const_iterator find(
const pos &p)
const 87 {
return std::find(this->begin(),this->end(),p); }
88 iterator find(
const pos &p)
89 {
return std::find(this->begin(),this->end(),p); }
90 bool In(
const pos &p)
const;
92 bool isClosed(
const GEOM_FT &tol= 1e-6)
const;
101 GEOM_FT
GetMax(
unsigned short i)
const;
102 GEOM_FT
GetMin(
unsigned short i)
const;
103 PolyPos GetMayores(
unsigned short int i,
const GEOM_FT &d)
const;
104 PolyPos GetMenores(
unsigned short int i,
const GEOM_FT &d)
const;
118 void simplify(GEOM_FT epsilon, iterator it1, iterator it2);
125 template <
class inputIterator>
126 void Cat(inputIterator begin, inputIterator end);
133 {
return (find(p)!=this->end()); }
149 const pos &first= this->front();
150 this->push_back(first);
160 const pos &first= this->front();
161 const pos &last= this->back();
162 if(dist(first,last)<treshold)
179 if(this->size()<2)
return 0.0;
181 const_iterator last= this->end();
185 for(const_iterator i=this->begin(); i != last; i++)
188 if (j!=this->end()) temp += dist(*i,*j);
197 const size_t sz= this->size();
198 std::vector<GEOM_FT> retval(sz, 0.0);
202 const_iterator last= this->end();
205 for(const_iterator i=this->begin(); i != std::prev(last); i++, count++)
219 const std::vector<GEOM_FT> lengths= this->
getLengths();
220 boost::python::list retval;
221 for(std::vector<GEOM_FT>::const_iterator i= lengths.begin(); i!=lengths.end(); i++)
233 const_iterator retval= this->end();
234 const size_t sz= this->size();
237 std::cerr <<
"PolyPos<>::" << __FUNCTION__
238 <<
";ERROR: no segments, so no length." << std::endl;
244 retval= this->begin();
246 std::clog <<
"PolyPos<>::" << __FUNCTION__
247 <<
";WARNING: length argument: " << s
248 <<
" negative. First segment returned." 257 retval= this->begin();
259 for(const_iterator i=this->begin(); i != this->end(); i++)
275 std::clog <<
"PolyPos<>::" << __FUNCTION__
276 <<
";WARNING: length argument: " << s
277 <<
" greater than total length: " << totalLength
279 retval= this->end()-2;
294 return std::distance(this->begin(), i);
309 boost::python::list retval;
312 for(const_iterator i=this->begin();i!=this->end(); i++)
314 const GEOM_FT value= (*i)[j];
315 retval.append(value);
328 const_iterator i=this->begin();
330 for(; i != this->end(); i++)
331 retval= std::max(retval,(*i)(j));
343 const_iterator i=this->begin();
345 for(; i != this->end(); i++)
346 retval= std::min(retval,(*i)(j));
355 const size_t sz= this->size();
356 const pos org= pos();
358 if(sz<2)
return *(this->begin());
359 const_iterator i= this->begin();
360 vector vpos_center_of_mass((*i).VectorPos());
362 for(; i != this->end(); i++)
363 vpos_center_of_mass= vpos_center_of_mass + (*i).VectorPos();
364 vpos_center_of_mass= vpos_center_of_mass * (1.0/sz);
365 return org+ vpos_center_of_mass;
373 const size_t sz= this->size();
376 assert(sz==areas.size());
378 retval= *(this->begin());
381 std::deque<GEOM_FT>::const_iterator iArea= areas.begin();
382 GEOM_FT areaTot(0.0);
383 const_iterator i= this->begin();
384 vector vpos_center_of_mass((*i).VectorPos()*(*iArea));
387 for(; i != this->end(); i++)
389 vpos_center_of_mass= vpos_center_of_mass + (*i).VectorPos()*(*iArea);
394 vpos_center_of_mass= vpos_center_of_mass * (1.0/areaTot);
395 retval= pos()+vpos_center_of_mass;
407 const size_t sz= this->size();
408 if (sz<2)
return retval;
409 for(
size_t i=0; i<sz; i++)
410 retval[sz-i-1]= (*
this)[i];
418 const size_t sz= this->size();
419 static std::deque<GEOM_FT> retval;
421 const GEOM_FT grande= 10.0*getBnd((*
this)).Diagonal().
GetModulus();
422 for(
size_t i= 0;i<sz;i++)
427 for(
size_t i= 0;i<sz;i++)
429 const pos &pi= (*this)[i];
430 for(
size_t j= 0;j<sz;j++)
433 const pos &pj= (*this)[j];
435 if(d<retval[i] && d>0.0)
448 const size_t sz= this->size();
452 for(
size_t i= 0;i<sz;i++)
463 for(const_iterator j=this->begin();j != this->end();j++)
464 if ((*j)(i) > d) retval.push_back(*j);
472 for(const_iterator j=this->begin();j != this->end();j++)
473 if ((*j)(i) < d) retval.push_back(*j);
480 {
return nearest(this->begin(), this->end(),p); }
485 {
return nearest(this->begin(), this->end(),p); }
491 iterator i= this->begin();
492 iterator retval= i; i++;
493 GEOM_FT maxDist= dist(p,*retval);
495 for(;i!= this->end();i++)
524 std::cerr <<
"PolyPos<>::" << __FUNCTION__
525 <<
";must be redefined in derived classes." << std::endl;
526 return this->begin();
537 GEOM_FT localTol= 10*DBL_EPSILON;
540 const size_t sz= this->size();
543 iterator i= this->begin();
545 for(; i!= this->end(); i++)
548 const GEOM_FT d= dist(p1, p0);
564 const size_t sz= this->size();
567 iterator i= this->begin();
570 vector iVector0= (p1-p0).getNormalized();
572 for(; i!= this->end(); i++)
577 vector iVector1= (p1-p0).getNormalized();
578 dot= iVector1.GetDot(iVector0);
585 if(10*selected.size()>2*sz)
586 std::clog <<
"PolyPos<>::" << __FUNCTION__
587 <<
";WARNING: many backwards segments (" << selected.size()
588 <<
"/" << sz <<
"), check input data." 599 std::set<const_iterator> repeated;
611 std::set<const_iterator> backwards;
627 if (distance(it1, it2) <= 1)
return;
644 for(; it < it2; it++)
656 static std::deque<pos> tmp;
658 for(const_iterator i= this->begin(); i!= this->end(); i++)
659 if(selected.find(i)==selected.end())
662 this->assign(tmp.begin(), tmp.end());
675 if (distance(it1, it2) <= 1)
return;
677 std::set<const_iterator> selected;
691 const bool closed= this->
isClosed();
694 std::set<const_iterator> selected;
695 iterator i= this->begin();
706 iterator i= this->begin();
707 iterator j= this->end(); --j;
728 for(
typename PolyPos<pos>::const_iterator k= l.begin();k!=l.end();k++)
729 this->AgregaSiNuevo(*k);
735 for(
typename PolyPos<pos>::const_iterator k= l.begin();k!=l.end();k++)
740 template <
class pos>
template<
class inputIterator>
743 for(inputIterator i= begin;i!=end;i++)
748 std::ostream &operator<<(std::ostream &os,const PolyPos<pos> &l)
750 if(l.size()<1)
return os;
751 typedef typename PolyPos<pos>::const_iterator c_iterator;
752 c_iterator i= l.begin();
754 for(;i!= l.end();i++)
bool In(const pos &p) const
Return true if the points is on en la lista.
Definition: PolyPos.h:132
bool isClosed(const GEOM_FT &tol=1e-6) const
True if dist(lastPoint,firstPoint)< tol*length.
Definition: PolyPos.h:156
void simplify_select(GEOM_FT epsilon, iterator it1, iterator it2, std::set< const_iterator > &selected)
Douglas Peucker algorithm implementation.
Definition: PolyPos.h:625
std::vector< GEOM_FT > getLengths(void) const
Return the lengths corresponding to each vertex.
Definition: PolyPos.h:195
PolyPos< pos > getSwap(void) const
Return a list with the elements in reverse order.
Definition: PolyPos.h:404
Base class for position lists.
Definition: PolyPos.h:35
void remove_selected(std::set< const_iterator > &selected)
Removes the selected items.
Definition: PolyPos.h:654
virtual GEOM_FT GetModulus(void) const
Return el módulo del vector.
Definition: Vector2d.cc:193
GEOM_FT GetSeparacionMedia(void) const
Return the average distance between points.
Definition: PolyPos.h:445
void close(void)
Close the point list (insert the first point as its last one)
Definition: PolyPos.h:145
pos getCenterOfMass(void) const
Return the center of mass del polígono.
Definition: PolyPos.h:353
iterator getNearestPoint(const pos &)
Returns the nearest point from those of the list.
Definition: PolyPos.h:479
virtual iterator getFarthestPointFromSegment(iterator it1, iterator it2, GEOM_FT &pMaxDist)
Definition: PolyPos.h:522
void select_backward_segments(std::set< const_iterator > &selected, const GEOM_FT &tol)
Select backward segments.
Definition: PolyPos.h:562
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:231
void removeBackwardSegments(const GEOM_FT &tol)
remove backward segments.
Definition: PolyPos.h:609
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:291
iterator getFarthestPoint(const pos &)
Returns the farthest point from those of the list.
Definition: PolyPos.h:489
std::deque< GEOM_FT > & GetSeparaciones(void) const
Compute the distance from each point to the nearest one.
Definition: PolyPos.h:416
boost::python::list getIthCoordinates(unsigned short i) const
Return the list of values for j-th coordinate.
Definition: PolyPos.h:307
GEOM_FT GetMin(unsigned short i) const
Return the minimum value of j-th coordinate.
Definition: PolyPos.h:338
PolyPos< pos > getSimplified(GEOM_FT epsilon) const
!
Definition: PolyPos.h:718
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:302
GEOM_FT getLengthUntilVertex(const_iterator) const
Return the length of the PolyPos until the vertex pointed by the iterator.
Definition: PolyPos.h:177
pos getWeightedCenterOfMass(const std::deque< GEOM_FT > &) const
Return the center of mass del polígono.
Definition: PolyPos.h:370
GEOM_FT getLength(void) const
Return the length of the PolyPos.
Definition: PolyPos.h:169
GEOM_FT GetMax(unsigned short i) const
Return the maximum value of j-th coordinate.
Definition: PolyPos.h:323
void removeRepeated(const GEOM_FT &tol=0.0)
remove repeated vertexes.
Definition: PolyPos.h:597
boost::python::list getLengthsPy(void) const
Return the lengths corresponding to each vertex in a Python list.
Definition: PolyPos.h:217
void simplify(GEOM_FT epsilon, iterator it1, iterator it2)
Douglas Peucker algorithm implementation.
Definition: PolyPos.h:673
void select_repeated(std::set< const_iterator > &selected, const GEOM_FT &tol=0.0)
Select repeated vertexes.
Definition: PolyPos.h:535
void extend(InputIterator first, InputIterator last)
Append the vertices between [first,last) to thebefore end of the list.
Definition: PolyPos.h:80