00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 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 "mitkImageToLookupTableFilter.h" 00019 #include "mitkImageToItk.h" 00020 #include "itkImage.h" 00021 #include "itkVector.h" 00022 #include "itkImageRegionIterator.h" 00023 #include "itkNumericTraits.h" 00024 #include <algorithm> 00025 00026 mitk::ImageToLookupTableFilter::ImageToLookupTableFilter() 00027 { 00028 this->SetNumberOfRequiredInputs(1); 00029 } 00030 00031 00032 00033 00034 mitk::ImageToLookupTableFilter::~ImageToLookupTableFilter() 00035 { 00036 00037 } 00038 00039 00040 00041 00042 void mitk::ImageToLookupTableFilter::SetInput( const mitk::ImageToLookupTableFilter::InputImageType *input) 00043 { 00044 // Process object is not const-correct so the const_cast is required here 00045 this->itk::ProcessObject::SetNthInput( 0, const_cast< InputImageType * >( input ) ); 00046 00047 } 00048 00049 00050 00051 00052 void mitk::ImageToLookupTableFilter::SetInput( unsigned int index, const mitk::ImageToLookupTableFilter::InputImageType * input) 00053 { 00054 if ( index + 1 > this->GetNumberOfInputs() ) 00055 { 00056 this->SetNumberOfRequiredInputs( index + 1 ); 00057 } 00058 // Process object is not const-correct so the const_cast is required here 00059 this->ProcessObject::SetNthInput( index, const_cast< InputImageType *>( input ) ); 00060 } 00061 00062 00063 00064 00065 const mitk::ImageToLookupTableFilter::InputImageType * mitk::ImageToLookupTableFilter::GetInput(void) 00066 { 00067 if ( this->GetNumberOfInputs() < 1 ) 00068 { 00069 return 0; 00070 } 00071 return static_cast<const InputImageType * >( this->ProcessObject::GetInput( 0 ) ); 00072 } 00073 00074 00075 00076 00077 const mitk::ImageToLookupTableFilter::InputImageType * mitk::ImageToLookupTableFilter::GetInput(unsigned int idx) 00078 { 00079 return static_cast< const InputImageType * >( this->ProcessObject::GetInput( idx ) ); 00080 } 00081 00082 00083 00084 00085 void mitk::ImageToLookupTableFilter::GenerateData() 00086 { 00087 this->SetNumberOfOutputs( this->GetNumberOfInputs() ); 00088 for (unsigned int inputIdx = 0; inputIdx < this->GetNumberOfInputs() ; ++inputIdx) 00089 { 00090 InputImagePointer image = const_cast<mitk::Image*>(this->GetInput( inputIdx )); 00091 OutputTypePointer output = dynamic_cast<OutputType*>(this->MakeOutput( inputIdx ).GetPointer()); 00092 00093 this->ProcessObject::SetNthOutput( inputIdx, output.GetPointer() ); 00094 if (image.IsNull()) 00095 { 00096 itkWarningMacro(<< inputIdx<<"'th input image is null!"); 00097 return; 00098 } 00099 00100 // the default vtkLookupTable has range=[0,1]; and hsv ranges set 00101 // up for rainbow color table (from red to blue). 00102 00103 vtkLookupTable* vtkLut = vtkLookupTable::New(); 00104 /* 00105 if ( ( image->GetPixelType().GetNumberOfComponents() == 3 ) && ( image->GetDimension() == 3 ) ) 00106 { 00107 00108 // some typedefs for conversion to an iterable itk image 00109 const unsigned int VectorDimension = 3; 00110 typedef float VectorComponentType; 00111 typedef itk::Vector< VectorComponentType, VectorDimension > VectorType; 00112 typedef itk::Image< VectorType, VectorDimension > VectorFieldType; 00113 typedef itk::ImageRegionIterator< VectorFieldType > VectorFieldIteratorType; 00114 typedef mitk::ImageToItk<VectorFieldType> ImageConverterType; 00115 00116 // some local variables 00117 float minValue = itk::NumericTraits<float>::max(); 00118 float maxValue = itk::NumericTraits<float>::NonpositiveMin(); 00119 float norm = 0.0f; 00120 00121 //determine the range of the vector magnitudes in the image 00122 ImageConverterType::Pointer imageConverter = ImageConverterType::New(); 00123 imageConverter->SetInput(image); 00124 VectorFieldType::Pointer itkImage = imageConverter->GetOutput(); 00125 VectorFieldIteratorType it( itkImage, itkImage->GetRequestedRegion() ); 00126 it.GoToBegin(); 00127 while ( !it.IsAtEnd() ) 00128 { 00129 norm = it.Get().GetNorm(); 00130 minValue = std::min(norm, minValue); 00131 maxValue = std::max(norm, maxValue); 00132 } 00133 MITK_INFO << "Range of vector magnitudes: [" << minValue << ", "<< maxValue << "]." << std::endl; 00134 vtkLut->SetRange(minValue, maxValue); 00135 } 00136 else 00137 { 00138 itkWarningMacro(<< "Sorry, only 3d vector images are currently supported!"); 00139 }*/ 00140 vtkLut->SetRange(0, 10); 00141 output->SetVtkLookupTable( vtkLut ); 00142 vtkLut->Delete(); 00143 } 00144 }