diff --git a/modules/iswa/rendering/iswabasegroup.h b/modules/iswa/rendering/iswabasegroup.h index b69e75f3e9..5df21788db 100644 --- a/modules/iswa/rendering/iswabasegroup.h +++ b/modules/iswa/rendering/iswabasegroup.h @@ -42,29 +42,29 @@ class IswaCygnet; class IswaBaseGroup : public properties::PropertyOwner{ public: - IswaBaseGroup(std::string name, std::string type); - ~IswaBaseGroup(); - bool isType(std::string type); + IswaBaseGroup(std::string name, std::string type); + ~IswaBaseGroup(); + bool isType(std::string type); - void updateGroup(); - virtual void clearGroup(); + void updateGroup(); + virtual void clearGroup(); - std::shared_ptr dataProcessor(); - std::shared_ptr > groupEvent(); + std::shared_ptr dataProcessor(); + std::shared_ptr > groupEvent(); protected: - void registerProperties(); - void unregisterProperties(); + void registerProperties(); + void unregisterProperties(); - properties::BoolProperty _enabled; - properties::FloatProperty _alpha; + properties::BoolProperty _enabled; + properties::FloatProperty _alpha; properties::TriggerProperty _delete; - std::shared_ptr > _groupEvent; + std::shared_ptr > _groupEvent; std::shared_ptr _dataProcessor; - bool _registered; - std::string _type; + bool _registered; + std::string _type; }; } //namespace openspace diff --git a/modules/iswa/rendering/iswagroup.h b/modules/iswa/rendering/iswagroup.h index b69e75f3e9..5df21788db 100644 --- a/modules/iswa/rendering/iswagroup.h +++ b/modules/iswa/rendering/iswagroup.h @@ -42,29 +42,29 @@ class IswaCygnet; class IswaBaseGroup : public properties::PropertyOwner{ public: - IswaBaseGroup(std::string name, std::string type); - ~IswaBaseGroup(); - bool isType(std::string type); + IswaBaseGroup(std::string name, std::string type); + ~IswaBaseGroup(); + bool isType(std::string type); - void updateGroup(); - virtual void clearGroup(); + void updateGroup(); + virtual void clearGroup(); - std::shared_ptr dataProcessor(); - std::shared_ptr > groupEvent(); + std::shared_ptr dataProcessor(); + std::shared_ptr > groupEvent(); protected: - void registerProperties(); - void unregisterProperties(); + void registerProperties(); + void unregisterProperties(); - properties::BoolProperty _enabled; - properties::FloatProperty _alpha; + properties::BoolProperty _enabled; + properties::FloatProperty _alpha; properties::TriggerProperty _delete; - std::shared_ptr > _groupEvent; + std::shared_ptr > _groupEvent; std::shared_ptr _dataProcessor; - bool _registered; - std::string _type; + bool _registered; + std::string _type; }; } //namespace openspace diff --git a/modules/onscreengui/include/guihelpcomponent.h b/modules/onscreengui/include/guihelpcomponent.h index dcaf9284d8..8f6e82e2c0 100644 --- a/modules/onscreengui/include/guihelpcomponent.h +++ b/modules/onscreengui/include/guihelpcomponent.h @@ -32,7 +32,7 @@ namespace gui { class GuiHelpComponent : public GuiComponent { public: - void render(); + void render() override; }; } // namespace gui diff --git a/modules/onscreengui/include/guiiswacomponent.h b/modules/onscreengui/include/guiiswacomponent.h index 42d5771132..a6d831f788 100644 --- a/modules/onscreengui/include/guiiswacomponent.h +++ b/modules/onscreengui/include/guiiswacomponent.h @@ -32,21 +32,15 @@ namespace openspace { namespace gui { -struct RadioOption { - int value; - std::string path; - std::string date; -}; - class GuiIswaComponent : public GuiPropertyComponent { public: GuiIswaComponent(); void render() override; private: - bool _gmdata; - bool _gmimage; - bool _iondata; + bool _gmData; + bool _gmImage; + bool _ionData; std::vector _cdfOptions; std::map _cdfOptionsMap; diff --git a/modules/onscreengui/include/guiorigincomponent.h b/modules/onscreengui/include/guiorigincomponent.h index d3507acaf4..8598b784e4 100644 --- a/modules/onscreengui/include/guiorigincomponent.h +++ b/modules/onscreengui/include/guiorigincomponent.h @@ -28,7 +28,6 @@ #include namespace openspace { - namespace gui { class GuiOriginComponent : public GuiComponent { @@ -36,61 +35,6 @@ public: void render() override; }; -// -//class GuiPropertyComponent : public GuiComponent { -//public: -// //void registerProperty(const std::string& propertyDescription); -// void registerProperty(properties::Property* prop); -// void render(); -// -//protected: -// enum class PropertyType { -// BoolProperty = 0, -// IntProperty, -// FloatProperty, -// Vec2Property, -// Vec3Property, -// StringProperty, -// OptionProperty, -// SelectionProperty, -// TriggerProperty, -// InvalidPropertyType -// }; -// -// struct PropertyInfo { -// PropertyType type; -// std::string identifier; -// std::string name; -// std::string group; -// }; -// typedef std::string PropertyOwner; -// -// struct Property { -// PropertyOwner owner; -// std::vector properties; -// }; -// -// void handleProperty(const ghoul::Dictionary& value); -// -// PropertyType toPropertyType(const std::string& name) const; -// -// void renderProperty(const PropertyInfo& info) const; -// -// std::set _boolProperties; -// std::set _intProperties; -// std::set _floatProperties; -// std::set _vec2Properties; -// std::set _vec3Properties; -// std::set _vec4Properties; -// std::set _stringProperties; -// std::set _optionProperties; -// std::set _selectionProperties; -// std::set _triggerProperties; -// std::map> _propertiesByOwner; -// -// //std::vector _properties; -//}; - } // namespace gui } // namespace openspace diff --git a/modules/onscreengui/include/guiperformancecomponent.h b/modules/onscreengui/include/guiperformancecomponent.h index 882c277fe4..f5beabd38a 100644 --- a/modules/onscreengui/include/guiperformancecomponent.h +++ b/modules/onscreengui/include/guiperformancecomponent.h @@ -27,6 +27,8 @@ #include +#include + namespace ghoul { class SharedMemory; } @@ -36,17 +38,14 @@ namespace gui { class GuiPerformanceComponent : public GuiComponent { public: - void initialize(); - void deinitialize(); - - void render(); + void render() override; protected: - ghoul::SharedMemory* _performanceMemory = nullptr; - int _sortingSelection; + std::unique_ptr _performanceMemory; + int _sortingSelection = -1; - bool _sceneGraphIsEnabled; - bool _functionsIsEnabled; + bool _sceneGraphIsEnabled = false; + bool _functionsIsEnabled = false; }; } // namespace gui diff --git a/modules/onscreengui/include/guitimecomponent.h b/modules/onscreengui/include/guitimecomponent.h index 4d6f5d1f4e..dcdb9f78ab 100644 --- a/modules/onscreengui/include/guitimecomponent.h +++ b/modules/onscreengui/include/guitimecomponent.h @@ -28,7 +28,6 @@ #include namespace openspace { - namespace gui { class GuiTimeComponent : public GuiComponent { @@ -36,61 +35,6 @@ public: void render() override; }; -// -//class GuiPropertyComponent : public GuiComponent { -//public: -// //void registerProperty(const std::string& propertyDescription); -// void registerProperty(properties::Property* prop); -// void render(); -// -//protected: -// enum class PropertyType { -// BoolProperty = 0, -// IntProperty, -// FloatProperty, -// Vec2Property, -// Vec3Property, -// StringProperty, -// OptionProperty, -// SelectionProperty, -// TriggerProperty, -// InvalidPropertyType -// }; -// -// struct PropertyInfo { -// PropertyType type; -// std::string identifier; -// std::string name; -// std::string group; -// }; -// typedef std::string PropertyOwner; -// -// struct Property { -// PropertyOwner owner; -// std::vector properties; -// }; -// -// void handleProperty(const ghoul::Dictionary& value); -// -// PropertyType toPropertyType(const std::string& name) const; -// -// void renderProperty(const PropertyInfo& info) const; -// -// std::set _boolProperties; -// std::set _intProperties; -// std::set _floatProperties; -// std::set _vec2Properties; -// std::set _vec3Properties; -// std::set _vec4Properties; -// std::set _stringProperties; -// std::set _optionProperties; -// std::set _selectionProperties; -// std::set _triggerProperties; -// std::map> _propertiesByOwner; -// -// //std::vector _properties; -//}; - } // namespace gui } // namespace openspace diff --git a/modules/onscreengui/include/renderproperties.h b/modules/onscreengui/include/renderproperties.h index 8625240265..d54087bb95 100644 --- a/modules/onscreengui/include/renderproperties.h +++ b/modules/onscreengui/include/renderproperties.h @@ -45,6 +45,6 @@ void renderVec3Property(properties::Property* prop, const std::string& ownerName void renderVec4Property(properties::Property* prop, const std::string& ownerName); void renderTriggerProperty(properties::Property* prop, const std::string& ownerName); -} // namespace +} // namespace openspace #endif __RENDERPROPERTIES_H__ diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index aec4488bff..480d689dc9 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -47,9 +47,6 @@ const std::string GuiFont = "${FONTS}/Roboto/Roboto-Regular.ttf"; const ImVec2 size = ImVec2(350, 500); //GLuint fontTex = 0; -GLint positionLocation = 0; -GLint uvLocation = 0; -GLint colorLocation = 0; // A VBO max size of 0 will cause a lazy instantiation of the buffer size_t vboMaxSize = 0; GLuint vao = 0; @@ -271,17 +268,13 @@ void GUI::initializeGL() { if (!_program) return; - positionLocation = glGetAttribLocation(*_program, "in_position"); - uvLocation = glGetAttribLocation(*_program, "in_uv"); - colorLocation = glGetAttribLocation(*_program, "in_color"); - - unsigned char* png_data; - int tex_x, tex_y; - ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&png_data, &tex_x, &tex_y); + unsigned char* pngData; + glm::ivec2 textureSize; + ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pngData, &textureSize.x, &textureSize.y); _fontTexture = std::make_unique( - png_data, - glm::uvec3(tex_x, tex_y, 1) + pngData, + glm::uvec3(textureSize.x, textureSize.y, 1) ); _fontTexture->setName("Gui Text"); _fontTexture->setDataOwnership(ghoul::opengl::Texture::TakeOwnership::No); @@ -291,16 +284,15 @@ void GUI::initializeGL() { glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, vboMaxSize, NULL, GL_DYNAMIC_DRAW); - glGenVertexArrays(1, &vao); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); - glEnableVertexAttribArray(positionLocation); - glEnableVertexAttribArray(uvLocation); - glEnableVertexAttribArray(colorLocation); + glEnableVertexAttribArray(_program->attributeLocation("in_position")); + glEnableVertexAttribArray(_program->attributeLocation("in_uv")); + glEnableVertexAttribArray(_program->attributeLocation("in_color")); glVertexAttribPointer( - positionLocation, + _program->attributeLocation("in_position"), 2, GL_FLOAT, GL_FALSE, @@ -308,7 +300,7 @@ void GUI::initializeGL() { reinterpret_cast(offsetof(ImDrawVert, pos)) ); glVertexAttribPointer( - uvLocation, + _program->attributeLocation("in_uv"), 2, GL_FLOAT, GL_FALSE, @@ -316,7 +308,7 @@ void GUI::initializeGL() { reinterpret_cast(offsetof(ImDrawVert, uv)) ); glVertexAttribPointer( - colorLocation, + _program->attributeLocation("in_color"), 4, GL_UNSIGNED_BYTE, GL_TRUE, @@ -336,6 +328,7 @@ void GUI::initializeGL() { void GUI::deinitializeGL() { _program = nullptr; + _fontTexture = nullptr; glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); @@ -480,7 +473,7 @@ void GUI::render() { static char addImageBuffer[addImageBufferSize]; ImGui::InputText("addImage", addImageBuffer, addImageBufferSize); - if (ImGui::SmallButton("Add Image")){ + if (ImGui::SmallButton("Add Image")) { addScreenSpaceRenderable(std::string(addImageBuffer)); } diff --git a/modules/onscreengui/src/guihelpcomponent.cpp b/modules/onscreengui/src/guihelpcomponent.cpp index 4530891a18..c38e2ebe38 100644 --- a/modules/onscreengui/src/guihelpcomponent.cpp +++ b/modules/onscreengui/src/guihelpcomponent.cpp @@ -39,5 +39,5 @@ void GuiHelpComponent::render() { ImGui::End(); } -} // gui -} // openspace +} // namespace gui +} // namespace openspace diff --git a/modules/onscreengui/src/guiiswacomponent.cpp b/modules/onscreengui/src/guiiswacomponent.cpp index 7b9e4ac3bb..e09a294a85 100644 --- a/modules/onscreengui/src/guiiswacomponent.cpp +++ b/modules/onscreengui/src/guiiswacomponent.cpp @@ -23,29 +23,16 @@ ****************************************************************************************/ #include -#include +#include + +#include #include -#include #include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include #include - -#include +#include #include "imgui.h" @@ -57,86 +44,96 @@ namespace { namespace openspace { namespace gui { + GuiIswaComponent::GuiIswaComponent() : GuiPropertyComponent("iSWA") - , _gmdata(false) - , _gmimage(false) - , _iondata(false) + , _gmData(false) + , _gmImage(false) + , _ionData(false) {} void GuiIswaComponent::render() { - bool gmdatavalue = _gmdata; - bool gmimagevalue = _gmimage; - bool iondatavalue = _iondata; +#ifdef OPENSPACE_MODULE_ISWA_ENABLED + bool oldGmDataValue = _gmData; + bool oldGmImageValue = _gmImage; + bool oldIonDataValue = _ionData; ImGui::Begin("ISWA", &_isEnabled, size, 0.5f); + ImGui::Text("Global Magnetosphere"); - ImGui::Checkbox("Gm From Data", &_gmdata); ImGui::SameLine(); - ImGui::Checkbox("Gm From Images", &_gmimage); + ImGui::Checkbox("Gm From Data", &_gmData); ImGui::SameLine(); + ImGui::Checkbox("Gm From Images", &_gmImage); ImGui::Text("Ionosphere"); - ImGui::Checkbox("Ion From Data", &_iondata); - + ImGui::Checkbox("Ion From Data", &_ionData); ImGui::Spacing(); static const int addCygnetBufferSize = 256; static char addCygnetBuffer[addCygnetBufferSize]; ImGui::InputText("addCynget", addCygnetBuffer, addCygnetBufferSize); - if(ImGui::SmallButton("Add Cygnet")) - OsEng.scriptEngine().queueScript("openspace.iswa.addCygnet("+std::string(addCygnetBuffer)+");"); + if (ImGui::SmallButton("Add Cygnet")) { + OsEng.scriptEngine().queueScript( + "openspace.iswa.addCygnet(" + std::string(addCygnetBuffer) + ");" + ); + } - if(_gmdata != gmdatavalue){ - if(_gmdata){ - std::string x = "openspace.iswa.addCygnet(-4,'Data','GMData');"; - std::string y = "openspace.iswa.addCygnet(-5,'Data','GMData');"; - std::string z = "openspace.iswa.addCygnet(-6,'Data','GMData');"; - OsEng.scriptEngine().queueScript(x+y+z); - }else{ + if (_gmData != oldGmDataValue) { + if (_gmData) { + std::string x = "openspace.iswa.addCygnet(-4, 'Data', 'GMData');"; + std::string y = "openspace.iswa.addCygnet(-5, 'Data', 'GMData');"; + std::string z = "openspace.iswa.addCygnet(-6, 'Data', 'GMData');"; + OsEng.scriptEngine().queueScript(x + y + z); + } else { OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('GMData');"); } } - if(_gmimage != gmimagevalue){ - if(_gmimage){ - std::string x = "openspace.iswa.addCygnet(-4,'Texture','GMImage');"; - std::string y = "openspace.iswa.addCygnet(-5,'Texture','GMImage');"; - std::string z = "openspace.iswa.addCygnet(-6,'Texture','GMImage');"; - OsEng.scriptEngine().queueScript(x+y+z); - }else{ + if (_gmImage != oldGmImageValue) { + if (_gmImage) { + std::string x = "openspace.iswa.addCygnet(-4, 'Texture', 'GMImage');"; + std::string y = "openspace.iswa.addCygnet(-5, 'Texture', 'GMImage');"; + std::string z = "openspace.iswa.addCygnet(-6, 'Texture', 'GMImage');"; + OsEng.scriptEngine().queueScript(x + y + z); + } else { OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('GMImage');"); } } - if(_iondata != iondatavalue){ - if(_iondata){ - OsEng.scriptEngine().queueScript("openspace.iswa.addCygnet(-10,'Data','Ionosphere');"); - }else{ + if(_ionData != oldIonDataValue) { + if(_ionData) { + OsEng.scriptEngine().queueScript( + "openspace.iswa.addCygnet(-10,'Data','Ionosphere');" + ); + } else { OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('Ionosphere');"); } } -#ifdef OPENSPACE_MODULE_ISWA_ENABLED - if(ImGui::CollapsingHeader("Cdf files")){ - auto cdfInfo = IswaManager::ref().cdfInformation(); + if (ImGui::CollapsingHeader("Cdf files")) { + const auto& cdfInfo = IswaManager::ref().cdfInformation(); - for(auto group : cdfInfo){ + for (const auto& group : cdfInfo) { std::string groupName = group.first; - if(_cdfOptionsMap.find(groupName) == _cdfOptionsMap.end()){ + if (_cdfOptionsMap.find(groupName) == _cdfOptionsMap.end()){ _cdfOptionsMap[groupName] = -1; } - if(ImGui::CollapsingHeader(groupName.c_str())){ + if (ImGui::CollapsingHeader(groupName.c_str())) { int cdfOptionValue = _cdfOptionsMap[groupName]; - auto cdfs = group.second; + const auto& cdfs = group.second; - for(int i=0; i= 0){ + if (cdfOptionValue != cdfOption) { + if (cdfOptionValue >= 0) { groupName = cdfs[cdfOptionValue].group; // std::cout << groupName << std::endl; // OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('"+groupName+"');"); @@ -145,24 +142,29 @@ void GuiIswaComponent::render() { std::string path = cdfs[cdfOption].path; std::string date = cdfs[cdfOption].date; groupName = cdfs[cdfOption].group; - OsEng.scriptEngine().queueScript("openspace.iswa.addKameleonPlanes('"+groupName+"',"+std::to_string(cdfOption)+");"); - OsEng.scriptEngine().queueScript("openspace.time.setTime('"+date+"');"); - OsEng.scriptEngine().queueScript("openspace.time.setDeltaTime(0);"); + OsEng.scriptEngine().queueScript( + "openspace.iswa.addKameleonPlanes('" + + groupName + + "'," + + std::to_string(cdfOption) + + ");" + ); + OsEng.scriptEngine().queueScript( + "openspace.time.setTime('" + date + "');" + ); + OsEng.scriptEngine().queueScript( + "openspace.time.setDeltaTime(0);" + ); } } } } -#endif GuiPropertyComponent::render(); - - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED if (ImGui::CollapsingHeader("iSWA screen space cygntes")) { - - auto map = IswaManager::ref().cygnetInformation(); - for(auto cygnetInfo : map){ + const auto& map = IswaManager::ref().cygnetInformation(); + for (const auto& cygnetInfo : map) { int id = cygnetInfo.first; auto info = cygnetInfo.second; @@ -170,27 +172,31 @@ void GuiIswaComponent::render() { ImGui::Checkbox(info->name.c_str(), &info->selected); ImGui::SameLine(); - if(ImGui::CollapsingHeader(("Description" + std::to_string(id)).c_str())){ + if (ImGui::CollapsingHeader(("Description" + std::to_string(id)).c_str())) { ImGui::TextWrapped(info->description.c_str()); ImGui::Spacing(); } - if(selected != info->selected){ - if(info->selected){ - OsEng.scriptEngine().queueScript("openspace.iswa.addScreenSpaceCygnet(" - "{CygnetId = "+std::to_string(id)+" });"); - }else{ - OsEng.scriptEngine().queueScript("openspace.iswa.removeScreenSpaceCygnet("+std::to_string(id)+");"); - + if (selected != info->selected) { + if (info->selected) { + OsEng.scriptEngine().queueScript( + "openspace.iswa.addScreenSpaceCygnet(" + "{CygnetId = " + std::to_string(id) + " });" + ); + } else { + OsEng.scriptEngine().queueScript( + "openspace.iswa.removeScreenSpaceCygnet(" + + std::to_string(id) + + ");" + ); } } - } } -#endif ImGui::End(); +#endif } -} // gui -} // openspace \ No newline at end of file +} // namespace gui +} // namespace openspace diff --git a/modules/onscreengui/src/guiorigincomponent.cpp b/modules/onscreengui/src/guiorigincomponent.cpp index 9a0f72564a..07bf244161 100644 --- a/modules/onscreengui/src/guiorigincomponent.cpp +++ b/modules/onscreengui/src/guiorigincomponent.cpp @@ -25,10 +25,12 @@ #include #include +#include #include #include -#include + #include + #include "imgui.h" namespace { @@ -39,144 +41,34 @@ namespace openspace { namespace gui { void GuiOriginComponent::render() { - const SceneGraphNode* currentFocus = OsEng.interactionHandler().focusNode(); + SceneGraphNode* currentFocus = OsEng.interactionHandler().focusNode(); - std::vector nodes = OsEng.renderEngine().scene()->allSceneGraphNodes(); - std::sort(nodes.begin(), nodes.end(), [](SceneGraphNode* lhs, SceneGraphNode* rhs) { return lhs->name() < rhs->name(); }); - auto it = std::find(nodes.begin(), nodes.end(), currentFocus); - ghoul_assert(it != nodes.end(), "Focus node not found"); + std::vector nodes = + OsEng.renderEngine().scene()->allSceneGraphNodes(); + std::sort( + nodes.begin(), + nodes.end(), + [](SceneGraphNode* lhs, SceneGraphNode* rhs) { + return lhs->name() < rhs->name(); + } + ); std::string nodeNames = ""; for (SceneGraphNode* n : nodes) nodeNames += n->name() + '\0'; + auto iCurrentFocus = std::find(nodes.begin(), nodes.end(), currentFocus); + ghoul_assert(iCurrentFocus != nodes.end(), "Focus node not found"); + int currentPosition = static_cast(std::distance(iCurrentFocus, nodes.begin())); - int position = static_cast(std::distance(it, nodes.begin())); - - bool result = ImGui::Combo("Origin", &position, nodeNames.c_str()); - - if (result) { - LINFO("openspace.setPropertyValue('Interaction.origin', '" + nodes[position]->name() + "');"); - OsEng.scriptEngine().queueScript("openspace.setPropertyValue('Interaction.origin', '" + nodes[position]->name() + "');"); + bool hasChanged = ImGui::Combo("Origin", ¤tPosition, nodeNames.c_str()); + if (hasChanged) { + OsEng.scriptEngine().queueScript( + "openspace.setPropertyValue('Interaction.origin', '" + + nodes[currentPosition]->name() + "');" + ); } - } } // gui } // openspace - - - // ImGui::Begin("Properties", &_isEnabled, size, 0.5f); - - - // //ImGui::ShowUserGuide(); - // ImGui::Spacing(); - - // for (const auto& p : _propertiesByOwner) { - // if (ImGui::CollapsingHeader(p.first.c_str())) { - // for (properties::Property* prop : p.second) { - // if (_boolProperties.find(prop) != _boolProperties.end()) { - // renderBoolProperty(prop, p.first); - // continue; - // } - - // if (_intProperties.find(prop) != _intProperties.end()) { - // renderIntProperty(prop, p.first); - // continue; - // } - - // if (_floatProperties.find(prop) != _floatProperties.end()) { - // renderFloatProperty(prop, p.first); - // continue; - // } - - // if (_vec2Properties.find(prop) != _vec2Properties.end()) { - // renderVec2Property(prop, p.first); - // continue; - // } - - // if (_vec3Properties.find(prop) != _vec3Properties.end()) { - // renderVec3Property(prop, p.first); - // continue; - // } - - // if (_vec4Properties.find(prop) != _vec4Properties.end()) { - // renderVec4Property(prop, p.first); - // continue; - // } - - // if (_optionProperties.find(prop) != _optionProperties.end()) { - // renderOptionProperty(prop, p.first); - // continue; - // } - - // if (_triggerProperties.find(prop) != _triggerProperties.end()) { - // renderTriggerProperty(prop, p.first); - // continue; - // } - - // if (_selectionProperties.find(prop) != _selectionProperties.end()) { - // renderSelectionProperty(prop, p.first); - // continue; - // } - - // if (_stringProperties.find(prop) != _stringProperties.end()) { - // renderStringProperty(prop, p.first); - // continue; - // } - // } - // } - // } - - //ImGui::End(); -//} -// -//GuiPropertyComponent::PropertyType GuiPropertyComponent::toPropertyType( -// const std::string& name) const -//{ -// if (name == "BoolProperty") -// return PropertyType::BoolProperty; -// if (name == "IntProperty") -// return PropertyType::IntProperty; -// if (name == "FloatProperty") -// return PropertyType::FloatProperty; -// if (name == "Vec2Property") -// return PropertyType::Vec2Property; -// if (name == "Vec3Property") -// return PropertyType::Vec3Property; -// if (name == "StringProperty") -// return PropertyType::StringProperty; -// if (name == "OptionProperty") -// return PropertyType::OptionProperty; -// if (name == "SelectionProperty") -// return PropertyType::SelectionProperty; -// if (name == "TriggerProperty") -// return PropertyType::TriggerProperty; -// -// LWARNING("Unsupported property type '" << name << "'"); -// return PropertyType::InvalidPropertyType; -//} -// -//void GuiPropertyComponent::renderProperty(const PropertyInfo& info) const { -// switch (info.type) { -// case PropertyType::BoolProperty: -// { -// // BoolProperty* p = static_cast(prop); -// // std::string name = p->guiName(); -// -// // BoolProperty::ValueType value = *p; -// // ImGui::Checkbox((ownerName + "." + name).c_str(), &value); -// // p->set(value); -// -// -// -// -// break; -// } -// default: -// LERROR("Missing case statement: {" << int(info.type) << "," << info.identifier << "}"); -// //ghoul_assert(false, "Missing case statement"); -// } -// -//} - diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index 9f161dc68d..7dcf7e48ed 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -39,30 +39,39 @@ namespace { const std::string _loggerCat = "GuiPerformanceComponent"; + + enum class Sorting { + NoSorting = -1, + UpdateEphemeris = 0, + UpdateRender = 1, + Render = 2, + Total = 3 + }; } namespace openspace { namespace gui { -void GuiPerformanceComponent::initialize() { - _sortingSelection = -1; - - _sceneGraphIsEnabled = false; - _functionsIsEnabled = false; -} - -void GuiPerformanceComponent::deinitialize() { - delete _performanceMemory; - _performanceMemory = nullptr; -} - void GuiPerformanceComponent::render() { + using ghoul::SharedMemory; using namespace performance; ImGui::Begin("Performance", &_isEnabled); - if (OsEng.renderEngine().doesPerformanceMeasurements() && - ghoul::SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData)) - { + if (OsEng.renderEngine().doesPerformanceMeasurements()) { + ghoul_assert( + SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData), + "Shared Memory block was not allocated" + ); + + if (!_performanceMemory) { + _performanceMemory = std::make_unique( + PerformanceManager::PerformanceMeasurementSharedData + ); + } + PerformanceLayout* layout = reinterpret_cast( + _performanceMemory->memory() + ); + ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled); ImGui::Checkbox("Functions", &_functionsIsEnabled); @@ -77,18 +86,34 @@ void GuiPerformanceComponent::render() { // The indices correspond to the index into the average array further below ImGui::Text("Sorting"); - ImGui::RadioButton("No Sorting", &_sortingSelection, -1); - ImGui::RadioButton("UpdateEphemeris", &_sortingSelection, 0); - ImGui::RadioButton("UpdateRender", &_sortingSelection, 1); - ImGui::RadioButton("RenderTime", &_sortingSelection, 2); - - if (!_performanceMemory) - _performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData); - - void* ptr = _performanceMemory->memory(); - - PerformanceLayout* layout = reinterpret_cast(ptr); + ImGui::RadioButton( + "No Sorting", + &_sortingSelection, + static_cast(Sorting::NoSorting) + ); + ImGui::RadioButton( + "UpdateEphemeris", + &_sortingSelection, + static_cast(Sorting::UpdateEphemeris) + ); + ImGui::RadioButton( + "UpdateRender", + &_sortingSelection, + static_cast(Sorting::UpdateRender) + ); + ImGui::RadioButton( + "RenderTime", + &_sortingSelection, + static_cast(Sorting::Render) + ); + ImGui::RadioButton( + "TotalTime", + &_sortingSelection, + static_cast(Sorting::Total) + ); + // Later, we will sort this indices list instead of the real values for + // performance reasons std::vector indices(layout->nScaleGraphEntries); std::iota(indices.begin(), indices.end(), 0); @@ -96,36 +121,44 @@ void GuiPerformanceComponent::render() { // updateEphemeris // UpdateRender // RenderTime - std::vector> averages(layout->nScaleGraphEntries, { 0.f, 0.f, 0.f }); + std::vector> averages( + layout->nScaleGraphEntries, + { 0.f, 0.f, 0.f } + ); std::vector, 3>> minMax( layout->nScaleGraphEntries ); for (int i = 0; i < layout->nScaleGraphEntries; ++i) { - const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i]; - - int v[3] = { 0, 0, 0 }; + const PerformanceLayout::SceneGraphPerformanceLayout& entry = + layout->sceneGraphEntries[i]; + int nValues[3] = { 0, 0, 0 }; + + // Compute the averages and count the number of values so we don't divide + // by 0 later for (int j = 0; j < PerformanceLayout::NumberValues; ++j) { averages[i][0] += entry.updateEphemeris[j]; if (entry.updateEphemeris[j] != 0.f) - ++(v[0]); + ++(nValues[0]); averages[i][1] += entry.updateRenderable[j]; if (entry.updateRenderable[j] != 0.f) - ++(v[1]); + ++(nValues[1]); averages[i][2] += entry.renderTime[j]; if (entry.renderTime[j] != 0.f) - ++(v[2]); + ++(nValues[2]); } - if (v[0] != 0) - averages[i][0] /= static_cast(v[0]); - if (v[1] != 0) - averages[i][1] /= static_cast(v[1]); - if (v[2] != 0) - averages[i][2] /= static_cast(v[2]); + if (nValues[0] != 0) + averages[i][0] /= static_cast(nValues[0]); + if (nValues[1] != 0) + averages[i][1] /= static_cast(nValues[1]); + if (nValues[2] != 0) + averages[i][2] /= static_cast(nValues[2]); + // Get the minimum/maximum values for each of the components so that we + // can scale the plot by these numbers auto minmaxEphemeris = std::minmax_element( std::begin(entry.updateEphemeris), std::end(entry.updateEphemeris) @@ -135,7 +168,6 @@ void GuiPerformanceComponent::render() { *(minmaxEphemeris.second) ); - auto minmaxUpdateRenderable = std::minmax_element( std::begin(entry.updateRenderable), std::end(entry.updateRenderable) @@ -145,7 +177,6 @@ void GuiPerformanceComponent::render() { *(minmaxUpdateRenderable.second) ); - auto minmaxRendering = std::minmax_element( std::begin(entry.renderTime), std::end(entry.renderTime) @@ -157,28 +188,66 @@ void GuiPerformanceComponent::render() { } + + // If we don't want to sort, we will leave the indices list alone, thus + // leaving them in the regular ordering + Sorting selection = Sorting(_sortingSelection); + if (selection != Sorting::NoSorting) { + std::function sortFunc; - if (_sortingSelection != -1) { - int sortIndex = _sortingSelection; + if (selection == Sorting::Total) { + // If we do want to sort totally, we need to sum all the averages and + // use that as the criterion + sortFunc = [&averages](size_t a, size_t b) { + float sumA = std::accumulate( + std::begin(averages[a]), + std::end(averages[a]), + 0.f + ); + + float sumB = std::accumulate( + std::begin(averages[b]), + std::end(averages[b]), + 0.f + ); + + return sumA > sumB; + }; + } + else { + // otherwise we use the sorting index + int sel = _sortingSelection; + sortFunc = [sel, &averages](size_t a, size_t b) { + return averages[a][sel] > averages[b][sel]; + }; + } std::sort( indices.begin(), indices.end(), - [sortIndex, &averages](size_t a, size_t b) { - return averages[a][sortIndex] > averages[b][sortIndex]; - } + sortFunc ); - } for (int i = 0; i < layout->nScaleGraphEntries; ++i) { - const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]]; + // We are using the indices list as an additional level of indirection + // into the respective values so that the list will be sorted by whatever + // criterion we selected previously + + const PerformanceLayout::SceneGraphPerformanceLayout& entry = + layout->sceneGraphEntries[indices[i]]; if (ImGui::CollapsingHeader(entry.name)) { - std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[PerformanceLayout::NumberValues - 1]) + "us"; - ; + + std::string updateEphemerisTime = std::to_string( + entry.updateEphemeris[PerformanceLayout::NumberValues - 1] + ) + "us"; + ImGui::PlotLines( - fmt::format("UpdateEphemeris\nAverage: {}us", averages[indices[i]][0]).c_str(), + fmt::format( + "UpdateEphemeris\nAverage: {}us", + averages[indices[i]][0] + ).c_str(), &entry.updateEphemeris[0], PerformanceLayout::NumberValues, 0, @@ -188,9 +257,15 @@ void GuiPerformanceComponent::render() { ImVec2(0, 40) ); - std::string updateRenderableTime = std::to_string(entry.updateRenderable[PerformanceLayout::NumberValues - 1]) + "us"; + std::string updateRenderableTime = std::to_string( + entry.updateRenderable[PerformanceLayout::NumberValues - 1] + ) + "us"; + ImGui::PlotLines( - fmt::format("UpdateRender\nAverage: {}us", averages[indices[i]][1]).c_str(), + fmt::format( + "UpdateRender\nAverage: {}us", + averages[indices[i]][1] + ).c_str(), &entry.updateRenderable[0], PerformanceLayout::NumberValues, 0, @@ -200,9 +275,15 @@ void GuiPerformanceComponent::render() { ImVec2(0, 40) ); - std::string renderTime = std::to_string(entry.renderTime[PerformanceLayout::NumberValues - 1]) + "us"; + std::string renderTime = std::to_string( + entry.renderTime[PerformanceLayout::NumberValues - 1] + ) + "us"; + ImGui::PlotLines( - fmt::format("RenderTime\nAverage: {}us", averages[indices[i]][2]).c_str(), + fmt::format( + "RenderTime\nAverage: {}us", + averages[indices[i]][2] + ).c_str(), &entry.renderTime[0], PerformanceLayout::NumberValues, 0, @@ -220,15 +301,9 @@ void GuiPerformanceComponent::render() { ImGui::Begin("Functions", &_functionsIsEnabled); using namespace performance; - if (!_performanceMemory) - _performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData); - - void* ptr = _performanceMemory->memory(); - - PerformanceLayout* layout = reinterpret_cast(ptr); - for (int i = 0; i < layout->nFunctionEntries; ++i) { - const PerformanceLayout::FunctionPerformanceLayout& entry = layout->functionEntries[i]; + const PerformanceLayout::FunctionPerformanceLayout& entry = + layout->functionEntries[i]; float avg = 0.f; int count = 0; @@ -244,9 +319,12 @@ void GuiPerformanceComponent::render() { std::end(layout->functionEntries[i].time) ); - const PerformanceLayout::FunctionPerformanceLayout& f = layout->functionEntries[i]; + const PerformanceLayout::FunctionPerformanceLayout& f = + layout->functionEntries[i]; - std::string renderTime = std::to_string(entry.time[PerformanceLayout::NumberValues - 1]) + "us"; + std::string renderTime = std::to_string( + entry.time[PerformanceLayout::NumberValues - 1] + ) + "us"; ImGui::PlotLines( fmt::format("{}\nAverage: {}us", entry.name, avg).c_str(), &entry.time[0], diff --git a/modules/onscreengui/src/guipropertycomponent.cpp b/modules/onscreengui/src/guipropertycomponent.cpp index 42978e553b..a8628c08d5 100644 --- a/modules/onscreengui/src/guipropertycomponent.cpp +++ b/modules/onscreengui/src/guipropertycomponent.cpp @@ -23,21 +23,11 @@ ****************************************************************************************/ #include + #include -#include -#include -#include +#include -#include -#include -#include -#include -#include - -#include -#include -#include #include "imgui.h" namespace { @@ -56,14 +46,6 @@ void GuiPropertyComponent::setSource(SourceFunction function) { _function = std::move(function); } -//void GuiPropertyComponent::registerPropertyOwner(properties::PropertyOwner* owner) { -// _owners.push_back(owner); -//} -// -//void GuiPropertyComponent::unregisterPropertyOwner(properties::PropertyOwner* owner) { -// _owners.erase(std::find(_owners.begin(), _owners.end(), owner)); -//} - void GuiPropertyComponent::render() { ImGui::Begin(_name.c_str(), &_isEnabled, size, 0.5f); @@ -88,8 +70,9 @@ void GuiPropertyComponent::render() { if (header()) { for (properties::Property* prop : pOwner->propertiesRecursive()) { - if (prop->isVisible()) + if (prop->isVisible()) { renderProperty(prop, pOwner); + } } } } @@ -114,8 +97,9 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop, properties }; auto it = FunctionMapping.find(prop->className()); - if (it != FunctionMapping.end()) + if (it != FunctionMapping.end()) { it->second(prop, owner->name()); + } } } // gui diff --git a/modules/onscreengui/src/guitimecomponent.cpp b/modules/onscreengui/src/guitimecomponent.cpp index 3222665d23..6c71d1c6d3 100644 --- a/modules/onscreengui/src/guitimecomponent.cpp +++ b/modules/onscreengui/src/guitimecomponent.cpp @@ -27,13 +27,8 @@ #include #include -#include #include "imgui.h" -namespace { - const std::string _loggerCat = "GuiTimeComponent"; -} - namespace openspace { namespace gui { @@ -41,37 +36,11 @@ void GuiTimeComponent::render() { float deltaTime = static_cast(Time::ref().deltaTime()); bool changed = ImGui::SliderFloat("Delta Time", &deltaTime, -500000.f, 500000.f); - if (changed) - OsEng.scriptEngine().queueScript("openspace.time.setDeltaTime(" + std::to_string(deltaTime) + ")"); - - - //char dateBuffer[512] = {}; - //ImGui::InputText("Date", dateBuffer, 512); - //bool pressed = ImGui::Button("Set Date"); - //if (pressed) - // OsEng.scriptEngine()->queueScript("openspace.time.setTime('" + std::string(dateBuffer) + "')"); - - //const SceneGraphNode* currentFocus = OsEng.interactionHandler()->focusNode(); - - //std::vector nodes = OsEng.renderEngine()->sceneGraph()->allSceneGraphNodes(); - //std::sort(nodes.begin(), nodes.end(), [](SceneGraphNode* lhs, SceneGraphNode* rhs) { return lhs->name() < rhs->name(); }); - //auto it = std::find(nodes.begin(), nodes.end(), currentFocus); - //ghoul_assert(it != nodes.end(), "Focus node not found"); - - //std::string nodeNames = ""; - //for (SceneGraphNode* n : nodes) - // nodeNames += n->name() + '\0'; - - - //int position = it - nodes.begin(); - - //bool result = ImGui::Combo("Origin", &position, nodeNames.c_str()); - - //if (result) { - // LINFO("openspace.setOrigin('" + nodes[position]->name() + "');"); - // OsEng.scriptEngine()->queueScript("openspace.setOrigin('" + nodes[position]->name() + "');"); - //} - + if (changed) { + OsEng.scriptEngine().queueScript( + "openspace.time.setDeltaTime(" + std::to_string(deltaTime) + ")" + ); + } } } // gui diff --git a/modules/onscreengui/src/renderproperties.cpp b/modules/onscreengui/src/renderproperties.cpp index c594c43f2b..e59e56221b 100644 --- a/modules/onscreengui/src/renderproperties.cpp +++ b/modules/onscreengui/src/renderproperties.cpp @@ -21,25 +21,19 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ + #include + +#include #include #include #include #include #include - -#include #include -#include - -#include -#include -#include - #include "imgui.h" - namespace openspace { using namespace properties; @@ -126,7 +120,7 @@ void renderStringProperty(Property* prop, const std::string& ownerName) { ImGui::InputText(name.c_str(), buffer, bufferSize); std::string newValue(buffer); - if (newValue != p->value() && FileSys.fileExists(newValue)) + if (newValue != p->value()) executeScript(p->fullyQualifiedIdentifier(), "'" + newValue + "'"); ImGui::PopID(); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 09edbe3fab..3dd53c0be4 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -70,6 +70,7 @@ #endif #ifdef OPENSPACE_MODULE_ISWA_ENABLED +#include #include #endif @@ -458,7 +459,23 @@ bool OpenSpaceEngine::initialize() { } ); - +#ifdef OPENSPACE_MODULE_ISWA_ENABLED + OsEng.gui()._iswa.setSource( + [&]() { + const auto& groups = IswaManager::ref().groups(); + std::vector res; + std::transform( + groups.begin(), + groups.end(), + std::back_inserter(res), + [](const auto& val) { + return val.second.get(); + } + ); + return res; + } + ); +#endif #endif