OpenWalnut  1.5.0dev
WAngleHelper.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 WANGLEHELPER_H
26 #define WANGLEHELPER_H
27 
28 #include <unordered_map>
29 #include <utility>
30 #include <vector>
31 
32 #include "WFiberHandler.h"
33 
34 /**
35  * Contains functions to help determine the path with the smallest angle change
36  */
37 namespace WAngleHelper
38 {
39  /**
40  * Hash function for the unorder map
41  */
42  struct HashFn
43  {
44  /**
45  * Hashes a WPosition object.
46  * \param pos The position.
47  * \return size_t The hash.
48  */
49  size_t operator()( const WPosition& pos ) const
50  {
51  return ( ( std::hash< double >{}( pos.x() ) // NOLINT
52  ^ ( std::hash< double >{}( pos.y() ) << 1 ) ) >> 1 ) // NOLINT
53  ^ ( std::hash< double >{}( pos.z() ) << 1 ); // NOLINT
54  }
55  };
56 
57  /**
58  * An unordered map from WPosition to WPosition.
59  */
60  typedef std::unordered_map< WPosition, WPosition, HashFn > PositionMap;
61 
62  /**
63  * An unordered map from WPosition to double.
64  */
65  typedef std::unordered_map< WPosition, double, HashFn > PositionDoubleMap;
66 
67  /**
68  * An unordered map from WPosition to a PositionDoubleMap
69  */
70  typedef std::unordered_map< WPosition, PositionMap, HashFn > PositionLineMap;
71 
72  /**
73  * The output of the createLine function
74  */
75  typedef std::pair< WAngleHelper::PositionLineMap, WAngleHelper::PositionLineMap > DJLinePair;
76 
77  /**
78  * The output of the dijkstra algorithm
79  */
80  typedef std::pair< PositionMap, PositionDoubleMap > DJOut;
81 
82  /**
83  * Determines the path with the smallest angle change
84  * \param positions The positions to build the path upon
85  * \return std::vector< WPosition > All the positions on the smallest path
86  */
87  std::vector< WPosition > findSmoothestPath( std::vector< WPosition > positions );
88 
89  /**
90  * Determines the path with the smallest angle change based on the given fiber
91  * \param positions The positions to build the path upon
92  * \param fiber The fiber used to adjust the path
93  * \return std::vector< WPosition > All the positions on the smallest path
94  */
95  std::vector< WPosition > findSmoothestPath( std::vector< WPosition > positions, WFiberHandler::PCFiber fiber );
96 
97  /**
98  * Calculates the angle between two positions.
99  * \param a The first position.
100  * \param b The second position.
101  * \return double The angle.
102  */
103  double calculateAngle( WPosition a, WPosition b );
104 }
105 
106 #endif // WANGLEHELPER_H
std::vector< osg::Vec3 > PCFiber
Vector of 3D vectors, representing points.
Definition: WFiberHandler.h:63
This only is a 3d double vector.
Contains functions to help determine the path with the smallest angle change.
Definition: WAngleHelper.h:38
std::unordered_map< WPosition, double, HashFn > PositionDoubleMap
An unordered map from WPosition to double.
Definition: WAngleHelper.h:65
std::vector< WPosition > findSmoothestPath(std::vector< WPosition > positions)
Determines the path with the smallest angle change.
std::unordered_map< WPosition, PositionMap, HashFn > PositionLineMap
An unordered map from WPosition to a PositionDoubleMap.
Definition: WAngleHelper.h:70
std::pair< WAngleHelper::PositionLineMap, WAngleHelper::PositionLineMap > DJLinePair
The output of the createLine function.
Definition: WAngleHelper.h:75
std::pair< PositionMap, PositionDoubleMap > DJOut
The output of the dijkstra algorithm.
Definition: WAngleHelper.h:80
double calculateAngle(WPosition a, WPosition b)
Calculates the angle between two positions.
std::unordered_map< WPosition, WPosition, HashFn > PositionMap
An unordered map from WPosition to WPosition.
Definition: WAngleHelper.h:60
Hash function for the unorder map.
Definition: WAngleHelper.h:43
size_t operator()(const WPosition &pos) const
Hashes a WPosition object.
Definition: WAngleHelper.h:49