| 103 | //------------------------------------------------------------------------------ |
| 104 | |
| 105 | int vtkTableToArray::RequestData( |
| 106 | vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) |
| 107 | { |
| 108 | vtkTable* const table = vtkTable::GetData(inputVector[0]); |
| 109 | |
| 110 | std::vector<vtkAbstractArray*> columns; |
| 111 | |
| 112 | for (size_t i = 0; i != this->Implementation->Columns.size(); ++i) |
| 113 | { |
| 114 | if (this->Implementation->Columns[i].IsString()) |
| 115 | { |
| 116 | columns.push_back( |
| 117 | table->GetColumnByName(this->Implementation->Columns[i].ToString().c_str())); |
| 118 | if (!columns.back()) |
| 119 | { |
| 120 | vtkErrorMacro(<< "Missing table column: " << this->Implementation->Columns[i].ToString()); |
| 121 | return 0; |
| 122 | } |
| 123 | } |
| 124 | else if (this->Implementation->Columns[i].IsInt()) |
| 125 | { |
| 126 | columns.push_back(table->GetColumn(this->Implementation->Columns[i].ToInt())); |
| 127 | if (!columns.back()) |
| 128 | { |
| 129 | vtkErrorMacro(<< "Missing table column: " << this->Implementation->Columns[i].ToInt()); |
| 130 | return 0; |
| 131 | } |
| 132 | } |
| 133 | else if (this->Implementation->Columns[i].IsChar() && |
| 134 | this->Implementation->Columns[i].ToChar() == 'A') |
| 135 | { |
| 136 | for (vtkIdType j = 0; j != table->GetNumberOfColumns(); ++j) |
| 137 | { |
| 138 | columns.push_back(table->GetColumn(j)); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | vtkDenseArray<double>* const array = vtkDenseArray<double>::New(); |
| 144 | array->Resize(table->GetNumberOfRows(), static_cast<vtkIdType>(columns.size())); |
| 145 | array->SetDimensionLabel(0, "row"); |
| 146 | array->SetDimensionLabel(1, "column"); |
| 147 | |
| 148 | for (vtkIdType i = 0; i != table->GetNumberOfRows(); ++i) |
| 149 | { |
| 150 | for (size_t j = 0; j != columns.size(); ++j) |
| 151 | { |
| 152 | array->SetValue(i, static_cast<vtkIdType>(j), columns[j]->GetVariantValue(i).ToDouble()); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | vtkArrayData* const output = vtkArrayData::GetData(outputVector); |
| 157 | output->ClearArrays(); |
| 158 | output->AddArray(array); |
| 159 | array->Delete(); |
| 160 | |
| 161 | return 1; |
| 162 | } |
nothing calls this directly
no test coverage detected