OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPLANE_H 00026 #define WPLANE_H 00027 00028 #include <set> 00029 00030 #include <boost/shared_ptr.hpp> 00031 00032 #include "../../dataHandler/WGridRegular3D.h" 00033 00034 #include "linearAlgebra/WVectorFixed.h" 00035 00036 /** 00037 * Represents a plane with a normal vector and a position in space. 00038 */ 00039 class WPlane // NOLINT 00040 { 00041 public: 00042 /** 00043 * Constructs a plane with its normal and containing the point. 00044 * 00045 * \param normal Direction of the plane 00046 * \param pos Position of the plane 00047 * 00048 * \return 00049 */ 00050 WPlane( const WVector3d& normal, const WPosition& pos ); 00051 00052 /** 00053 * Constructs a plane with its normal and its base point/origin as well as explicitly specifying its vectors in the plane. 00054 * 00055 * \param normal Normal vector for the direction 00056 * \param pos Base point of the plane, aka origin. 00057 * \param first First vector perpendicular to the normal 00058 * \param second Second vector perpendicular to the normal and linearly independent from first. 00059 * 00060 * \note Due to numerical stability a comparison to 0.0 is not performed. Instead the absolute value of the dot product is checked to 00061 * be smaller than the FLT_EPS. FLT_EPS is used instead of DBL_EPS just numerical errors may sum up above DBL_EPS. 00062 */ 00063 WPlane( const WVector3d& normal, const WPosition& pos, const WVector3d& first, const WVector3d& second ); 00064 00065 /** 00066 * Destructor. 00067 */ 00068 virtual ~WPlane(); 00069 00070 /** 00071 * Determines whether a given point is in this plane or not. 00072 * 00073 * \param point Position to query 00074 * 00075 * \return True if and only if the point is in this plane. 00076 */ 00077 bool isInPlane( WPosition point ) const; 00078 00079 /** 00080 * Reset the position of the plane, normal remains the same. 00081 * 00082 * \param newPos New Position (point in plane). 00083 */ 00084 void resetPosition( WPosition newPos ); 00085 00086 /** 00087 * Computes sample points on that plane. 00088 * 00089 * \param grid 00090 * \param stepWidth 00091 * 00092 * \return Set of positions on the plane 00093 */ 00094 boost::shared_ptr< std::set< WPosition > > samplePoints( const WGridRegular3D& grid, double stepWidth ); 00095 00096 00097 /** 00098 * Computes with relative coordinates a point in this plane. (0,0) means its position is returned. 00099 * 00100 * \param x how far along the direction of the first vector which spans the plane 00101 * \param y how far along the direction of the second vector which spans the plane too 00102 * 00103 * \return the new calculated position 00104 */ 00105 WPosition getPointInPlane( double x, double y ) const; 00106 00107 /** 00108 * Returns a point in that plane. 00109 * 00110 * \return The point in that plane describing its position 00111 */ 00112 const WPosition& getPosition() const; 00113 00114 /** 00115 * Returns the normal of the plane. 00116 * 00117 * \return Normalized normal vector. 00118 */ 00119 const WVector3d& getNormal() const; 00120 00121 /** 00122 * Resets the vector spanning the plane. Both must be linear independent and perpendicular to the already 00123 * existing normal vector. After setting the vectors they are normalized. 00124 * 00125 * \param first First vector spanning the plane 00126 * \param second Second vector spanning the plane 00127 */ 00128 void setPlaneVectors( const WVector3d& first, const WVector3d& second ); 00129 00130 /** 00131 * Resets the normal of this plane. 00132 * 00133 * \param normal New normal for this plane. 00134 */ 00135 void setNormal( const WVector3d& normal ) 00136 { 00137 m_normal = normalize( normal ); 00138 WVector3d gen( 1, 0, 0 ); 00139 if( cross( normal, gen ) == WVector3d( 0, 0, 0 ) ) 00140 { 00141 gen = WVector3d( 0, 1, 0 ); 00142 } 00143 m_first = cross( normal, gen ); 00144 m_first = normalize( m_first ); 00145 m_second = cross( normal, m_first ); 00146 m_second = normalize( m_second ); 00147 } 00148 00149 // \cond Suppress_Doxygen 00150 // /** 00151 // * Computes sample points on that plane. 00152 // * 00153 // * \param grid 00154 // * \param stepWidth 00155 // * 00156 // * \return Set of positions on the plane 00157 // */ 00158 // boost::shared_ptr< std::set< WPosition > > samplePoints( const WGridRegular3D& grid, double stepWidth ); 00159 // \endcond 00160 00161 /** 00162 * Computes a fixed number of sample points on that plane. 00163 * 00164 * \param stepWidth 00165 * \param numX 00166 * \param numY 00167 * 00168 * \return Set of positions on the plane 00169 */ 00170 boost::shared_ptr< std::set< WPosition > > samplePoints( double stepWidth, size_t numX, size_t numY ) const; 00171 00172 protected: 00173 WVector3d m_normal; //!< Direction of the plane 00174 WPosition m_pos; //!< Position of the plane specifying the center 00175 WVector3d m_first; //!< First vector in the plane 00176 WVector3d m_second; //!< Second vector in the plane 00177 00178 private: 00179 }; 00180 00181 inline const WPosition& WPlane::getPosition() const 00182 { 00183 return m_pos; 00184 } 00185 00186 inline const WVector3d& WPlane::getNormal() const 00187 { 00188 return m_normal; 00189 } 00190 00191 #endif // WPLANE_H