Skip to content

Commit

Permalink
add test for QGoManualSegmentationDockWidget
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://orchestra.med.harvard.edu/svn/megason/Code/GoFigure2@1619 ef826fda-c0ae-4237-af8e-f8dcbcf7929c
  • Loading branch information
Arnaud Gelas committed Oct 21, 2009
1 parent 30ba52a commit 64f7e04
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
#include "QGoManualSegmentationDockWidget.h"

#include <QColorDialog>
#include <cstdlib>

QGoManualSegmentationDockWidget::
QGoManualSegmentationDockWidget( QWidget* parent ) : QDockWidget( parent )
QGoManualSegmentationDockWidget( QWidget* parent ) :
QDockWidget( parent ),
m_OrderVector( 5, 0 ),
m_ValidatedColor( Qt::red )
{
// m_SettingsDialog = new QGoManualSegmentationSettingsDialog( this );
// QObject::connect( m_SettingsDialog, SIGNAL( accepted() ),
// this,
// SLOT(/*here define the right slot that will update color, line width*/);
m_SettingsDialog = new QGoManualSegmentationSettingsDialog( this );

this->setupUi( this );

QObject::connect( this->SettingsBtn, SIGNAL( pressed() ),
m_SettingsDialog, SLOT( exec() ) );

QObject::connect( m_SettingsDialog, SIGNAL( accepted() ),
this, SLOT( SetContourColor() ) );

QObject::connect( this->IdSpinBox, SIGNAL( valueChanged( int ) ),
this, SLOT( GenerateRandomColorForGivenId( int ) ) );

QObject::connect( this->ReinitializeBtn, SIGNAL( pressed() ),
this, SIGNAL( ReinitializePressed() ) );

// QObject::connect( this->SettingsBtn, SIGNAL( pressed() ),
// m_SettingsDialog, SLOT( show() ) );
QObject::connect( this->ValidateBtn, SIGNAL( pressed() ),
this, SIGNAL( ValidatePressed() ) );

QObject::connect( this->ReinitializeIncrementBtn, SIGNAL( pressed() ),
this, SIGNAL( ReinitializeAndIncrementPressed() ) );
}

QGoManualSegmentationDockWidget::
Expand All @@ -21,43 +41,49 @@ void
QGoManualSegmentationDockWidget::
OnSetColorPressed()
{
// m_ValidatedColor = QColorDialog::getColor( m_ValidatedColor, this,
// tr( "Pick a color for validated contours" ) );
QColor temp = QColorDialog::getColor( m_ValidatedColor, this,
tr( "Pick a color for validated contours" ) );

if( temp != m_ValidatedColor )
{
m_ValidatedColor = temp;
// SetContourColor( m_ValidatedColor );
}
}

void QGoManualSegmentationDockWidget::
SetContourColor( )
{
QColor color = m_SettingsDialog->GetLineColor();
GenerateOrderVector( color );
}

// QColor
// QGoManualSegmentationDockWidget::
// GenerateRandomColorForGivenId( const unsigned int& iId,
// const QColor& iSelectedColor )
// {
// int h, s, v;
// iSelectedColor.getHsv( &h, &s, &v );
//
// int min_hue_diff = 360;
// int closest_hue = -1;
// int hue;
//
// for( int i = 0; i < 6; i++ )
// {
// hue = i * 60;
// diff = vnl_math_abs( h - hue );
// if( diff < min_hue_diff )
// {
// min_hue_diff = diff;
// closest_hue = hue;
// }
// }
//
// if( iId < 6 )
// {
// if( iId * 60 != hue )
// {
// oColor.setHsv( iId * 60, 255, 255 );
// }
// else
// {
//
// }
// }
//
// }
void QGoManualSegmentationDockWidget::
GenerateOrderVector( const QColor& iSelectedColor )
{
int h, s, v;
iSelectedColor.getHsv( &h, &s, &v );

unsigned int closest_id = static_cast< unsigned int >(
floor( static_cast< double >( h ) / 60. + 0.5 ) );

unsigned int k = 0;
for( unsigned int i = 0; i < 6; i++ )
{
if( i != closest_id )
{
m_OrderVector[k] = i;
k++;
}
}
}

void
QGoManualSegmentationDockWidget::
GenerateRandomColorForGivenId( int iId )
{
unsigned int k = static_cast< unsigned int >( iId ) % 5;
int t = 60 * static_cast< int >( m_OrderVector[k] );

m_ValidatedColor.setHsv( rand() % 60 + t, rand() % 256, rand() % 128 + 127 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <QDockWidget>
#include "ui_ManualSegmentationDockWidget.h"

#include "QGoManualSegmentationSettingsDialog.h"

class QGoManualSegmentationDockWidget :
public QDockWidget,
private Ui::ManualSegmentationDockWidget
Expand All @@ -15,12 +17,23 @@ class QGoManualSegmentationDockWidget :

public slots:
void OnSetColorPressed();
void OnReinitializePressed();
void OnValidatePressed();
void OnReinitializeAndIncrementPressed();
void SetContourColor();
void GenerateRandomColorForGivenId( int iId );

signals:
void ReinitializePressed();
void ValidatePressed();
void ReinitializeAndIncrementPressed();

protected:
QHash< unsigned int, QColor > m_IdValidatedColor;
std::vector< unsigned int > m_OrderVector;
QColor m_ValidatedColor;
// QHash< unsigned int, QColor > m_IdValidatedColor;
QGoManualSegmentationSettingsDialog* m_SettingsDialog;

void GenerateOrderVector( const QColor& iSelectedColor );


private:
};

Expand Down
6 changes: 6 additions & 0 deletions branches/GoFigure2Beta/Examples/GUI/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SET( QGOGUILIB_EXAMPLE_SRC
qgotabimageview4d
qgomanualsegmentationsettingsdialog
qgovisualizationdockwidget
qgomanualsegmentationdockwidget
)


Expand Down Expand Up @@ -69,3 +70,8 @@ ADD_TEST( qgovisualizationdockwidgetTest
1
)

ADD_TEST( qgomanualsegmentationdockwidgetTest
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qgomanualsegmentationdockwidget
1
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <QApplication>
#include <QTimer>

#include "QGoManualSegmentationDockWidget.h"

int main( int argc, char** argv )
{
if( argc != 2 )
{
std::cerr <<"qgomanualsegmentationdockwidget requires 1 argument:" <<std::endl;
std::cerr <<"1-test (boolean)" <<std::endl;
return EXIT_FAILURE;
}

QApplication app( argc, argv );
QCoreApplication::setOrganizationName("MegasonLab");
QCoreApplication::setOrganizationDomain( "http://gofigure2.sourceforge.net" );

QGoManualSegmentationDockWidget* dock = new QGoManualSegmentationDockWidget;
dock->show();

QTimer* timer = new QTimer;
timer->setSingleShot( true );
QObject::connect( timer, SIGNAL( timeout() ), dock, SLOT( close() ) );

if( atoi( argv[1] ) == 1 )
{
timer->start( 100 );
}

app.processEvents();
int output = app.exec();
app.closeAllWindows();

delete dock;

return output;
}

0 comments on commit 64f7e04

Please sign in to comment.