15 #include "vtkDataArray.h" 16 #include "vtkImageData.h" 17 #include "vtkInformation.h" 18 #include "vtkInformationVector.h" 19 #include "vtkObjectFactory.h" 20 #include "vtkPointData.h" 21 #include "vtkStreamingDemandDrivenPipeline.h" 38 this->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS);
44 this->Superclass::PrintSelf(os, indent);
46 os << indent <<
"Dimensionality: " << this->
Dimensionality <<
"\n";
51 vtkInformationVector **inputVector,
52 vtkInformationVector *outputVector)
55 vtkInformation *outInfo = outputVector->GetInformationObject(0);
56 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
60 inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
63 extent[4] = extent[5] = 0;
66 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent, 6);
80 vtkInformationVector **inputVector,
81 vtkInformationVector *outputVector)
84 vtkInformation *outInfo = outputVector->GetInformationObject(0);
85 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
89 inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent);
93 outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), inUExt);
98 inUExt[4] = wholeExtent[4];
99 inUExt[5] = wholeExtent[5];
102 inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), inUExt, 6);
113 vtkImageData *inData,
115 vtkImageData *outData,
122 vtkIdType inIncX, inIncY, inIncZ;
123 vtkIdType outIncX, outIncY, outIncZ;
125 int *inExt = inData->GetExtent();
131 maxX = outExt[1] - outExt[0];
132 maxY = outExt[3] - outExt[2];
140 inData->GetContinuousIncrements(outExt, inIncX, inIncY, inIncZ);
141 outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ);
152 inIncs = inData->GetIncrements();
153 wholeExtent = inData->GetExtent();
156 inPtr += (outExt[0] - inExt[0]) * inIncs[0] + (outExt[2] - inExt[2]) * inIncs[1] + (outExt[4] - inExt[4]) * inIncs[2];
160 int _minZ = wholeExtent[4];
161 int _maxZ = wholeExtent[5];
166 double invNum = 1.0 / (_maxZ - _minZ + 1);
168 switch (self->GetThickSliceMode())
174 for (idxY = 0; idxY <= maxY; idxY++)
178 for (idxX = 0; idxX <= maxX; idxX++)
183 T mip = inPtr[_minZ * inIncs[2]];
185 for (
int z = _minZ + 1; z <= _maxZ; z++)
187 T value = inPtr[z * inIncs[2]];
206 for (idxY = 0; idxY <= maxY; idxY++)
210 for (idxX = 0; idxX <= maxX; idxX++)
217 for (
int z = _minZ; z <= _maxZ; z++)
219 T value = inPtr[z * inIncs[2]];
224 *outPtr =
static_cast<T
>(invNum * sum);
236 const int size = _maxZ - _minZ;
237 std::vector<double> weights(size);
238 double mean = 0.5 * double(_minZ + _maxZ);
239 double sigma_sq = double(size) / 6.0;
240 sigma_sq *= sigma_sq;
243 for (
int z = _minZ + 1; z <= _maxZ; z++)
245 double val = exp(-(((
double)z - mean) / sigma_sq));
249 for (i = 0; i < size; i++)
254 for (idxY = 0; idxY <= maxY; idxY++)
258 for (idxX = 0; idxX <= maxX; idxX++)
263 T mip = inPtr[_minZ * inIncs[2]];
266 for (
int z = _minZ + 1; z <= _maxZ; z++)
268 double value = inPtr[z * inIncs[2]];
269 mymip += value * weights[i++];
271 mip =
static_cast<T
>(mymip);
285 for (idxY = 0; idxY <= maxY; idxY++)
287 for (idxX = 0; idxX <= maxX; idxX++)
289 T mip = inPtr[_minZ * inIncs[2]];
291 for (
int z = _minZ + 1; z <= _maxZ; z++)
293 T value = inPtr[z * inIncs[2]];
311 const int size = _maxZ - _minZ;
314 for (idxY = 0; idxY <= maxY; idxY++)
316 for (idxX = 0; idxX <= maxX; idxX++)
319 for (
int z = _minZ; z <= _maxZ; z++)
321 T value = inPtr[z * inIncs[2]];
325 T mip =
static_cast<T
>(sum / size);
341 vtkInformationVector **inputVector,
342 vtkInformationVector *outputVector)
344 if (!this->Superclass::RequestData(request, inputVector, outputVector))
348 vtkImageData *output = vtkImageData::GetData(outputVector);
349 vtkDataArray *outArray = output->GetPointData()->GetScalars();
350 std::ostringstream newname;
351 newname << (outArray->GetName() ? outArray->GetName() :
"") <<
"Gradient";
352 outArray->SetName(newname.str().c_str());
354 if (this->GetInputArrayToProcess(0, inputVector))
356 output->GetPointData()->AddArray(this->GetInputArrayToProcess(0, inputVector));
366 vtkInformationVector **inputVector,
367 vtkInformationVector *,
368 vtkImageData ***inData,
369 vtkImageData **outData,
374 vtkImageData *input = inData[0][0];
375 vtkImageData *output = outData[0];
386 vtkDataArray *inputArray = this->GetInputArrayToProcess(0, inputVector);
389 vtkErrorMacro(
"No input array was found. Cannot execute");
395 if (inputArray->GetNumberOfComponents() != 1)
397 vtkErrorMacro(
"Execute: input has more than one component. " 398 "The input to gradient should be a single component image. " 399 "Think about it. If you insist on using a color image then " 400 "run it though RGBToHSV then ExtractComponents to get the V " 401 "components. That's probably what you want anyhow.");
405 void *inPtr = inputArray->GetVoidPointer(0);
406 void *outPtr = output->GetScalarPointerForExtent(outExt);
408 switch (inputArray->GetDataType())
411 this, input, static_cast<VTK_TT *>(inPtr), output, static_cast<VTK_TT *>(outPtr), outExt, threadId));
413 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
int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(ostream &os, vtkIndent indent) override
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override