OpenWalnut
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
src
core
common
math
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
* Reverses the order of the points. (mirroring)
75
*/
76
void
reverseOrder
();
77
78
/**
79
* Collapse samplepoints which are equal and neighboured.
80
*/
81
void
removeAdjacentDuplicates
();
82
83
/**
84
* Put the line into reverse ordering if the reverse ordering would have a
85
* similar direction to the given line. That means if the start point (or
86
* multiple selected sample points) of the given line will better match to
87
* end point (or multiple selected sample points) of this line (in term of
88
* direction) the line is reordered.
89
*
90
* \param other The line giving the direction to align this line to.
91
*/
92
void
unifyDirectionBy
(
const
WLine
& other );
93
};
94
95
// Some convinience functions as non-member non-friend functions
96
97
/**
98
* Computes a AABB (axis aligned bounding box) for all positions inside this line.
99
*
100
* \param line The line to compute the bounding box for.
101
*
102
* \return The AABB for this line.
103
*/
104
WBoundingBox
computeBoundingBox(
const
WLine
& line );
105
106
/**
107
* Computes the length of a line in terms of accumulated segment lengths.
108
*
109
* \param line The line which used for computations
110
*
111
* \return Sum of all line segment lengths
112
*/
113
double
pathLength(
const
WLine
& line );
114
115
/**
116
* Returns the point in the middle of a line. In case of an even sized
117
* line the mid point is the same as if there were only size()-1 many
118
* elements present.
119
*
120
* \param line The line to compute the mid point for.
121
*
122
* \throws WOutOfBounds In case its called on an empty line
123
*
124
* \return Const reference to the midpoint element.
125
*/
126
const
WPosition
& midPoint(
const
WLine
& line );
127
128
/**
129
* Compares two lines with each other point wise upto a given delta.
130
*
131
* \param line The first line
132
* \param other The other line
133
* \param delta Specifying the environment upto this two points are considered to be the same
134
*
135
* \return -1 in case of the two fibers are considered equal, otherwise the first position on which they differ is returned.
136
*/
137
int
equalsDelta(
const
WLine
& line,
const
WLine
& other,
double
delta );
138
139
/**
140
* Compute the maximal segment length of all segements of a line. If there are no segements meaning
141
* zero or one point, zero is returned.
142
*
143
* \param line The line used for computation of the max segment length
144
*
145
* \return Max segement length or zero if there aren't any.
146
*/
147
double
maxSegmentLength(
const
WLine
& line );
148
149
/**
150
* Boolean predicate indicating that the first line has more points then
151
* the second one.
152
*
153
* \param first First line
154
* \param second Second line
155
* \return True if the first line has more points than the second
156
*/
157
bool
hasMorePointsThen(
const
WLine
& first,
const
WLine
& second );
158
159
inline
bool
hasMorePointsThen(
const
WLine
& first,
const
WLine
& second )
160
{
161
return
first.
size
() > second.
size
();
162
}
163
164
#endif // WLINE_H
Generated by
1.8.4