SpiceKernelMgr.hh
2.76 KB
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
/**
* SpiceKernelMgr.hh
*
* Created on: 08 jul. 2016
* Author: AKKA IS
*/
#ifndef SPICEKERNELMGR_HH_
#define SPICEKERNELMGR_HH_
#include <string>
#include "dsgpatt_Singleton.hh"
#include "SpiceKernelConfig.hh"
#include "SpiceKernelLogger.hh"
namespace AMDA {
namespace SpiceKernel {
/**
* @class SpiceKernelMgr
* @brief Singleton to manage spice kernel
* @details
*/
class SpiceKernelMgr : public ::Singleton<SpiceKernelMgr> {
public:
template<typename T>
bool transform(const char* fromFrame, const char* toFrame, bool isPosition, double time, const std::vector<T>& input, std::vector<T>& output) {
if (!SpiceKernelMgr::getInstance()->loadDataFilesForFrameName(fromFrame)) {
LOG4CXX_ERROR(gLogger, "SpiceKernelMgr::transform - Error to load data files for frame " << fromFrame);
return false;
}
if (!SpiceKernelMgr::getInstance()->loadDataFilesForFrameName(toFrame)) {
LOG4CXX_ERROR(gLogger, "SpiceKernelMgr::transform - Error to load data files for frame " << toFrame);
return false;
}
double et = timeStampToEt(time);
double rotation[3][3];
if (!getRotationMatrix(fromFrame, toFrame, et, rotation))
return false;
double translation[3] = {0,0,0};
if (!getTranslation(fromFrame, toFrame, isPosition, et, translation))
return false;
double vin[3] = {(double)input[0], (double)input[1], (double)input[2]};
double vout[3];
if (!computeTransformation(vin, translation, rotation, vout))
return false;
output.reserve(3);
output[0] = (T)vout[0];
output[1] = (T)vout[1];
output[2] = (T)vout[2];
return true;
}
double timeStampToEt(double timeStamp);
double timeStampToJulianDate(double timeStamp);
protected:
friend class ::Singleton<SpiceKernelMgr>;
SpiceKernelMgr();
virtual ~SpiceKernelMgr();
private:
void loadConfig();
int getBodyCenterFromFrameName(const char *frameName);
int getFrameIdFromFrameName(const char *frameName);
bool isDataFileLoaded(const char* filePath);
bool loadListOfDataFiles(std::list<std::string> dataFilesList);
bool loadDataFilesForFrameName(const char *frameName);
bool loadGenericDataFiles();
bool getRotationMatrix(const char* fromFrame, const char* toChar, double et, double rotate[3][3]);
bool getTranslation(const char* fromFrame, const char* toFrame, bool isPosition, double et, double translation[3]);
bool computeTransformation(double input[3], double translation[3], double rotation[3][3], double output[3]);
bool _genericDataFilesLoaded;
boost::shared_ptr<SpiceKernelConfig> _config;
std::list<std::string> _loadedDataFiles;
std::list<std::string> _DataFilesLoadedForFrameName;
std::map<std::string, int> _bodyCenterFromFrameNameMap;
std::map<std::string, int> _frameIdFromFrameNameMap;
};
} /* SpiceKernelMgr */
} /* AMDA */
#endif // SPICEKERNELMGR_HH_