27 #ifndef __itkHistogram_h
28 #include <itkHistogram.h>
41 class SubImageSelector;
42 class ImageTimeSelector;
44 class ImageStatisticsHolder;
82 itkFactorylessNewMacro(
Self);
98 DontManageMemory = ReferenceMemory
117 unsigned int GetDimension()
const;
124 unsigned int GetDimension(
int i)
const;
130 virtual vtkImageData *GetVtkImageData(
int t = 0,
int n = 0);
131 virtual const vtkImageData *GetVtkImageData(
int t = 0,
int n = 0)
const;
136 bool IsSliceSet(
int s = 0,
int t = 0,
int n = 0)
const override;
141 bool IsVolumeSet(
int t = 0,
int n = 0)
const override;
146 bool IsChannelSet(
int n = 0)
const override;
160 virtual bool SetSlice(
const void *data,
int s = 0,
int t = 0,
int n = 0);
174 virtual bool SetVolume(
const void *data,
int t = 0,
int n = 0);
188 virtual bool SetChannel(
const void *data,
int n = 0);
199 virtual bool SetImportSlice(
211 virtual bool SetImportVolume(
void *data,
216 virtual bool SetImportVolume(
const void *const_data,
int t = 0,
int n = 0);
227 virtual bool SetImportChannel(
void *data,
236 unsigned int dimension,
237 const unsigned int *dimensions,
238 unsigned int channels = 1);
250 unsigned int channels = 1,
263 unsigned int channels = 1,
277 unsigned int channels = 1,
301 virtual void Initialize(vtkImageData *vtkimagedata,
int channels = 1,
int tDim = -1,
int sDim = -1,
int pDim = -1);
314 template <
typename itkImageType>
315 void InitializeByItk(
const itkImageType *itkimage,
int channels = 1,
int tDim = -1,
int sDim = -1)
317 if (itkimage ==
nullptr)
320 MITK_DEBUG <<
"Initializing MITK image from ITK image.";
322 m_Dimension = itkimage->GetImageDimension();
323 unsigned int i, *tmpDimensions =
new unsigned int[m_Dimension > 4 ? m_Dimension : 4];
324 for (i = 0; i < m_Dimension; ++i)
325 tmpDimensions[i] = itkimage->GetLargestPossibleRegion().GetSize().GetSize()[i];
329 for (i = 0, p = tmpDimensions + m_Dimension; i < 4 - m_Dimension; ++i, ++p)
334 if ((m_Dimension > 2) && (sDim >= 0))
335 tmpDimensions[2] = sDim;
337 if ((m_Dimension > 3) && (tDim >= 0))
338 tmpDimensions[3] = tDim;
344 MakePixelType<itkImageType>(itkimage->GetNumberOfComponentsPerPixel()), m_Dimension, tmpDimensions, channels);
345 const typename itkImageType::SpacingType &itkspacing = itkimage->GetSpacing();
351 if (m_Dimension >= 2)
352 spacing[1] = itkspacing[1];
353 if (m_Dimension >= 3)
354 spacing[2] = itkspacing[2];
358 const typename itkImageType::PointType &itkorigin = itkimage->GetOrigin();
361 if (m_Dimension >= 2)
362 origin[1] = itkorigin[1];
363 if (m_Dimension >= 3)
364 origin[2] = itkorigin[2];
367 const typename itkImageType::DirectionType &itkdirection = itkimage->GetDirection();
368 MITK_DEBUG <<
"ITK direction " << itkdirection;
370 matrix.SetIdentity();
371 unsigned int j, itkDimMax3 = (m_Dimension >= 3 ? 3 : m_Dimension);
373 bool itkdirectionOk =
true;
375 for (j = 0; j < itkDimMax3; ++j)
378 for (i = 0; i < itkDimMax3; ++i)
380 columnSum += fabs(itkdirection[i][j]);
384 itkdirectionOk =
false;
388 (j == 2) && (m_Dimensions[2] == 1))
400 MITK_WARN <<
"Illegal value of itk::Image::GetSpacing()[" << j <<
"]=" << spacing[j]
401 <<
". Using inverted value " << -spacing[j];
402 spacing[j] = -spacing[j];
406 MITK_ERROR <<
"Illegal value of itk::Image::GetSpacing()[" << j <<
"]=" << spacing[j]
407 <<
". Using 1.0 instead.";
411 if (itkdirectionOk ==
false)
413 MITK_ERROR <<
"Illegal matrix returned by itk::Image::GetDirection():" << itkdirection
414 <<
" Using identity instead.";
415 for (i = 0; i < itkDimMax3; ++i)
416 for (j = 0; j < itkDimMax3; ++j)
418 matrix[i][j] = spacing[j];
424 for (i = 0; i < itkDimMax3; ++i)
425 for (j = 0; j < itkDimMax3; ++j)
426 matrix[i][j] = itkdirection[i][j] * spacing[j];
441 timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
442 SetTimeGeometry(timeGeometry);
445 delete[] tmpDimensions;
454 virtual bool IsValidSlice(
int s = 0,
int t = 0,
int n = 0)
const;
460 virtual bool IsValidVolume(
int t = 0,
int n = 0)
const;
466 virtual bool IsValidChannel(
int n = 0)
const;
473 bool IsRotated()
const;
480 unsigned int *GetDimensions()
const;
491 virtual ImageDataItemPointer GetSliceData(
int s = 0,
494 void *data =
nullptr,
495 ImportMemoryManagementType importMemoryManagement = CopyMemory)
const;
500 virtual ImageDataItemPointer GetVolumeData(
int t = 0,
502 void *data =
nullptr,
503 ImportMemoryManagementType importMemoryManagement = CopyMemory)
const;
508 virtual ImageDataItemPointer GetChannelData(
int n = 0,
509 void *data =
nullptr,
510 ImportMemoryManagementType importMemoryManagement = CopyMemory)
const;
525 int GetSliceIndex(
int s = 0,
int t = 0,
int n = 0)
const;
527 int GetVolumeIndex(
int t = 0,
int n = 0)
const;
529 void ComputeOffsetTable();
531 virtual bool IsValidTimeStep(
int t)
const;
533 void Expand(
unsigned int timeSteps)
override;
539 void *data =
nullptr,
554 void Clear()
override;
557 void Initialize()
override;
559 void PrintSelf(std::ostream &os, itk::Indent indent)
const override;
600 bool IsSliceSet_unlocked(
int s,
int t,
int n)
const;
601 bool IsVolumeSet_unlocked(
int t,
int n)
const;
602 bool IsChannelSet_unlocked(
int n)
const;
605 mutable std::vector<ImageAccessorBase *> m_Readers;
607 mutable std::vector<ImageAccessorBase *> m_Writers;
609 mutable std::vector<ImageAccessorBase *> m_VtkReaders;
612 mutable std::mutex m_ReadWriteLock;
614 mutable std::mutex m_VtkReadersLock;