mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-31 08:29:04 -06:00
made constructor for radecmanager, now we create instances of it to handle multiple spacecraft positioning
This commit is contained in:
@@ -170,6 +170,30 @@ namespace openspace {
|
||||
}
|
||||
return fileStartTimes;
|
||||
}
|
||||
|
||||
int DataFileHelper::findFileIndexForCurrentTime(double time, std::vector<double> vec) {
|
||||
// upper_bound has O(log n) for sorted vectors, more efficient than for loop
|
||||
auto iter = std::upper_bound(vec.begin(), vec.end(), time);
|
||||
|
||||
int fileIndex = -1;
|
||||
//check what index we got
|
||||
if (iter != vec.end()) {
|
||||
if (iter != vec.begin()) {
|
||||
fileIndex = static_cast<int>(
|
||||
std::distance(vec.begin(), iter)
|
||||
) - 1;
|
||||
}
|
||||
else {
|
||||
fileIndex = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fileIndex = static_cast<int>(vec.size()) - 1;
|
||||
}
|
||||
|
||||
return fileIndex;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <modules/dsn/managers/signalmanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
@@ -45,6 +45,8 @@ namespace openspace {
|
||||
static std::string getFileNameTime(std::string filename, const int FilenameSize);
|
||||
/* Extracts the timestamp from a vector of filenames */
|
||||
static std::vector<double> extractTriggerTimesFromFileNames(std::vector<std::string> _dataFiles, const int FilenameSize);
|
||||
/* Returns an index for our filenames */
|
||||
static int findFileIndexForCurrentTime(double time, std::vector<double> vec);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -26,30 +26,26 @@
|
||||
|
||||
namespace openspace {
|
||||
constexpr const char* _loggerCat = "RadecManager";
|
||||
std::vector<std::string> RadecManager::_dataFiles;
|
||||
double RadecManager::_ra;
|
||||
double RadecManager::_dec;
|
||||
double RadecManager::_range;
|
||||
double RadecManager::_checkFileTime;
|
||||
|
||||
RadecManager::RadecManager() = default;
|
||||
bool RadecManager::extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr<ghoul::Dictionary> &dictionary){
|
||||
bool dataFilesSuccess = DataFileHelper::checkFileNames(identifier, dictionary, RadecManager::_dataFiles);
|
||||
bool dataFilesSuccess = DataFileHelper::checkFileNames(identifier, dictionary, _dataFiles);
|
||||
radecParser(0);
|
||||
return dataFilesSuccess;
|
||||
}
|
||||
|
||||
glm::vec3 RadecManager::GetPosForTime(double time) {
|
||||
glm::vec3 RadecManager::getPosForTime(double time) const{
|
||||
std::vector<double> timeDoubles = DataFileHelper::getHoursFromFileNames(_dataFiles); //save as member
|
||||
int idx = RenderableSignals::findFileIndexForCurrentTime(time, timeDoubles);
|
||||
int idx = DataFileHelper::findFileIndexForCurrentTime(time, timeDoubles);
|
||||
|
||||
//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);
|
||||
}
|
||||
if (radecParser(idx)) {
|
||||
return glm::vec3(_ra,_dec,_range);
|
||||
}
|
||||
return glm::vec3(-1,-1,-1);
|
||||
}
|
||||
|
||||
bool RadecManager::radecParser(int index) {
|
||||
bool RadecManager::radecParser(int index) const{
|
||||
std::string filename;
|
||||
|
||||
if (index == -1 || index > _dataFiles.size())
|
||||
@@ -58,7 +54,7 @@ namespace openspace {
|
||||
filename = _dataFiles[index];
|
||||
|
||||
std::string startTimeString = DataFileHelper::getHourFromFileName(filename);
|
||||
const double triggerTime = Time::convertTime(startTimeString);
|
||||
double triggerTime = Time::convertTime(startTimeString);
|
||||
_checkFileTime = triggerTime;
|
||||
|
||||
std::ifstream ifs(filename);
|
||||
|
||||
@@ -27,28 +27,29 @@
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <modules/dsn/managers/datafilehelper.h>
|
||||
#include <modules/dsn/rendering/renderablesignals.h>
|
||||
|
||||
#include <openspace/json.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RadecManager {
|
||||
|
||||
public:
|
||||
static double _ra;
|
||||
static double _dec;
|
||||
static double _range;
|
||||
RadecManager();
|
||||
mutable double _ra;
|
||||
mutable double _dec;
|
||||
mutable double _range;
|
||||
/*Used to check if the loaded file is still relevant or if we should look for another one. */
|
||||
static double _checkFileTime;
|
||||
|
||||
mutable double _checkFileTime;
|
||||
/* A vector with all our datafile paths*/
|
||||
static std::vector<std::string> _dataFiles;
|
||||
std::vector<std::string> _dataFiles;
|
||||
|
||||
/* Extracts all the mandatory information we need from our asset file */
|
||||
static bool extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr<ghoul::Dictionary> &dictionary);
|
||||
bool extractMandatoryInfoFromDictionary(const char* identifier, std::unique_ptr<ghoul::Dictionary> &dictionary);
|
||||
/*gets the correct datafile, that matches the current time in open space*/
|
||||
static glm::vec3 GetPosForTime(double time);
|
||||
glm::vec3 getPosForTime(double time) const;
|
||||
/* parses positioningdata from a file given an index in our preloaded filename vector */
|
||||
static bool radecParser(int index);
|
||||
bool radecParser(int index) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
|
||||
@@ -35,7 +35,6 @@ namespace {
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
glm::vec3 RadecTranslation:: _pos;
|
||||
|
||||
constexpr const char* _loggerCat = "RadecTranslation";
|
||||
|
||||
@@ -68,12 +67,13 @@ RadecTranslation::RadecTranslation()
|
||||
glm::dvec3(std::numeric_limits<double>::max())
|
||||
)
|
||||
{
|
||||
//todo, exchange this property to ra dec range probably
|
||||
addProperty(_position);
|
||||
|
||||
_position.onChange([this]() {
|
||||
requireUpdate();
|
||||
notifyObservers();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
RadecTranslation::RadecTranslation(const ghoul::Dictionary& dictionary)
|
||||
@@ -92,7 +92,7 @@ RadecTranslation::RadecTranslation(const ghoul::Dictionary& dictionary)
|
||||
void RadecTranslation::extractData(std::unique_ptr<ghoul::Dictionary> &dictionary){
|
||||
const char* _identifier = "spacecraft";
|
||||
|
||||
if (!RadecManager::extractMandatoryInfoFromDictionary(_identifier, dictionary)) {
|
||||
if (!radecManager.extractMandatoryInfoFromDictionary(_identifier, dictionary)) {
|
||||
LERROR(fmt::format("{}: Did not manage to extract data. (from RadecTranslation and RadecManager)", _identifier));
|
||||
}
|
||||
else {
|
||||
@@ -124,16 +124,16 @@ glm::dvec3 RadecTranslation::transformCartesianCoordinates(glm::vec3 pos) const
|
||||
return worldposition;
|
||||
}
|
||||
|
||||
glm::dvec3 RadecTranslation::position(const UpdateData& data) const{
|
||||
glm::dvec3 RadecTranslation::position(const UpdateData& data) const {
|
||||
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);
|
||||
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);
|
||||
|
||||
}
|
||||
return _pos;
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/properties/vector/dvec3property.h>
|
||||
#include <modules/dsn/rendering/renderablesignals.h>
|
||||
#include <modules/dsn/managers/radecmanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -43,20 +43,23 @@ 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);
|
||||
/* Converts the Ra Dec range coordinates into cartesian coordinates*/
|
||||
glm::dvec3 convertRaDecRangeToCartesian(double ra, double dec, double range) const;
|
||||
/*Transforms the cartesian coordinates with a rotation and a translation*/
|
||||
glm::dvec3 transformCartesianCoordinates(glm::vec3 pos) const;
|
||||
|
||||
void extractData(std::unique_ptr<ghoul::Dictionary> &dictionary);
|
||||
glm::dvec3 position(const UpdateData& data) const override;
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
/* Converts the Ra Dec range coordinates into cartesian coordinates*/
|
||||
glm::dvec3 convertRaDecRangeToCartesian(double ra, double dec, double range) const;
|
||||
/*Transforms the cartesian coordinates with a rotation and a translation*/
|
||||
glm::dvec3 transformCartesianCoordinates(glm::vec3 pos) const;
|
||||
|
||||
RadecManager radecManager;
|
||||
mutable glm::vec3 _pos;
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user