Transformation Manager

This commit is contained in:
Sebastian Piwell
2016-05-10 11:18:09 -04:00
parent 18c83a3bd7
commit e51b104ce8
7 changed files with 249 additions and 139 deletions

View File

@@ -0,0 +1,52 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __TRANSFORMATIONMANAGER__
#define __TRANSFORMATIONMANAGER__
#include <ghoul/designpattern/singleton.h>
#include <ghoul/glm.h>
#include <ccmc/Kameleon.h>
namespace openspace {
class ccmc::Kameleon;
class TransformationManager : public ghoul::Singleton<TransformationManager> {
friend class ghoul::Singleton<TransformationManager>;
public:
TransformationManager();
~TransformationManager();
glm::dmat3 frameTransformationMatrix(std::string from, std::string to, double ephemerisTime) const;
private:
std::shared_ptr<ccmc::Kameleon> _kameleon;
std::set<std::string> _kameleonFrames;
std::set<std::string> _dipoleFrames;
};
}
#endif //__TRANSFORMATIONMANAGER__

View File

@@ -27,6 +27,8 @@
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/time.h>
#include <openspace/util/transformationmanager.h>
namespace openspace{
@@ -175,7 +177,7 @@ void IswaCygnet::update(const UpdateData& data){
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
_stateMatrix = IswaManager::ref().getTransform(_data->frame, "GALACTIC", _openSpaceTime);
_stateMatrix = TransformationManager::ref().frameTransformationMatrix(_data->frame, "GALACTIC", _openSpaceTime);
// glm::dmat3 spiceMatrix = SpiceManager::ref().positionTransformMatrix("J2000", "GALACTIC", _openSpaceTime);
// = spiceMatrix*kameleonMatrix;

View File

@@ -70,11 +70,6 @@ IswaManager::IswaManager()
_geom[CygnetGeometry::Plane] = "Plane";
_geom[CygnetGeometry::Sphere] = "Sphere";
_kameleon = std::make_shared<ccmc::Kameleon>();
_kameleonFrames = { "J2000", "GEI", "GEO", "MAG", "GSE", "GSM", "SM", "RTN", "GSEQ", //geocentric
"HEE", "HAE", "HEEQ" //heliocentric
};
}
IswaManager::~IswaManager(){
@@ -358,74 +353,74 @@ std::string IswaManager::parseJSONToLuaTable(std::shared_ptr<MetadataFuture> dat
return "";
}
void IswaManager::createKameleonPlane(std::string kwPath, int group){
kwPath = "${OPENSPACE_DATA}/" + kwPath;
const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
// void IswaManager::createKameleonPlane(std::string kwPath, int group){
// kwPath = "${OPENSPACE_DATA}/" + kwPath;
// const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){
std::string luaTable = parseKWToLuaTable(kwPath, group);
if(!luaTable.empty()){
std::cout << luaTable << std::endl;
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
OsEng.scriptEngine().queueScript(script);
}
}else{
LWARNING( kwPath + " is not a cdf file or can't be found.");
}
}
std::string IswaManager::parseKWToLuaTable(std::string kwPath, int group){
if(kwPath != ""){
const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
if(extension == "cdf"){
KameleonWrapper kw = KameleonWrapper(absPath(kwPath));
// if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){
// std::string luaTable = parseKWToLuaTable(kwPath, group);
// if(!luaTable.empty()){
// std::cout << luaTable << std::endl;
// std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
// OsEng.scriptEngine().queueScript(script);
// }
// }else{
// LWARNING( kwPath + " is not a cdf file or can't be found.");
// }
// }
//
// std::string IswaManager::parseKWToLuaTable(std::string kwPath, int group){
// if(kwPath != ""){
// const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
// if(extension == "cdf"){
// KameleonWrapper kw = KameleonWrapper(absPath(kwPath));
std::string parent = kw.getParent();
std::string frame = kw.getFrame();
glm::vec3 min = kw.getGridMin();
glm::vec3 max = kw.getGridMax();
// std::string parent = kw.getParent();
// std::string frame = kw.getFrame();
// glm::vec3 min = kw.getGridMin();
// glm::vec3 max = kw.getGridMax();
glm::vec4 spatialScale;
std::string coordinateType;
// glm::vec4 spatialScale;
// std::string coordinateType;
std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits();
if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") {
spatialScale.x = 6.371f;
spatialScale.y = 6.371f;
spatialScale.z = 6.371f;
spatialScale.w = 6;
// std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits();
// if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") {
// spatialScale.x = 6.371f;
// spatialScale.y = 6.371f;
// spatialScale.z = 6.371f;
// spatialScale.w = 6;
coordinateType = "Cartesian";
}else{
spatialScale = glm::vec4(1.0);
spatialScale.w = 1; //-log10(1.0f/max.x);
// coordinateType = "Cartesian";
// }else{
// spatialScale = glm::vec4(1.0);
// spatialScale.w = 1; //-log10(1.0f/max.x);
coordinateType = "Polar";
}
std::string table = "{"
"Name = 'KameleonPlane0',"
"Parent = '" + parent + "', "
"Renderable = {"
"Type = 'KameleonPlane', "
"Id = 0 ,"
"Frame = '" + frame + "' , "
"GridMin = " + std::to_string(min) + ", "
"GridMax = " + std::to_string(max) + ", "
"SpatialScale = " + std::to_string(spatialScale) + ", "
"UpdateTime = 0, "
"kwPath = '" + kwPath + "' ,"
"axisCut = 'y' ,"
"CoordinateType = '" + coordinateType + "', "
"Group = "+ std::to_string(group) + " ,"
"}"
"}"
;
// std::cout << table << std::endl;
return table;
}
}
return "";
}
// coordinateType = "Polar";
// }
// std::string table = "{"
// "Name = 'KameleonPlane0',"
// "Parent = '" + parent + "', "
// "Renderable = {"
// "Type = 'KameleonPlane', "
// "Id = 0 ,"
// "Frame = '" + frame + "' , "
// "GridMin = " + std::to_string(min) + ", "
// "GridMax = " + std::to_string(max) + ", "
// "SpatialScale = " + std::to_string(spatialScale) + ", "
// "UpdateTime = 0, "
// "kwPath = '" + kwPath + "' ,"
// "axisCut = 'y' ,"
// "CoordinateType = '" + coordinateType + "', "
// "Group = "+ std::to_string(group) + " ,"
// "}"
// "}"
// ;
// // std::cout << table << std::endl;
// return table;
// }
// }
// return "";
// }
void IswaManager::registerGroup(int id){
@@ -467,75 +462,6 @@ std::shared_ptr<IswaGroup> IswaManager::iswaGroup(std::string name){
return nullptr;
}
glm::dmat3 IswaManager::getTransform(std::string from, std::string to, double et){
std::set<std::string> _diopoleFrames = {"GSM", "SM", "MAG"};
auto fromit = _diopoleFrames.find(from);
auto toit = _diopoleFrames.find(to);
//diopole frame to J200 makes the frame rotate.
if(fromit != _diopoleFrames.end()) from = "GSE";
if(toit != _diopoleFrames.end()) to = "GSE";
fromit = _kameleonFrames.find(from);
toit = _kameleonFrames.find(to);
bool fromKameleon = (fromit != _kameleonFrames.end());
bool toKameleon = (toit != _kameleonFrames.end());
ccmc::Position in0 = {1.f, 0.f, 0.f};
ccmc::Position in1 = {0.f, 1.f, 0.f};
ccmc::Position in2 = {0.f, 0.f , 1.f};
ccmc::Position out0;
ccmc::Position out1;
ccmc::Position out2;
if(fromKameleon && toKameleon){
_kameleon->_cxform(from.c_str(), to.c_str(), et, &in0, &out0);
_kameleon->_cxform(from.c_str(), to.c_str(), et, &in1, &out1);
_kameleon->_cxform(from.c_str(), to.c_str(), et, &in2, &out2);
return glm::dmat3(
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);
}else if(fromKameleon && !toKameleon){
_kameleon->_cxform(from.c_str(), "J2000", et, &in0, &out0);
_kameleon->_cxform(from.c_str(), "J2000", et, &in1, &out1);
_kameleon->_cxform(from.c_str(), "J2000", et, &in2, &out2);
glm::dmat3 kameleonTrans(
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);
glm::dmat3 spiceTrans = SpiceManager::ref().frameTransformationMatrix("J2000", to, et);
return spiceTrans*kameleonTrans;
}else if(!fromKameleon && toKameleon){
glm::dmat3 spiceTrans = SpiceManager::ref().frameTransformationMatrix(from, "J2000", et);
_kameleon->_cxform("J2000", to.c_str(), et, &in0, &out0);
_kameleon->_cxform("J2000", to.c_str(), et, &in1, &out1);
_kameleon->_cxform("J2000", to.c_str(), et, &in2, &out2);
glm::dmat3 kameleonTrans(
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);
return kameleonTrans*spiceTrans;
}else{
return SpiceManager::ref().frameTransformationMatrix(from, to, et);
}
}
scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() {
return {
"iswa",

View File

@@ -85,8 +85,6 @@ public:
void registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options);
std::shared_ptr<IswaGroup> iswaGroup(std::string name);
glm::dmat3 getTransform(std::string from, std::string to, double et);
static scripting::ScriptEngine::LuaLibrary luaLibrary();
std::string iswaUrl(int id, std::string type = "image");

View File

@@ -89,6 +89,7 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/util/syncbuffer.cpp
${OPENSPACE_BASE_DIR}/src/util/time.cpp
${OPENSPACE_BASE_DIR}/src/util/time_lua.inl
${OPENSPACE_BASE_DIR}/src/util/transformationmanager.cpp
)
set(OPENSPACE_HEADER
@@ -166,6 +167,7 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/util/syncbuffer.h
${OPENSPACE_BASE_DIR}/include/openspace/util/time.h
${OPENSPACE_BASE_DIR}/include/openspace/util/updatestructures.h
${OPENSPACE_BASE_DIR}/include/openspace/util/transformationmanager.h
)
# Place files into source groups

View File

@@ -46,6 +46,7 @@
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/syncbuffer.h>
#include <openspace/util/transformationmanager.h>
#include <ghoul/ghoul.h>
#include <ghoul/cmdparser/commandlineparser.h>
@@ -142,6 +143,8 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
SpiceManager::initialize();
Time::initialize();
ghoul::systemcapabilities::SystemCapabilities::initialize();
TransformationManager::initialize();
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
IswaManager::initialize();
#endif

View File

@@ -0,0 +1,127 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/util/transformationmanager.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/logging/logmanager.h>
namespace {
const std::string _loggerCat = "TransformationManager";
}
namespace openspace{
TransformationManager::TransformationManager(){
#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED
_kameleon = std::make_shared<ccmc::Kameleon>();
#else
LWARNING("Kameleon module needed for transformations with dynamic frames");
#endif
_kameleonFrames = { "J2000", "GEI", "GEO", "MAG", "GSE", "GSM", "SM", "RTN", "GSEQ", //geocentric
"HEE", "HAE", "HEEQ" //heliocentric
};
_dipoleFrames = {"GSM", "SM", "MAG"};
}
TransformationManager::~TransformationManager(){
_kameleon = nullptr;
}
glm::dmat3 TransformationManager::frameTransformationMatrix(std::string from,
std::string to,
double ephemerisTime) const
{
auto fromit = _dipoleFrames.find(from);
auto toit = _dipoleFrames.find(to);
//diopole frame to J200 makes the frame rotate.
if(fromit != _dipoleFrames.end()) from = "GSE";
if(toit != _dipoleFrames.end()) to = "GSE";
fromit = _kameleonFrames.find(from);
toit = _kameleonFrames.find(to);
bool fromKameleon = (fromit != _kameleonFrames.end());
bool toKameleon = (toit != _kameleonFrames.end());
ccmc::Position in0 = {1.f, 0.f, 0.f};
ccmc::Position in1 = {0.f, 1.f, 0.f};
ccmc::Position in2 = {0.f, 0.f , 1.f};
ccmc::Position out0;
ccmc::Position out1;
ccmc::Position out2;
if(!fromKameleon && !toKameleon){
return SpiceManager::ref().frameTransformationMatrix(from, to, ephemerisTime);
}
#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED
if(fromKameleon && toKameleon){
_kameleon->_cxform(from.c_str(), to.c_str(), ephemerisTime, &in0, &out0);
_kameleon->_cxform(from.c_str(), to.c_str(), ephemerisTime, &in1, &out1);
_kameleon->_cxform(from.c_str(), to.c_str(), ephemerisTime, &in2, &out2);
return glm::dmat3(
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);
}else if(fromKameleon && !toKameleon){
_kameleon->_cxform(from.c_str(), "J2000", ephemerisTime, &in0, &out0);
_kameleon->_cxform(from.c_str(), "J2000", ephemerisTime, &in1, &out1);
_kameleon->_cxform(from.c_str(), "J2000", ephemerisTime, &in2, &out2);
glm::dmat3 kameleonTransformation(
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);
glm::dmat3 spiceTransformation = SpiceManager::ref().frameTransformationMatrix("J2000", to, ephemerisTime);
return spiceTransformation*kameleonTransformation;
}else if(!fromKameleon && toKameleon){
glm::dmat3 spiceTransformation = SpiceManager::ref().frameTransformationMatrix(from, "J2000", ephemerisTime);
_kameleon->_cxform("J2000", to.c_str(), ephemerisTime, &in0, &out0);
_kameleon->_cxform("J2000", to.c_str(), ephemerisTime, &in1, &out1);
_kameleon->_cxform("J2000", to.c_str(), ephemerisTime, &in2, &out2);
glm::dmat3 kameleonTransformation(
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);
return kameleonTransformation*spiceTransformation;
}
#else
LERROR("Can not transform dynamic frames without kameleon module enabled");
#endif
return glm::dmat3(1.0);
}
}