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
30using namespace std;
31
32namespace 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
46
61 m_intercept(NULL) {
62
63 // defaults for ShapeModel parent class include:
64 // name = empty string
65 // surfacePoint = null sp
66 // hasIntersection = false
67 // hasNormal = false
68 // normal = (0,0,0)
69 // hasEllipsoidIntersection = false
70
71 setName("DSK"); // Really is used as type in the system at present!
72
73 PvlGroup &kernels = pvl.findGroup("Kernels", Pvl::Traverse);
74
75 QString dskFile;
76 if (kernels.hasKeyword("ElevationModel")) {
77 dskFile = (QString) kernels["ElevationModel"];
78 }
79 else { // if (kernels.hasKeyword("ShapeModel")) {
80 dskFile = (QString) kernels["ShapeModel"];
81 }
82
83 // Attempt to initialize the DSK file - exception ensues if errors occur
84 // error thrown if ShapeModel=Null (i.e. Ellipsoid)
85 m_model = NaifDskPlateModel(dskFile);
86
87 }
88
89
104 m_model(model), m_intercept(NULL) {
105
106 // TODO create valid Target
107 // Using this constructor, ellipsoidNormal(),
108 // calculateSurfaceNormal(), and setLocalNormalFromIntercept()
109 // methods can not be called
110 }
111
112
115
116
135 bool NaifDskShape::intersectSurface(std::vector<double> observerPos,
136 std::vector<double> lookDirection) {
137 NaifVertex obs(3, &observerPos[0]);
138 NaifVector raydir(3, &lookDirection[0]);
139 m_intercept.reset(m_model.intercept(obs, raydir));
140
141 bool success = !m_intercept.isNull();
142 if (success) {
143 SurfacePoint point = m_intercept->location();
144 setSurfacePoint(point); // sets ShapeModel::m_hasIntersection=t, ShapeModel::m_hasNormal=f
145 }
146 return ( success );
147 }
148
149
167 const std::vector<double> &observerPos,
168 const bool &backCheck) {
169
170 std::vector<double> look(3);
171 look[0] = surfpt.GetX().kilometers() - observerPos[0];
172 look[1] = surfpt.GetY().kilometers() - observerPos[1];
173 look[2] = surfpt.GetZ().kilometers() - observerPos[2];
174
175 return intersectSurface(observerPos, look);
176
177 }
178
179
197 const Longitude &lon) {
198 QScopedPointer<SurfacePoint> pnt(m_model.point(lat, lon));
199 if ( !pnt.isNull() ) return (pnt->GetLocalRadius());
200 return (Distance());
201 }
202
203
214
215 // Sanity check
216 if ( !hasIntersection() ) { // hasIntersection() <==> !m_intercept.isNull()
217 QString mess = "Intercept point does not exist - cannot provide normal vector";
218 throw IException(IException::Programmer, mess, _FILEINFO_);
219 }
220
221 // Got it, use the existing intercept point (plate) normal
222 NaifVector norm(m_intercept->normal());
223 setLocalNormal(norm[0], norm[1], norm[2]); // this also takes care of setHasLocalNormal(true);
224 return;
225 }
226
227
235 bool NaifDskShape::isDEM() const {
236 return false;
237 }
238
239
265 void NaifDskShape::calculateLocalNormal(QVector<double *> neighborPoints) {
266 // Sanity check
267 if ( !hasIntersection() ) { // hasIntersection() <==> !m_intercept.isNull()
268 QString mess = "Intercept point does not exist - cannot provide normal vector";
269 throw IException(IException::Programmer, mess, _FILEINFO_);
270 }
271
273 return;
274 }
275
276
279 // ShapeModel (parent class) throws error if no intersection
281 }
282
283
286 // ShapeModel (parent class) throws error if no intersection
287 setNormal(ellipsoidNormal().toStdVector());// this takes care of setHasNormal(true);
288 return;
289 }
290
291
307
308 // Sanity check on state
309 if ( !hasIntersection() ) {
310 QString msg = "An intersection must be defined before computing the surface normal.";
311 throw IException(IException::Programmer, msg, _FILEINFO_);
312 }
313 if ( !surfaceIntersection()->Valid() ) {
314 QString msg = "The surface point intersection must be valid to compute the surface normal.";
315 throw IException(IException::Programmer, msg, _FILEINFO_);
316 }
317 if (!hasValidTarget()) {
318 QString msg = "A valid target must be defined before computing the surface normal.";
319 throw IException(IException::Programmer, msg, _FILEINFO_);
320 }
321
322 // Get the coordinates of the current surface point
323 SpiceDouble pB[3];
324 surfaceIntersection()->ToNaifArray(pB);
325
326 // Get the body radii and compute the true normal of the ellipsoid
327 QVector<double> norm(3);
328 // need a case for target == NULL
329 QVector<Distance> radii = QVector<Distance>::fromStdVector(targetRadii());
331 surfnm_c(radii[0].kilometers(), radii[1].kilometers(), radii[2].kilometers(),
332 pB, &norm[0]);
334
335 return (norm);
336 }
337
338
341 return (m_model);
342 }
343
344
358 return ( m_intercept.data() );
359 }
360
361}; // namespace Isis
Distance measurement, usually in meters.
Definition Distance.h:34
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Container for a intercept condition.
Definition Intercept.h:36
This class is designed to encapsulate the concept of a Latitude.
Definition Latitude.h:51
This class is designed to encapsulate the concept of a Longitude.
Definition Longitude.h:40
Implementation interface API for NAIF's DSK plate model.
Intercept * intercept(const NaifVertex &vertex, const NaifVector &raydir) const
Determine a target body intercept point from an observer and look direction.
SurfacePoint * point(const Latitude &lat, const Longitude &lon) const
Get surface intersection for a lat/lon grid point.
QScopedPointer< Intercept > m_intercept
Pointer to the shape's intercept.
void setLocalNormalFromIntercept()
Set the local normal vector to the intercept point normal.
const Intercept * intercept() const
Returns a pointer to the current intercept.
QVector< double > ellipsoidNormal()
Compute the true surface normal vector of an ellipsoid.
NaifDskShape()
Generic constructor sets type to a TIN.
NaifDskPlateModel m_model
Plate model to intersect.
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
Compute a DEM intersection from and observer and look direction.
void calculateDefaultNormal()
Return the surface normal of the ellipsoid as the default.
Distance localRadius(const Latitude &lat, const Longitude &lon)
Determine DEM radius at a given lat/lon grid point.
void calculateSurfaceNormal()
Return the surface normal of the ellipsoid.
void calculateLocalNormal(QVector< double * > cornerNeighborPoints)
Compute the normal for a local region of surface points.
bool isDEM() const
Indicates that this shape model is not from a DEM.
~NaifDskShape()
Destructor - cleanup is handled automagically.
const NaifDskPlateModel & model() const
Returns a direct reference to the DSK plate model file interface.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
@ Traverse
Search child objects.
Definition PvlObject.h:158
Define shapes and provide utilities for Isis targets.
Definition ShapeModel.h:66
bool hasIntersection()
Returns intersection status.
void setNormal(const std::vector< double >)
Sets the surface normal for the currect intersection point.
void setLocalNormal(const std::vector< double >)
Sets the local normal for the currect intersection point.
virtual SurfacePoint * surfaceIntersection() const
Returns the surface intersection for this ShapeModel.
bool hasValidTarget() const
Returns the status of the target.
virtual void setSurfacePoint(const SurfacePoint &surfacePoint)
Set surface intersection point.
std::vector< Distance > targetRadii() const
Returns the radii of the body in km.
void setName(QString name)
Sets the shape name.
This class defines a body-fixed surface point.
This class is used to create and store valid Isis targets.
Definition Target.h:63
This is free and unencumbered software released into the public domain.
Definition Calculator.h:18
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
TNT::Array1D< SpiceDouble > NaifVector
Namespace to contain type definitions of NAIF DSK fundamentals.
Definition NaifDskApi.h:46
TNT::Array1D< SpiceDouble > NaifVertex
1-D Buffer[3]
Definition NaifDskApi.h:47
Namespace for the standard library.