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

Method RequestData

Filters/General/vtkMatricizeArray.cxx:35–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35int vtkMatricizeArray::RequestData(
36 vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
37{
38 vtkArrayData* const input = vtkArrayData::GetData(inputVector[0]);
39 if (input->GetNumberOfArrays() != 1)
40 {
41 vtkErrorMacro(
42 << "vtkMatricizeArray requires vtkArrayData containing exactly one array as input.");
43 return 0;
44 }
45
46 vtkSparseArray<double>* const input_array =
47 vtkSparseArray<double>::SafeDownCast(input->GetArray(static_cast<vtkIdType>(0)));
48 if (!input_array)
49 {
50 vtkErrorMacro(<< "vtkMatricizeArray requires a vtkSparseArray<double> as input.");
51 return 0;
52 }
53
54 if (this->SliceDimension < 0 || this->SliceDimension >= input_array->GetDimensions())
55 {
56 vtkErrorMacro(<< "Slice dimension " << this->SliceDimension << " out-of-range for array with "
57 << input_array->GetDimensions() << " dimensions.");
58 return 0;
59 }
60
61 vtkSparseArray<double>* const output_array = vtkSparseArray<double>::New();
62
63 // Compute the extents of the output array ...
64 const vtkArrayExtents input_extents = input_array->GetExtents();
65 vtkArrayExtents output_extents(0, 0);
66 output_extents[0] = input_extents[this->SliceDimension];
67 output_extents[1] =
68 vtkArrayRange(0, input_extents.GetSize() / input_extents[this->SliceDimension].GetSize());
69 output_array->Resize(output_extents);
70
71 // "Map" every non-null element in the input array to its position in the output array.
72 // Indices in the slice dimension map directly to the row index in the output.
73 // The remaining coordinates are multiplied by a "stride" value for each dimension and
74 // the results are summed to compute the output column index.
75 //
76 // Setting the slice-dimension stride to zero simplifies computation of column coordinates
77 // later-on and eliminate an inner-loop comparison.
78 std::vector<vtkIdType> strides(input_array->GetDimensions());
79 for (vtkIdType i = input_array->GetDimensions() - 1, stride = 1; i >= 0; --i)
80 {
81 if (i == this->SliceDimension)
82 {
83 strides[i] = 0;
84 }
85 else
86 {
87 strides[i] = stride;
88 stride *= input_extents[i].GetSize();
89 }
90 }
91
92 std::vector<vtkIdType> temp(input_array->GetDimensions());

Callers

nothing calls this directly

Calls 15

GetExtentsMethod · 0.80
CheckAbortMethod · 0.80
AddValueMethod · 0.80
DeleteMethod · 0.65
GetDataFunction · 0.50
NewFunction · 0.50
GetNumberOfArraysMethod · 0.45
GetArrayMethod · 0.45
GetDimensionsMethod · 0.45
GetSizeMethod · 0.45
ResizeMethod · 0.45
GetBeginMethod · 0.45

Tested by

no test coverage detected