-
Mathias Paulin authoredMathias Paulin authored
VisualizationGui.cpp 4.60 KiB
#include <RadiumNBR/Gui/VisualizationGui.hpp>
#include <RadiumNBR/NodeBasedRenderer.hpp>
#include <RadiumNBR/Renderer/Visualization.hpp>
#include <fstream>
namespace RadiumNBR {
using namespace Gui;
RadiumNBR::Gui::RendererPanel*
buildControllerGui( NodeBasedRenderer* renderer, const std::function<void()>& appUpdateCallback ) {
auto& controller = dynamic_cast<VisualizationController&>( renderer->getController() );
auto controlPanel = new RendererPanel( renderer->getRendererName() );
auto defColor = Ra::Core::Utils::Color::linearRGBTosRGB( renderer->getBackgroundColor() );
auto clrClbck = [renderer, appUpdateCallback]( const Ra::Core::Utils::Color& clr ) {
// set the background color for all passes that need it
renderer->setBackgroundColor( clr );
appUpdateCallback();
};
controlPanel->addColorInput( "Background Color", clrClbck, defColor );
controlPanel->addSeparator();
controlPanel->beginLayout( QBoxLayout::LeftToRight );
controlPanel->addOption(
" Post processing",
[&controller, appUpdateCallback]( bool b ) {
controller.enablePostProcess( b );
appUpdateCallback();
},
true );
controlPanel->addOption(
" Show Debug ",
[renderer, appUpdateCallback]( bool b ) {
renderer->showDebug( b );
appUpdateCallback();
},
false );
controlPanel->addOption(
" Show UI ",
[renderer, appUpdateCallback]( bool b ) {
renderer->showUI( b );
appUpdateCallback();
},
false );
controlPanel->endLayout( true );
controlPanel->beginLayout( QBoxLayout::LeftToRight );
controlPanel->beginLayout( QBoxLayout::TopToBottom );
// auto visualizationFunction = controller.getAttribToColorFunc();
auto getAttribCode = [&controller]() { return controller.getAttribToColorFunc().first; };
auto getColorCode = [&controller]() { return controller.getAttribToColorFunc().second; };
controlPanel->addCodeEditor(
"Edit attribute function",
[&controller, getColorCode, appUpdateCallback]( const std::string& s ) {
controller.setAttribToColorFunc( s, getColorCode() );
appUpdateCallback();
},
getAttribCode );
controlPanel->addCodeEditor(
"Edit Color function",
[&controller, getAttribCode, appUpdateCallback]( const std::string& s ) {
controller.setAttribToColorFunc( getAttribCode(), s );
appUpdateCallback();
},
getColorCode );
controlPanel->endLayout( false );
controlPanel->beginLayout( QBoxLayout::TopToBottom );
auto loadAttribFuncClbk =
[&controller, getColorCode, appUpdateCallback]( const std::string& file ) {
if ( file.empty() ) { return; }
std::cout << "Loading attrib function from file " << file << std::endl;
std::ifstream inFile( file );
std::stringstream strStream;
strStream << inFile.rdbuf(); // read the file
controller.setAttribToColorFunc( strStream.str(), getColorCode() );
appUpdateCallback();
};
auto loadColorFuncClbk =
[&controller, getAttribCode, appUpdateCallback]( const std::string& file ) {
if ( file.empty() ) { return; }
std::cout << "Loading color function from file " << file << std::endl;
std::ifstream inFile( file );
std::stringstream strStream;
strStream << inFile.rdbuf(); // read the file
controller.setAttribToColorFunc( getAttribCode(), strStream.str() );
appUpdateCallback();
};
controlPanel->addFileInput(
"Load attribute func", loadAttribFuncClbk, "./", "Shaders (*.glsl)" );
controlPanel->addFileInput( "Load color func", loadColorFuncClbk, "./", "Shaders (*.glsl)" );
controlPanel->endLayout( false );
controlPanel->beginLayout( QBoxLayout::TopToBottom );
auto saveAttribFuncClbk = [getAttribCode, appUpdateCallback]( const std::string& file ) {
std::ofstream outFile( file );
outFile << getAttribCode();
};
auto saveColorFuncClbk = [getColorCode, appUpdateCallback]( const std::string& file ) {
std::ofstream outFile( file );
outFile << getColorCode();
};
controlPanel->addFileOuput(
"Save attribute func", saveAttribFuncClbk, "./", "Shaders (*.glsl)" );
controlPanel->addFileOuput( "Save color func", saveColorFuncClbk, "./", "Shaders (*.glsl)" );
controlPanel->endLayout( false );
controlPanel->endLayout( true );
return controlPanel;
}
} // namespace RadiumNBR