Commit 2217ce74 authored by Sergio Galindo's avatar Sergio Galindo
Browse files

Merge branch 'planeSelection' into 'master'

Plane selection

See merge request nsviz/visimpl!51
parents 880b24b3 c78390f7
......@@ -42,3 +42,4 @@ gmrvlex
prefr
scoop
vmmlib
HighFive
......@@ -37,6 +37,8 @@ namespace visimpl
typedef simil::Spike Spike;
typedef simil::TSpikes TSpikes;
typedef std::unordered_map< unsigned int, unsigned int > TUIntUintMap;
typedef std::set< uint32_t > TGIDSet;
typedef std::vector< vmml::Vector3f > TPosVect;
......
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# ViSimpl
# 2015-2016 (c) ViSimpl / Universidad Rey Juan Carlos
# 2015-2019 (c) ViSimpl / Universidad Rey Juan Carlos
# sergio.galindo@urjc.es
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
......@@ -25,47 +25,51 @@ configure_file(${CMAKE_SOURCE_DIR}/CMake/common/cpp/version.cpp
set(UIDIR ${PROJECT_SOURCE_DIR}/ui)
set(QRCDIR ${PROJECT_SOURCE_DIR}/qrc)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
#set(CMAKE_AUTOMOC ON)
#set(CMAKE_AUTOUIC ON)
set(VISIMPL_SOURCES
${PROJECT_BINARY_DIR}/src/visimpl/version.cpp
CMakeSetup.rc
visimpl.ui
resources.qrc
visimpl.cpp
MainWindow.cpp
OpenGLWidget.cpp
VisualGroup.cpp
DomainManager.cpp
SelectionManagerWidget.cpp
prefr/ColorSource.cpp
prefr/ColorOperationModel.cpp
prefr/SourceMultiPosition.cpp
prefr/UpdaterStaticPosition.cpp
render/Plane.cpp
)
set(VISIMPL_HEADERS
${PROJECT_BINARY_DIR}/include/visimpl/version.h
OpenGLWidget.h
MainWindow.h
VisualGroup.h
DomainManager.h
SelectionManagerWidget.h
prefr/PrefrShaders.h
prefr/ColorSource.h
prefr/ColorOperationModel.h
prefr/SourceMultiPosition.h
prefr/UpdaterStaticPosition.h
render/Plane.cpp
)
......
......@@ -150,6 +150,16 @@ namespace visimpl
_particleSystem->start();
}
const tGidPosMap& DomainManager::positions( void ) const
{
return _gidPositions;
}
const TGIDSet& DomainManager::gids( void ) const
{
return _gids;
}
void DomainManager::mode( tVisualMode newMode )
{
clearView( );
......
......@@ -87,6 +87,8 @@ namespace visimpl
const std::vector< VisualGroup* >& groups( void ) const;
const std::vector< VisualGroup* >& attributeGroups( void ) const;
const tGidPosMap& positions( void ) const;
const TGIDSet& gids( void ) const;
tBoundingBox boundingBox( void ) const;
......
......@@ -88,8 +88,8 @@ namespace visimpl
, _modeSelectionWidget( nullptr )
, _toolBoxOptions( nullptr )
, _groupBoxTransferFunction( nullptr )
, _tfEditor( nullptr )
, _tfWidget( nullptr )
, _selectionManager( nullptr )
, _autoNameGroups( false )
, _groupBoxGroups( nullptr )
, _groupLayout( nullptr )
......@@ -115,6 +115,7 @@ namespace visimpl
, _spinBoxClippingWidth( nullptr )
, _spinBoxClippingDist( nullptr )
, _frameClippingColor( nullptr )
, _buttonSelectionFromClippingPlanes( nullptr )
{
_ui->setupUi( this );
......@@ -163,7 +164,7 @@ namespace visimpl
// Connect about dialog
connect( _ui->actionAbout, SIGNAL( triggered( )),
this, SLOT( aboutDialog( )));
this, SLOT( dialogAbout( )));
connect( _ui->actionHome, SIGNAL( triggered( )),
......@@ -249,6 +250,8 @@ namespace visimpl
QStringList attributes = { "Morphological type", "Functional type" };
_comboAttribSelection->addItems( attributes );
_selectionManager->setGIDs( _domainManager->gids( ));
}
void MainWindow::openBlueConfigThroughDialog( void )
......@@ -361,7 +364,7 @@ namespace visimpl
}
void MainWindow::aboutDialog( void )
void MainWindow::dialogAbout( void )
{
QString msj =
......@@ -443,6 +446,14 @@ namespace visimpl
QMessageBox::about(this, tr( "About ViSimpl" ), msj );
}
void MainWindow::dialogSelectionManagement( void )
{
if( !_selectionManager )
return;
_selectionManager->show( );
}
void MainWindow::togglePlaybackDock( void )
{
if( _ui->actionTogglePlaybackDock->isChecked( ))
......@@ -620,6 +631,15 @@ namespace visimpl
_tfWidget = new TransferFunctionWidget( );
_tfWidget->setMinimumHeight( 150 );
_selectionManager = new SelectionManagerWidget( );
// _selectionManager->setWindowFlags( Qt::D );
_selectionManager->setWindowModality( Qt::WindowModal );
_selectionManager->setMinimumHeight( 300 );
_selectionManager->setMinimumWidth( 500 );
connect( _selectionManager, SIGNAL( selectionChanged( void )),
this, SLOT( selectionManagerChanged( void )));
_deltaTimeBox = new QDoubleSpinBox( );
_deltaTimeBox->setMinimum( 0.00000001 );
_deltaTimeBox->setMaximum( 50 );
......@@ -689,6 +709,10 @@ namespace visimpl
_frameClippingColor->setMinimumSize( 20, 20 );
_frameClippingColor->setMaximumSize( 20, 20 );
_buttonSelectionFromClippingPlanes = new QPushButton( "To selection");
_buttonSelectionFromClippingPlanes->setToolTip( tr( "Create a selection set from elements between planes" ));
QWidget* topContainer = new QWidget( );
QVBoxLayout* verticalLayout = new QVBoxLayout( );
......@@ -743,12 +767,16 @@ namespace visimpl
vcLayout->addWidget( rFunctionGB );
vcContainer->setLayout( vcLayout );
QPushButton* buttonSelectionManager = new QPushButton( "..." );
buttonSelectionManager->setToolTip( tr( "Show the selection management dialog" ));
buttonSelectionManager->setMaximumWidth( 30 );
QGroupBox* selFunctionGB = new QGroupBox( "Current selection");
QHBoxLayout* selLayout = new QHBoxLayout( );
selLayout->setAlignment( Qt::AlignTop );
selLayout->addWidget( new QLabel( "Selection size: " ));
selLayout->addWidget( new QLabel( "Size: " ));
selLayout->addWidget( _selectionSizeLabel );
selLayout->addWidget( buttonSelectionManager );
selLayout->addWidget( _addGroupButton );
selLayout->addWidget( _clearSelectionButton );
selFunctionGB->setLayout( selLayout );
......@@ -760,8 +788,9 @@ namespace visimpl
QGroupBox* gbClippingPlanes = new QGroupBox( "Clipping planes" );
QGridLayout* layoutClippingPlanes = new QGridLayout( );
gbClippingPlanes->setLayout( layoutClippingPlanes );
layoutClippingPlanes->addWidget( _checkClipping, 0, 0, 1, 2 );
layoutClippingPlanes->addWidget( _checkShowPlanes, 0, 2, 1, 2 );
layoutClippingPlanes->addWidget( _checkClipping, 0, 0, 1, 1 );
layoutClippingPlanes->addWidget( _checkShowPlanes, 0, 1, 1, 2 );
layoutClippingPlanes->addWidget( _buttonSelectionFromClippingPlanes, 0, 3, 1, 1 );
layoutClippingPlanes->addWidget( line, 1, 0, 1, 4 );
layoutClippingPlanes->addWidget( _frameClippingColor, 2, 0, 1, 1 );
layoutClippingPlanes->addWidget( _buttonResetPlanes, 2, 1, 1, 1 );
......@@ -926,6 +955,9 @@ namespace visimpl
connect( _tfWidget, SIGNAL( previewColor( void )),
this, SLOT( PreviewSimulationSizeFunction( void )));
connect( buttonSelectionManager, SIGNAL( clicked( void )),
this, SLOT( dialogSelectionManagement( void )));
connect( _deltaTimeBox, SIGNAL( valueChanged( double )),
this, SLOT( updateSimDeltaTime( void )));
......@@ -952,6 +984,9 @@ namespace visimpl
connect( _checkShowPlanes, SIGNAL( stateChanged( int )),
_openGLWidget, SLOT( paintClippingPlanes( int )));
connect( _buttonSelectionFromClippingPlanes, SIGNAL( clicked( void )),
this, SLOT( selectionFromPlanes( void )));
connect( _buttonResetPlanes, SIGNAL( clicked( void )),
this, SLOT( clippingPlanesReset( void )));
......@@ -968,13 +1003,8 @@ namespace visimpl
connect( _frameClippingColor, SIGNAL( clicked( )),
this, SLOT( colorSelectionClicked()));
#ifdef VISIMPL_USE_ZEROEQ
#ifdef VISIMPL_USE_GMRVLEX
connect( _clearSelectionButton, SIGNAL( clicked( void )),
this, SLOT( ClearSelection( void )));
#endif
#endif
this, SLOT( clearSelection( void )));
connect( _addGroupButton, SIGNAL( clicked( void )),
this, SLOT( addGroupFromSelection( )));
......@@ -1218,6 +1248,7 @@ namespace visimpl
_spinBoxClippingWidth->setEnabled( active );
_spinBoxClippingDist->setEnabled( active );
_frameClippingColor->setEnabled( active );
_buttonSelectionFromClippingPlanes->setEnabled( active );
_openGLWidget->clippingPlanes( active );
......@@ -1301,6 +1332,65 @@ namespace visimpl
}
}
void MainWindow::selectionFromPlanes( void )
{
if( !_openGLWidget )
return;
auto ids = _openGLWidget->getPlanesContainedElements( );
visimpl::GIDUSet selectedSet( ids.begin( ), ids.end( ));
if( selectedSet.empty( ))
return;
setSelection( selectedSet, SRC_PLANES );
}
void MainWindow::selectionManagerChanged( void )
{
setSelection( _selectionManager->selected( ), SRC_WIDGET );
}
void MainWindow::_updateSelectionGUI( void )
{
auto selection = _domainManager->selection( );
_addGroupButton->setEnabled( true );
_clearSelectionButton->setEnabled( true );
_selectionSizeLabel->setText( QString::number( selection.size( )));
_selectionSizeLabel->update( );
}
void MainWindow::setSelection( const GIDUSet& selectedSet,
TSelectionSource source_ )
{
if( source_ == SRC_UNDEFINED )
return;
_domainManager->selection( selectedSet );
_openGLWidget->setSelectedGIDs( selectedSet );
if( source_ != SRC_WIDGET )
_selectionManager->setSelected( selectedSet );
_updateSelectionGUI( );
}
void MainWindow::clearSelection( void )
{
if( _openGLWidget )
{
_domainManager->clearSelection( );
_openGLWidget->clearSelection( );
_selectionManager->clearSelection( );
_addGroupButton->setEnabled( false );
_clearSelectionButton->setEnabled( false );
_selectionSizeLabel->setText( "0" );
}
}
#ifdef VISIMPL_USE_ZEROEQ
......@@ -1380,17 +1470,7 @@ namespace visimpl
// pthread_exit( NULL );
//}
void MainWindow::ClearSelection( void )
{
if( _openGLWidget )
{
_openGLWidget->clearSelection( );
_addGroupButton->setEnabled( false );
_clearSelectionButton->setEnabled( false );
_selectionSizeLabel->setText( "0" );
}
}
void MainWindow::_onSelectionEvent( lexis::data::ConstSelectedIDsPtr selected )
{
......@@ -1403,18 +1483,9 @@ namespace visimpl
std::vector< uint32_t > ids = selected->getIdsVector( );
visimpl::GIDUSet selectedSet( ids.begin( ), ids.end( ));
if( selectedSet.size( ) == 0 )
return;
_openGLWidget->setSelectedGIDs( selectedSet );
_addGroupButton->setEnabled( true );
_clearSelectionButton->setEnabled( true );
_selectionSizeLabel->setText( QString::number( selectedSet.size( )));
setSelection( selectedSet, SRC_EXTERNAL );
}
}
......
......@@ -18,6 +18,7 @@
#include <QToolBox>
#include "OpenGLWidget.h"
#include "SelectionManagerWidget.h"
#include <sumrice/sumrice.h>
......@@ -31,6 +32,14 @@ class MainWindow;
namespace visimpl
{
enum TSelectionSource
{
SRC_EXTERNAL = 0,
SRC_PLANES,
SRC_WIDGET,
SRC_UNDEFINED
};
class MainWindow
: public QMainWindow
{
......@@ -63,7 +72,8 @@ namespace visimpl
void openSubsetEventFile( const std::string& fileName,
bool append = false );
void aboutDialog( void );
void dialogAbout( void );
void dialogSelectionManagement( void );
void togglePlaybackDock( void );
void toggleSimConfigDock( void );
......@@ -125,6 +135,11 @@ namespace visimpl
void colorSelectionClicked( void );
void selectionManagerChanged( void );
void setSelection( const GIDUSet& selection_, TSelectionSource source_ = SRC_UNDEFINED );
void clearSelection( void );
void selectionFromPlanes( void );
protected:
void _initSimControlDock( void );
......@@ -134,6 +149,8 @@ namespace visimpl
void _configurePlayer( void );
void _resetClippingParams( void );
void _updateSelectionGUI( void );
bool _showDialog( QColor& current, const QString& message = "" );
......@@ -147,7 +164,6 @@ namespace visimpl
#endif
void ClearSelection( void );
protected:
......@@ -188,8 +204,8 @@ namespace visimpl
QToolBox* _toolBoxOptions;
QGroupBox* _groupBoxTransferFunction;
TransferFunctionEditor* _tfEditor;
TransferFunctionWidget* _tfWidget;
SelectionManagerWidget* _selectionManager;
bool _autoNameGroups;
QGroupBox* _groupBoxGroups;
......@@ -225,6 +241,7 @@ namespace visimpl
QDoubleSpinBox* _spinBoxClippingWidth;
QDoubleSpinBox* _spinBoxClippingDist;
QPushButton* _frameClippingColor;
QPushButton* _buttonSelectionFromClippingPlanes;
};
......
......@@ -123,6 +123,7 @@ namespace visimpl
, _flagUpdateAttributes( false )
, _flagPickingSingle( false )
, _flagChangeShader( false )
, _flagUpdateRender( false )
, _flagModeChange( false )
, _newMode( TMODE_UNDEFINED )
, _flagAttribChange( false )
......@@ -594,9 +595,15 @@ namespace visimpl
_camera->position( )[ 1 ],
_camera->position( )[ 2 ] );
_particleSystem->updateCameraDistances( cameraPosition );
if( _player->isPlaying( ) || _lastCameraPosition != cameraPosition || _flagUpdateRender )
{
_particleSystem->updateCameraDistances( cameraPosition );
_lastCameraPosition = cameraPosition;
_particleSystem->updateRender( );
_lastCameraPosition = cameraPosition;
_flagUpdateRender = false;
}
if( _clipping )
{
......@@ -604,8 +611,6 @@ namespace visimpl
_clippingPlaneRight->activate( _shaderParticlesCurrent, 1 );
}
_particleSystem->updateRender( );
_particleSystem->render( );
if( _clipping )
......@@ -863,6 +868,7 @@ namespace visimpl
_domainManager->mode( _newMode );
_flagModeChange = false;
_flagUpdateRender = true;
if( _domainManager->mode( ) == TMODE_ATTRIBUTE )
emit attributeStatsComputed( );
......@@ -886,14 +892,13 @@ namespace visimpl
{
_particleSystem->run( false );
_domainManager->selection( _selectedGIDs );
updateCameraBoundingBox( );
_particleSystem->run( true );
_particleSystem->update( 0.0f );
_flagUpdateSelection = false;
_flagUpdateRender = true;
}
}
......@@ -972,7 +977,6 @@ namespace visimpl
void OpenGLWidget::clearSelection( void )
{
_domainManager->clearSelection( );
_selectedGIDs.clear( );
_flagUpdateSelection = true;
}
......@@ -1133,7 +1137,7 @@ namespace visimpl
_planesCenter = glmToEigen( currentBoundingBox.first + currentBoundingBox.second ) * 0.5f;
_planeDistance = std::abs( currentBoundingBox.second.x - currentBoundingBox.first.x );
_planeDistance = std::abs( currentBoundingBox.second.x - currentBoundingBox.first.x ) + 1;
_planeHeight = std::abs( currentBoundingBox.second.y - currentBoundingBox.first.y );
_planeWidth = std::abs( currentBoundingBox.second.z - currentBoundingBox.first.z );
......@@ -1213,23 +1217,23 @@ namespace visimpl
centerLeft = transform( centerLeft, center, _planeRotation );
centerRight = transform( centerRight, center, _planeRotation );
evec3 leftNormal = ( center - centerLeft ).normalized( );
evec3 rightNormal = ( center - centerRight ).normalized( );
_planeNormalLeft = ( center - centerLeft ).normalized( );
_planeNormalRight = ( center - centerRight ).normalized( );
_clippingPlaneLeft->setEquationByPointAndNormal( centerLeft, leftNormal );
_clippingPlaneRight->setEquationByPointAndNormal( centerRight, rightNormal );
_clippingPlaneLeft->setEquationByPointAndNormal( centerLeft, _planeNormalLeft );
_clippingPlaneRight->setEquationByPointAndNormal( centerRight, _planeNormalRight );
std::cout << "Planes:" << std::endl
<< " Left: "
<< std::endl << vecToStr( transformedPoints[ 0 ])
<< std::endl << vecToStr( transformedPoints[ 1 ])
<< std::endl << vecToStr( transformedPoints[ 2 ])
<< std::endl
<< " Right: "
<< std::endl << vecToStr( transformedPoints[ 3 ])
<< std::endl << vecToStr( transformedPoints[ 4 ])
<< std::endl << vecToStr( transformedPoints[ 5 ])
<< std::endl;
// std::cout << "Planes:" << std::endl
// << " Left: "
// << std::endl << vecToStr( transformedPoints[ 0 ])
// << std::endl << vecToStr( transformedPoints[ 1 ])
// << std::endl << vecToStr( transformedPoints[ 2 ])
// << std::endl
// << " Right: "
// << std::endl << vecToStr( transformedPoints[ 3 ])
// << std::endl << vecToStr( transformedPoints[ 4 ])
// << std::endl << vecToStr( transformedPoints[ 5 ])
// << std::endl;
......@@ -1353,6 +1357,41 @@ namespace visimpl
_updatePlanes( );
}
GIDVec OpenGLWidget::getPlanesContainedElements( void ) const
{
GIDVec result;
// Project elements
evec3 normal = - _planeNormalLeft;
normal.normalize( );
auto positions = _domainManager->positions( );
result.reserve( positions.size( ));
float distance = 0.0f;
std::cout << "Contained elements: ";
for( auto neuronPos : positions )
{
distance = normal.dot( _planeLeft.points( )[ 0 ] ) -
normal.dot( glmToEigen( neuronPos.second ));
if( distance > 0.0f && distance <= _planeDistance )
{
result.emplace_back( neuronPos.first );
// std::cout << " [" << neuronPos.first << ":" << distance << "]";
}
}
result.shrink_to_fit( );
std::cout << " " << result.size( ) << std::endl;
return result;
}
void OpenGLWidget::mousePressEvent( QMouseEvent* event_ )
{
......
......@@ -201,6 +201,8 @@ namespace visimpl
void changeSimulationDecayValue( float value );
float getSimulationDecayValue( void );
GIDVec getPlanesContainedElements( void ) const;
protected:
void _resolveFlagsOperations( void );
......@@ -314,6 +316,8 @@ namespace visimpl
reto::ClippingPlane* _clippingPlaneLeft;
reto::ClippingPlane* _clippingPlaneRight;
evec3 _planesCenter;
evec3 _planeNormalLeft;
evec3 _planeNormalRight;
std::vector< Eigen::Vector3f > _planePosLeft;
std::vector< Eigen::Vector3f > _planePosRight;
Eigen::Matrix4f _planeRotation;
......@@ -376,6 +380,7 @@ namespace visimpl
bool _flagUpdateAttributes;
bool _flagPickingSingle;
bool _flagChangeShader;
bool _flagUpdateRender;
bool _flagModeChange;
tVisualMode _newMode;
......
/*
* @file SelectionManagerWidget.cpp
* @brief