LRAUV  revA
NavChartDb.h
Go to the documentation of this file.
1 
9 #ifndef NAVCHARTDB_H_
10 #define NAVCHARTDB_H_
11 
13 #include "data/StrValue.h"
14 #include "io/EncReader.h"
15 #include "logger/Logger.h"
16 #include "utils/FastMap.h"
17 #include "utils/Mutex.h"
18 
19 class EncReader;
20 class DataWriter;
21 class Mtx;
22 
30 class NavChartDb : public AsyncComponent
31 {
32 public:
33 
34  NavChartDb( );
35 
36  virtual ~NavChartDb();
37 
38  virtual void initialize();
39 
40  virtual void run();
41  void updateCurrent( const float latitude, const float longitude,
42  bool gotFix );
43  float getSeaFloorDepth( const float latitude, const float longitude );
44  float getDistanceFromShore( const float latitude, const float longitude );
45  virtual void uninitialize();
46 
49  static int CalcGeoIndex( float latitude, float longitude );
50 
52  static int MakeGeoIndex( int latIndex, int lonIndex );
53 
56  static int CalcLatIndex( float latitude );
57 
60  static int CalcNumLonIndices( int latIndex );
61 
64  static int CalcLonIndex( float longitude, int nLons );
65 
66  bool ready()
67  {
68  return ready_;
69  }
70 
72  {
73  return Instance_;
74  }
75 
77  {
78  okToUpdateFromDisk_ = true;
79  }
80 
81  void setChartsCfg( const Str chartsCfg );
82 
83 protected:
84  class ClosePoint
85  {
86  public:
88  depth_( nanf( "" ) ), lat_( nanf( "" ) ), lon_( nanf( "" ) ), cosLat_(
89  nanf( "" ) ), angle_( nanf( "" ) ), angleSq_( nanf( "" ) )
90  {
91  }
92 
93  float getdepth()
94  {
95  return depth_;
96  }
97 
98  float getlat()
99  {
100  return lat_;
101  }
102 
103  float getLon()
104  {
105  return lon_;
106  }
107 
108  float getCosLat()
109  {
110  return cosLat_;
111  }
112 
113  float getAngle()
114  {
115  return angle_;
116  }
117 
118  float getAngleSq()
119  {
120  return angleSq_;
121  }
122 
123  void setDepth( const float& depth )
124  {
125  depth_ = depth;
126  }
127 
128  void setLat( const float& lat )
129  {
130  lat_ = lat;
131  }
132 
133  void setLon( const float& lon )
134  {
135  lon_ = lon;
136  }
137 
138  void setCosLat( const float& cosLat )
139  {
140  cosLat_ = cosLat;
141  }
142 
143  void setAngle( const float& angle )
144  {
145  angle_ = angle;
146  }
147 
148  void setAngleSq( const float& angleSq )
149  {
150  angleSq_ = angleSq;
151  }
152 
153  friend bool operator >( const ClosePoint& ptL, const ClosePoint& ptR )
154  {
155  return ptL.angleSq_ > ptR.angleSq_;
156  }
157 
158  float depth_;
159  float lat_;
160  float lon_;
161  float cosLat_;
162  float angle_;
163  float angleSq_;
164  };
165  struct EncInfo
166  {
167  EncInfo( int encId, int resLevel, bool loaded, Str& filename ) :
168  encId_( encId ),
169  resLevel_( resLevel ),
170  loaded_( loaded ),
171  filename_( filename )
172  {
173  }
174 
175  virtual ~EncInfo() {}
176 
177  int encId_;
179  bool loaded_;
181  };
182 
183 private:
184  NavChartDb( const NavChartDb& old );
185  void wipeOut();
186  void updateClosest();
187  bool initDataDir();
188  bool saveDepths();
189  bool loadDepths();
190  bool createIndices();
191  bool createSoundings();
192  bool createContour( const Str* depthStr );
193  bool appendToContour( const Str* depthStr, const int encId,
194  const int resLevel, const float latitude, const float longitude );
195  bool appendToSoundings( const float depth, const int encId,
196  const int resLevel, const float latitude, const float longitude );
197  bool appendToCoverage( const int encId, const int resLevel,
198  const float x0, const float y0, const float x1, const float y1 );
199  bool loadCoverage( const int resLevel, EncArea** coverage );
200  bool saveEncs();
201  bool loadEncs();
202  bool addEncData( EncInfo* encInfo );
203  Str* mapDepth( const float depth );
204  EncArea* getCoverage( int resLevel );
205  float calcDistFromLineSq( const float x, const float y, const float x1,
206  const float y1, const float x2, const float y2 );
207  void doIndexing( const Str* depthStr );
208  void updateGeoIndices();
209 
211  bool ready_;
214 
216 
218 
220 
222 
224 
226 
228 
230 
231  unsigned int currentGeoIndex_;
232 
234 
236 
237  int encId_;
238 
240 
242 
255  float latitude_;
257  float longitude_;
260  bool mapDone_;
264 
266  static const Str NAME;
267 
268  // No need for a NavChartDbIF.h since no other components seem to read these variables.
269  // However, we still want to define const DataURI elements so that we can use the
270  // non-deprecated Component::newDataWriter method instead of the deprecated Slate::NewOutputWriter method.
271  static const DataURI CLOSEST_DISTANCE;
272  static const DataURI NEXT_DISTANCE;
273  static const DataURI CLOSEST_DEPTH;
274  static const DataURI NEXT_DEPTH;
277 
278  static const float NUM_LATS;
279  static const float LAT_INCREMENT;
280 
285 
288 
290 
291  static const Timespan PERIOD;
292 
293 };
294 
295 #endif /*NAVCHARTDB_H_*/
bool createSoundings()
Definition: NavChartDb.cpp:789
float depth_
Definition: NavChartDb.h:158
bool loadEncs()
Definition: NavChartDb.cpp:938
Simple class for providing key-pointer mappings.
Definition: Slate.h:44
static NavChartDb * Instance_
Definition: NavChartDb.h:265
bool appendToContour(const Str *depthStr, const int encId, const int resLevel, const float latitude, const float longitude)
Definition: NavChartDb.cpp:820
float cycleTimeoutCfgTmp_
Definition: NavChartDb.h:262
bool addEncData(EncInfo *encInfo)
Definition: NavChartDb.cpp:990
FastMap< const float, ClosePoint * > closeMap_
Definition: NavChartDb.h:227
EncArea * getCoverage(int resLevel)
Definition: NavChartDb.cpp:1116
virtual ~NavChartDb()
Definition: NavChartDb.cpp:105
float longitude_
Definition: NavChartDb.h:257
float angle_
Definition: NavChartDb.h:162
friend bool operator>(const ClosePoint &ptL, const ClosePoint &ptR)
Definition: NavChartDb.h:153
float getdepth()
Definition: NavChartDb.h:93
bool mapDone_
Definition: NavChartDb.h:260
float cosLat_
Definition: NavChartDb.h:161
int indexIndex_
Definition: NavChartDb.h:250
void setAngleSq(const float &angleSq)
Definition: NavChartDb.h:148
ClosePoint currentPoint_
Definition: NavChartDb.h:244
void setChartsCfg(const Str chartsCfg)
Definition: NavChartDb.cpp:172
float getAngle()
Definition: NavChartDb.h:113
bool loadCoverage(const int resLevel, EncArea **coverage)
Definition: NavChartDb.cpp:886
bool createIndices()
Definition: NavChartDb.cpp:773
void updateGeoIndices()
Definition: NavChartDb.cpp:326
FastMap< const float, Str * > depthMap_
Definition: NavChartDb.h:217
ClosePoint()
Definition: NavChartDb.h:87
virtual void uninitialize()
Provide a space for uninitialization.
Definition: NavChartDb.cpp:668
Str * mapDepth(const float depth)
Definition: NavChartDb.cpp:1096
Definition: NavChartDb.h:165
int depthIndex_
Definition: NavChartDb.h:251
float lon_
Definition: NavChartDb.h:160
void setLat(const float &lat)
Definition: NavChartDb.h:128
void updateClosest()
For the current latitude/longitude pair (in radians), update closest point on each contour...
Definition: NavChartDb.cpp:389
EncReader * encReader_
Definition: NavChartDb.h:243
FastMap< const Str, EncInfo * > encMap_
Definition: NavChartDb.h:215
FlexArray< EncArea * > coverages_
Definition: NavChartDb.h:241
int currentCount_
Definition: NavChartDb.h:245
static const Timespan PERIOD
Definition: NavChartDb.h:291
ClosePoint workingClosePoints_[4]
Definition: NavChartDb.h:233
bool initDataDir()
Definition: NavChartDb.cpp:673
int insertCount_
Definition: NavChartDb.h:246
Definition: EncReader.h:114
FlexArrayBase currentGeoIndices_
Definition: NavChartDb.h:229
static const RestartConfigURI CHARTS_CFG
Definition: NavChartDb.h:275
A simple pthread Mutex abstraction.
Definition: Mutex.h:20
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
void wipeOut()
Definition: NavChartDb.cpp:161
bool loaded_
Definition: NavChartDb.h:179
static const DataURI CLOSEST_DISTANCE
Definition: NavChartDb.h:271
float changeLongitudeTo_
Definition: NavChartDb.h:258
ConfigReader * chartsCfgReader_
Definition: NavChartDb.h:286
Reads a standard electronic navigation chart (ENC) in S-57 format, stores it in a database...
Definition: NavChartDb.h:30
bool appendToCoverage(const int encId, const int resLevel, const float x0, const float y0, const float x1, const float y1)
Definition: NavChartDb.cpp:870
Definition: Mtx.h:24
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
bool saveDepths()
Definition: NavChartDb.cpp:687
void doIndexing(const Str *depthStr)
Definition: NavChartDb.cpp:709
int quadrant_
Definition: NavChartDb.h:254
NavChartDb()
Definition: NavChartDb.cpp:57
float lat_
Definition: NavChartDb.h:159
Timespan cycleTimeoutCfg_
Definition: NavChartDb.h:263
int encId_
Definition: NavChartDb.h:237
static int CalcLonIndex(float longitude, int nLons)
Calculates longitudinal index of small area in the latIndex band around the planet.
Definition: NavChartDb.cpp:1175
virtual void initialize()
Provide a space for initialization before being run.
Definition: NavChartDb.cpp:177
Contains the StrValue class definition.
virtual void run()
The actual "payload" of the component.
Definition: NavChartDb.cpp:271
FastMap< const Str *, Str * > depthMtxNameMap_
Definition: NavChartDb.h:219
float getlat()
Definition: NavChartDb.h:98
float getSeaFloorDepth(const float latitude, const float longitude)
For a latitude/longitude pair (in radians), return the approximate depth.
Definition: NavChartDb.cpp:584
Definition: NavChartDb.h:84
int encId_
Definition: NavChartDb.h:177
float currentDepth_
Definition: NavChartDb.h:247
Str * currentDepthStr_
Definition: NavChartDb.h:248
float getAngleSq()
Definition: NavChartDb.h:118
void setCosLat(const float &cosLat)
Definition: NavChartDb.h:138
int nextDepthIndex_
Definition: NavChartDb.h:252
DataWriter * closestDistanceWriter_
Definition: NavChartDb.h:281
Simple class providing a flexible size array of void*.
Definition: FlexArray.h:22
Replacement for standard template class string.
Definition: Str.h:12
static const float NUM_LATS
Definition: NavChartDb.h:278
float getDistanceFromShore(const float latitude, const float longitude)
For a given latitude and longitude (in radians), estimates the distance from the shoreline at that lo...
Definition: NavChartDb.cpp:631
static const float LAT_INCREMENT
Definition: NavChartDb.h:279
int resLevel_
Definition: NavChartDb.h:178
float getCosLat()
Definition: NavChartDb.h:108
EncInfo(int encId, int resLevel, bool loaded, Str &filename)
Definition: NavChartDb.h:167
static int CalcGeoIndex(float latitude, float longitude)
converts a latitude and longitude into a index that covers a small area of the planet (smaller than G...
Definition: NavChartDb.cpp:1145
unsigned int currentGeoIndex_
Definition: NavChartDb.h:231
Definition: ConfigReader.h:13
void setLon(const float &lon)
Definition: NavChartDb.h:133
static NavChartDb * GetInstance()
Definition: NavChartDb.h:71
static int MakeGeoIndex(int latIndex, int lonIndex)
Combines latitude index and longitude index into a single index.
Definition: NavChartDb.cpp:1154
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
Abstract Base class for software components that run independently from the computation cycle...
Definition: AsyncComponent.h:20
static const RestartConfigURI CYCLE_TIMEOUT_CFG
Definition: NavChartDb.h:276
Contains the FastMap class declaration.
FlexArray< EncInfo * > encInfos_
Definition: NavChartDb.h:239
Contains the Logger class definition.
bool initialized_
Definition: NavChartDb.h:210
float changeLatitudeTo_
Definition: NavChartDb.h:256
bool saveEncs()
Definition: NavChartDb.cpp:922
static const DataURI CLOSEST_DEPTH
Definition: NavChartDb.h:273
static const DataURI NEXT_DEPTH
Definition: NavChartDb.h:274
int changeNextDepthIndexTo_
Definition: NavChartDb.h:253
const Str soundingsStr_
Definition: NavChartDb.h:249
static const DataURI NEXT_DISTANCE
Definition: NavChartDb.h:272
Definition: ElementURI.h:229
virtual ~EncInfo()
Definition: NavChartDb.h:175
void setAngle(const float &angle)
Definition: NavChartDb.h:143
static int CalcLatIndex(float latitude)
converts a latitude into a index that covers a small band around the planet
Definition: NavChartDb.cpp:1161
ClosePoint * closeSoundings_
Definition: NavChartDb.h:235
bool okToUpdateFromDisk_
Definition: NavChartDb.h:212
DataWriter * nextDepthWriter_
Definition: NavChartDb.h:284
Simple class providing a flexible size array of pointers.
Definition: DataReader.h:19
bool ready_
Definition: NavChartDb.h:211
float angleSq_
Definition: NavChartDb.h:163
static int CalcNumLonIndices(int latIndex)
Returns number of small longitudinal areas in the latIndex band around the planet (each smaller than ...
Definition: NavChartDb.cpp:1168
bool appendToSoundings(const float depth, const int encId, const int resLevel, const float latitude, const float longitude)
Definition: NavChartDb.cpp:844
void setOkToUpdateFromDisk()
Definition: NavChartDb.h:76
float calcDistFromLineSq(const float x, const float y, const float x1, const float y1, const float x2, const float y2)
Definition: NavChartDb.cpp:1127
bool createContour(const Str *depthStr)
Definition: NavChartDb.cpp:812
int changeOkToUpdateFromDiskTo_
Definition: NavChartDb.h:213
FastMap< const Str *, Str * > depthIdxNameMap_
Definition: NavChartDb.h:221
Mutex currentMutex_
Definition: NavChartDb.h:289
Definition: EncReader.h:167
FastMap< const Str *, Mtx * > depthIdxMap_
Definition: NavChartDb.h:225
void updateCurrent(const float latitude, const float longitude, bool gotFix)
Update the curent latitude/longitude pair (in radians)
Definition: NavChartDb.cpp:369
DataWriter * nextDistanceWriter_
Definition: NavChartDb.h:282
Wraps a string (see Str) as a DataValue, so strings can be written to and read from the slate...
Definition: StrValue.h:34
Str filename_
Definition: NavChartDb.h:180
ConfigReader * cycleTimeoutCfgReader_
Definition: NavChartDb.h:287
float getLon()
Definition: NavChartDb.h:103
DataWriter * closestDepthWriter_
Definition: NavChartDb.h:283
bool ready()
Definition: NavChartDb.h:66
StrValue chartsCfg_
Definition: NavChartDb.h:261
bool loadDepths()
Definition: NavChartDb.cpp:697
void setDepth(const float &depth)
Definition: NavChartDb.h:123
bool shoreDone_
Definition: NavChartDb.h:259
Definition: ElementURI.h:192
FastMap< const Str *, FastMap< const int, Mtx * > * > depthMtxMap_
Definition: NavChartDb.h:223
float latitude_
Definition: NavChartDb.h:255
static const Str NAME
Definition: NavChartDb.h:266
Contains the AsyncComponent class definition.