diff --git a/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.cpp b/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.cpp index 5af81847c3..e1bc23900f 100644 --- a/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.cpp +++ b/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.cpp @@ -1,137 +1,156 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "vtkMitkApplyLevelWindowToRGBFilter.h" #include #include #include #include #include #include vtkMitkApplyLevelWindowToRGBFilter::vtkMitkApplyLevelWindowToRGBFilter() { } vtkMitkApplyLevelWindowToRGBFilter::~vtkMitkApplyLevelWindowToRGBFilter() { } void vtkMitkApplyLevelWindowToRGBFilter::SetLookupTable(vtkScalarsToColors *lookupTable) { m_LookupTable = lookupTable; } vtkScalarsToColors* vtkMitkApplyLevelWindowToRGBFilter::GetLookupTable() { return m_LookupTable; } //---------------------------------------------------------------------------- // This templated function executes the filter for any type of data. template - void vtkMitkApplyLevelWindowToRGBFilter::vtkCalculateIntensityFromLookupTable( - vtkImageData *inData, - vtkImageData *outData, - int outExt[6], T *) + void vtkCalculateIntensityFromLookupTable(vtkMitkApplyLevelWindowToRGBFilter *self, + vtkImageData *inData, + vtkImageData *outData, + int outExt[6], T *) { vtkImageIterator inIt(inData, outExt); vtkImageIterator outIt(outData, outExt); vtkLookupTable* lookupTable; int idxC, maxC; double H, S, I, Imin, Imax; double imgRange[2]; double tableRange[2]; // find the region to loop over maxC = inData->GetNumberOfScalarComponents()-1; Imin = 255; Imax = 0; // Loop through ouput pixels while (!outIt.IsAtEnd()) - { + { T* inSI = inIt.BeginSpan(); T* outSI = outIt.BeginSpan(); T* outSIEnd = outIt.EndSpan(); while (outSI != outSIEnd) - { + { // Pixel operation H = static_cast(*inSI); inSI++; S = static_cast(*inSI); inSI++; I = static_cast(*inSI); inSI++; - lookupTable = dynamic_cast(this->GetLookupTable()); + lookupTable = dynamic_cast(self->GetLookupTable()); lookupTable->GetTableRange(tableRange); inData->GetScalarRange(imgRange); I = ((I - tableRange[0]) / ( tableRange[1] - tableRange[0] )) * imgRange[1]; I = (I < imgRange[0] ? imgRange[0] : I); I = (I > imgRange[1] ? imgRange[1] : I); // assign output. *outSI = static_cast(H); outSI++; *outSI = static_cast(S); outSI++; *outSI = static_cast(I); outSI++; for (idxC = 3; idxC <= maxC; idxC++) - { + { *outSI++ = *inSI++; - } } + } inIt.NextSpan(); outIt.NextSpan(); - } + } } void vtkMitkApplyLevelWindowToRGBFilter::ExecuteInformation() { vtkImageData *input = this->GetInput(); vtkImageData *output = this->GetOutput(); if (!input) { vtkErrorMacro(<< "Input not set."); return; } output->CopyTypeSpecificInformation( input ); int extent[6]; input->GetWholeExtent(extent); output->SetExtent(extent); output->SetWholeExtent(extent); output->SetUpdateExtent(extent); output->AllocateScalars(); switch (input->GetScalarType()) - { + { vtkTemplateMacro( - vtkCalculateIntensityFromLookupTable( input, - output, extent, - static_cast(0))); - default: - vtkErrorMacro(<< "Execute: Unknown ScalarType"); - return; - } + vtkCalculateIntensityFromLookupTable( this, + input, + output, extent, + static_cast(0))); + default: + vtkErrorMacro(<< "Execute: Unknown ScalarType"); + return; + } +} + +void vtkMitkApplyLevelWindowToRGBFilter::ThreadedExecute(vtkImageData *inData, + vtkImageData *outData, + int extent[6], int id) +{ + switch (inData->GetScalarType()) + { + vtkTemplateMacro( + vtkCalculateIntensityFromLookupTable( this, + inData, + outData, + extent, + static_cast(0))); + default: + vtkErrorMacro(<< "Execute: Unknown ScalarType"); + return; + } } void vtkMitkApplyLevelWindowToRGBFilter::ExecuteInformation( - vtkImageData *vtkNotUsed(inData), vtkImageData *vtkNotUsed(outData)) + vtkImageData *vtkNotUsed(inData), vtkImageData *vtkNotUsed(outData)) { } diff --git a/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.h b/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.h index 14bf9e7d8e..03856b156c 100644 --- a/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.h +++ b/Core/Code/Rendering/vtkMitkApplyLevelWindowToRGBFilter.h @@ -1,63 +1,70 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __vtkMitkApplyLevelWindowToRGBFilter_h #define __vtkMitkApplyLevelWindowToRGBFilter_h class vtkScalarsToColors; //class vtkImageToImageFilter; //#include #include //#include //#include //#include //#include #include //#include #include "mitkCommon.h" //#include "vtkThreadedImageAlgorithm.h" class MITK_CORE_EXPORT vtkMitkApplyLevelWindowToRGBFilter : public vtkImageToImageFilter { public: vtkScalarsToColors* GetLookupTable(); void SetLookupTable(vtkScalarsToColors *lookupTable); vtkMitkApplyLevelWindowToRGBFilter(); protected: ~vtkMitkApplyLevelWindowToRGBFilter(); - void ThreadedExecute(vtkImageData *inData, vtkImageData *outData,int extent[6], int id) - - template - void vtkCalculateIntensityFromLookupTable( - vtkImageData *inData, - vtkImageData *outData, - int outExt[6], T *); + /** \brief Method for threaded execution of the filter. + * \param *inData: The input. + * \param *outData: The output of the filter. + * \param extent[6]: Specefies the region of the image to be updated inside this thread. + * It is a six-component array of the form (xmin, xmax, ymin, ymax, zmin, zmax). + * \param id: The thread id. + */ + void ThreadedExecute(vtkImageData *inData, vtkImageData *outData,int extent[6], int id); + +// template +// void vtkCalculateIntensityFromLookupTable( +// vtkImageData *inData, +// vtkImageData *outData, +// int outExt[6], T *); void ExecuteInformation(); void ExecuteInformation(vtkImageData *vtkNotUsed(inData), vtkImageData *vtkNotUsed(outData)); private: vtkScalarsToColors* m_LookupTable; }; #endif