LRAUV  revA
LocationNode.h
Go to the documentation of this file.
1 /*
2  * LocationNode.h
3  *
4  * Created on: Jan 6, 2014
5  * Author: godin
6  */
7 
8 #ifndef LOCATIONNODE_H_
9 #define LOCATIONNODE_H_
10 
11 #include "data/Location.h"
12 #include "utils/FastMap.h"
13 
14 class LocationNode: public Location
15 {
16 public:
17 
18  enum NodeColor
19  {
23  };
24 
25  LocationNode( double latitude, double longitude, int latIndex, int lonIndex )
26  : Location( Units::RADIAN, latitude, longitude ),
27  latIndex_( latIndex ),
28  lonIndex_( lonIndex ),
29  cameFrom_( NULL ),
30  nodeColor_( WHITE ),
31  dScore_( INFINITY ),
32  fScore_( INFINITY )
33  {}
34 
35  void setDScoreAndHeuristic( float dScore, float heuristic )
36  {
37  dScore_ = dScore;
38  fScore_ = dScore + heuristic;
39  }
40 
41  int getLatIndex() const
42  {
43  return latIndex_;
44  }
45 
46  int getLonIndex() const
47  {
48  return lonIndex_;
49  }
50 
51  void setNodeColor( NodeColor nodeColor )
52  {
53  nodeColor_ = nodeColor;
54  }
55 
56  void setCameFrom( LocationNode* cameFrom, float dScore, float heuristic, FastMap<const float, LocationNode*>& nodeQueue )
57  {
58  if( NULL != cameFrom && nodeColor_ == GRAY )
59  {
60  removeFromQueue( nodeQueue );
61  }
62  else if( NULL != cameFrom )
63  {
64  nodeColor_ = GRAY;
65  }
66  else
67  {
68  nodeColor_ = WHITE;
69  }
70 
71  cameFrom_ = cameFrom;
72  dScore_ = dScore;
73  fScore_ = dScore_ + heuristic;
74 
75  if( NULL != cameFrom )
76  {
77  nodeQueue.put( fScore_, this );
78  }
79  }
80 
81 
82  const double getLat() const
83  {
84  return lat_;
85  }
86 
87  const double getLon() const
88  {
89  return lon_;
90  }
91 
93  {
94  return cameFrom_;
95  }
96 
97  float getDScore()
98  {
99  return dScore_;
100  }
101 
102  float getFScore()
103  {
104  return fScore_;
105  }
106 
108  {
109  int index = nodeQueue.findIndex( fScore_ );
110  if( index == -1 )
111  {
112  // Not in the queue at all
113  return;
114  }
115  if( nodeQueue.getIndexed( index ) == this )
116  {
117  // Uniquely at the index
118  nodeQueue.popIndexed( index );
119  return;
120  }
121  // Look forward
122  for( int i = index + 1; i < ( int ) nodeQueue.size(); ++i )
123  {
124  if( nodeQueue.getIndexed( i ) == this )
125  {
126  nodeQueue.popIndexed( i );
127  return;
128  }
129  else if( nodeQueue.getIndexedEntry( i )->getKey() != fScore_ )
130  {
131  break;
132  }
133  }
134  // Look backward
135  for( int i = index - 1; i >= 0; --i )
136  {
137  if( nodeQueue.getIndexed( i ) == this )
138  {
139  nodeQueue.popIndexed( i );
140  return;
141  }
142  else if( nodeQueue.getIndexedEntry( i )->getKey() != fScore_ )
143  {
144  break;
145  }
146  }
147 
148  }
149 
150 private:
151  // Note that the copy constructor below is private and not given a body.
152  // Any attempt to call it will return a compiler error.
153  LocationNode( const LocationNode& old ); // disallow copy constructor
154 
159  float dScore_;
160  float fScore_;
161 };
162 
163 #endif /* LOCATIONNODE_H_ */
double & lon_
Longitude, in radians east.
Definition: Location.h:296
int lonIndex_
Definition: LocationNode.h:156
NodeColor nodeColor_
Definition: LocationNode.h:158
LocationNode * cameFrom_
Definition: LocationNode.h:157
void setDScoreAndHeuristic(float dScore, float heuristic)
Definition: LocationNode.h:35
float getDScore()
Definition: LocationNode.h:97
int findIndex(const S &key, int minIndex=0, int maxIndex=-1)
Definition: FastMap.h:124
float fScore_
Definition: LocationNode.h:160
const double getLat() const
Definition: LocationNode.h:82
int getLonIndex() const
Definition: LocationNode.h:46
double & lat_
Latitude, in radians north.
Definition: Location.h:293
Definition: LocationNode.h:22
unsigned int size()
Definition: FastMap.h:159
Definition: LocationNode.h:14
float dScore_
Definition: LocationNode.h:159
LocationNode * getCameFrom()
Definition: LocationNode.h:92
Definition: LocationNode.h:21
MapEntry< S, T > * getIndexedEntry(unsigned int index, bool andPop=false)
Definition: FastMap.h:96
T getIndexed(unsigned int index, bool andPop=false)
Definition: FastMap.h:81
LocationNode(double latitude, double longitude, int latIndex, int lonIndex)
Definition: LocationNode.h:25
void setNodeColor(NodeColor nodeColor)
Definition: LocationNode.h:51
Definition: LocationNode.h:20
virtual S & getKey()
Definition: MapEntry.h:35
Contains the FastMap class declaration.
Static collection of standard engineering Units Can use UnitRegistry to look these up by name...
Definition: Units.h:33
void setCameFrom(LocationNode *cameFrom, float dScore, float heuristic, FastMap< const float, LocationNode * > &nodeQueue)
Definition: LocationNode.h:56
T popIndexed(unsigned int index)
Definition: FastMap.h:106
const double getLon() const
Definition: LocationNode.h:87
NodeColor
Definition: LocationNode.h:18
int getLatIndex() const
Definition: LocationNode.h:41
void removeFromQueue(FastMap< const float, LocationNode * > &nodeQueue)
Definition: LocationNode.h:107
int latIndex_
Definition: LocationNode.h:155
Wraps a pair of double precision (8-byte) floating point numbers and units for storage in a DataEleme...
Definition: Location.h:38
Contains the Location class definition.
float getFScore()
Definition: LocationNode.h:102
bool put(S &key, T item, bool deleteOnCleanup=false)
Definition: FastMap.h:39