OpenWalnut
1.3.1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
src
core
common
math
WPlane.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 WPLANE_H
26
#define WPLANE_H
27
28
#include <set>
29
30
#include <boost/shared_ptr.hpp>
31
32
#include "../../dataHandler/WGridRegular3D.h"
33
34
#include "linearAlgebra/WLinearAlgebra.h"
35
36
/**
37
* Represents a plane with a normal vector and a position in space.
38
*/
39
class
WPlane
// NOLINT
40
{
41
public
:
42
/**
43
* Constructs a plane with its normal and containing the point.
44
*
45
* \param normal Direction of the plane
46
* \param pos Position of the plane
47
*
48
* \return
49
*/
50
WPlane
(
const
WVector3d
& normal,
const
WPosition
& pos );
51
52
/**
53
* Constructs a plane with its normal and its base point/origin as well as explicitly specifying its vectors in the plane.
54
*
55
* \param normal Normal vector for the direction
56
* \param pos Base point of the plane, aka origin.
57
* \param first First vector perpendicular to the normal
58
* \param second Second vector perpendicular to the normal and linearly independent from first.
59
*
60
* \note Due to numerical stability a comparison to 0.0 is not performed. Instead the absolute value of the dot product is checked to
61
* be smaller than the FLT_EPS. FLT_EPS is used instead of DBL_EPS just numerical errors may sum up above DBL_EPS.
62
*/
63
WPlane
(
const
WVector3d
& normal,
const
WPosition
& pos,
const
WVector3d
& first,
const
WVector3d
& second );
64
65
/**
66
* Destructor.
67
*/
68
virtual
~WPlane
();
69
70
/**
71
* Determines whether a given point is in this plane or not.
72
*
73
* \param point Position to query
74
*
75
* \return True if and only if the point is in this plane.
76
*/
77
bool
isInPlane
(
WPosition
point )
const
;
78
79
/**
80
* Reset the position of the plane, normal remains the same.
81
*
82
* \param newPos New Position (point in plane).
83
*/
84
void
resetPosition
(
WPosition
newPos );
85
86
/**
87
* Computes sample points on that plane.
88
*
89
* \param grid
90
* \param stepWidth
91
*
92
* \return Set of positions on the plane
93
*/
94
boost::shared_ptr< std::set< WPosition > >
samplePoints
(
const
WGridRegular3D
& grid,
double
stepWidth );
95
96
97
/**
98
* Computes with relative coordinates a point in this plane. (0,0) means its position is returned.
99
*
100
* \param x how far along the direction of the first vector which spans the plane
101
* \param y how far along the direction of the second vector which spans the plane too
102
*
103
* \return the new calculated position
104
*/
105
WPosition
getPointInPlane
(
double
x,
double
y )
const
;
106
107
/**
108
* Returns a point in that plane.
109
*
110
* \return The point in that plane describing its position
111
*/
112
const
WPosition
&
getPosition
()
const
;
113
114
/**
115
* Returns the normal of the plane.
116
*
117
* \return Normalized normal vector.
118
*/
119
const
WVector3d
&
getNormal
()
const
;
120
121
/**
122
* Resets the vector spanning the plane. Both must be linear independent and perpendicular to the already
123
* existing normal vector. After setting the vectors they are normalized.
124
*
125
* \param first First vector spanning the plane
126
* \param second Second vector spanning the plane
127
*/
128
void
setPlaneVectors
(
const
WVector3d
& first,
const
WVector3d
& second );
129
130
/**
131
* Resets the normal of this plane.
132
*
133
* \param normal New normal for this plane.
134
*/
135
void
setNormal
(
const
WVector3d
& normal )
136
{
137
m_normal
= normalize( normal );
138
WVector3d
gen( 1, 0, 0 );
139
if
( cross( normal, gen ) ==
WVector3d
( 0, 0, 0 ) )
140
{
141
gen =
WVector3d
( 0, 1, 0 );
142
}
143
m_first
= cross( normal, gen );
144
m_first
= normalize(
m_first
);
145
m_second
= cross( normal,
m_first
);
146
m_second
= normalize(
m_second
);
147
}
148
149
// \cond Suppress_Doxygen
150
// /**
151
// * Computes sample points on that plane.
152
// *
153
// * \param grid
154
// * \param stepWidth
155
// *
156
// * \return Set of positions on the plane
157
// */
158
// boost::shared_ptr< std::set< WPosition > > samplePoints( const WGridRegular3D& grid, double stepWidth );
159
// \endcond
160
161
/**
162
* Computes a fixed number of sample points on that plane.
163
*
164
* \param stepWidth
165
* \param numX
166
* \param numY
167
*
168
* \return Set of positions on the plane
169
*/
170
boost::shared_ptr< std::set< WPosition > >
samplePoints
(
double
stepWidth,
size_t
numX,
size_t
numY )
const
;
171
172
protected
:
173
WVector3d
m_normal
;
//!< Direction of the plane
174
WPosition
m_pos
;
//!< Position of the plane specifying the center
175
WVector3d
m_first
;
//!< First vector in the plane
176
WVector3d
m_second
;
//!< Second vector in the plane
177
178
private
:
179
};
180
181
inline
const
WPosition
&
WPlane::getPosition
()
const
182
{
183
return
m_pos
;
184
}
185
186
inline
const
WVector3d
&
WPlane::getNormal
()
const
187
{
188
return
m_normal
;
189
}
190
191
#endif // WPLANE_H
Generated by
1.8.4