00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision: 1.12 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkAutoCropTool.h" 00019 00020 #include "mitkAutoCropTool.xpm" 00021 00022 #include "mitkAutoCropImageFilter.h" 00023 00024 namespace mitk { 00025 MITK_TOOL_MACRO(MitkExt_EXPORT, AutoCropImageFilter, "Crop tool"); 00026 } 00027 00028 mitk::AutoCropTool::AutoCropTool() 00029 { 00030 } 00031 00032 mitk::AutoCropTool::~AutoCropTool() 00033 { 00034 } 00035 00036 const char** mitk::AutoCropTool::GetXPM() const 00037 { 00038 return mitkAutoCropTool_xpm; 00039 } 00040 00041 const char* mitk::AutoCropTool::GetName() const 00042 { 00043 return "Crop"; 00044 } 00045 00046 std::string mitk::AutoCropTool::GetErrorMessage() 00047 { 00048 return "Cropping of these nodes failed:"; 00049 } 00050 00051 bool mitk::AutoCropTool::ProcessOneWorkingData( DataNode* node ) 00052 { 00053 if (node) 00054 { 00055 Image::Pointer image = dynamic_cast<Image*>( node->GetData() ); 00056 if (image.IsNull()) return false; 00057 00058 // if (image->GetDimension() == 4) 00059 // { 00060 // Tool::ErrorMessage.Send("Cropping 3D+t segmentations is not implemented. Sorry. Bug #1281"); 00061 // return false; 00062 // } 00063 00064 AutoCropImageFilter::Pointer cropFilter = AutoCropImageFilter::New(); 00065 cropFilter->SetInput( image ); 00066 cropFilter->SetBackgroundValue( 0 ); 00067 try 00068 { 00069 cropFilter->Update(); 00070 00071 image = cropFilter->GetOutput(); 00072 if (image.IsNotNull()) 00073 { 00074 node->SetData( image ); 00075 } 00076 else 00077 { 00078 return false; 00079 } 00080 } 00081 catch(...) 00082 { 00083 return false; 00084 } 00085 } 00086 00087 return true; 00088 } 00089