19 #include <vtkImageData.h>
20 #include <vtkPointData.h>
22 #include <vtkBitArray.h>
23 #include <vtkCharArray.h>
24 #include <vtkDoubleArray.h>
25 #include <vtkFloatArray.h>
26 #include <vtkIntArray.h>
27 #include <vtkLongArray.h>
28 #include <vtkShortArray.h>
29 #include <vtkUnsignedCharArray.h>
30 #include <vtkUnsignedIntArray.h>
31 #include <vtkUnsignedLongArray.h>
32 #include <vtkUnsignedShortArray.h>
41 unsigned int dimension,
45 : m_Data(static_cast<unsigned char *>(aParent.m_Data) + offset),
47 m_ManageMemory(false),
48 m_VtkImageData(nullptr),
49 m_VtkImageReadAccessor(nullptr),
50 m_VtkImageWriteAccessor(nullptr),
55 m_Dimension(dimension),
60 for (
unsigned int i = 0; i < dimension; i++)
62 m_Dimensions[i] = desc->GetDimensions()[i];
64 this->ComputeItemSize(m_Dimensions, dimension);
66 if (data !=
nullptr && data !=
m_Data)
71 delete[](
unsigned char *) data;
80 if (m_VtkImageData !=
nullptr)
82 m_VtkImageData->Delete();
85 if (m_VtkImageReadAccessor !=
nullptr)
87 delete m_VtkImageReadAccessor;
89 if (m_VtkImageWriteAccessor !=
nullptr)
91 delete m_VtkImageWriteAccessor;
94 if (m_Parent.IsNull())
106 : m_Data(static_cast<unsigned char *>(data)),
108 m_ManageMemory(manageMemory),
109 m_VtkImageData(nullptr),
110 m_VtkImageReadAccessor(nullptr),
111 m_VtkImageWriteAccessor(nullptr),
115 m_Dimension(desc->GetNumberOfDimensions()),
119 const unsigned int *dimensions = desc->GetDimensions();
120 for (
unsigned int i = 0; i < m_Dimension; i++)
122 m_Dimensions[i] = dimensions[i];
125 this->ComputeItemSize(m_Dimensions, m_Dimension);
129 m_Data = mitk::MemoryUtilities::AllocateElements<unsigned char>(
m_Size);
133 m_ReferenceCount = 0;
138 unsigned int dimension,
139 unsigned int *dimensions,
142 : m_Data(static_cast<unsigned char *>(data)),
144 m_ManageMemory(manageMemory),
145 m_VtkImageData(nullptr),
146 m_VtkImageReadAccessor(nullptr),
147 m_VtkImageWriteAccessor(nullptr),
152 m_Dimension(dimension),
155 for (
unsigned int i = 0; i < m_Dimension; i++)
157 m_Dimensions[i] = dimensions[i];
160 this->ComputeItemSize(dimensions, dimension);
164 m_Data = mitk::MemoryUtilities::AllocateElements<unsigned char>(
m_Size);
168 m_ReferenceCount = 0;
172 :
itk::LightObject(),
173 m_Data(other.m_Data),
175 m_ManageMemory(other.m_ManageMemory),
176 m_VtkImageData(nullptr),
177 m_VtkImageReadAccessor(nullptr),
178 m_VtkImageWriteAccessor(nullptr),
179 m_Offset(other.m_Offset),
180 m_IsComplete(other.m_IsComplete),
181 m_Size(other.m_Size),
182 m_Parent(other.m_Parent),
183 m_Dimension(other.m_Dimension),
184 m_Timestep(other.m_Timestep)
188 m_Dimensions[i] = other.m_Dimensions[i];
194 newGeometry->UnRegister();
195 return newGeometry.GetPointer();
198 void mitk::ImageDataItem::ComputeItemSize(
const unsigned int *dimensions,
unsigned int dimension)
200 m_Size = m_PixelType->GetSize();
201 for (
unsigned int i = 0; i < dimension; i++)
203 m_Size *= *(dimensions + i);
210 vtkDataArray *scalars =
nullptr;
212 const unsigned int *dims = m_Dimensions;
213 const unsigned int dim = m_Dimension;
215 unsigned long size = 0;
218 inData->SetDimensions(dims[0] - 1, 1, 1);
224 inData->SetDimensions(dims[0], dims[1], 1);
225 size = dims[0] * dims[1];
230 inData->SetDimensions(dims[0], dims[1], dims[2]);
231 size = dims[0] * dims[1] * dims[2];
234 inData->SetOrigin(0, 0, 0);
245 geom3d = iP->GetSlicedGeometry(m_Timestep);
248 double dspacing[3] = {vspacing[0], vspacing[1], vspacing[2]};
249 inData->SetSpacing(dspacing);
252 if (m_PixelType->GetComponentType() == itk::ImageIOBase::CHAR)
256 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::UCHAR)
260 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::SHORT)
264 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::USHORT)
268 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::INT)
272 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::UINT)
276 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::LONG)
280 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::ULONG)
284 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::FLOAT)
288 else if (m_PixelType->GetComponentType() == itk::ImageIOBase::DOUBLE)
298 m_VtkImageData = inData;
301 scalars->SetNumberOfComponents(m_PixelType->GetNumberOfComponents());
302 scalars->SetVoidArray(m_Data, size * m_PixelType->GetNumberOfComponents(), 1);
304 m_VtkImageData->GetPointData()->SetScalars(scalars);
311 m_VtkImageData->Modified();
316 if (m_VtkImageData ==
nullptr)
318 ConstructVtkImageData(iP);
320 if (m_VtkImageReadAccessor ==
nullptr)
324 return m_VtkImageReadAccessor;
329 if (m_VtkImageData ==
nullptr)
331 ConstructVtkImageData(iP.GetPointer());
333 if (m_VtkImageWriteAccessor ==
nullptr)
337 return m_VtkImageWriteAccessor;
itk::SmartPointer< Self > Pointer
ImageVtkReadAccessor * GetVtkImageAccessor(ImageConstPointer) const
GetVtkImageAccessor Returns a vtkImageDataItem, if none is present, a new one is constructed by the C...
DataCollection - Class to facilitate loading/accessing structured data.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
virtual itk::LightObject::Pointer InternalClone() const override
virtual void Modified() const
ImageDataItem(const ImageDataItem &aParent, const mitk::ImageDescriptor::Pointer desc, int timestep, unsigned int dimension, void *data=nullptr, bool manageMemory=false, vcl_size_t offset=0)
#define MAX_IMAGE_DIMENSIONS
Defines the maximum of 8 dimensions per image channel taken from ipPicDescriptor. ...
virtual void ConstructVtkImageData(ImageConstPointer) const
Describes the geometry of a data object consisting of slices.
ImageVtkReadAccessor class provides any image read access which is required by Vtk methods...
Internal class for managing references on sub-images.
ImageVtkWriteAccessor class provides any image write access which is required by Vtk methods...
Class for defining the data type of pixels.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.