Commit e9828d66 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents 67ebf72e 72ea8ff8
......@@ -49,6 +49,8 @@ W_LOADABLE_MODULE( WMClusterDisplayVoxels )
WMClusterDisplayVoxels::WMClusterDisplayVoxels():
WModule(),
m_currentDisplayMode( CDV_SINGLE ),
m_currentDisplayModeString( "" ),
m_moduleNode( new WGEGroupNode() ),
m_dendrogramNode( new WGEGroupNode() ),
m_meshNode( new WGEGroupNode() ),
......@@ -110,6 +112,21 @@ void WMClusterDisplayVoxels::properties()
// Group selection
m_groupSelection = m_properties->addPropertyGroup( "Cluster selections", "Groups the different cluster selection methods" ); //NOLINT
m_clusterSelectionsList = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_clusterSelectionsList->addItem( "Single", "" );
m_clusterSelectionsList->addItem( "Biggest", "" );
m_clusterSelectionsList->addItem( "X Clusters", "" );
m_clusterSelectionsList->addItem( "Similarity", "" );
m_clusterSelectionsList->addItem( "Levels from top", "" );
m_clusterSelectionsList->addItem( "Minimum branch length", "" );
m_clusterSelectionsList->addItem( "Loaded partition", "" );
m_clusterSelection = m_groupSelection->addProperty( "Selection method", "selection",
m_clusterSelectionsList->getSelectorFirst(), m_propCondition );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_clusterSelection );
m_propSelectedCluster = m_groupSelection->addProperty( "Selected Cluster", "", 0, m_propCondition );
m_propSelectedCluster->setMin( 0 );
m_propSelectedCluster->setMax( 0 );
......@@ -133,20 +150,29 @@ void WMClusterDisplayVoxels::properties()
m_propSelectedLoadedPartion->setMin( 1 );
m_propSelectedLoadedPartion->setMax( 1 );
m_propShowSelectedButtons = m_groupSelection->addProperty( "Show Buttons", "Shows/Hides the buttons for selected cluster on the left side", true, m_propCondition ); //NOLINT
// Group branch length
m_groupMinBranchLength = m_properties->addPropertyGroup( "Branch length", "Cluster Selection depending on the distance of a cluster to it's parent" ); //NOLINT
m_propMinBranchLength = m_groupMinBranchLength->addProperty( "Minimum branch length", "", 0.1, m_propCondition );
m_propMinBranchLength = m_groupSelection->addProperty( "Minimum branch length", "", 0.1, m_propCondition );
m_propMinBranchLength->setMin( 0.0 );
m_propMinBranchLength->setMax( 1.0 );
m_propMinBranchSize = m_groupMinBranchLength->addProperty( "Minimum branch size", "", 50, m_propCondition );
m_propMinBranchSize = m_groupSelection->addProperty( "Minimum branch size", "", 50, m_propCondition );
m_propMinBranchSize->setMin( 1 );
m_propMinBranchSize->setMax( 500 );
m_buttonExecuteSelection = m_groupSelection->addProperty( "Update", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
m_propShowSelectedButtons = m_groupSelection->addProperty( "Show Buttons", "Shows/Hides the buttons for selected cluster on the left side", true, m_propCondition ); //NOLINT
m_buttonLabelList = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_buttonLabelList->addItem( "Number", "" );
m_buttonLabelList->addItem( "Size", "" );
m_buttonLabelList->addItem( "Level", "" );
m_buttonLabelList->addItem( "Similarity", "" );
m_buttonLabelSelection = m_groupSelection->addProperty( "Button label", "selection",
m_buttonLabelList->getSelectorFirst(), m_propCondition );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_buttonLabelSelection );
// Group Triangulation
m_groupTriangulation = m_properties->addPropertyGroup( "Triangulation", "Groups the triangulation properties" ); //NOLINT
m_propShowVoxelTriangulation = m_groupTriangulation->addProperty( "Triangulate", "", false, m_propCondition );
......@@ -178,10 +204,13 @@ void WMClusterDisplayVoxels::properties()
m_propDendrogramOffsetY->setMax( 1000 );
m_groupSelection->setHidden( true );
m_groupMinBranchLength->setHidden( true );
m_groupTriangulation->setHidden( true );
m_groupDendrogram->setHidden( true );
m_buttonUpdateOutput = m_properties->addProperty( "Update output", "Updates the output connector",
WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
// Info properties
m_infoCountLeafes = m_infoProperties->addProperty( "Count voxels", "", 0 );
m_infoCountClusters = m_infoProperties->addProperty( "Count clusters", "", 0 );
......@@ -277,9 +306,7 @@ void WMClusterDisplayVoxels::moduleMain()
{
m_propReadTrigger->setHidden( true );
m_propClusterFile->setHidden( true );
m_groupSelection->setHidden( false );
m_groupMinBranchLength->setHidden( false );
m_groupTriangulation->setHidden( false );
m_groupDendrogram->setHidden( false );
......@@ -293,13 +320,7 @@ void WMClusterDisplayVoxels::moduleMain()
{
createTexture();
setPropertyBoundaries();
initWidgets();
m_selectionChanged = true;
updateWidgets();
m_dendrogramGeode = new WDendrogramGeode( &m_tree, m_rootCluster, 1000, 500 );
m_camera->addChild( m_dendrogramGeode );
m_propSelectedCluster->get( true );
m_propSelectedLoadedPartion->get( true );
......@@ -310,7 +331,10 @@ void WMClusterDisplayVoxels::moduleMain()
m_propMinBranchLength->get( true );
m_propMinBranchSize->get( true );
m_propLevelsFromTop->get( true );
m_propHideOutliers->get( true );
m_showNotInClusters->get( true );
updateAll();
}
// main loop, respond to controls
......@@ -323,54 +347,79 @@ void WMClusterDisplayVoxels::moduleMain()
break;
}
if( m_propSelectedCluster->changed() )
{
m_activatedClusters.clear();
m_activatedClusters.push_back( m_propSelectedCluster->get( true ) );
m_currentDisplayMode = CDV_SINGLE;
updateAll();
}
if( m_propXBiggestClusters->changed() )
{
m_activatedClusters = m_tree.findXBiggestClusters2( m_propSelectedCluster->get(), m_propXBiggestClusters->get( true ) );
m_currentDisplayMode = CDV_BIGGEST;
updateAll();
}
if( m_propXClusters->changed() )
if ( m_clusterSelection->changed( true ) )
{
m_activatedClusters = m_tree.findXClusters( m_propSelectedCluster->get(), m_propXClusters->get( true ) );
m_currentDisplayMode = CDV_X;
updateAll();
}
if ( m_propValue->changed() )
{
m_activatedClusters = m_tree.findClustersForValue( m_propValue->get( true ) );
m_currentDisplayMode = CDV_SIMILARITY;
updateAll();
}
if ( m_propMinBranchLength->changed() || m_propMinBranchSize->changed() )
{
m_activatedClusters = m_tree.findClustersForBranchLength( m_propMinBranchLength->get( true ), m_propMinBranchSize->get( true ) );
m_currentDisplayMode = CDV_MINBRANCHLENGTH;
updateAll();
}
if ( m_propLevelsFromTop->changed() || m_propHideOutliers->changed() )
{
m_activatedClusters = m_tree.downXLevelsFromTop( m_propLevelsFromTop->get( true ), m_propHideOutliers->get( true ) );
m_currentDisplayMode = CDV_LEVELSFROMTOP;
updateAll();
m_propSelectedCluster->setHidden( true );
m_propXBiggestClusters->setHidden( true );
m_propXClusters->setHidden( true );
m_propValue->setHidden( true );
m_propLevelsFromTop->setHidden( true );
m_propHideOutliers->setHidden( true );
m_propMinBranchLength->setHidden( true );
m_propMinBranchSize->setHidden( true );
m_propSelectedLoadedPartion->setHidden( true );
switch ( m_clusterSelection->get( true ).getItemIndexOfSelected( 0 ) )
{
case 0:
m_propSelectedCluster->setHidden( false );
break;
case 1:
m_propXBiggestClusters->setHidden( false );
break;
case 2:
m_propXClusters->setHidden( false );
break;
case 3:
m_propValue->setHidden( false );
break;
case 4:
m_propLevelsFromTop->setHidden( false );
m_propHideOutliers->setHidden( false );
break;
case 5:
m_propMinBranchLength->setHidden( false );
m_propMinBranchSize->setHidden( false );
break;
case 6:
m_propSelectedLoadedPartion->setHidden( false );
break;
default:
m_propSelectedCluster->setHidden( false );
break;
}
}
if ( m_propSelectedLoadedPartion->changed() )
if ( m_buttonExecuteSelection->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
{
m_activatedClusters = m_loadedPartitions[ m_propSelectedLoadedPartion->get( true ) - 1 ];
m_currentDisplayMode = CDV_LOADED;
m_buttonExecuteSelection->set( WPVBaseTypes::PV_TRIGGER_READY, false );
switch ( m_clusterSelection->get( true ).getItemIndexOfSelected( 0 ) )
{
case 0:
m_currentDisplayMode = CDV_SINGLE;
break;
case 1:
m_currentDisplayMode = CDV_BIGGEST;
break;
case 2:
m_currentDisplayMode = CDV_X;
break;
case 3:
m_currentDisplayMode = CDV_SIMILARITY;
break;
case 4:
m_currentDisplayMode = CDV_LEVELSFROMTOP;
break;
case 5:
m_currentDisplayMode = CDV_MINBRANCHLENGTH;
break;
case 6:
m_currentDisplayMode = CDV_LOADED;
break;
default:
m_currentDisplayMode = CDV_SINGLE;
break;
}
updateAll();
}
......@@ -390,12 +439,23 @@ void WMClusterDisplayVoxels::moduleMain()
handleMinSizeChanged();
}
if ( m_buttonLabelSelection->changed() )
{
setButtonLabels();
}
if ( m_propShowDendrogram->changed( true ) || m_propResizeWithWindow->changed( true ) || m_propDendrogramSizeX->changed( true ) ||
m_propDendrogramSizeY->changed( true ) || m_propDendrogramOffsetX->changed( true ) || m_propDendrogramOffsetY->changed( true ) ||
m_propPlotHeightByLevel->changed( true ) || m_propShowSelectedButtons->changed( true ) )
m_propPlotHeightByLevel->changed( true ) || m_propShowSelectedButtons->changed() )
{
m_dendrogramDirty = true;
}
if ( m_buttonUpdateOutput->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
{
updateOutDataset();
m_buttonUpdateOutput->set( WPVBaseTypes::PV_TRIGGER_READY, false );
}
}
con.disconnect();
......@@ -405,6 +465,42 @@ void WMClusterDisplayVoxels::moduleMain()
void WMClusterDisplayVoxels::updateAll()
{
switch ( m_currentDisplayMode )
{
case CDV_SINGLE:
m_activatedClusters.clear();
m_activatedClusters.push_back( m_propSelectedCluster->get( true ) );
m_currentDisplayModeString = std::string( "Single selection" );
break;
case CDV_BIGGEST:
m_activatedClusters = m_tree.findXBiggestClusters2( m_propSelectedCluster->get(), m_propXBiggestClusters->get( true ) );
m_currentDisplayModeString = std::string( "Biggest clusters" );
break;
case CDV_X:
m_activatedClusters = m_tree.findXClusters( m_propSelectedCluster->get(), m_propXClusters->get( true ) );
m_currentDisplayModeString = std::string( "X clusters" );
break;
case CDV_SIMILARITY:
m_activatedClusters = m_tree.findClustersForValue( m_propValue->get( true ) );
m_currentDisplayModeString = std::string( "Similarity value selection" );
break;
case CDV_LEVELSFROMTOP:
m_activatedClusters = m_tree.downXLevelsFromTop( m_propLevelsFromTop->get( true ), m_propHideOutliers->get( true ) );
m_currentDisplayModeString = std::string( "Levels from top" );
break;
case CDV_MINBRANCHLENGTH:
m_activatedClusters = m_tree.findClustersForBranchLength( m_propMinBranchLength->get( true ), m_propMinBranchSize->get( true ) );
m_currentDisplayModeString = std::string( "Minimum branch length" );
break;
case CDV_LOADED:
m_activatedClusters = m_loadedPartitions[ m_propSelectedLoadedPartion->get( true ) - 1 ];
m_currentDisplayModeString = std::string( "Loaded Partition" );
break;
default:
break;
};
// set colors for cluster in the tree
m_tree.colorCluster( m_tree.getClusterCount() - 1, WColor( 0.3, 0.3, 0.3, 1.0 ) );
for ( size_t k = 0; k < m_activatedClusters.size(); ++k )
......@@ -458,7 +554,6 @@ void WMClusterDisplayVoxels::updateAll()
}
m_texture->dirtyTextureObject();
createMesh();
renderMesh();
......@@ -732,7 +827,8 @@ void WMClusterDisplayVoxels::updateWidgets()
int height = viewer->getCamera()->getViewport()->height();
int width = viewer->getCamera()->getViewport()->width();
int rows = height / 20;
int rows = ( height - 20 ) / 20;
int buttonWidth = 70;
if ( ( height != m_oldViewHeight ) || width != m_oldViewWidth )
{
......@@ -742,12 +838,14 @@ void WMClusterDisplayVoxels::updateWidgets()
m_dendrogramDirty = true;
}
if ( !widgetClicked() && !m_dendrogramDirty )
bool buttonClicked = widgetClicked();
if ( !buttonClicked && !m_dendrogramDirty )
{
return;
}
if ( m_selectionChanged || m_propShowSelectedButtons->changed( true ) )
if ( m_selectionChanged || m_propShowSelectedButtons->changed() || m_dendrogramDirty )
{
for ( size_t i = 0; i < m_activeClustersButtonList.size(); ++i )
{
......@@ -756,16 +854,14 @@ void WMClusterDisplayVoxels::updateWidgets()
m_activeClustersButtonList.clear();
if ( m_propShowSelectedButtons->get() )
if ( m_propShowSelectedButtons->get( true ) )
{
for ( size_t i = 0; i < m_activatedClusters.size(); ++i )
{
osg::ref_ptr<WOSGButton> newButton = osg::ref_ptr<WOSGButton>( new WOSGButton( std::string( "" ),
osgWidget::Box::VERTICAL, true, true ) );
newButton->setPosition( osg::Vec3( 5.f + ( i / rows ) * 60, ( i % rows ) * 20.f, 0 ) );
newButton->setPosition( osg::Vec3( 5.f + ( i / rows ) * buttonWidth, ( i % rows ) * 20.f, 0 ) );
newButton->setId( m_activatedClusters[i] );
//newButton->setLabel( boost::lexical_cast<std::string>( m_tree.size( m_activatedClusters[i] ) ) );
newButton->setLabel( boost::lexical_cast<std::string>( m_activatedClusters[i] ) );
newButton->managed( m_wm );
m_wm->addChild( newButton );
m_activeClustersButtonList.push_back( newButton );
......@@ -773,10 +869,38 @@ void WMClusterDisplayVoxels::updateWidgets()
}
}
setButtonLabels();
osg::ref_ptr<WOSGButton> newButton = osg::ref_ptr<WOSGButton>( new WOSGButton( std::string( "" ),
osgWidget::Box::VERTICAL, true, true ) );
newButton->setPosition( osg::Vec3( 5.f, height - 20.f, 0 ) );
newButton->setId( 0 );
newButton->setLabel( m_currentDisplayModeString );
newButton->managed( m_wm );
m_wm->addChild( newButton );
m_activeClustersButtonList.push_back( newButton );
newButton->setBackgroundColor( wge::getNthHSVColor( m_currentDisplayMode ) );
m_selectionChanged = false;
}
m_wm->resizeAllWindows();
if ( m_propShowSelectedButtons && buttonClicked )
{
m_tree.colorCluster( m_tree.getClusterCount() - 1, WColor( 0.3, 0.3, 0.3, 1.0 ) );
for ( size_t k = 0; k < m_activatedClusters.size(); ++k )
{
if ( m_activeClustersButtonList[k]->pushed() )
{
size_t current = m_activatedClusters[k];
m_tree.colorCluster( current, wge::getNthHSVColor( k ) );
}
}
m_dendrogramDirty = true;
}
if ( m_dendrogramDirty )
{
m_camera->removeChild( m_dendrogramGeode );
......@@ -794,8 +918,8 @@ void WMClusterDisplayVoxels::updateWidgets()
if ( m_propShowSelectedButtons->get() )
{
m_dendrogramGeode = new WDendrogramGeode( &m_tree, m_tree.getClusterCount() - 1, m_propPlotHeightByLevel->get( true ),
m_propMinSizeToColor->get(), width - ( ( m_activatedClusters.size() / rows ) + 1 ) * 62, height / 2 ,
( ( m_activatedClusters.size() / rows ) + 1 ) * 60 );
m_propMinSizeToColor->get(), width - ( ( m_activatedClusters.size() / rows ) + 1 ) * buttonWidth, height / 2 ,
( ( m_activatedClusters.size() / rows ) + 1 ) * buttonWidth );
}
else
{
......@@ -817,7 +941,7 @@ void WMClusterDisplayVoxels::updateWidgets()
bool WMClusterDisplayVoxels::widgetClicked()
{
bool clicked = false;
bool biggestClusterSelectionChanged = false;
bool selectionChanged = false;
for ( size_t i = 0; i < m_activeClustersButtonList.size(); ++i )
{
......@@ -825,25 +949,30 @@ bool WMClusterDisplayVoxels::widgetClicked()
{
if ( m_activeClustersButtonList[i]->getId() < 10000000 )
{
biggestClusterSelectionChanged = true;
selectionChanged = true;
clicked = true;
}
else
{
clicked = true;
m_propSelectedCluster->set( m_activeClustersButtonList[i]->getId() - 10000000 );
}
}
}
if ( biggestClusterSelectionChanged )
if ( selectionChanged )
{
std::vector<size_t>activeClusters;
for ( size_t i = 0; i < m_activeClustersButtonList.size(); ++i )
{
if ( m_activeClustersButtonList[i]->pushed() )
{
activeClusters.push_back( m_activeClustersButtonList[i]->getId() );
if ( m_outputGeodes.size() > i )
{
m_outputGeodes[i]->setNodeMask( 0xFFFFFFFF );
}
}
else
{
if ( m_outputGeodes.size() > i )
{
m_outputGeodes[i]->setNodeMask( 0x00000000 );
}
}
}
}
......@@ -863,3 +992,71 @@ void WMClusterDisplayVoxels::dendrogramClick( WPickInfo pickInfo )
std::cout << cluster << std::endl;
m_propSelectedCluster->set( cluster );
}
void WMClusterDisplayVoxels::updateOutDataset()
{
WAssert( m_dataSet, "" );
WAssert( m_dataSet->getValueSet(), "" );
WAssert( m_dataSet->getGrid(), "" );
boost::shared_ptr< std::vector< float > >ptr( new std::vector< float >( m_data.size() ) );
for ( size_t i = 0; i < m_data.size(); ++i )
{
ptr->at( i ) = static_cast<float>( m_data[i] );
}
boost::shared_ptr< WValueSet< float > > vs =
boost::shared_ptr< WValueSet< float > >( new WValueSet< float >( 0, 1, ptr, W_DT_FLOAT ) );
m_outData = boost::shared_ptr< WDataSetScalar >( new WDataSetScalar( vs, m_grid ) );
m_output->updateData( m_outData );
}
void WMClusterDisplayVoxels::setButtonLabels()
{
if ( m_propShowSelectedButtons->get() )
{
std::string ns;
for ( size_t i = 0; i < m_activatedClusters.size(); ++i )
{
if ( m_buttonLabelSelection->get( true ).getItemIndexOfSelected( 0 ) == 0 )
{
ns = boost::lexical_cast<std::string>( m_activatedClusters[i] );
}
else if ( m_buttonLabelSelection->get( true ).getItemIndexOfSelected( 0 ) == 1 )
{
ns = boost::lexical_cast<std::string>( m_tree.size( m_activatedClusters[i] ) );
}
else if ( m_buttonLabelSelection->get( true ).getItemIndexOfSelected( 0 ) == 2 )
{
ns = boost::lexical_cast<std::string>( m_tree.getLevel( m_activatedClusters[i] ) );
}
else
{
ns = boost::lexical_cast<std::string>( m_tree.getCustomData( m_activatedClusters[i] ) );
if ( ns.size() > 8 )
{
ns = ns.substr( 0, 8 );
}
}
for ( size_t k = 8 - ns.size(); k > 0; --k )
{
if ( k %2 == 1 )
{
ns = std::string( " " ) + ns;
}
else
{
ns = ns + std::string( " " );
}
}
if ( m_activeClustersButtonList.size() > i )
{
m_activeClustersButtonList[i]->setLabel( ns );
}
}
}
}
......@@ -186,6 +186,17 @@ private:
*/
void dendrogramClick( WPickInfo pickInfo );
/**
* update the output connector on demand, for performance reasons this is not done every time
* a change to the cluster selection is applied
*/
void updateOutDataset();
/**
* helper function to set the label on the in scene buttons depending on which labeling scheme is selected
*/
void setButtonLabels();
/**
* An input connector that accepts order 1 datasets.
......@@ -316,12 +327,6 @@ private:
*/
WPropGroup m_groupTriangulation;
/**
* grouping the properties controlling cluster selection for minimum branch length
*/
WPropGroup m_groupMinBranchLength;
/**
* controls the display of the dendrogram overlay
*/
......@@ -394,6 +399,36 @@ private:
WPropInt m_infoMaxLevel; //!< info property
std::vector< std::vector<size_t> >m_loadedPartitions; //!< set partitions loaded from file
/**
* updates the output connector on demand, as we don't want to do this every paint command
*/
WPropTrigger m_buttonUpdateOutput;
/**
* A list of cluster selection methods
*/
boost::shared_ptr< WItemSelection > m_clusterSelectionsList;
/**
* Selection property for clusters
*/
WPropSelection m_clusterSelection;
/**
* triggers the cluster selection update
*/
WPropTrigger m_buttonExecuteSelection;
/**
* A list of button labels
*/
boost::shared_ptr< WItemSelection > m_buttonLabelList;
/**
* Selection property for button labels
*/
WPropSelection m_buttonLabelSelection;