mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2025-12-31 16:30:07 -06:00
* Add sonification module * WIP: Extract planet positions in own thread * WIP Extract camera position and angle * Extract distance to camera and fix angle * WIP: Extract focus node * Optimize and clean up * Fix signed angle for surround sound * WIP add solar system view sonification * Extract time Extract the speed of time in OpenSpace and send it to supercollider. Needed to scale the sonification time in sync with OpenSpace * Extract moon angles Extract the angle from the planet to the major moons. Used in sonification to position the moons in surround. * Add easy change of angles Easier to switch what angle is calculated and sent to the sonification. Preperation for test in Dome * Fix shutdown error and nullptr error Add deinitialize for sonification module. Make sure pointers are initialized to nullptrs at start. Check in sonification main in the start if the scene is initialized * Add properties to contol sonification * Add property to turn on/off sonification for each planet * Change so the data only send for those planets that are enabled with the property * WIP: Improve GUI for sonification control * Add GUI for every sonification parameter per planet * However, only for Earth and Mars so far * Make data send more often and not just when the planet is enabled * Add sonification GUI for Mercury and Venus * GUI for each parameter for Marcury and Venus * Send a shutdown message to SuperCollider during deinitialization * Group properties together * Gather the planets properties under a planets property owner * Prepare to expand GUI * Name changes * Add Solar view in GUI * Add GUI that controls the solar sonification * Remove the all enabled slot in the settings arrays * No longer sends the all enabled slot in teh settings arrays * WIP Compare view * Add compare view in GUI. Allows to compare two planets sonification. * Finish compare view * Add connection to sonification for compare view * Improve responsiveness of GUI * Expand GUI with the outer planets * Add GUI for the outer planets * Increase array sizes to compe with all the planets * Add functionality for the outer planets GUI * Add temperature option in GUI * Fix so that compare cannot compare to itself * Scale selected planets in compare view * Fix reset of compare view * Add Rings sonification to GUI * Fix solar sonification GUI * Bind onChange function for the outer planets in the solar GUI * Add comment about where in the settings array the setting for rings are * Add master buttuns in GUI * Add button to turn on/off all the planets * Add button to turn on/off everything, solar when sun is in focus and planetary otherwise. * Add function to easier turn on/off all the parameters of solar and planetary * Only master start sonification module * Add check that only the master start the sonification thread * Clean up a few lines in the angle calculation * Optimize the sending of time * Time is not sent with every message but only when it changes instead * Add GUI for choosing what parts to compare * More GUI in compare view to control which sonification to compare * Fix deinitialize turn off sounds * Make sure the auto (enable all) now also work with the new compare GUI * Fix socket problem and code clean up * Only use one socket to send information to supercollider * General code clean up * Remove sending of focus node since supercollider does not use it * Adjust to new master * Fix oscpack linker issues * Update to new master * Add start of SonificationEngine * Move osc code into SonificationEngine * Add function for the planetary settings * Add function to access SonificationEngine via the module * Add base sonification class * Start seperating into different sonification classes * Add PlanetarySonification to the internal list * Move osc to its own module * Seperate planet sonifications into seperate sonification classes * Make time sonification its own class * Some clean up * Update to new cmake version * Add proper module dependency for the sonification module * Fix thread issue * Temporary fix with a sleep, works for now * Fix log messages issue * Add enabled property for the sonification module * Some clean up * More clean up * More clean up * Make it possible to send in node position directly for helper function * Add stop function for sonifications * Make possible to specify sonification destination ip and port in cfg file * Use Parameters struct for the sonification module dictionary * Make sonification module a singleton * Minor code style fix * Use module engine module function for singleton pattern instead * Add angle calculations for the surround modes * Use codegen map function for surround mode enum * Improve data storage and sending for planet sonificaitons * Add focus sonification * Fix elevation angle calculation for circular surround mode * Add Lua function to add entries for the PlanetsSonification * Add sonification profile * Add lua library file for planets sonification * Fix gui osc messages sending * Update to latest master * Rename planets sonificaitons to reflect they only work for planets * Add generic nodes sonification * Clean up Time sonification * plus a little in the nodes sonification * Add current time information to the time sonification * Add precision propertysubowner to structure Gui and make it flexible * Some general clean up * Rename solar sonification to planets overview sonification * Add Camera sonification * Fix some bugs with the camera sonificaiton * Make sure the sonificaiton thread is synced with the main thread * Fix camera and scene bug in sonificaiton * Dont hold up the main thread while sonificaiton thread does its work * Use the current frame time for speed calculaiton instead of average * Fix osc::Blob memory bug * Wait max 30 seconds in the sonification thread for the main thread * Make sure deinitialize of sonificaiton thread does not halt * Add the mode sonification as a proper sonification * Add nodes sonification example with ISS and Tiangong * Some renaming and restructuring * Add more detailed documentation for the sonification math * The util functions for different angles in the sonificaiton/telemetry module * Major clean up and restructuring * Rename module to telemetry to make it more clear that we do not produce the sonifications, we just spit out data used by a sonificaiton software * Add the new moon of Neptune to sonification and add sonification files * And add the test osc supercollider file * Add the OpenSpace header to the supercollider example file * Apply suggestions from code review Co-authored-by: Alexander Bock <alexander.bock@liu.se> * Adjust suggestions to fix errors * Address more PR comments * Address more PR comments * More PR comments * More PR comments * More PR comments * Even more PR comments * Update to latest master * More PR comments * Add OSC as a submodule * NOTE that due to path issues this commit will not build with the osc module, you will need to change the paths inside two osc files for it to build. Will fix very soon * Fix issue with oscpack not setting correct include directory * Address PR comments * Address PR comments * Update the SuperCollider files --------- Co-authored-by: Alexander Bock <alexander.bock@liu.se> Co-authored-by: Ivar Gorenko <ivago071@student.liu.se>
320 lines
12 KiB
C++
320 lines
12 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2025 *
|
|
* *
|
|
* 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 <modules/telemetry/telemetrymodule.h>
|
|
|
|
#include <modules/telemetry/include/general/anglemodetelemetry.h>
|
|
#include <modules/telemetry/include/general/cameratelemetry.h>
|
|
#include <modules/telemetry/include/general/focustelemetry.h>
|
|
#include <modules/telemetry/include/general/nodestelemetry.h>
|
|
#include <modules/telemetry/include/general/timetelemetry.h>
|
|
#include <modules/telemetry/include/specific/planetscomparesonification.h>
|
|
#include <modules/telemetry/include/specific/planetsoverviewsonification.h>
|
|
#include <modules/telemetry/include/specific/planetssonification.h>
|
|
#include <openspace/camera/camera.h>
|
|
#include <openspace/documentation/documentation.h>
|
|
#include <openspace/engine/globals.h>
|
|
#include <openspace/engine/globalscallbacks.h>
|
|
#include <openspace/engine/windowdelegate.h>
|
|
#include <openspace/rendering/renderengine.h>
|
|
#include <openspace/scene/scene.h>
|
|
#include <openspace/scripting/lualibrary.h>
|
|
#include <ghoul/logging/logmanager.h>
|
|
|
|
namespace {
|
|
constexpr std::string_view _loggerCat = "TelemetryModule";
|
|
|
|
// The default Open Sound Control receiver is SuperCollider with these default values.
|
|
// However, the user can define any receiver in the openspace.cfg file as the
|
|
// ModuleConfiguration for the Telemetry module.
|
|
constexpr std::string_view DefaultSuperColliderIp = "127.0.0.1";
|
|
constexpr int DefaultSuperColliderPort = 57120;
|
|
|
|
constexpr openspace::properties::Property::PropertyInfo EnabledInfo = {
|
|
"Enabled",
|
|
"Enabled",
|
|
"Enable or disable all gathering of telemetry information.",
|
|
openspace::properties::Property::Visibility::User
|
|
};
|
|
|
|
constexpr openspace::properties::Property::PropertyInfo IpAddressInfo = {
|
|
"IpAddress",
|
|
"IP Address",
|
|
"The network IP address that the telemetry Open Sound Control messages is sent "
|
|
"to.",
|
|
openspace::properties::Property::Visibility::User
|
|
};
|
|
|
|
constexpr openspace::properties::Property::PropertyInfo PortInfo = {
|
|
"Port",
|
|
"Port",
|
|
"The network port that the telemetry Open Sound Control messages are sent to.",
|
|
openspace::properties::Property::Visibility::User
|
|
};
|
|
|
|
constexpr openspace::properties::Property::PropertyInfo AngleCalculationModeInfo = {
|
|
"AngleCalculationMode",
|
|
"Angle Calculation Mode",
|
|
"This setting changes the method used to calculate any angles in the "
|
|
"telemetries. The Horizontal mode, generally works well for flat displays or "
|
|
"forward facing immersive environments. The Circular mode, generally works well "
|
|
"for centered fisheye displays or omnidirectional immersive environments. For "
|
|
"more information, see the pages \"Angle Calculations\" and \"Surround Sound "
|
|
"Configurations\"on the OpenSpace documentation page.",
|
|
openspace::properties::Property::Visibility::User
|
|
};
|
|
|
|
constexpr openspace::properties::Property::PropertyInfo IncludeElevationAngleInfo = {
|
|
"IncludeElevationAngle",
|
|
"Include Elevation Angle",
|
|
"This setting determines if an additional elevation angle should be calculated "
|
|
"for the telemetries that calculate angles. This angle determines where the "
|
|
"object is placed within a vertical plane of reference in relation to the "
|
|
"camera, i.e the height in relation to the horizontal plane of reference. The "
|
|
"method used for this calculation also depends on the angle calculation mode. "
|
|
"For more information, see the page \"Angle Calculations\" on the OpenSpace "
|
|
"documentation page.",
|
|
openspace::properties::Property::Visibility::User
|
|
};
|
|
|
|
struct [[codegen::Dictionary(TelemetryModule)]] Parameters {
|
|
// [[codegen::verbatim(IpAddressInfo.description)]]
|
|
std::optional<std::string> ipAddress;
|
|
|
|
// [[codegen::verbatim(PortInfo.description)]]
|
|
std::optional<int> port;
|
|
|
|
enum class
|
|
[[codegen::map(openspace::TelemetryModule::AngleCalculationMode)]]
|
|
AngleCalculationMode {
|
|
Horizontal,
|
|
Circular
|
|
};
|
|
|
|
// [[codegen::verbatim(AngleCalculationModeInfo.description)]]
|
|
std::optional<AngleCalculationMode> angleCalculationMode;
|
|
|
|
// [[codegen::verbatim(IncludeElevationAngleInfo.description)]]
|
|
std::optional<bool> includeElevationAngle;
|
|
};
|
|
#include "telemetrymodule_codegen.cpp"
|
|
} // namespace
|
|
|
|
namespace openspace {
|
|
|
|
TelemetryModule::TelemetryModule()
|
|
: OpenSpaceModule("Telemetry")
|
|
, _enabled(EnabledInfo, false)
|
|
, _ipAddress(IpAddressInfo, DefaultSuperColliderIp.data())
|
|
, _port(PortInfo, DefaultSuperColliderPort, 1025, 65536)
|
|
, _modeOptions(AngleCalculationModeInfo)
|
|
, _includeElevationAngle(IncludeElevationAngleInfo, false)
|
|
{
|
|
addProperty(_enabled);
|
|
|
|
_ipAddress.setReadOnly(true);
|
|
addProperty(_ipAddress);
|
|
|
|
_port.setReadOnly(true);
|
|
addProperty(_port);
|
|
|
|
// Add options to the drop down menu
|
|
_modeOptions.addOptions({
|
|
{ 0, "Horizontal" },
|
|
{ 1, "Circular" }
|
|
});
|
|
_modeOptions.onChange([this]() { guiOnChangeAngleCalculationMode(); });
|
|
|
|
// Select Horizontal angle calculation mode as the default
|
|
_modeOptions.setValue(static_cast<int>(AngleCalculationMode::Horizontal));
|
|
addProperty(_modeOptions);
|
|
|
|
addProperty(_includeElevationAngle);
|
|
}
|
|
|
|
TelemetryModule::~TelemetryModule() {
|
|
// Clear the telemetries list
|
|
for (TelemetryBase* telemetry : _telemetries) {
|
|
delete telemetry;
|
|
}
|
|
}
|
|
|
|
void TelemetryModule::guiOnChangeAngleCalculationMode() {
|
|
_angleCalculationMode = static_cast<AngleCalculationMode>(_modeOptions.value());
|
|
}
|
|
|
|
void TelemetryModule::internalInitialize(const ghoul::Dictionary& dictionary) {
|
|
const Parameters p = codegen::bake<Parameters>(dictionary);
|
|
|
|
_ipAddress = p.ipAddress.value_or(_ipAddress);
|
|
_port = p.port.value_or(_port);
|
|
|
|
if (p.angleCalculationMode.has_value()) {
|
|
Parameters::AngleCalculationMode mode =
|
|
Parameters::AngleCalculationMode(*p.angleCalculationMode);
|
|
_angleCalculationMode = codegen::map<AngleCalculationMode>(mode);
|
|
}
|
|
|
|
// Fill telemetry list
|
|
TelemetryBase* telemetry = new AngleModeTelemetry(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new CameraTelemetry(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new FocusTelemetry(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new TimeTelemetry(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new NodesTelemetry(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new PlanetsCompareSonification(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new PlanetsOverviewSonification(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
telemetry = new PlanetsSonification(_ipAddress, _port);
|
|
addTelemetry(telemetry);
|
|
|
|
// Only the master runs the TelemetryModule update thread
|
|
if (global::windowDelegate->isMaster()) {
|
|
_isRunning = true;
|
|
_updateThread = std::thread([this]() { update(std::ref(_isRunning)); });
|
|
|
|
// Make sure the telemetry thread is synced with the main thread
|
|
global::callback::postSyncPreDraw->emplace_back([this]() {
|
|
// Tell the telemetry thread that a new frame is starting
|
|
syncToMain.notify_one();
|
|
});
|
|
|
|
// When the program shuts down, make sure this module turns itself off.
|
|
// If the module is turned on while the scene is being destroyed, then it will crash.
|
|
global::callback::deinitialize->emplace_back([this]() {
|
|
_enabled = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
void TelemetryModule::addTelemetry(TelemetryBase* telemetry) {
|
|
_telemetries.push_back(telemetry);
|
|
addPropertySubOwner(telemetry);
|
|
}
|
|
|
|
void TelemetryModule::internalDeinitialize() {
|
|
// Stop the loop and tell the thread it is ok to run the last itteration
|
|
_isRunning = false;
|
|
syncToMain.notify_one();
|
|
|
|
_updateThread.join();
|
|
}
|
|
|
|
const std::vector<TelemetryBase*>& TelemetryModule::telemetries() const {
|
|
return _telemetries;
|
|
}
|
|
|
|
const TelemetryBase* TelemetryModule::telemetry(const std::string_view& id) const {
|
|
for (const TelemetryBase* t : _telemetries) {
|
|
if (t->identifier() == id) {
|
|
return t;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
TelemetryBase* TelemetryModule::telemetry(const std::string_view& id) {
|
|
for (TelemetryBase* t : _telemetries) {
|
|
if (t->identifier() == id) {
|
|
return t;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
TelemetryModule::AngleCalculationMode TelemetryModule::angleCalculationMode() const {
|
|
return _angleCalculationMode;
|
|
}
|
|
|
|
bool TelemetryModule::includeElevationAngle() const {
|
|
return _includeElevationAngle;
|
|
}
|
|
|
|
void TelemetryModule::update(std::atomic<bool>& isRunning) {
|
|
Scene* scene = nullptr;
|
|
Camera* camera = nullptr;
|
|
bool isInitialized = false;
|
|
|
|
while (isRunning) {
|
|
// Wait for the main thread
|
|
std::unique_lock<std::mutex> lk(mutexLock);
|
|
syncToMain.wait(lk);
|
|
|
|
// No need to update if the module isn't currently enabled
|
|
if (!_enabled) {
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
continue;
|
|
}
|
|
|
|
// Initialize the scena and camera information if that has not already been done
|
|
if (!isInitialized) {
|
|
// Find the scene
|
|
if (!scene) {
|
|
scene = global::renderEngine->scene();
|
|
}
|
|
|
|
// Find the camera in the scene
|
|
if (!camera) {
|
|
camera = scene ? scene->camera() : nullptr;
|
|
}
|
|
|
|
// Check status
|
|
isInitialized = scene && !scene->isInitializing() &&
|
|
!scene->root()->children().empty() && camera &&
|
|
glm::length(camera->positionVec3()) >
|
|
std::numeric_limits<double>::epsilon();
|
|
}
|
|
|
|
// Process the telemetries
|
|
if (isInitialized) {
|
|
for (TelemetryBase* telemetry : _telemetries) {
|
|
if (telemetry) {
|
|
telemetry->update(camera);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::vector<scripting::LuaLibrary> TelemetryModule::luaLibraries() const {
|
|
return {
|
|
NodesTelemetry::luaLibrary(),
|
|
PlanetsSonification::luaLibrary()
|
|
};
|
|
}
|
|
|
|
} // namespace openspace
|