Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkQBallToRgbImageFilter.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkQBallToRgbImageFilter_h
18 #define __itkQBallToRgbImageFilter_h
19 
20 #include "itkUnaryFunctorImageFilter.h"
22 #include "itkRGBAPixel.h"
23 #include "itkImageRegionConstIterator.h"
24 #include "itkImageRegionIterator.h"
25 
26 namespace itk
27 {
28 
29  #define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val) (val) = \
30  ( (val) < 0 ) ? ( 0 ) : ( ( (val)>1 ) ? ( 1 ) : ( (val) ) );
31 
32 
36 template <typename TInputImage,
37 typename TOutputImage=itk::Image<itk::RGBAPixel<unsigned char>,3> >
39  public ImageToImageFilter<TInputImage,TOutputImage>
40  {
41  public:
44  typedef ImageToImageFilter<TInputImage,TOutputImage>
48 
50  typedef typename Superclass::OutputImageType OutputImageType;
54 
56  itkTypeMacro( QBallToRgbImageFilter, ImageToImageFilter )
57 
58 
59  itkFactorylessNewMacro(Self)
60  itkCloneMacro(Self)
61 
63  void PrintSelf(std::ostream& os, Indent indent) const
64  { this->Superclass::PrintSelf( os, indent ); }
65 
66 #ifdef ITK_USE_CONCEPT_CHECKING
67 
68  itkConceptMacro(InputHasNumericTraitsCheck,
69  (Concept::HasNumericTraits<InputValueType>));
71 #endif
72 
73 protected:
76 
77  void GenerateData()
78  {
79 
80  typename InputImageType::Pointer qballImage = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
81 
82  typename OutputImageType::Pointer outputImage =
83  static_cast< OutputImageType * >(this->ProcessObject::GetPrimaryOutput());
84 
85  typename InputImageType::RegionType region = qballImage->GetLargestPossibleRegion();
86 
87  outputImage->SetSpacing( qballImage->GetSpacing() ); // Set the image spacing
88  outputImage->SetOrigin( qballImage->GetOrigin() ); // Set the image origin
89  outputImage->SetDirection( qballImage->GetDirection() ); // Set the image direction
90  outputImage->SetRegions( qballImage->GetLargestPossibleRegion());
91  outputImage->Allocate();
92 
93  typedef ImageRegionConstIterator< InputImageType > QBallImageIteratorType;
94  QBallImageIteratorType qballIt(qballImage, qballImage->GetLargestPossibleRegion());
95 
96  typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
97  OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
98 
99  qballIt.GoToBegin();
100  outputIt.GoToBegin();
101 
102  while(!qballIt.IsAtEnd() && !outputIt.IsAtEnd()){
103 
104  InputPixelType x = qballIt.Get();
106  OdfType odf(x.GetDataPointer());
107 
108  int pd = odf.GetPrincipleDiffusionDirection();
109  if (pd==-1)
110  MITK_ERROR << "ODF corrupted: GetPrincipleDiffusionDirection returned -1";
111 
112  vnl_vector_fixed<double,3> dir = OdfType::GetDirection(pd);
113 
114  const float fa = odf.GetGeneralizedFractionalAnisotropy();
115  float r = fabs(dir[0]) * fa;
116  float g = fabs(dir[1]) * fa;
117  float b = fabs(dir[2]) * fa;
118 // float a = (fa-(m_OpacLevel-m_OpacWindow/2.0f))/m_OpacWindow;
119  float a = fa;
120 
125 
126  OutputPixelType out;
127  out.SetRed( r * 255.0f);
128  out.SetGreen( g * 255.0f);
129  out.SetBlue( b * 255.0f);
130  out.SetAlpha( a * 255.0f);
131 
132  outputIt.Set(out);
133 
134  ++qballIt;
135  ++outputIt;
136  }
137 
138  }
139 
140 private:
141  QBallToRgbImageFilter(const Self&); //purposely not implemented
142  void operator=(const Self&); //purposely not implemented
143 };
144 
145 } // end namespace itk
146 
147 #endif
itk::SmartPointer< Self > Pointer
#define MITK_ERROR
Definition: mitkLogMacros.h:24
#define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val)
InputPixelType::ValueType InputValueType
STL namespace.
TInputImage::PixelType InputPixelType
void PrintSelf(std::ostream &os, Indent indent) const
OutputImageType::PixelType OutputPixelType
itk::Image< double, 3 > InputImageType
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
SmartPointer< const Self > ConstPointer
unsigned short PixelType
Superclass::OutputImageType OutputImageType
Superclass::InputImageType InputImageType
ImageToImageFilter< TInputImage, TOutputImage > Superclass