OpenWalnut  1.5.0dev
WPlane.cpp
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 #include <memory>
26 #include <set>
27 
28 
29 #include "../../common/WAssert.h"
30 #include "../../common/WLimits.h"
31 #include "../../common/math/WLinearAlgebraFunctions.h"
32 #include "../../common/math/linearAlgebra/WVectorFixed.h"
33 #include "WPlane.h"
34 
35 WPlane::WPlane( const WVector3d& normal, const WPosition& pos )
36  : m_normal( normal ),
37  m_pos( pos )
38 {
39  setNormal( normal );
40 }
41 
42 WPlane::WPlane( const WVector3d& normal, const WPosition& pos, const WVector3d& first, const WVector3d& second )
43  : m_normal( normal ),
44  m_pos( pos )
45 {
46  setPlaneVectors( first, second );
47  m_first = normalize( m_first );
48  m_second = normalize( m_second );
49 }
50 
52 {
53 }
54 
55 bool WPlane::isInPlane( WPosition /* point */ ) const
56 {
57  // TODO(math): implement this: pos + first*m + second*n == point ??
58  return false;
59 }
60 
62 {
63  // TODO(math): check if pos is in plane first!
64  m_pos = newPos;
65 }
66 
67 
68 std::shared_ptr< std::set< WPosition > > WPlane::samplePoints( double stepWidth, size_t numX, size_t numY ) const
69 {
70  // idea: start from m_pos in m_first direction until boundary reached, increment in m_second direction from m_pos and start again
71  std::shared_ptr< std::set< WPosition > > result( new std::set< WPosition >() );
72 
73  // the plane has two directions m_first and m_second
74  const WVector3d ycrement = stepWidth * m_second;
75  const WVector3d xcrement = stepWidth * m_first;
76  result->insert( m_pos );
77  for( size_t i = 0; i < numY; ++i )
78  {
79  for( size_t j = 0; j < numX; ++j )
80  {
81  // NOTE: on some machines with older compilers, the size_t is not mapped to uint32_t or uint64_t. This
82  // breaks our WMatrixFixed type promotion. So we use doubles directly.
83  double id = i;
84  double jd = j;
85  result->insert( m_pos - id * ycrement - jd * xcrement );
86  result->insert( m_pos + id * ycrement - jd * xcrement );
87  result->insert( m_pos - id * ycrement + jd * xcrement );
88  result->insert( m_pos + id * ycrement + jd * xcrement );
89  }
90  }
91  return result;
92 }
93 
94 WPosition WPlane::getPointInPlane( double x, double y ) const
95 {
96  WVector3d sd= m_pos +
97  x * m_first
98  +
99  y * m_second;
100  return sd;
101 }
102 
103 void WPlane::setPlaneVectors( const WVector3d& first, const WVector3d& second )
104 {
105  std::stringstream msg;
106  msg << "The give two vectors are not perpendicular to plane. First: " << first << " second: " << second << " for plane normal: " << m_normal;
107  WAssert( std::abs( dot( first, m_normal ) ) < wlimits::FLT_EPS && std::abs( dot( second, m_normal ) ) < wlimits::FLT_EPS, msg.str() );
108 
109  std::stringstream msg2;
110  msg2 << "The given two vectors are not linear independent!: " << first << " and " << second;
111  WAssert( linearIndependent( first, second ), msg2.str() );
112 
113  m_first = first;
114  m_second = second;
115 }
std::shared_ptr< std::set< WPosition > > samplePoints(const WGridRegular3D &grid, double stepWidth)
Computes sample points on that plane.
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
virtual ~WPlane()
Destructor.
Definition: WPlane.cpp:51
This only is a 3d double vector.
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
Definition: WLimits.cpp:47