Skip to content

Commit

Permalink
UI-ImGui: add RangeSlider and use for filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
GPMueller committed Jan 3, 2021
1 parent 816343c commit a62dd7d
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 68 deletions.
4 changes: 4 additions & 0 deletions ui-cpp/ui-imgui/include/widgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ void show_settings( bool & show, ui::RenderingLayer & rendering_layer );
void show_keybindings( bool & show );
void show_about( bool & show );

bool RangeSliderFloat(
const char * label, float * v1, float * v2, float v_min, float v_max, const char * display_format = "(%.3f, %.3f)",
float power = 1.0f );

} // namespace widgets

#endif
62 changes: 22 additions & 40 deletions ui-cpp/ui-imgui/src/renderer_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <fonts.hpp>
#include <renderer_widget.hpp>
#include <widgets.hpp>

#include <VFRendering/ArrowRenderer.hxx>
#include <VFRendering/BoundingBoxRenderer.hxx>
Expand Down Expand Up @@ -569,55 +570,36 @@ void RendererWidget::show_filters()
{
ImGui::TextUnformatted( "Orientation" );
ImGui::Indent( 15 );
ImGui::TextUnformatted( "min" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_direction_min", filter_direction_min, -1, 1 ) )
{
filter_direction_max[0] = std::max( filter_direction_max[0], filter_direction_min[0] );
filter_direction_max[1] = std::max( filter_direction_max[1], filter_direction_min[1] );
filter_direction_max[2] = std::max( filter_direction_max[2], filter_direction_min[2] );

renderer->setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( get_is_visible_implementation(
state, filter_position_min, filter_position_max, filter_direction_min, filter_direction_max ) );
}
ImGui::TextUnformatted( "max" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_direction_max", filter_direction_max, -1, 1 ) )
{
filter_direction_min[0] = std::min( filter_direction_min[0], filter_direction_max[0] );
filter_direction_min[1] = std::min( filter_direction_min[1], filter_direction_max[1] );
filter_direction_min[2] = std::min( filter_direction_min[2], filter_direction_max[2] );

renderer->setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( get_is_visible_implementation(
state, filter_position_min, filter_position_max, filter_direction_min, filter_direction_max ) );
}
bool update = false;
if( widgets::RangeSliderFloat(
"##filter_direction_x", &filter_direction_min[0], &filter_direction_max[0], -1, 1, "x: [%.3f, %.3f]" ) )
update = true;
if( widgets::RangeSliderFloat(
"##filter_direction_y", &filter_direction_min[1], &filter_direction_max[1], -1, 1, "y: [%.3f, %.3f]" ) )
update = true;
if( widgets::RangeSliderFloat(
"##filter_direction_z", &filter_direction_min[2], &filter_direction_max[2], -1, 1, "z: [%.3f, %.3f]" ) )
update = true;
ImGui::Indent( -15 );

ImGui::TextUnformatted( "Position" );
ImGui::Indent( 15 );
ImGui::TextUnformatted( "min" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_position_min", filter_position_min, 0, 1 ) )
{
filter_position_max[0] = std::max( filter_position_max[0], filter_position_min[0] );
filter_position_max[1] = std::max( filter_position_max[1], filter_position_min[1] );
filter_position_max[2] = std::max( filter_position_max[2], filter_position_min[2] );
if( widgets::RangeSliderFloat(
"##filter_position_x", &filter_position_min[0], &filter_position_max[0], 0, 1, "x: [%.3f, %.3f]" ) )
update = true;
if( widgets::RangeSliderFloat(
"##filter_position_y", &filter_position_min[1], &filter_position_max[1], 0, 1, "y: [%.3f, %.3f]" ) )
update = true;
if( widgets::RangeSliderFloat(
"##filter_position_z", &filter_position_min[2], &filter_position_max[2], 0, 1, "z: [%.3f, %.3f]" ) )
update = true;
ImGui::Indent( -15 );

renderer->setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( get_is_visible_implementation(
state, filter_position_min, filter_position_max, filter_direction_min, filter_direction_max ) );
}
ImGui::TextUnformatted( "max" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_position_max", filter_position_max, 0, 1 ) )
if( update )
{
filter_position_min[0] = std::min( filter_position_min[0], filter_position_max[0] );
filter_position_min[1] = std::min( filter_position_min[1], filter_position_max[1] );
filter_position_min[2] = std::min( filter_position_min[2], filter_position_max[2] );

renderer->setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( get_is_visible_implementation(
state, filter_position_min, filter_position_max, filter_direction_min, filter_direction_max ) );
}
ImGui::Indent( -15 );

ImGui::TreePop();
}
Expand Down
47 changes: 19 additions & 28 deletions ui-cpp/ui-imgui/src/visualisation_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <visualisation_widget.hpp>
#include <widgets.hpp>

#include <Spirit/Geometry.h>

Expand Down Expand Up @@ -137,48 +138,38 @@ void VisualisationWidget::show()

ImGui::TextUnformatted( "Orientation" );
ImGui::Indent( 15 );
ImGui::TextUnformatted( "min" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_direction_min", filter_direction_min, -1, 1 ) )
if( widgets::RangeSliderFloat(
"##filter_direction_x", &filter_direction_min[0], &filter_direction_max[0], -1, 1, "x: [%.3f, %.3f]" ) )
{
filter_direction_max[0] = std::max( filter_direction_max[0], filter_direction_min[0] );
filter_direction_max[1] = std::max( filter_direction_max[1], filter_direction_min[1] );
filter_direction_max[2] = std::max( filter_direction_max[2], filter_direction_min[2] );

rendering_layer.view.setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( is_visible() );
}
ImGui::TextUnformatted( "max" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_direction_max", filter_direction_max, -1, 1 ) )
if( widgets::RangeSliderFloat(
"##filter_direction_y", &filter_direction_min[1], &filter_direction_max[1], -1, 1, "y: [%.3f, %.3f]" ) )
{
rendering_layer.view.setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( is_visible() );
}
if( widgets::RangeSliderFloat(
"##filter_direction_z", &filter_direction_min[2], &filter_direction_max[2], -1, 1, "z: [%.3f, %.3f]" ) )
{
filter_direction_min[0] = std::min( filter_direction_min[0], filter_direction_max[0] );
filter_direction_min[1] = std::min( filter_direction_min[1], filter_direction_max[1] );
filter_direction_min[2] = std::min( filter_direction_min[2], filter_direction_max[2] );

rendering_layer.view.setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( is_visible() );
}
ImGui::Indent( -15 );

ImGui::TextUnformatted( "Position" );
ImGui::Indent( 15 );
ImGui::TextUnformatted( "min" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_position_min", filter_position_min, 0, 1 ) )
if( widgets::RangeSliderFloat(
"##filter_position_x", &filter_position_min[0], &filter_position_max[0], 0, 1, "x: [%.3f, %.3f]" ) )
{
filter_position_max[0] = std::max( filter_position_max[0], filter_position_min[0] );
filter_position_max[1] = std::max( filter_position_max[1], filter_position_min[1] );
filter_position_max[2] = std::max( filter_position_max[2], filter_position_min[2] );

rendering_layer.view.setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( is_visible() );
}
ImGui::TextUnformatted( "max" );
ImGui::SameLine();
if( ImGui::SliderFloat3( "##filter_position_max", filter_position_max, 0, 1 ) )
if( widgets::RangeSliderFloat(
"##filter_position_y", &filter_position_min[1], &filter_position_max[1], 0, 1, "y: [%.3f, %.3f]" ) )
{
rendering_layer.view.setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( is_visible() );
}
if( widgets::RangeSliderFloat(
"##filter_position_z", &filter_position_min[2], &filter_position_max[2], 0, 1, "z: [%.3f, %.3f]" ) )
{
filter_position_min[0] = std::min( filter_position_min[0], filter_position_max[0] );
filter_position_min[1] = std::min( filter_position_min[1], filter_position_max[1] );
filter_position_min[2] = std::min( filter_position_min[2], filter_position_max[2] );

rendering_layer.view.setOption<VFRendering::View::Option::IS_VISIBLE_IMPLEMENTATION>( is_visible() );
}
ImGui::Indent( -15 );
Expand Down
Loading

0 comments on commit a62dd7d

Please sign in to comment.