Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkBinaryThresholdToolGUI.h"
00019 #include "QmitkNewSegmentationDialog.h"
00020
00021 #include <qlabel.h>
00022 #include <qslider.h>
00023 #include <qpushbutton.h>
00024 #include <qlayout.h>
00025
00026 MITK_TOOL_GUI_MACRO(QmitkExt_EXPORT, QmitkBinaryThresholdToolGUI, "")
00027
00028 QmitkBinaryThresholdToolGUI::QmitkBinaryThresholdToolGUI()
00029 :QmitkToolGUI(),
00030 m_Slider(NULL),
00031 m_Spinner(NULL)
00032 {
00033
00034 QBoxLayout* mainLayout = new QVBoxLayout(this);
00035
00036 QLabel* label = new QLabel( "Threshold :", this );
00037 QFont f = label->font();
00038 f.setBold(false);
00039 label->setFont( f );
00040 mainLayout->addWidget(label);
00041
00042
00043 QBoxLayout* layout = new QHBoxLayout();
00044
00045 m_Spinner = new QSpinBox();
00046 m_Spinner->setMaximum(20);
00047 m_Spinner->setMinimum(5);
00048 m_Spinner->setValue(1);
00049
00050 connect(m_Spinner, SIGNAL(valueChanged(int)), this, SLOT(OnSpinnerValueChanged(int)) );
00051 layout->addWidget(m_Spinner);
00052
00053
00054 m_Slider = new QSlider( Qt::Horizontal, this );
00055 m_Slider->setMinimum(5);
00056 m_Slider->setMaximum(20);
00057 m_Slider->setPageStep(1);
00058 m_Slider->setValue(1);
00059 connect( m_Slider, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueChanged(int)));
00060 layout->addWidget( m_Slider );
00061
00062 QPushButton* okButton = new QPushButton("Ok", this);
00063 connect( okButton, SIGNAL(clicked()), this, SLOT(OnAcceptThresholdPreview()));
00064 okButton->setFont( f );
00065 layout->addWidget( okButton );
00066
00067 mainLayout->addLayout(layout);
00068
00069 connect( this, SIGNAL(NewToolAssociated(mitk::Tool*)), this, SLOT(OnNewToolAssociated(mitk::Tool*)) );
00070 }
00071
00072 QmitkBinaryThresholdToolGUI::~QmitkBinaryThresholdToolGUI()
00073 {
00074
00075 if (m_BinaryThresholdTool.IsNotNull())
00076 {
00077 m_BinaryThresholdTool->IntervalBordersChanged -= mitk::MessageDelegate2<QmitkBinaryThresholdToolGUI, int, int>( this, &QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged );
00078 m_BinaryThresholdTool->ThresholdingValueChanged -= mitk::MessageDelegate1<QmitkBinaryThresholdToolGUI, int>( this, &QmitkBinaryThresholdToolGUI::OnThresholdingValueChanged );
00079 }
00080
00081 }
00082
00083 void QmitkBinaryThresholdToolGUI::OnNewToolAssociated(mitk::Tool* tool)
00084 {
00085 if (m_BinaryThresholdTool.IsNotNull())
00086 {
00087 m_BinaryThresholdTool->IntervalBordersChanged -= mitk::MessageDelegate2<QmitkBinaryThresholdToolGUI, int, int>( this, &QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged );
00088 m_BinaryThresholdTool->ThresholdingValueChanged -= mitk::MessageDelegate1<QmitkBinaryThresholdToolGUI, int>( this, &QmitkBinaryThresholdToolGUI::OnThresholdingValueChanged );
00089 }
00090
00091 m_BinaryThresholdTool = dynamic_cast<mitk::BinaryThresholdTool*>( tool );
00092
00093 if (m_BinaryThresholdTool.IsNotNull())
00094 {
00095 m_BinaryThresholdTool->IntervalBordersChanged += mitk::MessageDelegate2<QmitkBinaryThresholdToolGUI, int, int>( this, &QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged );
00096 m_BinaryThresholdTool->ThresholdingValueChanged += mitk::MessageDelegate1<QmitkBinaryThresholdToolGUI, int>( this, &QmitkBinaryThresholdToolGUI::OnThresholdingValueChanged );
00097 }
00098 }
00099
00100 void QmitkBinaryThresholdToolGUI::OnSliderValueChanged(int value)
00101 {
00102 if (m_BinaryThresholdTool.IsNotNull())
00103 {
00104 m_BinaryThresholdTool->SetThresholdValue( value );
00105 }
00106 m_Spinner->setValue(value);
00107 }
00108 void QmitkBinaryThresholdToolGUI::OnAcceptThresholdPreview()
00109 {
00110 if (m_BinaryThresholdTool.IsNotNull())
00111 {
00112 QmitkNewSegmentationDialog* dialog = new QmitkNewSegmentationDialog( this );
00113 dialog->setPrompt("What did you just segment?");
00114 int dialogReturnValue = dialog->exec();
00115
00116 std::string organName = dialog->GetSegmentationName().toStdString();
00117 mitk::Color color = dialog->GetColor();
00118
00119 delete dialog;
00120
00121 if ( dialogReturnValue != QDialog::Rejected )
00122 {
00123 m_BinaryThresholdTool->AcceptCurrentThresholdValue( organName, color );
00124 }
00125 else
00126 {
00127 m_BinaryThresholdTool->CancelThresholding();
00128 }
00129 }
00130 }
00131
00132 void QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged(int lower, int upper)
00133 {
00134 m_Slider->setRange(lower, upper);
00135 m_Spinner->setRange(lower, upper);
00136 }
00137
00138 void QmitkBinaryThresholdToolGUI::OnThresholdingValueChanged(int current)
00139 {
00140 m_Slider->setValue(current);
00141 m_Spinner->setValue(current);
00142 }
00143
00144 void QmitkBinaryThresholdToolGUI::OnSpinnerValueChanged(int value)
00145 {
00146 m_Slider->setValue(value);
00147 }