Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkAutoCropTool.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkAutoCropTool.h"
18 
19 #include "mitkAutoCropTool.xpm"
20 
22 
23 namespace mitk
24 {
26 }
27 
29 {
30 }
31 
33 {
34 }
35 
36 const char **mitk::AutoCropTool::GetXPM() const
37 {
38  return mitkAutoCropTool_xpm;
39 }
40 
41 const char *mitk::AutoCropTool::GetName() const
42 {
43  return "Crop";
44 }
45 
47 {
48  return "Cropping of these nodes failed:";
49 }
50 
52 {
53  if (node)
54  {
55  Image::Pointer image = dynamic_cast<Image *>(node->GetData());
56  if (image.IsNull())
57  return false;
58 
59  // if (image->GetDimension() == 4)
60  // {
61  // Tool::ErrorMessage.Send("Cropping 3D+t segmentations is not implemented. Sorry. Bug #1281");
62  // return false;
63  // }
64 
66  cropFilter->SetInput(image);
67  cropFilter->SetBackgroundValue(0);
68  try
69  {
70  cropFilter->Update();
71 
72  image = cropFilter->GetOutput();
73  if (image.IsNotNull())
74  {
75  node->SetData(image);
76  }
77  else
78  {
79  return false;
80  }
81  }
82  catch (...)
83  {
84  return false;
85  }
86  }
87 
88  return true;
89 }
virtual bool ProcessOneWorkingData(DataNode *node) override
Subclasses should override this method.
Shrink the image borders to a minimum considering a background color.
virtual void SetData(mitk::BaseData *baseData)
Set the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
#define MITK_TOOL_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual const char ** GetXPM() const override
Returns an icon in the XPM format.
virtual std::string GetErrorMessage() override
Describes the error (if one occurred during processing).
static Pointer New()
Image class for storing images.
Definition: mitkImage.h:76
virtual const char * GetName() const override
Returns the name of this tool. Make it short!
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66