00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkDataNodeObject.h"
00019 #include "mitkProperties.h"
00020 #include "mitkSegTool2D.h"
00021 #include "mitkGlobalInteraction.h"
00022
00023 #include "QmitkStdMultiWidget.h"
00024 #include "QmitkNewSegmentationDialog.h"
00025
00026 #include <QMessageBox>
00027
00028 #include <berryIWorkbenchPage.h>
00029
00030 #include "QmitkSegmentationView.h"
00031 #include "QmitkSegmentationPostProcessing.h"
00032 #include "QmitkSegmentationOrganNamesHandling.cpp"
00033
00034 #include <mitkSurfaceToImageFilter.h>
00035 #include <vtkPolyData.h>
00036
00037
00038
00039 QmitkSegmentationView::QmitkSegmentationView()
00040 :m_Parent(NULL)
00041 ,m_Controls(NULL)
00042 ,m_MultiWidget(NULL)
00043 ,m_PostProcessing(NULL)
00044 ,m_RenderingManagerObserverTag(0)
00045 {
00046 }
00047
00048 QmitkSegmentationView::~QmitkSegmentationView()
00049 {
00050 delete m_PostProcessing;
00051 delete m_Controls;
00052 }
00053
00054 void QmitkSegmentationView::NewNodesGenerated()
00055 {
00056 ForceDisplayPreferencesUponAllImages();
00057 }
00058
00059 void QmitkSegmentationView::NewNodeObjectsGenerated(mitk::ToolManager::DataVectorType* nodes)
00060 {
00061 if (!nodes) return;
00062
00063 mitk::ToolManager* toolManager = m_Controls->m_ManualToolSelectionBox->GetToolManager();
00064 if (!toolManager) return;
00065 for (mitk::ToolManager::DataVectorType::iterator iter = nodes->begin(); iter != nodes->end(); ++iter)
00066 {
00067 this->FireNodeSelected( *iter );
00068
00069 }
00070 }
00071
00072 void QmitkSegmentationView::Activated()
00073 {
00074
00075 if( m_Controls )
00076 {
00077 m_Controls->m_ManualToolSelectionBox->setEnabled( true );
00078 m_Controls->m_OrganToolSelectionBox->setEnabled( true );
00079 m_Controls->m_LesionToolSelectionBox->setEnabled( true );
00080
00081 m_Controls->m_SlicesInterpolator->EnableInterpolation( m_Controls->widgetStack->currentWidget() == m_Controls->pageManual );
00082
00083 itk::ReceptorMemberCommand<QmitkSegmentationView>::Pointer command1 = itk::ReceptorMemberCommand<QmitkSegmentationView>::New();
00084 command1->SetCallbackFunction( this, &QmitkSegmentationView::RenderingManagerReinitialized );
00085 m_RenderingManagerObserverTag = mitk::RenderingManager::GetInstance()->AddObserver( mitk::RenderingManagerViewsInitializedEvent(), command1 );
00086 }
00087 }
00088
00089 void QmitkSegmentationView::Deactivated()
00090 {
00091 if( m_Controls )
00092 {
00093 mitk::RenderingManager::GetInstance()->RemoveObserver( m_RenderingManagerObserverTag );
00094
00095 m_Controls->m_ManualToolSelectionBox->setEnabled( false );
00096
00097 m_Controls->m_ManualToolSelectionBox->GetToolManager()->ActivateTool(-1);
00098 m_Controls->m_OrganToolSelectionBox->setEnabled( false );
00099 m_Controls->m_LesionToolSelectionBox->setEnabled( false );
00100
00101 m_Controls->m_SlicesInterpolator->EnableInterpolation( false );
00102 }
00103 }
00104
00105 void QmitkSegmentationView::StdMultiWidgetAvailable( QmitkStdMultiWidget& stdMultiWidget )
00106 {
00107 SetMultiWidget(&stdMultiWidget);
00108 }
00109
00110 void QmitkSegmentationView::StdMultiWidgetNotAvailable()
00111 {
00112 SetMultiWidget(NULL);
00113 }
00114
00115 void QmitkSegmentationView::StdMultiWidgetClosed( QmitkStdMultiWidget& )
00116 {
00117 SetMultiWidget(NULL);
00118 }
00119
00120 void QmitkSegmentationView::SetMultiWidget(QmitkStdMultiWidget* multiWidget)
00121 {
00122 if (m_MultiWidget)
00123 {
00124 mitk::SlicesCoordinator* coordinator = m_MultiWidget->GetSlicesRotator();
00125 if (coordinator)
00126 {
00127 coordinator->RemoveObserver( m_SlicesRotationObserverTag1 );
00128 }
00129 coordinator = m_MultiWidget->GetSlicesSwiveller();
00130 if (coordinator)
00131 {
00132 coordinator->RemoveObserver( m_SlicesRotationObserverTag2 );
00133 }
00134 }
00135
00136
00137 m_MultiWidget = multiWidget;
00138
00139 if (m_MultiWidget)
00140 {
00141 mitk::SlicesCoordinator* coordinator = m_MultiWidget->GetSlicesRotator();
00142 if (coordinator)
00143 {
00144 itk::ReceptorMemberCommand<QmitkSegmentationView>::Pointer command2 = itk::ReceptorMemberCommand<QmitkSegmentationView>::New();
00145 command2->SetCallbackFunction( this, &QmitkSegmentationView::SliceRotation );
00146 m_SlicesRotationObserverTag1 = coordinator->AddObserver( mitk::SliceRotationEvent(), command2 );
00147 }
00148
00149 coordinator = m_MultiWidget->GetSlicesSwiveller();
00150 if (coordinator)
00151 {
00152 itk::ReceptorMemberCommand<QmitkSegmentationView>::Pointer command2 = itk::ReceptorMemberCommand<QmitkSegmentationView>::New();
00153 command2->SetCallbackFunction( this, &QmitkSegmentationView::SliceRotation );
00154 m_SlicesRotationObserverTag2 = coordinator->AddObserver( mitk::SliceRotationEvent(), command2 );
00155 }
00156 }
00157
00158 if (m_Parent)
00159 {
00160 m_Parent->setEnabled(m_MultiWidget);
00161 }
00162
00163
00164 if (m_Controls && m_MultiWidget)
00165 {
00166 mitk::ToolManager* toolManager = m_Controls->m_ManualToolSelectionBox->GetToolManager();
00167 m_Controls->m_SlicesInterpolator->SetDataStorage( *(this->GetDefaultDataStorage()));
00168 m_Controls->m_SlicesInterpolator->Initialize( toolManager, m_MultiWidget );
00169 }
00170 }
00171
00172 void QmitkSegmentationView::OnPreferencesChanged(const berry::IBerryPreferences*)
00173 {
00174 ForceDisplayPreferencesUponAllImages();
00175 }
00176
00177 void QmitkSegmentationView::RenderingManagerReinitialized(const itk::EventObject&)
00178 {
00179 CheckImageAlignment();
00180 }
00181
00182 void QmitkSegmentationView::SliceRotation(const itk::EventObject&)
00183 {
00184 CheckImageAlignment();
00185 }
00186
00187
00188
00189
00190 void QmitkSegmentationView::CreateNewSegmentation()
00191 {
00192 mitk::DataNode::Pointer node = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetReferenceData(0);
00193 if (node.IsNotNull())
00194 {
00195 mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() );
00196 if (image.IsNotNull())
00197 {
00198 if (image->GetDimension()>2)
00199 {
00200
00201 QmitkNewSegmentationDialog* dialog = new QmitkNewSegmentationDialog( m_Parent );
00202
00203 QString storedList = QString::fromStdString( this->GetPreferences()->GetByteArray("Organ-Color-List","") );
00204 QStringList organColors;
00205 if (storedList.isEmpty())
00206 {
00207 organColors = GetDefaultOrganColorString();
00208 }
00209 else
00210 {
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 QString storedString = QString::fromStdString( this->GetPreferences()->GetByteArray("Organ-Color-List","") );
00229 MITK_DEBUG << "storedString: " << storedString.toStdString();
00230
00231 QRegExp onePart("(?:[^;]|\\\\;)*");
00232 MITK_DEBUG << "matching " << onePart.pattern().toStdString();
00233 int count = 0;
00234 int pos = 0;
00235 while( (pos = onePart.indexIn( storedString, pos )) != -1 )
00236 {
00237 ++count;
00238 int length = onePart.matchedLength();
00239 if (length == 0) break;
00240 QString matchedString = storedString.mid(pos, length);
00241 MITK_DEBUG << " Captured length " << length << ": " << matchedString.toStdString();
00242 pos += length + 1;
00243
00244
00245 matchedString.replace("\\;", ";");
00246
00247
00248 organColors << matchedString;
00249 }
00250 MITK_DEBUG << "Captured " << count << " organ name/colors";
00251 }
00252
00253 dialog->SetSuggestionList( organColors );
00254
00255 int dialogReturnValue = dialog->exec();
00256
00257 if ( dialogReturnValue == QDialog::Rejected ) return;
00258
00259
00260
00261 mitk::ToolManager* toolManager = m_Controls->m_ManualToolSelectionBox->GetToolManager();
00262 mitk::Tool* firstTool = toolManager->GetToolById(0);
00263 if (firstTool)
00264 {
00265 try
00266 {
00267 mitk::DataNode::Pointer emptySegmentation =
00268 firstTool->CreateEmptySegmentationNode( image, dialog->GetSegmentationName().toStdString(), dialog->GetColor() );
00269
00270 if (!emptySegmentation) return;
00271
00272 UpdateOrganList( organColors, dialog->GetSegmentationName(), dialog->GetColor() );
00273
00274
00275
00276
00277 std::string stringForStorage = organColors.replaceInStrings(";","\\;").join(";").toStdString();
00278 MITK_DEBUG << "Will store: " << stringForStorage;
00279 this->GetPreferences()->PutByteArray("Organ-Color-List", stringForStorage );
00280 this->GetPreferences()->Flush();
00281
00282 this->GetDefaultDataStorage()->Add( emptySegmentation, node );
00283
00284 this->FireNodeSelected( emptySegmentation );
00285 this->OnSelectionChanged( emptySegmentation );
00286 }
00287 catch (std::bad_alloc)
00288 {
00289 QMessageBox::warning(NULL,"Create new segmentation","Could not allocate memory for new segmentation");
00290 }
00291 }
00292 }
00293 else
00294 {
00295 QMessageBox::information(NULL,"Segmentation","Segmentation is currently not supported for 2D images");
00296 }
00297 }
00298 }
00299 else
00300 {
00301 MITK_ERROR << "'Create new segmentation' button should never be clickable unless a patient image is selected...";
00302 }
00303 }
00304
00305 void QmitkSegmentationView::CreateSegmentationFromSurface()
00306 {
00307 mitk::DataNode::Pointer surfaceNode =
00308 m_Controls->MaskSurfaces->GetSelectedNode();
00309 mitk::Surface::Pointer surface(0);
00310 if(surfaceNode.IsNotNull())
00311 surface = dynamic_cast<mitk::Surface*> ( surfaceNode->GetData() );
00312 if(surface.IsNull())
00313 {
00314 this->HandleException( "No surface selected.", m_Parent, true);
00315 return;
00316 }
00317
00318 mitk::DataNode::Pointer imageNode
00319 = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetReferenceData(0);
00320 mitk::Image::Pointer image(0);
00321 if (imageNode.IsNotNull())
00322 image = dynamic_cast<mitk::Image*>( imageNode->GetData() );
00323 if(image.IsNull())
00324 {
00325 this->HandleException( "No image selected.", m_Parent, true);
00326 return;
00327 }
00328
00329 mitk::SurfaceToImageFilter::Pointer s2iFilter
00330 = mitk::SurfaceToImageFilter::New();
00331
00332 s2iFilter->MakeOutputBinaryOn();
00333 s2iFilter->SetInput(surface);
00334 s2iFilter->SetImage(image);
00335 s2iFilter->Update();
00336
00337 mitk::DataNode::Pointer resultNode = mitk::DataNode::New();
00338 std::string nameOfResultImage = imageNode->GetName();
00339 nameOfResultImage.append(surfaceNode->GetName());
00340 resultNode->SetProperty("name", mitk::StringProperty::New(nameOfResultImage) );
00341 resultNode->SetProperty("binary", mitk::BoolProperty::New(true) );
00342 resultNode->SetData( s2iFilter->GetOutput() );
00343
00344 this->GetDataStorage()->Add(resultNode, imageNode);
00345
00346 }
00347
00348 void QmitkSegmentationView::ManualToolSelected(int id)
00349 {
00350
00351 if (m_MultiWidget)
00352 {
00353 if (id >= 0)
00354 {
00355 m_MultiWidget->DisableNavigationControllerEventListening();
00356 }
00357 else
00358 {
00359 m_MultiWidget->EnableNavigationControllerEventListening();
00360 }
00361 }
00362 }
00363
00364 void QmitkSegmentationView::ToolboxStackPageChanged(int id)
00365 {
00366
00367 m_Controls->m_SlicesInterpolator->EnableInterpolation( id == 0 );
00368
00369 if( id == 0 )
00370 {
00371 mitk::DataNode::Pointer workingData = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetWorkingData(0);
00372 if( workingData.IsNotNull() )
00373 {
00374 m_Controls->lblSegmentation->setText( workingData->GetName().c_str() );
00375 m_Controls->lblSegImage->show();
00376 m_Controls->lblSegmentation->show();
00377 }
00378 }
00379 else
00380 {
00381 m_Controls->lblSegImage->hide();
00382 m_Controls->lblSegmentation->hide();
00383 }
00384
00385
00386 if (id==2)
00387 {
00388 mitk::DataNode::Pointer node = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetReferenceData(0);
00389 if (node.IsNotNull())
00390 {
00391 mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() );
00392 if (image.IsNotNull())
00393 {
00394 if (image->GetDimension()>3)
00395 {
00396 m_Controls->widgetStack->setCurrentIndex(0);
00397 QMessageBox::information(NULL,"Segmentation","Lesion segmentation is currently not supported for 4D images");
00398 }
00399 }
00400 }
00401 }
00402 }
00403
00404
00405
00406 void QmitkSegmentationView::OnComboBoxSelectionChanged( const mitk::DataNode* node )
00407 {
00408 mitk::DataNode* selectedNode = const_cast<mitk::DataNode*>(node);
00409 if( selectedNode != NULL )
00410 {
00411 m_Controls->refImageSelector->show();
00412 m_Controls->lblReferenceImageSelectionWarning->hide();
00413 this->OnSelectionChanged( const_cast<mitk::DataNode*>(node) );
00414 }
00415 else
00416 {
00417 m_Controls->refImageSelector->hide();
00418 m_Controls->lblReferenceImageSelectionWarning->show();
00419 }
00420 }
00421 void QmitkSegmentationView::OnSelectionChanged(mitk::DataNode* node)
00422 {
00423 std::vector<mitk::DataNode*> nodes;
00424 nodes.push_back( node );
00425 this->OnSelectionChanged( nodes );
00426 }
00427
00428
00429
00430 void QmitkSegmentationView::OnSurfaceSelectionChanged()
00431 {
00432
00433 if ( (m_Controls->refImageSelector->GetSelectedNode().IsNull()) ||
00434 (m_Controls->MaskSurfaces->GetSelectedNode().IsNull()))
00435 m_Controls->CreateSegmentationFromSurface->setEnabled(false);
00436 else
00437 m_Controls->CreateSegmentationFromSurface->setEnabled(true);
00438 }
00439
00440 void QmitkSegmentationView::OnSelectionChanged(std::vector<mitk::DataNode*> nodes)
00441 {
00442
00443 if ( (m_Controls->refImageSelector->GetSelectedNode().IsNull()) ||
00444 (m_Controls->MaskSurfaces->GetSelectedNode().IsNull()))
00445 m_Controls->CreateSegmentationFromSurface->setEnabled(false);
00446 else
00447 m_Controls->CreateSegmentationFromSurface->setEnabled(true);
00448
00449 if (!m_Parent || !m_Parent->isVisible()) return;
00450
00451
00452
00453
00454
00455
00456 mitk::DataNode::Pointer referenceData = FindFirstRegularImage( nodes );
00457 mitk::DataNode::Pointer workingData = FindFirstSegmentation( nodes );
00458
00459 bool invalidSelection( !nodes.empty() &&
00460 (
00461 nodes.size() > 2 ||
00462 (nodes.size() == 2 && (workingData.IsNull() || referenceData.IsNull()) ) ||
00463 ( workingData.GetPointer() == referenceData.GetPointer() )
00464
00465 )
00466 );
00467
00468 if (invalidSelection)
00469 {
00470
00471 MITK_ERROR << "WARNING: No image, too many (>2) or two equal images were selected.";
00472 workingData = NULL;
00473
00474 if( m_Controls->refImageSelector->GetSelectedNode().IsNull() )
00475 referenceData = NULL;
00476 }
00477
00478 if ( workingData.IsNotNull() && referenceData.IsNull() )
00479 {
00480
00481
00482 mitk::TNodePredicateDataType<mitk::Image>::Pointer isImage = mitk::TNodePredicateDataType<mitk::Image>::New();
00483 mitk::NodePredicateProperty::Pointer isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true));
00484 mitk::NodePredicateNot::Pointer isNotBinary = mitk::NodePredicateNot::New( isBinary );
00485 mitk::NodePredicateAnd::Pointer isNormalImage = mitk::NodePredicateAnd::New( isImage, isNotBinary );
00486
00487 mitk::DataStorage::SetOfObjects::ConstPointer possibleParents = this->GetDefaultDataStorage()->GetSources( workingData, isNormalImage );
00488
00489 if (possibleParents->size() > 0)
00490 {
00491 if (possibleParents->size() > 1)
00492 {
00493
00494 MITK_ERROR << "Selected binary image has multiple parents. Using arbitrary first one for segmentation.";
00495 }
00496
00497 referenceData = (*possibleParents)[0];
00498 }
00499 }
00500
00501
00502 disconnect( m_Controls->refImageSelector, SIGNAL( OnSelectionChanged( const mitk::DataNode* ) ),
00503 this, SLOT( OnComboBoxSelectionChanged( const mitk::DataNode* ) ) );
00504
00505 m_Controls->refImageSelector->setCurrentIndex( m_Controls->refImageSelector->Find(referenceData) );
00506
00507 connect( m_Controls->refImageSelector, SIGNAL( OnSelectionChanged( const mitk::DataNode* ) ),
00508 this, SLOT( OnComboBoxSelectionChanged( const mitk::DataNode* ) ) );
00509
00510
00511
00512 if ( (m_Controls->refImageSelector->GetSelectedNode().IsNull()) ||
00513 (m_Controls->MaskSurfaces->GetSelectedNode().IsNull()) ||
00514 (!referenceData))
00515 m_Controls->CreateSegmentationFromSurface->setEnabled(false);
00516 else
00517 m_Controls->CreateSegmentationFromSurface->setEnabled(true);
00518
00519
00520 SetToolManagerSelection(referenceData, workingData);
00521 ForceDisplayPreferencesUponAllImages();
00522 }
00523
00524
00525 mitk::DataNode::Pointer QmitkSegmentationView::FindFirstRegularImage( std::vector<mitk::DataNode*> nodes )
00526 {
00527 if (nodes.empty()) return NULL;
00528
00529 for(unsigned int i = 0; i < nodes.size(); ++i)
00530 {
00531
00532 bool isImage(false);
00533 if (nodes.at(i)->GetData())
00534 {
00535 isImage = dynamic_cast<mitk::Image*>(nodes.at(i)->GetData()) != NULL;
00536 }
00537
00538
00539 bool isSegmentation(false);
00540 nodes.at(i)->GetBoolProperty("binary", isSegmentation);
00541
00542
00543 if (isImage && !isSegmentation) return nodes.at(i);
00544 }
00545
00546 return NULL;
00547 }
00548
00549
00550 mitk::DataNode::Pointer QmitkSegmentationView::FindFirstSegmentation( std::vector<mitk::DataNode*> nodes )
00551 {
00552 if (nodes.empty()) return NULL;
00553
00554
00555 for(unsigned int i = 0; i < nodes.size(); ++i)
00556 {
00557 bool isImage(false);
00558 if (nodes.at(i)->GetData())
00559 {
00560 isImage = dynamic_cast<mitk::Image*>(nodes.at(i)->GetData()) != NULL;
00561 }
00562
00563 bool isSegmentation(false);
00564 nodes.at(i)->GetBoolProperty("binary", isSegmentation);
00565
00566
00567 if (isImage && isSegmentation)
00568 {
00569 return nodes.at(i);
00570 }
00571 }
00572
00573 return NULL;
00574 }
00575
00576 void QmitkSegmentationView::SetToolManagerSelection(const mitk::DataNode* referenceData, const mitk::DataNode* workingData)
00577 {
00578
00579
00580
00581 mitk::ToolManager* toolManager = m_Controls->m_ManualToolSelectionBox->GetToolManager();
00582 toolManager->SetReferenceData(const_cast<mitk::DataNode*>(referenceData));
00583 toolManager->SetWorkingData( const_cast<mitk::DataNode*>(workingData));
00584
00585
00586
00587 m_Controls->btnNewSegmentation->setEnabled(referenceData != NULL);
00588 if (referenceData)
00589 {
00590 m_Controls->lblReferenceImageSelectionWarning->hide();
00591 }
00592 else
00593 {
00594 m_Controls->lblReferenceImageSelectionWarning->show();
00595 m_Controls->lblWorkingImageSelectionWarning->hide();
00596 m_Controls->lblSegImage->hide();
00597 m_Controls->lblSegmentation->hide();
00598 }
00599
00600
00601 CheckImageAlignment();
00602
00603
00604 if (referenceData)
00605 {
00606 if (!workingData)
00607 {
00608 m_Controls->lblWorkingImageSelectionWarning->show();
00609
00610 if( m_Controls->widgetStack->currentIndex() == 0 )
00611 {
00612 m_Controls->lblSegImage->hide();
00613 m_Controls->lblSegmentation->hide();
00614 }
00615 }
00616 else
00617 {
00618 m_Controls->lblWorkingImageSelectionWarning->hide();
00619
00620 if( m_Controls->widgetStack->currentIndex() == 0 )
00621 {
00622 m_Controls->lblSegmentation->setText( workingData->GetName().c_str() );
00623 m_Controls->lblSegmentation->show();
00624 m_Controls->lblSegImage->show();
00625 }
00626 }
00627 }
00628 }
00629
00630 void QmitkSegmentationView::CheckImageAlignment()
00631 {
00632 bool wrongAlignment(false);
00633
00634 mitk::DataNode::Pointer node = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetReferenceData(0);
00635 if (node.IsNotNull())
00636 {
00637 mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() );
00638
00639 if (image.IsNotNull() && m_MultiWidget)
00640 {
00641
00642 wrongAlignment = !( IsRenderWindowAligned(m_MultiWidget->GetRenderWindow1(), image )
00643 && IsRenderWindowAligned(m_MultiWidget->GetRenderWindow2(), image )
00644 && IsRenderWindowAligned(m_MultiWidget->GetRenderWindow3(), image )
00645 );
00646 }
00647 }
00648
00649 if (wrongAlignment)
00650 {
00651 m_Controls->lblAlignmentWarning->show();
00652 }
00653 else
00654 {
00655 m_Controls->lblAlignmentWarning->hide();
00656 }
00657 }
00658
00659 bool QmitkSegmentationView::IsRenderWindowAligned(QmitkRenderWindow* renderWindow, mitk::Image* image)
00660 {
00661 if (!renderWindow) return false;
00662
00663
00664 mitk::PlaneGeometry::ConstPointer displayPlane = dynamic_cast<const mitk::PlaneGeometry*>( renderWindow->GetRenderer()->GetCurrentWorldGeometry2D() );
00665 if (displayPlane.IsNull()) return false;
00666
00667 int affectedDimension(-1);
00668 int affectedSlice(-1);
00669 return mitk::SegTool2D::DetermineAffectedImageSlice( image, displayPlane, affectedDimension, affectedSlice );
00670 }
00671
00672 void QmitkSegmentationView::ForceDisplayPreferencesUponAllImages()
00673 {
00674 if (!m_Parent || !m_Parent->isVisible()) return;
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692 if (!m_Controls) return;
00693 mitk::DataNode::Pointer referenceData = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetReferenceData(0);
00694 mitk::DataNode::Pointer workingData = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetWorkingData(0);
00695
00696
00697 if (referenceData.IsNotNull())
00698 {
00699
00700 mitk::TNodePredicateDataType<mitk::Image>::Pointer isImage = mitk::TNodePredicateDataType<mitk::Image>::New();
00701
00702 mitk::DataStorage::SetOfObjects::ConstPointer allImages = this->GetDefaultDataStorage()->GetSubset( isImage );
00703 for ( mitk::DataStorage::SetOfObjects::const_iterator iter = allImages->begin();
00704 iter != allImages->end();
00705 ++iter)
00706
00707 {
00708 mitk::DataNode* node = *iter;
00709
00710 ApplyDisplayOptions(node);
00711
00712
00713 node->SetVisibility(node == referenceData);
00714 }
00715 }
00716
00717
00718 if (workingData.IsNotNull())
00719 {
00720 workingData->SetVisibility(true);
00721 }
00722
00723 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
00724 }
00725
00726 void QmitkSegmentationView::ApplyDisplayOptions(mitk::DataNode* node)
00727 {
00728 if (!node) return;
00729
00730 bool isBinary(false);
00731 node->GetPropertyValue("binary", isBinary);
00732
00733 if (isBinary)
00734 {
00735 node->SetProperty( "outline binary", mitk::BoolProperty::New( this->GetPreferences()->GetBool("draw outline", true)) );
00736 node->SetProperty( "outline width", mitk::FloatProperty::New( 2.0 ) );
00737 node->SetProperty( "opacity", mitk::FloatProperty::New( this->GetPreferences()->GetBool("draw outline", true) ? 1.0 : 0.3 ) );
00738 node->SetProperty( "volumerendering", mitk::BoolProperty::New( this->GetPreferences()->GetBool("volume rendering", false) ) );
00739 }
00740 }
00741
00742 void QmitkSegmentationView::CreateQtPartControl(QWidget* parent)
00743 {
00744
00745 m_Parent = parent;
00746
00747 m_Controls = new Ui::QmitkSegmentationControls;
00748 m_Controls->setupUi(parent);
00749 m_Controls->lblWorkingImageSelectionWarning->hide();
00750 m_Controls->lblAlignmentWarning->hide();
00751 m_Controls->lblSegImage->hide();
00752 m_Controls->lblSegmentation->hide();
00753
00754 m_Controls->refImageSelector->SetDataStorage(this->GetDefaultDataStorage());
00755 m_Controls->refImageSelector->SetPredicate(mitk::NodePredicateDataType::New("Image"));
00756
00757 if( m_Controls->refImageSelector->GetSelectedNode().IsNotNull() )
00758 m_Controls->lblReferenceImageSelectionWarning->hide();
00759 else
00760 m_Controls->refImageSelector->hide();
00761
00762
00763 mitk::ToolManager* toolManager = m_Controls->m_ManualToolSelectionBox->GetToolManager();
00764 toolManager->SetDataStorage( *(this->GetDefaultDataStorage()) );
00765 assert ( toolManager );
00766
00767
00768 m_Controls->m_ManualToolSelectionBox->SetGenerateAccelerators(true);
00769 m_Controls->m_ManualToolSelectionBox->SetToolGUIArea( m_Controls->m_ManualToolGUIContainer );
00770 m_Controls->m_ManualToolSelectionBox->SetDisplayedToolGroups("Add Subtract Paint Wipe 'Region Growing' Correction Fill Erase");
00771 m_Controls->m_ManualToolSelectionBox->SetEnabledMode( QmitkToolSelectionBox::EnabledWithReferenceAndWorkingData );
00772
00773
00774 if ( !m_Controls->m_OrganToolSelectionBox->children().count() )
00775 {
00776 m_Controls->widgetStack->setItemEnabled( 1, false );
00777 }
00778 m_Controls->m_OrganToolSelectionBox->SetToolManager( *toolManager );
00779 m_Controls->m_OrganToolSelectionBox->SetToolGUIArea( m_Controls->m_OrganToolGUIContainer );
00780 m_Controls->m_OrganToolSelectionBox->SetDisplayedToolGroups("'Hippocampus left' 'Hippocampus right' 'Lung left' 'Lung right' 'Liver' 'Heart LV' 'Endocard LV' 'Epicard LV' 'Prostate'");
00781 m_Controls->m_OrganToolSelectionBox->SetEnabledMode( QmitkToolSelectionBox::EnabledWithReferenceData );
00782
00783
00784 if ( !m_Controls->m_LesionToolSelectionBox->children().count() )
00785 {
00786 m_Controls->widgetStack->setItemEnabled( 2, false );
00787 }
00788 m_Controls->m_LesionToolSelectionBox->SetToolManager( *toolManager );
00789 m_Controls->m_LesionToolSelectionBox->SetToolGUIArea( m_Controls->m_LesionToolGUIContainer );
00790 m_Controls->m_LesionToolSelectionBox->SetDisplayedToolGroups("'Lymph Node'");
00791 m_Controls->m_LesionToolSelectionBox->SetEnabledMode( QmitkToolSelectionBox::EnabledWithReferenceData );
00792
00793 toolManager->NewNodesGenerated +=
00794 mitk::MessageDelegate<QmitkSegmentationView>( this, &QmitkSegmentationView::NewNodesGenerated );
00795 toolManager->NewNodeObjectsGenerated +=
00796 mitk::MessageDelegate1<QmitkSegmentationView, mitk::ToolManager::DataVectorType*>( this, &QmitkSegmentationView::NewNodeObjectsGenerated );
00797
00798
00799 connect( m_Controls->refImageSelector, SIGNAL( OnSelectionChanged( const mitk::DataNode* ) ),
00800 this, SLOT( OnComboBoxSelectionChanged( const mitk::DataNode* ) ) );
00801 connect( m_Controls->btnNewSegmentation, SIGNAL(clicked()), this, SLOT(CreateNewSegmentation()) );
00802 connect( m_Controls->CreateSegmentationFromSurface, SIGNAL(clicked()), this, SLOT(CreateSegmentationFromSurface()) );
00803 connect( m_Controls->m_ManualToolSelectionBox, SIGNAL(ToolSelected(int)), this, SLOT(ManualToolSelected(int)) );
00804 connect( m_Controls->widgetStack, SIGNAL(currentChanged(int)), this, SLOT(ToolboxStackPageChanged(int)) );
00805
00806
00807 connect(m_Controls->MaskSurfaces, SIGNAL( OnSelectionChanged( const mitk::DataNode* ) ),
00808 this, SLOT( OnSurfaceSelectionChanged( ) ) );
00809
00810 m_Controls->MaskSurfaces->SetDataStorage(this->GetDefaultDataStorage());
00811 m_Controls->MaskSurfaces->SetPredicate(mitk::NodePredicateDataType::New("Surface"));
00812
00814 m_PostProcessing = new QmitkSegmentationPostProcessing(this->GetDefaultDataStorage(), this, m_Parent);
00815 }
00816
00817
00818
00819