Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MITKBOUNDINGOBJECTCUTTER_TXX
00020 #define MITKBOUNDINGOBJECTCUTTER_TXX
00021
00022
00023 #include "mitkStatusBar.h"
00024 #include "mitkImageToItk.h"
00025 #include "itkImageRegionIteratorWithIndex.h"
00026
00027 namespace mitk
00028 {
00029
00030 template < typename TPixel, unsigned int VImageDimension, typename TOutputPixel >
00031 void CutImageWithOutputTypeSelect
00032 ( itk::Image<TPixel, VImageDimension>* inputItkImage, mitk::BoundingObjectCutter* cutter, int , TOutputPixel* )
00033 {
00034 typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
00035 typedef itk::Image<TOutputPixel, VImageDimension> ItkOutputImageType;
00036 typedef typename itk::ImageBase<VImageDimension>::RegionType ItkRegionType;
00037 typedef itk::ImageRegionIteratorWithIndex< ItkInputImageType > ItkInputImageIteratorType;
00038 typedef itk::ImageRegionIteratorWithIndex< ItkOutputImageType > ItkOutputImageIteratorType;
00039
00040 if(cutter->m_BoundingObject.IsNull())
00041 return;
00042
00043 if (inputItkImage == NULL)
00044 {
00045 mitk::StatusBar::GetInstance()->DisplayErrorText ("An internal error occurred. Can't convert Image. Please report to bugs@mitk.org");
00046 std::cout << " image is NULL...returning" << std::endl;
00047 return;
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 typename ItkRegionType::IndexType::IndexValueType tmpIndex[3];
00059 itk2vtk(cutter->m_InputRequestedRegion.GetIndex(), tmpIndex);
00060 typename ItkRegionType::IndexType index;
00061 index.SetIndex(tmpIndex);
00062
00063
00064 typename ItkRegionType::SizeType::SizeValueType tmpSize[3];
00065 itk2vtk(cutter->m_InputRequestedRegion.GetSize(), tmpSize);
00066 typename ItkRegionType::SizeType size;
00067 size.SetSize(tmpSize);
00068
00069
00070 ItkRegionType inputRegionOfInterest(index, size);
00071
00072
00073 typename mitk::ImageToItk<ItkOutputImageType>::Pointer outputimagetoitk = mitk::ImageToItk<ItkOutputImageType>::New();
00074 outputimagetoitk->SetInput(cutter->m_OutputTimeSelector->GetOutput());
00075 outputimagetoitk->Update();
00076 typename ItkOutputImageType::Pointer outputItkImage = outputimagetoitk->GetOutput();
00077
00078
00079
00080
00081 ItkInputImageIteratorType inputIt( inputItkImage, inputRegionOfInterest );
00082 ItkOutputImageIteratorType outputIt( outputItkImage, outputItkImage->GetLargestPossibleRegion() );
00083
00084
00085
00086 cutter->m_OutsidePixelCount = 0;
00087 cutter->m_InsidePixelCount = 0;
00088 mitk::Point3D p;
00089 mitk::Geometry3D* inputGeometry = cutter->GetInput()->GetGeometry();
00090
00091 TOutputPixel outsideValue;
00092 if(cutter->m_AutoOutsideValue)
00093 {
00094 outsideValue = itk::NumericTraits<TOutputPixel>::min();
00095 }
00096 else
00097 {
00098 outsideValue = (TOutputPixel) cutter->m_OutsideValue;
00099 }
00100
00101
00102 if (cutter->GetUseInsideValue())
00103 {
00104 TOutputPixel insideValue = (TOutputPixel) cutter->m_InsideValue;
00105
00106 for ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
00107 {
00108 vtk2itk(inputIt.GetIndex(), p);
00109 inputGeometry->IndexToWorld(p, p);
00110 if(cutter->m_BoundingObject->IsInside(p))
00111 {
00112 outputIt.Set(insideValue);
00113 ++cutter->m_InsidePixelCount;
00114 }
00115 else
00116 {
00117 outputIt.Set(outsideValue);
00118 ++cutter->m_OutsidePixelCount;
00119 }
00120 }
00121 }
00122 else
00123 {
00124
00125 for ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
00126 {
00127 vtk2itk(inputIt.GetIndex(), p);
00128 inputGeometry->IndexToWorld(p, p);
00129 if(cutter->m_BoundingObject->IsInside(p))
00130 {
00131 outputIt.Set( (TOutputPixel) inputIt.Value() );
00132 ++cutter->m_InsidePixelCount;
00133 }
00134 else
00135 {
00136 outputIt.Set( outsideValue );
00137 ++cutter->m_OutsidePixelCount;
00138 }
00139 }
00140 }
00141 }
00142
00143 template < typename TPixel, unsigned int VImageDimension >
00144 void CutImage( itk::Image< TPixel, VImageDimension >* inputItkImage, mitk::BoundingObjectCutter* cutter, int boTimeStep )
00145 {
00146 TPixel* dummy = NULL;
00147 CutImageWithOutputTypeSelect<TPixel, VImageDimension, TPixel>(inputItkImage, cutter, boTimeStep, dummy);
00148 }
00149
00150 }
00151
00152 #include "mitkImageCast.h"
00153
00154 #endif // of MITKBOUNDINGOBJECTCUTTER_TXX