11 #include "EllipsoidShape.h"
13 #include "IException.h"
14 #include "NaifStatus.h"
17 #include "ShapeModelFactory.h"
18 #include "SpecialPixel.h"
42 m_bodyCode =
new SpiceInt;
43 m_systemCode =
new SpiceInt;
53 *m_name = inst[
"TargetName"][0];
54 QString trykey =
"NaifIkCode";
56 m_systemName =
new QString;
59 trykey =
"NaifFrameCode";
62 if (name().toUpper() ==
"SKY") {
63 m_radii[0] = m_radii[1] = m_radii[2] =
Distance(1000.0, Distance::Meters);
65 int ikCode =
toInt(kernels[trykey][0]);
66 *m_bodyCode = ikCode / 1000;
69 *m_bodyCode = (int) kernels[
"NaifSpkCode"];
73 (*m_systemName).append(
"THE COSMOS");
77 *m_bodyCode = lookupNaifBodyCode(lab);
80 *m_systemCode = (*m_bodyCode/100)*100 + 99;
82 SpiceChar naifBuf[40];
84 bodc2n_c((SpiceInt) *m_systemCode,
sizeof(naifBuf), naifBuf, &found);
85 NaifStatus::CheckErrors();
87 (*m_systemName).append(s.c_str());
96 *m_bodyCode = (int) kernels[
"NaifBodyCode"];
98 m_shape = ShapeModelFactory::create(
this, lab);
109 Target::Target(
Pvl &label) {
119 QString targetName = inst[
"TargetName"][0];
122 m_shape = ShapeModelFactory::create(
this, label);
152 void Target::init() {
154 m_originalShape = NULL;
163 NaifStatus::CheckErrors();
177 if (m_radii.size() != 0) {
181 delete m_originalShape;
182 m_originalShape = NULL;
190 bool Target::isSky()
const {
201 SpiceInt Target::lookupNaifBodyCode(
Pvl &lab)
const {
204 code = lookupNaifBodyCode(*m_name);
211 code = m_spice->getInteger(
"BODY_CODE", 0);
216 && lab.
findObject(
"NaifKeywords").hasKeyword(
"BODY_CODE") ) {
217 code = int(lab.
findObject(
"NaifKeywords").findKeyword(
"BODY_CODE"));
223 "BODY_CODE not found for this Target.",
231 "Unable to look up NAIF body code for this Target.",
244 SpiceInt Target::lookupNaifBodyCode(QString name) {
246 NaifStatus::CheckErrors();
249 bodn2c_c(name.toLatin1().data(), &code, &found);
251 QString msg =
"Could not convert Target [" + name +
252 "] to NAIF body code";
253 throw IException(IException::Io, msg, _FILEINFO_);
255 NaifStatus::CheckErrors();
291 target = mapping[
"TargetName"][0];
295 if (target.isEmpty()) {
296 bool hasInstrumentGroup = cubeLab.
findObject(
"IsisCube").hasGroup(
"Instrument");
297 if (hasInstrumentGroup) {
300 target = inst[
"TargetName"][0];
307 if (target.isEmpty()) {
309 "Unable to find a TargetName keyword in the given PVL.",
316 PvlGroup radii = Target::radiiGroup(target);
338 SpiceInt bodyCode = 0;
341 bodyCode = lookupNaifBodyCode(target);
346 QString radiiKeyword =
"BODY" +
toString(
int(bodyCode)) +
"_RADII";
352 PvlContainer::Replace);
355 PvlContainer::Replace);
361 if (naifKeywords.
hasKeyword(
"BODY_FRAME_CODE")) {
364 QString radiiKeyword =
"BODY" + bodyFrame[0] +
"_RADII";
371 PvlContainer::Replace);
375 PvlContainer::Replace);
384 QString msg =
"Unable to find Equatorial and Polar radii for target [" + target +
"].";
385 throw IException(e, IException::Unknown, msg, _FILEINFO_);
405 if (target.isEmpty()) {
407 "Unable to find TargetRadii. The given TargetName is empty.",
414 if (cachedResults.contains(target)) {
415 mapping = cachedResults[target];
419 SpiceInt bodyCode = 0;
421 bodyCode = lookupNaifBodyCode(target);
424 QString msg =
"Unable to find target radii for given target ["
426 throw IException(IException::Io, msg, _FILEINFO_);
429 PvlGroup radiiGroup = Target::radiiGroup(
int(bodyCode));
431 mapping += radiiGroup.
findKeyword(
"EquatorialRadius");
433 cachedResults[target] = mapping;
454 static bool pckLoaded =
false;
456 NaifStatus::CheckErrors();
458 FileName kern(
"$base/kernels/pck/pck?????.tpc");
463 furnsh_c(kernName.toLatin1().data());
469 SpiceDouble radii[3];
470 bodvar_c(bodyCode,
"RADII", &n, radii);
473 NaifStatus::CheckErrors();
476 QString msg =
"Unable to find radii for target code [" +
toString(bodyCode)
477 +
"]. Target code was not found in furnished kernels.";
479 throw IException(e, IException::Unknown, msg, _FILEINFO_);
497 SpiceInt Target::naifBodyCode()
const {
510 SpiceInt Target::naifPlanetSystemCode()
const {
511 return *m_systemCode;
516 QString Target::name()
const {
522 QString Target::systemName()
const {
523 return *m_systemName;
532 std::vector<Distance> Target::radii()
const {
537 int Target::frameType() {
538 return spice()->bodyRotation()->getFrameType();
542 std::vector<Angle> Target::poleRaCoefs() {
543 return spice()->bodyRotation()->poleRaCoefs();
547 std::vector<Angle> Target::poleDecCoefs() {
548 return spice()->bodyRotation()->poleDecCoefs();
552 std::vector<Angle> Target::pmCoefs() {
553 return spice()->bodyRotation()->pmCoefs();
557 std::vector<double> Target::poleRaNutPrecCoefs() {
558 return spice()->bodyRotation()->poleRaNutPrecCoefs();
562 std::vector<double> Target::poleDecNutPrecCoefs() {
563 return spice()->bodyRotation()->poleDecNutPrecCoefs();
567 std::vector<double> Target::pmNutPrecCoefs() {
568 return spice()->bodyRotation()->pmNutPrecCoefs();
572 std::vector<Angle> Target::sysNutPrecConstants() {
573 return spice()->bodyRotation()->sysNutPrecConstants();
577 std::vector<Angle> Target::sysNutPrecCoefs() {
578 return spice()->bodyRotation()->sysNutPrecCoefs();
585 void Target::restoreShape() {
586 if (m_shape->name() !=
"Ellipsoid") {
591 else if (m_originalShape == NULL) {
595 m_shape = m_originalShape;
596 m_originalShape = NULL;
603 void Target::setShapeEllipsoid() {
605 m_originalShape = m_shape;
615 void Target::setRadii(std::vector<Distance> radii) {
616 if (m_radii.size() < 3) {
619 m_radii[0] = radii[0];
620 m_radii[1] = radii[1];
621 m_radii[2] = radii[2];
632 void Target::setName(QString name) {
633 if (m_name == NULL) {
634 m_name =
new QString;
647 void Target::setSpice(
Spice *spice) {