check if correct positioning data is already loaded

This commit is contained in:
Agnes Heppich
2018-11-21 16:41:33 -05:00
parent be71ed7707
commit e4a6e7c459
7 changed files with 51 additions and 21 deletions

View File

@@ -124,19 +124,25 @@ namespace openspace {
return true;
}
/*Get the day, must have format YYYY-DDDT*/
/*Get one day, must have format YYYY-DDDT*/
std::string DataFileHelper::getDayFromFileName(std::string filename) {
// number of characters in filename (excluding '.json')
constexpr const int FilenameSize = 9;
return DataFileHelper::getFileNameTime(filename, FilenameSize);
}
/*get a vector of all filenames, must have format YYY-DDDT*/
std::vector<double> DataFileHelper::getDaysFromFileNames(std::vector<std::string> _dataFiles) {
// number of characters in filename (excluding '.json')
constexpr const int FilenameSize = 9;
return DataFileHelper::extractTriggerTimesFromFileNames(_dataFiles, FilenameSize);
}
/*Get the hour, must have format YYYY-DDDTHH*/
/*Get one hour, must have format YYYY-DDDTHH*/
std::string DataFileHelper::getHourFromFileName(std::string filename) {
// number of characters in filename (excluding '.json')
constexpr const int FilenameSize = 11;
return DataFileHelper::getFileNameTime(filename, FilenameSize);
}
/*Get a vector of all hour, must have format YYYY-DDDTHH*/
std::vector<double> DataFileHelper::getHoursFromFileNames(std::vector<std::string> _dataFiles) {
// number of characters in filename (excluding '.json')
constexpr const int FilenameSize = 11;

View File

@@ -21,8 +21,8 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_DSN___JSONHELPER___H__
#define __OPENSPACE_MODULE_DSN___JSONHELPER___H__
#ifndef __OPENSPACE_MODULE_DSN___DATAFILEHELPER___H__
#define __OPENSPACE_MODULE_DSN___DATAFILEHELPER___H__
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
@@ -38,6 +38,7 @@ namespace openspace {
/* Extracts all the mandatory information we need from our asset files */
static bool checkFileNames(const char* identifier, std::unique_ptr<ghoul::Dictionary> &dictionary, std::vector<std::string> &dataFiles);
static std::string getDayFromFileName(std::string filename);
static std::string getHourFromFileName(std::string filename);
static std::vector<double> getDaysFromFileNames(std::vector<std::string> _dataFiles);
static std::vector<double> getHoursFromFileNames(std::vector<std::string> _dataFiles);
/* Extracts the timestamp from the filename */

View File

@@ -30,6 +30,7 @@ namespace openspace {
double RadecManager::_ra;
double RadecManager::_dec;
double RadecManager::_range;
double RadecManager::_checkFileTime;
bool RadecManager::extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr<ghoul::Dictionary> &dictionary){
bool dataFilesSuccess = DataFileHelper::checkFileNames(identifier, dictionary, RadecManager::_dataFiles);
@@ -38,22 +39,28 @@ namespace openspace {
}
glm::vec3 RadecManager::GetPosForTime(double time) {
std::vector<double> timeDoubles = DataFileHelper::getHoursFromFileNames(_dataFiles);
std::vector<double> timeDoubles = DataFileHelper::getHoursFromFileNames(_dataFiles); //save as member
int idx = RenderableSignals::findFileIndexForCurrentTime(time, timeDoubles);
if (radecParser(idx)) {
return glm::vec3(_ra,_dec,_range);
}
return glm::vec3(-1,-1,-1);
}
//If the current hour in open space found in filesystem, parse the data and return the ra dec values from that file.
if (radecParser(idx)) {
return glm::vec3(_ra,_dec,_range);
}
return glm::vec3(-1,-1,-1);
}
bool RadecManager::radecParser(int index) {
std::string filename;
if (index == -1 || index > _dataFiles.size())
return false;
filename = _dataFiles[index];
std::string startTimeString = DataFileHelper::getHourFromFileName(filename);
const double triggerTime = Time::convertTime(startTimeString);
_checkFileTime = triggerTime;
std::ifstream ifs(filename);
nlohmann::json j = nlohmann::json::parse(ifs);
_ra = j["RADn"].get<double>();

View File

@@ -38,7 +38,9 @@ namespace openspace {
static double _ra;
static double _dec;
static double _range;
/*Used to check if the loaded file is still relevant or if we should look for another one. */
static double _checkFileTime;
/* A vector with all our datafile paths*/
static std::vector<std::string> _dataFiles;
/* Extracts all the mandatory information we need from our asset file */

View File

@@ -35,6 +35,7 @@ namespace {
} // namespace
namespace openspace {
glm::vec3 RadecTranslation:: _pos;
constexpr const char* _loggerCat = "RadecTranslation";
@@ -111,7 +112,7 @@ glm::dvec3 RadecTranslation::convertRaDecRangeToCartesian(double ra, double dec,
glm::dvec3 RadecTranslation::transformCartesianCoordinates(glm::vec3 pos) const {
glm::vec3 cartesianPos = convertRaDecRangeToCartesian(pos.x, pos.y, pos.z);
glm::dvec3 cartesianPos = convertRaDecRangeToCartesian(pos.x, pos.y, pos.z);
glm::dvec3 earthPos = global::renderEngine.scene()->sceneGraphNode("Earth")->worldPosition();
glm::dmat4 translationMatrixEarth = glm::translate( glm::dmat4(1.0), glm::dvec3(earthPos) );
@@ -124,9 +125,20 @@ glm::dvec3 RadecTranslation::transformCartesianCoordinates(glm::vec3 pos) const
}
glm::dvec3 RadecTranslation::position(const UpdateData& data) const{
glm::vec3 pos = RadecManager::GetPosForTime(data.time.j2000Seconds());
glm::dvec3 _position = transformCartesianCoordinates(pos);
return _position;
double endTime = 3600;
const bool isTimeInFileInterval = (data.time.j2000Seconds() >= RadecManager::_checkFileTime) &&
(data.time.j2000Seconds() < RadecManager::_checkFileTime + endTime); //if true -> time is within file interval
if (!isTimeInFileInterval) {
// The time in open space is is not in the file interval, we need to update the positions
glm::vec3 pos = RadecManager::GetPosForTime(data.time.j2000Seconds());
_pos = transformCartesianCoordinates(pos);
LDEBUG(fmt::format("Openspace time is NOT in interval, update coordinates. FileTime {}; OpenSpaceTime {}; FileEndTime{}",
std::to_string(RadecManager::_checkFileTime), std::to_string(data.time.j2000Seconds()), std::to_string(RadecManager::_checkFileTime + endTime)));
}
return _pos;
}
} // namespace openspace

View File

@@ -42,6 +42,9 @@ namespace documentation { struct Documentation; }
class RadecTranslation : public Translation {
public:
static glm::vec3 _pos;
RadecTranslation();
void extractData(std::unique_ptr<ghoul::Dictionary> &dictionary);
RadecTranslation(const ghoul::Dictionary& dictionary);
@@ -51,10 +54,9 @@ public:
glm::dvec3 transformCartesianCoordinates(glm::vec3 pos) const;
glm::dvec3 position(const UpdateData& data) const override;
static documentation::Documentation Documentation();
private:
properties::DVec3Property _position;
glm::dmat4 _rotEquatorialSphere = { -0.05487554, 0.4941095, -0.8676661, 0.0,
-0.8734371 , -0.4448296, -0.1980764, 0.0,
-0.483835 , 0.7469823, 0.4559838, 0.0,