[WIP] Receive RA Dec Distance

This commit is contained in:
Jacob Molin
2022-06-24 14:34:07 -06:00
parent 78cdcf9178
commit 4ee5b6a259
11 changed files with 245 additions and 21 deletions
@@ -609,6 +609,9 @@ void handleDataMessage(const std::vector<std::byte>& message, std::shared_ptr<So
if (dataKey == simp::DataKey::X
|| dataKey == simp::DataKey::Y
|| dataKey == simp::DataKey::Z
|| dataKey == simp::DataKey::RA
|| dataKey == simp::DataKey::Dec
|| dataKey == simp::DataKey::Distance
|| dataKey == simp::DataKey::U
|| dataKey == simp::DataKey::V
|| dataKey == simp::DataKey::W
@@ -667,6 +670,9 @@ void handleDataMessage(const std::vector<std::byte>& message, std::shared_ptr<So
if (dataKey == simp::DataKey::PointUnit) {
if (!handleStringValue(message, offset, identifier, dataKey, "PointUnit")) break;
}
else if (dataKey == simp::DataKey::PositionCoordSystem) {
if (!handleStringValue(message, offset, identifier, dataKey, "PositionCoordSystem")) break;
}
// Handle fixed color
else if (dataKey == simp::DataKey::Red) {
if (!simp::readColorChannel(message, offset, dataKey, newColor, 0)) break;
@@ -43,6 +43,9 @@
#include <ghoul/opengl/textureunit.h>
#include <fstream>
const std::string STRING_NOT_SET = "<string not set>";
namespace {
constexpr const char* _loggerCat = "PointsCloud";
@@ -77,6 +80,12 @@ namespace {
"Point Unit",
"The distance unit of the point data."
};
constexpr openspace::properties::Property::PropertyInfo PositionCoordSystemInfo = {
"PositionCoordSystem",
"Position Coordinate System",
"The coordinate system of the point data."
};
constexpr openspace::properties::Property::PropertyInfo SizeOptionInfo = {
"SizeOption",
@@ -181,6 +190,9 @@ namespace {
// [[codegen::verbatim(PointUnitInfo.description)]]
std::optional<std::string> pointUnit;
// [[codegen::verbatim(PositionCoordSystemInfo.description)]]
std::optional<std::string> positionCoordSystem;
// [[codegen::verbatim(ColormapMinInfo.description)]]
std::optional<float> colormapMin;
@@ -246,7 +258,8 @@ RenderablePointsCloud::RenderablePointsCloud(const ghoul::Dictionary& dictionary
: Renderable(dictionary)
, _color(ColorInfo, glm::vec4(glm::vec3(0.5f), 1.f), glm::vec4(0.f), glm::vec4(1.f), glm::vec4(.01f))
, _size(SizeInfo, 1.f, 0.f, 500.f, .1f)
, _pointUnit(PointUnitInfo, "<no unit set>")
, _pointUnit(PointUnitInfo, STRING_NOT_SET)
, _positionCoordSystem(PositionCoordSystemInfo, STRING_NOT_SET)
, _sizeOption(SizeOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
, _colormapMin(ColormapMinInfo)
, _colormapMax(ColormapMaxInfo)
@@ -256,8 +269,8 @@ RenderablePointsCloud::RenderablePointsCloud(const ghoul::Dictionary& dictionary
, _linearSizeMax(LinearSizeMinInfo)
, _linearSizeMin(LinearSizeMaxInfo)
, _linearSizeEnabled(LinearSizeEnabledInfo, false)
, _velocityDistanceUnit(VelocityDistanceUnitInfo, "<no unit set>")
, _velocityTimeUnit(VelocityTimeUnitInfo, "<no unit set>")
, _velocityDistanceUnit(VelocityDistanceUnitInfo, STRING_NOT_SET)
, _velocityTimeUnit(VelocityTimeUnitInfo, STRING_NOT_SET)
, _velocityDateRecorded(VelocityDateRecordedInfo, glm::ivec3{ -1 })
, _velocityNanMode(VelocityNanModeInfo)
, _name(NameInfo)
@@ -299,6 +312,11 @@ RenderablePointsCloud::RenderablePointsCloud(const ghoul::Dictionary& dictionary
_pointUnit.onChange([this] { _pointUnitIsDirty = true; });
addProperty(_pointUnit);
_positionCoordSystem = p.positionCoordSystem.value_or(_positionCoordSystem);
_positionCoordSystem.setVisibility(properties::Property::Visibility::Hidden);
_positionCoordSystem.onChange([this] { _positionCoordSystemIsDirty = true; });
addProperty(_positionCoordSystem);
// =============== Colormap ===============
_colormapMin = p.colormapMin.value_or(_colormapMin);
_colormapMin.setVisibility(properties::Property::Visibility::Hidden);
@@ -626,6 +644,7 @@ bool RenderablePointsCloud::checkDataStorage() {
loadPointData(softwareIntegrationModule);
updatedDataSlices = true;
_pointUnitIsDirty = false;
_positionCoordSystemIsDirty = false;
}
if (shouldLoadColormap(softwareIntegrationModule)) {
@@ -653,8 +672,33 @@ bool RenderablePointsCloud::checkDataStorage() {
void RenderablePointsCloud::loadPointData(SoftwareIntegrationModule* softwareIntegrationModule) {
// Fetch point data from module's centralized storage
std::vector<float> pointData;
if (!softwareIntegrationModule->fetchData(_identifier.value(), storage::Key::DataPoints, pointData)) {
ghoul::Dictionary additionalInfo;
switch (simp::getCoordSystem(_positionCoordSystem)) {
case simp::CoordSystem::Cartesian: {
additionalInfo.setValue(
"CoordSystem",
simp::getStringFromCoordSystem(simp::CoordSystem::Cartesian)
);
break;
}
case simp::CoordSystem::ICRS: {
additionalInfo.setValue(
"CoordSystem",
simp::getStringFromCoordSystem(simp::CoordSystem::ICRS)
);
break;
}
default: { // Unknown
LERROR(fmt::format(
"Could not find any coordinate system '{}'",
_positionCoordSystem
));
return;
}
}
std::vector<float> pointData;
if (!softwareIntegrationModule->fetchData(_identifier.value(), storage::Key::DataPoints, pointData, additionalInfo)) {
LERROR("There was an issue trying to fetch the point data from the centralized storage.");
return;
}
@@ -938,9 +982,11 @@ bool RenderablePointsCloud::shouldLoadPointData(SoftwareIntegrationModule* softw
return (
(
_pointUnitIsDirty
|| _positionCoordSystemIsDirty
|| softwareIntegrationModule->isDataDirty(_identifier.value(), storage::Key::DataPoints)
)
&& _pointUnit.value() != "<no unit set>"
&& _pointUnit.value() != STRING_NOT_SET
&& _positionCoordSystem.value() != STRING_NOT_SET
);
}
@@ -950,8 +996,8 @@ bool RenderablePointsCloud::shouldLoadVelocityData(SoftwareIntegrationModule* so
_velocityUnitsAreDirty
|| softwareIntegrationModule->isDataDirty(_identifier.value(), storage::Key::VelocityData)
)
&& _velocityDistanceUnit.value() != "<no unit set>"
&& _velocityTimeUnit.value() != "<no unit set>"
&& _velocityDistanceUnit.value() != STRING_NOT_SET
&& _velocityTimeUnit.value() != STRING_NOT_SET
);
}
@@ -97,6 +97,7 @@ private:
properties::FloatProperty _size;
properties::Vec4Property _color;
properties::StringProperty _pointUnit;
properties::StringProperty _positionCoordSystem;
properties::OptionProperty _sizeOption;
properties::BoolProperty _linearSizeEnabled;
@@ -120,6 +121,7 @@ private:
std::optional<std::string> _identifier = std::nullopt;
bool _pointUnitIsDirty = false;
bool _positionCoordSystemIsDirty = false;
bool _hasLoadedColormapAttributeData = false;
bool _hasLoadedColormap = false;
+32
View File
@@ -49,7 +49,11 @@ const std::unordered_map<std::string, DataKey> _dataTypeFromString{
{ "pos.x", DataKey::X },
{ "pos.y", DataKey::Y },
{ "pos.z", DataKey::Z },
{ "pos.ra", DataKey::RA },
{ "pos.dec", DataKey::Dec },
{ "pos.dist", DataKey::Distance },
{ "pos.unit", DataKey::PointUnit },
{ "pos.coordsys", DataKey::PositionCoordSystem },
{ "vel.u", DataKey::U },
{ "vel.v", DataKey::V },
{ "vel.w", DataKey::W },
@@ -85,6 +89,11 @@ const std::unordered_map<std::string, DataKey> _dataTypeFromString{
{ "vis.val", DataKey::Visibility },
};
const std::unordered_map<std::string, CoordSystem> _coordSystemFromString {
{ "Cartesian", CoordSystem::Cartesian },
{ "ICRS", CoordSystem::ICRS },
};
const std::unordered_map<std::string, ColormapNanRenderMode> _colormapNanRenderModeFromString {
{ "Hide", ColormapNanRenderMode::Hide },
{ "FixedColor", ColormapNanRenderMode::FixedColor },
@@ -253,6 +262,29 @@ std::string getStringFromDataKey(const DataKey& key) {
return it->first;
}
bool hasCoordSystem(const std::string& key) {
return _coordSystemFromString.count(key) > 0;
}
CoordSystem getCoordSystem(const std::string& key) {
if (hasCoordSystem(key)) {
return _coordSystemFromString.at(key);
}
return CoordSystem::Unknown;
}
std::string getStringFromCoordSystem(const CoordSystem& key) {
auto it = std::find_if(
_coordSystemFromString.begin(),
_coordSystemFromString.end(),
[key](const std::pair<const std::string, CoordSystem>& p) {
return key == p.second;
}
);
if (it == _coordSystemFromString.end()) return "";
return it->first;
}
ColormapNanRenderMode getColormapNanRenderMode(const std::string& type) {
if (_colormapNanRenderModeFromString.count(type) == 0) return ColormapNanRenderMode::Unknown;
return _colormapNanRenderModeFromString.at(type);
+14
View File
@@ -54,7 +54,11 @@ enum class DataKey : uint16_t {
X = 0,
Y,
Z,
RA,
Dec,
Distance,
PointUnit,
PositionCoordSystem,
// Velocity
U,
V,
@@ -97,6 +101,12 @@ enum class DataKey : uint16_t {
Unknown
};
enum class CoordSystem : uint8_t {
Cartesian = 0,
ICRS,
Unknown
};
enum class ColormapNanRenderMode {
Hide = 0,
FixedColor,
@@ -135,6 +145,10 @@ DataKey getDataKey(const std::string& type);
std::string getStringFromDataKey(const DataKey& type);
CoordSystem getCoordSystem(const std::string& type);
std::string getStringFromCoordSystem(const CoordSystem& type);
ColormapNanRenderMode getColormapNanRenderMode(const std::string& type);
VelocityNanRenderMode getVelocityNanRenderMode(const std::string& type);
@@ -66,9 +66,10 @@ void SoftwareIntegrationModule::storeData(
bool SoftwareIntegrationModule::isDataDirty(
const SyncableStorage::Identifier& identifier,
const storage::Key key
const storage::Key key,
const ghoul::Dictionary& additionalInfo
) {
return _syncableStorage.isDirty(identifier, key);
return _syncableStorage.isDirty(identifier, key, additionalInfo);
}
void SoftwareIntegrationModule::setDataLoaded(
@@ -56,11 +56,13 @@ public:
bool fetchData(
const SyncableStorage::Identifier& identifier,
const storage::Key key,
T& resultingData
T& resultingData,
const ghoul::Dictionary& additionalInfo = {}
);
bool isDataDirty(
const SyncableStorage::Identifier& identifier,
const storage::Key key
const storage::Key key,
const ghoul::Dictionary& additionalInfo = {}
);
void setDataLoaded(
const SyncableStorage::Identifier& identifier,
@@ -28,9 +28,10 @@ template <typename T>
bool SoftwareIntegrationModule::fetchData(
const SyncableStorage::Identifier& identifier,
const storage::Key key,
T& resultingData
T& resultingData,
const ghoul::Dictionary& additionalInfo
) {
return _syncableStorage.fetch(identifier, key, resultingData);
return _syncableStorage.fetch(identifier, key, resultingData, additionalInfo);
}
} // namespace openspace
@@ -25,6 +25,7 @@
#include <modules/softwareintegration/utils/syncablestorage.h>
#include <openspace/util/syncbuffer.h>
#include <openspace/util/coordinateconversion.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/logging/logmanager.h>
@@ -244,6 +245,33 @@ void SyncableStorage::insertAssign(const Identifier& identifier, const simp::Dat
}
}
// ghoul::Dictionary getDataKeysAdditionalInfo(const storage::Key storageKey) {
// ghoul::Dictionary additionalInfo;
// switch () {
// case simp::CoordSystem::Cartesian: {
// additionalInfo.setValue(
// "CoordSystem",
// simp::getStringFromCoordSystem(simp::CoordSystem::Cartesian)
// );
// break;
// }
// case simp::CoordSystem::ICRS: {
// additionalInfo.setValue(
// "CoordSystem",
// simp::getStringFromCoordSystem(simp::CoordSystem::ICRS)
// );
// break;
// }
// default: { // Unknown
// LERROR(fmt::format(
// "Could not find any coordinate system '{}'",
// _positionCoordSystem
// ));
// return;
// }
// }
// }
size_t SyncableStorage::count(const Identifier& identifier) {
return _storage.count(identifier);
}
@@ -255,10 +283,34 @@ size_t SyncableStorage::count(const Identifier& identifier, const simp::DataKey
return sceneIt->second.count(key);
}
std::vector<simp::DataKey> SyncableStorage::simpDataKeysFromStorageKey(const storage::Key key) {
std::vector<simp::DataKey> SyncableStorage::simpDataKeysFromStorageKey(
const storage::Key key,
const ghoul::Dictionary& additionalInfo
) {
switch (key) {
case storage::Key::DataPoints: {
return { simp::DataKey::X, simp::DataKey::Y, simp::DataKey::Z };
if (!additionalInfo.hasKey("CoordSystem")) {
LERROR(fmt::format(
"A coordinate system is needed to load point data from syncable storage."
));
return {};
}
std::string coordSystemString = additionalInfo.value<std::string>("CoordSystem");
simp::CoordSystem coordSystem = simp::getCoordSystem(coordSystemString);
switch (coordSystem) {
case simp::CoordSystem::Cartesian:
return { simp::DataKey::X, simp::DataKey::Y, simp::DataKey::Z };
case simp::CoordSystem::ICRS:
return { simp::DataKey::RA, simp::DataKey::Dec, simp::DataKey::Distance };
default: { // simp::CoordSystem::Unknown
LERROR(fmt::format(
"Could not find the coordinate system '{}'.",
coordSystemString
));
return {};
}
}
}
case storage::Key::VelocityData:{
return { simp::DataKey::U, simp::DataKey::V, simp::DataKey::W };
@@ -394,6 +446,52 @@ bool SyncableStorage::fetchDimFloatData(
return true;
}
bool SyncableStorage::fetchPositionData(
const Identifier& identifier,
const storage::Key storageKey,
std::vector<float>& resultingData,
const ghoul::Dictionary& additionalInfo
) {
if (!additionalInfo.hasKey("CoordSystem")) {
LERROR(fmt::format(
"A coordinate system is needed to load point data from syncable storage."
));
return false;
}
std::string coordSystemString = additionalInfo.value<std::string>("CoordSystem");
simp::CoordSystem coordSystem = simp::getCoordSystem(coordSystemString);
bool success = fetchDimFloatData(identifier, simpDataKeysFromStorageKey(storageKey, additionalInfo), resultingData);
if (!success) return false;
switch (coordSystem) {
case simp::CoordSystem::Cartesian:
return success;
case simp::CoordSystem::ICRS: {
// Convert (RA, Dec, Distance) => (X, Y, Z)
for (size_t i = 0; i < resultingData.size()/3; i += 3) {
double ra = resultingData[i];
double dec = resultingData[i + 1];
double dist = resultingData[i + 2];
glm::dvec3 pos = icrsToGalacticCartesian(ra, dec, dist);
resultingData[i] = static_cast<float>(pos.x);
resultingData[i + 1] = static_cast<float>(pos.y);
resultingData[i + 2] = static_cast<float>(pos.z);
}
// TODO: Check for errors
return true;
}
default: { // simp::CoordSystem::Unknown
LERROR(fmt::format(
"Could not find the coordinate system '{}' when trying to fetch data from syncable storage",
coordSystemString
));
return false;
}
}
}
/* ================================================== */
} // namespace openspace
@@ -29,6 +29,8 @@
#include <openspace/util/syncable.h>
#include <modules/softwareintegration/simp/simp.h>
#include <ghoul/misc/dictionary.h>
#include <mutex>
#include <unordered_map>
@@ -81,7 +83,8 @@ public:
bool fetch(
const Identifier& identifier,
const storage::Key storageKey,
T& resultingData
T& resultingData,
const ghoul::Dictionary& additionalInfo
);
void setLoaded(const Identifier& identifier, const storage::Key storageKey);
bool hasLoaded(const Identifier& identifier, const storage::Key storageKey);
@@ -97,14 +100,26 @@ public:
private:
/* =============== Utility functions ================ */
void insertAssign(const Identifier& identifier, const simp::DataKey key, const Value& value);
size_t count(const Identifier& identifier);
size_t count(const Identifier& identifier, const simp::DataKey key);
std::vector<simp::DataKey> simpDataKeysFromStorageKey(const storage::Key key);
std::vector<simp::DataKey> simpDataKeysFromStorageKey(
const storage::Key key,
const ghoul::Dictionary& additionalInfo = {}
);
bool fetchDimFloatData(
const Identifier& identifier,
const std::vector<simp::DataKey> dimDataKeys,
std::vector<float>& resultingData
);
bool fetchPositionData(
const Identifier& identifier,
// const std::vector<simp::DataKey> dimDataKeys,
const storage::Key key,
std::vector<float>& resultingData,
const ghoul::Dictionary& additionalInfo
);
/* ================================================== */
std::mutex _mutex;
@@ -30,7 +30,8 @@ template<typename T>
bool SyncableStorage::fetch(
const Identifier& identifier,
const storage::Key storageKey,
T& resultingData
T& resultingData,
const ghoul::Dictionary& additionalInfo
) {
LDEBUGC("SyncableStorage", fmt::format("Loading data from float data storage: {}-{}", identifier, storage::getStorageKeyString(storageKey)));
std::lock_guard guard(_mutex);
@@ -42,8 +43,11 @@ bool SyncableStorage::fetch(
return false;
}
LERRORC("SyncableStorage", fmt::format("stroageKey={}", storage::getStorageKeyString(storageKey)));
switch (storageKey) {
case storage::Key::DataPoints:
case storage::Key::DataPoints: {
return fetchPositionData(identifier, storageKey, resultingData, additionalInfo);
}
case storage::Key::Colormap:
case storage::Key::ColormapAttrData:
case storage::Key::LinearSizeAttrData:
@@ -55,7 +59,10 @@ bool SyncableStorage::fetch(
));
return false;
}
// std::vector<simp::DataKey> simpDataKeys = simpDataKeysFromStorageKey(storageKey, additionalInfo);
// if (simpDataKeys.size() < 1) {
// return false;
// }
return fetchDimFloatData(identifier, simpDataKeysFromStorageKey(storageKey), resultingData);
}
default: {