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