OpenWalnut 1.2.5
|
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 WLINE_H 00026 #define WLINE_H 00027 00028 #include <algorithm> 00029 #include <iostream> 00030 #include <vector> 00031 00032 #include "../WBoundingBox.h" 00033 #include "../WExportCommon.h" 00034 #include "../WMixinVector.h" 00035 #include "linearAlgebra/WLinearAlgebra.h" 00036 00037 // forward declarations 00038 class WLineTest; 00039 00040 /** 00041 * A line is an ordered sequence of WPositions. 00042 */ 00043 class OWCOMMON_EXPORT WLine : public WMixinVector< WPosition > 00044 { 00045 public: 00046 /** 00047 * Generates a new line out of a sequence of points. 00048 * 00049 * \param points Point sequence 00050 */ 00051 explicit WLine( const std::vector< WPosition > &points ); 00052 00053 /** 00054 * Creates an empty line. 00055 */ 00056 WLine(); 00057 00058 /** 00059 * Resample this line so it has a number of given points afterwards. 00060 * \warning This changes your line! 00061 * 00062 * \param numPoints Number of sampling points. 00063 */ 00064 void resampleByNumberOfPoints( size_t numPoints ); 00065 00066 /** 00067 * 00068 * 00069 * \warning This may elongate your line at max. by the newSegmentLength 00070 * 00071 * \param newSegementLength 00072 */ 00073 void resampleBySegmentLength( double newSegementLength ); 00074 00075 /** 00076 * Reverses the order of the points. (mirroring) 00077 */ 00078 void reverseOrder(); 00079 00080 /** 00081 * Collapse samplepoints which are equal and neighboured. 00082 */ 00083 void removeAdjacentDuplicates(); 00084 00085 /** 00086 * Put the line into reverse ordering if the reverse ordering would have a 00087 * similar direction to the given line. That means if the start point (or 00088 * multiple selected sample points) of the given line will better match to 00089 * end point (or multiple selected sample points) of this line (in term of 00090 * direction) the line is reordered. 00091 * 00092 * \param other The line giving the direction to align this line to. 00093 */ 00094 void unifyDirectionBy( const WLine& other ); 00095 }; 00096 00097 // Some convinience functions as non-member non-friend functions 00098 00099 /** 00100 * Computes a AABB (axis aligned bounding box) for all positions inside this line. 00101 * 00102 * \param line The line to compute the bounding box for. 00103 * 00104 * \return The AABB for this line. 00105 */ 00106 OWCOMMON_EXPORT WBoundingBox computeBoundingBox( const WLine& line ); 00107 00108 /** 00109 * Computes the length of a line in terms of accumulated segment lengths. 00110 * 00111 * \param line The line which used for computations 00112 * 00113 * \return Sum of all line segment lengths 00114 */ 00115 OWCOMMON_EXPORT double pathLength( const WLine& line ); 00116 00117 /** 00118 * Returns the point in the middle of a line. In case of an even sized 00119 * line the mid point is the same as if there were only size()-1 many 00120 * elements present. 00121 * 00122 * \param line The line to compute the mid point for. 00123 * 00124 * \throws WOutOfBounds In case its called on an empty line 00125 * 00126 * \return Const reference to the midpoint element. 00127 */ 00128 OWCOMMON_EXPORT const WPosition& midPoint( const WLine& line ); 00129 00130 /** 00131 * Compares two lines with each other point wise upto a given delta. 00132 * 00133 * \param line The first line 00134 * \param other The other line 00135 * \param delta Specifying the environment upto this two points are considered to be the same 00136 * 00137 * \return -1 in case of the two fibers are considered equal, otherwise the first position on which they differ is returned. 00138 */ 00139 OWCOMMON_EXPORT int equalsDelta( const WLine& line, const WLine& other, double delta ); 00140 00141 /** 00142 * Compute the maximal segment length of all segements of a line. If there are no segements meaning 00143 * zero or one point, zero is returned. 00144 * 00145 * \param line The line used for computation of the max segment length 00146 * 00147 * \return Max segement length or zero if there aren't any. 00148 */ 00149 OWCOMMON_EXPORT double maxSegmentLength( const WLine& line ); 00150 00151 /** 00152 * Boolean predicate indicating that the first line has more points then 00153 * the second one. 00154 * 00155 * \param first First line 00156 * \param second Second line 00157 * \return True if the first line has more points than the second 00158 */ 00159 bool hasMorePointsThen( const WLine& first, const WLine& second ); 00160 00161 inline bool hasMorePointsThen( const WLine& first, const WLine& second ) 00162 { 00163 return first.size() > second.size(); 00164 } 00165 00166 #endif // WLINE_H