LidarCloudDBModel.cc
Go to the documentation of this file.
1 
10 #include <det/Detector.h>
11 
12 #include <fdet/FDetector.h>
13 #include <fdet/Eye.h>
14 #include <fdet/Telescope.h>
15 #include <fdet/Pixel.h>
16 
17 #include <atm/CloudResult.h>
18 #include <atm/LidarDB.h>
19 #include <atm/LidarZone.h>
20 #include <atm/LidarCloudDBModel.h>
21 
22 #include <fwk/CoordinateSystemRegistry.h>
23 
24 #include <utl/Point.h>
25 #include <utl/UTMPoint.h>
26 #include <utl/ErrorLogger.h>
27 #include <utl/ReferenceEllipsoid.h>
28 #include <utl/Vector.h>
29 
30 #include <iostream>
31 #include <string>
32 #include <sstream>
33 #include <limits>
34 
35 using namespace det;
36 using namespace fdet;
37 using namespace atm;
38 using namespace fwk;
39 using namespace utl;
40 using namespace std;
41 
42 LidarCloudDBModel::LidarCloudDBModel() :
43  VCloudModel(),
44  fCloudHeightMap(0),
45  fLidarDbIsEmptyNow(false)
46 {
47 }
48 
50 {
51  delete fCloudHeightMap;
52 }
53 
54 void
56 {
57 }
58 
59 bool
61  const
62 {
63  return true;
64  // return CheckForUpdates();
65 }
66 
69 LidarCloudDBModel::EvaluateCloudCoverage(const unsigned int eyeId, const unsigned int telescopeId, const unsigned int pixelId, const utl::Point& x)
70  const
71 {
72  bool hasLidarData;
73 
74  // If we have lidar data, get the cloud base height from the nearest FD zone
75  if ((hasLidarData = CheckForUpdates())) {
76 
77  const ReferenceEllipsoid wgs84(ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84));
78  const double pointHeight = (wgs84.PointToLatitudeLongitudeHeight(x)).get<2>();
79 
80  const string lidarZoneName = GetZoneName(x);
81  const double cloudHeight = ((*fCloudHeightMap)[lidarZoneName]);
82 
83 //#warning fix negative height in LIDAR DB
84  // -999 in LIDAR DB for no clouds detected...
85  if ( cloudHeight < -998 )
86  return CloudResult(0, hasLidarData);
87 
88  // If the Point altitude is below the lowest cloud base altitude, then
89  // treat the pixel as unobscured regardless of the cloud camera data
90  if (pointHeight < cloudHeight)
91  return CloudResult(0, hasLidarData);
92  }
93 
94  // If we do not have lidar data, or if the cloud base is below the point
95  // altitude, check the IR camera database for coverage data
96  if (det::Detector::GetInstance().GetFDetector().
97  GetEye(eyeId).GetTelescope(telescopeId).GetPixel(pixelId).HasCloudFraction()) {
98  float cloudFraction = det::Detector::GetInstance().GetFDetector().
99  GetEye(eyeId).GetTelescope(telescopeId).GetPixel(pixelId).GetCloudFraction();
100 
101  return CloudResult(cloudFraction, hasLidarData);
102  }
103 
104  // No data available: return default CloudResult
105  else {
106  DEBUGLOG("no cloud data in pixel");
107  return CloudResult();
108  }
109 }
110 
111 // Check for cached lidar data; return true if found.
112 bool
114  const
115 {
116  // Minimize queries to the lidar database.
117  if (fCurrentTime == det::Detector::GetInstance().GetTime() && fCurrentTime)
118  return !fLidarDbIsEmptyNow;
119 
120  fCurrentTime = det::Detector::GetInstance().GetTime();
121  fLidarDbIsEmptyNow = false;
122 
123  delete fCloudHeightMap;
124  fCloudHeightMap = new map<string, double>;
125 
126  fZonePositions.clear();
127 
128  const LidarDB& lidarDB =
129  det::Detector::GetInstance().GetAtmosphere().GetLidarDB();
130 
131  unsigned int zoneCount = 0;
132  for (LidarDB::ZoneIterator zIt = lidarDB.ZonesBegin();
133  zIt != lidarDB.ZonesEnd(); ++zIt, ++zoneCount)
134  {
135  // Fill zone name and position.
136  fZonePositions[zIt->GetName()] =
137  UTMPoint(zIt->GetNorthing(), zIt->GetEasting(),
138  0., 19, 'H',
139  ReferenceEllipsoid::GetEllipsoidIDFromString("WGS84")).GetPoint();
140  // Get lidar cloud base data.
141  (*fCloudHeightMap)[zIt->GetName()] = zIt->GetLowestCloudHeight();
142  }
143 
144  // Mindless copy of MeasuredDBMieModel:
145  // If there are no data, an exception should have been thrown by the
146  // low-level interface (no?); so reaching this point would be a bug.
147  if (zoneCount == 0) {
148  fLidarDbIsEmptyNow = true;
149 
150  ostringstream msg;
151  msg << "Cloud model requested data from lidar database, but none were found"
152  << " at " << det::Detector::GetInstance().GetTime();
153 
154  DEBUGLOG(msg);
155  return false;
156  }
157  return true;
158 }
159 
160 // Get the LidarZone closest to the current Eye, identified by the Eye number.
161 // NOTE: this is just for test; it's probably not what we want.
162 // Instead, it's probably best to pick the LidarZone nearest the viewing point.
163 string
164 LidarCloudDBModel::GetZoneName(const unsigned int eyeId)
165  const
166 {
167  const utl::Point& eyePos =
168  det::Detector::GetInstance().GetFDetector().GetEye(eyeId).GetPosition();
169 
170  string zoneName("");
171  double smallestDist = numeric_limits<float>::max(); // was HUGE
172 
173  for (map<string, Point>::const_iterator zIt = fZonePositions.begin();
174  zIt != fZonePositions.end(); ++zIt)
175  {
176  const double dist = (eyePos - zIt->second).GetMag();
177 
178  if (dist <= smallestDist) {
179  smallestDist = dist;
180  zoneName = zIt->first;
181  }
182  }
183 
184  return zoneName;
185 }
186 
187 // Get the LidarZone nearest to the specified point.
188 string
190  const
191 {
192  string zoneName("");
193  double smallestDist = numeric_limits<float>::max(); // was HUGE
194 
195  for (map<string, Point>::const_iterator zIt = fZonePositions.begin();
196  zIt != fZonePositions.end(); ++zIt)
197  {
198  const double dist = (x - zIt->second).GetMag();
199 
200  if (dist <= smallestDist) {
201  smallestDist = dist;
202  zoneName = zIt->first;
203  }
204  }
205 
206  return zoneName;
207 }
boost::transform_iterator< InternalZoneFunctor, InternalZoneIterator, const LidarZone & > ZoneIterator
ZoneIterator returns a pointer to an LidarZone.
Definition: LidarDB.h:45
CloudResult EvaluateCloudCoverage(const unsigned int eyeId, const unsigned int telescopeId, const unsigned int pixelId, const utl::Point &x) const
Evaluate coverage for a pixel with some Eye, Telescope, and Pixel ID.
std::map< std::string, double > * fCloudHeightMap
Point object.
Definition: Point.h:32
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
ZoneIterator ZonesEnd() const
End of the collection of valid Zones.
Definition: LidarDB.h:52
bool HasData() const
True if a data source is for the given model.
#define max(a, b)
Reference ellipsoids for UTM transformations.
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
Triple PointToLatitudeLongitudeHeight(const Point &thePoint) const
Convert Point to Lat/Long/Height.
std::string GetZoneName(const unsigned int eyeId) const
Store the obscuration of an FD pixel by a cloud in the field of view.
Definition: CloudResult.h:43
Detector description interface for LidarDB-realted data.
Definition: LidarDB.h:26
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
std::map< std::string, utl::Point > fZonePositions
Base class for cloud coverage calculations.
Definition: VCloudModel.h:39
ZoneIterator ZonesBegin() const
Beginning of the collection of valid Zones.
Definition: LidarDB.h:48

, generated on Tue Sep 26 2023.