Isis 3 Programmer Reference
NaifDskShape.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "NaifDskShape.h"
8 
9 #include <numeric>
10 
11 #include <QtGlobal>
12 #include <QVector>
13 
14 #include "IException.h"
15 #include "Intercept.h"
16 #include "IString.h"
17 #include "Latitude.h"
18 #include "Longitude.h"
19 #include "NaifDskApi.h"
20 #include "NaifDskPlateModel.h"
21 #include "NaifStatus.h"
22 #include "Pvl.h"
23 #include "ShapeModel.h"
24 #include "SpecialPixel.h"
25 #include "Statistics.h"
26 #include "SurfacePoint.h"
27 #include "Target.h"
28 
29 
30 using namespace std;
31 
32 namespace Isis {
33 
35  NaifDskShape::NaifDskShape() : ShapeModel(), m_intercept(NULL) {
36  // defaults for ShapeModel parent class include:
37  // name = empty string
38  // surfacePoint = null sp
39  // hasIntersection = false
40  // hasNormal = false
41  // normal = (0,0,0)
42  // hasEllipsoidIntersection = false
43  setName("DSK");
44  }
45 
59  NaifDskShape::NaifDskShape(Target *target, Pvl &pvl) : ShapeModel(target),
60  m_intercept(NULL) {
61 
62  // defaults for ShapeModel parent class include:
63  // name = empty string
64  // surfacePoint = null sp
65  // hasIntersection = false
66  // hasNormal = false
67  // normal = (0,0,0)
68  // hasEllipsoidIntersection = false
69 
70  setName("DSK"); // Really is used as type in the system at present!
71 
72  PvlGroup &kernels = pvl.findGroup("Kernels", Pvl::Traverse);
73 
74  QString dskFile;
75  if (kernels.hasKeyword("ElevationModel")) {
76  dskFile = (QString) kernels["ElevationModel"];
77  }
78  else { // if (kernels.hasKeyword("ShapeModel")) {
79  dskFile = (QString) kernels["ShapeModel"];
80  }
81 
82  // Attempt to initialize the DSK file - exception ensues if errors occur
83  // error thrown if ShapeModel=Null (i.e. Ellipsoid)
84  m_model = NaifDskPlateModel(dskFile);
85 
86  }
87 
102  m_model(model), m_intercept(NULL) {
103 
104  // TODO create valid Target
105  // Using this constructor, ellipsoidNormal(),
106  // calculateSurfaceNormal(), and setLocalNormalFromIntercept()
107  // methods can not be called
108  }
109 
110 
113 
114 
133  bool NaifDskShape::intersectSurface(std::vector<double> observerPos,
134  std::vector<double> lookDirection) {
135  NaifVertex obs(3, &observerPos[0]);
136  NaifVector raydir(3, &lookDirection[0]);
137  m_intercept.reset(m_model.intercept(obs, raydir));
138 
139  bool success = !m_intercept.isNull();
140  if (success) {
141  SurfacePoint point = m_intercept->location();
142  setSurfacePoint(point); // sets ShapeModel::m_hasIntersection=t, ShapeModel::m_hasNormal=f
143  }
144  return ( success );
145  }
146 
164  const Longitude &lon) {
165  QScopedPointer<SurfacePoint> pnt(m_model.point(lat, lon));
166  if ( !pnt.isNull() ) return (pnt->GetLocalRadius());
167  return (Distance());
168  }
169 
180 
181  // Sanity check
182  if ( !hasIntersection() ) { // hasIntersection() <==> !m_intercept.isNull()
183  QString mess = "Intercept point does not exist - cannot provide normal vector";
184  throw IException(IException::Programmer, mess, _FILEINFO_);
185  }
186 
187  // Got it, use the existing intercept point (plate) normal
188  NaifVector norm(m_intercept->normal());
189  setNormal(norm[0], norm[1], norm[2]); // this also takes care of setHasNormal(true);
190  return;
191  }
192 
193 
201  bool NaifDskShape::isDEM() const {
202  return false;
203  }
204 
205 
232 
233  // Sanity check
234  if ( !hasIntersection() ) { // hasIntersection() <==> !m_intercept.isNull()
235  QString mess = "Intercept point does not exist - cannot provide normal vector";
236  throw IException(IException::Programmer, mess, _FILEINFO_);
237  }
238 
240  return;
241  }
242 
243 
246  // ShapeModel (parent class) throws error if no intersection
248  }
249 
252  // ShapeModel (parent class) throws error if no intersection
253  setNormal(ellipsoidNormal().toStdVector());// this takes care of setHasNormal(true);
254  return;
255  }
256 
272 
273  // Sanity check on state
274  if ( !hasIntersection() ) {
275  QString msg = "An intersection must be defined before computing the surface normal.";
276  throw IException(IException::Programmer, msg, _FILEINFO_);
277  }
278  if ( !surfaceIntersection()->Valid() ) {
279  QString msg = "The surface point intersection must be valid to compute the surface normal.";
280  throw IException(IException::Programmer, msg, _FILEINFO_);
281  }
282  if (!hasValidTarget()) {
283  QString msg = "A valid target must be defined before computing the surface normal.";
284  throw IException(IException::Programmer, msg, _FILEINFO_);
285  }
286 
287  // Get the coordinates of the current surface point
288  SpiceDouble pB[3];
290 
291  // Get the body radii and compute the true normal of the ellipsoid
292  QVector<double> norm(3);
293  // need a case for target == NULL
296  surfnm_c(radii[0].kilometers(), radii[1].kilometers(), radii[2].kilometers(),
297  pB, &norm[0]);
299 
300  return (norm);
301  }
302 
305  return (m_model);
306  }
307 
321  return ( m_intercept.data() );
322  }
323 
324 }; // namespace Isis
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::NaifDskShape::ellipsoidNormal
QVector< double > ellipsoidNormal()
Compute the true surface normal vector of an ellipsoid.
Definition: NaifDskShape.cpp:271
Isis::NaifVertex
TNT::Array1D< SpiceDouble > NaifVertex
1-D Buffer[3]
Definition: NaifDskApi.h:47
Isis::Latitude
This class is designed to encapsulate the concept of a Latitude.
Definition: Latitude.h:51
Isis::ShapeModel::surfaceIntersection
SurfacePoint * surfaceIntersection() const
Returns the surface intersection for this ShapeModel.
Definition: ShapeModel.cpp:358
Isis::ShapeModel::setSurfacePoint
virtual void setSurfacePoint(const SurfacePoint &surfacePoint)
Set surface intersection point.
Definition: ShapeModel.cpp:565
Isis::ShapeModel::targetRadii
std::vector< Distance > targetRadii() const
Returns the radii of the body in km.
Definition: ShapeModel.cpp:465
Isis::NaifDskShape::calculateDefaultNormal
void calculateDefaultNormal()
Return the surface normal of the ellipsoid as the default.
Definition: NaifDskShape.cpp:245
Isis::NaifDskShape::model
const NaifDskPlateModel & model() const
Returns a direct reference to the DSK plate model file interface.
Definition: NaifDskShape.cpp:304
Isis::NaifDskShape::isDEM
bool isDEM() const
Indicates that this shape model is not from a DEM.
Definition: NaifDskShape.cpp:201
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::NaifDskShape::NaifDskShape
NaifDskShape()
Generic constructor sets type to a TIN.
Definition: NaifDskShape.cpp:35
Isis::NaifStatus::CheckErrors
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:28
Isis::ShapeModel::setNormal
void setNormal(const std::vector< double >)
Sets the normal for the currect intersection point.
Definition: ShapeModel.cpp:487
Isis::NaifDskShape::intersectSurface
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
Compute a DEM intersection from and observer and look direction.
Definition: NaifDskShape.cpp:133
Isis::NaifDskShape::calculateSurfaceNormal
void calculateSurfaceNormal()
Return the surface normal of the ellipsi=oud.
Definition: NaifDskShape.cpp:251
Isis::NaifDskShape::intercept
const Intercept * intercept() const
Returns a pointer to the current intercept.
Definition: NaifDskShape.cpp:320
Isis::NaifDskShape::setLocalNormalFromIntercept
void setLocalNormalFromIntercept()
Set the normal vector to the intercept point normal.
Definition: NaifDskShape.cpp:179
Isis::Distance
Distance measurement, usually in meters.
Definition: Distance.h:34
Isis::Longitude
This class is designed to encapsulate the concept of a Longitude.
Definition: Longitude.h:40
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::NaifDskShape::localRadius
Distance localRadius(const Latitude &lat, const Longitude &lon)
Determine DEM radius at a given lat/lon grid point.
Definition: NaifDskShape.cpp:163
Isis::ShapeModel::setName
void setName(QString name)
Sets the shape name.
Definition: ShapeModel.cpp:532
Isis::NaifDskPlateModel::intercept
Intercept * intercept(const NaifVertex &vertex, const NaifVector &raydir) const
Determine a target body intercept point from an observer and look direction.
Definition: NaifDskPlateModel.cpp:179
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::NaifDskShape::m_intercept
QScopedPointer< Intercept > m_intercept
Pointer to the shape's intercept.
Definition: NaifDskShape.h:82
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::ShapeModel::hasValidTarget
bool hasValidTarget() const
Returns the status of the target.
Definition: ShapeModel.cpp:449
Isis::ShapeModel
Define shapes and provide utilities for Isis targets.
Definition: ShapeModel.h:62
Isis::Intercept
Container for a intercept condition.
Definition: Intercept.h:36
Isis::SurfacePoint::ToNaifArray
void ToNaifArray(double naifOutput[3]) const
A naif array is a c-style array of size 3.
Definition: SurfacePoint.cpp:870
Isis::ShapeModel::hasIntersection
bool hasIntersection()
Returns intersection status.
Definition: ShapeModel.cpp:368
QVector
This is free and unencumbered software released into the public domain.
Definition: Calculator.h:18
Isis::NaifDskPlateModel
Implementation interface API for NAIF's DSK plate model.
Definition: NaifDskPlateModel.h:49
Isis::NaifVector
TNT::Array1D< SpiceDouble > NaifVector
Namespace to contain type definitions of NAIF DSK fundamentals.
Definition: NaifDskApi.h:46
Isis::NaifDskShape::m_model
NaifDskPlateModel m_model
Plate model to intersect.
Definition: NaifDskShape.h:81
Isis::Target
This class is used to create and store valid Isis targets.
Definition: Target.h:63
Isis::NaifDskPlateModel::point
SurfacePoint * point(const Latitude &lat, const Longitude &lon) const
Get surface intersection for a lat/lon grid point.
Definition: NaifDskPlateModel.cpp:121
Isis::SurfacePoint
This class defines a body-fixed surface point.
Definition: SurfacePoint.h:132
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::NaifDskShape::~NaifDskShape
~NaifDskShape()
Destructor - cleanup is handled automagically.
Definition: NaifDskShape.cpp:112
Isis::NaifDskShape::calculateLocalNormal
void calculateLocalNormal(QVector< double * > cornerNeighborPoints)
Compute the normal for a local region of surface points.
Definition: NaifDskShape.cpp:231