diff --git a/Modules/QtWidgetsExt/QmitkColorTransferFunctionCanvas.h b/Modules/QtWidgetsExt/QmitkColorTransferFunctionCanvas.h index d4df17deab..52baa4f2f0 100755 --- a/Modules/QtWidgetsExt/QmitkColorTransferFunctionCanvas.h +++ b/Modules/QtWidgetsExt/QmitkColorTransferFunctionCanvas.h @@ -1,119 +1,119 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKCOLORTRANSFERFUNCTIONCANVAS_H_INCLUDED #define QMITKCOLORTRANSFERFUNCTIONCANVAS_H_INCLUDED #include "QmitkTransferFunctionCanvas.h" #include "MitkQtWidgetsExtExports.h" #include class MitkQtWidgetsExt_EXPORT QmitkColorTransferFunctionCanvas: public QmitkTransferFunctionCanvas { Q_OBJECT public: QmitkColorTransferFunctionCanvas( QWidget* parent = 0, Qt::WindowFlags f = 0 ) ; virtual void paintEvent( QPaintEvent* e ); int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32); void SetTitle(const QString& title); void SetColorTransferFunction(vtkColorTransferFunction* colorTransferFunction) { this->m_ColorTransferFunction = colorTransferFunction; this->SetMin(colorTransferFunction->GetRange()[0]); this->SetMax(colorTransferFunction->GetRange()[1]); setEnabled(true); update(); } int AddFunctionPoint(double x, double) { return m_ColorTransferFunction->AddRGBPoint(x,m_ColorTransferFunction->GetRedValue(x),m_ColorTransferFunction->GetGreenValue(x),m_ColorTransferFunction->GetBlueValue(x)); } void RemoveFunctionPoint(double x) { int old_size = GetFunctionSize(); m_ColorTransferFunction->RemovePoint(x); if (GetFunctionSize() + 1 != old_size) { std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl; std::cout << "called with x=" << x << std::endl; } } double GetFunctionX(int index) { return m_ColorTransferFunction->GetDataPointer()[index*4]; } int GetFunctionSize() { return m_ColorTransferFunction->GetSize(); } void DoubleClickOnHandle(int handle); void MoveFunctionPoint(int index, std::pair pos); void AddRGB(double x, double r, double g, double b); double GetFunctionMax() { return m_ColorTransferFunction->GetRange()[1]; } double GetFunctionMin() { return m_ColorTransferFunction->GetRange()[0]; } double GetFunctionRange() { double range; if((m_ColorTransferFunction->GetRange()[0])==0) { range = m_ColorTransferFunction->GetRange()[1]; return range; } else { range = (m_ColorTransferFunction->GetRange()[1])-(m_ColorTransferFunction->GetRange()[0]); return range; } } void RemoveAllFunctionPoints() { m_ColorTransferFunction->AddRGBSegment(this->GetFunctionMin(),1,0,0,this->GetFunctionMax(),1,1,0); } - float GetFunctionY(int) + double GetFunctionY(int) { return 0.0; } protected: vtkColorTransferFunction* m_ColorTransferFunction; QString m_Title; }; #endif diff --git a/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.cpp b/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.cpp index 9045304895..896dd74620 100755 --- a/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.cpp +++ b/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.cpp @@ -1,158 +1,162 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkPiecewiseFunctionCanvas.h" #include #include QmitkPiecewiseFunctionCanvas::QmitkPiecewiseFunctionCanvas(QWidget * parent, Qt::WindowFlags f) : QmitkTransferFunctionCanvas(parent, f), m_PiecewiseFunction(0) { // used for drawing a border setContentsMargins(1,1,1,1); } void QmitkPiecewiseFunctionCanvas::SetTitle(const QString& title) { m_Title=title; } void QmitkPiecewiseFunctionCanvas::paintEvent(QPaintEvent*) { QPainter painter(this); PaintHistogram(painter); if (m_Title.size()>0) { painter.setPen(Qt::black); painter.drawText(QPoint(11,21),m_Title); painter.setPen(Qt::white); painter.drawText(QPoint(10,20),m_Title); } { QString qs_min = QString::number( m_Min ); QString qs_max = QString::number( m_Max ); QRect qr_min = painter.fontMetrics().boundingRect( qs_min ); QRect qr_max = painter.fontMetrics().boundingRect( qs_max ); int y,x; y=this->contentsRect().height()-qr_min.height()+5; x=10; // Fill the tf presets in the generator widget painter.setPen(Qt::black); painter.drawText(QPoint(x+1,y+1),qs_min); painter.setPen(Qt::white); painter.drawText(QPoint(x ,y ),qs_min); y=this->contentsRect().height()-qr_max.height()+5; x=this->contentsRect().width()-qr_max.width()-6; painter.setPen(Qt::black); painter.drawText(QPoint(x,y+1),qs_max); painter.setPen(Qt::white); painter.drawText(QPoint(x,y ),qs_max); } painter.setPen(Qt::gray); QRect contentsRect = this->contentsRect(); painter.drawRect(0, 0, contentsRect.width()+1, contentsRect.height()+1); if (m_PiecewiseFunction && this->isEnabled()) { double* dp = m_PiecewiseFunction->GetDataPointer(); // Render lines painter.setPen(Qt::black); for (int i = -1; i < m_PiecewiseFunction->GetSize(); i++) { std::pair left; std::pair right; if(i < 0) left = this->FunctionToCanvas(std::make_pair(-32768, dp[0 * 2 + 1])); else left = this->FunctionToCanvas(std::make_pair(dp[i * 2], dp[i * 2 + 1])); if(i+1 >= m_PiecewiseFunction->GetSize()) right = this->FunctionToCanvas(std::make_pair(32768, dp[(i ) * 2 + 1])); else right = this->FunctionToCanvas(std::make_pair(dp[(i+1) * 2], dp[(i+1) * 2 + 1])); painter.drawLine(left.first, left.second, right.first, right.second); } // Render Points for (int i = 0; i < m_PiecewiseFunction->GetSize(); i++) { std::pair point = this->FunctionToCanvas(std::make_pair( dp[i * 2], dp[i * 2 + 1])); if (i == m_GrabbedHandle) { painter.setBrush(QBrush(Qt::red)); if (m_LineEditAvailable) { + int xCursor = m_XEdit->cursorPosition(); + int yCursor = m_YEdit->cursorPosition(); m_XEdit->setText(QString::number(GetFunctionX(m_GrabbedHandle))); - m_YEdit->setText(QString::number(GetFunctionY(m_GrabbedHandle), 'f', 5)); + m_YEdit->setText(QString::number(GetFunctionY(m_GrabbedHandle))); + m_XEdit->setCursorPosition( xCursor ); + m_YEdit->setCursorPosition( yCursor ); } } else { painter.setBrush(QBrush(Qt::green)); } painter.drawEllipse(point.first - 4, point.second - 4, 8, 8); } painter.setBrush(Qt::NoBrush); } } int QmitkPiecewiseFunctionCanvas::GetNearHandle(int x, int y, unsigned int maxSquaredDistance) { double* dp = m_PiecewiseFunction->GetDataPointer(); for (int i = 0; i < m_PiecewiseFunction->GetSize(); i++) { std::pair point = this->FunctionToCanvas(std::make_pair(dp[i * 2], dp[i * 2 + 1])); if ((unsigned int) ((point.first - x) * (point.first - x) + (point.second - y) * (point.second - y)) <= maxSquaredDistance) { return i; } } return -1; } void QmitkPiecewiseFunctionCanvas::MoveFunctionPoint(int index, std::pair pos) { RemoveFunctionPoint(GetFunctionX(index)); m_GrabbedHandle = AddFunctionPoint(pos.first, pos.second); } diff --git a/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.h b/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.h index 5f6fd9453a..e885f45685 100755 --- a/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.h +++ b/Modules/QtWidgetsExt/QmitkPiecewiseFunctionCanvas.h @@ -1,130 +1,130 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKPIECEWISEFUNCTIONCANVAS_H_INCLUDED #define QMITKPIECEWISEFUNCTIONCANVAS_H_INCLUDED #include "QmitkTransferFunctionCanvas.h" #include "MitkQtWidgetsExtExports.h" #include class MitkQtWidgetsExt_EXPORT QmitkPiecewiseFunctionCanvas: public QmitkTransferFunctionCanvas { Q_OBJECT public: QmitkPiecewiseFunctionCanvas( QWidget * parent=0, Qt::WindowFlags f = 0 ); virtual void paintEvent( QPaintEvent* e ); void SetTitle(const QString& title); int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32); void SetPiecewiseFunction(vtkPiecewiseFunction* piecewiseFunction) { this->m_PiecewiseFunction = piecewiseFunction; this->SetMin(m_PiecewiseFunction->GetRange()[0]); this->SetMax(m_PiecewiseFunction->GetRange()[1]); setEnabled(true); update(); } int AddFunctionPoint(double x,double val) { return m_PiecewiseFunction->AddPoint(x,val); } void RemoveFunctionPoint(double x) { int old_size = GetFunctionSize(); m_PiecewiseFunction->RemovePoint(x); if (GetFunctionSize() + 1 != old_size) { std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl; std::cout << "called with x=" << x << std::endl; } } double GetFunctionX(int index) { return m_PiecewiseFunction->GetDataPointer()[index*2]; } - float GetFunctionY(int index) + double GetFunctionY(int index) { return m_PiecewiseFunction->GetValue(m_PiecewiseFunction->GetDataPointer()[index*2]); } int GetFunctionSize() { return m_PiecewiseFunction->GetSize(); } void DoubleClickOnHandle(int) { } void MoveFunctionPoint(int index, std::pair pos); double GetFunctionMax() { return m_PiecewiseFunction->GetRange()[1]; } double GetFunctionMin() { return m_PiecewiseFunction->GetRange()[0]; } double GetFunctionRange() { double range; if((m_PiecewiseFunction->GetRange()[0])<0) { range = (m_PiecewiseFunction->GetRange()[1])-(m_PiecewiseFunction->GetRange()[0]); return range; } else { range = m_PiecewiseFunction->GetRange()[1]; return range; } } void RemoveAllFunctionPoints() { m_PiecewiseFunction->AddSegment(this->GetFunctionMin(),0,this->GetFunctionMax(),1); m_PiecewiseFunction->AddPoint(0.0,0.0); } void ResetGO() { //Gradient Opacity m_PiecewiseFunction->AddSegment(this->GetFunctionMin(),0,0,1); m_PiecewiseFunction->AddSegment(0,1,((this->GetFunctionRange())*0.125),1); m_PiecewiseFunction->AddSegment(((this->GetFunctionRange())*0.125),1,((this->GetFunctionRange())*0.2),1); m_PiecewiseFunction->AddSegment(((this->GetFunctionRange())*0.2),1,((this->GetFunctionRange())*0.25),1); } protected: vtkPiecewiseFunction* m_PiecewiseFunction; QString m_Title; }; #endif diff --git a/Modules/QtWidgetsExt/QmitkTransferFunctionCanvas.h b/Modules/QtWidgetsExt/QmitkTransferFunctionCanvas.h index a8f1176734..fdb39a3b82 100755 --- a/Modules/QtWidgetsExt/QmitkTransferFunctionCanvas.h +++ b/Modules/QtWidgetsExt/QmitkTransferFunctionCanvas.h @@ -1,168 +1,168 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKTRANSFERFUNCTIONCANVAS_H_INCLUDED #define QMITKTRANSFERFUNCTIONCANVAS_H_INCLUDED #include "MitkQtWidgetsExtExports.h" #include #include #include #include class MitkQtWidgetsExt_EXPORT QmitkTransferFunctionCanvas : public QWidget { Q_OBJECT public: QmitkTransferFunctionCanvas( QWidget * parent=0, Qt::WindowFlags f = 0 ); mitk::SimpleHistogram* GetHistogram() { return m_Histogram; } void SetHistogram(mitk::SimpleHistogram *histogram) { m_Histogram = histogram; } double GetMin() { return m_Min; } void SetMin(double min) { this->m_Min = min; SetLower(min); } double GetMax() { return m_Max; } void SetMax(double max) { this->m_Max = max; SetUpper(max); } double GetLower() { return m_Lower; } void SetLower(double lower) { this->m_Lower = lower; } double GetUpper() { return m_Upper; } void SetUpper(double upper) { this->m_Upper = upper; } void mousePressEvent( QMouseEvent* mouseEvent ); virtual void paintEvent( QPaintEvent* e ); virtual void DoubleClickOnHandle(int handle) = 0; void mouseMoveEvent( QMouseEvent* mouseEvent ); void mouseReleaseEvent( QMouseEvent* mouseEvent ); void mouseDoubleClickEvent( QMouseEvent* mouseEvent ); void PaintHistogram(QPainter &p); virtual int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32) = 0; virtual int AddFunctionPoint(double x,double val) = 0; virtual void RemoveFunctionPoint(double x) = 0; virtual void MoveFunctionPoint(int index, std::pair pos) = 0; virtual double GetFunctionX(int index) = 0; - virtual float GetFunctionY(int index) = 0; + virtual double GetFunctionY(int index) = 0; virtual int GetFunctionSize() = 0; int m_GrabbedHandle; double m_Lower, m_Upper, m_Min, m_Max; std::pair FunctionToCanvas(std::pair); std::pair CanvasToFunction(std::pair); mitk::SimpleHistogram *m_Histogram; void keyPressEvent ( QKeyEvent * e ); void SetImmediateUpdate(bool state); std::pair ValidateCoord( std::pair x ) { double max = m_Histogram->GetMax(); double min = m_Histogram->GetMin(); if( x.first < min ) x.first = min; if( x.first > max ) x.first = max; if( x.second < 0 ) x.second = 0; if( x.second > 1 ) x.second = 1; return x; } void SetX(float x) { if (m_GrabbedHandle != -1) { this->MoveFunctionPoint(m_GrabbedHandle, ValidateCoord(std::make_pair(x,GetFunctionY(m_GrabbedHandle)))); update(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void SetY(float y) { if (m_GrabbedHandle != -1) { this->MoveFunctionPoint(m_GrabbedHandle, ValidateCoord(std::make_pair(GetFunctionX(m_GrabbedHandle),y))); update(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void SetQLineEdits(QLineEdit* xEdit, QLineEdit* yEdit) { m_XEdit = xEdit; m_YEdit = yEdit; m_LineEditAvailable = true; } protected: bool m_ImmediateUpdate; float m_Range; bool m_LineEditAvailable; QLineEdit* m_XEdit; QLineEdit* m_YEdit; }; #endif diff --git a/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp b/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp index c714e1914e..d421e2b910 100755 --- a/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp +++ b/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.cpp @@ -1,251 +1,266 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkTransferFunctionWidget.h" #include #include QmitkTransferFunctionWidget::QmitkTransferFunctionWidget(QWidget* parent, - Qt::WindowFlags f) : + Qt::WindowFlags f) : QWidget(parent, f) { this->setupUi(this); // signals and slots connections - connect(m_XEditScalarOpacity, SIGNAL(returnPressed()), this, SLOT(SetXValueScalar())); - connect(m_YEditScalarOpacity, SIGNAL(returnPressed()), this, SLOT(SetYValueScalar())); + connect(m_XEditScalarOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetXValueScalar( const QString & ))); + connect(m_YEditScalarOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetYValueScalar( const QString & ))); - connect(m_XEditGradientOpacity, SIGNAL(returnPressed()), this, SLOT(SetXValueGradient())); - connect(m_YEditGradientOpacity, SIGNAL(returnPressed()), this, SLOT(SetYValueGradient())); + connect(m_XEditGradientOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetXValueGradient( const QString & ))); + connect(m_YEditGradientOpacity, SIGNAL(textEdited ( const QString & )), this, SLOT(SetYValueGradient( const QString & ))); - connect(m_XEditColor, SIGNAL(returnPressed()), this, SLOT(SetXValueColor())); + connect(m_XEditColor, SIGNAL( textEdited ( const QString & ) ), this, SLOT(SetXValueColor( const QString & ))); QPlastiqueStyle *sliderStyle = new QPlastiqueStyle(); m_RangeSlider->setMaximum(2048); m_RangeSlider->setMinimum(-2048); m_RangeSlider->setHandleMovementMode(QxtSpanSlider::NoOverlapping); m_RangeSlider->setStyle(sliderStyle); connect(m_RangeSlider, SIGNAL(spanChanged(double,double)),this, SLOT(OnSpanChanged(double,double))); //reset button connect(m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider())); m_ScalarOpacityFunctionCanvas->SetQLineEdits(m_XEditScalarOpacity, m_YEditScalarOpacity); m_GradientOpacityCanvas->SetQLineEdits(m_XEditGradientOpacity, m_YEditGradientOpacity); m_ColorTransferFunctionCanvas->SetQLineEdits(m_XEditColor, 0); m_ScalarOpacityFunctionCanvas->SetTitle("Grayvalue -> Opacity"); m_GradientOpacityCanvas->SetTitle("Grayvalue/Gradient -> Opacity"); m_ColorTransferFunctionCanvas->SetTitle("Grayvalue -> Color"); } QmitkTransferFunctionWidget::~QmitkTransferFunctionWidget() { } void QmitkTransferFunctionWidget::SetIntegerMode(bool intMode) { m_RangeSlider->setIntegerMode(intMode); } void QmitkTransferFunctionWidget::SetScalarLabel(const QString& scalarLabel) { m_textLabelX->setText(scalarLabel); m_textLabelX_2->setText(scalarLabel); m_textLabelX_3->setText(scalarLabel); m_ScalarOpacityFunctionCanvas->SetTitle(scalarLabel + " -> Opacity"); m_GradientOpacityCanvas->SetTitle(scalarLabel + "/Gradient -> Opacity"); m_ColorTransferFunctionCanvas->SetTitle(scalarLabel + " -> Color"); } void QmitkTransferFunctionWidget::ShowScalarOpacityFunction(bool show) { m_ScalarOpacityWidget->setVisible(show); } void QmitkTransferFunctionWidget::ShowColorFunction(bool show) { m_ColorWidget->setVisible(show); } void QmitkTransferFunctionWidget::ShowGradientOpacityFunction(bool show) { m_GradientOpacityWidget->setVisible(show); } void QmitkTransferFunctionWidget::SetScalarOpacityFunctionEnabled(bool enable) { m_ScalarOpacityWidget->setEnabled(enable); } void QmitkTransferFunctionWidget::SetColorFunctionEnabled(bool enable) { m_ColorWidget->setEnabled(enable); } void QmitkTransferFunctionWidget::SetGradientOpacityFunctionEnabled(bool enable) { m_GradientOpacityWidget->setEnabled(enable); } void QmitkTransferFunctionWidget::SetDataNode(mitk::DataNode* node) { if (node) { tfpToChange = dynamic_cast(node->GetProperty("TransferFunction")); if(!tfpToChange) { if (! dynamic_cast(node->GetData())) { MITK_WARN << "QmitkTransferFunctionWidget::SetDataNode called with non-image node"; goto turnOff; } node->SetProperty("TransferFunction", tfpToChange = mitk::TransferFunctionProperty::New() ); } mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); if( mitk::BaseData* data = node->GetData() ) { mitk::SimpleHistogram *h = histogramCache[data]; m_RangeSliderMin= h->GetMin(); m_RangeSliderMax= h->GetMax(); m_RangeSlider->blockSignals(true); m_RangeSlider->setMinimum(m_RangeSliderMin); m_RangeSlider->setMaximum(m_RangeSliderMax); m_RangeSlider->setSpan( m_RangeSliderMin, m_RangeSliderMax); m_RangeSlider->blockSignals(false); m_ScalarOpacityFunctionCanvas->SetHistogram( h ); m_GradientOpacityCanvas->SetHistogram( h ); } OnUpdateCanvas(); return; } - turnOff: +turnOff: m_ScalarOpacityFunctionCanvas->setEnabled(false); m_ScalarOpacityFunctionCanvas->SetHistogram(0); m_GradientOpacityCanvas->setEnabled(false); m_GradientOpacityCanvas->SetHistogram(0); m_ColorTransferFunctionCanvas->setEnabled(false); tfpToChange = 0; } void QmitkTransferFunctionWidget::OnUpdateCanvas() { if(tfpToChange.IsNull()) return; mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); if(tf.IsNull()) return; m_ScalarOpacityFunctionCanvas->SetPiecewiseFunction( tf->GetScalarOpacityFunction() ); m_GradientOpacityCanvas->SetPiecewiseFunction( tf->GetGradientOpacityFunction() ); m_ColorTransferFunctionCanvas->SetColorTransferFunction( tf->GetColorTransferFunction() ); UpdateRanges(); m_ScalarOpacityFunctionCanvas->update(); m_GradientOpacityCanvas->update(); m_ColorTransferFunctionCanvas->update(); } -void QmitkTransferFunctionWidget::SetXValueScalar() +void QmitkTransferFunctionWidget::SetXValueScalar( const QString text ) { - m_ScalarOpacityFunctionCanvas->SetX(m_XEditScalarOpacity->text().toFloat()); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if ( !text.endsWith( "." )) + { + m_ScalarOpacityFunctionCanvas->SetX(text.toFloat()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } } -void QmitkTransferFunctionWidget::SetYValueScalar() +void QmitkTransferFunctionWidget::SetYValueScalar( const QString text ) { - m_ScalarOpacityFunctionCanvas->SetY(m_YEditScalarOpacity->text().toFloat()); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if ( !text.endsWith( "." )) + { + m_ScalarOpacityFunctionCanvas->SetY(text.toFloat()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } } -void QmitkTransferFunctionWidget::SetXValueGradient() +void QmitkTransferFunctionWidget::SetXValueGradient( const QString text ) { - m_GradientOpacityCanvas->SetX(m_XEditGradientOpacity->text().toFloat()); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if ( !text.endsWith( "." )) + { + m_GradientOpacityCanvas->SetX(text.toFloat()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } } -void QmitkTransferFunctionWidget::SetYValueGradient() +void QmitkTransferFunctionWidget::SetYValueGradient( const QString text ) { - m_GradientOpacityCanvas->SetY(m_YEditGradientOpacity->text().toFloat()); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if ( !text.endsWith( "." )) + { + m_GradientOpacityCanvas->SetY(text.toFloat()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } } -void QmitkTransferFunctionWidget::SetXValueColor() +void QmitkTransferFunctionWidget::SetXValueColor( const QString text ) { - m_ColorTransferFunctionCanvas->SetX(m_XEditColor->text().toFloat()); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if ( !text.endsWith( "." )) + { + m_ColorTransferFunctionCanvas->SetX(text.toFloat()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } } void QmitkTransferFunctionWidget::UpdateRanges() { double lower = m_RangeSlider->lowerValue(); double upper = m_RangeSlider->upperValue(); m_ScalarOpacityFunctionCanvas->SetMin(lower); m_ScalarOpacityFunctionCanvas->SetMax(upper); m_GradientOpacityCanvas->SetMin(lower); m_GradientOpacityCanvas->SetMax(upper); m_ColorTransferFunctionCanvas->SetMin(lower); m_ColorTransferFunctionCanvas->SetMax(upper); } void QmitkTransferFunctionWidget::OnSpanChanged(double, double) { UpdateRanges(); m_GradientOpacityCanvas->update(); m_ColorTransferFunctionCanvas->update(); m_ScalarOpacityFunctionCanvas->update(); } void QmitkTransferFunctionWidget::OnResetSlider() { m_RangeSlider->blockSignals(true); m_RangeSlider->setUpperValue(m_RangeSliderMax); m_RangeSlider->setLowerValue(m_RangeSliderMin); m_RangeSlider->blockSignals(false); UpdateRanges(); m_GradientOpacityCanvas->update(); m_ColorTransferFunctionCanvas->update(); m_ScalarOpacityFunctionCanvas->update(); } diff --git a/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.h b/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.h index 317cf66c29..b3ccaf4fb5 100755 --- a/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.h +++ b/Modules/QtWidgetsExt/QmitkTransferFunctionWidget.h @@ -1,87 +1,87 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKTRANSFERFUNCTIONWIDGET_H #define QMITKTRANSFERFUNCTIONWIDGET_H #include "ui_QmitkTransferFunctionWidget.h" #include "MitkQtWidgetsExtExports.h" #include #include #include #include #include #include #include class MitkQtWidgetsExt_EXPORT QmitkTransferFunctionWidget : public QWidget, public Ui::QmitkTransferFunctionWidget { Q_OBJECT public: QmitkTransferFunctionWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkTransferFunctionWidget () ; void SetDataNode(mitk::DataNode* node); void SetIntegerMode(bool intMode); void SetScalarLabel(const QString& scalarLabel); void ShowScalarOpacityFunction(bool show); void ShowColorFunction(bool show); void ShowGradientOpacityFunction(bool show); void SetScalarOpacityFunctionEnabled(bool enable); void SetColorFunctionEnabled(bool enable); void SetGradientOpacityFunctionEnabled(bool enable); public slots: - void SetXValueScalar(); - void SetYValueScalar(); - void SetXValueGradient(); - void SetYValueGradient(); - void SetXValueColor(); + void SetXValueScalar( const QString text ); + void SetYValueScalar( const QString text ); + void SetXValueGradient( const QString text ); + void SetYValueGradient( const QString text ); + void SetXValueColor( const QString text ); void OnUpdateCanvas(); void UpdateRanges(); void OnResetSlider(); void OnSpanChanged (double lower, double upper); protected: mitk::TransferFunctionProperty::Pointer tfpToChange; double m_RangeSliderMin; double m_RangeSliderMax; mitk::SimpleHistogramCache histogramCache; }; #endif