27 #ifndef __itkHistogram_h
28 #include <itkHistogram.h>
41 class SubImageSelector;
42 class ImageTimeSelector;
44 class ImageStatisticsHolder;
88 itkFactorylessNewMacro(Self);
112 DontManageMemory = ReferenceMemory
178 bool IsSliceSet(
int s = 0,
int t = 0,
int n = 0)
const override;
214 virtual bool SetSlice(
const void *data,
int s = 0,
int t = 0,
int n = 0);
232 virtual bool SetVolume(
const void *data,
int t = 0,
int n = 0);
348 unsigned int dimension,
349 const unsigned int *dimensions,
350 unsigned int channels = 1);
362 unsigned int channels = 1,
376 unsigned int channels = 1,
397 unsigned int channels = 1,
414 virtual void Initialize(
const mitk::ImageDescriptor::Pointer inDesc);
428 virtual void Initialize(vtkImageData *vtkimagedata,
int channels = 1,
int tDim = -1,
int sDim = -1,
int pDim = -1);
442 template <
typename itkImageType>
443 void InitializeByItk(
const itkImageType *itkimage,
int channels = 1,
int tDim = -1,
int sDim = -1)
445 if (itkimage ==
nullptr)
448 MITK_DEBUG <<
"Initializing MITK image from ITK image.";
450 m_Dimension = itkimage->GetImageDimension();
451 unsigned int i, *tmpDimensions =
new unsigned int[m_Dimension > 4 ? m_Dimension : 4];
452 for (i = 0; i < m_Dimension; ++i)
453 tmpDimensions[i] = itkimage->GetLargestPossibleRegion().GetSize().GetSize()[i];
457 for (i = 0, p = tmpDimensions + m_Dimension; i < 4 - m_Dimension; ++i, ++p)
462 if ((m_Dimension > 2) && (sDim >= 0))
463 tmpDimensions[2] = sDim;
465 if ((m_Dimension > 3) && (tDim >= 0))
466 tmpDimensions[3] = tDim;
472 MakePixelType<itkImageType>(itkimage->GetNumberOfComponentsPerPixel()), m_Dimension, tmpDimensions, channels);
473 const typename itkImageType::SpacingType &itkspacing = itkimage->GetSpacing();
479 if (m_Dimension >= 2)
480 spacing[1] = itkspacing[1];
481 if (m_Dimension >= 3)
482 spacing[2] = itkspacing[2];
486 const typename itkImageType::PointType &itkorigin = itkimage->GetOrigin();
489 if (m_Dimension >= 2)
490 origin[1] = itkorigin[1];
491 if (m_Dimension >= 3)
492 origin[2] = itkorigin[2];
495 const typename itkImageType::DirectionType &itkdirection = itkimage->GetDirection();
496 MITK_DEBUG <<
"ITK direction " << itkdirection;
498 matrix.SetIdentity();
499 unsigned int j, itkDimMax3 = (m_Dimension >= 3 ? 3 : m_Dimension);
501 bool itkdirectionOk =
true;
503 for (j = 0; j < itkDimMax3; ++j)
506 for (i = 0; i < itkDimMax3; ++i)
508 columnSum += fabs(itkdirection[i][j]);
512 itkdirectionOk =
false;
516 (j == 2) && (m_Dimensions[2] == 1))
528 MITK_WARN <<
"Illegal value of itk::Image::GetSpacing()[" << j <<
"]=" << spacing[j]
529 <<
". Using inverted value " << -spacing[j];
530 spacing[j] = -spacing[j];
534 MITK_ERROR <<
"Illegal value of itk::Image::GetSpacing()[" << j <<
"]=" << spacing[j]
535 <<
". Using 1.0 instead.";
539 if (itkdirectionOk ==
false)
541 MITK_ERROR <<
"Illegal matrix returned by itk::Image::GetDirection():" << itkdirection
542 <<
" Using identity instead.";
543 for (i = 0; i < itkDimMax3; ++i)
544 for (j = 0; j < itkDimMax3; ++j)
546 matrix[i][j] = spacing[j];
552 for (i = 0; i < itkDimMax3; ++i)
553 for (j = 0; j < itkDimMax3; ++j)
554 matrix[i][j] = itkdirection[i][j] * spacing[j];
569 timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
570 SetTimeGeometry(timeGeometry);
573 delete[] tmpDimensions;
670 void *data =
nullptr,
687 void *data =
nullptr,
702 void *data =
nullptr,
726 const void *
GetData(
int t = 0,
int n = 0)
const;
752 void Expand(
unsigned int timeSteps)
override;
758 void *data =
nullptr,
778 void PrintSelf(std::ostream &os, itk::Indent indent)
const override;
819 bool IsSliceSet_unlocked(
int s,
int t,
int n)
const;
820 bool IsVolumeSet_unlocked(
int t,
int n)
const;
821 bool IsChannelSet_unlocked(
int n)
const;
824 mutable std::vector<ImageAccessorBase *> m_Readers;
826 mutable std::vector<ImageAccessorBase *> m_Writers;
828 mutable std::vector<ImageAccessorBase *> m_VtkReaders;
831 mutable std::mutex m_ReadWriteLock;
833 mutable std::mutex m_VtkReadersLock;
Abstract base class describing the geometry of a data object.
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (voxel size) for each axis.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the affine transform that maps index coordinates to world coordinates.
void SetOrigin(const Point3D &origin)
Set the origin of the geometry in world coordinates (mm).
Holds essential information about a single channel of an Image.
Provides locked read-only access to a particular region of image data.
Class holding the statistics information about a single mitk::Image.
Provides read access to image data in the form required by VTK methods.
Provides write access to image data in the form required by VTK methods.
Provides locked write access to a particular region of image data.
Image class for storing multi-dimensional medical image data.
virtual void Initialize(const mitk::PixelType &type, int sDim, const mitk::PlaneGeometry &geometry2d, unsigned int channels=1, int tDim=1)
Initialize (or re-initialize) image from a PlaneGeometry and number of slices.
bool IsRotated() const
Check whether the image has a rotated geometry.
ImageDataItemPointerArray m_Slices
void SetGeometry(BaseGeometry *aGeometry3D) override
Set the geometry of the image.
ImageDataItemPointerArray m_Channels
ImageDataItemPointer m_CompleteData
itk::Statistics::Histogram< double > HistogramType
Histogram type used for image statistics (double-precision).
unsigned int * GetDimensions() const
Get the sizes of all dimensions as an integer array.
void Expand(unsigned int timeSteps) override
Expand the TimeGeometry to a number of time steps.
virtual void AllocateZeroedVolume(int t=0, int n=0)
Allocate a zero-initialized volume at time t in channel n.
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 with configurable memory management.
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.
void Clear() override
Reset the data object by calling ClearData() and InitializeEmpty().
virtual bool SetImportChannel(void *data, int n=0, ImportMemoryManagementType importMemoryManagement=CopyMemory)
Set data as the data for channel n with configurable memory management.
mitk::ImageStatisticsHolder * StatisticsHolderPointer
Pointer type to the ImageStatisticsHolder.
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.
std::lock_guard< std::mutex > MutexHolder
itk::SmartPointer< ImageDataItem > ImageDataItemPointer
Smart Pointer type to an ImageDataItem.
virtual void Initialize(const mitk::PixelType &type, const mitk::BaseGeometry &geometry, unsigned int channels=1, int tDim=1)
Initialize (or re-initialize) image from a BaseGeometry.
virtual bool IsValidVolume(int t=0, int n=0) const
Check whether the volume at time t in channel n is valid.
void ComputeOffsetTable()
ImageDescriptor::Pointer GetImageDescriptor() const
Get the image descriptor containing type and dimension information.
virtual ImageDataItemPointer GetSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
Get the ImageDataItem for slice s at time t in channel n.
ChannelDescriptor GetChannelDescriptor(int id=0) const
Get the channel descriptor for channel id.
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 with configurable memory management.
int GetVolumeIndex(int t=0, int n=0) const
virtual void Initialize(const mitk::ImageDescriptor::Pointer inDesc)
Initialize (or re-initialize) image from an ImageDescriptor.
unsigned int * m_Dimensions
void InitializeByItk(const itkImageType *itkimage, int channels=1, int tDim=-1, int sDim=-1)
Initialize (or re-initialize) image from a templated ITK image.
virtual bool IsValidTimeStep(int t) const
virtual ImageDataItemPointer GetChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
Get the ImageDataItem for channel n.
virtual void Initialize(vtkImageData *vtkimagedata, int channels=1, int tDim=-1, int sDim=-1, int pDim=-1)
Initialize (or re-initialize) image from a vtkImageData.
virtual bool IsValidChannel(int n=0) const
Check whether channel n is valid.
void Initialize() override
mitkClassMacro(Image, SlicedData)
bool IsChannelSet(int n=0) const override
Check whether channel n is set.
unsigned int GetDimension(int i) const
Get the size of dimension i.
unsigned int GetDimension() const
Get the number of dimensions of the image.
void * GetData(int t=0, int n=0)
Get a raw pointer to the volume data at t in channel n without locking.
int GetSliceIndex(int s=0, int t=0, int n=0) const
bool IsVolumeSet(int t=0, int n=0) const override
Check whether the 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)
Set const_data as volume at time t in channel n (copy-only).
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.
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
Get the ImageDataItem for the volume at time t in channel n.
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 (or re-initialize) image from a TimeGeometry.
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time step t of channel n as a vtkImageData.
virtual bool SetChannel(const void *data, int n=0)
Set data as the data for channel n.
virtual const vtkImageData * GetVtkImageData(int t=0, int n=0) const
Get a volume at a specific time step t of channel n as a vtkImageData.
StatisticsHolderPointer GetStatistics() const
Get the ImageStatisticsHolder that provides statistics for this image.
ImportMemoryManagementType
Defines how imported memory is managed when setting data on an Image.
@ CopyMemory
Data is copied to a new memory block owned by the Image. The original buffer is not freed by Image.
@ ReferenceMemory
Data is referenced by the Image. The Image does not free the buffer on deletion; the caller retains o...
@ ManageMemory
Data is referenced by the Image. The Image takes ownership and will free the buffer on deletion.
virtual void Initialize(const mitk::PixelType &type, unsigned int dimension, const unsigned int *dimensions, unsigned int channels=1)
Initialize (or re-initialize) image with pixel type and dimensions.
ImageDataItemPointerArray m_Volumes
const void * GetData(int t=0, int n=0) const
Get a raw pointer to the volume data at t in channel n without locking.
virtual void Initialize(const mitk::Image *image)
Initialize (or re-initialize) image from another mitk::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.
MITK matrix type extending itk::Matrix with additional constructors and utility methods.
Describes the data type of image pixels.
Describes the geometry of a plane object.
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 MITK_ERROR
Log an error message.
#define MITK_WARN
Log a warning message.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
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)
Fill a 3D array/vector with the given x, y, z values.
double ScalarType
Scalar type used throughout MITK for geometric computations.
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.