Isis 3 Programmer Reference
NaifDskShape.cpp
Go to the documentation of this file.
1 
25 #include "NaifDskShape.h"
26 
27 #include <numeric>
28 
29 #include <QtGlobal>
30 #include <QVector>
31 
32 #include "IException.h"
33 #include "Intercept.h"
34 #include "IString.h"
35 #include "Latitude.h"
36 #include "Longitude.h"
37 #include "NaifDskApi.h"
38 #include "NaifDskPlateModel.h"
39 #include "NaifStatus.h"
40 #include "Pvl.h"
41 #include "ShapeModel.h"
42 #include "SpecialPixel.h"
43 #include "Statistics.h"
44 #include "SurfacePoint.h"
45 #include "Target.h"
46 
47 
48 using namespace std;
49 
50 namespace Isis {
51 
53  NaifDskShape::NaifDskShape() : ShapeModel(), m_intercept(NULL) {
54  // defaults for ShapeModel parent class include:
55  // name = empty string
56  // surfacePoint = null sp
57  // hasIntersection = false
58  // hasNormal = false
59  // normal = (0,0,0)
60  // hasEllipsoidIntersection = false
61  setName("DSK");
62  }
63 
77  NaifDskShape::NaifDskShape(Target *target, Pvl &pvl) : ShapeModel(target),
78  m_intercept(NULL) {
79 
80  // defaults for ShapeModel parent class include:
81  // name = empty string
82  // surfacePoint = null sp
83  // hasIntersection = false
84  // hasNormal = false
85  // normal = (0,0,0)
86  // hasEllipsoidIntersection = false
87 
88  setName("DSK"); // Really is used as type in the system at present!
89 
90  PvlGroup &kernels = pvl.findGroup("Kernels", Pvl::Traverse);
91 
92  QString dskFile;
93  if (kernels.hasKeyword("ElevationModel")) {
94  dskFile = (QString) kernels["ElevationModel"];
95  }
96  else { // if (kernels.hasKeyword("ShapeModel")) {
97  dskFile = (QString) kernels["ShapeModel"];
98  }
99 
100  // Attempt to initialize the DSK file - exception ensues if errors occur
101  // error thrown if ShapeModel=Null (i.e. Ellipsoid)
102  m_model = NaifDskPlateModel(dskFile);
103 
104  }
105 
120  m_model(model), m_intercept(NULL) {
121 
122  // TODO create valid Target
123  // Using this constructor, ellipsoidNormal(),
124  // calculateSurfaceNormal(), and setLocalNormalFromIntercept()
125  // methods can not be called
126  }
127 
128 
131 
132 
151  bool NaifDskShape::intersectSurface(std::vector<double> observerPos,
152  std::vector<double> lookDirection) {
153  NaifVertex obs(3, &observerPos[0]);
154  NaifVector raydir(3, &lookDirection[0]);
155  m_intercept.reset(m_model.intercept(obs, raydir));
156 
157  bool success = !m_intercept.isNull();
158  if (success) {
159  SurfacePoint point = m_intercept->location();
160  setSurfacePoint(point); // sets ShapeModel::m_hasIntersection=t, ShapeModel::m_hasNormal=f
161  }
162  return ( success );
163  }
164 
182  const Longitude &lon) {
183  QScopedPointer<SurfacePoint> pnt(m_model.point(lat, lon));
184  if ( !pnt.isNull() ) return (pnt->GetLocalRadius());
185  return (Distance());
186  }
187 
198 
199  // Sanity check
200  if ( !hasIntersection() ) { // hasIntersection() <==> !m_intercept.isNull()
201  QString mess = "Intercept point does not exist - cannot provide normal vector";
203  }
204 
205  // Got it, use the existing intercept point (plate) normal
206  NaifVector norm(m_intercept->normal());
207  setNormal(norm[0], norm[1], norm[2]); // this also takes care of setHasNormal(true);
208  return;
209  }
210 
211 
219  bool NaifDskShape::isDEM() const {
220  return false;
221  }
222 
223 
250 
251  // Sanity check
252  if ( !hasIntersection() ) { // hasIntersection() <==> !m_intercept.isNull()
253  QString mess = "Intercept point does not exist - cannot provide normal vector";
255  }
256 
258  return;
259  }
260 
261 
264  // ShapeModel (parent class) throws error if no intersection
266  }
267 
270  // ShapeModel (parent class) throws error if no intersection
271  setNormal(ellipsoidNormal().toStdVector());// this takes care of setHasNormal(true);
272  return;
273  }
274 
290 
291  // Sanity check on state
292  if ( !hasIntersection() ) {
293  QString msg = "An intersection must be defined before computing the surface normal.";
295  }
296  if ( !surfaceIntersection()->Valid() ) {
297  QString msg = "The surface point intersection must be valid to compute the surface normal.";
299  }
300  if (!hasValidTarget()) {
301  QString msg = "A valid target must be defined before computing the surface normal.";
303  }
304 
305  // Get the coordinates of the current surface point
306  SpiceDouble pB[3];
308 
309  // Get the body radii and compute the true normal of the ellipsoid
310  QVector<double> norm(3);
311  // need a case for target == NULL
314  surfnm_c(radii[0].kilometers(), radii[1].kilometers(), radii[2].kilometers(),
315  pB, &norm[0]);
317 
318  return (norm);
319  }
320 
323  return (m_model);
324  }
325 
339  return ( m_intercept.data() );
340  }
341 
342 }; // namespace Isis
This class defines a body-fixed surface point.
Definition: SurfacePoint.h:148
void calculateSurfaceNormal()
Return the surface normal of the ellipsi=oud.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
void setLocalNormalFromIntercept()
Set the normal vector to the intercept point normal.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
bool hasValidTarget() const
Returns the status of the target.
Definition: ShapeModel.cpp:443
void setNormal(const std::vector< double >)
Sets the normal for the currect intersection point.
Definition: ShapeModel.cpp:481
bool hasIntersection()
Returns intersection status.
Definition: ShapeModel.cpp:362
const Intercept * intercept() const
Returns a pointer to the current intercept.
NaifDskPlateModel m_model
Plate model to intersect.
Definition: NaifDskShape.h:97
Namespace for the standard library.
This class is designed to encapsulate the concept of a Latitude.
Definition: Latitude.h:63
QVector< double > ellipsoidNormal()
Compute the true surface normal vector of an ellipsoid.
Search child objects.
Definition: PvlObject.h:170
SurfacePoint * surfaceIntersection() const
Returns the surface intersection for this ShapeModel.
Definition: ShapeModel.cpp:352
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
Distance measurement, usually in meters.
Definition: Distance.h:47
~NaifDskShape()
Destructor - cleanup is handled automagically.
TNT::Array1D< SpiceDouble > NaifVector
Namespace to contain type definitions of NAIF DSK fundamentals.
Definition: NaifDskApi.h:61
std::vector< Distance > targetRadii() const
Returns the radii of the body in km.
Definition: ShapeModel.cpp:459
Intercept * intercept(const NaifVertex &vertex, const NaifVector &raydir) const
Determine a target body intercept point from an observer and look direction.
This class is designed to encapsulate the concept of a Longitude.
Definition: Longitude.h:52
TNT::Array1D< SpiceDouble > NaifVertex
1-D Buffer[3]
Definition: NaifDskApi.h:62
SurfacePoint * point(const Latitude &lat, const Longitude &lon) const
Get surface intersection for a lat/lon grid point.
NaifDskShape()
Generic constructor sets type to a TIN.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Container for a intercept condition.
Definition: Intercept.h:51
QScopedPointer< Intercept > m_intercept
Pointer to the shape&#39;s intercept.
Definition: NaifDskShape.h:98
const NaifDskPlateModel & model() const
Returns a direct reference to the DSK plate model file interface.
Distance localRadius(const Latitude &lat, const Longitude &lon)
Determine DEM radius at a given lat/lon grid point.
Container for cube-like labels.
Definition: Pvl.h:135
This class is used to create and store valid Isis3 targets.
Definition: Target.h:76
Define shapes and provide utilities for Isis3 targets.
Definition: ShapeModel.h:78
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
void ToNaifArray(double naifOutput[3]) const
A naif array is a c-style array of size 3.
void calculateLocalNormal(QVector< double *> cornerNeighborPoints)
Compute the normal for a local region of surface points.
virtual void setSurfacePoint(const SurfacePoint &surfacePoint)
Set surface intersection point.
Definition: ShapeModel.cpp:559
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:43
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void calculateDefaultNormal()
Return the surface normal of the ellipsoid as the default.
void setName(QString name)
Sets the shape name.
Definition: ShapeModel.cpp:526
Implementation interface API for NAIF&#39;s DSK plate model.
bool isDEM() const
Indicates that this shape model is not from a DEM.
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
Compute a DEM intersection from and observer and look direction.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.