xc
PlanePolyline3d.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Planepolyline3d.h
22 
23 #ifndef PLANEPOLYLINE3D_H
24 #define PLANEPOLYLINE3D_H
25 
26 #include "utility/geom/d2/D2to3d.h"
27 #include "utility/geom/pos_vec/Vector3d.h"
28 #include "utility/geom/d1/Polyline2d.h"
29 #include "../cgal_types.h"
30 #include "utility/geom/d2/Plane.h"
31 
32 class VectorPos3d;
33 
35 //
37 class PlanePolyline3d: public D2to3d
38  {
39  public:
40  typedef Polyline2d::iterator iterator;
41  typedef Polyline2d::const_iterator const_iterator;
42  protected:
43  Polyline2d pline2d;
44 
45  inline Pos2d computePos2d(const Pos3d &p) const
46  {
47  const Plane plane= this->getPlane(); // Get the plane containing the polyline.
48  const Pos3d prj= plane.Projection(p); // Compute projection.
49  const Pos2d p2d(to_2d(prj)); // Convert to 2D.
50  return p2d;
51  }
52  public:
53  PlanePolyline3d(void): D2to3d(),pline2d() {}
54  template <typename InputIterator>
55  explicit PlanePolyline3d(InputIterator first,InputIterator last);
56  PlanePolyline3d(const Pos3d &p1,const Pos3d &p2,const Pos3d &p3);
57  PlanePolyline3d(const Ref2d3d &,const Polyline2d &p= Polyline2d());
58  PlanePolyline3d(const Ref3d3d &,const Polyline2d &p= Polyline2d());
59  explicit PlanePolyline3d(const GeomObj::list_Pos3d &);
60  explicit PlanePolyline3d(const boost::python::list &);
61 
62  virtual GeomObj *getCopy(void) const
63  { return new PlanePolyline3d(*this); }
64 
65  inline void push_back(const Pos3d &p)
66  { pline2d.push_back(to_2d(p)); }
67 
68  Pos3d getFromPoint(void) const
69  { return to_3d(this->pline2d.getFromPoint()); }
70 
71  Pos3d getToPoint(void) const
72  { return to_3d(this->pline2d.getToPoint()); }
73 
74  PlanePolyline3d offset(const GEOM_FT &d) const;
75  Polygon3d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices= 8) const;
76 
77  bool empty(void) const;
78  GEOM_FT GetXMax(void) const;
79  GEOM_FT GetYMax(void) const;
80  GEOM_FT GetZMax(void) const;
81  GEOM_FT GetXMin(void) const;
82  GEOM_FT GetYMin(void) const;
83  GEOM_FT GetZMin(void) const;
84 
85  inline virtual unsigned int getNumVertices(void) const
86  { return pline2d.getNumVertices(); }
87  inline virtual unsigned int getNumSegments(void) const
88  { return pline2d.getNumSegments(); }
90  inline GEOM_FT getLength(void) const
91  { return pline2d.getLength(); }
92  inline std::vector<GEOM_FT> getLengths(void) const
93  { return pline2d.getLengths(); }
94  inline boost::python::list getLengthsPy(void) const
95  { return pline2d.getLengthsPy(); }
96  GEOM_FT getLengthUpTo(const Pos3d &) const;
97  inline GEOM_FT getLambda(const Pos3d &p) const
98  { return getLengthUpTo(p); }
99  bool isClosed(const GEOM_FT &tol= 1e-6) const;
100  const_iterator getSegmentAtLength(const GEOM_FT &s) const;
101  int getIndexOfSegmentAtLength(const GEOM_FT &s) const;
102  int getIndexOfSegmentAtParam(const GEOM_FT &lambda) const;
103  const Pos3d appendVertex(const Pos3d &);
104  const Pos3d appendVertexLeft(const Pos3d &);
105  void insertVertex(const Pos3d &, const GEOM_FT &tol= 1e-6);
106 
108  inline Pos3d Vertice(unsigned int i) const
109  { return to_3d(pline2d.Vertice(i)); }
112  inline Pos3d Vertice0(unsigned int j) const
113  { return to_3d(pline2d.Vertice0(j)); }
115  boost::python::list getVertexListPy(void) const;
116  Segment3d getSegment0(unsigned int i) const;
117  Segment3d getSegment(unsigned int i) const;
118  Polyline3d getPolyline3d(void) const;
119 
120  Pos3d getPointAtLength(const GEOM_FT &) const;
121  Vector3d getIVectorAtLength(const GEOM_FT &) const;
122  Vector3d getJVectorAtLength(const GEOM_FT &) const;
123  Vector3d getKVectorAtLength(const GEOM_FT &) const;
124 
125  VectorPos3d Divide(int num_partes) const;
126  boost::python::list DividePy(int num_partes) const;
127  VectorPos3d Divide(const std::vector<double> &) const;
128  boost::python::list DividePy(const boost::python::list &) const;
129 
130  void swap(void);
131 
132  Plane getPlaneFromSide0(unsigned int i) const;
133  Plane getPlaneFromSide(unsigned int i) const;
134 
135  Pos3d getCenterOfMass(void) const;
136  GEOM_FT Ix(void) const;
137  GEOM_FT Iy(void) const;
138  GEOM_FT Iz(void) const;
139 
140  GEOM_FT GetMax(unsigned short int i) const;
141  GEOM_FT GetMin(unsigned short int i) const;
142  bool In(const Pos3d &p,const double &tol) const;
143  bool TocaCuadrante(const int &) const;
144  Segment3d getNearestSegment(const Pos3d &) const;
145  Pos3d Projection(const Pos3d &) const;
146 
147  // GEOM_FT distSigno(const Pos3d &p) const;
148  // GEOM_FT dist(const Pos3d &p) const;
149  // GEOM_FT distSigno2(const Pos3d &p) const;
150  // GEOM_FT dist2(const Pos3d &p) const;
151 
152  bool intersects(const Line3d &) const;
154  bool intersects(const Plane &) const;
156 
157  void simplify(GEOM_FT epsilon, iterator it1, iterator it2);
158  void simplify(GEOM_FT epsilon);
159  void removeRepeated(const GEOM_FT &tol= 0.0);
160  void removeBackwardSegments(const GEOM_FT &tol);
161  PlanePolyline3d getChunk(const Pos3d &,const short int &, const GEOM_FT &) const;
162  PlanePolyline3d getLeftChunk(const Pos3d &, const GEOM_FT &tol) const;
163  PlanePolyline3d getRightChunk(const Pos3d &, const GEOM_FT &tol) const;
164  boost::python::list split(const Pos3d &) const;
165 
166  void Print(std::ostream &os) const;
167  };
168 
169 template <typename InputIterator>
170 PlanePolyline3d::PlanePolyline3d(InputIterator begin,InputIterator end)
171  : D2to3d(), pline2d()
172  {
173  Plane p(begin, end);
174  auto i= begin;
175  const Pos3d A= *i; i++;
176  const Pos3d B= *i; i++;
177  const Pos3d C= *i;
178  const Ref2d3d ref= Ref2d3d(*begin,p.Base1(), p.Base2());
179  PlanePolyline3d tmp(ref);
180  for(InputIterator i= begin; i!= end; i++)
181  tmp.push_back(*i);
182  (*this)= tmp;
183 
184  }
185 
186 #endif
Pos2d to_2d(const Pos3d &) const
Return the 2D point corresponding to the 3D point argument.
Definition: D2to3d.cc:132
VectorPos3d Divide(int num_partes) const
Return the points that results from the segment division.
Definition: PlanePolyline3d.cc:411
PlanePolyline3d getRightChunk(const Pos3d &, const GEOM_FT &tol) const
Return the polyline chunk that goes the nearest vertex to to p to its end.
Definition: PlanePolyline3d.cc:307
std::vector< GEOM_FT > getLengths(void) const
Return the lengths corresponding to each vertex.
Definition: PolyPos.h:195
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: PlanePolyline3d.cc:339
const Pos3d appendVertex(const Pos3d &)
Append the projection of the vertex to the polyline.
Definition: PlanePolyline3d.cc:256
Plane polygon in a 3D space.
Definition: Polygon3d.h:35
void insertVertex(const Pos3d &, const GEOM_FT &tol=1e-6)
Insert the point argurment as vertex by splitting the nearest segment.
Definition: PlanePolyline3d.cc:277
Segment3d getNearestSegment(const Pos3d &) const
Return the nearest 2D segment.
Definition: PlanePolyline3d.cc:213
Segment en tres dimensiones.
Definition: Segment3d.h:41
Base class for position lists.
Definition: PolyPos.h:35
void removeRepeated(const GEOM_FT &tol=0.0)
Remove vertices that are closer than the given tolerance.
Definition: PlanePolyline3d.cc:684
const Pos2d & Vertice(const size_t &) const
Return the i-th vertex (the first one has the index 1).
Definition: Polyline2d.cc:311
Polyline3d getPolyline3d(void) const
Return the corresponding 3D polyline.
Definition: PlanePolyline3d.cc:364
Posición en dos dimensiones.
Definition: Pos2d.h:41
Segment3d getSegment0(unsigned int i) const
Return the i-th side (i between 0 and num_sides-1).
Definition: PlanePolyline3d.cc:357
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: PlanePolyline3d.cc:332
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: PlanePolyline3d.cc:346
Vector3d Base1(void) const
Return un vector ortogonal al devuelto por Normal().
Definition: Plane.cc:145
PlanePolyline3d getLeftChunk(const Pos3d &, const GEOM_FT &tol) const
Return the polyline chunk that goes from its beginning to the nearest vertex to p.
Definition: PlanePolyline3d.cc:297
Polyline in a three-dimensional space.
Definition: Polyline3d.h:37
Vector3d getIVectorAtLength(const GEOM_FT &) const
Return the I vector of the segment that lies at the point at a distance "s" measured along the polyli...
Definition: PlanePolyline3d.cc:382
Vector3d getKVectorAtLength(const GEOM_FT &) const
Return the K vector of the segment that lies at the point at a distance "s" measured along the polyli...
Definition: PlanePolyline3d.cc:402
Plane in a three-dimensional space.
Definition: Plane.h:49
PlanePolyline3d getChunk(const Pos3d &, const short int &, const GEOM_FT &) const
Assuming that p is a vertex of the polyline Return the chunk: from the beginning to p if sgn < 0 from...
Definition: PlanePolyline3d.cc:287
bool isClosed(const GEOM_FT &tol=1e-6) const
Returns true if the polyline is closed.
Definition: PlanePolyline3d.cc:325
Pos3d Vertice0(unsigned int j) const
Return the position of the i-th vertex (0 based: j=0..getNumVertices()-1)
Definition: PlanePolyline3d.h:112
GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: PlanePolyline3d.cc:535
Pos3d Projection(const Pos3d &) const
Return the projection of the given point into the polyline.
Definition: PlanePolyline3d.cc:241
bool empty(void) const
Return true if there are no vertices.
Definition: PlanePolyline3d.cc:100
Pos3d Vertice(unsigned int i) const
Return the position of the i-th vertex.
Definition: PlanePolyline3d.h:108
boost::python::list DividePy(int num_partes) const
Return a Python list containing the points that results from the segment division.
Definition: PlanePolyline3d.cc:426
GEOM_FT getLengthUpTo(const Pos3d &) const
Return the length along the polyline upto the given point.
Definition: PlanePolyline3d.cc:249
const Pos2d & Vertice0(const size_t &) const
Return the i-th vertex (the first one has the index 0).
Definition: Polyline2d.cc:315
bool TocaCuadrante(const int &) const
Return true if alguno de los vertices toca el cuadrante que se pasa como parámetro.
Definition: PlanePolyline3d.cc:643
GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: PlanePolyline3d.cc:530
const Pos3d appendVertexLeft(const Pos3d &)
Append a vertex to the beginning of the polyline.
Definition: PlanePolyline3d.cc:266
GeomObj::list_Pos3d getVertexList(void) const
Return a Python list containing the positions of the polyline vertices.
Definition: PlanePolyline3d.cc:78
void simplify(GEOM_FT epsilon, iterator it1, iterator it2)
Douglas Peucker algorithm implementation.
Definition: PlanePolyline3d.cc:674
GEOM_FT getLength(void) const
Return the length of the object.
Definition: PlanePolyline3d.h:90
Class that places 2D objects (circle, ellipse, polygons, ...) in a 3D space.
Definition: D2to3d.h:44
Segment3d getSegment(unsigned int i) const
Return the i-th edge (i between 1 and num_sides).
Definition: PlanePolyline3d.cc:350
virtual GEOM_FT getLength(void) const
Return the length of the object.
Definition: Polyline2d.h:104
Pos3d getPointAtLength(const GEOM_FT &) const
Return the the point at a distance "s" measured along the polyline from its origin.
Definition: PlanePolyline3d.cc:372
Vector3d Base2(void) const
Return un vector ortogonal al devuelto por Normal() y al devuelto por Base1().
Definition: Plane.cc:152
D2to3d(void)
Constructor.
Definition: D2to3d.cc:40
void removeBackwardSegments(const GEOM_FT &tol)
Remove emove the vertices that generate backward segments.
Definition: PlanePolyline3d.cc:689
GEOM_FT Ix(void) const
Moment of inertia with respect to an axis parallel to the x axis passing through the center of mass...
Definition: PlanePolyline3d.cc:505
Pos3d Projection(const Pos3d &) const
Return the projection of the point onto this plane.
Definition: Plane.cc:176
GEOM_FT Iz(void) const
Moment of inertia with respect to an axis parallel to the z axis passing through the center of mass...
Definition: PlanePolyline3d.cc:523
Posición en tres dimensiones.
Definition: Pos3d.h:44
Line in a three-dimensional space.
Definition: Line3d.h:62
boost::python::list getLengthsPy(void) const
Return the lengths corresponding to each vertex in a Python list.
Definition: PolyPos.h:217
Vector3d getJVectorAtLength(const GEOM_FT &) const
Return the J vector of the segment that lies at the point at a distance "s" measured along the polyli...
Definition: PlanePolyline3d.cc:392
Pos3d getCenterOfMass(void) const
Return the center of mass of the polyline.
Definition: PlanePolyline3d.cc:497
Polyline in a two-dimensional space.
Definition: Polyline2d.h:41
Vector de posiciones en tres dimensiones [(x1,y1,z1),(x1,y2,z2),...].
Definition: VectorPos3d.h:32
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
GeomObj3d::list_Pos3d getIntersection(const Line3d &) const
Return the intersection with the line argument.
Definition: PlanePolyline3d.cc:613
Plane polygon in a 3D space.
Definition: PlanePolyline3d.h:37
bool intersects(const Line3d &) const
Return true if the line intersects the polyline.
Definition: PlanePolyline3d.cc:595
Vector en tres dimensiones.
Definition: Vector3d.h:39
Two-dimensional reference system defined in a three-dimensional space.
Definition: Ref2d3d.h:41
bool In(const Pos3d &p, const double &tol) const
Return true if the point lies inside the polyline (i.
Definition: PlanePolyline3d.cc:481
GEOM_FT Iy(void) const
Moment of inertia with respect to an axis parallel to the y axis passing through the center of mass...
Definition: PlanePolyline3d.cc:514
Three-dimensional reference system defined in a three-dimensional space.
Definition: Ref3d3d.h:39
boost::python::list getVertexListPy(void) const
Return a Python list containing the positions of the polyline vertices.
Definition: PlanePolyline3d.cc:89
Pos3d to_3d(const Pos2d &) const
Return the 3D point corresponding to the 2D point argument.
Definition: D2to3d.cc:100