MCPcopy Create free account
hub / github.com/Kitware/VTK / RequestData

Method RequestData

Filters/General/vtkNormalizeMatrixVectors.cxx:39–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39int vtkNormalizeMatrixVectors::RequestData(
40 vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
41{
42 int vector_dimension = std::min(1, std::max(0, this->VectorDimension));
43 double p_value = std::max(1.0, this->PValue);
44
45 vtkArrayData* const input = vtkArrayData::GetData(inputVector[0]);
46 if (input->GetNumberOfArrays() != 1)
47 {
48 vtkErrorMacro(
49 << "vtkNormalizeMatrixVectors requires vtkArrayData containing exactly one array as input.");
50 return 0;
51 }
52
53 vtkTypedArray<double>* const input_array =
54 vtkTypedArray<double>::SafeDownCast(input->GetArray(static_cast<vtkIdType>(0)));
55 if (!input_array)
56 {
57 vtkErrorMacro(<< "vtkNormalizeMatrixVectors requires a vtkTypedArray<double> as input.");
58 return 0;
59 }
60 if (input_array->GetDimensions() != 2)
61 {
62 vtkErrorMacro(<< "vtkNormalizeMatrixVectors requires a matrix as input.");
63 return 0;
64 }
65
66 vtkTypedArray<double>* const output_array =
67 vtkTypedArray<double>::SafeDownCast(input_array->DeepCopy());
68
69 const vtkArrayRange vectors = input_array->GetExtent(vector_dimension);
70 const vtkIdType value_count = input_array->GetNonNullSize();
71
72 // Create temporary storage for computed vector weights ...
73 std::vector<double> weight(vectors.GetSize(), 0.0);
74
75 // Store the sum of the squares of each vector value ...
76 vtkArrayCoordinates coordinates;
77 for (vtkIdType n = 0; n != value_count; ++n)
78 {
79 if (this->CheckAbort())
80 {
81 break;
82 }
83 output_array->GetCoordinatesN(n, coordinates);
84 weight[coordinates[vector_dimension] - vectors.GetBegin()] +=
85 pow(output_array->GetValueN(n), p_value);
86 }
87
88 // Convert the sums into weights, avoiding divide-by-zero ...
89 for (vtkIdType i = 0; i != vectors.GetSize(); ++i)
90 {
91 if (this->CheckAbort())
92 {
93 break;
94 }
95 const double length = pow(weight[i], 1.0 / p_value);
96 weight[i] = length ? 1.0 / length : 0.0;

Callers

nothing calls this directly

Calls 15

CheckAbortMethod · 0.80
DeleteMethod · 0.65
minFunction · 0.50
maxFunction · 0.50
GetDataFunction · 0.50
powFunction · 0.50
GetNumberOfArraysMethod · 0.45
GetArrayMethod · 0.45
GetDimensionsMethod · 0.45
DeepCopyMethod · 0.45
GetExtentMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected