-
Notifications
You must be signed in to change notification settings - Fork 169
/
IsisBundleObservation.cpp
1374 lines (1176 loc) · 51 KB
/
IsisBundleObservation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/
/* SPDX-License-Identifier: CC0-1.0 */
#include "IsisBundleObservation.h"
#include <QDebug>
#include <QString>
#include <QStringList>
#include <QVector>
#include "BundleImage.h"
#include "BundleControlPoint.h"
#include "BundleObservationSolveSettings.h"
#include "BundleTargetBody.h"
#include "Camera.h"
#include "LinearAlgebra.h"
#include "SpicePosition.h"
#include "SpiceRotation.h"
#include "CameraGroundMap.h"
using namespace std;
using namespace boost::numeric::ublas;
namespace Isis {
/**
* Constructs a IsisBundleObservation initialized to a default state.
*/
IsisBundleObservation::IsisBundleObservation() {
m_instrumentPosition = NULL;
m_instrumentRotation = NULL;
}
/**
* Constructs a IsisBundleObservation from an BundleImage, an instrument id, an observation
* number to assign to this IsisBundleObservation, and a target body.
*
* @param image QSharedPointer to the primary image in the observation
* @param observationNumber Observation number of the observation
* @param instrumentId Id of the instrument for the observation
* @param bundleTargetBody QSharedPointer to the target body of the observation
*/
IsisBundleObservation::IsisBundleObservation(BundleImageQsp image, QString observationNumber,
QString instrumentId, BundleTargetBodyQsp bundleTargetBody) :
BundleObservation(image, observationNumber, instrumentId, bundleTargetBody) {
m_bundleTargetBody = bundleTargetBody;
m_instrumentRotation = NULL;
m_instrumentPosition = NULL;
if (image) {
// set the observations spice position and rotation objects from the primary image in the
// observation (this is, by design at the moment, the first image added to the observation)
// if the image, camera, or instrument position/orientation is null, then set to null
m_instrumentPosition = (image->camera() ?
(image->camera()->instrumentPosition() ?
image->camera()->instrumentPosition() : NULL)
: NULL);
m_instrumentRotation = (image->camera() ?
(image->camera()->instrumentRotation() ?
image->camera()->instrumentRotation() : NULL)
: NULL);
}
}
/**
* Creates a copy of another IsisBundleObservation.
*
* @param src Reference to the IsisBundleObservation to copy
*/
IsisBundleObservation::IsisBundleObservation(const IsisBundleObservation &src) : BundleObservation(src) {
m_instrumentPosition = src.m_instrumentPosition;
m_instrumentRotation = src.m_instrumentRotation;
m_solveSettings = src.m_solveSettings;
m_bundleTargetBody = src.m_bundleTargetBody;
}
/**
* Destructor.
*
* Contained BundleImages will remain until all shared pointers are deleted.
*/
IsisBundleObservation::~IsisBundleObservation() {
}
/**
* Assignment operator
*
* Assigns the state of the source IsisBundleObservation to this IsisBundleObservation
*
* @param IsisBundleObservation Reference to the source IsisBundleObservation to assign from
*
* @return @b IsisBundleObservation& Reference to this IsisBundleObservation
*/
IsisBundleObservation &IsisBundleObservation::operator=(const IsisBundleObservation &src) {
if (&src != this) {
BundleObservation::operator=(src);
m_instrumentPosition = src.m_instrumentPosition;
m_instrumentRotation = src.m_instrumentRotation;
m_solveSettings = src.m_solveSettings;
m_bundleTargetBody = src.m_bundleTargetBody;
}
return *this;
}
/**
* Set solve parameters
*
* @param solveSettings The solve settings to use
*
* @return @b bool Returns true if settings were successfully set
*/
bool IsisBundleObservation::setSolveSettings(BundleObservationSolveSettings solveSettings) {
m_solveSettings = BundleObservationSolveSettingsQsp(
new BundleObservationSolveSettings(solveSettings));
// initialize solution parameters for this observation
int nCameraAngleCoefficients = m_solveSettings->numberCameraAngleCoefficientsSolved();
int nCameraPositionCoefficients = m_solveSettings->numberCameraPositionCoefficientsSolved();
int nParameters = 3*nCameraPositionCoefficients + 2*nCameraAngleCoefficients;
if (nCameraAngleCoefficients >= 1 && m_solveSettings->solveTwist()) {
nParameters += nCameraAngleCoefficients;
}
// size vectors and set to zero
m_weights.resize(nParameters);
m_weights.clear();
m_corrections.resize(nParameters);
m_corrections.clear();
m_adjustedSigmas.resize(nParameters);
m_adjustedSigmas.clear();
m_aprioriSigmas.resize(nParameters);
for ( int i = 0; i < nParameters; i++) {
m_aprioriSigmas[i] = Isis::Null;
}
if (!initParameterWeights()) {
return false;
}
return true;
}
/**
* Accesses the instrument's spice rotation
*
* @return @b SpiceRotation* Returns the SpiceRotation for this observation
*/
SpiceRotation *IsisBundleObservation::spiceRotation() {
return m_instrumentRotation;
}
/**
* Accesses the instrument's spice position
*
* @return @b SpicePosition* Returns the SpicePosition for this observation
*/
SpicePosition *IsisBundleObservation::spicePosition() {
return m_instrumentPosition;
}
/**
* Accesses the solve settings
*
* @return @b const IsisBundleObservationSolveSettingsQsp Returns a pointer to the solve
* settings for this IsisBundleObservation
*/
const BundleObservationSolveSettingsQsp IsisBundleObservation::solveSettings() {
return m_solveSettings;
}
/**
* Initializes the exterior orientation
*
* @return @b bool Returns true upon successful intialization
*/
bool IsisBundleObservation::initializeExteriorOrientation() {
if (m_solveSettings->instrumentPositionSolveOption() !=
BundleObservationSolveSettings::NoPositionFactors) {
double positionBaseTime = 0.0;
double positiontimeScale = 0.0;
std::vector<double> posPoly1, posPoly2, posPoly3;
for (int i = 0; i < size(); i++) {
BundleImageQsp image = at(i);
SpicePosition *spicePosition = image->camera()->instrumentPosition();
// If this image isn't the first, copy the position from the first
if (i > 0) {
spicePosition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());
spicePosition->SetOverrideBaseTime(positionBaseTime, positiontimeScale);
spicePosition->SetPolynomial(posPoly1, posPoly2, posPoly3,
m_solveSettings->positionInterpolationType());
}
// Otherwise we need to fit the initial position
else {
// first, set the degree of the spk polynomial to be fit for a priori values
spicePosition->SetPolynomialDegree(m_solveSettings->spkDegree());
// now, set what kind of interpolation to use (polynomial function or
// polynomial function over hermite spline)
spicePosition->SetPolynomial(m_solveSettings->positionInterpolationType());
// finally, set the degree of the position polynomial actually used in the bundle adjustment
spicePosition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());
if (m_instrumentPosition) {
positionBaseTime = m_instrumentPosition->GetBaseTime();
positiontimeScale = m_instrumentPosition->GetTimeScale();
m_instrumentPosition->GetPolynomial(posPoly1, posPoly2, posPoly3);
}
}
}
}
if (m_solveSettings->instrumentPointingSolveOption() !=
BundleObservationSolveSettings::NoPointingFactors) {
double rotationBaseTime = 0.0;
double rotationtimeScale = 0.0;
std::vector<double> anglePoly1, anglePoly2, anglePoly3;
for (int i = 0; i < size(); i++) {
BundleImageQsp image = at(i);
SpiceRotation *spicerotation = image->camera()->instrumentRotation();
// If this image isn't the first, copy the pointing from the first
if (i > 0) {
spicerotation->SetPolynomialDegree(m_solveSettings->ckSolveDegree());
spicerotation->SetOverrideBaseTime(rotationBaseTime, rotationtimeScale);
spicerotation->SetPolynomial(anglePoly1, anglePoly2, anglePoly3,
m_solveSettings->pointingInterpolationType());
}
// Otherwise we need to fit the initial pointing
else {
// first, set the degree of the polynomial to be fit for a priori values
spicerotation->SetPolynomialDegree(m_solveSettings->ckDegree());
// now, set what kind of interpolation to use (polynomial function or
// polynomial function over a pointing cache)
spicerotation->SetPolynomial(m_solveSettings->pointingInterpolationType());
// finally, set the degree of the pointing polynomial actually used in the bundle adjustment
spicerotation->SetPolynomialDegree(m_solveSettings->ckSolveDegree());
rotationBaseTime = spicerotation->GetBaseTime();
rotationtimeScale = spicerotation->GetTimeScale();
spicerotation->GetPolynomial(anglePoly1, anglePoly2, anglePoly3);
}
}
}
return true;
}
/**
* Intializes the body rotation
*/
void IsisBundleObservation::initializeBodyRotation() {
std::vector<Angle> raCoefs = m_bundleTargetBody->poleRaCoefs();
std::vector<Angle> decCoefs = m_bundleTargetBody->poleDecCoefs();
std::vector<Angle> pmCoefs = m_bundleTargetBody->pmCoefs();
for (int i = 0; i < size(); i++) {
BundleImageQsp image = at(i);
image->camera()->bodyRotation()->setPckPolynomial(raCoefs, decCoefs, pmCoefs);
}
}
/**
* Updates the body rotation
*/
void IsisBundleObservation::updateBodyRotation() {
std::vector<Angle> raCoefs = m_bundleTargetBody->poleRaCoefs();
std::vector<Angle> decCoefs = m_bundleTargetBody->poleDecCoefs();
std::vector<Angle> pmCoefs = m_bundleTargetBody->pmCoefs();
for (int i = 0; i < size(); i++) {
BundleImageQsp image = at(i);
image->camera()->bodyRotation()->setPckPolynomial(raCoefs, decCoefs, pmCoefs);
}
}
/**
* Initializes the paramater weights for solving
*
* @return @b bool Returns true upon successful intialization
*/
bool IsisBundleObservation::initParameterWeights() {
// weights for
double posWeight = 0.0; // position
double velWeight = 0.0; // velocity
double accWeight = 0.0; // acceleration
double angWeight = 0.0; // angles
double angVelWeight = 0.0; // angular velocity
double angAccWeight = 0.0; // angular acceleration
QList<double> aprioriPointingSigmas = m_solveSettings->aprioriPointingSigmas();
QList<double> aprioriPositionSigmas = m_solveSettings->aprioriPositionSigmas();
int nCamPosCoeffsSolved = 3 *m_solveSettings->numberCameraPositionCoefficientsSolved();
int nCamAngleCoeffsSolved;
if (m_solveSettings->solveTwist()) {
nCamAngleCoeffsSolved = 3 *m_solveSettings->numberCameraAngleCoefficientsSolved();
}
else {
nCamAngleCoeffsSolved = 2 *m_solveSettings->numberCameraAngleCoefficientsSolved();
}
if (aprioriPositionSigmas.size() >= 1 && aprioriPositionSigmas.at(0) > 0.0) {
posWeight = aprioriPositionSigmas.at(0);
posWeight = 1.0 / (posWeight *posWeight * 1.0e-6);
}
if (aprioriPositionSigmas.size() >= 2 && aprioriPositionSigmas.at(1) > 0.0) {
velWeight = aprioriPositionSigmas.at(1);
velWeight = 1.0 / (velWeight *velWeight * 1.0e-6);
}
if (aprioriPositionSigmas.size() >= 3 && aprioriPositionSigmas.at(2) > 0.0) {
accWeight = aprioriPositionSigmas.at(2);
accWeight = 1.0 / (accWeight *accWeight * 1.0e-6);
}
if (aprioriPointingSigmas.size() >= 1 && aprioriPointingSigmas.at(0) > 0.0) {
angWeight = aprioriPointingSigmas.at(0);
angWeight = 1.0 / (angWeight *angWeight * DEG2RAD * DEG2RAD);
}
if (aprioriPointingSigmas.size() >= 2 && aprioriPointingSigmas.at(1) > 0.0) {
angVelWeight = aprioriPointingSigmas.at(1);
angVelWeight = 1.0 / (angVelWeight * angVelWeight * DEG2RAD * DEG2RAD);
}
if (aprioriPointingSigmas.size() >= 3 && aprioriPointingSigmas.at(2) > 0.0) {
angAccWeight = aprioriPointingSigmas.at(2);
angAccWeight = 1.0 / (angAccWeight * angAccWeight * DEG2RAD * DEG2RAD);
}
int nSpkTerms = m_solveSettings->spkSolveDegree()+1;
nSpkTerms = m_solveSettings->numberCameraPositionCoefficientsSolved();
for ( int i = 0; i < nCamPosCoeffsSolved; i++) {
if (i % nSpkTerms == 0) {
m_aprioriSigmas[i] = aprioriPositionSigmas.at(0);
m_weights[i] = posWeight;
}
if (i % nSpkTerms == 1) {
m_aprioriSigmas[i] = aprioriPositionSigmas.at(1);
m_weights[i] = velWeight;
}
if (i % nSpkTerms == 2) {
m_aprioriSigmas[i] = aprioriPositionSigmas.at(2);
m_weights[i] = accWeight;
}
}
int nCkTerms = m_solveSettings->ckSolveDegree()+1;
nCkTerms = m_solveSettings->numberCameraAngleCoefficientsSolved();
for ( int i = 0; i < nCamAngleCoeffsSolved; i++) {
if (i % nCkTerms == 0) {
m_aprioriSigmas[nCamPosCoeffsSolved + i] = aprioriPointingSigmas.at(0);
m_weights[nCamPosCoeffsSolved + i] = angWeight;
}
if (i % nCkTerms == 1) {
m_aprioriSigmas[nCamPosCoeffsSolved + i] = aprioriPointingSigmas.at(1);
m_weights[nCamPosCoeffsSolved + i] = angVelWeight;
}
if (i % nCkTerms == 2) {
m_aprioriSigmas[nCamPosCoeffsSolved + i] = aprioriPointingSigmas.at(2);
m_weights[nCamPosCoeffsSolved + i] = angAccWeight;
}
}
return true;
}
/**
* Applies the parameter corrections
*
* @param corrections Vector of corrections to apply
*
* @throws IException::Unknown "Instrument position is NULL, but position solve option is
* [not NoPositionFactors]"
* @throws IException::Unknown "Instrument position is NULL, but pointing solve option is
* [not NoPointingFactors]"
* @throws IException::Unknown "Unable to apply parameter corrections to IsisBundleObservation."
*
* @return @b bool Returns true upon successful application of corrections
*/
bool IsisBundleObservation::applyParameterCorrections(LinearAlgebra::Vector corrections) {
int index = 0;
try {
int nCameraAngleCoefficients = m_solveSettings->numberCameraAngleCoefficientsSolved();
int nCameraPositionCoefficients = m_solveSettings->numberCameraPositionCoefficientsSolved();
BundleObservationSolveSettings::InstrumentPositionSolveOption positionOption
= m_solveSettings->instrumentPositionSolveOption();
if (positionOption != BundleObservationSolveSettings::NoPositionFactors) {
if (!m_instrumentPosition) {
QString msg = "Instrument position is NULL, but position solve option is ";
msg.append(BundleObservationSolveSettings::instrumentPositionSolveOptionToString(
positionOption));
throw IException(IException::Unknown, msg, _FILEINFO_);
}
std::vector<double> coefX(nCameraPositionCoefficients);
std::vector<double> coefY(nCameraPositionCoefficients);
std::vector<double> coefZ(nCameraPositionCoefficients);
m_instrumentPosition->GetPolynomial(coefX, coefY, coefZ);
// update X coordinate coefficient(s) and sum parameter correction
for (int i = 0; i < nCameraPositionCoefficients; i++) {
coefX[i] += corrections(index);
index++;
}
// update Y coordinate coefficient(s) and sum parameter correction
for (int i = 0; i < nCameraPositionCoefficients; i++) {
coefY[i] += corrections(index);
index++;
}
// update Z coordinate coefficient(s) and sum parameter correction
for (int i = 0; i < nCameraPositionCoefficients; i++) {
coefZ[i] += corrections(index);
index++;
}
// apply updates to all images in observation
for (int i = 0; i < size(); i++) {
BundleImageQsp image = at(i);
SpicePosition *spiceposition = image->camera()->instrumentPosition();
spiceposition->SetPolynomial(coefX, coefY, coefZ,
m_solveSettings->positionInterpolationType());
}
}
BundleObservationSolveSettings::InstrumentPointingSolveOption pointingOption
= m_solveSettings->instrumentPointingSolveOption();
if (pointingOption != BundleObservationSolveSettings::NoPointingFactors) {
if (!m_instrumentRotation) {
QString msg = "Instrument rotation is NULL, but pointing solve option is ";
msg.append(BundleObservationSolveSettings::instrumentPointingSolveOptionToString(
pointingOption));
throw IException(IException::Unknown, msg, _FILEINFO_);
}
std::vector<double> coefRA(nCameraPositionCoefficients);
std::vector<double> coefDEC(nCameraPositionCoefficients);
std::vector<double> coefTWI(nCameraPositionCoefficients);
m_instrumentRotation->GetPolynomial(coefRA, coefDEC, coefTWI);
// update RA coefficient(s)
for (int i = 0; i < nCameraAngleCoefficients; i++) {
coefRA[i] += corrections(index);
index++;
}
// update DEC coefficient(s)
for (int i = 0; i < nCameraAngleCoefficients; i++) {
coefDEC[i] += corrections(index);
index++;
}
if (m_solveSettings->solveTwist()) {
// update TWIST coefficient(s)
for (int i = 0; i < nCameraAngleCoefficients; i++) {
coefTWI[i] += corrections(index);
index++;
}
}
// apply updates to all images in observation
for (int i = 0; i < size(); i++) {
BundleImageQsp image = at(i);
SpiceRotation *spiceRotation = image->camera()->instrumentRotation();
spiceRotation->SetPolynomial(coefRA, coefDEC, coefTWI,
m_solveSettings->pointingInterpolationType());
}
}
// update corrections
m_corrections += corrections;
}
catch (IException &e) {
QString msg = "Unable to apply parameter corrections to IsisBundleObservation.";
throw IException(e, IException::Unknown, msg, _FILEINFO_);
}
return true;
}
/**
* Returns the number of position parameters there are
*
* @return @b int Returns the number of position parameters
*/
int IsisBundleObservation::numberPositionParameters() {
return 3.0 * m_solveSettings->numberCameraPositionCoefficientsSolved();
}
/**
* Returns the number of pointing parameters being solved for
*
* @return @b int Returns the number of pointing parameters
*/
int IsisBundleObservation::numberPointingParameters() {
int angleCoefficients = m_solveSettings->numberCameraAngleCoefficientsSolved();
if (m_solveSettings->solveTwist()) {
return 3.0 * angleCoefficients;
}
return 2.0 * angleCoefficients;
}
/**
* Returns the number of total parameters there are for solving
*
* The total number of parameters is equal to the number of position parameters and number of
* pointing parameters
*
* @return @b int Returns the number of parameters there are
*/
int IsisBundleObservation::numberParameters() {
return numberPositionParameters() + numberPointingParameters();
}
/**
* Returns the list of observation parameter names.
*
* This will always return at least one set of positions and pointings
* because we always output at least the center values even when not solving
* for them.
*
* @return @b QStringList List of observation parameter names
*/
QStringList IsisBundleObservation::parameterList() {
QStringList paramList;
// We still want to output the center postion even if not solving for it
// so always do at least 1
int numberCamPosCoefSolved = std::max(
solveSettings()->numberCameraPositionCoefficientsSolved(),
1);
for (int i = 0; i < numberCamPosCoefSolved; i++) {
if (numberCamPosCoefSolved == 1) {
paramList.push_back("X");
}
else {
QString str = "X(t" + toString(i) + ")";
paramList.push_back(str);
}
}
for (int i = 0; i < numberCamPosCoefSolved; i++) {
if (numberCamPosCoefSolved == 1) {
paramList.push_back("Y");
}
else {
QString str = "Y(t" + toString(i) + ")";
paramList.push_back(str);
}
}
for (int i = 0; i < numberCamPosCoefSolved; i++) {
if (numberCamPosCoefSolved == 1) {
paramList.push_back("Z");
}
else {
QString str = "Z(t" + toString(i) + ")";
paramList.push_back(str);
}
}
// We still want to output the center pointing even if not solving for it
// so always do at least 1
int numberCamAngleCoefSolved = std::max(
solveSettings()->numberCameraAngleCoefficientsSolved(),
1);
for (int i = 0; i < numberCamAngleCoefSolved; i++) {
if (numberCamAngleCoefSolved == 1) {
paramList.push_back("RA");
}
else {
QString str = "RA(t" + toString(i) + ")";
paramList.push_back(str);
}
}
for (int i = 0; i < numberCamAngleCoefSolved; i++) {
if (numberCamAngleCoefSolved == 1) {
paramList.push_back("DEC");
}
else {
QString str = "DEC(t" + toString(i) + ")";
paramList.push_back(str);
}
}
for (int i = 0; i < numberCamAngleCoefSolved; i++) {
if (numberCamAngleCoefSolved == 1) {
paramList.push_back("TWIST");
}
else {
QString str = "TWIST(t" + toString(i) + ")";
paramList.push_back(str);
}
}
return paramList;
}
/**
* @brief Fetches data for the log file output methods.
*
* @param finalParameterValues Reference to QVector<double> of calculated
* position and pointing
* @param nPositionCoefficients Reference to int of the number of position coefficients
* @param nPointingCoefficients Reference to int of the number of pointing coefficients
* @param useDefaultPosition Reference to boolean of whether to use default position
* @param useDefaultPointing Reference to boolean of whether to use default pointing
* @param useDefaultTwist Reference to bollean of whether to use defualt twist
*/
void IsisBundleObservation::bundleOutputFetchData(QVector<double> &finalParameterValues,
int &nPositionCoefficients, int &nPointingCoefficients,
bool &useDefaultPosition,
bool &useDefaultPointing, bool &useDefaultTwist) {
std::vector<double> coefX,coefY,coefZ,coefRA,coefDEC,coefTWI;
nPositionCoefficients = m_solveSettings->numberCameraPositionCoefficientsSolved();
nPointingCoefficients = m_solveSettings->numberCameraAngleCoefficientsSolved();
// Indicate if we need to obtain default position or pointing values
useDefaultPosition = false;
useDefaultPointing = false;
// Indicate if we need to use default values when not solving twist
useDefaultTwist = !(m_solveSettings->solveTwist());
// If we aren't solving for position, set the number of coefficients to 1 so we
// can output the instrumentPosition's center coordinate values for X, Y, and Z
if (nPositionCoefficients == 0) {
nPositionCoefficients = 1;
useDefaultPosition = true;
}
// If we arent' solving for pointing, set the number of coefficients to 1 so we
// can output the instrumentPointing's center angles for RA, DEC, and TWI
if (nPointingCoefficients == 0) {
nPointingCoefficients = 1;
useDefaultPointing = true;
}
coefX.resize(nPositionCoefficients);
coefY.resize(nPositionCoefficients);
coefZ.resize(nPositionCoefficients);
coefRA.resize(nPointingCoefficients);
coefDEC.resize(nPointingCoefficients);
coefTWI.resize(nPointingCoefficients);
if (m_instrumentPosition) {
if (!useDefaultPosition) {
m_instrumentPosition->GetPolynomial(coefX,coefY,coefZ);
}
// Use the position's center coordinate if not solving for spacecraft position
else {
const std::vector<double> centerCoord = m_instrumentPosition->GetCenterCoordinate();
coefX[0] = centerCoord[0];
coefY[0] = centerCoord[1];
coefZ[0] = centerCoord[2];
}
}
if (m_instrumentRotation) {
if (!useDefaultPointing) {
m_instrumentRotation->GetPolynomial(coefRA,coefDEC,coefTWI);
}
// Use the pointing's center angles if not solving for pointing (rotation)
else {
const std::vector<double> centerAngles = m_instrumentRotation->GetCenterAngles();
coefRA[0] = centerAngles[0];
coefDEC[0] = centerAngles[1];
coefTWI[0] = centerAngles[2];
}
}
// Combine all vectors into one
if (nPositionCoefficients > 0) {
for (int i=0; i < nPositionCoefficients; i++) {
finalParameterValues.append(coefX[i]);
}
for (int i=0; i < nPositionCoefficients; i++) {
finalParameterValues.append(coefY[i]);
}
for (int i=0; i < nPositionCoefficients; i++) {
finalParameterValues.append(coefZ[i]);
}
}
if (nPointingCoefficients > 0) {
for (int i=0; i < nPointingCoefficients; i++) {
finalParameterValues.append(coefRA[i]);
}
for (int i=0; i < nPointingCoefficients; i++) {
finalParameterValues.append(coefDEC[i]);
}
for (int i=0; i < nPointingCoefficients; i++) {
finalParameterValues.append(coefTWI[i]);
}
}
}
/**
* @brief Takes in an open std::ofstream and writes out information which goes into the
* bundleout.txt file.
*
* @param fpOut The open std::ofstream object which is passed in from
* BundleSolutionInfo::outputText()
* @param errorPropagation Boolean indicating whether or not to attach more information
* (corrections, sigmas, adjusted sigmas...) to the output.
*/
void IsisBundleObservation::bundleOutputString(std::ostream &fpOut, bool errorPropagation) {
char buf[4096];
QVector<double> finalParameterValues;
int nPositionCoefficients, nPointingCoefficients;
bool useDefaultPosition, useDefaultPointing,useDefaultTwist;
bundleOutputFetchData(finalParameterValues,
nPositionCoefficients,nPointingCoefficients,
useDefaultPosition,useDefaultPointing,useDefaultTwist);
int nPositionParameters = 3 * nPositionCoefficients;
int nPointingParameters = 3 * nPointingCoefficients;
int nParameters = nPositionParameters + nPointingParameters;
// for convenience, create vectors of parameters names and values in the correct sequence
QStringList parameterNamesListX,parameterNamesListY,parameterNamesListZ,
parameterNamesListRA,parameterNamesListDEC,parameterNamesListTWI,
parameterNamesList;
QStringList correctionUnitListX,correctionUnitListY,correctionUnitListZ,
correctionUnitListRA,correctionUnitListDEC,correctionUnitListTWI,
correctionUnitList;
QString str("%1(%2) ");
QString str2("%1(%2) ");
QString strN("%1(%2)");
if (nPositionCoefficients > 0) {
for (int j = 0; j < nPositionCoefficients;j++) {
if (j == 0) {
parameterNamesListX.append(str.arg(" X ").arg("km"));
parameterNamesListY.append(str.arg(" Y ").arg("km"));
parameterNamesListZ.append(str.arg(" Z ").arg("km"));
correctionUnitListX.append("m");
correctionUnitListY.append("m");
correctionUnitListZ.append("m");
} //end inner-if
else if (j==1) {
parameterNamesListX.append( str2.arg(" ").arg("km/s") );
parameterNamesListY.append( str2.arg(" ").arg("km/s") );
parameterNamesListZ.append( str2.arg(" ").arg("km/s") );
correctionUnitListX.append("m/s");
correctionUnitListY.append("m/s");
correctionUnitListZ.append("m/s");
}
else {
QString str("%1(%2)");
parameterNamesListX.append(strN.arg(" ").arg("km/s^"+toString(j) ) );
parameterNamesListY.append(strN.arg(" ").arg("km/s^"+toString(j) ) );
parameterNamesListZ.append(strN.arg(" ").arg("km/s^"+toString(j) ) );
correctionUnitListX.append("m/s^"+toString(j));
correctionUnitListY.append("m/s^"+toString(j));
correctionUnitListZ.append("m/s^"+toString(j));
}
}//end for
}//end outer-if
if (nPointingCoefficients > 0) {
for (int j = 0; j < nPointingCoefficients;j++) {
if (j == 0) {
parameterNamesListRA.append(str.arg(" RA ").arg("dd"));
parameterNamesListDEC.append(str.arg("DEC ").arg("dd"));
parameterNamesListTWI.append(str.arg("TWI ").arg("dd"));
correctionUnitListRA.append("dd");
correctionUnitListDEC.append("dd");
correctionUnitListTWI.append("dd");
} //end inner-if
else if (j==1) {
parameterNamesListRA.append( str2.arg(" ").arg("dd/s") );
parameterNamesListDEC.append( str2.arg(" ").arg("dd/s") );
parameterNamesListTWI.append( str2.arg(" ").arg("dd/s") );
correctionUnitListRA.append("dd/s");
correctionUnitListDEC.append("dd/s");
correctionUnitListTWI.append("dd/s");
}
else {
parameterNamesListRA.append(strN.arg(" ").arg("dd/s^"+toString(j) ) );
parameterNamesListDEC.append(strN.arg(" ").arg("dd/s^"+toString(j) ) );
parameterNamesListTWI.append(strN.arg(" ").arg("dd/s^"+toString(j) ) );
correctionUnitListRA.append("dd/s^"+toString(j));
correctionUnitListDEC.append("dd/s^"+toString(j));
correctionUnitListTWI.append("dd/s^"+toString(j));
}
}//end for
}// end outer-if
//Put all of the parameter names together into one QStringList
parameterNamesList.append(parameterNamesListX);
parameterNamesList.append(parameterNamesListY);
parameterNamesList.append(parameterNamesListZ);
parameterNamesList.append(parameterNamesListRA);
parameterNamesList.append(parameterNamesListDEC);
parameterNamesList.append(parameterNamesListTWI);
//Put all of the correction unit names together into one QStringList
correctionUnitList.append(correctionUnitListX);
correctionUnitList.append(correctionUnitListY);
correctionUnitList.append(correctionUnitListZ);
correctionUnitList.append(correctionUnitListDEC);
correctionUnitList.append(correctionUnitListRA);
correctionUnitList.append(correctionUnitListTWI);
// Set up default values when we are using default position
QString sigma = "N/A";
QString adjustedSigma = "N/A";
double correction = 0.0;
// position parameters
for (int i = 0; i < nPositionParameters; i++) {
// If not using the default position, we can correctly access sigmas and corrections
// members
if (!useDefaultPosition) {
correction = m_corrections(i);
adjustedSigma = QString::number(m_adjustedSigmas[i], 'f', 8);
sigma = ( IsSpecial(m_aprioriSigmas[i]) ? "FREE" : toString(m_aprioriSigmas[i], 8) );
}
snprintf(buf, sizeof(buf),"%s", parameterNamesList.at(i).toStdString().c_str() );
fpOut << buf;
snprintf(buf, sizeof(buf),"%18.8lf ", finalParameterValues[i] - correction);
fpOut << buf;
snprintf(buf, sizeof(buf),"%20.8lf ", correction);
fpOut << buf;
snprintf(buf, sizeof(buf),"%23.8lf ", finalParameterValues[i]);
fpOut << buf;
snprintf(buf, sizeof(buf)," ");
fpOut << buf;
snprintf(buf, sizeof(buf),"%6s", sigma.toStdString().c_str());
fpOut << buf;
snprintf(buf, sizeof(buf)," ");
fpOut << buf;
if (errorPropagation) {
snprintf(buf, sizeof(buf),"%s", adjustedSigma.toStdString().c_str());
}
else {
snprintf(buf, sizeof(buf),"%s", "N/A");
}
fpOut << buf;
snprintf(buf, sizeof(buf)," ");
fpOut << buf;
snprintf(buf, sizeof(buf),"%s\n", correctionUnitList.at(i).toStdString().c_str() );
fpOut << buf;
}
// We need to use an offset of -3 (1 coef; X,Y,Z) if we used the default center coordinate
// (i.e. we did not solve for position), as m_corrections and m_*sigmas are populated
// according to which parameters are solved
int offset = 0;
if (useDefaultPosition) {
offset = 3;
}
// pointing parameters
for (int i = nPositionParameters; i < nParameters; i++) {
if (!useDefaultPointing) {
// If solving camera and not solving for twist, provide default values for twist to
// prevent bad indexing into m_corrections and m_*sigmas
// TWIST is last parameter, which corresponds to nParameters - nPointingCoefficients
if ( (i >= nParameters - nPointingCoefficients) && useDefaultTwist) {
correction = 0.0;
adjustedSigma = "N/A";
sigma = "N/A";
}
else {
correction = m_corrections(i - offset);
adjustedSigma = QString::number(m_adjustedSigmas(i-offset) * RAD2DEG, 'f', 8);
sigma = ( IsSpecial(m_aprioriSigmas[i - offset]) ? "FREE" :
toString(m_aprioriSigmas[i-offset], 8) );
}
}
// We are using default pointing, so provide default correction and sigma values to output
else {
correction = 0.0;
adjustedSigma = "N/A";
sigma = "N/A";
}
snprintf(buf, sizeof(buf),"%s",parameterNamesList.at(i).toStdString().c_str() );
fpOut << buf;
snprintf(buf, sizeof(buf),"%18.8lf ",(finalParameterValues[i]*RAD2DEG - correction*RAD2DEG));
fpOut << buf;
snprintf(buf, sizeof(buf),"%20.8lf ",(correction*RAD2DEG));
fpOut << buf;
snprintf(buf, sizeof(buf),"%23.8lf ",(finalParameterValues[i]*RAD2DEG));
fpOut << buf;
snprintf(buf, sizeof(buf)," ");
fpOut << buf;
snprintf(buf, sizeof(buf),"%6s",sigma.toStdString().c_str());
fpOut << buf;
snprintf(buf, sizeof(buf)," ");
fpOut << buf;
if (errorPropagation) {
snprintf(buf, sizeof(buf),"%s",adjustedSigma.toStdString().c_str());
}
else {
snprintf(buf, sizeof(buf),"%s","N/A");
}
fpOut<<buf;
snprintf(buf, sizeof(buf)," ");
fpOut<<buf;
snprintf(buf, sizeof(buf),"%s\n",correctionUnitList.at(i).toStdString().c_str() );
fpOut<<buf;
}
}
/**
* @brief Creates and returns a formatted QString representing the bundle coefficients and
* parameters in csv format.
*
* @param errorPropagation Boolean indicating whether or not to attach more information
* (corrections, sigmas, adjusted sigmas...) to the output QString
*
* @return @b QString Returns a formatted QString representing the IsisBundleObservation in
* csv format
*/
QString IsisBundleObservation::bundleOutputCSV(bool errorPropagation) {
QVector<double> finalParameterValues;
int nPositionCoefficients, nPointingCoefficients;
bool useDefaultPosition, useDefaultPointing,useDefaultTwist;
bundleOutputFetchData(finalParameterValues,
nPositionCoefficients,nPointingCoefficients,
useDefaultPosition,useDefaultPointing,useDefaultTwist);
int nPositionParameters = 3 * nPositionCoefficients;
int nPointingParameters = 3 * nPointingCoefficients;
int nParameters = nPositionParameters + nPointingParameters;
QString finalqStr = "";
// Set up default values when we are using default position
QString sigma = "N/A";
QString adjustedSigma = "N/A";
double correction = 0.0;
// Position parameters
for (int i = 0; i < nPositionParameters; i++) {
if (!useDefaultPosition) {
correction = m_corrections(i);
adjustedSigma = QString::number(m_adjustedSigmas[i], 'f', 8);
sigma = ( IsSpecial(m_aprioriSigmas[i]) ? "FREE" : toString(m_aprioriSigmas[i], 8) );
}
// Provide default values for position if not solving position
else {
correction = 0.0;
adjustedSigma = "N/A";
sigma = "N/A";
}
finalqStr += toString(finalParameterValues[i] - correction) + ",";