diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.cpp index a0beef38c8..023da6fbfb 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.cpp @@ -1,1056 +1,977 @@ /*=================================================================== 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. ===================================================================*/ //#define MBILOG_ENABLE_DEBUG #include "QmitkQBallReconstructionView.h" #include "mitkDiffusionImagingConfigure.h" // qt includes #include // itk includes #include "itkTimeProbe.h" // mitk includes #include "mitkProgressBar.h" #include "mitkStatusBar.h" #include "mitkNodePredicateDataType.h" #include "QmitkDataStorageComboBox.h" #include "QmitkStdMultiWidget.h" #include "itkDiffusionQballReconstructionImageFilter.h" #include "itkAnalyticalDiffusionQballReconstructionImageFilter.h" #include "itkDiffusionMultiShellQballReconstructionImageFilter.h" #include "itkVectorContainer.h" #include "mitkQBallImage.h" #include "mitkProperties.h" #include "mitkVtkResliceInterpolationProperty.h" #include "mitkLookupTable.h" #include "mitkLookupTableProperty.h" #include "mitkTransferFunction.h" #include "mitkTransferFunctionProperty.h" #include "mitkDataNodeObject.h" #include "mitkOdfNormalizationMethodProperty.h" #include "mitkOdfScaleByProperty.h" #include "berryIStructuredSelection.h" #include "berryIWorkbenchWindow.h" #include "berryISelectionService.h" #include const std::string QmitkQBallReconstructionView::VIEW_ID = "org.mitk.views.qballreconstruction"; typedef float TTensorPixelType; const int QmitkQBallReconstructionView::nrconvkernels = 252; struct QbrShellSelection { - QmitkQBallReconstructionView* m_View; - mitk::DataNode * m_Node; - std::string m_NodeName; + QmitkQBallReconstructionView* m_View; + mitk::DataNode * m_Node; + std::string m_NodeName; - std::vector m_CheckBoxes; - QLabel * m_Label; + std::vector m_CheckBoxes; + QLabel * m_Label; - mitk::DiffusionImage * m_Image; - typedef mitk::DiffusionImage::BValueMap BValueMap; + mitk::DiffusionImage * m_Image; + typedef mitk::DiffusionImage::BValueMap BValueMap; - QbrShellSelection(QmitkQBallReconstructionView* view, mitk::DataNode * node) - : m_View(view), - m_Node(node), - m_NodeName(node->GetName()) - { - m_Image = dynamic_cast * > (node->GetData()); - if(!m_Image){MITK_INFO << "QmitkQBallReconstructionView::QbrShellSelection : fail to initialize DiffusionImage "; return;} + QbrShellSelection(QmitkQBallReconstructionView* view, mitk::DataNode * node) + : m_View(view), + m_Node(node), + m_NodeName(node->GetName()) + { + m_Image = dynamic_cast * > (node->GetData()); + if(!m_Image){MITK_INFO << "QmitkQBallReconstructionView::QbrShellSelection : fail to initialize DiffusionImage "; return;} - GenerateCheckboxes(); + GenerateCheckboxes(); - } + } - void GenerateCheckboxes() - { - BValueMap origMap = m_Image->GetBValueMap(); - BValueMap::iterator itStart = origMap.begin(); - itStart++; - BValueMap::iterator itEnd = origMap.end(); + void GenerateCheckboxes() + { + BValueMap origMap = m_Image->GetBValueMap(); + BValueMap::iterator itStart = origMap.begin(); + itStart++; + BValueMap::iterator itEnd = origMap.end(); - m_Label = new QLabel(m_NodeName.c_str()); - m_Label->setVisible(true); - m_View->m_Controls->m_QBallSelectionBox->layout()->addWidget(m_Label); + m_Label = new QLabel(m_NodeName.c_str()); + m_Label->setVisible(true); + m_View->m_Controls->m_QBallSelectionBox->layout()->addWidget(m_Label); - for(BValueMap::iterator it = itStart ; it!= itEnd; it++) - { - QCheckBox * box = new QCheckBox(QString::number(it->first)); - m_View->m_Controls->m_QBallSelectionBox->layout()->addWidget(box); + for(BValueMap::iterator it = itStart ; it!= itEnd; it++) + { + QCheckBox * box = new QCheckBox(QString::number(it->first)); + m_View->m_Controls->m_QBallSelectionBox->layout()->addWidget(box); - box->setChecked(true); - box->setCheckable(true); - // box->setVisible(true); - m_CheckBoxes.push_back(box); + box->setChecked(true); + box->setCheckable(true); + // box->setVisible(true); + m_CheckBoxes.push_back(box); + } } - } - void SetVisible(bool vis) - { - foreach(QCheckBox * box, m_CheckBoxes) + void SetVisible(bool vis) { - box->setVisible(vis); + foreach(QCheckBox * box, m_CheckBoxes) + { + box->setVisible(vis); + } } - } - - BValueMap GetBValueSelctionMap() - { - BValueMap inputMap = m_Image->GetBValueMap(); - BValueMap outputMap; - unsigned int val = 0; + BValueMap GetBValueSelctionMap() + { + BValueMap inputMap = m_Image->GetBValueMap(); + BValueMap outputMap; - if(inputMap.find(0) == inputMap.end()){ - MITK_INFO << "QbrShellSelection: return empty BValueMap from GUI Selection"; - return outputMap; - }else{ - outputMap[val] = inputMap[val]; - MITK_INFO << val; - } + unsigned int val = 0; - foreach(QCheckBox * box, m_CheckBoxes) - { - if(box->isChecked()){ - val = box->text().toDouble(); - outputMap[val] = inputMap[val]; - MITK_INFO << val; - } - } + if(inputMap.find(0) == inputMap.end()){ + MITK_INFO << "QbrShellSelection: return empty BValueMap from GUI Selection"; + return outputMap; + }else{ + outputMap[val] = inputMap[val]; + MITK_INFO << val; + } - return outputMap; - } + foreach(QCheckBox * box, m_CheckBoxes) + { + if(box->isChecked()){ + val = box->text().toDouble(); + outputMap[val] = inputMap[val]; + MITK_INFO << val; + } + } - ~QbrShellSelection() - { - m_View->m_Controls->m_QBallSelectionBox->layout()->removeWidget(m_Label); - delete m_Label; + return outputMap; + } - for(std::vector::iterator it = m_CheckBoxes.begin() ; it!= m_CheckBoxes.end(); it++) + ~QbrShellSelection() { - m_View->m_Controls->m_QBallSelectionBox->layout()->removeWidget((*it)); - delete (*it); + m_View->m_Controls->m_QBallSelectionBox->layout()->removeWidget(m_Label); + delete m_Label; + + for(std::vector::iterator it = m_CheckBoxes.begin() ; it!= m_CheckBoxes.end(); it++) + { + m_View->m_Controls->m_QBallSelectionBox->layout()->removeWidget((*it)); + delete (*it); + } + m_CheckBoxes.clear(); } - m_CheckBoxes.clear(); - } }; using namespace berry; struct QbrSelListener : ISelectionListener { - berryObjectMacro(QbrSelListener); - - QbrSelListener(QmitkQBallReconstructionView* view) - { - m_View = view; - } - - void DoSelectionChanged(ISelection::ConstPointer selection) - { - // save current selection in member variable - m_View->m_CurrentSelection = selection.Cast(); + berryObjectMacro(QbrSelListener); - // do something with the selected items - if(m_View->m_CurrentSelection) + QbrSelListener(QmitkQBallReconstructionView* view) { - bool foundDwiVolume = false; - - m_View->m_Controls->m_DiffusionImageLabel->setText("mandatory"); - m_View->m_Controls->m_InputData->setTitle("Please Select Input Data"); - - QString selected_images = ""; - - mitk::DataStorage::SetOfObjects::Pointer set = - mitk::DataStorage::SetOfObjects::New(); - - int at = 0; + m_View = view; + } - // iterate selection - for (IStructuredSelection::iterator i = m_View->m_CurrentSelection->Begin(); - i != m_View->m_CurrentSelection->End(); ++i) - { + void DoSelectionChanged(ISelection::ConstPointer selection) + { + // save current selection in member variable + m_View->m_CurrentSelection = selection.Cast(); - // extract datatree node - if (mitk::DataNodeObject::Pointer nodeObj = i->Cast()) + // do something with the selected items + if(m_View->m_CurrentSelection) { - mitk::DataNode::Pointer node = nodeObj->GetDataNode(); - mitk::DiffusionImage* diffusionImage = dynamic_cast * >(node->GetData()); - // only look at interesting types - if(diffusionImage) - { - foundDwiVolume = true; - selected_images += QString(node->GetName().c_str()); - if(i + 1 != m_View->m_CurrentSelection->End()) - selected_images += "\n"; - set->InsertElement(at++, node); - } + bool foundDwiVolume = false; + + m_View->m_Controls->m_DiffusionImageLabel->setText("mandatory"); + m_View->m_Controls->m_InputData->setTitle("Please Select Input Data"); + + QString selected_images = ""; + + mitk::DataStorage::SetOfObjects::Pointer set = + mitk::DataStorage::SetOfObjects::New(); + + int at = 0; + + // iterate selection + for (IStructuredSelection::iterator i = m_View->m_CurrentSelection->Begin(); + i != m_View->m_CurrentSelection->End(); ++i) + { + + // extract datatree node + if (mitk::DataNodeObject::Pointer nodeObj = i->Cast()) + { + mitk::DataNode::Pointer node = nodeObj->GetDataNode(); + mitk::DiffusionImage* diffusionImage = dynamic_cast * >(node->GetData()); + // only look at interesting types + if(diffusionImage) + { + foundDwiVolume = true; + selected_images += QString(node->GetName().c_str()); + if(i + 1 != m_View->m_CurrentSelection->End()) + selected_images += "\n"; + set->InsertElement(at++, node); + } + } + } + m_View->GenerateShellSelectionUI(set); + m_View->m_Controls->m_DiffusionImageLabel->setText(selected_images); + m_View->m_Controls->m_ButtonStandard->setEnabled(foundDwiVolume); + if (foundDwiVolume) + m_View->m_Controls->m_InputData->setTitle("Input Data"); + else + m_View->m_Controls->m_DiffusionImageLabel->setText("mandatory"); } - } - m_View->GenerateShellSelectionUI(set); - m_View->m_Controls->m_DiffusionImageLabel->setText(selected_images); - m_View->m_Controls->m_ButtonStandard->setEnabled(foundDwiVolume); - if (foundDwiVolume) - m_View->m_Controls->m_InputData->setTitle("Input Data"); - else - m_View->m_Controls->m_DiffusionImageLabel->setText("mandatory"); } - } - void SelectionChanged(IWorkbenchPart::Pointer part, ISelection::ConstPointer selection) - { - // check, if selection comes from datamanager - if (part) + void SelectionChanged(IWorkbenchPart::Pointer part, ISelection::ConstPointer selection) { - QString partname(part->GetPartName().c_str()); - if(partname.compare("Data Manager")==0) - { + // check, if selection comes from datamanager + if (part) + { + QString partname(part->GetPartName().c_str()); + if(partname.compare("Data Manager")==0) + { - // apply selection - DoSelectionChanged(selection); + // apply selection + DoSelectionChanged(selection); - } + } + } } - } - QmitkQBallReconstructionView* m_View; + QmitkQBallReconstructionView* m_View; }; // --------------- QmitkQBallReconstructionView----------------- // QmitkQBallReconstructionView::QmitkQBallReconstructionView() - : QmitkFunctionality(), - m_Controls(NULL), - m_MultiWidget(NULL) + : QmitkFunctionality(), + m_Controls(NULL), + m_MultiWidget(NULL) { } QmitkQBallReconstructionView::~QmitkQBallReconstructionView() { - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->RemovePostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelListener); + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->RemovePostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelListener); } void QmitkQBallReconstructionView::CreateQtPartControl(QWidget *parent) { - if (!m_Controls) - { - // create GUI widgets - m_Controls = new Ui::QmitkQBallReconstructionViewControls; - m_Controls->setupUi(parent); - this->CreateConnections(); + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkQBallReconstructionViewControls; + m_Controls->setupUi(parent); + this->CreateConnections(); - m_Controls->m_DiffusionImageLabel->setText("mandatory"); + m_Controls->m_DiffusionImageLabel->setText("mandatory"); - QStringList items; - items << "2" << "4" << "6" << "8" << "10" << "12"; - m_Controls->m_QBallReconstructionMaxLLevelComboBox->addItems(items); - m_Controls->m_QBallReconstructionMaxLLevelComboBox->setCurrentIndex(1); - MethodChoosen(m_Controls->m_QBallReconstructionMethodComboBox->currentIndex()); + QStringList items; + items << "2" << "4" << "6" << "8" << "10" << "12"; + m_Controls->m_QBallReconstructionMaxLLevelComboBox->addItems(items); + m_Controls->m_QBallReconstructionMaxLLevelComboBox->setCurrentIndex(1); + MethodChoosen(m_Controls->m_QBallReconstructionMethodComboBox->currentIndex()); #ifndef DIFFUSION_IMAGING_EXTENDED - m_Controls->m_QBallReconstructionMethodComboBox->removeItem(3); + m_Controls->m_QBallReconstructionMethodComboBox->removeItem(3); #endif - AdvancedCheckboxClicked(); - } + AdvancedCheckboxClicked(); + } - m_SelListener = berry::ISelectionListener::Pointer(new QbrSelListener(this)); - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelListener); - berry::ISelection::ConstPointer sel( - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); - m_CurrentSelection = sel.Cast(); - m_SelListener.Cast()->DoSelectionChanged(sel); + m_SelListener = berry::ISelectionListener::Pointer(new QbrSelListener(this)); + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelListener); + berry::ISelection::ConstPointer sel( + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); + m_CurrentSelection = sel.Cast(); + m_SelListener.Cast()->DoSelectionChanged(sel); } void QmitkQBallReconstructionView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { - m_MultiWidget = &stdMultiWidget; + m_MultiWidget = &stdMultiWidget; } void QmitkQBallReconstructionView::StdMultiWidgetNotAvailable() { - m_MultiWidget = NULL; + m_MultiWidget = NULL; } void QmitkQBallReconstructionView::CreateConnections() { - if ( m_Controls ) - { - connect( (QObject*)(m_Controls->m_ButtonStandard), SIGNAL(clicked()), this, SLOT(ReconstructStandard()) ); - connect( (QObject*)(m_Controls->m_AdvancedCheckbox), SIGNAL(clicked()), this, SLOT(AdvancedCheckboxClicked()) ); - connect( (QObject*)(m_Controls->m_QBallReconstructionMethodComboBox), SIGNAL(currentIndexChanged(int)), this, SLOT(MethodChoosen(int)) ); + if ( m_Controls ) + { + connect( (QObject*)(m_Controls->m_ButtonStandard), SIGNAL(clicked()), this, SLOT(ReconstructStandard()) ); + connect( (QObject*)(m_Controls->m_AdvancedCheckbox), SIGNAL(clicked()), this, SLOT(AdvancedCheckboxClicked()) ); + connect( (QObject*)(m_Controls->m_QBallReconstructionMethodComboBox), SIGNAL(currentIndexChanged(int)), this, SLOT(MethodChoosen(int)) ); - } + } } void QmitkQBallReconstructionView::OnSelectionChanged( std::vector ) { } void QmitkQBallReconstructionView::Activated() { - QmitkFunctionality::Activated(); + QmitkFunctionality::Activated(); - berry::ISelection::ConstPointer sel( - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); - m_CurrentSelection = sel.Cast(); - m_SelListener.Cast()->DoSelectionChanged(sel); + berry::ISelection::ConstPointer sel( + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); + m_CurrentSelection = sel.Cast(); + m_SelListener.Cast()->DoSelectionChanged(sel); } void QmitkQBallReconstructionView::Deactivated() { - QmitkFunctionality::Deactivated(); + QmitkFunctionality::Deactivated(); } void QmitkQBallReconstructionView::ReconstructStandard() { - int index = m_Controls->m_QBallReconstructionMethodComboBox->currentIndex(); + int index = m_Controls->m_QBallReconstructionMethodComboBox->currentIndex(); #ifndef DIFFUSION_IMAGING_EXTENDED - if(index>=3) - { - index = index + 1; - } + if(index>=3) + { + index = index + 1; + } #endif - switch(index) - { - case 0: - { - // Numerical - Reconstruct(0,0); - break; - } - case 1: - { - // Standard - Reconstruct(1,0); - break; - } - case 2: - { - // Solid Angle - Reconstruct(1,6); - break; - } - case 3: - { - // Constrained Solid Angle - Reconstruct(1,7); - break; - } - case 4: - { - // ADC - Reconstruct(1,4); - break; - } - case 5: - { - // Raw Signal - Reconstruct(1,5); - break; - } - case 6: - { - // Q-Ball reconstruction - Reconstruct(2,0); - break; - } - } + switch(index) + { + case 0: + { + // Numerical + Reconstruct(0,0); + break; + } + case 1: + { + // Standard + Reconstruct(1,0); + break; + } + case 2: + { + // Solid Angle + Reconstruct(1,6); + break; + } + case 3: + { + // Constrained Solid Angle + Reconstruct(1,7); + break; + } + case 4: + { + // ADC + Reconstruct(1,4); + break; + } + case 5: + { + // Raw Signal + Reconstruct(1,5); + break; + } + case 6: + { + // Q-Ball reconstruction + Reconstruct(2,0); + break; + } + } } void QmitkQBallReconstructionView::MethodChoosen(int method) { #ifndef DIFFUSION_IMAGING_EXTENDED - if(method>=3) - { - method = method + 1; - } + if(method>=3) + { + method = method + 1; + } #endif - m_Controls->m_QBallSelectionBox->setHidden(true); - m_Controls->m_OutputCoeffsImage->setHidden(true); - - if (method==0) - m_Controls->m_ShFrame->setVisible(false); - else - m_Controls->m_ShFrame->setVisible(true); - - switch(method) - { - case 0: - m_Controls->m_Description->setText("Numerical recon. (Tuch 2004)"); - break; - case 1: - m_Controls->m_Description->setText("Spherical harmonics recon. (Descoteaux 2007)"); - m_Controls->m_OutputCoeffsImage->setHidden(false); - break; - case 2: - m_Controls->m_Description->setText("SH recon. with solid angle consideration (Aganj 2009)"); - m_Controls->m_OutputCoeffsImage->setHidden(false); - break; - case 3: - m_Controls->m_Description->setText("SH solid angle with non-neg. constraint (Goh 2009)"); - break; - case 4: - m_Controls->m_Description->setText("SH recon. of the plain ADC-profiles"); - break; - case 5: - m_Controls->m_Description->setText("SH recon. of the raw diffusion signal"); - break; - case 6: - m_Controls->m_Description->setText("SH recon. of the multi shell diffusion signal (Aganj 2010)"); - m_Controls->m_QBallSelectionBox->setHidden(false); - m_Controls->m_OutputCoeffsImage->setHidden(false); - break; - } + m_Controls->m_QBallSelectionBox->setHidden(true); + m_Controls->m_OutputCoeffsImage->setHidden(true); + + if (method==0) + m_Controls->m_ShFrame->setVisible(false); + else + m_Controls->m_ShFrame->setVisible(true); + + switch(method) + { + case 0: + m_Controls->m_Description->setText("Numerical recon. (Tuch 2004)"); + break; + case 1: + m_Controls->m_Description->setText("Spherical harmonics recon. (Descoteaux 2007)"); + m_Controls->m_OutputCoeffsImage->setHidden(false); + break; + case 2: + m_Controls->m_Description->setText("SH recon. with solid angle consideration (Aganj 2009)"); + m_Controls->m_OutputCoeffsImage->setHidden(false); + break; + case 3: + m_Controls->m_Description->setText("SH solid angle with non-neg. constraint (Goh 2009)"); + break; + case 4: + m_Controls->m_Description->setText("SH recon. of the plain ADC-profiles"); + break; + case 5: + m_Controls->m_Description->setText("SH recon. of the raw diffusion signal"); + break; + case 6: + m_Controls->m_Description->setText("SH recon. of the multi shell diffusion signal (Aganj 2010)"); + m_Controls->m_QBallSelectionBox->setHidden(false); + m_Controls->m_OutputCoeffsImage->setHidden(false); + break; + } } void QmitkQBallReconstructionView::AdvancedCheckboxClicked() { - bool check = m_Controls->m_AdvancedCheckbox->isChecked(); + bool check = m_Controls->m_AdvancedCheckbox->isChecked(); - m_Controls->m_QBallReconstructionMaxLLevelTextLabel_2->setVisible(check); - m_Controls->m_QBallReconstructionMaxLLevelComboBox->setVisible(check); - m_Controls->m_QBallReconstructionLambdaTextLabel_2->setVisible(check); - m_Controls->m_QBallReconstructionLambdaLineEdit->setVisible(check); + m_Controls->m_QBallReconstructionMaxLLevelTextLabel_2->setVisible(check); + m_Controls->m_QBallReconstructionMaxLLevelComboBox->setVisible(check); + m_Controls->m_QBallReconstructionLambdaTextLabel_2->setVisible(check); + m_Controls->m_QBallReconstructionLambdaLineEdit->setVisible(check); - m_Controls->m_QBallReconstructionThresholdLabel_2->setVisible(check); - m_Controls->m_QBallReconstructionThreasholdEdit->setVisible(check); - m_Controls->label_2->setVisible(check); - m_Controls->frame_2->setVisible(check); + m_Controls->m_QBallReconstructionThresholdLabel_2->setVisible(check); + m_Controls->m_QBallReconstructionThreasholdEdit->setVisible(check); + m_Controls->label_2->setVisible(check); + m_Controls->frame_2->setVisible(check); } void QmitkQBallReconstructionView::Reconstruct(int method, int normalization) { - if (m_CurrentSelection) - { - mitk::DataStorage::SetOfObjects::Pointer set = - mitk::DataStorage::SetOfObjects::New(); - - int at = 0; - for (IStructuredSelection::iterator i = m_CurrentSelection->Begin(); - i != m_CurrentSelection->End(); - ++i) + if (m_CurrentSelection) { + mitk::DataStorage::SetOfObjects::Pointer set = + mitk::DataStorage::SetOfObjects::New(); - if (mitk::DataNodeObject::Pointer nodeObj = i->Cast()) - { - mitk::DataNode::Pointer node = nodeObj->GetDataNode(); - if(QString("DiffusionImage").compare(node->GetData()->GetNameOfClass())==0) + int at = 0; + for (IStructuredSelection::iterator i = m_CurrentSelection->Begin(); + i != m_CurrentSelection->End(); + ++i) { - set->InsertElement(at++, node); + + if (mitk::DataNodeObject::Pointer nodeObj = i->Cast()) + { + mitk::DataNode::Pointer node = nodeObj->GetDataNode(); + if(QString("DiffusionImage").compare(node->GetData()->GetNameOfClass())==0) + { + set->InsertElement(at++, node); + } + } } - } - } - if(method == 0) - { - NumericalQBallReconstruction(set, normalization); - } - else - { + if(method == 0) + { + NumericalQBallReconstruction(set, normalization); + } + else + { #if BOOST_VERSION / 100000 > 0 #if BOOST_VERSION / 100 % 1000 > 34 - if(method == 1) - { - AnalyticalQBallReconstruction(set, normalization); - } - if(method == 2) - { - MultiQBallReconstruction(set); - } + if(method == 1) + { + AnalyticalQBallReconstruction(set, normalization); + } + if(method == 2) + { + MultiQBallReconstruction(set); + } #else - std::cout << "ERROR: Boost 1.35 minimum required" << std::endl; - QMessageBox::warning(NULL,"ERROR","Boost 1.35 minimum required"); + std::cout << "ERROR: Boost 1.35 minimum required" << std::endl; + QMessageBox::warning(NULL,"ERROR","Boost 1.35 minimum required"); #endif #else - std::cout << "ERROR: Boost 1.35 minimum required" << std::endl; - QMessageBox::warning(NULL,"ERROR","Boost 1.35 minimum required"); + std::cout << "ERROR: Boost 1.35 minimum required" << std::endl; + QMessageBox::warning(NULL,"ERROR","Boost 1.35 minimum required"); #endif + } } - } } void QmitkQBallReconstructionView::NumericalQBallReconstruction (mitk::DataStorage::SetOfObjects::Pointer inImages, int normalization) { - try - { - itk::TimeProbe clock; - - int nrFiles = inImages->size(); - if (!nrFiles) return; + try + { + itk::TimeProbe clock; - QString status; - mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); + int nrFiles = inImages->size(); + if (!nrFiles) return; - mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); - mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); + QString status; + mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); - std::vector nodes; - while ( itemiter != itemiterend ) // for all items - { + mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - mitk::DiffusionImage* vols = - static_cast*>( - (*itemiter)->GetData()); - - std::string nodename; - (*itemiter)->GetStringProperty("name", nodename); - ++itemiter; - - // QBALL RECONSTRUCTION - clock.Start(); - MITK_INFO << "QBall reconstruction "; - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( - "QBall reconstruction for %s", nodename.c_str()).toAscii()); - - typedef itk::DiffusionQballReconstructionImageFilter - - QballReconstructionImageFilterType; - - QballReconstructionImageFilterType::Pointer filter = - QballReconstructionImageFilterType::New(); - filter->SetGradientImage( vols->GetDirections(), vols->GetVectorImage() ); - filter->SetBValue(vols->GetReferenceBValue()); - filter->SetThreshold( m_Controls->m_QBallReconstructionThreasholdEdit->value() ); - - switch(normalization) - { - case 0: - { - filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_STANDARD); - break; - } - case 1: - { - filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_B_ZERO_B_VALUE); - break; - } - case 2: - { - filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_B_ZERO); - break; - } - case 3: - { - filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_NONE); - break; - } - default: - { - filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_STANDARD); - } - } - - filter->Update(); - clock.Stop(); - MITK_DEBUG << "took " << clock.GetMean() << "s." ; - - // ODFs TO DATATREE - mitk::QBallImage::Pointer image = mitk::QBallImage::New(); - image->InitializeByItk( filter->GetOutput() ); - //image->SetImportVolume( filter->GetOutput()->GetBufferPointer(), 0, 0, mitk::Image::ImportMemoryManagementType::ManageMemory ); - image->SetVolume( filter->GetOutput()->GetBufferPointer() ); - mitk::DataNode::Pointer node=mitk::DataNode::New(); - node->SetData( image ); - QString newname; - newname = newname.append(nodename.c_str()); - newname = newname.append("_QN%1").arg(normalization); - SetDefaultNodeProperties(node, newname.toStdString()); - nodes.push_back(node); - mitk::ProgressBar::GetInstance()->Progress(); - } + while ( itemiter != itemiterend ) // for all items + { - std::vector::iterator nodeIt; - for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) - GetDefaultDataStorage()->Add(*nodeIt); + mitk::DiffusionImage* vols = + static_cast*>( + (*itemiter)->GetData()); + + std::string nodename; + (*itemiter)->GetStringProperty("name", nodename); + + // QBALL RECONSTRUCTION + clock.Start(); + MITK_INFO << "QBall reconstruction "; + mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( + "QBall reconstruction for %s", nodename.c_str()).toAscii()); + + typedef itk::DiffusionQballReconstructionImageFilter + + QballReconstructionImageFilterType; + + QballReconstructionImageFilterType::Pointer filter = + QballReconstructionImageFilterType::New(); + filter->SetGradientImage( vols->GetDirections(), vols->GetVectorImage() ); + filter->SetBValue(vols->GetReferenceBValue()); + filter->SetThreshold( m_Controls->m_QBallReconstructionThreasholdEdit->value() ); + + std::string nodePostfix; + switch(normalization) + { + case 0: + { + filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_STANDARD); + nodePostfix = "_Numerical_Qball"; + break; + } + case 1: + { + filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_B_ZERO_B_VALUE); + nodePostfix = "_Numerical_ZeroBvalueNormalization_Qball"; + break; + } + case 2: + { + filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_B_ZERO); + nodePostfix = "_NumericalQball_ZeroNormalization_Qball"; + break; + } + case 3: + { + filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_NONE); + nodePostfix = "_NumericalQball_NoNormalization_Qball"; + break; + } + default: + { + filter->SetNormalizationMethod(QballReconstructionImageFilterType::QBR_STANDARD); + nodePostfix = "_NumericalQball_Qball"; + } + } + + filter->Update(); + clock.Stop(); + MITK_DEBUG << "took " << clock.GetMean() << "s." ; + + // ODFs TO DATATREE + mitk::QBallImage::Pointer image = mitk::QBallImage::New(); + image->InitializeByItk( filter->GetOutput() ); + image->SetVolume( filter->GetOutput()->GetBufferPointer() ); + mitk::DataNode::Pointer node=mitk::DataNode::New(); + node->SetData( image ); + SetDefaultNodeProperties(node, nodename+nodePostfix); + mitk::ProgressBar::GetInstance()->Progress(); + + GetDefaultDataStorage()->Add(node, *itemiter); + ++itemiter; + } - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); - m_MultiWidget->RequestUpdate(); + mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); + m_MultiWidget->RequestUpdate(); - } - catch (itk::ExceptionObject &ex) - { - MITK_INFO << ex ; - QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); - return ; - } + } + catch (itk::ExceptionObject &ex) + { + MITK_INFO << ex ; + QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); + return ; + } } void QmitkQBallReconstructionView::AnalyticalQBallReconstruction( - mitk::DataStorage::SetOfObjects::Pointer inImages, - int normalization) + mitk::DataStorage::SetOfObjects::Pointer inImages, + int normalization) { - try - { - itk::TimeProbe clock; - - int nrFiles = inImages->size(); - if (!nrFiles) return; - - std::vector lambdas; - float minLambda = m_Controls->m_QBallReconstructionLambdaLineEdit->value(); - lambdas.push_back(minLambda); - int nLambdas = lambdas.size(); - - - QString status; - mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles*nLambdas); - - mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); - mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - - std::vector* nodes - = new std::vector(); - while ( itemiter != itemiterend ) // for all items + try { + itk::TimeProbe clock; - mitk::DiffusionImage* vols = - static_cast*>( - (*itemiter)->GetData()); + int nrFiles = inImages->size(); + if (!nrFiles) return; - std::string nodename; - (*itemiter)->GetStringProperty("name",nodename); - itemiter++; + std::vector lambdas; + float minLambda = m_Controls->m_QBallReconstructionLambdaLineEdit->value(); + lambdas.push_back(minLambda); + int nLambdas = lambdas.size(); - // QBALL RECONSTRUCTION - clock.Start(); - MITK_INFO << "QBall reconstruction "; - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( - "QBall reconstruction for %s", nodename.c_str()).toAscii()); - for(int i=0; iAddStepsToDo(nrFiles*nLambdas); - float currentLambda = lambdas[i]; + mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - switch(m_Controls->m_QBallReconstructionMaxLLevelComboBox->currentIndex()) - { - case 0: - { - TemplatedAnalyticalQBallReconstruction<2>(vols, currentLambda, nodename, nodes, normalization); - break; - } - case 1: - { - TemplatedAnalyticalQBallReconstruction<4>(vols, currentLambda, nodename, nodes, normalization); - break; - } - case 2: - { - TemplatedAnalyticalQBallReconstruction<6>(vols, currentLambda, nodename, nodes, normalization); - break; - } - case 3: - { - TemplatedAnalyticalQBallReconstruction<8>(vols, currentLambda, nodename, nodes, normalization); - break; - } - case 4: - { - TemplatedAnalyticalQBallReconstruction<10>(vols, currentLambda, nodename, nodes, normalization); - break; - } - case 5: + std::vector* nodes + = new std::vector(); + while ( itemiter != itemiterend ) // for all items { - TemplatedAnalyticalQBallReconstruction<12>(vols, currentLambda, nodename, nodes, normalization); - break; + // QBALL RECONSTRUCTION + clock.Start(); + MITK_INFO << "QBall reconstruction "; + mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("QBall reconstruction for %s", (*itemiter)->GetName().c_str()).toAscii()); + + for(int i=0; im_QBallReconstructionMaxLLevelComboBox->currentIndex()) + { + case 0: + { + TemplatedAnalyticalQBallReconstruction<2>(*itemiter, currentLambda, normalization); + break; + } + case 1: + { + TemplatedAnalyticalQBallReconstruction<4>(*itemiter, currentLambda, normalization); + break; + } + case 2: + { + TemplatedAnalyticalQBallReconstruction<6>(*itemiter, currentLambda, normalization); + break; + } + case 3: + { + TemplatedAnalyticalQBallReconstruction<8>(*itemiter, currentLambda, normalization); + break; + } + case 4: + { + TemplatedAnalyticalQBallReconstruction<10>(*itemiter, currentLambda, normalization); + break; + } + case 5: + { + TemplatedAnalyticalQBallReconstruction<12>(*itemiter, currentLambda, normalization); + break; + } + } + clock.Stop(); + MITK_DEBUG << "took " << clock.GetMean() << "s." ; + mitk::ProgressBar::GetInstance()->Progress(); + itemiter++; + } } - } - - clock.Stop(); - MITK_DEBUG << "took " << clock.GetMean() << "s." ; - mitk::ProgressBar::GetInstance()->Progress(); - - } - } - std::vector::iterator nodeIt; - for(nodeIt = nodes->begin(); nodeIt != nodes->end(); ++nodeIt) - GetDefaultDataStorage()->Add(*nodeIt); + std::vector::iterator nodeIt; + for(nodeIt = nodes->begin(); nodeIt != nodes->end(); ++nodeIt) + GetDefaultDataStorage()->Add(*nodeIt); - m_MultiWidget->RequestUpdate(); + m_MultiWidget->RequestUpdate(); - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); + mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); - } - catch (itk::ExceptionObject &ex) - { - MITK_INFO << ex; - QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); - return; - } + } + catch (itk::ExceptionObject &ex) + { + MITK_INFO << ex; + QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); + return; + } } template -void QmitkQBallReconstructionView::TemplatedAnalyticalQBallReconstruction( - mitk::DiffusionImage* vols, float lambda, - std::string nodename, std::vector* nodes, - int normalization) -{ - typedef itk::AnalyticalDiffusionQballReconstructionImageFilter - FilterType; - typename FilterType::Pointer filter = FilterType::New(); - filter->SetGradientImage( vols->GetDirections(), vols->GetVectorImage() ); - filter->SetBValue(vols->GetReferenceBValue()); - filter->SetThreshold( m_Controls->m_QBallReconstructionThreasholdEdit->value() ); - filter->SetLambda(lambda); - - switch(normalization) - { - case 0: - { - filter->SetNormalizationMethod(FilterType::QBAR_STANDARD); - break; - } - case 1: - { - filter->SetNormalizationMethod(FilterType::QBAR_B_ZERO_B_VALUE); - break; - } - case 2: - { - filter->SetNormalizationMethod(FilterType::QBAR_B_ZERO); - break; - } - case 3: - { - filter->SetNormalizationMethod(FilterType::QBAR_NONE); - break; - } - case 4: - { - filter->SetNormalizationMethod(FilterType::QBAR_ADC_ONLY); - break; - } - case 5: - { - filter->SetNormalizationMethod(FilterType::QBAR_RAW_SIGNAL); - break; - } - case 6: - { - filter->SetNormalizationMethod(FilterType::QBAR_SOLID_ANGLE); - break; - } - case 7: - { - filter->SetNormalizationMethod(FilterType::QBAR_NONNEG_SOLID_ANGLE); - break; - } - default: - { - filter->SetNormalizationMethod(FilterType::QBAR_STANDARD); - } - } - - filter->Update(); - - // ODFs TO DATATREE - mitk::QBallImage::Pointer image = mitk::QBallImage::New(); - image->InitializeByItk( filter->GetOutput() ); - image->SetVolume( filter->GetOutput()->GetBufferPointer() ); - mitk::DataNode::Pointer node=mitk::DataNode::New(); - node->SetData( image ); - QString newname; - newname = newname.append(nodename.c_str()); - newname = newname.append("_QA%1").arg(normalization); - SetDefaultNodeProperties(node, newname.toStdString()); - nodes->push_back(node); - - if(m_Controls->m_OutputCoeffsImage->isChecked()) - { - mitk::Image::Pointer coeffsImage = mitk::Image::New(); - coeffsImage->InitializeByItk( filter->GetCoefficientImage().GetPointer() ); - coeffsImage->SetVolume( filter->GetCoefficientImage()->GetBufferPointer() ); - mitk::DataNode::Pointer coeffsNode=mitk::DataNode::New(); - coeffsNode->SetData( coeffsImage ); - coeffsNode->SetProperty( "name", mitk::StringProperty::New( - QString(nodename.c_str()).append("_coeffs").toStdString()) ); - coeffsNode->SetVisibility(false); - nodes->push_back(coeffsNode); - } - -} - -void QmitkQBallReconstructionView::MultiQBallReconstruction( - mitk::DataStorage::SetOfObjects::Pointer inImages) +void QmitkQBallReconstructionView::TemplatedAnalyticalQBallReconstruction(mitk::DataNode* dataNodePointer, float lambda, int normalization) { - try - { - itk::TimeProbe clock; - - int nrFiles = inImages->size(); - if (!nrFiles) return; - - std::vector lambdas; - float minLambda = m_Controls->m_QBallReconstructionLambdaLineEdit->value(); - lambdas.push_back(minLambda); - int nLambdas = lambdas.size(); + typedef itk::AnalyticalDiffusionQballReconstructionImageFilter + FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + mitk::DiffusionImage* vols = dynamic_cast*>(dataNodePointer->GetData()); + filter->SetGradientImage( vols->GetDirections(), vols->GetVectorImage() ); + filter->SetBValue(vols->GetReferenceBValue()); + filter->SetThreshold( m_Controls->m_QBallReconstructionThreasholdEdit->value() ); + filter->SetLambda(lambda); + + std::string nodePostfix; + switch(normalization) + { + case 0: + { + filter->SetNormalizationMethod(FilterType::QBAR_STANDARD); + nodePostfix = "_SphericalHarmonics_Qball"; + break; + } + case 1: + { + filter->SetNormalizationMethod(FilterType::QBAR_B_ZERO_B_VALUE); + nodePostfix = "_SphericalHarmonics_1_Qball"; + break; + } + case 2: + { + filter->SetNormalizationMethod(FilterType::QBAR_B_ZERO); + nodePostfix = "_SphericalHarmonics_2_Qball"; + break; + } + case 3: + { + filter->SetNormalizationMethod(FilterType::QBAR_NONE); + nodePostfix = "_SphericalHarmonics_3_Qball"; + break; + } + case 4: + { + filter->SetNormalizationMethod(FilterType::QBAR_ADC_ONLY); + nodePostfix = "_AdcProfile"; + break; + } + case 5: + { + filter->SetNormalizationMethod(FilterType::QBAR_RAW_SIGNAL); + nodePostfix = "_RawSignal"; + break; + } + case 6: + { + filter->SetNormalizationMethod(FilterType::QBAR_SOLID_ANGLE); + nodePostfix = "_SphericalHarmonics_CSA_Qball"; + break; + } + case 7: + { + filter->SetNormalizationMethod(FilterType::QBAR_NONNEG_SOLID_ANGLE); + nodePostfix = "_SphericalHarmonics_NonNegCSA_Qball"; + break; + } + default: + { + filter->SetNormalizationMethod(FilterType::QBAR_STANDARD); + } + } + filter->Update(); - QString status; - mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles*nLambdas); + // ODFs TO DATATREE + mitk::QBallImage::Pointer image = mitk::QBallImage::New(); + image->InitializeByItk( filter->GetOutput() ); + image->SetVolume( filter->GetOutput()->GetBufferPointer() ); + mitk::DataNode::Pointer node=mitk::DataNode::New(); + node->SetData( image ); + SetDefaultNodeProperties(node, dataNodePointer->GetName()+nodePostfix); - mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); - mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); + GetDefaultDataStorage()->Add(node, dataNodePointer); - std::vector* nodes - = new std::vector(); - while ( itemiter != itemiterend ) // for all items + if(m_Controls->m_OutputCoeffsImage->isChecked()) { + mitk::Image::Pointer coeffsImage = mitk::Image::New(); + coeffsImage->InitializeByItk( filter->GetCoefficientImage().GetPointer() ); + coeffsImage->SetVolume( filter->GetCoefficientImage()->GetBufferPointer() ); + mitk::DataNode::Pointer coeffsNode=mitk::DataNode::New(); + coeffsNode->SetData( coeffsImage ); + coeffsNode->SetProperty( "name", mitk::StringProperty::New(dataNodePointer->GetName()+"_SH-Coeffs") ); + coeffsNode->SetVisibility(false); + GetDefaultDataStorage()->Add(coeffsNode, node); + } +} - mitk::DiffusionImage* vols = - static_cast*>( - (*itemiter)->GetData()); - - - const mitk::DataNode * nodePointer = (*itemiter).GetPointer(); - std::string nodename; - (*itemiter)->GetStringProperty("name",nodename); +void QmitkQBallReconstructionView::MultiQBallReconstruction(mitk::DataStorage::SetOfObjects::Pointer inImages) +{ + try + { + itk::TimeProbe clock; - itemiter++; + int nrFiles = inImages->size(); + if (!nrFiles) return; - // QBALL RECONSTRUCTION - clock.Start(); - MITK_INFO << "QBall reconstruction "; - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( - "QBall reconstruction for %s", nodename.c_str()).toAscii()); + std::vector lambdas; + float minLambda = m_Controls->m_QBallReconstructionLambdaLineEdit->value(); + lambdas.push_back(minLambda); + int nLambdas = lambdas.size(); - for(int i=0; iAddStepsToDo(nrFiles*nLambdas); - float currentLambda = lambdas[i]; + mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - switch(m_Controls->m_QBallReconstructionMaxLLevelComboBox->currentIndex()) - { - case 0: - { - TemplatedMultiQBallReconstruction<2>(vols, currentLambda, nodePointer, nodes); - break; - } - case 1: + while ( itemiter != itemiterend ) // for all items { - TemplatedMultiQBallReconstruction<4>(vols, currentLambda, nodePointer, nodes); - break; + mitk::DataNode* nodePointer = (*itemiter).GetPointer(); + std::string nodename; + (*itemiter)->GetStringProperty("name",nodename); + + itemiter++; + + // QBALL RECONSTRUCTION + clock.Start(); + MITK_INFO << "QBall reconstruction "; + mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("QBall reconstruction for %s", nodename.c_str()).toAscii()); + + for(int i=0; im_QBallReconstructionMaxLLevelComboBox->currentIndex()) + { + case 0: + { + TemplatedMultiQBallReconstruction<2>(currentLambda, nodePointer); + break; + } + case 1: + { + TemplatedMultiQBallReconstruction<4>(currentLambda, nodePointer); + break; + } + case 2: + { + TemplatedMultiQBallReconstruction<6>(currentLambda, nodePointer); + break; + } + case 3: + { + TemplatedMultiQBallReconstruction<8>(currentLambda, nodePointer); + break; + } + case 4: + { + TemplatedMultiQBallReconstruction<10>(currentLambda, nodePointer); + break; + } + case 5: + { + TemplatedMultiQBallReconstruction<12>(currentLambda, nodePointer); + break; + } + } + + clock.Stop(); + MITK_DEBUG << "took " << clock.GetMean() << "s." ; + mitk::ProgressBar::GetInstance()->Progress(); + } } - case 2: - { - TemplatedMultiQBallReconstruction<6>(vols, currentLambda, nodePointer, nodes); - break; - } - case 3: - { - TemplatedMultiQBallReconstruction<8>(vols, currentLambda, nodePointer, nodes); - break; - } - case 4: - { - TemplatedMultiQBallReconstruction<10>(vols, currentLambda, nodePointer, nodes); - break; - } - case 5: - { - TemplatedMultiQBallReconstruction<12>(vols, currentLambda, nodePointer, nodes); - break; - } - } - - clock.Stop(); - MITK_DEBUG << "took " << clock.GetMean() << "s." ; - mitk::ProgressBar::GetInstance()->Progress(); - - } + m_MultiWidget->RequestUpdate(); + mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); } + catch (itk::ExceptionObject &ex) + { + MITK_INFO << ex ; + QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); + return ; + } +} - std::vector::iterator nodeIt; - for(nodeIt = nodes->begin(); nodeIt != nodes->end(); ++nodeIt) - GetDefaultDataStorage()->Add(*nodeIt); +template +void QmitkQBallReconstructionView::TemplatedMultiQBallReconstruction(float lambda, mitk::DataNode* dataNodePointer) +{ + typedef itk::DiffusionMultiShellQballReconstructionImageFilter + FilterType; + typename FilterType::Pointer filter = FilterType::New(); - m_MultiWidget->RequestUpdate(); + std::string nodename; + dataNodePointer->GetStringProperty("name",nodename); - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); + mitk::DiffusionImage* dwi = dynamic_cast*>(dataNodePointer->GetData()); - } - catch (itk::ExceptionObject &ex) - { - MITK_INFO << ex ; - QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); - return ; - } -} + filter->SetBValueMap(m_ShellSelectorMap[dataNodePointer]->GetBValueSelctionMap()); + filter->SetGradientImage( dwi->GetDirections(), dwi->GetVectorImage(), dwi->GetReferenceBValue() ); + filter->SetThreshold( m_Controls->m_QBallReconstructionThreasholdEdit->value() ); + filter->SetLambda(lambda); + filter->Update(); -template -void QmitkQBallReconstructionView::TemplatedMultiQBallReconstruction( - mitk::DiffusionImage* vols, float lambda, - const mitk::DataNode * dataNodePointer, std::vector* nodes) -{ - typedef itk::DiffusionMultiShellQballReconstructionImageFilter - FilterType; - typename FilterType::Pointer filter = FilterType::New(); - - std::string nodename; - dataNodePointer->GetStringProperty("name",nodename); - - filter->SetBValueMap(m_ShellSelectorMap[dataNodePointer]->GetBValueSelctionMap()); - filter->SetGradientImage( vols->GetDirections(), vols->GetVectorImage(), vols->GetReferenceBValue() ); - filter->SetThreshold( m_Controls->m_QBallReconstructionThreasholdEdit->value() ); - filter->SetLambda(lambda); - - - filter->Update(); - - // ODFs TO DATATREE - mitk::QBallImage::Pointer image = mitk::QBallImage::New(); - image->InitializeByItk( filter->GetOutput() ); - image->SetVolume( filter->GetOutput()->GetBufferPointer() ); - mitk::DataNode::Pointer node=mitk::DataNode::New(); - node->SetData( image ); - QString newname; - newname = newname.append(nodename.c_str()); - newname = newname.append("_QAMultiShell"); - SetDefaultNodeProperties(node, newname.toStdString()); - nodes->push_back(node); - - if(m_Controls->m_OutputCoeffsImage->isChecked()) - { - mitk::Image::Pointer coeffsImage = mitk::Image::New(); - coeffsImage->InitializeByItk( filter->GetCoefficientImage().GetPointer() ); - coeffsImage->SetVolume( filter->GetCoefficientImage()->GetBufferPointer() ); - mitk::DataNode::Pointer coeffsNode=mitk::DataNode::New(); - coeffsNode->SetData( coeffsImage ); - coeffsNode->SetProperty( "name", mitk::StringProperty::New( - QString(nodename.c_str()).append("_coeffs").toStdString()) ); - nodes->push_back(coeffsNode); - } + // ODFs TO DATATREE + mitk::QBallImage::Pointer image = mitk::QBallImage::New(); + image->InitializeByItk( filter->GetOutput() ); + image->SetVolume( filter->GetOutput()->GetBufferPointer() ); + mitk::DataNode::Pointer node=mitk::DataNode::New(); + node->SetData( image ); + SetDefaultNodeProperties(node, nodename+"_SphericalHarmonics_MultiShell_Qball"); + + GetDefaultDataStorage()->Add(node, dataNodePointer); + if(m_Controls->m_OutputCoeffsImage->isChecked()) + { + mitk::Image::Pointer coeffsImage = mitk::Image::New(); + coeffsImage->InitializeByItk( filter->GetCoefficientImage().GetPointer() ); + coeffsImage->SetVolume( filter->GetCoefficientImage()->GetBufferPointer() ); + mitk::DataNode::Pointer coeffsNode=mitk::DataNode::New(); + coeffsNode->SetData( coeffsImage ); + coeffsNode->SetProperty( "name", mitk::StringProperty::New( + QString(nodename.c_str()).append("_SH-Coefficients").toStdString()) ); + coeffsNode->SetVisibility(false); + GetDefaultDataStorage()->Add(coeffsNode, node); + } } void QmitkQBallReconstructionView::SetDefaultNodeProperties(mitk::DataNode::Pointer node, std::string name) { - node->SetProperty( "ShowMaxNumber", mitk::IntProperty::New( 500 ) ); - node->SetProperty( "Scaling", mitk::FloatProperty::New( 1.0 ) ); - node->SetProperty( "Normalization", mitk::OdfNormalizationMethodProperty::New()); - node->SetProperty( "ScaleBy", mitk::OdfScaleByProperty::New()); - node->SetProperty( "IndexParam1", mitk::FloatProperty::New(2)); - node->SetProperty( "IndexParam2", mitk::FloatProperty::New(1)); - node->SetProperty( "visible", mitk::BoolProperty::New( true ) ); - node->SetProperty( "VisibleOdfs", mitk::BoolProperty::New( false ) ); - node->SetProperty ("layer", mitk::IntProperty::New(100)); - node->SetProperty( "DoRefresh", mitk::BoolProperty::New( true ) ); - //node->SetProperty( "opacity", mitk::FloatProperty::New(1.0f) ); - - node->SetProperty( "name", mitk::StringProperty::New(name) ); - + node->SetProperty( "ShowMaxNumber", mitk::IntProperty::New( 500 ) ); + node->SetProperty( "Scaling", mitk::FloatProperty::New( 1.0 ) ); + node->SetProperty( "Normalization", mitk::OdfNormalizationMethodProperty::New()); + node->SetProperty( "ScaleBy", mitk::OdfScaleByProperty::New()); + node->SetProperty( "IndexParam1", mitk::FloatProperty::New(2)); + node->SetProperty( "IndexParam2", mitk::FloatProperty::New(1)); + node->SetProperty( "visible", mitk::BoolProperty::New( true ) ); + node->SetProperty( "VisibleOdfs", mitk::BoolProperty::New( false ) ); + node->SetProperty ("layer", mitk::IntProperty::New(100)); + node->SetProperty( "DoRefresh", mitk::BoolProperty::New( true ) ); + node->SetProperty( "name", mitk::StringProperty::New(name) ); } - -//node->SetProperty( "volumerendering", mitk::BoolProperty::New( false ) ); -//node->SetProperty( "use color", mitk::BoolProperty::New( true ) ); -//node->SetProperty( "texture interpolation", mitk::BoolProperty::New( true ) ); -//node->SetProperty( "reslice interpolation", mitk::VtkResliceInterpolationProperty::New() ); -//node->SetProperty( "layer", mitk::IntProperty::New(0)); -//node->SetProperty( "in plane resample extent by geometry", mitk::BoolProperty::New( false ) ); -//node->SetOpacity(1.0f); -//node->SetColor(1.0,1.0,1.0); -//node->SetVisibility(true); -//node->SetProperty( "IsQBallVolume", mitk::BoolProperty::New( true ) ); - -//mitk::LevelWindowProperty::Pointer levWinProp = mitk::LevelWindowProperty::New(); -//mitk::LevelWindow levelwindow; -//// levelwindow.SetAuto( image ); -//levWinProp->SetLevelWindow( levelwindow ); -//node->GetPropertyList()->SetPropertx( "levelwindow", levWinProp ); - -//// add a default rainbow lookup table for color mapping -//if(!node->GetProperty("LookupTable")) -//{ -// mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); -// vtkLookupTable* vtkLut = mitkLut->GetVtkLookupTable(); -// vtkLut->SetHueRange(0.6667, 0.0); -// vtkLut->SetTableRange(0.0, 20.0); -// vtkLut->Build(); -// mitk::LookupTableProperty::Pointer mitkLutProp = mitk::LookupTableProperty::New(); -// mitkLutProp->SetLookupTable(mitkLut); -// node->SetProperty( "LookupTable", mitkLutProp ); -//} -//if(!node->GetProperty("binary")) -// node->SetProperty( "binary", mitk::BoolProperty::New( false ) ); - -//// add a default transfer function -//mitk::TransferFunction::Pointer tf = mitk::TransferFunction::New(); -//node->SetProperty ( "TransferFunction", mitk::TransferFunctionProperty::New ( tf.GetPointer() ) ); - -//// set foldername as string property -//mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New( name ); -//node->SetProperty( "name", nameProp ); - - void QmitkQBallReconstructionView::GenerateShellSelectionUI(mitk::DataStorage::SetOfObjects::Pointer set) { - std::map tempMap; + std::map tempMap; - const mitk::DataStorage::SetOfObjects::iterator setEnd( set->end() ); - mitk::DataStorage::SetOfObjects::iterator NodeIt( set->begin() ); - while(NodeIt != setEnd) - { + const mitk::DataStorage::SetOfObjects::iterator setEnd( set->end() ); + mitk::DataStorage::SetOfObjects::iterator NodeIt( set->begin() ); + while(NodeIt != setEnd) + { - if(m_ShellSelectorMap.find( (*NodeIt).GetPointer() ) != m_ShellSelectorMap.end()) - { - tempMap[(*NodeIt).GetPointer()] = m_ShellSelectorMap[(*NodeIt).GetPointer()]; - m_ShellSelectorMap.erase((*NodeIt).GetPointer()); - }else - { - tempMap[(*NodeIt).GetPointer()] = new QbrShellSelection(this, (*NodeIt) ); - tempMap[(*NodeIt).GetPointer()]->SetVisible(true); - } + if(m_ShellSelectorMap.find( (*NodeIt).GetPointer() ) != m_ShellSelectorMap.end()) + { + tempMap[(*NodeIt).GetPointer()] = m_ShellSelectorMap[(*NodeIt).GetPointer()]; + m_ShellSelectorMap.erase((*NodeIt).GetPointer()); + }else + { + tempMap[(*NodeIt).GetPointer()] = new QbrShellSelection(this, (*NodeIt) ); + tempMap[(*NodeIt).GetPointer()]->SetVisible(true); + } - NodeIt++; - } + NodeIt++; + } - for(std::map::iterator it = m_ShellSelectorMap.begin(); it != m_ShellSelectorMap.end();it ++) - { - delete it->second; - } - m_ShellSelectorMap.clear(); - m_ShellSelectorMap = tempMap; + for(std::map::iterator it = m_ShellSelectorMap.begin(); it != m_ShellSelectorMap.end();it ++) + { + delete it->second; + } + m_ShellSelectorMap.clear(); + m_ShellSelectorMap = tempMap; } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.h b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.h index 3d45f1dacd..429da04967 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.h +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkQBallReconstructionView.h @@ -1,125 +1,123 @@ /*=================================================================== 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 _QMITKQBALLRECONSTRUCTIONVIEW_H_INCLUDED #define _QMITKQBALLRECONSTRUCTIONVIEW_H_INCLUDED #include #include #include "ui_QmitkQBallReconstructionViewControls.h" #include "mitkDiffusionImage.h" #include #include #include typedef short DiffusionPixelType; struct QbrSelListener; struct QbrShellSelection; /*! * \ingroup org_mitk_gui_qt_qballreconstruction_internal * * \brief QmitkQBallReconstructionView * * Document your class here. * * \sa QmitkFunctionality */ class QmitkQBallReconstructionView : public QmitkFunctionality { friend struct QbrSelListener; friend struct QbrShellSelection; // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkQBallReconstructionView(); virtual ~QmitkQBallReconstructionView(); virtual void CreateQtPartControl(QWidget *parent); /// \brief Creation of the connections of main and control widget virtual void CreateConnections(); /// \brief Called when the functionality is activated virtual void Activated(); virtual void Deactivated(); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); static const int nrconvkernels; protected slots: void ReconstructStandard(); void AdvancedCheckboxClicked(); void MethodChoosen(int method); void Reconstruct(int method, int normalization); void NumericalQBallReconstruction(mitk::DataStorage::SetOfObjects::Pointer inImages, int normalization); void AnalyticalQBallReconstruction(mitk::DataStorage::SetOfObjects::Pointer inImages, int normalization); void MultiQBallReconstruction(mitk::DataStorage::SetOfObjects::Pointer inImages); protected: /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( std::vector nodes ); Ui::QmitkQBallReconstructionViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; template - void TemplatedAnalyticalQBallReconstruction(mitk::DiffusionImage* vols, - float lambda, std::string nodename, std::vector* nodes, int normalization); + void TemplatedAnalyticalQBallReconstruction(mitk::DataNode* dataNodePointer, float lambda, int normalization); template - void TemplatedMultiQBallReconstruction(mitk::DiffusionImage* vols, - float lambda, const mitk::DataNode * , std::vector* nodes); + void TemplatedMultiQBallReconstruction(float lambda, mitk::DataNode*); void SetDefaultNodeProperties(mitk::DataNode::Pointer node, std::string name); //void Create berry::ISelectionListener::Pointer m_SelListener; berry::IStructuredSelection::ConstPointer m_CurrentSelection; private: std::map< const mitk::DataNode *, QbrShellSelection * > m_ShellSelectorMap; void GenerateShellSelectionUI(mitk::DataStorage::SetOfObjects::Pointer set); }; #endif // _QMITKQBALLRECONSTRUCTIONVIEW_H_INCLUDED diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkTensorReconstructionView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkTensorReconstructionView.cpp index 1df5dff8ef..db1e14a815 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkTensorReconstructionView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkTensorReconstructionView.cpp @@ -1,1022 +1,967 @@ /*=================================================================== 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 "QmitkTensorReconstructionView.h" #include "mitkDiffusionImagingConfigure.h" // qt includes #include #include #include #include #include // itk includes #include "itkTimeProbe.h" //#include "itkTensor.h" // mitk includes #include "mitkProgressBar.h" #include "mitkStatusBar.h" #include "mitkNodePredicateDataType.h" #include "QmitkDataStorageComboBox.h" #include "QmitkStdMultiWidget.h" #include "mitkTeemDiffusionTensor3DReconstructionImageFilter.h" #include "itkDiffusionTensor3DReconstructionImageFilter.h" #include "itkTensorImageToDiffusionImageFilter.h" #include "itkPointShell.h" #include "itkVector.h" #include "itkB0ImageExtractionImageFilter.h" #include "itkTensorReconstructionWithEigenvalueCorrectionFilter.h" //#include "itkFreeWaterEliminationFilter.h" #include "mitkProperties.h" #include "mitkDataNodeObject.h" #include "mitkOdfNormalizationMethodProperty.h" #include "mitkOdfScaleByProperty.h" #include "mitkDiffusionImageMapper.h" #include "mitkLookupTableProperty.h" #include "mitkLookupTable.h" #include "mitkImageStatisticsHolder.h" #include #include #include #include const std::string QmitkTensorReconstructionView::VIEW_ID = "org.mitk.views.tensorreconstruction"; typedef float TTensorPixelType; typedef itk::DiffusionTensor3D< TTensorPixelType > TensorPixelType; typedef itk::Image< TensorPixelType, 3 > TensorImageType; using namespace berry; QmitkTensorReconstructionView::QmitkTensorReconstructionView() : QmitkFunctionality(), m_Controls(NULL), m_MultiWidget(NULL) { m_DiffusionImages = mitk::DataStorage::SetOfObjects::New(); m_TensorImages = mitk::DataStorage::SetOfObjects::New(); } QmitkTensorReconstructionView::~QmitkTensorReconstructionView() { } void QmitkTensorReconstructionView::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkTensorReconstructionViewControls; m_Controls->setupUi(parent); this->CreateConnections(); Advanced1CheckboxClicked(); } } void QmitkTensorReconstructionView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkTensorReconstructionView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } void QmitkTensorReconstructionView::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_StartReconstruction), SIGNAL(clicked()), this, SLOT(Reconstruct()) ); connect( (QObject*)(m_Controls->m_Advanced1), SIGNAL(clicked()), this, SLOT(Advanced1CheckboxClicked()) ); connect( (QObject*)(m_Controls->m_TensorsToDWIButton), SIGNAL(clicked()), this, SLOT(TensorsToDWI()) ); connect( (QObject*)(m_Controls->m_TensorsToQbiButton), SIGNAL(clicked()), this, SLOT(TensorsToQbi()) ); connect( (QObject*)(m_Controls->m_ResidualButton), SIGNAL(clicked()), this, SLOT(ResidualCalculation()) ); connect( (QObject*)(m_Controls->m_PerSliceView), SIGNAL(pointSelected(int, int)), this, SLOT(ResidualClicked(int, int)) ); } } void QmitkTensorReconstructionView::ResidualClicked(int slice, int volume) { // Use image coord to reset crosshair // Find currently selected diffusion image // Update Label // to do: This position should be modified in order to skip B0 volumes that are not taken into account // when calculating residuals // Find the diffusion image mitk::DiffusionImage* diffImage; mitk::DataNode::Pointer correctNode; mitk::Geometry3D* geometry; if (m_DiffusionImage.IsNotNull()) { diffImage = static_cast*>(m_DiffusionImage->GetData()); geometry = diffImage->GetGeometry(); // Remember the node whose display index must be updated correctNode = mitk::DataNode::New(); correctNode = m_DiffusionImage; } if(diffImage != NULL) { typedef vnl_vector_fixed< double, 3 > GradientDirectionType; typedef itk::VectorContainer< unsigned int, GradientDirectionType > GradientDirectionContainerType; GradientDirectionContainerType::Pointer dirs = diffImage->GetDirections(); for(unsigned int i=0; iSize() && i<=volume; i++) { GradientDirectionType grad = dirs->ElementAt(i); // check if image is b0 weighted if(fabs(grad[0]) < 0.001 && fabs(grad[1]) < 0.001 && fabs(grad[2]) < 0.001) { volume++; } } QString pos = "Volume: "; pos.append(QString::number(volume)); pos.append(", Slice: "); pos.append(QString::number(slice)); m_Controls->m_PositionLabel->setText(pos); if(correctNode) { int oldDisplayVal; correctNode->GetIntProperty("DisplayChannel", oldDisplayVal); std::string oldVal = QString::number(oldDisplayVal).toStdString(); std::string newVal = QString::number(volume).toStdString(); correctNode->SetIntProperty("DisplayChannel",volume); correctNode->SetSelected(true); this->FirePropertyChanged("DisplayChannel", oldVal, newVal); correctNode->UpdateOutputInformation(); mitk::Point3D p3 = m_MultiWidget->GetCrossPosition(); itk::Index<3> ix; geometry->WorldToIndex(p3, ix); // ix[2] = slice; mitk::Vector3D vec; vec[0] = ix[0]; vec[1] = ix[1]; vec[2] = slice; mitk::Vector3D v3New; geometry->IndexToWorld(vec, v3New); mitk::Point3D origin = geometry->GetOrigin(); mitk::Point3D p3New; p3New[0] = v3New[0] + origin[0]; p3New[1] = v3New[1] + origin[1]; p3New[2] = v3New[2] + origin[2]; m_MultiWidget->MoveCrossToPosition(p3New); m_MultiWidget->RequestUpdate(); } } } void QmitkTensorReconstructionView::Advanced1CheckboxClicked() { bool check = m_Controls-> m_Advanced1->isChecked(); m_Controls->frame->setVisible(check); } void QmitkTensorReconstructionView::Activated() { QmitkFunctionality::Activated(); } void QmitkTensorReconstructionView::Deactivated() { QmitkFunctionality::Deactivated(); } void QmitkTensorReconstructionView::ResidualCalculation() { // Extract dwi and dti from current selection // In case of multiple selections, take the first one, since taking all combinations is not meaningful mitk::DataStorage::SetOfObjects::Pointer set = mitk::DataStorage::SetOfObjects::New(); mitk::DiffusionImage::Pointer diffImage = mitk::DiffusionImage::New(); TensorImageType::Pointer tensorImage; std::string nodename; if(m_DiffusionImage.IsNotNull()) { diffImage = static_cast*>(m_DiffusionImage->GetData()); } else return; if(m_TensorImage.IsNotNull()) { mitk::TensorImage* mitkVol; mitkVol = static_cast(m_TensorImage->GetData()); mitk::CastToItkImage(mitkVol, tensorImage); m_TensorImage->GetStringProperty("name", nodename); } else return; typedef itk::TensorImageToDiffusionImageFilter< TTensorPixelType, DiffusionPixelType > FilterType; mitk::DiffusionImage::GradientDirectionContainerType* gradients = diffImage->GetDirections(); // Find the min and the max values from a baseline image mitk::ImageStatisticsHolder *stats = diffImage->GetStatistics(); //Initialize filter that calculates the modeled diffusion weighted signals FilterType::Pointer filter = FilterType::New(); filter->SetInput( tensorImage ); filter->SetBValue(diffImage->GetReferenceBValue()); filter->SetGradientList(gradients); filter->SetMin(stats->GetScalarValueMin()); filter->SetMax(stats->GetScalarValueMax()); filter->Update(); // TENSORS TO DATATREE mitk::DiffusionImage::Pointer image = mitk::DiffusionImage::New(); image->SetVectorImage( filter->GetOutput() ); image->SetReferenceBValue(diffImage->GetReferenceBValue()); image->SetDirections(gradients); image->InitializeFromVectorImage(); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData( image ); mitk::DiffusionImageMapper::SetDefaultProperties(node); QString newname; newname = newname.append(nodename.c_str()); - newname = newname.append("_dwi"); + newname = newname.append("_DWI"); node->SetName(newname.toAscii()); GetDefaultDataStorage()->Add(node); mitk::DiffusionImage::BValueMap map =image->GetBValueMap(); mitk::DiffusionImage::IndicesVector b0Indices = map[0]; typedef itk::ResidualImageFilter ResidualImageFilterType; ResidualImageFilterType::Pointer residualFilter = ResidualImageFilterType::New(); residualFilter->SetInput(diffImage->GetVectorImage()); residualFilter->SetSecondDiffusionImage(image->GetVectorImage()); residualFilter->SetGradients(gradients); residualFilter->SetB0Index(b0Indices[0]); residualFilter->SetB0Threshold(30); residualFilter->Update(); itk::Image::Pointer residualImage = itk::Image::New(); residualImage = residualFilter->GetOutput(); mitk::Image::Pointer mitkResImg = mitk::Image::New(); mitk::CastToMitkImage(residualImage, mitkResImg); stats = mitkResImg->GetStatistics(); float min = stats->GetScalarValueMin(); float max = stats->GetScalarValueMax(); mitk::LookupTableProperty::Pointer lutProp = mitk::LookupTableProperty::New(); mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); vtkSmartPointer lookupTable = vtkSmartPointer::New(); lookupTable->SetTableRange(min, max); // If you don't want to use the whole color range, you can use // SetValueRange, SetHueRange, and SetSaturationRange lookupTable->Build(); vtkSmartPointer reversedlookupTable = vtkSmartPointer::New(); reversedlookupTable->SetTableRange(min+1, max); reversedlookupTable->Build(); for(int i=0; i<256; i++) { double* rgba = reversedlookupTable->GetTableValue(255-i); lookupTable->SetTableValue(i, rgba[0], rgba[1], rgba[2], rgba[3]); } lut->SetVtkLookupTable(lookupTable); lutProp->SetLookupTable(lut); // Create lookuptable mitk::DataNode::Pointer resNode=mitk::DataNode::New(); resNode->SetData( mitkResImg ); resNode->SetName("Residual Image"); resNode->SetProperty("LookupTable", lutProp); bool b; resNode->GetBoolProperty("use color", b); resNode->SetBoolProperty("use color", false); GetDefaultDataStorage()->Add(resNode); m_MultiWidget->RequestUpdate(); // Draw Graph std::vector means = residualFilter->GetMeans(); std::vector q1s = residualFilter->GetQ1(); std::vector q3s = residualFilter->GetQ3(); std::vector percentagesOfOUtliers = residualFilter->GetPercentagesOfOutliers(); m_Controls->m_ResidualAnalysis->SetMeans(means); m_Controls->m_ResidualAnalysis->SetQ1(q1s); m_Controls->m_ResidualAnalysis->SetQ3(q3s); m_Controls->m_ResidualAnalysis->SetPercentagesOfOutliers(percentagesOfOUtliers); if(m_Controls->m_PercentagesOfOutliers->isChecked()) { m_Controls->m_ResidualAnalysis->DrawPercentagesOfOutliers(); } else { m_Controls->m_ResidualAnalysis->DrawMeans(); } // Draw Graph for volumes per slice in the QGraphicsView std::vector< std::vector > outliersPerSlice = residualFilter->GetOutliersPerSlice(); int xSize = outliersPerSlice.size(); if(xSize == 0) { return; } int ySize = outliersPerSlice[0].size(); // Find maximum in outliersPerSlice double maxOutlier= 0.0; for(int i=0; imaxOutlier) { maxOutlier = outliersPerSlice[i][j]; } } } // Create some QImage QImage qImage(xSize, ySize, QImage::Format_RGB32); QImage legend(1, 256, QImage::Format_RGB32); QRgb value; vtkSmartPointer lookup = vtkSmartPointer::New(); lookup->SetTableRange(0.0, maxOutlier); lookup->Build(); reversedlookupTable->SetTableRange(0, maxOutlier); reversedlookupTable->Build(); for(int i=0; i<256; i++) { double* rgba = reversedlookupTable->GetTableValue(255-i); lookup->SetTableValue(i, rgba[0], rgba[1], rgba[2], rgba[3]); } // Fill qImage for(int i=0; iMapValue(out); int r, g, b; r = _rgba[0]; g = _rgba[1]; b = _rgba[2]; value = qRgb(r, g, b); qImage.setPixel(i,j,value); } } for(int i=0; i<256; i++) { double* rgba = lookup->GetTableValue(i); int r, g, b; r = rgba[0]*255; g = rgba[1]*255; b = rgba[2]*255; value = qRgb(r, g, b); legend.setPixel(0,255-i,value); } QString upper = QString::number(maxOutlier, 'g', 3); upper.append(" %"); QString lower = QString::number(0.0); lower.append(" %"); m_Controls->m_UpperLabel->setText(upper); m_Controls->m_LowerLabel->setText(lower); QGraphicsScene* scene = new QGraphicsScene; QGraphicsScene* scene2 = new QGraphicsScene; QPixmap pixmap(QPixmap::fromImage(qImage)); QGraphicsPixmapItem *item = new QGraphicsPixmapItem( pixmap, 0, scene); item->scale(10.0, 3.0); QPixmap pixmap2(QPixmap::fromImage(legend)); QGraphicsPixmapItem *item2 = new QGraphicsPixmapItem( pixmap2, 0, scene2); item2->scale(20.0, 1.0); m_Controls->m_PerSliceView->SetResidualPixmapItem(item); m_Controls->m_PerSliceView->setScene(scene); m_Controls->m_LegendView->setScene(scene2); m_Controls->m_PerSliceView->show(); m_Controls->m_PerSliceView->repaint(); m_Controls->m_LegendView->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); m_Controls->m_LegendView->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); m_Controls->m_LegendView->show(); m_Controls->m_LegendView->repaint(); } void QmitkTensorReconstructionView::Reconstruct() { int method = m_Controls->m_ReconctructionMethodBox->currentIndex(); switch (method) { case 0: ItkTensorReconstruction(m_DiffusionImages); break; case 1: TensorReconstructionWithCorr(m_DiffusionImages); break; default: ItkTensorReconstruction(m_DiffusionImages); } } void QmitkTensorReconstructionView::TensorReconstructionWithCorr (mitk::DataStorage::SetOfObjects::Pointer inImages) { try { - itk::TimeProbe clock; int nrFiles = inImages->size(); if (!nrFiles) return; QString status; mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - std::vector nodes; while ( itemiter != itemiterend ) // for all items { typedef mitk::DiffusionImage DiffusionImageType; typedef DiffusionImageType::GradientDirectionContainerType GradientDirectionContainerType; DiffusionImageType* vols = static_cast((*itemiter)->GetData()); std::string nodename; (*itemiter)->GetStringProperty("name", nodename); - ++itemiter; // TENSOR RECONSTRUCTION - clock.Start(); MITK_INFO << "Tensor reconstruction with correction for negative eigenvalues"; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Tensor reconstruction for %s", nodename.c_str()).toAscii()); typedef itk::TensorReconstructionWithEigenvalueCorrectionFilter< DiffusionPixelType, TTensorPixelType > ReconstructionFilter; float b0Threshold = m_Controls->m_TensorReconstructionThreshold->value(); GradientDirectionContainerType::Pointer gradientContainerCopy = GradientDirectionContainerType::New(); for(GradientDirectionContainerType::ConstIterator it = vols->GetDirections()->Begin(); it != vols->GetDirections()->End(); it++) { gradientContainerCopy->push_back(it.Value()); } ReconstructionFilter::Pointer reconFilter = ReconstructionFilter::New(); reconFilter->SetGradientImage( gradientContainerCopy, vols->GetVectorImage() ); reconFilter->SetBValue(vols->GetReferenceBValue()); reconFilter->SetB0Threshold(b0Threshold); reconFilter->Update(); typedef itk::Image, 3> TensorImageType; TensorImageType::Pointer outputTensorImg = reconFilter->GetOutput(); typedef itk::ImageRegionIterator TensorImageIteratorType; TensorImageIteratorType tensorIt(outputTensorImg, outputTensorImg->GetRequestedRegion()); tensorIt.GoToBegin(); int negatives = 0; while(!tensorIt.IsAtEnd()) { typedef itk::DiffusionTensor3D TensorType; TensorType tensor = tensorIt.Get(); TensorType::EigenValuesArrayType ev; tensor.ComputeEigenValues(ev); for(unsigned int i=0; iInitializeByItk( outputTensorImg.GetPointer() ); image->SetVolume( outputTensorImg->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); - - QString newname; - newname = newname.append(nodename.c_str()); - newname = newname.append("_dti_corrected"); - - SetDefaultNodeProperties(node, newname.toStdString()); - nodes.push_back(node); - - // Corrected diffusion image -// typedef itk::VectorImage ImageType; -// ImageType::Pointer correctedVols = reconFilter->GetVectorImage(); -// DiffusionImageType::Pointer correctedDiffusion = DiffusionImageType::New(); -// correctedDiffusion->SetVectorImage(correctedVols); -// correctedDiffusion->SetDirections(vols->GetDirections()); -// correctedDiffusion->SetB_Value(vols->GetB_Value()); -// correctedDiffusion->InitializeFromVectorImage(); -// mitk::DataNode::Pointer diffNode = mitk::DataNode::New(); -// diffNode->SetData( correctedDiffusion ); -// QString diffname; -// diffname = diffname.append(nodename.c_str()); -// diffname = diffname.append("corrDiff"); -// SetDefaultNodeProperties(diffNode, diffname.toStdString()); -// nodes.push_back(diffNode); + SetDefaultNodeProperties(node, nodename+"_EigenvalueCorrected_DT"); + GetDefaultDataStorage()->Add(node, *itemiter); mitk::ProgressBar::GetInstance()->Progress(); + ++itemiter; } - std::vector::iterator nodeIt; - for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) - GetDefaultDataStorage()->Add(*nodeIt); - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); m_MultiWidget->RequestUpdate(); } catch (itk::ExceptionObject &ex) { MITK_INFO << ex ; QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); } } void QmitkTensorReconstructionView::ItkTensorReconstruction(mitk::DataStorage::SetOfObjects::Pointer inImages) { try { itk::TimeProbe clock; int nrFiles = inImages->size(); if (!nrFiles) return; QString status; mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - std::vector nodes; while ( itemiter != itemiterend ) // for all items { mitk::DiffusionImage* vols = static_cast*>( (*itemiter)->GetData()); std::string nodename; (*itemiter)->GetStringProperty("name", nodename); - ++itemiter; // TENSOR RECONSTRUCTION clock.Start(); MITK_DEBUG << "Tensor reconstruction "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Tensor reconstruction for %s", nodename.c_str()).toAscii()); typedef itk::DiffusionTensor3DReconstructionImageFilter< DiffusionPixelType, DiffusionPixelType, TTensorPixelType > TensorReconstructionImageFilterType; TensorReconstructionImageFilterType::Pointer tensorReconstructionFilter = TensorReconstructionImageFilterType::New(); typedef mitk::DiffusionImage DiffusionImageType; typedef DiffusionImageType::GradientDirectionContainerType GradientDirectionContainerType; GradientDirectionContainerType::Pointer gradientContainerCopy = GradientDirectionContainerType::New(); for(GradientDirectionContainerType::ConstIterator it = vols->GetDirections()->Begin(); it != vols->GetDirections()->End(); it++) { gradientContainerCopy->push_back(it.Value()); } tensorReconstructionFilter->SetGradientImage( gradientContainerCopy, vols->GetVectorImage() ); tensorReconstructionFilter->SetBValue(vols->GetReferenceBValue()); tensorReconstructionFilter->SetThreshold( m_Controls->m_TensorReconstructionThreshold->value() ); tensorReconstructionFilter->Update(); clock.Stop(); MITK_DEBUG << "took " << clock.GetMean() << "s."; // TENSORS TO DATATREE mitk::TensorImage::Pointer image = mitk::TensorImage::New(); typedef itk::Image, 3> TensorImageType; TensorImageType::Pointer tensorImage; tensorImage = tensorReconstructionFilter->GetOutput(); // Check the tensor for negative eigenvalues if(m_Controls->m_CheckNegativeEigenvalues->isChecked()) { typedef itk::ImageRegionIterator TensorImageIteratorType; TensorImageIteratorType tensorIt(tensorImage, tensorImage->GetRequestedRegion()); tensorIt.GoToBegin(); while(!tensorIt.IsAtEnd()) { typedef itk::DiffusionTensor3D TensorType; //typedef itk::Tensor TensorType2; TensorType tensor = tensorIt.Get(); TensorType::EigenValuesArrayType ev; tensor.ComputeEigenValues(ev); for(unsigned int i=0; iSetDirection( vols->GetVectorImage()->GetDirection() ); image->InitializeByItk( tensorImage.GetPointer() ); image->SetVolume( tensorReconstructionFilter->GetOutput()->GetBufferPointer() ); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); - - QString newname; - newname = newname.append(nodename.c_str()); - newname = newname.append("_dti"); - - SetDefaultNodeProperties(node, newname.toStdString()); - nodes.push_back(node); - + SetDefaultNodeProperties(node, nodename+"_WeightedLinearLeastSquares_DT"); + GetDefaultDataStorage()->Add(node, *itemiter); mitk::ProgressBar::GetInstance()->Progress(); + ++itemiter; } - std::vector::iterator nodeIt; - for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) - GetDefaultDataStorage()->Add(*nodeIt); - mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); m_MultiWidget->RequestUpdate(); - } catch (itk::ExceptionObject &ex) { MITK_INFO << ex ; QMessageBox::information(0, "Reconstruction not possible:", ex.GetDescription()); return; } } void QmitkTensorReconstructionView::SetDefaultNodeProperties(mitk::DataNode::Pointer node, std::string name) { node->SetProperty( "ShowMaxNumber", mitk::IntProperty::New( 500 ) ); node->SetProperty( "Scaling", mitk::FloatProperty::New( 1.0 ) ); node->SetProperty( "Normalization", mitk::OdfNormalizationMethodProperty::New()); node->SetProperty( "ScaleBy", mitk::OdfScaleByProperty::New()); node->SetProperty( "IndexParam1", mitk::FloatProperty::New(2)); node->SetProperty( "IndexParam2", mitk::FloatProperty::New(1)); node->SetProperty( "visible", mitk::BoolProperty::New( true ) ); node->SetProperty( "VisibleOdfs", mitk::BoolProperty::New( false ) ); node->SetProperty ("layer", mitk::IntProperty::New(100)); node->SetProperty( "DoRefresh", mitk::BoolProperty::New( true ) ); node->SetProperty( "name", mitk::StringProperty::New(name) ); } void QmitkTensorReconstructionView::TensorsToDWI() { DoTensorsToDWI(m_TensorImages); } void QmitkTensorReconstructionView::TensorsToQbi() { for (unsigned int i=0; isize(); i++) { mitk::DataNode::Pointer tensorImageNode = m_TensorImages->at(i); MITK_INFO << "starting Q-Ball estimation"; typedef float TTensorPixelType; typedef itk::DiffusionTensor3D< TTensorPixelType > TensorPixelType; typedef itk::Image< TensorPixelType, 3 > TensorImageType; TensorImageType::Pointer itkvol = TensorImageType::New(); mitk::CastToItkImage(dynamic_cast(tensorImageNode->GetData()), itkvol); typedef itk::TensorImageToQBallImageFilter< TTensorPixelType, TTensorPixelType > FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetInput( itkvol ); filter->Update(); typedef itk::Vector OutputPixelType; typedef itk::Image OutputImageType; mitk::QBallImage::Pointer image = mitk::QBallImage::New(); OutputImageType::Pointer outimg = filter->GetOutput(); image->InitializeByItk( outimg.GetPointer() ); image->SetVolume( outimg->GetBufferPointer() ); mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData( image ); - QString newname; - newname = newname.append(tensorImageNode->GetName().c_str()); - newname = newname.append("_qbi"); - node->SetName(newname.toAscii()); - GetDefaultDataStorage()->Add(node); + node->SetName(tensorImageNode->GetName()+"_Qball"); + GetDefaultDataStorage()->Add(node, tensorImageNode); } } void QmitkTensorReconstructionView::OnSelectionChanged( std::vector nodes ) { m_DiffusionImages = mitk::DataStorage::SetOfObjects::New(); m_TensorImages = mitk::DataStorage::SetOfObjects::New(); bool foundDwiVolume = false; bool foundTensorVolume = false; m_Controls->m_DiffusionImageLabel->setText("mandatory"); m_DiffusionImage = NULL; m_TensorImage = NULL; m_Controls->m_InputData->setTitle("Please Select Input Data"); // iterate selection for( std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it ) { mitk::DataNode::Pointer node = *it; if (node.IsNull()) continue; // only look at interesting types if(dynamic_cast*>(node->GetData())) { foundDwiVolume = true; m_Controls->m_DiffusionImageLabel->setText(node->GetName().c_str()); m_DiffusionImages->push_back(node); m_DiffusionImage = node; } else if(dynamic_cast(node->GetData())) { foundTensorVolume = true; m_Controls->m_DiffusionImageLabel->setText(node->GetName().c_str()); m_TensorImages->push_back(node); m_TensorImage = node; } } m_Controls->m_StartReconstruction->setEnabled(foundDwiVolume); m_Controls->m_TensorsToDWIButton->setEnabled(foundTensorVolume); m_Controls->m_TensorsToQbiButton->setEnabled(foundTensorVolume); if (foundDwiVolume || foundTensorVolume) m_Controls->m_InputData->setTitle("Input Data"); m_Controls->m_ResidualButton->setEnabled(foundDwiVolume && foundTensorVolume); m_Controls->m_PercentagesOfOutliers->setEnabled(foundDwiVolume && foundTensorVolume); m_Controls->m_PerSliceView->setEnabled(foundDwiVolume && foundTensorVolume); } template QmitkTensorReconstructionView::GradientListType::Pointer QmitkTensorReconstructionView::MakeGradientList() { QmitkTensorReconstructionView::GradientListType::Pointer retval = GradientListType::New(); vnl_matrix_fixed* U = itk::PointShell >::DistributePointShell(); for(int i=0; iget(0,i); v[1] = U->get(1,i); v[2] = U->get(2,i); retval->push_back(v); } // Add 0 vector for B0 GradientType v(0.0); retval->push_back(v); return retval; } void QmitkTensorReconstructionView::DoTensorsToDWI(mitk::DataStorage::SetOfObjects::Pointer inImages) { try { itk::TimeProbe clock; int nrFiles = inImages->size(); if (!nrFiles) return; QString status; mitk::ProgressBar::GetInstance()->AddStepsToDo(nrFiles); mitk::DataStorage::SetOfObjects::const_iterator itemiter( inImages->begin() ); mitk::DataStorage::SetOfObjects::const_iterator itemiterend( inImages->end() ); - std::vector nodes; while ( itemiter != itemiterend ) // for all items { std::string nodename; (*itemiter)->GetStringProperty("name", nodename); mitk::TensorImage* vol = static_cast((*itemiter)->GetData()); - ++itemiter; - typedef float TTensorPixelType; typedef itk::DiffusionTensor3D< TTensorPixelType > TensorPixelType; typedef itk::Image< TensorPixelType, 3 > TensorImageType; TensorImageType::Pointer itkvol = TensorImageType::New(); mitk::CastToItkImage(vol, itkvol); typedef itk::TensorImageToDiffusionImageFilter< TTensorPixelType, DiffusionPixelType > FilterType; FilterType::GradientListType::Pointer gradientList; switch(m_Controls->m_TensorsToDWINumDirsSelect->currentIndex()) { case 0: gradientList = MakeGradientList<12>(); break; case 1: gradientList = MakeGradientList<42>(); break; case 2: gradientList = MakeGradientList<92>(); break; case 3: gradientList = MakeGradientList<162>(); break; case 4: gradientList = MakeGradientList<252>(); break; case 5: gradientList = MakeGradientList<362>(); break; case 6: gradientList = MakeGradientList<492>(); break; case 7: gradientList = MakeGradientList<642>(); break; case 8: gradientList = MakeGradientList<812>(); break; case 9: gradientList = MakeGradientList<1002>(); break; default: gradientList = MakeGradientList<92>(); } double bVal = m_Controls->m_TensorsToDWIBValueEdit->text().toDouble(); // DWI ESTIMATION clock.Start(); MBI_INFO << "DWI Estimation "; mitk::StatusBar::GetInstance()->DisplayText(status.sprintf( "DWI Estimation for %s", nodename.c_str()).toAscii()); FilterType::Pointer filter = FilterType::New(); filter->SetInput( itkvol ); filter->SetBValue(bVal); filter->SetGradientList(gradientList); //filter->SetNumberOfThreads(1); filter->Update(); clock.Stop(); MBI_DEBUG << "took " << clock.GetMean() << "s."; // TENSORS TO DATATREE mitk::DiffusionImage::Pointer image = mitk::DiffusionImage::New(); image->SetVectorImage( filter->GetOutput() ); image->SetReferenceBValue(bVal); image->SetDirections(gradientList); image->InitializeFromVectorImage(); mitk::DataNode::Pointer node=mitk::DataNode::New(); node->SetData( image ); - mitk::DiffusionImageMapper::SetDefaultProperties(node); - - QString newname; - newname = newname.append(nodename.c_str()); - newname = newname.append("_dwi"); - node->SetName(newname.toAscii()); - - nodes.push_back(node); + node->SetName(nodename+"_DWI"); + GetDefaultDataStorage()->Add(node, *itemiter); mitk::ProgressBar::GetInstance()->Progress(); - + ++itemiter; } - std::vector::iterator nodeIt; - for(nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt) - GetDefaultDataStorage()->Add(*nodeIt); mitk::StatusBar::GetInstance()->DisplayText(status.sprintf("Finished Processing %d Files", nrFiles).toAscii()); m_MultiWidget->RequestUpdate(); } catch (itk::ExceptionObject &ex) { MITK_INFO << ex ; QMessageBox::information(0, "DWI estimation failed:", ex.GetDescription()); return ; } }