Isis 3 Programmer Reference
PlaneShape.cpp
1 #include <algorithm>
2 #include <cfloat>
3 #include <string>
4 #include <vector>
5 
6 #include <cmath>
7 #include <iomanip>
8 
9 #include "PlaneShape.h"
10 
11 #include "Distance.h"
12 #include "IException.h"
13 #include "Latitude.h"
14 #include "Longitude.h"
15 #include "NaifStatus.h"
16 #include "ShapeModel.h"
17 #include "SurfacePoint.h"
18 
19 namespace Isis {
25  PlaneShape::PlaneShape(Target *target, Pvl &pvl) : ShapeModel (target) {
26  setName("Plane");
27 
28  // set surface normal
29  // setNormal(0.0, 0.0, 1.0);
30  }
31 
32 
39  setName("Plane");
40 
41  // set normal vector
42  // setNormal(0.0, 0.0, 1.0);
43  }
44 
45 
52  setName("Plane");
53  }
54 
55 
60  }
61 
62 
71  bool PlaneShape::intersectSurface (std::vector<double> observerPos,
72  std::vector<double> lookDirection) {
74  SpiceDouble zvec[3];
75  SpicePlane plane;
76  SpiceInt nxpts;
77  SpiceDouble xpt[3];
78 
79 // std::vector<double> n = normal();
80 
81 // zvec[0] = n[0];
82 // zvec[1] = n[1];
83 // zvec[2] = n[2];
84  zvec[0] = 0.0;
85  zvec[1] = 0.0;
86  zvec[2] = 1.0;
87 
88  if (observerPos[2] < 0.0)
89  zvec[2] = -zvec[2];
90 
91  // NAIF routine to "Make a CSPICE plane from a normal vector and a constant"
92  // see http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/nvc2pl_c.html
93  nvc2pl_c(zvec, 0.0, &plane);
94 
95  SpiceDouble position[3];
96  SpiceDouble lookvector[3];
97 
98  position[0] = observerPos[0];
99  position[1] = observerPos[1];
100  position[2] = observerPos[2];
101 
102  lookvector[0] = lookDirection[0];
103  lookvector[1] = lookDirection[1];
104  lookvector[2] = lookDirection[2];
105 
106  // NAIF routine to "find the intersection of a ray and a plane"
107  // see http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inrypl_c.html
108  inrypl_c(&position, &lookvector, &plane, &nxpts, xpt);
109 
110  if (nxpts != 1 ) {
111  setHasIntersection(false);
112  return false;
113  }
114 
115  setHasIntersection(true);
116  setNormal(0.0,0.0,1.0);
119 
120  return true;
121  }
122 
123 
131  bool PlaneShape::isDEM() const {
132  return false;
133  }
134 
135 
140  }
141 
142 
147  }
148 
149 
154  }
155 
156 
172  double PlaneShape::emissionAngle(const std::vector<double> & sB) {
173 
174  SpiceDouble pB[3]; // surface intersection in body-fixed coordinates
175  SpiceDouble psB[3]; // vector from spacecraft to surface intersection
176  SpiceDouble upsB[3]; // unit vector from spacecraft to surface intersection
177  SpiceDouble dist; // vector magnitude
178 
179  // Get vector from center of body to surface point
180  pB[0] = surfaceIntersection()->GetX().kilometers();
181  pB[1] = surfaceIntersection()->GetY().kilometers();
182  pB[2] = surfaceIntersection()->GetZ().kilometers();
183 
184  // Get vector from surface intersect point to observer and normalize it
185  vsub_c((ConstSpiceDouble *) &sB[0], pB, psB);
186  unorm_c(psB, upsB, &dist);
187 
188  // temporary normal vector
189  SpiceDouble n[3];
190  n[0] = 0.0;
191  n[1] = 0.0;
192  n[2] = 1.0;
193 
194  // flip normal if observer is "below" the plane, assuming that the target
195  // body north pole defines the "up" direction
196  if (sB[2] < 0.0)
197  n[2] = -n[2];
198 
199  // dot product of surface normal and observer-surface intersection vector
200  double angle = vdot_c(n, upsB);
201 
202  if (angle > 1.0)
203  return 0.0;
204 
205  if (angle < -1.0)
206  return 180.0;
207 
208  return acos(angle) * RAD2DEG;
209  }
210 
211 
229  double PlaneShape::incidenceAngle(const std::vector<double> &uB) {
230 
231  SpiceDouble pB[3]; // surface intersection in body-fixed coordinates
232  SpiceDouble puB[3]; // vector from sun to surface intersection
233  SpiceDouble upuB[3]; // unit vector from sun to surface intersection
234  SpiceDouble dist; // vector magnitude
235 
236  // Get vector from center of body to surface point
237  pB[0] = surfaceIntersection()->GetX().kilometers();
238  pB[1] = surfaceIntersection()->GetY().kilometers();
239  pB[2] = surfaceIntersection()->GetZ().kilometers();
240 
241  // Get vector from surface intersect point to sun and normalize it
242  vsub_c((SpiceDouble *) &uB[0], pB, puB);
243  unorm_c(puB, upuB, &dist);
244 
245  // temporary normal vector
246  SpiceDouble n[3];
247  n[0] = 0.0;
248  n[1] = 0.0;
249  n[2] = 1.0;
250 
251  // flip normal if sun is "below" the plane, assuming that the target
252  // body north pole defines the "up" direction
253  if (uB[2] < 0.0)
254  n[2] = -n[2];
255 
256  double angle = vdot_c((SpiceDouble *) &n[0], upuB);
257 
258  if (angle > 1.0)
259  return 0.0;
260 
261  if(angle < -1.0)
262  return 180.0;
263 
264  return acos(angle) * RAD2DEG;
265  }
266 
267 
277  // TODO: what should this do in the case of a ring plane (or any other plane
278  // for that matter)?
280 
281  SpiceDouble pB[3]; // surface intersection in body-fixed coordinates
282 
283  // Get vector from center of body to surface point
284  pB[0] = surfaceIntersection()->GetX().kilometers();
285  pB[1] = surfaceIntersection()->GetY().kilometers();
286  pB[2] = surfaceIntersection()->GetZ().kilometers();
287 
288  double radius = sqrt(pB[0]*pB[0] + pB[1]*pB[1] + pB[2]*pB[2]);
289 
290  return Distance(radius, Distance::Kilometers);
291  }
292 }
bool isDEM() const
Indicates that this shape model is not from a DEM.
Definition: PlaneShape.cpp:131
void setNormal(const std::vector< double >)
Sets the normal for the currect intersection point.
Definition: ShapeModel.cpp:481
void calculateSurfaceNormal()
There is no implementation for this method.
Definition: PlaneShape.cpp:139
Distance localRadius(const Latitude &lat, const Longitude &lon)
Gets the local radius for the given latitude/longitude coordinate.
Definition: PlaneShape.cpp:279
This class is designed to encapsulate the concept of a Latitude.
Definition: Latitude.h:63
The distance is being specified in kilometers.
Definition: Distance.h:58
SurfacePoint * surfaceIntersection() const
Returns the surface intersection for this ShapeModel.
Definition: ShapeModel.cpp:352
void calculateLocalNormal(QVector< double *> cornerNeighborPoints)
There is no implementation for this method.
Definition: PlaneShape.cpp:153
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Distance measurement, usually in meters.
Definition: Distance.h:47
double incidenceAngle(const std::vector< double > &uB)
Computes and returns incidence angle in degrees given the sun position.
Definition: PlaneShape.cpp:229
void setHasIntersection(bool b)
Sets the flag to indicate whether this ShapeModel has an intersection.
Definition: ShapeModel.cpp:548
This class is designed to encapsulate the concept of a Longitude.
Definition: Longitude.h:52
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
Find the intersection point.
Definition: PlaneShape.cpp:71
PlaneShape()
Initialize the PlaneShape.
Definition: PlaneShape.cpp:51
~PlaneShape()
Destructor.
Definition: PlaneShape.cpp:59
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 calculateDefaultNormal()
There is no implementation for this method.
Definition: PlaneShape.cpp:146
void FromNaifArray(const double naifValues[3])
A naif array is a c-style array of size 3.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:43
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void setName(QString name)
Sets the shape name.
Definition: ShapeModel.cpp:526
const double RAD2DEG
Multiplier for converting from radians to degrees.
Definition: Constants.h:60
double kilometers() const
Get the displacement in kilometers.
double emissionAngle(const std::vector< double > &sB)
Computes and returns emission angle in degrees given the observer position.
Definition: PlaneShape.cpp:172
Unless noted otherwise, the portions of Isis written by the USGS are public domain.