Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkCreateSurfaceTool.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkCreateSurfaceTool.h"
14 
15 #include "mitkCreateSurfaceTool.xpm"
16 
17 #include "mitkProgressBar.h"
19 #include "mitkStatusBar.h"
20 #include "mitkToolManager.h"
21 
22 #include "itkCommand.h"
23 
24 namespace mitk
25 {
27 }
28 
30 {
31 }
32 
34 {
35 }
36 
37 const char **mitk::CreateSurfaceTool::GetXPM() const
38 {
39  return mitkCreateSurfaceTool_xpm;
40 }
41 
43 {
44  return "Surface";
45 }
46 
48 {
49  return "No surfaces created for these segmentations:";
50 }
51 
53 {
54  if (node)
55  {
56  Image::Pointer image = dynamic_cast<Image *>(node->GetData());
57  if (image.IsNull())
58  return false;
59 
60  try
61  {
62  mitk::ShowSegmentationAsSurface::Pointer surfaceFilter = mitk::ShowSegmentationAsSurface::New();
63 
64  // attach observer to get notified about result
65  itk::SimpleMemberCommand<CreateSurfaceTool>::Pointer goodCommand =
66  itk::SimpleMemberCommand<CreateSurfaceTool>::New();
67  goodCommand->SetCallbackFunction(this, &CreateSurfaceTool::OnSurfaceCalculationDone);
68  surfaceFilter->AddObserver(mitk::ResultAvailable(), goodCommand);
69  itk::SimpleMemberCommand<CreateSurfaceTool>::Pointer badCommand =
70  itk::SimpleMemberCommand<CreateSurfaceTool>::New();
71  badCommand->SetCallbackFunction(this, &CreateSurfaceTool::OnSurfaceCalculationDone);
72  surfaceFilter->AddObserver(mitk::ProcessingError(), badCommand);
73 
74  DataNode::Pointer nodepointer = node;
75  surfaceFilter->SetPointerParameter("Input", image);
76  surfaceFilter->SetPointerParameter("Group node", nodepointer);
77  surfaceFilter->SetParameter("Show result", true);
78  surfaceFilter->SetParameter("Sync visibility", false);
79  surfaceFilter->SetDataStorage(*m_ToolManager->GetDataStorage());
80 
82  StatusBar::GetInstance()->DisplayText("Surface creation started in background...");
83  surfaceFilter->StartAlgorithm();
84  }
85  catch (...)
86  {
87  return false;
88  }
89  }
90 
91  return true;
92 }
93 
95 {
97  m_ToolManager->NewNodesGenerated();
98 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
static Pointer New(void)
Creates surface models from segmentations.
bool ProcessOneWorkingData(DataNode *node) override
Subclasses should override this method.
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
std::string GetErrorMessage() override
Describes the error (if one occurred during processing).
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
MITK_TOOL_MACRO(MITKSEGMENTATION_EXPORT, LiveWireTool2D, "LiveWire tool")
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void DisplayText(const char *t)
Send a string to the applications StatusBar.
Image class for storing images.
Definition: mitkImage.h:72
mitk::Image::Pointer image
static StatusBar * GetInstance()
static method to get the GUI dependent StatusBar-instance so the methods DisplayText, etc. can be called No reference counting, cause of decentral static use!
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
const char * GetName() const override
Returns the name of this tool. Make it short!
const char ** GetXPM() const override
Returns an icon in the XPM format.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57