33 #include "vtkDataSetAttributes.h"
34 #include "vtkGarbageCollector.h"
35 #include "vtkImageData.h"
36 #include "vtkImageStencilData.h"
37 #include "vtkInformation.h"
38 #include "vtkInformationVector.h"
40 #include "vtkObjectFactory.h"
41 #include "vtkStreamingDemandDrivenPipeline.h"
42 #include "vtkTransform.h"
44 #include "vtkTemplateAliasMacro.h"
47 #define VTK_USE_INT64 0
49 #define VTK_USE_UINT64 0
63 #if defined mips || defined sparc || defined __ppc__
65 unsigned int i =
static_cast<unsigned int>(x);
67 return static_cast<int>(i - 2147483648U);
68 #elif defined i386 || defined _M_IX86
74 dual.d = x + 103079215104.0;
75 f = dual.s[0] * 0.0000152587890625;
76 return static_cast<int>((dual.i[1] << 16) | ((dual.i[0]) >> 16));
77 #elif defined ia64 || defined __ia64__ || defined IA64
79 long long i =
static_cast<long long>(x);
81 return static_cast<int>(i - 103079215104LL);
85 return static_cast<int>(y);
91 #if defined mips || defined sparc || defined __ppc__
92 return static_cast<int>(
static_cast<unsigned int>(x + 2147483648.5) - 2147483648U);
93 #elif defined i386 || defined _M_IX86
98 dual.d = x + 103079215104.5;
99 return static_cast<int>((dual.i[1] << 16) | ((dual.i[0]) >> 16));
100 #elif defined ia64 || defined __ia64__ || defined IA64
102 long long i =
static_cast<long long>(x);
103 return static_cast<int>(i - 103079215104LL);
105 return static_cast<int>(floor(x + 0.5));
113 this->GetOutput()->AllocateScalars(VTK_UNSIGNED_INT, 1);
124 #define VTK_RESLICE_BACKGROUND 0 // use background if out-of-bounds
125 #define VTK_RESLICE_WRAP 1 // wrap to opposite side of image
126 #define VTK_RESLICE_MIRROR 2 // mirror off of the boundary
127 #define VTK_RESLICE_BORDER 3 // use a half-voxel border
128 #define VTK_RESLICE_NULL 4 // do nothing to *outPtr if out-of-bounds
133 #if (VTK_USE_INT8 != 0)
141 #if (VTK_USE_UINT8 != 0)
149 #if (VTK_USE_INT16 != 0)
157 #if (VTK_USE_UINT16 != 0)
165 #if (VTK_USE_INT32 != 0)
173 #if (VTK_USE_UINT32 != 0)
181 #if (VTK_USE_FLOAT32 != 0)
189 #if (VTK_USE_FLOAT64 != 0)
200 #if (VTK_USE_INT8 != 0)
202 inline void vtkResliceClamp(F val, vtkTypeInt8 &clamp)
216 #if (VTK_USE_UINT8 != 0)
218 inline void vtkResliceClamp(F val, vtkTypeUInt8 &clamp)
232 #if (VTK_USE_INT16 != 0)
234 inline void vtkResliceClamp(F val, vtkTypeInt16 &clamp)
248 #if (VTK_USE_UINT16 != 0)
250 inline void vtkResliceClamp(F val, vtkTypeUInt16 &clamp)
264 #if (VTK_USE_INT32 != 0)
266 inline void vtkResliceClamp(F val, vtkTypeInt32 &clamp)
268 if (val < -2147483648.0)
272 if (val > 2147483647.0)
280 #if (VTK_USE_UINT32 != 0)
282 inline void vtkResliceClamp(F val, vtkTypeUInt32 &clamp)
288 if (val > 4294967295.0)
296 #if (VTK_USE_FLOAT32 != 0)
298 inline void vtkResliceClamp(F val, vtkTypeFloat32 &clamp)
304 #if (VTK_USE_FLOAT64 != 0)
306 inline void vtkResliceClamp(F val, vtkTypeFloat64 &clamp)
318 if ((num %= range) < 0)
334 int count = num / range;
338 num = range - num - 1;
349 if (inIdX0 >= 0 && inIdX1 < inExtX)
353 if (inIdX0 == -1 && fx >= 0.5)
358 if (inIdX0 == inExtX - 1 && fx < 0.5)
369 if ((inIdX0 >= 0 && inIdX1 < inExtX) || (inIdX0 == -1 && fx >= 0.5) || (inIdX0 == inExtX - 1 && fx < 0.5))
383 template <
class F,
class T>
387 const vtkIdType inInc[3],
398 int inExtX = inExt[1] - inExt[0] + 1;
399 int inExtY = inExt[3] - inExt[2] + 1;
400 int inExtZ = inExt[5] - inExt[4] + 1;
402 if (inIdX0 < 0 || inIdX0 >= inExtX || inIdY0 < 0 || inIdY0 >= inExtY || inIdZ0 < 0 || inIdZ0 >= inExtZ)
420 *outPtr++ = *background++;
421 }
while (--numscalars);
430 inPtr += inIdX0 * inInc[0] + inIdY0 * inInc[1] + inIdZ0 * inInc[2];
434 if (!self->IsOverwriteMode())
437 *outPtr++ = *inPtr++;
442 *(
const_cast<T *
>(inPtr)) = *outPtr++;
445 }
while (--numscalars);
454 int (**interpolate)(
void *&outPtr,
457 const vtkIdType inInc[3],
464 int dataType =
self->GetOutput()->GetScalarType();
468 vtkTemplateAliasMacro(*((
int (**)(VTK_TT * &outPtr,
471 const vtkIdType inInc[3],
475 const VTK_TT *background,
478 interpolate =
nullptr;
489 struct vtkImageResliceSetPixels
491 static void Set(
void *&outPtrV,
const void *inPtrV,
int numscalars,
int n)
493 const T *inPtr =
static_cast<const T *
>(inPtrV);
494 T *outPtr =
static_cast<T *
>(outPtrV);
495 for (
int i = 0; i < n; i++)
497 const T *tmpPtr = inPtr;
501 *outPtr++ = *tmpPtr++;
508 static void Set1(
void *&outPtrV,
const void *inPtrV,
int vtkNotUsed(numscalars),
int n)
510 const T *inPtr =
static_cast<const T *
>(inPtrV);
511 T *outPtr =
static_cast<T *
>(outPtrV);
513 for (
int i = 0; i < n; i++)
523 void (**setpixels)(
void *&out,
const void *
in,
int numscalars,
int n))
525 int dataType =
self->GetOutput()->GetScalarType();
526 int numscalars =
self->GetOutput()->GetNumberOfScalarComponents();
533 vtkTemplateAliasMacro(*setpixels = &vtkImageResliceSetPixels<VTK_TT>::Set1);
540 vtkTemplateAliasMacro(*setpixels = &vtkImageResliceSetPixels<VTK_TT>::Set);
552 *background_ptr =
new T[numComponents];
555 for (
int i = 0; i < numComponents; i++)
559 vtkResliceClamp(self->GetBackgroundColor()[i], background[i]);
570 switch (self->GetOutput()->GetScalarType())
578 switch (self->GetOutput()->GetScalarType())
580 vtkTemplateAliasMacro(
delete[] * ((VTK_TT **)rval));
598 void (*setpixels)(
void *&out,
const void *
in,
int numscalars,
int n),
620 int rval = stencil->GetNextExtent(r1, r2, rmin, rmax, yIdx, zIdx, iter);
627 setpixels(outPtr, background, numscalars, clear2 - clear1 + 1);
637 mitkVtkImageOverwrite *
self, vtkImageData *,
void *, vtkImageData *outData,
void *outPtr,
int outExt[6],
int id)
641 vtkIdType outIncX, outIncY, outIncZ;
643 unsigned long count = 0;
644 unsigned long target;
646 void (*setpixels)(
void *&out,
const void *
in,
int numscalars,
int n);
649 target =
static_cast<unsigned long>((outExt[5] - outExt[4] + 1) * (outExt[3] - outExt[2] + 1) / 50.0);
653 outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ);
654 scalarSize = outData->GetScalarSize();
655 numscalars = outData->GetNumberOfScalarComponents();
663 for (idZ = outExt[4]; idZ <= outExt[5]; idZ++)
665 for (idY = outExt[2]; idY <= outExt[3]; idY++)
669 if (!(count % target))
671 self->UpdateProgress(count / (50.0 * target));
676 setpixels(outPtr, background, numscalars, outExt[1] - outExt[0] + 1);
677 outPtr =
static_cast<void *
>(
static_cast<char *
>(outPtr) + outIncY * scalarSize);
679 outPtr =
static_cast<void *
>(
static_cast<char *
>(outPtr) + outIncZ * scalarSize);
689 vtkImageData *inData,
691 vtkImageData *outData,
698 int idXmin, idXmax, iter;
699 vtkIdType outIncX, outIncY, outIncZ;
703 unsigned long count = 0;
704 unsigned long target;
707 double *inSpacing, *inOrigin, *outSpacing, *outOrigin, inInvSpacing[3];
709 int (*interpolate)(
void *&outPtr,
712 const vtkIdType inInc[3],
714 const double point[3],
718 void (*setpixels)(
void *&out,
const void *
in,
int numscalars,
int n) =
nullptr;
722 if (self->GetMirror())
726 else if (self->GetWrap())
730 else if (self->GetBorder())
736 vtkAbstractTransform *transform =
self->GetResliceTransform();
737 vtkMatrix4x4 *matrix =
self->GetResliceAxes();
740 inOrigin = inData->GetOrigin();
741 inSpacing = inData->GetSpacing();
742 outOrigin = outData->GetOrigin();
743 outSpacing = outData->GetSpacing();
746 inInvSpacing[0] = 1.0 / inSpacing[0];
747 inInvSpacing[1] = 1.0 / inSpacing[1];
748 inInvSpacing[2] = 1.0 / inSpacing[2];
751 inData->GetExtent(inExt);
754 target =
static_cast<unsigned long>((outExt[5] - outExt[4] + 1) * (outExt[3] - outExt[2] + 1) / 50.0);
758 inData->GetIncrements(inInc);
759 outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ);
760 scalarSize = outData->GetScalarSize();
761 numscalars = inData->GetNumberOfScalarComponents();
771 vtkImageStencilData *stencil =
self->GetStencil();
774 for (idZ = outExt[4]; idZ <= outExt[5]; idZ++)
776 for (idY = outExt[2]; idY <= outExt[3]; idY++)
780 if (!(count % target))
782 self->UpdateProgress(count / (50.0 * target));
789 stencil, idXmin, idXmax, outExt[0], outExt[1], idY, idZ, outPtr, background, numscalars, setpixels, iter))
791 for (idX = idXmin; idX <= idXmax; idX++)
794 point[0] = idX * outSpacing[0] + outOrigin[0];
795 point[1] = idY * outSpacing[1] + outOrigin[1];
796 point[2] = idZ * outSpacing[2] + outOrigin[2];
802 matrix->MultiplyPoint(point, point);
812 transform->InternalTransformPoint(point, point);
816 point[0] = (point[0] - inOrigin[0]) * inInvSpacing[0];
817 point[1] = (point[1] - inOrigin[1]) * inInvSpacing[1];
818 point[2] = (point[2] - inOrigin[2]) * inInvSpacing[2];
821 interpolate(outPtr, inPtr, inExt, inInc, numscalars, point, mode, background,
self);
824 outPtr =
static_cast<void *
>(
static_cast<char *
>(outPtr) + outIncY * scalarSize);
826 outPtr =
static_cast<void *
>(
static_cast<char *
>(outPtr) + outIncZ * scalarSize);
840 this->SetOutput(slice);
847 vtkInformationVector **vtkNotUsed(inputVector),
848 vtkInformationVector *vtkNotUsed(outputVector),
849 vtkImageData ***inData,
850 vtkImageData **outData,
854 vtkDebugMacro(<<
"Execute: inData = " << inData[0][0] <<
", outData = " << outData[0]);
856 if (inData[0][0]->GetScalarType() != outData[0]->GetScalarType())
858 vtkErrorMacro(<<
"Execute: input ScalarType, " << inData[0][0]->GetScalarType() <<
", must match out ScalarType "
859 << outData[0]->GetScalarType());
864 inData[0][0]->GetExtent(inExt);
866 if (inExt[1] < inExt[0] || inExt[3] < inExt[2] || inExt[5] < inExt[4])
872 void *outPtr = outData[0]->GetScalarPointerForExtent(outExt);
874 if (this->HitInputExtent == 0)
881 void *inPtr = inData[0][0]->GetScalarPointerForExtent(inExt);
#define VTK_RESLICE_BACKGROUND
int vtkResliceFloor(double x, F &f)
virtual ~mitkVtkImageOverwrite()
static void vtkImageResliceClearExecute(mitkVtkImageOverwrite *self, vtkImageData *, void *, vtkImageData *outData, void *outPtr, int outExt[6], int id)
int vtkInterpolateWrap(int num, int range)
vtkStandardNewMacro(mitkVtkImageOverwrite)
static void vtkGetSetPixelsFunc(mitkVtkImageOverwrite *self, void(**setpixels)(void *&out, const void *in, int numscalars, int n))
#define VTK_RESLICE_BORDER
int vtkInterpolateBorder(int &inIdX0, int &inIdX1, int inExtX, double fx)
static int vtkNearestNeighborInterpolation(T *&outPtr, const T *inPtr, const int inExt[6], const vtkIdType inInc[3], int numscalars, const F point[3], int mode, const T *background, mitkVtkImageOverwrite *self)
static int vtkResliceGetNextExtent(vtkImageStencilData *stencil, int &r1, int &r2, int rmin, int rmax, int yIdx, int zIdx, void *&outPtr, void *background, int numscalars, void(*setpixels)(void *&out, const void *in, int numscalars, int n), int &iter)
static void vtkAllocBackgroundPixelT(mitkVtkImageOverwrite *self, T **background_ptr, int numComponents)
int vtkInterpolateMirror(int num, int range)
A vtk Filter based on vtkImageReslice with the aditional feature to write a slice into the given inpu...
static void vtkGetResliceInterpFunc(mitkVtkImageOverwrite *self, int(**interpolate)(void *&outPtr, const void *inPtr, const int inExt[6], const vtkIdType inInc[3], int numscalars, const F point[3], int mode, const void *background, mitkVtkImageOverwrite *self))
static void vtkImageResliceExecute(mitkVtkImageOverwrite *self, vtkImageData *inData, void *inPtr, vtkImageData *outData, void *outPtr, int outExt[6], int id)
static void vtkFreeBackgroundPixel(mitkVtkImageOverwrite *self, void **rval)
int vtkInterpolateBorderCheck(int inIdX0, int inIdX1, int inExtX, double fx)
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
static void vtkAllocBackgroundPixel(mitkVtkImageOverwrite *self, void **rval, int numComponents)
void SetOverwriteMode(bool b)
Set the mode either to reslice (false) or to overwrite (true). Default: false.
virtual void ThreadedRequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *vtkNotUsed(outputVector), vtkImageData ***inData, vtkImageData **outData, int outExt[6], int id) override
int vtkResliceRound(double x)
void SetInputSlice(vtkImageData *slice)
Set the slice for overwrite mode. Note: It is recommend not to use this in reslice mode because other...
#define VTK_RESLICE_MIRROR