fixed function to optimize position data reading

This commit is contained in:
Agnes Heppich
2018-11-30 17:12:12 -05:00
parent e1ab66e791
commit 865b19fab1
3 changed files with 41 additions and 28 deletions

View File

@@ -34,16 +34,28 @@ namespace openspace {
return dataFilesSuccess;
}
glm::vec3 RadecManager::getPosForTime(double time) const {
std::vector<double> timeDoubles = DataFileHelper::getHoursFromFileNames(_dataFiles); //save as member
bool RadecManager::correctHour(double time) const{
const bool isTimeInFileInterval = (time >= _checkFileTime) &&
(time < _checkFileTime + 3600);
int idx = DataFileHelper::findFileIndexForCurrentTime(time, timeDoubles);
if (radecParser(idx)) {
//If we have the correct file, check for the correct position in that file.
glm::vec3 pos = findPositionInVector(time);
return glm::vec3(pos.x,pos.y,pos.z);
return isTimeInFileInterval;
}
bool RadecManager::correctMinute(double time) const {
const bool isTimeInActiveMinute = (time >= activeMinute && time < activeMinute + 60);
return isTimeInActiveMinute;
}
glm::vec3 RadecManager::getPosForTime(double time) const {
if (!correctHour(time)) {
std::vector<double> timeDoubles = DataFileHelper::getHoursFromFileNames(_dataFiles);
int idx = DataFileHelper::findFileIndexForCurrentTime(time, timeDoubles);
radecParser(idx);
}
return glm::vec3(-1,-1,-1);
if(!correctMinute(time)) {
getPositionInVector(time);
}
return glm::vec3(position.ra, position.dec, position.range);
}
bool RadecManager::radecParser(int index) const{
@@ -77,19 +89,23 @@ namespace openspace {
return true;
}
glm::vec3 RadecManager::findPositionInVector(double time) const{
RadecManager::Position RadecManager::getPositionInVector(double time) const{
minuteTimes.clear();
minuteTimes.reserve(0);
for (int i = 0; i < RadecManager::positions.size(); i++) {
//Convert each timestamp in vector of positions to j2000
minuteTimes.push_back(Time::convertTime(positions[i].timeStamp));
}
int idx = DataFileHelper::findFileIndexForCurrentTime(time, minuteTimes);
glm::vec3 pos = { positions[idx].ra, positions[idx].dec, positions[idx].range };
return pos;
}
activeMinute = minuteTimes[idx];
position.timeStamp = positions[idx].timeStamp;
position.ra = positions[idx].ra;
position.dec = positions[idx].dec;
position.range = positions[idx].range;
return position;
}
}

View File

@@ -45,6 +45,9 @@ namespace openspace {
};
mutable std::vector<Position> positions;
mutable std::vector<double> minuteTimes;
mutable Position position;
mutable glm::vec3 currentMinute;
mutable double activeMinute = 0;
/*Used to check if the loaded file is still relevant or if we should look for another one. */
mutable double _checkFileTime;
@@ -57,8 +60,12 @@ namespace openspace {
glm::vec3 getPosForTime(double time) const;
/* parses positioningdata from a file given an index in our preloaded filename vector */
bool radecParser(int index) const;
glm::vec3 findPositionInVector(double time) const;
/*Find the correct minute in the vector of loaded positions*/
RadecManager::Position getPositionInVector(double time) const;
/*Check if current hour in open space is already loaded*/
bool correctHour(double time) const;
/*Check if current minute in open space is already loaded*/
bool correctMinute(double time) const;
};
}

View File

@@ -125,18 +125,8 @@ glm::dvec3 RadecTranslation::transformCartesianCoordinates(glm::vec3 pos) const
}
glm::dvec3 RadecTranslation::position(const UpdateData& data) const{
//double endTime = 3600;
double endTime = 60;
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);
}
glm::vec3 pos = radecManager.getPosForTime(data.time.j2000Seconds());
_pos = transformCartesianCoordinates(pos);
return _pos;
}