27#include "CubeManager.h"
29#include "EllipsoidShape.h"
31#include "IException.h"
32#include "Interpolator.h"
36#include "NaifStatus.h"
38#include "Projection.h"
41#include "SurfacePoint.h"
44#include "UniqueIOCachingAlgorithm.h"
61 m_demValue = -std::numeric_limits<double>::max();
80 m_demValue = -std::numeric_limits<double>::max();
82 PvlGroup &kernels = pvl.findGroup(
"Kernels", Pvl::Traverse);
85 if (kernels.hasKeyword(
"ElevationModel")) {
86 demCubeFile = (QString) kernels[
"ElevationModel"];
88 else if(kernels.hasKeyword(
"ShapeModel")) {
89 demCubeFile = (QString) kernels[
"ShapeModel"];
108 const PvlGroup &mapgrp =
m_demCube->label()->findGroup(
"Mapping", Pvl::Traverse);
142 vector<double>
const& lookDirection,
144 double * intersectionPoint,
151 for (
size_t i = 0; i < 3; i++)
152 intersectionPoint[i] = observerPos[i] + t * lookDirection[i];
154 double pointRadiusKm = sqrt(intersectionPoint[0]*intersectionPoint[0] +
155 intersectionPoint[1]*intersectionPoint[1] +
156 intersectionPoint[2]*intersectionPoint[2]);
161 double norm2 = intersectionPoint[0] * intersectionPoint[0] +
162 intersectionPoint[1] * intersectionPoint[1];
163 double latDD = atan2(intersectionPoint[2], sqrt(norm2)) * RAD2DEG;
164 double lonDD = atan2(intersectionPoint[1], intersectionPoint[0]) * RAD2DEG;
174 if (Isis::IsSpecial(surfaceRadiusKm.
kilometers())) {
185 return pointRadiusKm - surfaceRadiusKm.
kilometers();
201 vector<double> lookDirection) {
204 double positionNormKm = 0.0;
205 for (
size_t i = 0; i < observerPos.size(); i++)
206 positionNormKm += observerPos[i]*observerPos[i];
207 positionNormKm = sqrt(positionNormKm);
211 SpiceDouble newIntersectPt[3];
216 r = std::min(r, positionNormKm - 0.0001);
221 surfpt_c((SpiceDouble *) &observerPos[0], &lookDirection[0], r, r, r, newIntersectPt,
222 (SpiceBoolean*) &status);
226 for (
size_t i = 0; i < 3; i++)
227 newIntersectPt[i] = observerPos[i];
236 double t0 = ((newIntersectPt[0] - observerPos[0]) * lookDirection[0] +
237 (newIntersectPt[1] - observerPos[1]) * lookDirection[1] +
238 (newIntersectPt[2] - observerPos[2]) * lookDirection[2])
239 / (lookDirection[0] * lookDirection[0] +
240 lookDirection[1] * lookDirection[1] +
241 lookDirection[2] * lookDirection[2]);
243 bool success =
false;
244 double intersectionPoint[3];
248 intersectionPoint, success);
250 std::vector<double> delta = {1.0, 0.1, 10.0, 100.0, 1000.0, 5000.0, 10000.0};
251 for (
size_t i = 0; i < delta.size(); i++) {
252 double try_t = t0 + delta[i] / 1000.0;
254 intersectionPoint, success);
269 std::vector<double> delta = {1.0, 0.1, 10.0, 0.01, 100.0};
270 double t1 = 0, f1 = 0;
272 for (
size_t i = 0; i < delta.size(); i++) {
273 t1 = t0 + delta[i] / 1000.0;
275 intersectionPoint, success);
288 bool converged =
false;
291 double tolFactor = 1000.0;
293 for (
int i = 1; i <= 15; i++) {
296 if (std::abs(f1) * 1000.0 < tol) {
302 if (std::abs(f1) * 1000.0 < tol) {
311 if (f1 == f0 && std::abs(f1) * 1000.0 >= tol) {
317 double t2 = t1 - f1 * (t1 - t0) / (f1 - f0);
319 intersectionPoint, success);
352 int numSamples =
m_demCube->sampleCount();
358 int sampleSpacing = std::max(numSamples / (num + 1), 1);
359 int lineSpacing = std::max(numLines / (num + 1), 1);
362 for (
int s = sampleSpacing; s <= numSamples - sampleSpacing; s += sampleSpacing) {
363 for (
int l = lineSpacing; l <= numLines - lineSpacing; l += lineSpacing) {
367 if (!Isis::IsSpecial(
m_portal->DoubleBuffer()[0])) {
377 double a = radii[0].kilometers();
378 double b = radii[1].kilometers();
379 double c = radii[2].kilometers();
461 std::vector<SpiceDouble>
normal(3);
462 if (neighborPoints.isEmpty()) {
470 double topMinusBottom[3];
471 vsub_c(neighborPoints[0], neighborPoints[1], topMinusBottom);
472 double rightMinusLeft[3];
473 vsub_c(neighborPoints[3], neighborPoints [2], rightMinusLeft);
476 ucrss_c(topMinusBottom, rightMinusLeft, (SpiceDouble *) &
normal[0]);
480 unorm_c((SpiceDouble *) &
normal[0], (SpiceDouble *) &
normal[0], &mag);
496 double centerLookVect[3];
499 unorm_c(pB, centerLookVect, &mag);
500 double dotprod = vdot_c((SpiceDouble *) &
normal[0], centerLookVect);
502 vminus_c((SpiceDouble *) &
normal[0], (SpiceDouble *) &
normal[0]);
bool isValid() const
This indicates whether we have a legitimate angle stored or are in an unset, or invalid,...
double degrees() const
Get the angle in units of Degrees.
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
IO Handler for Isis Cubes.
static Cube * Open(const QString &cubeFileName)
This method calls the method OpenCube() on the static instance.
Projection * m_demProj
The projection of the model.
Cube * m_demCube
The cube containing the model.
~DemShape()
Destroys the DemShape.
Interpolator * m_interp
Use bilinear interpolation from dem.
Portal * m_portal
Buffer used to read from the model.
double m_demValue
A value picked from the dem.
bool m_demValueFound
True if it was attempted to find a value in the DEM.
double calcDemErrUpdateIntersection(std::vector< double > const &observerPos, std::vector< double > const &lookDirection, double t, double *intersectionPoint, bool &success)
Given a position along a ray, compute the difference between the radius at that position and the surf...
Distance localRadius(const Latitude &lat, const Longitude &lon)
Gets the radius from the DEM, if we have one.
double demScale()
Return the scale of the DEM shape, in pixels per degree.
double findDemValue()
Find a value in the DEM.
DemShape()
Construct a DemShape object.
Cube * demCube()
Returns the cube defining the shape model.
bool isDEM() const
Indicates that this shape model is from a DEM.
void calculateLocalNormal(QVector< double * > cornerNeighborPoints)
This method calculates the local surface normal of the current intersection point.
double m_pixPerDegree
Scale of DEM file in pixels per degree.
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
Find the intersection point with the DEM.
Distance measurement, usually in meters.
double kilometers() const
Get the distance in kilometers.
@ Meters
The distance is being specified in meters.
This class is designed to encapsulate the concept of a Latitude.
This class is designed to encapsulate the concept of a Longitude.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Buffer for containing a two dimensional section of an image.
double resolution()
Convenience method to get pixel resolution (m/pix) at current intersection point.
void setHasIntersection(bool b)
Sets the flag to indicate whether this ShapeModel has an intersection.
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.
virtual std::vector< double > normal()
Returns the surface normal at the current intersection point.
std::vector< Distance > targetRadii() const
Returns the radii of the body in km.
void setHasLocalNormal(bool status)
Sets the flag to indicate whether this ShapeModel has a local normal.
ShapeModel()
Default constructor creates ShapeModel object, initializing name to an empty string,...
void setName(QString name)
Sets the shape name.
void ToNaifArray(double naifOutput[3]) const
A naif array is a c-style array of size 3.
void FromNaifArray(const double naifValues[3])
A naif array is a c-style array of size 3.
This class is used to create and store valid Isis targets.
This algorithm is designed for applications that jump around between a couple of spots in the cube wi...
This is free and unencumbered software released into the public domain.
Namespace for the standard library.