OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WLine.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WLINE_H
26 #define WLINE_H
27 
28 #include <algorithm>
29 #include <iostream>
30 #include <vector>
31 
32 #include "../WBoundingBox.h"
33 #include "../WExportCommon.h"
34 #include "../WMixinVector.h"
35 #include "linearAlgebra/WLinearAlgebra.h"
36 
37 // forward declarations
38 class WLineTest;
39 
40 /**
41  * A line is an ordered sequence of WPositions.
42  */
43 class OWCOMMON_EXPORT WLine : public WMixinVector< WPosition >
44 {
45 public:
46  /**
47  * Generates a new line out of a sequence of points.
48  *
49  * \param points Point sequence
50  */
51  explicit WLine( const std::vector< WPosition > &points );
52 
53  /**
54  * Creates an empty line.
55  */
56  WLine();
57 
58  /**
59  * Resample this line so it has a number of given points afterwards.
60  * \warning This changes your line!
61  *
62  * \param numPoints Number of sampling points.
63  */
64  void resampleByNumberOfPoints( size_t numPoints );
65 
66  /**
67  *
68  *
69  * \warning This may elongate your line at max. by the newSegmentLength
70  *
71  * \param newSegementLength
72  */
73  void resampleBySegmentLength( double newSegementLength );
74 
75  /**
76  * Reverses the order of the points. (mirroring)
77  */
78  void reverseOrder();
79 
80  /**
81  * Collapse samplepoints which are equal and neighboured.
82  */
83  void removeAdjacentDuplicates();
84 
85  /**
86  * Put the line into reverse ordering if the reverse ordering would have a
87  * similar direction to the given line. That means if the start point (or
88  * multiple selected sample points) of the given line will better match to
89  * end point (or multiple selected sample points) of this line (in term of
90  * direction) the line is reordered.
91  *
92  * \param other The line giving the direction to align this line to.
93  */
94  void unifyDirectionBy( const WLine& other );
95 };
96 
97 // Some convinience functions as non-member non-friend functions
98 
99 /**
100  * Computes a AABB (axis aligned bounding box) for all positions inside this line.
101  *
102  * \param line The line to compute the bounding box for.
103  *
104  * \return The AABB for this line.
105  */
106 OWCOMMON_EXPORT WBoundingBox computeBoundingBox( const WLine& line );
107 
108 /**
109  * Computes the length of a line in terms of accumulated segment lengths.
110  *
111  * \param line The line which used for computations
112  *
113  * \return Sum of all line segment lengths
114  */
115 OWCOMMON_EXPORT double pathLength( const WLine& line );
116 
117 /**
118  * Returns the point in the middle of a line. In case of an even sized
119  * line the mid point is the same as if there were only size()-1 many
120  * elements present.
121  *
122  * \param line The line to compute the mid point for.
123  *
124  * \throws WOutOfBounds In case its called on an empty line
125  *
126  * \return Const reference to the midpoint element.
127  */
128 OWCOMMON_EXPORT const WPosition& midPoint( const WLine& line );
129 
130 /**
131  * Compares two lines with each other point wise upto a given delta.
132  *
133  * \param line The first line
134  * \param other The other line
135  * \param delta Specifying the environment upto this two points are considered to be the same
136  *
137  * \return -1 in case of the two fibers are considered equal, otherwise the first position on which they differ is returned.
138  */
139 OWCOMMON_EXPORT int equalsDelta( const WLine& line, const WLine& other, double delta );
140 
141 /**
142  * Compute the maximal segment length of all segements of a line. If there are no segements meaning
143  * zero or one point, zero is returned.
144  *
145  * \param line The line used for computation of the max segment length
146  *
147  * \return Max segement length or zero if there aren't any.
148  */
149 OWCOMMON_EXPORT double maxSegmentLength( const WLine& line );
150 
151 /**
152  * Boolean predicate indicating that the first line has more points then
153  * the second one.
154  *
155  * \param first First line
156  * \param second Second line
157  * \return True if the first line has more points than the second
158  */
159 bool hasMorePointsThen( const WLine& first, const WLine& second );
160 
161 inline bool hasMorePointsThen( const WLine& first, const WLine& second )
162 {
163  return first.size() > second.size();
164 }
165 
166 #endif // WLINE_H