27 #ifndef __itkHistogram_h
28 #include <itkHistogram.h>
41 class SubImageSelector;
42 class ImageTimeSelector;
44 class ImageStatisticsHolder;
82 itkFactorylessNewMacro(
Self);
98 DontManageMemory = ReferenceMemory
136 bool IsSliceSet(
int s = 0,
int t = 0,
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);
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;
494 void *data =
nullptr,
502 void *data =
nullptr,
509 void *data =
nullptr,
533 void Expand(
unsigned int timeSteps)
override;
539 void *data =
nullptr,
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;
BaseGeometry Describes the geometry of a data object.
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
An object which holds all essential information about a single channel of an Image.
ImageReadAccessor class to get locked read access for a particular image part.
Class holding the statistics information about a single mitk::Image.
ImageVtkReadAccessor class provides any image read access which is required by Vtk methods.
ImageVtkWriteAccessor class provides any image write access which is required by Vtk methods.
ImageWriteAccessor class to get locked write-access for a particular image part.
Image class for storing images.
virtual void Initialize(const mitk::PixelType &type, int sDim, const mitk::PlaneGeometry &geometry2d, unsigned int channels=1, int tDim=1)
bool IsRotated() const
Returns true if an image is rotated, i.e. its geometry's transformation matrix has nonzero elements b...
ImageDataItemPointerArray m_Slices
void SetGeometry(BaseGeometry *aGeometry3D) override
Sets a geometry to an image.
ImageDataItemPointerArray m_Channels
ImageDataItemPointer m_CompleteData
itk::Statistics::Histogram< double > HistogramType
unsigned int * GetDimensions() const
Get the sizes of all dimensions as an integer-array.
void Expand(unsigned int timeSteps) override
Expands the TimeGeometry to a number of TimeSteps.
StatisticsHolderPointer m_ImageStatistics
virtual bool SetImportVolume(void *data, int t=0, int n=0, ImportMemoryManagementType importMemoryManagement=CopyMemory)
Set data as volume at time t in channel n. It is in the responsibility of the caller to ensure that t...
virtual ImageDataItemPointer AllocateSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
std::mutex m_ImageDataArraysLock
std::vector< ImageDataItemPointer > ImageDataItemPointerArray
Vector container of SmartPointers to ImageDataItems; Class is only for internal usage to allow conven...
void Clear() override
Calls ClearData() and InitializeEmpty();.
virtual bool SetImportChannel(void *data, int n=0, ImportMemoryManagementType importMemoryManagement=CopyMemory)
Set data in channel n. It is in the responsibility of the caller to ensure that the data vector data ...
mitk::ImageStatisticsHolder * StatisticsHolderPointer
void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual bool SetSlice(const void *data, int s=0, int t=0, int n=0)
Set data as slice s at time t in channel n. It is in the responsibility of the caller to ensure that ...
std::lock_guard< std::mutex > MutexHolder
itk::SmartPointer< ImageDataItem > ImageDataItemPointer
virtual void Initialize(const mitk::PixelType &type, const mitk::BaseGeometry &geometry, unsigned int channels=1, int tDim=1)
virtual bool IsValidVolume(int t=0, int n=0) const
Check whether volume at time t in channel n is valid, i.e., is (or can be) inside of the image.
void ComputeOffsetTable()
ImageDescriptor::Pointer GetImageDescriptor() const
virtual ImageDataItemPointer GetSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
ChannelDescriptor GetChannelDescriptor(int id=0) const
virtual ImageDataItemPointer AllocateVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
virtual bool SetImportSlice(void *data, int s=0, int t=0, int n=0, ImportMemoryManagementType importMemoryManagement=CopyMemory)
Set data as slice s at time t in channel n. It is in the responsibility of the caller to ensure that ...
int GetVolumeIndex(int t=0, int n=0) const
virtual void Initialize(const mitk::ImageDescriptor::Pointer inDesc)
unsigned int * m_Dimensions
void InitializeByItk(const itkImageType *itkimage, int channels=1, int tDim=-1, int sDim=-1)
virtual bool IsValidTimeStep(int t) const
virtual ImageDataItemPointer GetChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
virtual void Initialize(vtkImageData *vtkimagedata, int channels=1, int tDim=-1, int sDim=-1, int pDim=-1)
virtual bool IsValidChannel(int n=0) const
Check whether the channel n is valid, i.e., is (or can be) inside of the image.
void Initialize() override
bool IsChannelSet(int n=0) const override
Check whether the channel n is set.
unsigned int GetDimension(int i) const
Get the size of dimension i (e.g., i=0 results in the number of pixels in x-direction).
unsigned int GetDimension() const
Get dimension of the image.
int GetSliceIndex(int s=0, int t=0, int n=0) const
bool IsVolumeSet(int t=0, int n=0) const override
Check whether volume at time t in channel n is set.
Image(const Image &other)
virtual bool SetImportVolume(const void *const_data, int t=0, int n=0)
ImageDescriptor::Pointer m_ImageDescriptor
virtual bool SetVolume(const void *data, int t=0, int n=0)
Set data as volume at time t in channel n. It is in the responsibility of the caller to ensure that t...
virtual ImageDataItemPointer AllocateChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
virtual ImageDataItemPointer GetVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
bool IsSliceSet(int s=0, int t=0, int n=0) const override
Check whether slice s at time t in channel n is set.
virtual void Initialize(const mitk::PixelType &type, const mitk::TimeGeometry &geometry, unsigned int channels=1, int tDim=-1)
Initialize new (or re-initialize) image information by a TimeGeometry.
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time t of channel n as a vtkImageData.
virtual bool SetChannel(const void *data, int n=0)
Set data in channel n. It is in the responsibility of the caller to ensure that the data vector data ...
virtual const vtkImageData * GetVtkImageData(int t=0, int n=0) const
StatisticsHolderPointer GetStatistics() const
Returns a pointer to the ImageStatisticsHolder object that holds all statistics information for the i...
ImportMemoryManagementType
virtual void Initialize(const mitk::PixelType &type, unsigned int dimension, const unsigned int *dimensions, unsigned int channels=1)
ImageDataItemPointerArray m_Volumes
virtual void Initialize(const mitk::Image *image)
virtual bool IsValidSlice(int s=0, int t=0, int n=0) const
Check whether slice s at time t in channel n is valid, i.e., is (or can be) inside of the image.
Class for defining the data type of pixels.
Describes a two-dimensional, rectangular plane.
Super class of data objects consisting of slices.
Describes the geometry of a data object consisting of slices.
virtual void InitializeEvenlySpaced(mitk::PlaneGeometry *geometry2D, unsigned int slices)
Completely initialize this instance as evenly-spaced with slices parallel to the provided PlaneGeomet...
Base class of all classes providing access to parts of an image.
#define mitkClassMacro(className, SuperClassName)
#define mitkCloneMacro(classname)
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
MITKCORE_EXPORT ImageDimensionVectorType DetermineImageDimensionsFromTimeGeometry(const TimeGeometry *timeGeometry)
std::vector< unsigned int > ImageDimensionVectorType
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.