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