QGpCoreTools/Segment.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  
00020 **
00021 **  Created: 2012-04-16
00022 **  Authors:
00023 **    Marc Wathelet (ISTerre, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef SEGMENT_H
00028 #define SEGMENT_H
00029 
00030 #include "Point.h"
00031 #include "Parallelepiped.h"
00032 #include "QGpCoreToolsDLLExport.h"
00033 
00034 namespace QGpCoreTools {
00035 
00036   class QGPCORETOOLS_EXPORT Segment
00037   {
00038   public:
00039     Segment() {}
00040     Segment(const Point& p1, const Point& p2) {set(p1,p2);}
00041     Segment(double x1, double y1, double z1,
00042             double x2, double y2, double z2) {set(x1, y1, z1,
00043                                                   x2, y2, z2);}
00044     Segment(const Segment& o);
00045 
00046     enum RelativePosition {Skew, Crossing, Parallel, Aligned,
00047                            Continuous, SmallOverlap, StrongOverlap};
00048     bool intersects(const Segment& seg, Point& p) const;
00049     QVector<Segment> distanceTo(const Segment& seg, RelativePosition& relPos) const;
00050 
00051     Point point(int index) const {return _point[index];}
00052     void set(const Point& p1, const Point& p2);
00053     void set(double x1, double y1, double z1,
00054              double x2, double y2, double z2);
00055     bool includes(const Point& p, double precision=1e-10) const;
00056     double length() const {return _point[0].distanceTo(_point[1]);}
00057     Point directionVector() const;
00058     bool parallelTo(const Segment& o) const;
00059 
00060     bool isSimilar(const Segment& o, double precision) const;
00061     bool operator<(const Segment& o) const;
00062   private:
00063     inline Segment linkSegment(double sc, double tc,
00064                                Point p, const Point& u,
00065                                Point q, const Point& v) const;
00066 
00067 
00068     Point _point[2];
00069     Parallelepiped _limits;
00070   };
00071 
00072 } // namespace QGpCoreTools
00073 
00074 #endif // SEGMENT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines