diff --git a/ElectronVisualizer/README.md b/ElectronVisualizer/README.md index 51a8e55..cd3ba7a 100644 --- a/ElectronVisualizer/README.md +++ b/ElectronVisualizer/README.md @@ -1,4 +1,8 @@ # ElectronVisualizer Quick Start +Run all of the following code in the **current folder**. + +## install npm first.(example in Ubuntu OS) +sudo apt-get install npm ## Install dependencies - npm install --save-dev electron @@ -6,5 +10,10 @@ ## Run the app - npm start -``` + +## Select file you want visualize ".czml" file +You can run flood "/SpaceDSL/ctest/TestMain.cpp", generate "TestData.czml" json file. +Select "TestData.czml" files from the upper left corner in app. + +``` diff --git a/SpaceDSL/CMakeLists.txt b/SpaceDSL/CMakeLists.txt index c60fd6a..e30c053 100644 --- a/SpaceDSL/CMakeLists.txt +++ b/SpaceDSL/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_CXX_STANDARD 14) message(STATUS "#ALL_OUTPUT_PATH=${ALL_OUTPUT_PATH}") # Set folder in project dir -add_subdirectory(include) +add_subdirectory(Include) add_subdirectory(source) diff --git a/SpaceDSL/include/SpaceDSL/SpCZMLScript.h b/SpaceDSL/include/SpaceDSL/SpCZMLScript.h index 698e53b..d30cb12 100644 --- a/SpaceDSL/include/SpaceDSL/SpCZMLScript.h +++ b/SpaceDSL/include/SpaceDSL/SpCZMLScript.h @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ * Copyright (C) 2018 Niu ZhiYong * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -66,7 +66,7 @@ namespace SpaceDSL { public: - void Initializer(const string &filePath, const Mission *pMission, const double step = 300); + void Initializer(const string &filePath, const Mission *pMission = nullptr, const double step = 300); /********************************************************************/ /// Writing CZML Content For Use With Cesium. @@ -78,6 +78,17 @@ namespace SpaceDSL { /********************************************************************/ void WirteCZML(); + /********************************************************************/ + /// Writing CZML Content For Use With Cesium. + /// @Author xiaogongwei + /// @Date 2018-11-06 + /// @Input data_MJD_POS=[mjd1,x1,y1,z1,mjd2,x2,y2,z2,......] (x1,y1,z1) is position in J2000 coordinate system + /// @Input data_MJD_Vel=[mjd1,v1,v1,v1,mjd2,v2,v2,v2,......] (v1,v1,v1) is speed + /// @vehicl_name this is you defined vehicl name + /// @Return void + /********************************************************************/ + void WirteCZML(vector data_MJD_POS, vector data_MJD_Vel, string vehicl_name = "Vehicl Defualt Name"); + private: string FormTimeStr(int year, int month, int day, int hour, int min, double sec); diff --git a/SpaceDSL/include/SpaceDSL/SpThread.h b/SpaceDSL/include/SpaceDSL/SpThread.h index 86e1dbc..ff92336 100644 --- a/SpaceDSL/include/SpaceDSL/SpThread.h +++ b/SpaceDSL/include/SpaceDSL/SpThread.h @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ * Copyright (C) 2018 Niu ZhiYong * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -189,7 +189,7 @@ namespace SpaceDSL { virtual void Run() = 0; private: - #ifdef WIN32 + #ifdef _WIN32 static unsigned __stdcall ThreadFunc(void* arg); #else static void* ThreadFunc(void* arg); diff --git a/SpaceDSL/include/SpaceDSL/SpaceDSL_Global.h b/SpaceDSL/include/SpaceDSL/SpaceDSL_Global.h index 98c117c..81f6516 100644 --- a/SpaceDSL/include/SpaceDSL/SpaceDSL_Global.h +++ b/SpaceDSL/include/SpaceDSL/SpaceDSL_Global.h @@ -39,17 +39,18 @@ #include -#ifdef SPACEDSL_SHARED_LIBRARY - #define SPACEDSL_API __declspec(dllexport) - #define EXPIMP_TEMPLATE +#ifdef _WIN32 + #ifdef SPACEDSL_SHARED_LIBRARY + #define SPACEDSL_API __declspec(dllexport) + #define EXPIMP_TEMPLATE + #elif SPACEDSL_STATIC_LIBRARY + #define SPACEDSL_API + #define EXPIMP_TEMPLATE + #else + #define SPACEDSL_API __declspec(dllimport) + #define EXPIMP_TEMPLATE extern + #endif #else - #define SPACEDSL_API __declspec(dllimport) - #define EXPIMP_TEMPLATE extern -#endif - - - -#ifdef SPACEDSL_STATIC_LIBRARY #define SPACEDSL_API #define EXPIMP_TEMPLATE #endif diff --git a/SpaceDSL/include/SpaceDSL/spdlog/fmt/bundled/format.h b/SpaceDSL/include/SpaceDSL/spdlog/fmt/bundled/format.h index 9f522f3..a118b5b 100644 --- a/SpaceDSL/include/SpaceDSL/spdlog/fmt/bundled/format.h +++ b/SpaceDSL/include/SpaceDSL/spdlog/fmt/bundled/format.h @@ -3710,6 +3710,7 @@ FMT_END_NAMESPACE # include "format-inl.h" #else # define FMT_FUNC +# include "format.cc" // this line add by xiaogongwei, right or not? #endif // Restore warnings. diff --git a/SpaceDSL/source/SpCZMLScript.cpp b/SpaceDSL/source/SpCZMLScript.cpp index e2b3952..3745447 100644 --- a/SpaceDSL/source/SpCZMLScript.cpp +++ b/SpaceDSL/source/SpCZMLScript.cpp @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ * Copyright (C) 2018 Niu ZhiYong * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -83,6 +83,128 @@ namespace SpaceDSL { m_bIsInitialized = true; } + void CZMLScript::WirteCZML(vector data_MJD_POS, vector data_MJD_Vel, string vehicl_name) + { + if (m_bIsInitialized != true) + throw SPException(__FILE__, __FUNCTION__, __LINE__, "CZMLScript Uninitialized!"); + + int MJD_POS_Len = data_MJD_POS.size(); + int MJD_Vel_Len = data_MJD_Vel.size(); + if(MJD_Vel_Len != MJD_POS_Len) + throw SPException(__FILE__, __FUNCTION__, __LINE__, "length MJD_POS must equal MJD_Vel!"); + if(MJD_POS_Len < 4) + throw SPException(__FILE__, __FUNCTION__, __LINE__, "MJD_POS must great 4!"); + + double initialMJD = data_MJD_POS[0], terminalMJD = data_MJD_POS[MJD_POS_Len-4]; + // get initial and terminal CalendarTime + CalendarTime initialEpoch, terminationEpoch; + MjdToCalendarTime(initialMJD, initialEpoch); + MjdToCalendarTime(terminalMJD, terminationEpoch); + string initialEpochStr = FormTimeStr(initialEpoch.Year(),initialEpoch.Mon(),initialEpoch.Day(), + initialEpoch.Hour(),initialEpoch.Min(),initialEpoch.Sec()); + string intervalEpochStr = FormTimeIntervalStr(initialEpoch.Year(),initialEpoch.Mon(),initialEpoch.Day(), + initialEpoch.Hour(),initialEpoch.Min(),initialEpoch.Sec(), + terminationEpoch.Year(),terminationEpoch.Mon(),terminationEpoch.Day(), + terminationEpoch.Hour(),terminationEpoch.Min(),terminationEpoch.Sec()); + // Head + json *pJhead = new json(); + (*pJhead)["id"] = "document"; + (*pJhead)["name"] = "DataFile"; + (*pJhead)["version"] = "1.0"; + (*pJhead)["clock"]["interval"] = intervalEpochStr; + (*pJhead)["clock"]["currentTime"] = initialEpochStr; + (*pJhead)["clock"]["multiplier"] = 60; + (*pJhead)["clock"]["range"] = "LOOP_STOP"; + (*pJhead)["clock"]["step"] = "SYSTEM_CLOCK_MULTIPLIER"; + m_pJsonList->push_back(*pJhead); + // single Vehicle + int colorStep = int(255/(1+1)); + int vehiclCount = 0; + ++vehiclCount; + int bias = colorStep * vehiclCount; + json *pJvehicl = new json(); + string name = vehicl_name; + + (*pJvehicl)["id"] = "Satellite/" + name; + (*pJvehicl)["name"] = name; + (*pJvehicl)["availability"] = intervalEpochStr; + (*pJvehicl)["description"] = "\r\n

Test Satellite

"; + + (*pJvehicl)["billboard"]["horizontalOrigin"] = "CENTER"; + (*pJvehicl)["billboard"]["verticalOrigin"] = "CENTER"; + (*pJvehicl)["billboard"]["image"] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADJSURBVDhPnZHRDcMgEEMZjVEYpaNklIzSEfLfD4qNnXAJSFWfhO7w2Zc0Tf9QG2rXrEzSUeZLOGm47WoH95x3Hl3jEgilvDgsOQUTqsNl68ezEwn1vae6lceSEEYvvWNT/Rxc4CXQNGadho1NXoJ+9iaqc2xi2xbt23PJCDIB6TQjOC6Bho/sDy3fBQT8PrVhibU7yBFcEPaRxOoeTwbwByCOYf9VGp1BYI1BA+EeHhmfzKbBoJEQwn1yzUZtyspIQUha85MpkNIXB7GizqDEECsAAAAASUVORK5CYII="; + (*pJvehicl)["billboard"]["scale"] = 1; + (*pJvehicl)["billboard"]["show"] = true; + + (*pJvehicl)["label"]["text"] = name; + (*pJvehicl)["label"]["horizontalOrigin"] ="LEFT"; + (*pJvehicl)["label"]["verticalOrigin"] ="CENTER"; + (*pJvehicl)["label"]["fillColor"]["rgba"] = {bias , 255 - bias, 0, 255}; + (*pJvehicl)["label"]["font"] ="11pt Lucida Console"; + (*pJvehicl)["label"]["pixelOffset"]["cartesian2"] = {6, -4}; + (*pJvehicl)["label"]["show"] = true; + + vector showTimePeriodList; + json showTimePeriod; + showTimePeriod["interval"] = intervalEpochStr; + showTimePeriod["boolean"] = true; + showTimePeriodList.push_back(showTimePeriod); + (*pJvehicl)["path"]["show"]= showTimePeriodList; + (*pJvehicl)["path"]["width"] = 1; + (*pJvehicl)["path"]["material"]["solidColor"]["color"]["rgba"] = {bias , 255 - bias, 0, 255}; + (*pJvehicl)["path"]["resolution"] = 120; + + OrbitElem elem; + CartState endState(data_MJD_POS[MJD_POS_Len-3], data_MJD_POS[MJD_POS_Len-2], data_MJD_POS[MJD_POS_Len-1], + data_MJD_Vel[MJD_POS_Len-3], data_MJD_Vel[MJD_POS_Len-2], data_MJD_Vel[MJD_POS_Len-1]);// last pos and speed + CartToOrbitElem (endState, GM_Earth, elem); + double T = 2*PI*sqrt(pow(elem.SMajAx(),3)/GM_Earth); + + vector leadTimeList; + json leadTimePeriod; + leadTimePeriod["interval"] = intervalEpochStr; + leadTimePeriod["epoch"] = initialEpochStr; + leadTimePeriod["number"] = {0, T , T, 0}; + leadTimeList.push_back(leadTimePeriod); + (*pJvehicl)["path"]["leadTime"] = leadTimeList; + + vector trailTimeList; + json trailTimePeriod; + trailTimePeriod["interval"] = intervalEpochStr; + trailTimePeriod["epoch"] = initialEpochStr; + trailTimePeriod["number"] = {T}; + trailTimeList.push_back(trailTimePeriod); + (*pJvehicl)["path"]["trailTime"] = trailTimeList; + + (*pJvehicl)["position"]["interpolationAlgorithm"] = "LAGRANGE"; + (*pJvehicl)["position"]["interpolationDegree"] = 5; + (*pJvehicl)["position"]["referenceFrame"] = "INERTIAL"; + (*pJvehicl)["position"]["epoch"] = initialEpochStr; + // + vector processData; + for (int i = 0;i < data_MJD_POS.size(); i++) + { + if(i%4 == 0) + { + processData.push_back((data_MJD_POS[i] - initialMJD)*DayToSec); + } + else + { + processData.push_back(data_MJD_POS[i]); + + } + } + (*pJvehicl)["position"]["cartesian"] = processData; + + m_pJsonList->push_back(*pJvehicl); + + m_pJsonToWirte = new json(*m_pJsonList); + ofstream o(m_FilePath); + o << setw(4); + o << (*m_pJsonToWirte) << endl; + o.close(); + } + void CZMLScript::WirteCZML() { if (m_bIsInitialized != true) diff --git a/SpaceDSL/source/SpThread.cpp b/SpaceDSL/source/SpThread.cpp index 98af7b9..34ce0be 100644 --- a/SpaceDSL/source/SpThread.cpp +++ b/SpaceDSL/source/SpThread.cpp @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ * Copyright (C) 2018 Niu ZhiYong * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -73,7 +73,7 @@ namespace SpaceDSL { SpThread::~SpThread() { - #ifdef WIN32 + #ifdef _WIN32 if (nullptr != m_Handle) { CloseHandle(m_Handle); @@ -207,7 +207,7 @@ namespace SpaceDSL { void SpThread::Start() { - #ifdef WIN32 + #ifdef _WIN32 m_Handle = (HANDLE)_beginthreadex(nullptr, 0, ThreadFunc, this, 0, nullptr); if (m_Handle == nullptr) { @@ -267,7 +267,7 @@ namespace SpaceDSL { #else pthread_join(m_Thread_t, nullptr); m_Thread_t = 0; - #endif // WIN32 + #endif // _WIN32 } bool SpThread::isRunning() const diff --git a/ctest/CMakeLists.txt b/ctest/CMakeLists.txt index fbc0d5d..e5f43f1 100644 --- a/ctest/CMakeLists.txt +++ b/ctest/CMakeLists.txt @@ -14,9 +14,10 @@ set(CMAKE_CXX_STANDARD 14) # Set Include h file path list(APPEND CTEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/Dependence) -list(APPEND CTEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/SpaceDSL/Include) +list(APPEND CTEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/SpaceDSL/include) +list(APPEND CTEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/SpaceDSL/include/SpaceDSL) # Set Include h file patIh -list(APPEND CTEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/nlopt/src/api) +list(APPEND CTEST_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/NLOpt/src/api) # Set if build With OpenSSL or not if (USE_OPENSSL) @@ -47,18 +48,34 @@ add_executable(ThreadTest TestThread.cpp) add_executable(NLOptTest TestNLOpt.cpp) # UnitTest Set if build SHARED LIBS or not -if (BUILD_SHARED_LIBS) - TARGET_LINK_LIBRARIES(UnitTest SpaceDSL) -else() - TARGET_LINK_LIBRARIES(UnitTest SpaceDSL_static) -endif() +IF (CMAKE_SYSTEM_NAME MATCHES "Windows") + if (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(UnitTest SpaceDSL) + else() + TARGET_LINK_LIBRARIES(UnitTest SpaceDSL_static) + endif() +ELSE() + if (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(UnitTest SpaceDSL pthread) + else() + TARGET_LINK_LIBRARIES(UnitTest SpaceDSL_static pthread) + endif() +ENDIF() # ThreadTest Set if build SHARED LIBS or not -if (BUILD_SHARED_LIBS) - TARGET_LINK_LIBRARIES(ThreadTest SpaceDSL) -else() - TARGET_LINK_LIBRARIES(ThreadTest SpaceDSL_static) -endif() +IF (CMAKE_SYSTEM_NAME MATCHES "Windows") + if (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(ThreadTest SpaceDSL) + else() + TARGET_LINK_LIBRARIES(ThreadTest SpaceDSL_static) + endif() +ELSE() + if (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(ThreadTest SpaceDSL pthread) + else() + TARGET_LINK_LIBRARIES(ThreadTest SpaceDSL_static pthread) + endif() +ENDIF() # NLOptTest Set if build SHARED LIBS or not if (BUILD_SHARED_LIBS) diff --git a/ctest/Example_1.cpp b/ctest/Example_1.cpp new file mode 100644 index 0000000..a34ac2d --- /dev/null +++ b/ctest/Example_1.cpp @@ -0,0 +1,116 @@ +/********************************************************************/ +/// Referring to Niu ZhiYong experiments, this example calls +/// void CZMLScript:: WirteCZML (vector < double > data_MJD_POS, vector < double > data_MJD_Vel, string vehicl_name) +/// @Author xiaogongwei +/// @Date 2018-11-06 +/********************************************************************/ + +#include +#include "SpaceDSL/SpaceDSL.h" + +using namespace std; +using namespace SpaceDSL; + +int main() +{ + cout<<"SpaceDSL test begin!"<GetGravMaxDegree() + 20 ,// m_pEnvironment->GetGravMaxOrder() + thirdGravSign, // m_pEnvironment->GetThirdBodySign() + GeodeticCoordSystem::GeodeticCoordType::E_WGS84System, // m_pEnvironment->GetGeodeticCoordType(), + AtmosphereModel::AtmosphereModelType::E_NRLMSISE00Atmosphere,// m_pEnvironment->GetAtmosphereModelType() + 2.2 , // pVehicle->GetDragCoef() // [1.5~3.0] sphere:2.0 Nonspheroid:2.0~2.3 + 10 ,// pVehicle->GetDragArea() + 150 ,// m_pEnvironment->GetAverageF107() + 150 ,// m_pEnvironment->GetDailyF107() + ap, //m_pEnvironment->GetGeomagneticIndex() + 1.21 ,// pVehicle->GetSRPCoef()// [1.21,1.30,1.88] + 10 ,// pVehicle->GetSRPArea() + true , // m_pEnvironment->GetIsUseDrag() + true // m_pEnvironment->GetIsUseSRP() + ); + + LLA = GEO.GetGeodeticCoord(pos, Mjd_UTC); + // set predict time + double step = 60;// set predict time interval + int predict_epoch = (int)((MJD_end - Mjd_Start)*DayToSec)/step + 1; + + cout.width(30); + cout.precision(15); + cout << " " << endl; + vector data_MJD_POS, data_MJD_Vel;// store MJD and POS + // store current MJD and pos + data_MJD_POS.push_back(Mjd_UTC); + data_MJD_POS.push_back(pos(0)); + data_MJD_POS.push_back(pos(1)); + data_MJD_POS.push_back(pos(2)); + // store current MJD and Vel + data_MJD_Vel.push_back(Mjd_UTC); + data_MJD_Vel.push_back(vel(0)); + data_MJD_Vel.push_back(vel(1)); + data_MJD_Vel.push_back(vel(2)); + + for (int i = 0; i < predict_epoch; ++i) + { + cout << "Mjd_UTC: " << Mjd_UTC << endl; + cout << "Epoch time: " << i*step <