USGS

Isis 3.0 Object Programmers' Reference

Home

Target.cpp
Go to the documentation of this file.
1 
22 #include "Target.h"
23 
24 #include "Distance.h"
25 #include "EllipsoidShape.h"
26 #include "IException.h"
27 #include "NaifStatus.h"
28 #include "Pvl.h"
29 #include "ShapeModelFactory.h"
30 #include "Spice.h"
31 
32 
33 using namespace std;
34 
35 namespace Isis {
36 
48  // TODO: what is needed to initialize?
49  Target::Target(Spice *spice, Pvl &lab) {
50 
51  // Initialize members
52  init();
53  m_bodyCode = new SpiceInt;
54  m_radii.resize(3, Distance());
55  m_spice = spice;
56 
57  // If we get this far, we know we have a kernels group. Spice requires it.
58  PvlGroup &kernels = lab.findGroup("Kernels", Pvl::Traverse);
59 
60  PvlGroup &inst = lab.findGroup("Instrument", Pvl::Traverse);
61  m_name = new QString;
62  *m_name = inst["TargetName"][0];
63  QString trykey = "NaifIkCode";
64  if (kernels.hasKeyword("NaifFrameCode")) trykey = "NaifFrameCode";
65 
66  if (name().toUpper() == "SKY") {
67  m_radii[0] = m_radii[1] = m_radii[2] = Distance(1000.0, Distance::Meters);
68  m_sky = true;
69  int ikCode = toInt(kernels[trykey][0]);
70  *m_bodyCode = ikCode / 1000;
71  // Check for override in kernel group
72  if (kernels.hasKeyword("NaifSpkCode"))
73  *m_bodyCode = (int) kernels["NaifSpkCode"];
74  }
75  else {
76  *m_bodyCode = lookupNaifBodyCode();
77  m_sky = false;
78  // IString radiiKey = "BODY" + IString((BigInt) naifBodyCode()) + "_RADII";
79  // m_radii[0] = Distance(getDouble(radiiKey, 0), Distance::Kilometers);
80  // m_radii[1] = Distance(getDouble(radiiKey, 1), Distance::Kilometers);
81  // m_radii[2] = Distance(getDouble(radiiKey, 2), Distance::Kilometers);
82  }
83  // Override it if it exists in the labels
84  if (kernels.hasKeyword("NaifBodyCode"))
85  *m_bodyCode = (int) kernels["NaifBodyCode"];
86  m_shape = ShapeModelFactory::create(this, lab);
87  }
88 
89 
99  Target::Target() {
100  m_bodyCode = NULL;
101  m_name = NULL;
102  m_spice = NULL;
103  init();
104  }
105 
106 
115  void Target::init() {
116  m_shape = NULL;
117  m_originalShape = NULL;
118  m_sky = false;
119  }
120 
121 
122 
126  Target::~Target() {
127  NaifStatus::CheckErrors();
128 
129  delete m_bodyCode;
130  m_bodyCode = NULL;
131 
132  delete m_name;
133  m_name = NULL;
134 
135  if (m_radii.size() != 0) {
136  m_radii.clear();
137  }
138 
139  delete m_originalShape;
140  m_originalShape = NULL;
141 
142  delete m_shape;
143  m_shape = NULL;
144  }
145 
146 
148  bool Target::isSky() const {
149  return m_sky;
150  }
151 
152 
159  SpiceInt Target::lookupNaifBodyCode() const {
160  SpiceInt code;
161  SpiceBoolean found;
162  bodn2c_c(m_name->toAscii().data(), &code, &found);
163  if (!found) {
164  IString msg = "Could not convert Target [" + *m_name +
165  "] to NAIF code";
166  throw IException(IException::Io, msg, _FILEINFO_);
167  }
168 
169  return code;
170  }
171 
172 
179  SpiceInt Target::naifBodyCode() const {
180  return *m_bodyCode;
181  }
182 
183 
185  QString Target::name() const {
186  return *m_name;
187  }
188 
189 
195  std::vector<Distance> Target::radii() const {
196  return m_radii;
197  }
198 
199 
203  void Target::restoreShape() {
204  if (m_shape->name() != "Ellipsoid") {
205  // Nothing to do
206  return;
207  }
208  // If we don't have a saved original shape, just stick to the current shape
209  else if (m_originalShape == NULL) {
210  // Nothing to do
211  return;
212  }
213  m_shape = m_originalShape;
214  m_originalShape = NULL;
215  }
216 
217 
221  void Target::setShapeEllipsoid() {
222  // Save the current shape to restore later
223  m_originalShape = m_shape;
224  m_shape = new EllipsoidShape(this);
225  }
226 
227 
233  void Target::setRadii(std::vector<Distance> radii) {
234  m_radii[0] = radii[0];
235  m_radii[1] = radii[1];
236  m_radii[2] = radii[2];
237  }
238 
239 
243  ShapeModel *Target::shape() const {
244  return m_shape;
245  }
246 
247 
251  Spice *Target::spice() const {
252  return m_spice;
253  }
254 }