00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkBinaryThresholdULToolGUI.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, QmitkBinaryThresholdULToolGUI, "")
00027
00028 QmitkBinaryThresholdULToolGUI::QmitkBinaryThresholdULToolGUI()
00029 :QmitkToolGUI(),
00030 m_RangeSlider(NULL)
00031 {
00032
00033 QBoxLayout* mainLayout = new QVBoxLayout(this);
00034
00035 QLabel* label = new QLabel( "Threshold :", this );
00036 QFont f = label->font();
00037 f.setBold(false);
00038 label->setFont( f );
00039 mainLayout->addWidget(label);
00040
00041 QBoxLayout* layout = new QHBoxLayout();
00042
00043 m_LowerSpinner = new QSpinBox();
00044 m_LowerSpinner->setMinimum(-2048);
00045 m_LowerSpinner->setMaximum(0);
00046 m_LowerSpinner->setValue(-2048);
00047 connect(m_LowerSpinner, SIGNAL(valueChanged(int)), this, SLOT(OnLowerSpinnerChanged(int)) );
00048
00049 m_RangeSlider = new QxtSpanSlider(Qt::Horizontal, this );
00050 m_RangeSlider->setMaximum(2048);
00051 m_RangeSlider->setMinimum(-2048);
00052 m_RangeSlider->setHandleMovementMode(QxtSpanSlider::NoOverlapping);
00053
00054 m_UpperSpinner = new QSpinBox();
00055 m_UpperSpinner->setMinimum(0);
00056 m_UpperSpinner->setMaximum(2048);
00057 m_UpperSpinner->setValue(2048);
00058
00059 connect(m_UpperSpinner, SIGNAL(valueChanged(int)), this, SLOT(OnUpperSpinnerChanged(int)) );
00060 connect(m_RangeSlider, SIGNAL(spanChanged(int, int) ),this, SLOT( OnSpanChanged(int , int ) ));
00061
00062 layout->addWidget(m_LowerSpinner);
00063 layout->addWidget(m_RangeSlider);
00064 layout->addWidget(m_UpperSpinner);
00065
00066 mainLayout->addLayout(layout);
00067
00068 QPushButton* okButton = new QPushButton("Ok", this);
00069 connect( okButton, SIGNAL(clicked()), this, SLOT(OnAcceptThresholdPreview()));
00070 okButton->setFont( f );
00071 mainLayout->addWidget( okButton );
00072
00073 connect( this, SIGNAL(NewToolAssociated(mitk::Tool*)), this, SLOT(OnNewToolAssociated(mitk::Tool*)) );
00074 }
00075
00076 QmitkBinaryThresholdULToolGUI::~QmitkBinaryThresholdULToolGUI()
00077 {
00078
00079 if (m_BinaryThresholdULTool.IsNotNull())
00080 {
00081 m_BinaryThresholdULTool->IntervalBordersChanged -= mitk::MessageDelegate2<QmitkBinaryThresholdULToolGUI, int, int>( this, &QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged );
00082 m_BinaryThresholdULTool->ThresholdingValuesChanged -= mitk::MessageDelegate2<QmitkBinaryThresholdULToolGUI, int, int>( this, &QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged );
00083 }
00084
00085 }
00086
00087 void QmitkBinaryThresholdULToolGUI::OnNewToolAssociated(mitk::Tool* tool)
00088 {
00089 if (m_BinaryThresholdULTool.IsNotNull())
00090 {
00091 m_BinaryThresholdULTool->IntervalBordersChanged -= mitk::MessageDelegate2<QmitkBinaryThresholdULToolGUI, int, int>( this, &QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged );
00092 m_BinaryThresholdULTool->ThresholdingValuesChanged -= mitk::MessageDelegate2<QmitkBinaryThresholdULToolGUI, int, int>( this, &QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged );
00093 }
00094
00095 m_BinaryThresholdULTool = dynamic_cast<mitk::BinaryThresholdULTool*>( tool );
00096
00097 if (m_BinaryThresholdULTool.IsNotNull())
00098 {
00099 m_BinaryThresholdULTool->IntervalBordersChanged += mitk::MessageDelegate2<QmitkBinaryThresholdULToolGUI, int, int>( this, &QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged );
00100 m_BinaryThresholdULTool->ThresholdingValuesChanged += mitk::MessageDelegate2<QmitkBinaryThresholdULToolGUI, int, int>( this, &QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged );
00101 }
00102 }
00103
00104 void QmitkBinaryThresholdULToolGUI::OnAcceptThresholdPreview()
00105 {
00106 if (m_BinaryThresholdULTool.IsNotNull())
00107 {
00108 QmitkNewSegmentationDialog* dialog = new QmitkNewSegmentationDialog( this );
00109 dialog->setPrompt("What did you just segment?");
00110 int dialogReturnValue = dialog->exec();
00111
00112 std::string organName = dialog->GetSegmentationName().toLocal8Bit().data();
00113 mitk::Color color = dialog->GetColor();
00114
00115 delete dialog;
00116
00117 if ( dialogReturnValue != QDialog::Rejected )
00118 {
00119 m_BinaryThresholdULTool->AcceptCurrentThresholdValue( organName, color );
00120 }
00121 else
00122 {
00123 m_BinaryThresholdULTool->CancelThresholding();
00124 }
00125 }
00126 }
00127
00128 void QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged(int lower, int upper)
00129 {
00130 m_RangeSlider->setMaximum(upper);
00131 m_RangeSlider->setMinimum(lower);
00132 m_LowerSpinner->setMaximum(upper);
00133 m_LowerSpinner->setMinimum(lower);
00134 m_UpperSpinner->setMaximum(upper);
00135 m_UpperSpinner->setMinimum(lower);
00136 }
00137
00138 void QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged(int lower, int upper)
00139 {
00140 m_RangeSlider->setSpan(lower, upper);
00141 m_LowerSpinner->setValue(lower);
00142 m_UpperSpinner->setValue(upper);
00143 }
00144
00145 void QmitkBinaryThresholdULToolGUI::OnSpanChanged(int lower, int upper)
00146 {
00147 if (upper < lower)
00148 {
00149 int tmp = upper;
00150 upper = lower;
00151 lower = tmp;
00152 }
00153
00154 if (m_BinaryThresholdULTool.IsNotNull())
00155 {
00156 m_BinaryThresholdULTool->SetThresholdValues(lower, upper);
00157 }
00158 if (m_LowerSpinner->value() != lower)
00159 m_LowerSpinner->setValue(lower);
00160 if (m_UpperSpinner->value() != upper)
00161 m_UpperSpinner->setValue(upper);
00162 }
00163
00164 void QmitkBinaryThresholdULToolGUI::OnLowerSpinnerChanged(int value)
00165 {
00166 m_RangeSlider->setLowerValue(value);
00167 }
00168
00169 void QmitkBinaryThresholdULToolGUI::OnUpperSpinnerChanged(int value)
00170 {
00171 m_RangeSlider->setUpperValue(value);
00172 }
00173