More cleanup of Gui code

Added IswaGroup properties to the iSWA properties list
Enable sorting the performance measurements by total time
This commit is contained in:
Alexander Bock
2016-06-28 19:22:50 +02:00
parent 3417f45805
commit cf80788067
17 changed files with 339 additions and 525 deletions
+13 -20
View File
@@ -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<ghoul::opengl::Texture>(
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<GLvoid*>(offsetof(ImDrawVert, pos))
);
glVertexAttribPointer(
uvLocation,
_program->attributeLocation("in_uv"),
2,
GL_FLOAT,
GL_FALSE,
@@ -316,7 +308,7 @@ void GUI::initializeGL() {
reinterpret_cast<GLvoid*>(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));
}
+2 -2
View File
@@ -39,5 +39,5 @@ void GuiHelpComponent::render() {
ImGui::End();
}
} // gui
} // openspace
} // namespace gui
} // namespace openspace
+86 -80
View File
@@ -23,29 +23,16 @@
****************************************************************************************/
#include <modules/onscreengui/include/guiiswacomponent.h>
#include <modules/onscreengui/include/renderproperties.h>
#include <modules/iswa/util/iswamanager.h>
#include <openspace/engine/downloadmanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#include <ext/json/json.hpp>
#include <openspace/engine/downloadmanager.h>
#include <modules/iswa/util/iswamanager.h>
#include <ghoul/filesystem/filesystem>
#include <fstream>
#include <ext/json/json.hpp>
#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<cdfs.size(); i++){
ImGui::RadioButton(cdfs[i].name.c_str(), &_cdfOptionsMap[groupName], i);
for (int i = 0; i < cdfs.size(); ++i) {
ImGui::RadioButton(
cdfs[i].name.c_str(),
&_cdfOptionsMap[groupName],
i
);
}
int cdfOption = _cdfOptionsMap[groupName];
if(cdfOptionValue != cdfOption){
if(cdfOptionValue >= 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
} // namespace gui
} // namespace openspace
+22 -130
View File
@@ -25,10 +25,12 @@
#include <modules/onscreengui/include/guiorigincomponent.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/interaction/interactionhandler.h>
#include <ghoul/misc/assert.h>
#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<SceneGraphNode*> 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<SceneGraphNode*> 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<int>(std::distance(iCurrentFocus, nodes.begin()));
int position = static_cast<int>(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", &currentPosition, 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<BoolProperty*>(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");
// }
//
//}
@@ -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<ghoul::SharedMemory>(
PerformanceManager::PerformanceMeasurementSharedData
);
}
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(
_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<PerformanceLayout*>(ptr);
ImGui::RadioButton(
"No Sorting",
&_sortingSelection,
static_cast<int>(Sorting::NoSorting)
);
ImGui::RadioButton(
"UpdateEphemeris",
&_sortingSelection,
static_cast<int>(Sorting::UpdateEphemeris)
);
ImGui::RadioButton(
"UpdateRender",
&_sortingSelection,
static_cast<int>(Sorting::UpdateRender)
);
ImGui::RadioButton(
"RenderTime",
&_sortingSelection,
static_cast<int>(Sorting::Render)
);
ImGui::RadioButton(
"TotalTime",
&_sortingSelection,
static_cast<int>(Sorting::Total)
);
// Later, we will sort this indices list instead of the real values for
// performance reasons
std::vector<size_t> indices(layout->nScaleGraphEntries);
std::iota(indices.begin(), indices.end(), 0);
@@ -96,36 +121,44 @@ void GuiPerformanceComponent::render() {
// updateEphemeris
// UpdateRender
// RenderTime
std::vector<std::array<float, 3>> averages(layout->nScaleGraphEntries, { 0.f, 0.f, 0.f });
std::vector<std::array<float, 3>> averages(
layout->nScaleGraphEntries,
{ 0.f, 0.f, 0.f }
);
std::vector<std::array<std::pair<float, float>, 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<float>(v[0]);
if (v[1] != 0)
averages[i][1] /= static_cast<float>(v[1]);
if (v[2] != 0)
averages[i][2] /= static_cast<float>(v[2]);
if (nValues[0] != 0)
averages[i][0] /= static_cast<float>(nValues[0]);
if (nValues[1] != 0)
averages[i][1] /= static_cast<float>(nValues[1]);
if (nValues[2] != 0)
averages[i][2] /= static_cast<float>(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<bool(size_t, size_t)> 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<PerformanceLayout*>(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],
@@ -23,21 +23,11 @@
****************************************************************************************/
#include <modules/onscreengui/include/guipropertycomponent.h>
#include <modules/onscreengui/include/renderproperties.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#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
+5 -36
View File
@@ -27,13 +27,8 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/time.h>
#include <ghoul/misc/assert.h>
#include "imgui.h"
namespace {
const std::string _loggerCat = "GuiTimeComponent";
}
namespace openspace {
namespace gui {
@@ -41,37 +36,11 @@ void GuiTimeComponent::render() {
float deltaTime = static_cast<float>(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<SceneGraphNode*> 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
+4 -10
View File
@@ -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 <modules/onscreengui/include/renderproperties.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/engine/openspaceengine.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#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();