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

Function ConvertMatrix

Infovis/Core/vtkArrayToTable.cxx:61–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59/// Convert a 2D array to a table with 1-or-more columns ...
60template <typename ValueT, typename ColumnT>
61static bool ConvertMatrix(vtkArray* Array, vtkTable* Output)
62{
63 if (Array->GetDimensions() != 2)
64 return false;
65
66 vtkTypedArray<ValueT>* const array = vtkTypedArray<ValueT>::SafeDownCast(Array);
67 if (!array)
68 return false;
69
70 vtkSparseArray<ValueT>* const sparse_array = vtkSparseArray<ValueT>::SafeDownCast(array);
71
72 const vtkIdType non_null_count = array->GetNonNullSize();
73 const vtkArrayRange columns = array->GetExtent(1);
74 const vtkArrayRange rows = array->GetExtent(0);
75
76 std::vector<ColumnT*> new_columns;
77 for (vtkIdType j = columns.GetBegin(); j != columns.GetEnd(); ++j)
78 {
79 std::ostringstream column_name;
80 column_name << j;
81
82 ColumnT* const column = ColumnT::New();
83 column->SetNumberOfTuples(rows.GetSize());
84 column->SetName(column_name.str().c_str());
85
86 if (sparse_array)
87 {
88 for (vtkIdType i = 0; i != rows.GetSize(); ++i)
89 column->SetValue(i, sparse_array->GetNullValue());
90 }
91
92 Output->AddColumn(column);
93 column->Delete();
94 new_columns.push_back(column);
95 }
96
97 for (vtkIdType n = 0; n != non_null_count; ++n)
98 {
99 vtkArrayCoordinates coordinates;
100 array->GetCoordinatesN(n, coordinates);
101
102 new_columns[coordinates[1] - columns.GetBegin()]->SetValue(
103 coordinates[0] - rows.GetBegin(), array->GetValueN(n));
104 }
105
106 return true;
107}
108
109//------------------------------------------------------------------------------
110

Callers

nothing calls this directly

Calls 14

DeleteMethod · 0.65
NewFunction · 0.50
GetDimensionsMethod · 0.45
GetExtentMethod · 0.45
GetBeginMethod · 0.45
GetEndMethod · 0.45
SetNumberOfTuplesMethod · 0.45
GetSizeMethod · 0.45
SetNameMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45
SetValueMethod · 0.45

Tested by

no test coverage detected