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 #ifndef __itkQBallToRgbImageFilter_h
00019 #define __itkQBallToRgbImageFilter_h
00020
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkOrientationDistributionFunction.h"
00023 #include "itkRGBAPixel.h"
00024
00025 namespace itk
00026 {
00027
00028 #define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val) (val) = \
00029 ( (val) < 0 ) ? ( 0 ) : ( ( (val)>1 ) ? ( 1 ) : ( (val) ) );
00030
00031
00035 template <typename TInputImage,
00036 typename TOutputImage=itk::Image<itk::RGBAPixel<unsigned char>,3> >
00037 class QBallToRgbImageFilter :
00038 public ImageToImageFilter<TInputImage,TOutputImage>
00039 {
00040 public:
00042 typedef QBallToRgbImageFilter Self;
00043 typedef ImageToImageFilter<TInputImage,TOutputImage>
00044 Superclass;
00045 typedef SmartPointer<Self> Pointer;
00046 typedef SmartPointer<const Self> ConstPointer;
00047
00048 typedef typename Superclass::InputImageType InputImageType;
00049 typedef typename Superclass::OutputImageType OutputImageType;
00050 typedef typename OutputImageType::PixelType OutputPixelType;
00051 typedef typename TInputImage::PixelType InputPixelType;
00052 typedef typename InputPixelType::ValueType InputValueType;
00053
00055 itkTypeMacro( QBallToRgbImageFilter, ImageToImageFilter );
00056
00058 itkNewMacro(Self);
00059
00061 void PrintSelf(std::ostream& os, Indent indent) const
00062 { this->Superclass::PrintSelf( os, indent ); }
00063
00064 #ifdef ITK_USE_CONCEPT_CHECKING
00065
00066 itkConceptMacro(InputHasNumericTraitsCheck,
00067 (Concept::HasNumericTraits<InputValueType>));
00069 #endif
00070
00071 protected:
00072 QBallToRgbImageFilter() {};
00073 virtual ~QBallToRgbImageFilter() {};
00074
00075 void GenerateData()
00076 {
00077
00078 typename InputImageType::Pointer qballImage = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
00079
00080 typename OutputImageType::Pointer outputImage =
00081 static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
00082
00083 typename InputImageType::RegionType region = qballImage->GetLargestPossibleRegion();
00084
00085 outputImage->SetSpacing( qballImage->GetSpacing() );
00086 outputImage->SetOrigin( qballImage->GetOrigin() );
00087 outputImage->SetDirection( qballImage->GetDirection() );
00088 outputImage->SetRegions( qballImage->GetLargestPossibleRegion());
00089 outputImage->Allocate();
00090
00091 typedef ImageRegionConstIterator< InputImageType > QBallImageIteratorType;
00092 QBallImageIteratorType qballIt(qballImage, qballImage->GetLargestPossibleRegion());
00093
00094 typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
00095 OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
00096
00097 qballIt.GoToBegin();
00098 outputIt.GoToBegin();
00099
00100 while(!qballIt.IsAtEnd() && !outputIt.IsAtEnd()){
00101
00102 InputPixelType x = qballIt.Get();
00103 typedef itk::OrientationDistributionFunction<float,QBALL_ODFSIZE> OdfType;
00104 OdfType odf(x.GetDataPointer());
00105
00106 int pd = odf.GetPrincipleDiffusionDirection();
00107 vnl_vector_fixed<double,3> dir = OdfType::GetDirection(pd);
00108
00109 const float fa = odf.GetGeneralizedFractionalAnisotropy();
00110 float r = fabs(dir[0]) * fa;
00111 float g = fabs(dir[1]) * fa;
00112 float b = fabs(dir[2]) * fa;
00113
00114 float a = fa;
00115
00116 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(r);
00117 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(g);
00118 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(b);
00119 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(a);
00120
00121 OutputPixelType out;
00122 out.SetRed( r * 255.0f);
00123 out.SetGreen( g * 255.0f);
00124 out.SetBlue( b * 255.0f);
00125 out.SetAlpha( a * 255.0f);
00126
00127 outputIt.Set(out);
00128
00129 ++qballIt;
00130 ++outputIt;
00131 }
00132
00133 }
00134
00135 private:
00136 QBallToRgbImageFilter(const Self&);
00137 void operator=(const Self&);
00138 };
00139
00140 }
00141
00142 #endif