Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPartialVolumeAnalysisHistogramCalculator.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 
18 #ifndef _MITK_PartialVolumeAnalysisHistogramCalculator_H
19 #define _MITK_PartialVolumeAnalysisHistogramCalculator_H
20 
22 
23 #include <itkObject.h>
24 #include <itkImage.h>
25 #include <itkTimeStamp.h>
26 
27 
28 #include "mitkImage.h"
29 #include "mitkImageTimeSelector.h"
30 #include "mitkPlanarFigure.h"
31 
32 
33 
34 namespace mitk
35 {
36 
58  {
59  public:
60 
61  enum
62  {
63  MASKING_MODE_NONE = 0,
65  MASKING_MODE_PLANARFIGURE
66  };
67 
69  typedef mitk::Image::HistogramType::ConstIterator HistogramConstIteratorType;
70 
71  struct Statistics
72  {
73  unsigned int N;
74  double Min;
75  double Max;
76  double Mean;
77  double Median;
78  double Variance;
79  double Sigma;
80  double RMS;
81 
82  void Reset()
83  {
84  N = 0;
85  Min = 0.0;
86  Max = 0.0;
87  Mean = 0.0;
88  Median = 0.0;
89  Variance = 0.0;
90  Sigma = 0.0;
91  RMS = 0.0;
92  }
93  };
94 
96 
97  typedef itk::TimeStamp TimeStampType;
98  typedef bool BoolType;
99 
100  typedef itk::Image< unsigned char, 3 > MaskImage3DType;
101  typedef itk::Image< unsigned char, 2 > MaskImage2DType;
102 
103  typedef itk::Image< float, 2 > InternalImage2DType;
104 
106  itkFactorylessNewMacro(Self)
107  itkCloneMacro(Self)
108 
110  void SetImage( const mitk::Image *image );
111 
113  void SetImageMask( const mitk::Image *imageMask );
114 
116  void SetPlanarFigure( const mitk::PlanarFigure *planarFigure );
117 
120  void AddAdditionalResamplingImage( const mitk::Image *image );
121 
123  void SetMaskingMode( unsigned int mode );
124 
126  itkGetMacro( MaskingMode, unsigned int );
127 
129  void SetMaskingModeToNone();
130 
132  void SetMaskingModeToImage();
133 
135  void SetMaskingModeToPlanarFigure();
136 
138  void SetNumberOfBins( unsigned int number )
139  {
140  if(m_NumberOfBins != number)
141  {
142  m_NumberOfBins = number;
143  SetModified();
144  }
145  }
146 
148  unsigned int GetNumberOfBins( )
149  { return m_NumberOfBins; }
150 
152  void SetUpsamplingFactor( float number )
153  {
154  if(m_UpsamplingFactor != number)
155  {
156  m_UpsamplingFactor = number;
157  SetModified();
158  }
159  }
160 
163  { return m_UpsamplingFactor; }
164 
166  void SetGaussianSigma( float number )
167  {
168  if(m_GaussianSigma != number)
169  {
170  m_GaussianSigma = number;
171  SetModified();
172  }
173  }
174 
176  unsigned int GetPlanarFigureThickness( )
177  { return m_PlanarFigureThickness; }
178 
179 
181  void SetPlanarFigureThickness( unsigned int number )
182  {
183  if(m_PlanarFigureThickness != number)
184  {
185  m_PlanarFigureThickness = number;
186  SetModified();
187  }
188  }
189 
192  { return m_GaussianSigma; }
193 
194  void SetModified();
195 
201  virtual bool ComputeStatistics( );
202 
203 
205  const HistogramType *GetHistogram( ) const;
206 
208  const Statistics &GetStatistics( ) const;
209 
211  {
212  return m_InternalImage;
213  }
214 
216  {
217  if(i < m_InternalAdditionalResamplingImages.size())
218  {
219  return m_InternalAdditionalResamplingImages[i];
220  }
221  else
222  {
223  return nullptr;
224  }
225  }
226 
227  void SetForceUpdate(bool b)
228  {
229  m_ForceUpdate = b;
230  }
231 
232  protected:
233 
235 
237 
246  void ExtractImageAndMask( );
247 
248 
252  bool GetPrincipalAxis( const Geometry3D *geometry, Vector3D vector,
253  unsigned int &axis );
254 
255  template < typename TPixel, unsigned int VImageDimension >
256  void InternalCalculateStatisticsUnmasked(
257  const itk::Image< TPixel, VImageDimension > *image,
258  Statistics &statistics,
259  typename HistogramType::ConstPointer *histogram );
260 
261  template < typename TPixel, unsigned int VImageDimension >
262  void InternalCalculateStatisticsMasked(
263  const itk::Image< TPixel, VImageDimension > *image,
264  itk::Image< unsigned char, VImageDimension > *maskImage,
265  Statistics &statistics,
266  typename HistogramType::ConstPointer *histogram );
267 
268  template < typename TPixel, unsigned int VImageDimension >
269  void InternalCalculateMaskFromPlanarFigure(
270  itk::Image< TPixel, VImageDimension > *image, unsigned int axis );
271 
272  template < typename TPixel, unsigned int VImageDimension >
273  void InternalReorientImagePlane(
274  const itk::Image< TPixel, VImageDimension > *image, mitk::BaseGeometry* imggeo, mitk::BaseGeometry* planegeo3D, int additionalIndex );
275 
276  template < typename TPixel, unsigned int VImageDimension >
277  void InternalResampleImageFromMask(
278  const itk::Image< TPixel, VImageDimension > *image, int additionalIndex );
279 
280  void InternalResampleImage(
281  const MaskImage3DType *image/*, mitk::Geometry3D* imggeo*/ );
282 
283  template < typename TPixel, unsigned int VImageDimension >
284  void InternalCropAdditionalImage(
285  itk::Image< TPixel, VImageDimension > *image, int additionalIndex );
286 
287  void InternalMaskImage( mitk::Image *image );
288 
290  template <typename ITK_Exporter, typename VTK_Importer>
291  void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
292  {
293  importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
294 
295  importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
296  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
297  importer->SetSpacingCallback(exporter->GetSpacingCallback());
298  importer->SetOriginCallback(exporter->GetOriginCallback());
299  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
300 
301  importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
302 
303  importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
304  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
305  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
306  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
307  importer->SetCallbackUserData(exporter->GetCallbackUserData());
308  }
309 
311  template <typename VTK_Exporter, typename ITK_Importer>
312  void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
313  {
314  importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
315 
316  importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
317  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
318  importer->SetSpacingCallback(exporter->GetSpacingCallback());
319  importer->SetOriginCallback(exporter->GetOriginCallback());
320  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
321 
322  importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
323 
324  importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
325  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
326  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
327  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
328  importer->SetCallbackUserData(exporter->GetCallbackUserData());
329  }
330 
331  void UnmaskedStatisticsProgressUpdate();
332  void MaskedStatisticsProgressUpdate();
333 
337 
341 
343 
344  StatisticsType m_ImageStatistics;
345  StatisticsType m_MaskedImageStatistics;
346  StatisticsType m_PlanarFigureStatistics;
347 
349 
350  unsigned int m_MaskingMode;
352 
356  itk::ImageRegion<3> m_InternalMask3D;
357  std::vector<mitk::Image::ConstPointer> m_AdditionalResamplingImages;
358  std::vector<mitk::Image::Pointer> m_InternalAdditionalResamplingImages;
359 
363 
367 
368  unsigned int m_NumberOfBins;
369 
371 
373 
374  itk::ImageRegion<3> m_CropRegion;
375 
377 
379 
380  };
381 
382 }
383 
384 #endif // #define _MITK_PartialVolumeAnalysisHistogramCalculator_H
itk::SmartPointer< Self > Pointer
Standard implementation of BaseGeometry.
DataCollection - Class to facilitate loading/accessing structured data.
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer *importer)
#define MITKDIFFUSIONCORE_EXPORT
itk::SmartPointer< const Self > ConstPointer
itk::Statistics::Histogram< double > HistogramType
Definition: mitkImage.h:94
void SetPlanarFigureThickness(unsigned int number)
Set thickness of planar figure.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
Image class for storing images.
Definition: mitkImage.h:76
void ConnectPipelines(VTK_Exporter *exporter, ITK_Importer importer)
unsigned int GetPlanarFigureThickness()
Get thickness of planar figure.
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons...
Class for calculating statistics and histogram for an (optionally masked) image.
BaseGeometry Describes the geometry of a data object.