19 #include "vtkDataArray.h"
20 #include "vtkImageData.h"
21 #include "vtkInformation.h"
22 #include "vtkInformationVector.h"
23 #include "vtkObjectFactory.h"
24 #include "vtkPointData.h"
25 #include "vtkStreamingDemandDrivenPipeline.h"
42 this->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS);
48 this->Superclass::PrintSelf(os, indent);
50 os << indent <<
"Dimensionality: " << this->
Dimensionality <<
"\n";
55 vtkInformationVector **inputVector,
56 vtkInformationVector *outputVector)
59 vtkInformation *outInfo = outputVector->GetInformationObject(0);
60 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
64 inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
67 extent[4] = extent[5] = 0;
70 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent, 6);
84 vtkInformationVector **inputVector,
85 vtkInformationVector *outputVector)
88 vtkInformation *outInfo = outputVector->GetInformationObject(0);
89 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
93 inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent);
97 outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), inUExt);
102 inUExt[4] = wholeExtent[4];
103 inUExt[5] = wholeExtent[5];
106 inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), inUExt, 6);
117 vtkImageData *inData,
119 vtkImageData *outData,
126 vtkIdType inIncX, inIncY, inIncZ;
127 vtkIdType outIncX, outIncY, outIncZ;
129 int *inExt = inData->GetExtent();
135 maxX = outExt[1] - outExt[0];
136 maxY = outExt[3] - outExt[2];
144 inData->GetContinuousIncrements(outExt, inIncX, inIncY, inIncZ);
145 outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ);
156 inIncs = inData->GetIncrements();
157 wholeExtent = inData->GetExtent();
160 inPtr += (outExt[0] - inExt[0]) * inIncs[0] + (outExt[2] - inExt[2]) * inIncs[1] + (outExt[4] - inExt[4]) * inIncs[2];
164 int _minZ = wholeExtent[4];
165 int _maxZ = wholeExtent[5];
170 double invNum = 1.0 / (_maxZ - _minZ + 1);
172 switch (self->GetThickSliceMode())
178 for (idxY = 0; idxY <= maxY; idxY++)
182 for (idxX = 0; idxX <= maxX; idxX++)
187 T mip = inPtr[_minZ * inIncs[2]];
189 for (
int z = _minZ + 1; z <= _maxZ; z++)
191 T value = inPtr[z * inIncs[2]];
210 for (idxY = 0; idxY <= maxY; idxY++)
214 for (idxX = 0; idxX <= maxX; idxX++)
221 for (
int z = _minZ; z <= _maxZ; z++)
223 T value = inPtr[z * inIncs[2]];
228 *outPtr =
static_cast<T
>(invNum * sum);
240 const int size = _maxZ - _minZ;
241 std::vector<double> weights(size);
242 double mean = 0.5 * double(_minZ + _maxZ);
243 double sigma_sq = double(size) / 6.0;
244 sigma_sq *= sigma_sq;
247 for (
int z = _minZ + 1; z <= _maxZ; z++)
249 double val = exp(-(((
double)z - mean) / sigma_sq));
253 for (i = 0; i < size; i++)
258 for (idxY = 0; idxY <= maxY; idxY++)
262 for (idxX = 0; idxX <= maxX; idxX++)
267 T mip = inPtr[_minZ * inIncs[2]];
270 for (
int z = _minZ + 1; z <= _maxZ; z++)
272 double value = inPtr[z * inIncs[2]];
273 mymip += value * weights[i++];
275 mip =
static_cast<T
>(mymip);
289 for (idxY = 0; idxY <= maxY; idxY++)
291 for (idxX = 0; idxX <= maxX; idxX++)
293 T mip = inPtr[_minZ * inIncs[2]];
295 for (
int z = _minZ + 1; z <= _maxZ; z++)
297 T value = inPtr[z * inIncs[2]];
315 const int size = _maxZ - _minZ;
318 for (idxY = 0; idxY <= maxY; idxY++)
320 for (idxX = 0; idxX <= maxX; idxX++)
323 for (
int z = _minZ; z <= _maxZ; z++)
325 T value = inPtr[z * inIncs[2]];
345 vtkInformationVector **inputVector,
346 vtkInformationVector *outputVector)
348 if (!this->Superclass::RequestData(request, inputVector, outputVector))
353 vtkDataArray *outArray = output->GetPointData()->GetScalars();
354 std::ostringstream newname;
355 newname << (outArray->GetName() ? outArray->GetName() :
"") <<
"Gradient";
356 outArray->SetName(newname.str().c_str());
358 if (this->GetInputArrayToProcess(0, inputVector))
360 output->GetPointData()->AddArray(this->GetInputArrayToProcess(0, inputVector));
370 vtkInformationVector **inputVector,
371 vtkInformationVector *,
372 vtkImageData ***inData,
373 vtkImageData **outData,
378 vtkImageData *input = inData[0][0];
379 vtkImageData *output = outData[0];
390 vtkDataArray *inputArray = this->GetInputArrayToProcess(0, inputVector);
393 vtkErrorMacro(
"No input array was found. Cannot execute");
399 if (inputArray->GetNumberOfComponents() != 1)
401 vtkErrorMacro(
"Execute: input has more than one component. "
402 "The input to gradient should be a single component image. "
403 "Think about it. If you insist on using a color image then "
404 "run it though RGBToHSV then ExtractComponents to get the V "
405 "components. That's probably what you want anyhow.");
409 void *inPtr = inputArray->GetVoidPointer(0);
410 void *outPtr = output->GetScalarPointerForExtent(outExt);
412 switch (inputArray->GetDataType())
415 this, input, static_cast<VTK_TT *>(inPtr), output, static_cast<VTK_TT *>(outPtr), outExt, threadId));
417 vtkErrorMacro(
"Execute: Unknown ScalarType " << input->GetScalarType());
vtkMitkThickSlicesFilter()
vtkStandardNewMacro(vtkMitkThickSlicesFilter)
void vtkMitkThickSlicesFilterExecute(vtkMitkThickSlicesFilter *self, vtkImageData *inData, T *inPtr, vtkImageData *outData, T *outPtr, int outExt[6], int)
void ThreadedRequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *, vtkImageData ***inData, vtkImageData **outData, int outExt[6], int threadId) override
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
T::Pointer GetData(const std::string &name)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(ostream &os, vtkIndent indent) override
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override