27 #include <vtkImageData.h>
30 #include <itkMutexLockHolder.h>
35 #define FILL_C_ARRAY(_arr, _size, _value) \
36 for (unsigned int i = 0u; i < _size; i++) \
44 m_Dimensions(nullptr),
45 m_ImageDescriptor(nullptr),
46 m_OffsetTable(nullptr),
47 m_CompleteData(nullptr),
48 m_ImageStatistics(nullptr)
59 m_Dimensions(nullptr),
60 m_ImageDescriptor(nullptr),
61 m_OffsetTable(nullptr),
62 m_CompleteData(nullptr),
63 m_ImageStatistics(nullptr)
79 for (
unsigned int i = 0u; i < time_steps; ++i)
101 delete[] m_OffsetTable;
102 delete m_ImageStatistics;
107 return this->m_ImageDescriptor->GetChannelTypeById(n);
117 if ((i >= 0) && (i < (
int)m_Dimension))
118 return m_Dimensions[i];
124 if (m_Initialized ==
false)
126 if (GetSource().IsNull())
128 if (GetSource()->Updating() ==
false)
129 GetSource()->UpdateOutputInformation();
131 m_CompleteData = GetChannelData();
136 m_ImageDescriptor->GetChannelDescriptor(0).SetData(m_CompleteData->GetData());
138 return m_CompleteData->GetData();
150 value = (double)(((T *)data)[offset]);
154 const unsigned int rgboffset =
offset;
156 double returnvalue = (((T *)data)[rgboffset]);
157 returnvalue += (((T *)data)[rgboffset + 1]);
158 returnvalue += (((T *)data)[rgboffset + 2]);
166 if (this->GetTimeSteps() < timestep)
168 timestep = this->GetTimeSteps();
173 const unsigned int *imageDims = this->m_ImageDescriptor->GetDimensions();
174 const mitk::PixelType ptype = this->m_ImageDescriptor->GetChannelTypeById(0);
179 if (position[0] < 0 || position[1] < 0 || position[2] < 0)
181 MITK_WARN <<
"Given position (" << position <<
") is out of image range, returning 0.";
185 else if ((
unsigned int)position[0] >= imageDims[0] || (
unsigned int)position[1] >= imageDims[1] ||
186 (imageDims[2] && (
unsigned int)position[2] >= imageDims[2]))
188 MITK_WARN <<
"Given position (" << position <<
") is out of image range, returning 0.";
192 const unsigned int offset = component +
194 position[2] * imageDims[0] * imageDims[1] +
195 timestep * imageDims[0] * imageDims[1] * imageDims[2]);
204 unsigned int timestep,
205 unsigned int component)
208 if (this->GetTimeSteps() < timestep)
210 timestep = this->GetTimeSteps();
214 this->GetGeometry()->WorldToIndex(position, itkIndex);
216 value = this->GetPixelValueByIndex(itkIndex, timestep, component);
223 if (m_Initialized ==
false)
225 if (GetSource().IsNull())
227 if (GetSource()->Updating() ==
false)
228 GetSource()->UpdateOutputInformation();
231 return volume.GetPointer() ==
nullptr ?
nullptr : volume->GetVtkImageAccessor(
this)->GetVtkImageData();
236 if (m_Initialized ==
false)
238 if (GetSource().IsNull())
240 if (GetSource()->Updating() ==
false)
241 GetSource()->UpdateOutputInformation();
244 return volume.GetPointer() ==
nullptr ?
nullptr : volume->GetVtkImageAccessor(
this)->GetVtkImageData();
251 return GetSliceData_unlocked(s, t, n, data, importMemoryManagement);
255 int s,
int t,
int n,
void *data, ImportMemoryManagementType importMemoryManagement)
const
257 if (IsValidSlice(s, t, n) ==
false)
260 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
263 int pos = GetSliceIndex(s, t, n);
264 if (m_Slices[pos].GetPointer() !=
nullptr)
266 return m_Slices[pos];
270 ImageDataItemPointer sl, ch, vol;
271 vol = m_Volumes[GetVolumeIndex(t, n)];
272 if ((vol.GetPointer() !=
nullptr) && (vol->IsComplete()))
274 sl =
new ImageDataItem(*vol,
279 importMemoryManagement == ManageMemory,
280 ((
size_t)s) * m_OffsetTable[2] * (ptypeSize));
281 sl->SetComplete(
true);
282 return m_Slices[pos] = sl;
287 if ((ch.GetPointer() !=
nullptr) && (ch->IsComplete()))
289 sl =
new ImageDataItem(*ch,
294 importMemoryManagement == ManageMemory,
295 (((
size_t)s) * m_OffsetTable[2] + ((
size_t)t) * m_OffsetTable[3]) * (ptypeSize));
296 sl->SetComplete(
true);
297 return m_Slices[pos] = sl;
301 if ((GetSource().IsNotNull()) && (GetSource()->Updating() ==
false))
304 m_RequestedRegion.SetIndex(0, 0);
305 m_RequestedRegion.SetIndex(1, 0);
306 m_RequestedRegion.SetIndex(2, s);
307 m_RequestedRegion.SetIndex(3, t);
308 m_RequestedRegion.SetIndex(4, n);
309 m_RequestedRegion.SetSize(0, m_Dimensions[0]);
310 m_RequestedRegion.SetSize(1, m_Dimensions[1]);
311 m_RequestedRegion.SetSize(2, 1);
312 m_RequestedRegion.SetSize(3, 1);
313 m_RequestedRegion.SetSize(4, 1);
314 m_RequestedRegionInitialized =
true;
315 GetSource()->Update();
316 if (IsSliceSet_unlocked(s, t, n))
318 return GetSliceData_unlocked(s, t, n, data, importMemoryManagement);
324 ImageDataItemPointer item = AllocateSliceData_unlocked(s, t, n, data, importMemoryManagement);
325 item->SetComplete(
true);
336 return GetVolumeData_unlocked(t, n, data, importMemoryManagement);
339 int t,
int n,
void *data, ImportMemoryManagementType importMemoryManagement)
const
341 if (IsValidVolume(t, n) ==
false)
344 ImageDataItemPointer ch, vol;
347 int pos = GetVolumeIndex(t, n);
348 vol = m_Volumes[pos];
349 if ((vol.GetPointer() !=
nullptr) && (vol->IsComplete()))
352 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
356 if ((ch.GetPointer() !=
nullptr) && (ch->IsComplete()))
363 importMemoryManagement == ManageMemory,
364 (((
size_t)t) * m_OffsetTable[3]) * (ptypeSize));
365 vol->SetComplete(
true);
366 return m_Volumes[pos] = vol;
370 bool complete =
true;
372 for (s = 0; s < m_Dimensions[2]; ++s)
374 if (m_Slices[GetSliceIndex(s, t, n)].GetPointer() ==
nullptr)
383 if (m_Dimensions[2] <= 1)
385 ImageDataItemPointer sl;
386 sl = GetSliceData_unlocked(0, t, n, data, importMemoryManagement);
387 vol =
new ImageDataItem(*sl, m_ImageDescriptor, t, 3, data, importMemoryManagement == ManageMemory);
388 vol->SetComplete(
true);
392 mitk::PixelType chPixelType = this->m_ImageDescriptor->GetChannelTypeById(n);
394 vol = m_Volumes[pos];
396 if (vol.GetPointer() ==
nullptr)
398 vol =
new ImageDataItem(chPixelType, t, 3, m_Dimensions,
nullptr,
true);
400 vol->SetComplete(
true);
401 size_t size = m_OffsetTable[2] * (ptypeSize);
402 for (s = 0; s < m_Dimensions[2]; ++s)
405 ImageDataItemPointer sl;
406 posSl = GetSliceIndex(s, t, n);
408 sl = m_Slices[posSl];
409 if (sl->GetParent() != vol)
412 size_t offset = ((size_t)s) * size;
413 std::memcpy(static_cast<char *>(vol->GetData()) + offset, sl->GetData(), size);
418 sl =
new ImageDataItem(
419 *vol, m_ImageDescriptor, t, 2, data, importMemoryManagement == ManageMemory, ((
size_t)s) * size);
420 sl->SetComplete(
true);
422 m_Slices[posSl] = sl;
428 return m_Volumes[pos] = vol;
432 if ((GetSource().IsNotNull()) && (GetSource()->Updating() ==
false))
435 m_RequestedRegion.SetIndex(0, 0);
436 m_RequestedRegion.SetIndex(1, 0);
437 m_RequestedRegion.SetIndex(2, 0);
438 m_RequestedRegion.SetIndex(3, t);
439 m_RequestedRegion.SetIndex(4, n);
440 m_RequestedRegion.SetSize(0, m_Dimensions[0]);
441 m_RequestedRegion.SetSize(1, m_Dimensions[1]);
442 m_RequestedRegion.SetSize(2, m_Dimensions[2]);
443 m_RequestedRegion.SetSize(3, 1);
444 m_RequestedRegion.SetSize(4, 1);
445 m_RequestedRegionInitialized =
true;
446 GetSource()->Update();
447 if (IsVolumeSet_unlocked(t, n))
449 return GetVolumeData_unlocked(t, n, data, importMemoryManagement);
455 ImageDataItemPointer item = AllocateVolumeData_unlocked(t, n, data, importMemoryManagement);
456 item->SetComplete(
true);
466 return GetChannelData_unlocked(n, data, importMemoryManagement);
470 int n,
void *data, ImportMemoryManagementType importMemoryManagement)
const
472 if (IsValidChannel(n) ==
false)
474 ImageDataItemPointer ch, vol;
476 if ((ch.GetPointer() !=
nullptr) && (ch->IsComplete()))
480 if (IsChannelSet_unlocked(n))
483 if (m_Dimensions[3] <= 1)
485 vol = GetVolumeData_unlocked(0, n, data, importMemoryManagement);
489 m_ImageDescriptor->GetNumberOfDimensions(),
491 importMemoryManagement == ManageMemory);
496 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
500 if (ch.GetPointer() ==
nullptr)
501 ch =
new ImageDataItem(this->m_ImageDescriptor, -1,
nullptr,
true);
502 ch->SetComplete(
true);
503 size_t size = m_OffsetTable[m_Dimension - 1] * (ptypeSize);
505 auto slicesIt = m_Slices.begin() + n * m_Dimensions[2] * m_Dimensions[3];
506 for (t = 0; t < m_Dimensions[3]; ++t)
509 ImageDataItemPointer vol;
511 posVol = GetVolumeIndex(t, n);
512 vol = GetVolumeData_unlocked(t, n, data, importMemoryManagement);
514 if (vol->GetParent() != ch)
517 size_t offset = ((size_t)t) * m_OffsetTable[3] * (ptypeSize);
518 std::memcpy(static_cast<char *>(ch->GetData()) + offset, vol->GetData(), size);
523 vol =
new ImageDataItem(*ch, m_ImageDescriptor, t, 3, data, importMemoryManagement == ManageMemory, offset);
524 vol->SetComplete(
true);
527 m_Volumes[posVol] = vol;
530 ImageDataItemPointer dnull =
nullptr;
531 for (
unsigned int i = 0; i < m_Dimensions[2]; ++i, ++slicesIt)
533 assert(slicesIt != m_Slices.end());
542 return m_Channels[n] = ch;
546 if ((GetSource().IsNotNull()) && (GetSource()->Updating() ==
false))
549 m_RequestedRegion.SetIndex(0, 0);
550 m_RequestedRegion.SetIndex(1, 0);
551 m_RequestedRegion.SetIndex(2, 0);
552 m_RequestedRegion.SetIndex(3, 0);
553 m_RequestedRegion.SetIndex(4, n);
554 m_RequestedRegion.SetSize(0, m_Dimensions[0]);
555 m_RequestedRegion.SetSize(1, m_Dimensions[1]);
556 m_RequestedRegion.SetSize(2, m_Dimensions[2]);
557 m_RequestedRegion.SetSize(3, m_Dimensions[3]);
558 m_RequestedRegion.SetSize(4, 1);
559 m_RequestedRegionInitialized =
true;
560 GetSource()->Update();
562 if (IsChannelSet_unlocked(n))
564 return GetChannelData_unlocked(n, data, importMemoryManagement);
570 ImageDataItemPointer item = AllocateChannelData_unlocked(n, data, importMemoryManagement);
571 item->SetComplete(
true);
579 return IsSliceSet_unlocked(s, t, n);
582 bool mitk::Image::IsSliceSet_unlocked(
int s,
int t,
int n)
const
584 if (IsValidSlice(s, t, n) ==
false)
587 if (m_Slices[GetSliceIndex(s, t, n)].GetPointer() !=
nullptr)
592 ImageDataItemPointer ch, vol;
593 vol = m_Volumes[GetVolumeIndex(t, n)];
594 if ((vol.GetPointer() !=
nullptr) && (vol->IsComplete()))
599 if ((ch.GetPointer() !=
nullptr) && (ch->IsComplete()))
609 return IsVolumeSet_unlocked(t, n);
612 bool mitk::Image::IsVolumeSet_unlocked(
int t,
int n)
const
614 if (IsValidVolume(t, n) ==
false)
616 ImageDataItemPointer ch, vol;
619 vol = m_Volumes[GetVolumeIndex(t, n)];
620 if ((vol.GetPointer() !=
nullptr) && (vol->IsComplete()))
625 if ((ch.GetPointer() !=
nullptr) && (ch->IsComplete()))
630 for (s = 0; s < m_Dimensions[2]; ++s)
632 if (m_Slices[GetSliceIndex(s, t, n)].GetPointer() ==
nullptr)
643 return IsChannelSet_unlocked(n);
646 bool mitk::Image::IsChannelSet_unlocked(
int n)
const
648 if (IsValidChannel(n) ==
false)
650 ImageDataItemPointer ch, vol;
652 if ((ch.GetPointer() !=
nullptr) && (ch->IsComplete()))
657 for (t = 0; t < m_Dimensions[3]; ++t)
659 if (IsVolumeSet_unlocked(t, n) ==
false)
670 return SetImportSlice(const_cast<void *>(data), s, t, n, CopyMemory);
676 return SetImportVolume(const_cast<void *>(data), t, n, CopyMemory);
682 return SetImportChannel(const_cast<void *>(data), n, CopyMemory);
687 if (IsValidSlice(s, t, n) ==
false)
690 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
692 if (IsSliceSet(s, t, n))
694 sl = GetSliceData(s, t, n, data, importMemoryManagement);
695 if (sl->GetManageMemory() ==
false)
697 sl = AllocateSliceData(s, t, n, data, importMemoryManagement);
698 if (sl.GetPointer() ==
nullptr)
701 if (sl->GetData() != data)
702 std::memcpy(sl->GetData(), data, m_OffsetTable[2] * (ptypeSize));
709 sl = AllocateSliceData(s, t, n, data, importMemoryManagement);
710 if (sl.GetPointer() ==
nullptr)
712 if (sl->GetData() != data)
713 std::memcpy(sl->GetData(), data, m_OffsetTable[2] * (ptypeSize));
722 if (IsValidVolume(t, n) ==
false)
725 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
727 if (IsVolumeSet(t, n))
729 vol = GetVolumeData(t, n, data, importMemoryManagement);
730 if (vol->GetManageMemory() ==
false)
732 vol = AllocateVolumeData(t, n, data, importMemoryManagement);
733 if (vol.GetPointer() ==
nullptr)
736 if (vol->GetData() != data)
737 std::memcpy(vol->GetData(), data, m_OffsetTable[3] * (ptypeSize));
739 vol->SetComplete(
true);
745 vol = AllocateVolumeData(t, n, data, importMemoryManagement);
746 if (vol.GetPointer() ==
nullptr)
748 if (vol->GetData() != data)
750 std::memcpy(vol->GetData(), data, m_OffsetTable[3] * (ptypeSize));
752 vol->SetComplete(
true);
753 this->m_ImageDescriptor->GetChannelDescriptor(n).SetData(vol->GetData());
762 if (IsValidChannel(n) ==
false)
767 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
772 ch = GetChannelData(n, data, importMemoryManagement);
773 if (ch->GetManageMemory() ==
false)
775 ch = AllocateChannelData(n, data, importMemoryManagement);
776 if (ch.GetPointer() ==
nullptr)
779 if (ch->GetData() != data)
780 std::memcpy(ch->GetData(), data, m_OffsetTable[4] * (ptypeSize));
782 ch->SetComplete(
true);
788 ch = AllocateChannelData(n, data, importMemoryManagement);
789 if (ch.GetPointer() ==
nullptr)
791 if (ch->GetData() != data)
792 std::memcpy(ch->GetData(), data, m_OffsetTable[4] * (ptypeSize));
793 ch->SetComplete(
true);
795 this->m_ImageDescriptor->GetChannelDescriptor(n).SetData(ch->GetData());
804 ImageDataItemPointerArray::iterator it, end;
805 for (it = m_Slices.begin(), end = m_Slices.end(); it != end; ++it)
809 for (it = m_Volumes.begin(), end = m_Volumes.end(); it != end; ++it)
813 for (it = m_Channels.begin(), end = m_Channels.end(); it != end; ++it)
817 m_CompleteData =
nullptr;
819 if (m_ImageStatistics ==
nullptr)
824 SetRequestedRegionToLargestPossibleRegion();
830 this->m_ImageDescriptor = inDesc;
834 inDesc->GetChannelDescriptor(0).GetPixelType(), inDesc->GetNumberOfDimensions(), inDesc->GetDimensions(), 1);
838 unsigned int dimension,
839 const unsigned int *dimensions,
840 unsigned int channels)
844 m_Dimension = dimension;
847 itkExceptionMacro(<<
"invalid zero dimension image");
850 for (i = 0; i < dimension; ++i)
852 if (dimensions[i] < 1)
853 itkExceptionMacro(<<
"invalid dimension[" << i <<
"]: " << dimensions[i]);
864 std::memcpy(m_Dimensions, dimensions,
sizeof(
unsigned int) * m_Dimension);
867 this->m_ImageDescriptor->Initialize(this->m_Dimensions, this->m_Dimension);
869 for (i = 0; i < 4; ++i)
871 m_LargestPossibleRegion.SetIndex(i, 0);
872 m_LargestPossibleRegion.SetSize(i, m_Dimensions[i]);
874 m_LargestPossibleRegion.SetIndex(i, 0);
875 m_LargestPossibleRegion.SetSize(i, channels);
877 if (m_LargestPossibleRegion.GetNumberOfPixels() == 0)
879 delete[] m_Dimensions;
880 m_Dimensions =
nullptr;
884 for (
unsigned int i = 0u; i < channels; i++)
886 this->m_ImageDescriptor->AddNewChannel(type);
890 planegeometry->InitializeStandardPlane(m_Dimensions[0], m_Dimensions[1]);
893 slicedGeometry->InitializeEvenlySpaced(planegeometry, m_Dimensions[2]);
896 timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
897 for (
TimeStepType step = 0; step < timeGeometry->CountTimeSteps(); ++step)
899 timeGeometry->GetGeometryForTimeStep(step)->ImageGeometryOn();
901 SetTimeGeometry(timeGeometry);
905 m_Channels.assign(GetNumberOfChannels(), dnull);
907 m_Volumes.assign(GetNumberOfChannels() * m_Dimensions[3], dnull);
909 m_Slices.assign(GetNumberOfChannels() * m_Dimensions[3] * m_Dimensions[2], dnull);
911 ComputeOffsetTable();
915 m_Initialized =
true;
920 unsigned int channels,
924 timeGeometry->Initialize(geometry.
Clone(), tDim);
925 this->Initialize(type, *timeGeometry, channels, tDim);
930 unsigned int channels,
933 unsigned int dimensions[5];
937 dimensions[3] = (tDim > 0) ? tDim : geometry.CountTimeSteps();
940 unsigned int dimension = 2;
941 if (dimensions[2] > 1)
943 if (dimensions[3] > 1)
946 Initialize(type, dimension, dimensions, channels);
947 if (geometry.CountTimeSteps() > 1)
950 SetTimeGeometry(cloned.GetPointer());
953 for (
TimeStepType step = 0; step < cloned->CountTimeSteps(); ++step)
955 if (!cloned->GetGeometryCloneForTimeStep(step)->GetImageGeometry())
957 MITK_WARN(
"Image.3DnT.Initialize") <<
" Attempt to initialize an image with a non-image geometry. "
958 "Re-interpretting the initialization geometry for timestep "
959 << step <<
" as image geometry, the original geometry remains unchanged.";
960 cloned->GetGeometryForTimeStep(step)->ImageGeometryOn();
968 if (!cloned->GetImageGeometry())
970 MITK_WARN(
"Image.Initialize") <<
" Attempt to initialize an image with a non-image geometry. Re-interpretting "
971 "the initialization geometry as image geometry, the original geometry remains "
973 cloned->ImageGeometryOn();
976 Superclass::SetGeometry(cloned);
1006 mitkThrow() <<
"Use this method without the flipped parameter (direction is specified by the handedness of the PlaneGeometry instead).";
1012 unsigned int channels,
1016 slicedGeometry->InitializeEvenlySpaced(geometry2d.
Clone(), sDim);
1017 Initialize(type, *slicedGeometry, channels, tDim);
1027 if (vtkimagedata ==
nullptr)
1030 m_Dimension = vtkimagedata->GetDataDimension();
1031 unsigned int i, *tmpDimensions =
new unsigned int[m_Dimension > 4 ? m_Dimension : 4];
1032 for (i = 0; i < m_Dimension; ++i)
1033 tmpDimensions[i] = vtkimagedata->GetDimensions()[i];
1034 if (m_Dimension < 4)
1037 for (i = 0, p = tmpDimensions + m_Dimension; i < 4 - m_Dimension; ++i, ++p)
1043 tmpDimensions[1] = pDim;
1044 if (m_Dimension < 2)
1049 tmpDimensions[2] = sDim;
1050 if (m_Dimension < 3)
1055 tmpDimensions[3] = tDim;
1056 if (m_Dimension < 4)
1061 Initialize(pixelType, m_Dimension, tmpDimensions, channels);
1063 const double *spacinglist = vtkimagedata->GetSpacing();
1066 if (m_Dimension >= 2)
1067 spacing[1] = spacinglist[1];
1068 if (m_Dimension >= 3)
1069 spacing[2] = spacinglist[2];
1073 double vtkorigin[3];
1074 vtkimagedata->GetOrigin(vtkorigin);
1076 if (m_Dimension >= 2)
1077 origin[1] = vtkorigin[1];
1078 if (m_Dimension >= 3)
1079 origin[2] = vtkorigin[2];
1092 timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
1093 SetTimeGeometry(timeGeometry);
1095 delete[] tmpDimensions;
1101 return ((s >= 0) && (s < (
int)m_Dimensions[2]) && (t >= 0) && (t < (
int)m_Dimensions[3]) && (n >= 0) &&
1102 (n < (
int)GetNumberOfChannels()));
1110 return IsValidSlice(0, t, n);
1118 return IsValidSlice(0, 0, n);
1125 if (m_OffsetTable !=
nullptr)
1126 delete[] m_OffsetTable;
1128 m_OffsetTable =
new size_t[m_Dimension > 4 ? m_Dimension + 1 : 4 + 1];
1132 m_OffsetTable[0] = 1;
1133 for (i = 0; i < m_Dimension; ++i)
1135 num *= m_Dimensions[i];
1136 m_OffsetTable[i + 1] = num;
1139 m_OffsetTable[i + 1] = num;
1144 return ((m_Dimension >= 4 && t <= (
int)m_Dimensions[3] && t > 0) || (t == 0));
1150 itkExceptionMacro(<<
"Invalid timestep in Image!");
1151 Superclass::Expand(timeSteps);
1156 if (IsValidSlice(s, t, n) ==
false)
1158 return ((
size_t)s) + ((size_t)t) * m_Dimensions[2] + ((size_t)n) * m_Dimensions[3] * m_Dimensions[2];
1163 if (IsValidVolume(t, n) ==
false)
1165 return ((
size_t)t) + ((size_t)n) * m_Dimensions[3];
1172 return AllocateSliceData_unlocked(s, t, n, data, importMemoryManagement);
1176 int s,
int t,
int n,
void *data, ImportMemoryManagementType importMemoryManagement)
const
1179 pos = GetSliceIndex(s, t, n);
1181 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
1184 ImageDataItemPointer sl, ch, vol;
1185 vol = m_Volumes[GetVolumeIndex(t, n)];
1186 if (vol.GetPointer() !=
nullptr)
1193 importMemoryManagement == ManageMemory,
1194 ((
size_t)s) * m_OffsetTable[2] * (ptypeSize));
1195 sl->SetComplete(
true);
1196 return m_Slices[pos] = sl;
1201 if (ch.GetPointer() !=
nullptr)
1203 sl =
new ImageDataItem(*ch,
1208 importMemoryManagement == ManageMemory,
1209 (((
size_t)s) * m_OffsetTable[2] + ((
size_t)t) * m_OffsetTable[3]) * (ptypeSize));
1210 sl->SetComplete(
true);
1211 return m_Slices[pos] = sl;
1215 m_Volumes[GetVolumeIndex(t, n)] = vol = AllocateVolumeData_unlocked(t, n,
nullptr, importMemoryManagement);
1216 sl =
new ImageDataItem(*vol,
1221 importMemoryManagement == ManageMemory,
1222 ((
size_t)s) * m_OffsetTable[2] * (ptypeSize));
1223 sl->SetComplete(
true);
1224 return m_Slices[pos] = sl;
1237 return AllocateVolumeData_unlocked(t, n, data, importMemoryManagement);
1241 int t,
int n,
void *data, ImportMemoryManagementType importMemoryManagement)
const
1244 pos = GetVolumeIndex(t, n);
1246 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
1249 ImageDataItemPointer ch, vol;
1251 if (ch.GetPointer() !=
nullptr)
1258 importMemoryManagement == ManageMemory,
1259 (((
size_t)t) * m_OffsetTable[3]) * (ptypeSize));
1260 return m_Volumes[pos] = vol;
1263 mitk::PixelType chPixelType = this->m_ImageDescriptor->GetChannelTypeById(n);
1266 if (importMemoryManagement == CopyMemory)
1268 vol =
new ImageDataItem(chPixelType, t, 3, m_Dimensions,
nullptr,
true);
1269 if (data !=
nullptr)
1270 std::memcpy(vol->GetData(), data, m_OffsetTable[3] * (ptypeSize));
1274 vol =
new ImageDataItem(chPixelType, t, 3, m_Dimensions, data, importMemoryManagement == ManageMemory);
1276 m_Volumes[pos] = vol;
1284 return AllocateChannelData_unlocked(n, data, importMemoryManagement);
1288 int n,
void *data, ImportMemoryManagementType importMemoryManagement)
const
1290 ImageDataItemPointer ch;
1292 if (importMemoryManagement == CopyMemory)
1294 const size_t ptypeSize = this->m_ImageDescriptor->GetChannelTypeById(n).GetSize();
1296 ch =
new ImageDataItem(this->m_ImageDescriptor, -1,
nullptr,
true);
1297 if (data !=
nullptr)
1298 std::memcpy(ch->GetData(), data, m_OffsetTable[4] * (ptypeSize));
1302 ch =
new ImageDataItem(this->m_ImageDescriptor, -1, data, importMemoryManagement == ManageMemory);
1310 return m_Dimensions;
1315 Superclass::Clear();
1316 delete[] m_Dimensions;
1317 m_Dimensions =
nullptr;
1326 MITK_INFO <<
"WARNING: Applied a non-image geometry onto an image. Please be SURE that this geometry is "
1327 "pixel-center-based! If it is not, you need to call "
1328 "Geometry3D->ChangeImageGeometryConsideringOriginOffset(true) before calling image->setGeometry(..)\n";
1330 Superclass::SetGeometry(aGeometry3D);
1331 for (
TimeStepType step = 0; step < GetTimeGeometry()->CountTimeSteps(); ++step)
1332 GetTimeGeometry()->GetGeometryForTimeStep(step)->ImageGeometryOn();
1340 os << indent <<
" Dimension: " << m_Dimension << std::endl;
1341 os << indent <<
" Dimensions: ";
1342 for (i = 0; i < m_Dimension; ++i)
1343 os << GetDimension(i) <<
" ";
1346 for (
unsigned int ch = 0; ch < this->m_ImageDescriptor->GetNumberOfChannels(); ch++)
1348 mitk::PixelType chPixelType = this->m_ImageDescriptor->GetChannelTypeById(ch);
1350 os << indent <<
" Channel: " << this->m_ImageDescriptor->GetChannelName(ch) << std::endl;
1352 os << indent <<
" BytesPerElement: " << chPixelType.
GetSize() << std::endl;
1360 os << indent <<
" Image not initialized: m_Initialized: false" << std::endl;
1363 Superclass::PrintSelf(os, indent);
1375 for (
short k = 0; k < 3; ++k)
1379 for (
short i = 0; i < 3; ++i)
1381 for (
short j = 0; j < 3; ++j)
1385 if (std::abs(mx[i][j]) > ref)
1396 return m_ImageStatistics->GetScalarValueMin(t);
1402 return m_ImageStatistics->GetScalarValueMax(t);
1408 return m_ImageStatistics->GetScalarValue2ndMin(t);
1413 return m_ImageStatistics->GetScalarValueMinNoRecompute(t);
1418 return m_ImageStatistics->GetScalarValue2ndMinNoRecompute(t);
1423 return m_ImageStatistics->GetScalarValue2ndMax(t);
1428 return m_ImageStatistics->GetScalarValueMaxNoRecompute(t);
1433 return m_ImageStatistics->GetScalarValue2ndMaxNoRecompute(t);
1438 return m_ImageStatistics->GetCountOfMinValuedVoxels(t);
1443 return m_ImageStatistics->GetCountOfMaxValuedVoxels(t);
1448 return m_ImageStatistics->GetCountOfMaxValuedVoxelsNoRecompute(t);
1453 return m_ImageStatistics->GetCountOfMinValuedVoxelsNoRecompute(t);
1458 if ((leftHandSide ==
nullptr) || (rightHandSide ==
nullptr))
1460 MITK_ERROR <<
"mitk::Equal(const mitk::Image* leftHandSide, const mitk::Image* rightHandSide, ScalarType eps, bool "
1461 "verbose) does not work with NULL pointer input.";
1464 return mitk::Equal(*leftHandSide, *rightHandSide, eps, verbose);
1469 bool returnValue =
true;
1476 MITK_INFO <<
"[( Image )] Dimensionality differs.";
1480 returnValue =
false;
1485 for (
unsigned int i = 0; i < minDimensionality; ++i)
1489 returnValue =
false;
1492 MITK_INFO <<
"[( Image )] dimension differs.";
1494 <<
"rightHandSide->GetDimension(" << i <<
") is " << rightHandSide.
GetDimension(i);
1502 if (!(pixelTypeRightHandSide == pixelTypeLeftHandSide))
1506 MITK_INFO <<
"[( Image )] PixelType differs.";
1510 returnValue =
false;
1518 MITK_INFO <<
"[( Image )] Geometries differ.";
1520 returnValue =
false;
1529 compareFilter->SetInput(0, &rightHandSide);
1530 compareFilter->SetInput(1, &leftHandSide);
1531 compareFilter->SetTolerance(eps);
1532 compareFilter->Update();
1534 if ((!compareFilter->GetResult()))
1536 returnValue =
false;
1539 MITK_INFO <<
"[(Image)] Pixel values differ: ";
1540 compareFilter->GetCompareResults().PrintSelf();
virtual bool IsChannelSet(int n=0) const override
Check whether the channel n is set.
unsigned int * m_Dimensions
std::string GetTypeAsString() const
Returns a string representing the pixel type and pixel components.
ScalarType GetScalarValueMin(int t=0) const
(DEPRECATED) Get the minimum for scalar images
virtual BaseGeometry::Pointer GetGeometryCloneForTimeStep(TimeStepType timeStep) const =0
Returns a clone of the geometry of a specific time point.
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 SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
void SetComplete(bool complete)
virtual void Initialize() override
ScalarType GetCountOfMaxValuedVoxels(int t=0) const
(DEPRECATED) Get the count of voxels with the largest scalar value in the dataset ...
std::string GetPixelTypeAsString() const
Returns a string containing the ITK pixel type name.
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...
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 ...
virtual bool IsVolumeSet(int t=0, int n=0) const override
Check whether volume at time t in channel n is set.
virtual bool IsSliceSet(int s=0, int t=0, int n=0) const override
Get the complete image, i.e., all channels linked together, as a mitkIpPicDescriptor.
virtual void SetTimeGeometry(TimeGeometry *geometry)
Set the TimeGeometry of the data, which will be referenced (not copied!).
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 ...
ScalarType GetScalarValue2ndMax(int t=0) const
(DEPRECATED) Get the second largest value for scalar images
ScalarType GetCountOfMinValuedVoxels(int t=0) const
(DEPRECATED) Get the count of voxels with the smallest scalar value in the dataset ...
virtual bool IsValidTimeStep(int t) const
ImportMemoryManagementType
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time t of channel n as a vtkImageData.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
vcl_size_t GetBitsPerComponent() const
Get the number of bits per components.
virtual ImageDataItemPointer GetVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
virtual void SetGeometry(BaseGeometry *aGeometry3D) override
Sets a geometry to an image.
virtual ImageDataItemPointer GetChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
void AccessPixel(const mitk::PixelType ptype, void *data, const unsigned int offset, double &value)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual ImageDataItemPointer AllocateSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
virtual ImageDataItemPointer GetSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
ScalarType GetScalarValue2ndMin(int t=0) const
(DEPRECATED) Get the second smallest value for scalar images
vcl_size_t GetSize() const
Get size of the PixelType in bytes.
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...
T::Pointer GetData(const std::string &name)
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 ...
virtual ImageDataItemPointer AllocateChannelData(int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
ScalarType GetScalarValue2ndMaxNoRecompute(unsigned int t=0) const
(DEPRECATED) Get the second largest value for scalar images, but do not recompute it first ...
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
int GetSliceIndex(int s=0, int t=0, int n=0) const
double GetPixelValueByWorldCoordinate(const mitk::Point3D &position, unsigned int timestep=0, unsigned int component=0)
Get the pixel value at one specific world position.
MITKCORE_EXPORT mitk::PixelType MakePixelType(vtkImageData *vtkimagedata)
deduct the PixelType for a given vtk image
unsigned int * GetDimensions() const
Get the sizes of all dimensions as an integer-array.
std::string GetComponentTypeAsString() const
Returns a string containing the name of the component.
virtual void Clear() override
Calls ClearData() and InitializeEmpty();.
#define mitkPixelTypeMultiplex3(function, ptype, param1, param2, param3)
Super class of data objects consisting of slices.
#define MAX_IMAGE_DIMENSIONS
Defines the maximum of 8 dimensions per image channel taken from ipPicDescriptor. ...
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
Image class for storing images.
virtual mitk::PlaneGeometry * GetPlaneGeometry(int s) const
Returns the PlaneGeometry of the slice (s).
#define FILL_C_ARRAY(_arr, _size, _value)
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 AllocateVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
ScalarType GetScalarValueMaxNoRecompute(unsigned int t=0) const
(DEPRECATED) Get the largest value for scalar images, but do not recompute it first ...
double GetPixelValueByIndex(const itk::Index< 3 > &position, unsigned int timestep=0, unsigned int component=0)
Get the pixel value at one specific index position.
std::vcl_size_t TimeStepType
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
Describes the geometry of a data object consisting of slices.
ScalarType GetScalarValue2ndMinNoRecompute(unsigned int t=0) const
(DEPRECATED) Get the second smallest value for scalar images, but do not recompute it first ...
bool IsRotated() const
Returns true if an image is rotated, i.e. its geometry's transformation matrix has nonzero elements b...
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 ...
Class holding the statistics informations about a single mitk::Image.
virtual void * GetData()
Get the data vector of the complete image, i.e., of all channels linked together. ...
unsigned int GetCountOfMinValuedVoxelsNoRecompute(unsigned int t=0) const
(DEPRECATED) Get the count of voxels with the smallest scalar value in the dataset ...
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.
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
virtual void Expand(unsigned int timeSteps) override
Expands the TimeGeometry to a number of TimeSteps.
MITKCORE_EXPORT const ScalarType eps
unsigned int GetCountOfMaxValuedVoxelsNoRecompute(unsigned int t=0) const
(DEPRECATED) Get the count of voxels with the largest scalar value in the dataset ...
void ComputeOffsetTable()
Describes a two-dimensional, rectangular plane.
int GetVolumeIndex(int t=0, int n=0) const
Internal class for managing references on sub-images.
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...
unsigned int GetDimension() const
Get dimension of the image.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
ScalarType GetScalarValueMinNoRecompute(unsigned int t=0) const
(DEPRECATED) Get the smallest value for scalar images, but do not recompute it first ...
virtual bool GetImageGeometry() const
Is this an ImageGeometry?
BaseGeometry Describes the geometry of a data object.
ScalarType GetScalarValueMax(int t=0) const
(DEPRECATED) Get the maximum for scalar images
Class for defining the data type of pixels.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.