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 "QmitkColourImageProcessingView.h"
00019 #include "mitkColourImageProcessor.h"
00020
00021 #include "mitkNodePredicateDataType.h"
00022 #include "QmitkDataStorageComboBox.h"
00023 #include "QmitkStdMultiWidget.h"
00024 #include <QMessageBox>
00025 #include <QComboBox>
00026
00027 #include <berryISelectionProvider.h>
00028 #include <berryISelectionService.h>
00029 #include <berryIWorkbenchWindow.h>
00030 #include <mitkDataNodeObject.h>
00031
00032 #include <mitkTransferFunction.h>
00033 #include <mitkTransferFunctionProperty.h>
00034 #include "QmitkPiecewiseFunctionCanvas.h"
00035 #include "QmitkColorTransferFunctionCanvas.h"
00036
00037 #include <QColor>
00038 #include <QColorDialog>
00039
00040
00041 const std::string QmitkColourImageProcessingView::VIEW_ID = "org.mitk.views.colourimageprocessing";
00042
00043 QmitkColourImageProcessingView::QmitkColourImageProcessingView()
00044 : QmitkFunctionality(),
00045 m_MultiWidget(NULL)
00046 {
00047 m_Controls=NULL;
00048
00049 m_Color[0]= 255;
00050 m_Color[1]= 0;
00051 m_Color[2]= 0;
00052 }
00053
00054 QmitkColourImageProcessingView::~QmitkColourImageProcessingView()
00055 {
00056 berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService();
00057 if(s)
00058 s->RemoveSelectionListener(m_SelectionListener);
00059 }
00060
00061 void QmitkColourImageProcessingView::CreateQtPartControl(QWidget *parent)
00062 {
00063 if (!m_Controls)
00064 {
00065 m_Controls = new Ui::QmitkColourImageProcessingViewControls;
00066 m_Controls->setupUi(parent);
00067
00068 connect( m_Controls->m_ConvertImageToRGBA, SIGNAL( clicked(bool) ),this, SLOT( OnConvertToRGBAImage() ));
00069 connect( m_Controls->m_ConvertImageMaskToRGBA, SIGNAL( clicked(bool) ),this, SLOT( OnConvertToRGBAImage() ));
00070 connect( m_Controls->m_ConvertImageMaskColorToRGBA, SIGNAL( clicked(bool) ),this, SLOT( OnConvertImageMaskColorToRGBAImage() ));
00071 connect( m_Controls->m_ColorButton, SIGNAL( clicked(bool) ),this, SLOT( OnChangeColor() ));
00072 connect( m_Controls->m_CombineRGBAButton, SIGNAL( clicked(bool) ),this, SLOT( OnCombineRGBA() ));
00073
00074 m_Controls->m_ImageSelectedLabel->hide();
00075 m_Controls->m_NoImageSelectedLabel->show();
00076
00077
00078
00079 }
00080
00081 m_SelectionListener = berry::ISelectionListener::Pointer(new berry::SelectionChangedAdapter<QmitkColourImageProcessingView>
00082 (this, &QmitkColourImageProcessingView::SelectionChanged));
00083 berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService();
00084 if(s)
00085 s->AddSelectionListener(m_SelectionListener);
00086
00087 }
00088
00089
00090 void QmitkColourImageProcessingView::SelectionChanged( berry::IWorkbenchPart::Pointer, berry::ISelection::ConstPointer selection )
00091 {
00092
00093 mitk::DataNodeSelection::ConstPointer _DataNodeSelection
00094 = selection.Cast<const mitk::DataNodeSelection>();
00095
00096 if(_DataNodeSelection.IsNotNull())
00097 {
00098 std::vector<mitk::DataNode*> selectedNodes;
00099 mitk::DataNodeObject* _DataNodeObject = 0;
00100
00101 for(mitk::DataNodeSelection::iterator it = _DataNodeSelection->Begin();it != _DataNodeSelection->End(); ++it)
00102 {
00103 _DataNodeObject = dynamic_cast<mitk::DataNodeObject*>((*it).GetPointer());
00104 if(_DataNodeObject)
00105 {
00106 mitk::DataNode::Pointer node = _DataNodeObject->GetDataNode();
00107
00108 if( node.IsNotNull() && dynamic_cast<mitk::Image*>(node->GetData())&&dynamic_cast<mitk::Image*>(node->GetData())->GetDimension()>=3 )
00109 selectedNodes.push_back( node );
00110 }
00111 }
00112
00113 mitk::DataNode::Pointer node;
00114
00115 if(selectedNodes.size() > 0)
00116 node=selectedNodes[0];
00117
00118 if( node.IsNotNull() )
00119 {
00120 m_SelectedNode = node;
00121
00122 m_Controls->m_NoImageSelectedLabel->hide();
00123 m_Controls->m_ImageSelectedLabel->show();
00124
00125 std::string infoText = std::string("Selected Image: ") + node->GetName();
00126
00127 if(selectedNodes.size() > 1)
00128 {
00129 mitk::DataNode::Pointer node2;
00130 node2=selectedNodes[1];
00131 m_SelectedNode2=node2;
00132 infoText = infoText + " and " + node2->GetName();
00133 }
00134 else
00135 {
00136 m_SelectedNode2= 0;
00137 }
00138
00139 m_Controls->m_ImageSelectedLabel->setText( QString( infoText.c_str() ) );
00140
00141 }
00142 else
00143 {
00144 m_Controls->m_ImageSelectedLabel->hide();
00145 m_Controls->m_NoImageSelectedLabel->show();
00146
00147 m_SelectedNode = 0;
00148 m_SelectedNode2= 0;
00149 }
00150
00151 }
00152 }
00153
00154
00155 void QmitkColourImageProcessingView::OnConvertToRGBAImage()
00156 {
00157 if(m_SelectedNode.IsNull())
00158 return;
00159
00160
00161 mitk::TransferFunctionProperty::Pointer transferFunctionProp = dynamic_cast<mitk::TransferFunctionProperty*>(m_SelectedNode->GetProperty("TransferFunction"));
00162
00163 if(transferFunctionProp.IsNull())
00164 return;
00165
00166 mitk::TransferFunction::Pointer tf = transferFunctionProp->GetValue();
00167
00168 if(tf.IsNull())
00169 return;
00170
00171 mitk::mitkColourImageProcessor CImageProcessor;
00172
00173 mitk::Image::Pointer RGBAImageResult;
00174
00175 if(m_SelectedNode2.IsNotNull())
00176 {
00177 RGBAImageResult = CImageProcessor.convertWithBinaryToRGBAImage(dynamic_cast<mitk::Image*>(m_SelectedNode->GetData()),dynamic_cast<mitk::Image*>(m_SelectedNode2->GetData()),tf);
00178 }
00179 else
00180 {
00181 RGBAImageResult = CImageProcessor.convertToRGBAImage(dynamic_cast<mitk::Image*>(m_SelectedNode->GetData()),tf);
00182 }
00183
00184 if (!RGBAImageResult)
00185 {
00186 QMessageBox::warning(NULL, "Warning", QString("Unsupported pixeltype"));
00187 return;
00188 }
00189
00190 mitk::DataNode::Pointer dtn = mitk::DataNode::New();
00191
00192 dtn->SetData( RGBAImageResult );
00193 dtn->SetName(m_SelectedNode->GetName() + "_RGBA");
00194 this->GetDefaultDataStorage()->Add( dtn );
00195
00196 MITK_INFO << "convertToRGBAImage finish";
00197
00198 }
00199
00200 void QmitkColourImageProcessingView::OnConvertImageMaskColorToRGBAImage( )
00201 {
00202 if(m_SelectedNode.IsNull())
00203 return;
00204
00205
00206 mitk::TransferFunctionProperty::Pointer transferFunctionProp = dynamic_cast<mitk::TransferFunctionProperty*>(m_SelectedNode->GetProperty("TransferFunction"));
00207
00208 if(transferFunctionProp.IsNull())
00209 return;
00210
00211 mitk::TransferFunction::Pointer tf = transferFunctionProp->GetValue();
00212
00213 if(tf.IsNull())
00214 return;
00215
00216 mitk::mitkColourImageProcessor CImageProcessor;
00217
00218 mitk::Image::Pointer RGBAImageResult;
00219
00220 if(m_SelectedNode2.IsNotNull())
00221 {
00222 RGBAImageResult = CImageProcessor.convertWithBinaryAndColorToRGBAImage(dynamic_cast<mitk::Image*>(m_SelectedNode->GetData()),dynamic_cast<mitk::Image*>(m_SelectedNode2->GetData()),tf, m_Color);
00223 }
00224 else
00225 {
00226 RGBAImageResult = CImageProcessor.convertToRGBAImage(dynamic_cast<mitk::Image*>(m_SelectedNode->GetData()),tf);
00227 }
00228
00229 if (!RGBAImageResult)
00230 {
00231 QMessageBox::warning(NULL, "Warning", QString("Unsupported pixeltype"));
00232 return;
00233 }
00234
00235 mitk::DataNode::Pointer dtn = mitk::DataNode::New();
00236
00237 dtn->SetData( RGBAImageResult );
00238 dtn->SetName(m_SelectedNode->GetName() + "_RGBA");
00239
00240 this->GetDefaultDataStorage()->Add( dtn );
00241
00242 }
00243
00244
00245 void QmitkColourImageProcessingView::OnChangeColor( )
00246 {
00247 QColor color = QColorDialog::getColor();
00248 if (color.spec() == 0)
00249 {
00250 color.setRed(255);
00251 color.setGreen(0);
00252 color.setBlue(0);
00253 }
00254
00255 m_Color[0]= color.red();
00256 m_Color[1]= color.green();
00257 m_Color[2]= color.blue();
00258
00259 m_Controls->m_ColorButton->setStyleSheet(QString("background-color:rgb(%1,%2, %3)").arg(color.red()).arg(color.green()).arg(color.blue()));
00260 }
00261
00262
00263 void QmitkColourImageProcessingView::OnCombineRGBA( )
00264 {
00265 if(m_SelectedNode.IsNull())
00266 return;
00267
00268 if(m_SelectedNode2.IsNull())
00269 return;
00270
00271
00272 mitk::mitkColourImageProcessor CImageProcessor;
00273
00274 mitk::Image::Pointer RGBAImageResult;
00275
00276 RGBAImageResult = CImageProcessor.combineRGBAImage(dynamic_cast<mitk::Image*>(m_SelectedNode->GetData()),dynamic_cast<mitk::Image*>(m_SelectedNode2->GetData()));
00277 MITK_INFO <<"RGBAImage Result";
00278 mitk::DataNode::Pointer dtn = mitk::DataNode::New();
00279
00280 dtn->SetData( RGBAImageResult );
00281
00282 this->GetDefaultDataStorage()->Add( dtn );
00283
00284 }