USGS

Isis 3.0 Object Programmers' Reference

Home

CameraPointInfo.cpp
Go to the documentation of this file.
1 
23 #include "CameraPointInfo.h"
24 
25 #include <QDebug>
26 
27 #include <iomanip>
28 
29 #include "Brick.h"
30 #include "Camera.h"
31 #include "Cube.h"
32 #include "CubeManager.h"
33 #include "Distance.h"
34 #include "IException.h"
35 #include "iTime.h"
36 #include "Longitude.h"
37 #include "SpecialPixel.h"
38 #include "TProjection.h"
39 #include "PvlGroup.h"
40 
41 using namespace Isis;
42 using namespace std;
43 
44 namespace Isis {
45 
46 
53  m_usedCubes = NULL;
54  m_usedCubes = new CubeManager();
55  m_usedCubes->SetNumOpenCubes(50);
56  m_currentCube = NULL;
57  m_camera = NULL;
58  }
59 
65  if (m_usedCubes) {
66  delete m_usedCubes;
67  m_usedCubes = NULL;
68  }
69  }
70 
71 
79  void CameraPointInfo::SetCube(const QString &cubeFileName) {
80  m_currentCube = m_usedCubes->OpenCube(cubeFileName);
81  m_camera = m_currentCube->camera();
82  }
83 
84 
95  PvlGroup *CameraPointInfo::SetImage(const double sample, const double line,
96  const bool outside, const bool errors) {
97  if (CheckCube()) {
98  bool passed = m_camera->SetImage(sample, line);
99  return GetPointInfo(passed, outside, errors);
100  }
101  // Should never get here, error will be thrown in CheckCube()
102  return NULL;
103  }
104 
111  PvlGroup *CameraPointInfo::SetCenter(const bool outside, const bool errors) {
112  if (CheckCube()) {
113  bool passed = m_camera->SetImage(m_currentCube->sampleCount() / 2.0,
114  m_currentCube->lineCount() / 2.0);
115  return GetPointInfo(passed, outside, errors);
116  }
117  // Should never get here, error will be thrown in CheckCube()
118  return NULL;
119  }
120 
121 
129  PvlGroup *CameraPointInfo::SetSample(const double sample,
130  const bool outside, const bool errors) {
131  if (CheckCube()) {
132  bool passed = m_camera->SetImage(sample, m_currentCube->lineCount() / 2.0);
133  return GetPointInfo(passed, outside, errors);
134  }
135  // Should never get here, error will be thrown in CheckCube()
136  return NULL;
137  }
138 
139 
147  PvlGroup *CameraPointInfo::SetLine(const double line,
148  const bool outside, const bool errors) {
149  if (CheckCube()) {
150  bool passed = m_camera->SetImage(m_currentCube->sampleCount() / 2.0, line);
151  return GetPointInfo(passed, outside, errors);
152  }
153  // Should never get here, error will be thrown in CheckCube()
154  return NULL;
155  }
156 
157 
170  PvlGroup *CameraPointInfo::SetGround(const double latitude, const double longitude,
171  const bool outside, const bool errors) {
172  if (CheckCube()) {
173  bool passed = m_camera->SetUniversalGround(latitude, longitude);
174  return GetPointInfo(passed, outside, errors);
175  }
176  // Should never get here, error will be thrown in CheckCube()
177  return NULL;
178  }
179 
180 
188  if (m_currentCube == NULL) {
189  string msg = "Please set a cube before setting parameters";
191  return false;
192  }
193  return true;
194  }
195 
203  PvlGroup *CameraPointInfo::GetPointInfo(bool passed, bool allowOutside, bool allowErrors) {
204  PvlGroup *gp = new PvlGroup("GroundPoint");
205  {
206  gp->addKeyword(PvlKeyword("Filename"));
207  gp->addKeyword(PvlKeyword("Sample"));
208  gp->addKeyword(PvlKeyword("Line"));
209  gp->addKeyword(PvlKeyword("PixelValue"));
210  gp->addKeyword(PvlKeyword("RightAscension"));
211  gp->addKeyword(PvlKeyword("Declination"));
212  gp->addKeyword(PvlKeyword("PlanetocentricLatitude"));
213  gp->addKeyword(PvlKeyword("PlanetographicLatitude"));
214  gp->addKeyword(PvlKeyword("PositiveEast360Longitude"));
215  gp->addKeyword(PvlKeyword("PositiveEast180Longitude"));
216  gp->addKeyword(PvlKeyword("PositiveWest360Longitude"));
217  gp->addKeyword(PvlKeyword("PositiveWest180Longitude"));
218  gp->addKeyword(PvlKeyword("BodyFixedCoordinate"));
219  gp->addKeyword(PvlKeyword("LocalRadius"));
220  gp->addKeyword(PvlKeyword("SampleResolution"));
221  gp->addKeyword(PvlKeyword("LineResolution"));
222  gp->addKeyword(PvlKeyword("SpacecraftPosition"));
223  gp->addKeyword(PvlKeyword("SpacecraftAzimuth"));
224  gp->addKeyword(PvlKeyword("SlantDistance"));
225  gp->addKeyword(PvlKeyword("TargetCenterDistance"));
226  gp->addKeyword(PvlKeyword("SubSpacecraftLatitude"));
227  gp->addKeyword(PvlKeyword("SubSpacecraftLongitude"));
228  gp->addKeyword(PvlKeyword("SpacecraftAltitude"));
229  gp->addKeyword(PvlKeyword("OffNadirAngle"));
230  gp->addKeyword(PvlKeyword("SubSpacecraftGroundAzimuth"));
231  gp->addKeyword(PvlKeyword("SunPosition"));
232  gp->addKeyword(PvlKeyword("SubSolarAzimuth"));
233  gp->addKeyword(PvlKeyword("SolarDistance"));
234  gp->addKeyword(PvlKeyword("SubSolarLatitude"));
235  gp->addKeyword(PvlKeyword("SubSolarLongitude"));
236  gp->addKeyword(PvlKeyword("SubSolarGroundAzimuth"));
237  gp->addKeyword(PvlKeyword("Phase"));
238  gp->addKeyword(PvlKeyword("Incidence"));
239  gp->addKeyword(PvlKeyword("Emission"));
240  gp->addKeyword(PvlKeyword("NorthAzimuth"));
241  gp->addKeyword(PvlKeyword("EphemerisTime"));
242  gp->addKeyword(PvlKeyword("UTC"));
243  gp->addKeyword(PvlKeyword("LocalSolarTime"));
244  gp->addKeyword(PvlKeyword("SolarLongitude"));
245  if (allowErrors) gp->addKeyword(PvlKeyword("Error"));
246  }
247 
248  bool noErrors = passed;
249  QString error = "";
250  if (!m_camera->HasSurfaceIntersection()) {
251  error = "Requested position does not project in camera model; no surface intersection";
252  noErrors = false;
253  if (!allowErrors) throw IException(IException::Unknown, error, _FILEINFO_);
254  }
255  if (!m_camera->InCube() && !allowOutside) {
256  error = "Requested position does not project in camera model; not inside cube";
257  noErrors = false;
258  if (!allowErrors) throw IException(IException::Unknown, error, _FILEINFO_);
259  }
260 
261  if (!noErrors) {
262  for (int i = 0; i < gp->keywords(); i++) {
263  QString name = (*gp)[i].name();
264  // These three keywords have 3 values, so they must have 3 NULLs
265  if (name == "BodyFixedCoordinate" || name == "SpacecraftPosition" ||
266  name == "SunPosition") {
267  (*gp)[i].addValue("NULL");
268  (*gp)[i].addValue("NULL");
269  (*gp)[i].addValue("NULL");
270  }
271  else {
272  (*gp)[i].setValue("NULL");
273  }
274  }
275  // Set all keywords that still have valid information
276  gp->findKeyword("Error").setValue(error);
277  gp->findKeyword("FileName").setValue(m_currentCube->fileName());
278  gp->findKeyword("Sample").setValue(toString(m_camera->Sample()));
279  gp->findKeyword("Line").setValue(toString(m_camera->Line()));
280  gp->findKeyword("EphemerisTime").setValue(
281  toString(m_camera->time().Et()), "seconds");
282  gp->findKeyword("EphemerisTime").addComment("Time");
283  QString utc = m_camera->time().UTC();
284  gp->findKeyword("UTC").setValue(utc);
285  gp->findKeyword("SpacecraftPosition").addComment("Spacecraft Information");
286  gp->findKeyword("SunPosition").addComment("Sun Information");
287  gp->findKeyword("Phase").addComment("Illumination and Other");
288  }
289 
290  else {
291 
292  Brick b(3, 3, 1, m_currentCube->pixelType());
293 
294  int intSamp = (int)(m_camera->Sample() + 0.5);
295  int intLine = (int)(m_camera->Line() + 0.5);
296  b.SetBasePosition(intSamp, intLine, 1);
297  m_currentCube->read(b);
298 
299  double pB[3], spB[3], sB[3];
300  QString utc;
301  double ssplat, ssplon, sslat, sslon, ocentricLat, ographicLat, pe360Lon, pw360Lon;
302 
303  {
304  gp->findKeyword("FileName").setValue(m_currentCube->fileName());
305  gp->findKeyword("Sample").setValue(toString(m_camera->Sample()));
306  gp->findKeyword("Line").setValue(toString(m_camera->Line()));
307  gp->findKeyword("PixelValue").setValue(PixelToString(b[0]));
308  gp->findKeyword("RightAscension").setValue(toString(
309  m_camera->RightAscension()));
310  gp->findKeyword("Declination").setValue(toString(
311  m_camera->Declination()));
312  ocentricLat = m_camera->UniversalLatitude();
313  gp->findKeyword("PlanetocentricLatitude").setValue(toString(ocentricLat));
314 
315  // Convert lat to planetographic
316  Distance radii[3];
317  m_camera->radii(radii);
318  ographicLat = TProjection::ToPlanetographic(ocentricLat,
319  radii[0].kilometers(),
320  radii[2].kilometers());
321  gp->findKeyword("PlanetographicLatitude").setValue(toString(ographicLat));
322 
323  pe360Lon = m_camera->UniversalLongitude();
324  gp->findKeyword("PositiveEast360Longitude").setValue(toString(pe360Lon));
325 
326  //Convert lon to -180 - 180 range
327  gp->findKeyword("PositiveEast180Longitude").setValue(toString(
328  TProjection::To180Domain(pe360Lon)));
329 
330  //Convert lon to positive west
331  pw360Lon = TProjection::ToPositiveWest(pe360Lon, 360);
332  gp->findKeyword("PositiveWest360Longitude").setValue(toString(pw360Lon));
333 
334  //Convert pwlon to -180 - 180 range
335  gp->findKeyword("PositiveWest180Longitude").setValue(
337 
338  m_camera->Coordinate(pB);
339  gp->findKeyword("BodyFixedCoordinate").addValue(toString(pB[0]), "km");
340  gp->findKeyword("BodyFixedCoordinate").addValue(toString(pB[1]), "km");
341  gp->findKeyword("BodyFixedCoordinate").addValue(toString(pB[2]), "km");
342 
343  gp->findKeyword("LocalRadius").setValue(toString(
344  m_camera->LocalRadius().meters()), "meters");
345 
346  gp->findKeyword("SampleResolution").setValue(toString(
347  m_camera->SampleResolution()), "meters/pixel");
348  gp->findKeyword("LineResolution").setValue(toString(
349  m_camera->LineResolution()), "meters/pixel");
350 
351  //body fixed
352  m_camera->instrumentPosition(spB);
353  gp->findKeyword("SpacecraftPosition").addValue(toString(spB[0]), "km");
354  gp->findKeyword("SpacecraftPosition").addValue(toString(spB[1]), "km");
355  gp->findKeyword("SpacecraftPosition").addValue(toString(spB[2]), "km");
356  gp->findKeyword("SpacecraftPosition").addComment("Spacecraft Information");
357 
358  double spacecraftAzi = m_camera->SpacecraftAzimuth();
359  if (Isis::IsValidPixel(spacecraftAzi)) {
360  gp->findKeyword("SpacecraftAzimuth").setValue(toString(spacecraftAzi));
361  }
362  else {
363  gp->findKeyword("SpacecraftAzimuth").setValue("NULL");
364  }
365 
366  gp->findKeyword("SlantDistance").setValue(toString(
367  m_camera->SlantDistance()), "km");
368  gp->findKeyword("TargetCenterDistance").setValue(toString(
369  m_camera->targetCenterDistance()), "km");
370  m_camera->subSpacecraftPoint(ssplat, ssplon);
371  gp->findKeyword("SubSpacecraftLatitude").setValue(toString(ssplat));
372  gp->findKeyword("SubSpacecraftLongitude").setValue(toString(ssplon));
373  gp->findKeyword("SpacecraftAltitude").setValue(toString(
374  m_camera->SpacecraftAltitude()), "km");
375  gp->findKeyword("OffNadirAngle").setValue(toString(
376  m_camera->OffNadirAngle()));
377  double subspcgrdaz = m_camera->GroundAzimuth(m_camera->UniversalLatitude(),
378  m_camera->UniversalLongitude(),
379  ssplat, ssplon);
380  gp->findKeyword("SubSpacecraftGroundAzimuth").setValue(toString(subspcgrdaz));
381 
382  m_camera->sunPosition(sB);
383  gp->findKeyword("SunPosition").addValue(toString(sB[0]), "km");
384  gp->findKeyword("SunPosition").addValue(toString(sB[1]), "km");
385  gp->findKeyword("SunPosition").addValue(toString(sB[2]), "km");
386  gp->findKeyword("SunPosition").addComment("Sun Information");
387 
388  double sunAzi = m_camera->SunAzimuth();
389  if (Isis::IsValidPixel(sunAzi)) {
390  gp->findKeyword("SubSolarAzimuth").setValue(toString(sunAzi));
391  }
392  else {
393  gp->findKeyword("SubSolarAzimuth").setValue("NULL");
394  }
395 
396  gp->findKeyword("SolarDistance").setValue(toString(
397  m_camera->SolarDistance()), "AU");
398  m_camera->subSolarPoint(sslat, sslon);
399  gp->findKeyword("SubSolarLatitude").setValue(toString(sslat));
400  gp->findKeyword("SubSolarLongitude").setValue(toString(sslon));
401  double subsolgrdaz = m_camera->GroundAzimuth(m_camera->UniversalLatitude(),
402  m_camera->UniversalLongitude(),
403  sslat, sslon);
404  gp->findKeyword("SubSolarGroundAzimuth").setValue(toString(subsolgrdaz));
405 
406  gp->findKeyword("Phase").setValue(toString(m_camera->PhaseAngle()));
407  gp->findKeyword("Phase").addComment("Illumination and Other");
408  gp->findKeyword("Incidence").setValue(toString(
409  m_camera->IncidenceAngle()));
410  gp->findKeyword("Emission").setValue(toString(
411  m_camera->EmissionAngle()));
412 
413  double northAzi = m_camera->NorthAzimuth();
414  if (Isis::IsValidPixel(northAzi)) {
415  gp->findKeyword("NorthAzimuth").setValue(toString(northAzi));
416  }
417  else {
418  gp->findKeyword("NorthAzimuth").setValue("NULL");
419  }
420 
421  gp->findKeyword("EphemerisTime").setValue(toString(
422  m_camera->time().Et()), "seconds");
423  gp->findKeyword("EphemerisTime").addComment("Time");
424  utc = m_camera->time().UTC();
425  gp->findKeyword("UTC").setValue(utc);
426  gp->findKeyword("LocalSolarTime").setValue(toString(
427  m_camera->LocalSolarTime()), "hour");
428  gp->findKeyword("SolarLongitude").setValue(toString(
429  m_camera->solarLongitude().degrees()));
430  if (allowErrors) gp->findKeyword("Error").setValue("NULL");
431  }
432  }
433  return gp;
434  }
435 
436 
437  Camera *CameraPointInfo::camera() {
438  return m_camera;
439  }
440 
441  Cube *CameraPointInfo::cube() {
442  return m_currentCube;
443  }
444 }