Isis 3.0 Programmer Reference
Back | Home
TargetBody.cpp
1 #include "TargetBody.h"
2 
3 #include <QDataStream>
4 #include <QDebug>
5 #include <QList>
6 #include <QUuid>
7 #include <QXmlStreamWriter>
8 
9 #include <hdf5.h>
10 #include <hdf5_hl.h>
11 
12 
13 #include "Distance.h"
14 #include "IString.h"
15 #include "Project.h"
16 #include "PvlKeyword.h"
17 #include "PvlObject.h"
19 #include "XmlStackedHandlerReader.h"
20 
21 namespace Isis {
27 TargetBody::TargetBody(Target *target, QObject *parent) : QObject(parent) {
28  m_id = NULL;
29 
30  m_radii.resize(3, Distance());
32 
33  m_bodyCode = new SpiceInt;
34  m_systemCode = new SpiceInt;
35 
36  m_systemName = target->systemName();
37 
38  m_frametype = target->frameType();
39 
40  // TODO - initialize TargetBody members from target
41  *m_bodyCode = target->naifBodyCode();
43  m_radii[0] = target->radii().at(0);
44  m_radii[1] = target->radii().at(1);
45  m_radii[2] = target->radii().at(2);
46 
47  m_raPole = target->poleRaCoefs();
48  m_decPole = target->poleDecCoefs();
49  m_pm = target->pmCoefs();
50 
51  m_raNutPrec = target->poleRaNutPrecCoefs();
52  m_decNutPrec = target->poleDecNutPrecCoefs();
53  m_pmNutPrec = target->pmNutPrecCoefs();
54 
55  m_sysNutPrec0 = target->sysNutPrecConstants();
56  m_sysNutPrec1 = target->sysNutPrecCoefs();
57 
59  = new TargetBodyDisplayProperties(target->name(), this);
60 
61  m_id = new QUuid(QUuid::createUuid());
62  }
63 
64 
70 /*
71  TargetBody::TargetBody(BundleTargetBodyQsp bundleTargetBody, QObject *parent) : QObject(parent)
72  {
73  m_id = NULL;
74 
75  m_radii.resize(3, Distance());
76  m_sigmaRadii.resize(3, Distance(0.0, Distance::Kilometers));
77 
78  m_bodyCode = new SpiceInt;
79  m_systemCode = new SpiceInt;
80 
81 // m_systemName = bundleTargetBody->systemName();
82 
83  // TODO - initialize TargetBody members from bundleTargetBody
84 // *m_bodyCode = target->naifBodyCode();
85 // *m_systemCode = target->naifPlanetSystemCode();
86  m_radii = bundleTargetBody->radii();
87 // m_sigmaRadii = bundleTargetBody->
88 
89  m_raPole = bundleTargetBody->poleRaCoefs();
90  m_decPole = bundleTargetBody->poleDecCoefs();
91  m_pm = bundleTargetBody->pmCoefs();
92 
93 // m_raNutPrec = bundleTargetBody->poleRaNutPrecCoefs();
94 // m_decNutPrec = bundleTargetBody->poleDecNutPrecCoefs();
95 // m_pmNutPrec = bundleTargetBody->pmNutPrecCoefs();
96 
97 // m_sysNutPrec0 = bundleTargetBody->sysNutPrecConstants();
98 // m_sysNutPrec1 = bundleTargetBody->sysNutPrecCoefs();
99 
100 // m_displayProperties
101 // = new TargetBodyDisplayProperties(target->name(), this);
102 
103  m_id = new QUuid(QUuid::createUuid());
104  }
105 */
106 
107 // TargetBody::TargetBody(Project *project, XmlStackedHandlerReader *xmlReader,
108 // QObject *parent) : QObject(parent) {
109 // TODO: does xml stuff need project???
110 // m_id = NULL;
111 
112 // xmlReader->pushContentHandler(new XmlHandler(this, project));
113 // xmlReader->setErrorHandler(new XmlHandler(this, project));
114 // }
115 
116 
117 
118 // TargetBody::TargetBody(const TargetBody &src)
119 // : m_id(new QUuid(src.m_id->toString())) {
120 //
121 // m_bodyCode = new SpiceInt(*src.m_bodyCode);
122 //
123 // m_radii.resize(3, Distance());
124 // m_sigmaRadii.resize(3, Distance(3.0, Distance::Kilometers));
125 // TODO - radii sigma fudged for now
126 //
127 // for (int i = 0; i < 3; i++) {
128 // m_radii[i] = src.m_radii[i];
129 // m_sigmaRadii[i] = src.m_sigmaRadii[i];
130 // }
131 //
132 // m_displayProperties
133 // = new TargetBodyDisplayProperties(*src.m_displayProperties);
134 //
135 // int fred=1;
136 // m_bodyCode = src.m_bodyCode;
137 // }
138 
139 
144  delete m_id;
145  m_id = NULL;
146 
147  delete m_bodyCode;
148  m_bodyCode = NULL;
149 
150  delete m_systemCode;
151  m_systemCode = NULL;
152  }
153 
154 
155 // TargetBody &TargetBody::operator=(const TargetBody &src) {
156 
157 // if (&src != this) {
158 
159 // delete m_id;
160 // m_id = NULL;
161 // m_id = new QUuid(src.m_id->toString());
162 // }
163 
164 // return *this;
165 // }
166 
167 
175  bool TargetBody::operator==(const TargetBody &src) const {
176 
177  TargetBody *rtargetBody = (TargetBody *) &src;
178 
179  if (*m_bodyCode != rtargetBody->naifBodyCode())
180  return false;
181  if (m_radii[0] != rtargetBody->radiusA())
182  return false;
183  if (m_radii[1] != rtargetBody->radiusB())
184  return false;
185  if (m_radii[2] != rtargetBody->radiusC())
186  return false;
187 
188  return true;
189  }
190 
191 
198  return m_displayProperties;
199  }
200 
201 
208  return m_displayProperties;
209  }
210 
211 
212 // PvlObject TargetBody::pvlObject(QString resultsName, QString settingsName,
213 // QString statisticsName) {
214 
215 // PvlObject pvl(resultsName);
216 // pvl += PvlKeyword("RunTime", runTime());
217 // if (m_controlNetworkFileName->expanded() != "") {
218 // pvl += PvlKeyword("OutputControlNetwork", controlNetworkFileName());
219 // }
220 // pvl += bundleSettings()->pvlObject(settingsName);
221 // pvl += bundleResults()->pvlObject(statisticsName);
222 // return pvl;
223 
224 // }
225 
231  return m_frametype;
232  }
233 
234 
239  std::vector<Angle> TargetBody::poleRaCoefs() {
240  return m_raPole;
241  }
242 
243 
248  std::vector<Angle> TargetBody::poleDecCoefs() {
249  return m_decPole;
250  }
251 
252 
257  std::vector<Angle> TargetBody::pmCoefs() {
258  return m_pm;
259  }
260 
261 
266  std::vector<double> TargetBody::poleRaNutPrecCoefs() {
267  return m_raNutPrec;
268  }
269 
270 
275  std::vector<double> TargetBody::poleDecNutPrecCoefs() {
276  return m_decNutPrec;
277  }
278 
279 
284  std::vector<double> TargetBody::pmNutPrecCoefs() {
285  return m_pmNutPrec;
286  }
287 
288 
293  std::vector<Angle> TargetBody::sysNutPrecConstants() {
294  return m_sysNutPrec0;
295  }
296 
301  std::vector<Angle> TargetBody::sysNutPrecCoefs() {
302  return m_sysNutPrec1;
303  }
304 
305 
312  SpiceInt TargetBody::naifBodyCode() const {
313  return *m_bodyCode;
314  }
315 
316 
324  return *m_systemCode;
325  }
326 
327 
335  return m_systemName;
336  }
337 
338 
345  return m_radii[0];
346  }
347 
348 
355  return m_sigmaRadii[0];
356  }
357 
358 
365  return m_radii[1];
366  }
367 
368 
375  return m_sigmaRadii[1];
376  }
377 
378 
385  return m_radii[2];
386  }
387 
388 
395  return m_sigmaRadii[2];
396  }
397 
398 
405  Distance meanRadius = m_radii[0] + m_radii[1] + m_radii[2];
406 
407  meanRadius = meanRadius/3.0;
408 
409  return meanRadius;
410  }
411 
412 
420 
421  sigmaMeanRadius = sigmaMeanRadius/3.0;
422 
423  return sigmaMeanRadius;
424  }
425 
426 
437 // void TargetBody::save(QXmlStreamWriter &stream, const Project *project,
438 // FileName newProjectRoot) const {
439 
440 // stream.writeStartElement("TargetBody");
441 // // save ID, cnet file name, and run time to stream
442 // stream.writeStartElement("generalAttributes");
443 // stream.writeTextElement("id", m_id->toString());
444 // stream.writeTextElement("runTime", runTime());
445 // stream.writeTextElement("fileName", m_controlNetworkFileName->expanded());
446 // stream.writeEndElement(); // end general attributes
447 
448 // // save settings to stream
449 // m_settings->save(stream, project);
450 
451 // // save statistics to stream
452 // m_statisticsResults->save(stream, project);
453 
454 // // save image lists to stream
455 // if ( !m_images->isEmpty() ) {
456 // stream.writeStartElement("imageLists");
457 
458 // for (int i = 0; i < m_images->count(); i++) {
459 // m_images->at(i)->save(stream, project, "");
460 // }
461 
462 // stream.writeEndElement();
463 // }
464 // stream.writeEndElement(); //end TargetBody
465 // }
466 
467 
468 
469 // void TargetBody::save(QXmlStreamWriter &stream, const Project *project) const {
470 
471 // stream.writeStartElement("TargetBody");
472 
473 // // save ID, attributes, and run time to stream
474 // stream.writeStartElement("generalAttributes");
475 // stream.writeTextElement("id", m_id->toString());
476 // stream.writeTextElement("runTime", runTime());
477 // stream.writeEndElement(); // end general attributes
478 
479 // stream.writeEndElement(); //end TargetBody
480 // }
481 
482 
483 
491 // TargetBody::XmlHandler::XmlHandler(TargetBody *TargetBody, Project *project) {
492 // m_xmlHandlerTargetBody = TargetBody;
493 // m_xmlHandlerProject = NULL;
494 // m_xmlHandlerProject = project;
495 // m_xmlHandlerCharacters = "";
496 // }
497 
498 
499 
500 // TargetBody::XmlHandler::~XmlHandler() {
501  // TargetBody passed in is "this" delete+null will cause problems,no?
502 // delete m_xmlHandlerTargetBody;
503 // m_xmlHandlerTargetBody = NULL;
504 
505  // we do not delete this pointer since it was set to a passed in pointer in constructor and we
506  // don't own it... is that right???
507 // delete m_xmlHandlerProject;
508 // m_xmlHandlerProject = NULL;
509 // }
510 
511 
512 
518 // bool TargetBody::XmlHandler::startElement(const QString &namespaceURI, const QString &localName,
519 // const QString &qName, const QXmlAttributes &atts) {
520 // m_xmlHandlerCharacters = "";
521 //
522 // if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
523 //
524 // if (localName == "targetBody") {
525 // m_xmlHandlerTargetBody =
526 // BundleSettingsQsp(new TargetBody(m_xmlHandlerProject, reader()));
527 // }
528 // else if (localName == "bundleResults") {
529 // delete m_xmlHandlerBundleResults;
530 // m_xmlHandlerBundleResults = NULL;
531 // m_xmlHandlerBundleResults = new BundleResults(m_xmlHandlerProject, reader());
532 //TODO: need to add constructor for this???
533 // }
534 // else if (localName == "imageList") {
535 // m_xmlHandlerImages->append(new ImageList(m_xmlHandlerProject, reader()));
536 // }
537 // }
538 // return true;
539 // }
540 
541 
542 
543 // bool TargetBody::XmlHandler::characters(const QString &ch) {
544 // m_xmlHandlerCharacters += ch;
545 // return XmlStackedHandler::characters(ch);
546 // }
547 
548 
549 
550 // bool TargetBody::XmlHandler::endElement(const QString &namespaceURI, const QString &localName,
551 // const QString &qName) {
552 // if (localName == "id") {
553 // m_xmlHandlerTargetBody->m_id = NULL;
554 // m_xmlHandlerTargetBody->m_id = new QUuid(m_xmlHandlerCharacters);
555 // }
556 // else if (localName == "runTime") {
557 // m_xmlHandlerTargetBody->m_runTime = m_xmlHandlerCharacters;
558 // }
559 // else if (localName == "fileName") {
560 // m_xmlHandlerTargetBody->m_controlNetworkFileName = NULL;
561 // m_xmlHandlerTargetBody->m_controlNetworkFileName = new FileName(m_xmlHandlerCharacters);
562 // }
563 // else if (localName == "bundleSettings") {
564 // m_xmlHandlerTargetBody->m_settings =
565 // BundleSettingsQsp(new BundleSettings(*m_xmlHandlerBundleSettings));
566 // }
567 // else if (localName == "bundleResults") {
568 // m_xmlHandlerTargetBody->m_statisticsResults = new BundleResults(*m_xmlHandlerBundleResults);
569 // }
570 // if (localName == "imageLists") {
571 // for (int i = 0; i < m_xmlHandlerImages->size(); i++) {
572 // m_xmlHandlerTargetBody->m_images->append(m_xmlHandlerImages->at(i));
573 // }
574 // m_xmlHandlerImages->clear();
575 // }
576 // m_xmlHandlerCharacters = "";
577 // return XmlStackedHandler::endElement(namespaceURI, localName, qName);
578 // }
579 
580 
581 
587  QString TargetBody::id() const {
588  return m_id->toString().remove(QRegExp("[{}]"));
589  }
590 
591 
592 // QDataStream &TargetBody::write(QDataStream &stream) const {
593 // stream << m_id->toString()
594 // << m_runTime;
595 //
596 // return stream;
597 // }
598 
599 
600 
601 // QDataStream &TargetBody::read(QDataStream &stream) {
602 
603 // QString id;
604 // stream >> id;
605 // delete m_id;
606 // m_id = NULL;
607 // m_id = new QUuid(id);
608 
609 // stream >> m_runTime;
610 
611 // return stream;
612 // }
613 
614 
615 
616 // QDataStream &operator<<(QDataStream &stream, const TargetBody &TargetBody) {
617 // return TargetBody.write(stream);
618 // }
619 
620 
621 
622 // QDataStream &operator>>(QDataStream &stream, TargetBody &TargetBody) {
623 // return TargetBody.read(stream);
624 // }
625 
626 
627 
628 // void TargetBody::savehdf5(FileName outputfilename) const {
629 // const H5std_string hdfFileName(outputfilename.expanded().toStdString());
630 //Is this the right way to have a dynamic file name? What about PATH?
631 
632 
633 // // Try block to detect exceptions raised by any of the calls inside it
634 // try {
635 // /*
636 // * Turn off the auto-printing when failure occurs so that we can
637 // * handle the errors appropriately
638 // */
639 // H5::Exception::dontPrint();
640 // /*
641 // * Create a new file using H5F_ACC_TRUNC access,
642 // * default file creation properties, and default file
643 // * access properties.
644 // */
645 // H5::H5File hdfFile = H5::H5File( hdfFileName, H5F_ACC_EXCL );
646 // hid_t fileId = hdfFile.getId();
647 //
648 // QString objectName = "/TargetBody";
649 // H5LTset_attribute_string(fileId, objectName.toLatin1(), "runTime", m_runTime.toAscii());
650 // H5LTset_attribute_string(fileId, objectName.toLatin1(), "controlNetworkFileName",
651 // m_controlNetworkFileName->expanded().toLatin1());
652 //
653 // //??? H5::Group settingsGroup = H5::Group(hdfFile.
654 // createGroup("/TargetBody/BundleSettings"));
655 // //???
656 // //???H5::Group settingsGroup = hdfFile.createGroup("/TargetBody/BundleSettings");
657 // QString groupName = objectName + "/BundleSettings";
658 // hid_t groupId = H5Gcreate(fileId, groupName.toLatin1(),
659 // H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
660 // m_settings->savehdf5(groupId, groupName.toLatin1());
661 // groupName = objectName + "/BundleResults";
662 // H5::Group resultsGroup = H5::Group(hdfFile.createGroup(groupName.toLatin1()));
663 // m_statisticsResults->savehdf5(fileId, resultsGroup);
664 //
665 // }
666 // catch (H5::FileIException error) {
667 // QString msg = QString(error.getCDetailMsg());
668 // IException hpfError(IException::Unknown, msg, _FILEINFO_);
669 // msg = "Unable to save TargetBody to hpf5 file. "
670 // "H5 exception handler has detected a file error.";
671 // throw IException(hpfError, IException::Unknown, msg, _FILEINFO_);
672 // }
673 // }
674 }
QString naifPlanetSystemName() const
This returns the body name of the target&#39;s planet system.
Definition: TargetBody.cpp:334
std::vector< double > m_pmNutPrec
Coefficients of prime meridian nut/prec terms.
Definition: TargetBody.h:217
std::vector< Angle > m_sysNutPrec0
Constants of planetary system nut/prec periods.
Definition: TargetBody.h:220
Distance meanRadius() const
Returns the mean radius.
Definition: TargetBody.cpp:404
TargetBodyDisplayProperties * m_displayProperties
The GUI information for how this Target will be displayed.
Definition: TargetBody.h:203
Container class for TargetBody.
Definition: TargetBody.h:77
SpiceInt naifPlanetSystemCode() const
This returns the NAIF body code of the target&#39;s planet system.
Definition: TargetBody.cpp:323
std::vector< Distance > radii() const
Returns the radii of the body in km.
Definition: Target.cpp:499
std::vector< Angle > sysNutPrecCoefs()
Returns Linear terms of planetary system nut/prec periods.
Definition: TargetBody.cpp:301
std::vector< Angle > sysNutPrecConstants()
Returns constants of planetary system nut/prec periods.
Definition: TargetBody.cpp:293
SpiceInt * m_systemCode
The NaifBodyCode system code.
Definition: TargetBody.h:183
int m_frametype
Fill this in when Debbie or Ken tell me what it is returning.
Definition: TargetBody.h:205
QString systemName() const
Return planet system name.
Definition: Target.cpp:489
int frameType()
Returns the frame type.
Definition: TargetBody.cpp:230
~TargetBody()
The second constructor for this class.
Definition: TargetBody.cpp:143
std::vector< Angle > poleDecCoefs()
Returns coefficients of a quadratic polynomial fitting pole dec.
Definition: TargetBody.cpp:248
SpiceInt naifBodyCode() const
This returns the NAIF body code of the target.
Definition: TargetBody.cpp:312
This is the GUI communication mechanism for target body objects.
std::vector< Angle > m_raPole
Coefficients of a quadratic polynomial fitting pole ra.
Definition: TargetBody.h:208
SpiceInt naifBodyCode() const
This returns the NAIF body code of the target.
Definition: Target.cpp:464
The distance is being specified in kilometers.
Definition: Distance.h:58
TargetBodyDisplayProperties * displayProperties()
Gets TargetBodyDisplayProperties.
Definition: TargetBody.cpp:197
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
std::vector< double > poleDecNutPrecCoefs()
TargetBody::poleDecNutPrecCoefs.
Definition: TargetBody.cpp:275
std::vector< double > poleRaNutPrecCoefs()
Returns coefficients of pole right ascension nut/prec terms.
Definition: TargetBody.cpp:266
Distance measurement, usually in meters.
Definition: Distance.h:47
std::vector< Angle > m_sysNutPrec1
Linear terms of planetary system nut/prec periods.
Definition: TargetBody.h:221
std::vector< Angle > m_pm
Coefficients of a quadratic polynomial fitting pole pm.
Definition: TargetBody.h:210
std::vector< Distance > m_sigmaRadii
target radii sigmas
Definition: TargetBody.h:198
Distance sigmaMeanRadius() const
Returns the mean radius sigma.
Definition: TargetBody.cpp:418
SpiceInt * m_bodyCode
TODO - RETHINK MEMBER VARIABLES AND METHODS The NaifBodyCode value, if it exists in the cube labels...
Definition: TargetBody.h:178
QString name() const
Return target name.
Definition: Target.cpp:483
Distance sigmaRadiusB() const
Returns &quot;b&quot; radius sigma.
Definition: TargetBody.cpp:374
TargetBody(Target *target, QObject *parent=0)
The first constructor for this class.
Definition: TargetBody.cpp:27
Distance sigmaRadiusA() const
Returns &quot;a&quot; radius sigma.
Definition: TargetBody.cpp:354
Distance sigmaRadiusC() const
Returns the &quot;c&quot; radius sigma.
Definition: TargetBody.cpp:394
Distance radiusB() const
Returns &quot;b&quot; radius.
Definition: TargetBody.cpp:364
bool operator==(const TargetBody &src) const
Compares two Target Body objects to see if they are equal.
Definition: TargetBody.cpp:175
std::vector< double > pmNutPrecCoefs()
Returns coefficients of the prime meridian nut/prec terms.
Definition: TargetBody.cpp:284
This class is used to create and store valid Isis3 targets.
Definition: Target.h:63
QUuid * m_id
A unique ID for this TargetBody object (useful for others to reference this object when saving to dis...
Definition: TargetBody.h:171
QString id() const
Output format:
Definition: TargetBody.cpp:587
std::vector< Angle > poleRaCoefs()
TargetBody::poleRaCoefs.
Definition: TargetBody.cpp:239
std::vector< Distance > m_radii
target radii
Definition: TargetBody.h:193
std::vector< Angle > m_decPole
Coefficients of a quadratic polynomial fitting pole dec.
Definition: TargetBody.h:209
SpiceInt naifPlanetSystemCode() const
This returns the NAIF planet system body code of the target.
Definition: Target.cpp:477
std::vector< double > m_decNutPrec
Coefficients of pole decliniation nut/prec terms.
Definition: TargetBody.h:216
QString m_systemName
The NaifBodyCode system name.
Definition: TargetBody.h:188
std::vector< double > m_raNutPrec
Coefficients of pole right ascension nut/prec terms.
Definition: TargetBody.h:215
std::vector< Angle > pmCoefs()
Returns coefficients of a quadratic polynomial fitting pole pm.
Definition: TargetBody.cpp:257
Distance radiusC() const
Returns the &quot;c&quot; radius.
Definition: TargetBody.cpp:384
Distance radiusA() const
Returns &quot;a&quot; radius.
Definition: TargetBody.cpp:344

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:30:33