OpenWalnut  1.5.0dev
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 <vector>
29 
30 #include "../WBoundingBox.h"
31 
32 #include "../WMixinVector.h"
33 #include "linearAlgebra/WPosition.h"
34 
35 // forward declarations
36 class WLineTest;
37 
38 /**
39  * A line is an ordered sequence of WPositions.
40  */
41 class WLine : public WMixinVector< WPosition >
42 {
43 public:
44  /**
45  * Generates a new line out of a sequence of points.
46  *
47  * \param points Point sequence
48  */
49  explicit WLine( const std::vector< WPosition > &points );
50 
51  /**
52  * Creates an empty line.
53  */
54  WLine();
55 
56  /**
57  * Resample this line so it has a number of given points afterwards.
58  * \warning This changes your line!
59  *
60  * \param numPoints Number of sampling points.
61  */
62  void resampleByNumberOfPoints( size_t numPoints );
63 
64  /**
65  * Resample this line so there are only segements of the given length.
66  *
67  * \warning This may shorten fib if new segment length is bigger than the remainder of the original fiber under the new sampling.
68  *
69  * \param newSegementLength
70  */
71  void resampleBySegmentLength( double newSegementLength );
72 
73  /**
74  * Resample this line so there are only segements of the given length.
75  *
76  * \note There will be segments of length < newSegmentLength at the ends of the lines; no lines will be discarded.
77  *
78  * \param newSegmentLength
79  */
80  void resampleBySegmentLengthKeepShortFibers( double newSegmentLength );
81 
82  /**
83  * Reverses the order of the points. (mirroring)
84  */
85  void reverseOrder();
86 
87  /**
88  * Collapse samplepoints which are equal and neighboured.
89  */
91 
92  /**
93  * Put the line into reverse ordering if the reverse ordering would have a
94  * similar direction to the given line. That means if the start point (or
95  * multiple selected sample points) of the given line will better match to
96  * end point (or multiple selected sample points) of this line (in term of
97  * direction) the line is reordered.
98  *
99  * \param other The line giving the direction to align this line to.
100  */
101  void unifyDirectionBy( const WLine& other );
102 };
103 
104 // Some convinience functions as non-member non-friend functions
105 
106 /**
107  * Computes a AABB (axis aligned bounding box) for all positions inside this line.
108  *
109  * \param line The line to compute the bounding box for.
110  *
111  * \return The AABB for this line.
112  */
113 WBoundingBox computeBoundingBox( const WLine& line );
114 
115 /**
116  * Computes the length of a line in terms of accumulated segment lengths.
117  *
118  * \param line The line which used for computations
119  *
120  * \return Sum of all line segment lengths
121  */
122 double pathLength( const WLine& line );
123 
124 /**
125  * Returns the point in the middle of a line. In case of an even sized
126  * line the mid point is the same as if there were only size()-1 many
127  * elements present.
128  *
129  * \param line The line to compute the mid point for.
130  *
131  * \throws WOutOfBounds In case its called on an empty line
132  *
133  * \return Const reference to the midpoint element.
134  */
135 const WPosition& midPoint( const WLine& line );
136 
137 /**
138  * Compares two lines with each other point wise upto a given delta.
139  *
140  * \param line The first line
141  * \param other The other line
142  * \param delta Specifying the environment upto this two points are considered to be the same
143  *
144  * \return -1 in case of the two fibers are considered equal, otherwise the first position on which they differ is returned.
145  */
146 int equalsDelta( const WLine& line, const WLine& other, double delta );
147 
148 /**
149  * Compute the maximal segment length of all segements of a line. If there are no segements meaning
150  * zero or one point, zero is returned.
151  *
152  * \param line The line used for computation of the max segment length
153  *
154  * \return Max segement length or zero if there aren't any.
155  */
156 double maxSegmentLength( const WLine& line );
157 
158 /**
159  * Boolean predicate indicating that the first line has more points then
160  * the second one.
161  *
162  * \param first First line
163  * \param second Second line
164  * \return True if the first line has more points than the second
165  */
166 bool hasMorePointsThen( const WLine& first, const WLine& second );
167 
168 inline bool hasMorePointsThen( const WLine& first, const WLine& second )
169 {
170  return first.size() > second.size();
171 }
172 
173 #endif // WLINE_H
Unit tests the WLine class.
Definition: WLine_test.h:43
A line is an ordered sequence of WPositions.
Definition: WLine.h:42
void resampleByNumberOfPoints(size_t numPoints)
Resample this line so it has a number of given points afterwards.
Definition: WLine.cpp:78
void unifyDirectionBy(const WLine &other)
Put the line into reverse ordering if the reverse ordering would have a similar direction to the give...
Definition: WLine.cpp:310
void resampleBySegmentLengthKeepShortFibers(double newSegmentLength)
Resample this line so there are only segements of the given length.
Definition: WLine.cpp:209
void reverseOrder()
Reverses the order of the points.
Definition: WLine.cpp:62
void removeAdjacentDuplicates()
Collapse samplepoints which are equal and neighboured.
Definition: WLine.cpp:124
void resampleBySegmentLength(double newSegementLength)
Resample this line so there are only segements of the given length.
Definition: WLine.cpp:147
WLine()
Creates an empty line.
Definition: WLine.cpp:48
This is taken from OpenSceneGraph <osg/MixinVector> but copy and pasted in order to reduce dependency...
Definition: WMixinVector.h:48
size_type size() const
Wrapper around std::vector member function.
Definition: WMixinVector.h:267
This only is a 3d double vector.