Skip to content

Commit

Permalink
Refresh renderer from representation settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Nov 13, 2024
1 parent 7bb0fe0 commit 10d941c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace VTX::App::Component::Representation
{
_representation.radiusSphereAdd = p_value;
}
else if constexpr ( S == E_REPRESENTATION_SETTINGS::RADIUS_FIXED )
else if constexpr ( S == E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED )
{
_representation.radiusFixed = p_value;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/app/src/app/component/representation/representation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace VTX::App::Component::Representation
{
// TODO: move default layout.
_representation.hasSphere = true;
_representation.radiusSphereFixed = 0.4f;
_representation.radiusSphereFixed = 0.1f;
_representation.radiusSphereAdd = 0.f;
_representation.radiusFixed = false;
_representation.radiusFixed = true;

_representation.hasCylinder = true;
_representation.hasCylinder = false;
_representation.radiusCylinder = 0.1f;
_representation.cylinderColorBlending = false;

Expand All @@ -31,7 +31,7 @@ namespace VTX::App::Component::Representation
_proxy->set( E_REPRESENTATION_SETTINGS::HAS_SPHERE, _representation.hasSphere );
_proxy->set( E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_FIXED, _representation.radiusSphereFixed );
_proxy->set( E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_ADD, _representation.radiusSphereAdd );
_proxy->set( E_REPRESENTATION_SETTINGS::RADIUS_FIXED, _representation.radiusFixed );
_proxy->set( E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED, _representation.radiusFixed );

_proxy->set( E_REPRESENTATION_SETTINGS::HAS_CYLINDER, _representation.hasCylinder );
_proxy->set( E_REPRESENTATION_SETTINGS::RADIUS_CYLINDER, _representation.radiusCylinder );
Expand Down
10 changes: 5 additions & 5 deletions lib/renderer/include/renderer/proxy/proxy_pointer_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ namespace VTX::Renderer::Proxy
template<typename T>
void set( const uint p_key, const T & p_value )
{
settings.emplace( p_key, &p_value );
_collection.emplace( p_key, &p_value );
}

// TODO: type check?
template<typename T>
const T & get( const uint p_key )
{
assert( settings.contains( p_key ) );
assert( settings[ p_key ] != nullptr );
assert( _collection.contains( p_key ) );
assert( _collection[ p_key ] != nullptr );

return *static_cast<const T *>( settings[ p_key ] );
return *static_cast<const T *>( _collection[ p_key ] );
}

private:
std::unordered_map<uint, const void *> settings;
std::unordered_map<uint, const void *> _collection;
};

} // namespace VTX::Renderer::Proxy
Expand Down
2 changes: 1 addition & 1 deletion lib/renderer/include/renderer/proxy/representation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VTX::Renderer::Proxy
HAS_SPHERE,
RADIUS_SPHERE_FIXED,
RADIUS_SPHERE_ADD,
RADIUS_FIXED,
IS_SPHERE_RADIUS_FIXED,

HAS_CYLINDER,
RADIUS_CYLINDER,
Expand Down
72 changes: 69 additions & 3 deletions lib/renderer/src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,22 +460,88 @@ namespace VTX::Renderer
std::end( _proxyRepresentations ), std::begin( p_proxies ), std::end( p_proxies )
);

// We need to draw spheres at cylinder radius when no spheres asked.
static auto refreshSphereUniFun = [ & ]( Proxy::Representation * const p_representation )
{
showAtoms = true;
if ( p_representation->get<bool>( E_REPRESENTATION_SETTINGS::HAS_SPHERE ) )
{
setValue(
p_representation->get<float>( E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_FIXED ),
"Sphere radius fixed",
0
);
setValue(
p_representation->get<float>( E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_ADD ), "Sphere radius add", 0
);
setValue(
uint( p_representation->get<bool>( E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED ) ),
"Is sphere radius fixed",
0
);
}
else
{
if ( p_representation->get<bool>( E_REPRESENTATION_SETTINGS::HAS_CYLINDER ) )
{
setValue( uint( true ), "Is sphere radius fixed", 0 );
setValue(
p_representation->get<float>( E_REPRESENTATION_SETTINGS::RADIUS_CYLINDER ),
"Sphere radius fixed",
0
);
}
else
{
showAtoms = false;
}
}
};

std::vector<_StructUBORepresentation> representations;
for ( Proxy::Representation * const representation : p_proxies )
for ( Proxy::Representation * const representation : _proxyRepresentations )
{
representations.emplace_back( _StructUBORepresentation {
representation->get<float>( E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_FIXED ),
representation->get<float>( E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_ADD ),
representation->get<bool>( E_REPRESENTATION_SETTINGS::RADIUS_FIXED ),
representation->get<bool>( E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED ),
representation->get<float>( E_REPRESENTATION_SETTINGS::RADIUS_CYLINDER ),
representation->get<bool>( E_REPRESENTATION_SETTINGS::CYLINDER_COLOR_BLENDING ),
representation->get<bool>( E_REPRESENTATION_SETTINGS::RIBBON_COLOR_BLENDING ) } );

// showAtoms = representation->get<bool>( E_REPRESENTATION_SETTINGS::HAS_SPHERE );
showBonds = representation->get<bool>( E_REPRESENTATION_SETTINGS::HAS_CYLINDER );
showRibbons = representation->get<bool>( E_REPRESENTATION_SETTINGS::HAS_RIBBON );

refreshSphereUniFun( representation );

// Callbacks.
representation->onChange<E_REPRESENTATION_SETTINGS::HAS_SPHERE, bool>() +=
[ &, representation ]( const bool p_value ) { refreshSphereUniFun( representation ); };
representation->onChange<E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED, bool>() +=
[ this ]( const bool p_value ) { setValue( uint( p_value ), "Is sphere radius fixed", 0 ); };
representation->onChange<E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_FIXED, float>() +=
[ this ]( const float p_value ) { setValue( p_value, "Sphere radius fixed", 0 ); };
representation->onChange<E_REPRESENTATION_SETTINGS::RADIUS_SPHERE_ADD, float>() +=
[ this ]( const float p_value ) { setValue( p_value, "Sphere radius add", 0 ); };

representation->onChange<E_REPRESENTATION_SETTINGS::HAS_CYLINDER, bool>() +=
[ &, representation ]( const bool p_value )
{
showBonds = p_value;
refreshSphereUniFun( representation );
};
representation->onChange<E_REPRESENTATION_SETTINGS::RADIUS_CYLINDER, float>() +=
[ this ]( const float p_value ) { setValue( p_value, "Cylinder radius", 0 ); };
[ &, representation ]( const float p_value )
{
setValue( p_value, "Cylinder radius", 0 );
refreshSphereUniFun( representation );
};
representation->onChange<E_REPRESENTATION_SETTINGS::CYLINDER_COLOR_BLENDING, bool>() +=
[ this ]( const bool p_value ) { setValue( uint( p_value ), "Cylinder color blending", 0 ); };

representation->onChange<E_REPRESENTATION_SETTINGS::HAS_RIBBON, bool>() +=
[ this ]( const bool p_value ) { showRibbons = p_value; };
representation->onChange<E_REPRESENTATION_SETTINGS::RIBBON_COLOR_BLENDING, bool>() +=
[ this ]( const bool p_value ) { setValue( uint( p_value ), "Ribbon color blending", 0 ); };
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/qt/src/ui/qt/dock_widget/representations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace VTX::UI::QT::DockWidget
{
App::ACTION_SYSTEM()
.execute<App::Action::Representation::
ChangeRepresentation<E_REPRESENTATION_SETTINGS::RADIUS_FIXED, bool>>( p_index );
ChangeRepresentation<E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED, bool>>( p_index );
}

);
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace VTX::UI::QT::DockWidget
// Callbacks.
p_component->callback<E_REPRESENTATION_SETTINGS::HAS_SPHERE, bool>() +=
[ groupBox ]( const bool p_value ) { groupBox->setChecked( p_value ); };
p_component->callback<E_REPRESENTATION_SETTINGS::RADIUS_FIXED, bool>() +=
p_component->callback<E_REPRESENTATION_SETTINGS::IS_SPHERE_RADIUS_FIXED, bool>() +=
[ comboBox, labelRadiusAdd, sliderRadiusAdd, labelRadiusFixed, sliderRadiusFixed ]( const bool p_value )
{
comboBox->setCurrentIndex( int( p_value ) );
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace VTX::UI::QT::DockWidget
);

// Radius.
auto * labelRadius = new QLabel( "Intensity", groupBox );
auto * labelRadius = new QLabel( "Radius", groupBox );
auto * slider = new QSlider( Qt::Orientation::Horizontal, groupBox );
layout->addWidget( labelRadius );
layout->addWidget( slider );
Expand Down

0 comments on commit 10d941c

Please sign in to comment.