27 #ifndef __itkHistogram_h
28 #include <itkHistogram.h>
41 class SubImageSelector;
42 class ImageTimeSelector;
44 class ImageStatisticsHolder;
83 itkFactorylessNewMacro(
Self);
99 DontManageMemory = ReferenceMemory
118 unsigned int GetDimension()
const;
125 unsigned int GetDimension(
int i)
const;
131 virtual vtkImageData *GetVtkImageData(
int t = 0,
int n = 0);
132 virtual const vtkImageData *GetVtkImageData(
int t = 0,
int n = 0)
const;
137 bool IsSliceSet(
int s = 0,
int t = 0,
int n = 0)
const override;
142 bool IsVolumeSet(
int t = 0,
int n = 0)
const override;
147 bool IsChannelSet(
int n = 0)
const override;
161 virtual bool SetSlice(
const void *data,
int s = 0,
int t = 0,
int n = 0);
175 virtual bool SetVolume(
const void *data,
int t = 0,
int n = 0);
189 virtual bool SetChannel(
const void *data,
int n = 0);
200 virtual bool SetImportSlice(
212 virtual bool SetImportVolume(
void *data,
217 virtual bool SetImportVolume(
const void *const_data,
int t = 0,
int n = 0);
228 virtual bool SetImportChannel(
void *data,
237 unsigned int dimension,
238 const unsigned int *dimensions,
239 unsigned int channels = 1);
251 unsigned int channels = 1,
264 unsigned int channels = 1,
278 unsigned int channels = 1,
302 virtual void Initialize(vtkImageData *vtkimagedata,
int channels = 1,
int tDim = -1,
int sDim = -1,
int pDim = -1);
315 template <
typename itkImageType>
316 void InitializeByItk(
const itkImageType *itkimage,
int channels = 1,
int tDim = -1,
int sDim = -1)
318 if (itkimage ==
nullptr)
321 MITK_DEBUG <<
"Initializing MITK image from ITK image.";
323 m_Dimension = itkimage->GetImageDimension();
324 unsigned int i, *tmpDimensions =
new unsigned int[m_Dimension > 4 ? m_Dimension : 4];
325 for (i = 0; i < m_Dimension; ++i)
326 tmpDimensions[i] = itkimage->GetLargestPossibleRegion().GetSize().GetSize()[i];
330 for (i = 0, p = tmpDimensions + m_Dimension; i < 4 - m_Dimension; ++i, ++p)
335 if ((m_Dimension > 2) && (sDim >= 0))
336 tmpDimensions[2] = sDim;
338 if ((m_Dimension > 3) && (tDim >= 0))
339 tmpDimensions[3] = tDim;
345 MakePixelType<itkImageType>(itkimage->GetNumberOfComponentsPerPixel()), m_Dimension, tmpDimensions, channels);
346 const typename itkImageType::SpacingType &itkspacing = itkimage->GetSpacing();
352 if (m_Dimension >= 2)
353 spacing[1] = itkspacing[1];
354 if (m_Dimension >= 3)
355 spacing[2] = itkspacing[2];
359 const typename itkImageType::PointType &itkorigin = itkimage->GetOrigin();
362 if (m_Dimension >= 2)
363 origin[1] = itkorigin[1];
364 if (m_Dimension >= 3)
365 origin[2] = itkorigin[2];
368 const typename itkImageType::DirectionType &itkdirection = itkimage->GetDirection();
369 MITK_DEBUG <<
"ITK direction " << itkdirection;
371 matrix.SetIdentity();
372 unsigned int j, itkDimMax3 = (m_Dimension >= 3 ? 3 : m_Dimension);
374 bool itkdirectionOk =
true;
376 for (j = 0; j < itkDimMax3; ++j)
379 for (i = 0; i < itkDimMax3; ++i)
381 columnSum += fabs(itkdirection[i][j]);
385 itkdirectionOk =
false;
389 (j == 2) && (m_Dimensions[2] == 1))
401 MITK_WARN <<
"Illegal value of itk::Image::GetSpacing()[" << j <<
"]=" << spacing[j]
402 <<
". Using inverted value " << -spacing[j];
403 spacing[j] = -spacing[j];
407 MITK_ERROR <<
"Illegal value of itk::Image::GetSpacing()[" << j <<
"]=" << spacing[j]
408 <<
". Using 1.0 instead.";
412 if (itkdirectionOk ==
false)
414 MITK_ERROR <<
"Illegal matrix returned by itk::Image::GetDirection():" << itkdirection
415 <<
" Using identity instead.";
416 for (i = 0; i < itkDimMax3; ++i)
417 for (j = 0; j < itkDimMax3; ++j)
419 matrix[i][j] = spacing[j];
425 for (i = 0; i < itkDimMax3; ++i)
426 for (j = 0; j < itkDimMax3; ++j)
427 matrix[i][j] = itkdirection[i][j] * spacing[j];
442 timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
443 SetTimeGeometry(timeGeometry);
446 delete[] tmpDimensions;
455 virtual bool IsValidSlice(
int s = 0,
int t = 0,
int n = 0)
const;
461 virtual bool IsValidVolume(
int t = 0,
int n = 0)
const;
467 virtual bool IsValidChannel(
int n = 0)
const;
474 bool IsRotated()
const;
481 unsigned int *GetDimensions()
const;
492 virtual ImageDataItemPointer GetSliceData(
int s = 0,
495 void *data =
nullptr,
496 ImportMemoryManagementType importMemoryManagement = CopyMemory)
const;
501 virtual ImageDataItemPointer GetVolumeData(
int t = 0,
503 void *data =
nullptr,
504 ImportMemoryManagementType importMemoryManagement = CopyMemory)
const;
509 virtual ImageDataItemPointer GetChannelData(
int n = 0,
510 void *data =
nullptr,
511 ImportMemoryManagementType importMemoryManagement = CopyMemory)
const;
526 int GetSliceIndex(
int s = 0,
int t = 0,
int n = 0)
const;
528 int GetVolumeIndex(
int t = 0,
int n = 0)
const;
530 void ComputeOffsetTable();
532 virtual bool IsValidTimeStep(
int t)
const;
534 void Expand(
unsigned int timeSteps)
override;
540 void *data =
nullptr,
555 void Clear()
override;
558 void Initialize()
override;
560 void PrintSelf(std::ostream &os, itk::Indent indent)
const override;
601 bool IsSliceSet_unlocked(
int s,
int t,
int n)
const;
602 bool IsVolumeSet_unlocked(
int t,
int n)
const;
603 bool IsChannelSet_unlocked(
int n)
const;
606 mutable std::vector<ImageAccessorBase *> m_Readers;
608 mutable std::vector<ImageAccessorBase *> m_Writers;
610 mutable std::vector<ImageAccessorBase *> m_VtkReaders;
613 mutable std::mutex m_ReadWriteLock;
615 mutable std::mutex m_VtkReadersLock;