diff --git a/Imaging/Core/vtkImageConstantPad.cxx b/Imaging/Core/vtkImageConstantPad.cxx index 558d0eb4c96bb975e9932056c4429bf30ae7c54c..c0d80f503336774ac8a9f9ba586f6f5749cb99e0 100644 --- a/Imaging/Core/vtkImageConstantPad.cxx +++ b/Imaging/Core/vtkImageConstantPad.cxx @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #include "vtkImageConstantPad.h" +#include "vtkDoubleArray.h" #include "vtkImageData.h" #include "vtkInformation.h" #include "vtkInformationVector.h" @@ -9,13 +10,23 @@ #include "vtkStreamingDemandDrivenPipeline.h" VTK_ABI_NAMESPACE_BEGIN +//------------------------------------------------------------------------------ vtkStandardNewMacro(vtkImageConstantPad); //------------------------------------------------------------------------------ -// Constructor sets default values +vtkCxxSetObjectMacro(vtkImageConstantPad, ComponentConstants, vtkDoubleArray); + +//---------------------------------------------------------------------------- vtkImageConstantPad::vtkImageConstantPad() { this->Constant = 0.0; + this->ComponentConstants = nullptr; +} + +//------------------------------------------------------------------------------ +vtkImageConstantPad::~vtkImageConstantPad() +{ + this->SetComponentConstants(nullptr); } //------------------------------------------------------------------------------ @@ -28,9 +39,9 @@ void vtkImageConstantPadExecute(vtkImageConstantPad* self, vtkImageData* inData, int maxC, maxX, maxY, maxZ; vtkIdType inIncX, inIncY, inIncZ; vtkIdType outIncX, outIncY, outIncZ; - T constant; + const T constant = static_cast<T>(self->GetConstant()); + vtkDoubleArray* componentConstants = self->GetComponentConstants(); int inMinX, inMaxX, inMaxC; - constant = static_cast<T>(self->GetConstant()); int state0, state1, state2, state3; unsigned long count = 0; unsigned long target; @@ -46,6 +57,9 @@ void vtkImageConstantPadExecute(vtkImageConstantPad* self, vtkImageData* inData, target = static_cast<unsigned long>((maxZ + 1) * (maxY + 1) / 50.0); target++; + const bool useComponentConstants = + componentConstants && componentConstants->GetNumberOfValues() == maxC; + // Get increments to march through data inData->GetContinuousIncrements(inExt, inIncX, inIncY, inIncZ); outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ); @@ -94,7 +108,7 @@ void vtkImageConstantPadExecute(vtkImageConstantPad* self, vtkImageData* inData, state0 = (state1 || idxC >= inMaxC); if (state0) { - *outPtr = constant; + *outPtr = useComponentConstants ? componentConstants->GetValue(idxC) : constant; } else { @@ -158,6 +172,7 @@ void vtkImageConstantPad::ThreadedRequestData(vtkInformation* vtkNotUsed(request } } +//------------------------------------------------------------------------------ void vtkImageConstantPad::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); diff --git a/Imaging/Core/vtkImageConstantPad.h b/Imaging/Core/vtkImageConstantPad.h index e402229609b4c36e45af1fed8900c01dded55e82..352a0849031cd08eda41dd74b32b5f98beb89e40 100644 --- a/Imaging/Core/vtkImageConstantPad.h +++ b/Imaging/Core/vtkImageConstantPad.h @@ -19,6 +19,8 @@ #include "vtkImagingCoreModule.h" // For export macro VTK_ABI_NAMESPACE_BEGIN +class vtkDoubleArray; + class VTKIMAGINGCORE_EXPORT vtkImageConstantPad : public vtkImagePadFilter { public: @@ -30,16 +32,29 @@ public: ///@{ /** * Set/Get the pad value. + * + * @note if the ComponentConstants array is set, this value is ignored. */ vtkSetMacro(Constant, double); vtkGetMacro(Constant, double); ///@} + ///@{ + /** + * Set/Get the pad values for each component. + * + * @note If this array is set, the Constant value is ignored. + */ + virtual void SetComponentConstants(vtkDoubleArray* values); + vtkGetObjectMacro(ComponentConstants, vtkDoubleArray); + ///@} + protected: vtkImageConstantPad(); - ~vtkImageConstantPad() override = default; + ~vtkImageConstantPad() override; double Constant; + vtkDoubleArray* ComponentConstants; void ThreadedRequestData(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector, vtkImageData*** inData, vtkImageData** outData, int ext[6],