| 127 | //------------------------------------------------------------------------------ |
| 128 | |
| 129 | int vtkTableToSparseArray::RequestData( |
| 130 | vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) |
| 131 | { |
| 132 | vtkTable* const table = vtkTable::GetData(inputVector[0]); |
| 133 | |
| 134 | std::vector<vtkAbstractArray*> coordinates(this->Implementation->Coordinates.size()); |
| 135 | for (size_t i = 0; i != this->Implementation->Coordinates.size(); ++i) |
| 136 | { |
| 137 | coordinates[i] = table->GetColumnByName(this->Implementation->Coordinates[i].c_str()); |
| 138 | if (!coordinates[i]) |
| 139 | { |
| 140 | vtkErrorMacro(<< "missing coordinate array: " << this->Implementation->Coordinates[i]); |
| 141 | } |
| 142 | } |
| 143 | // See http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html |
| 144 | // Language Feature: Partial Specializations |
| 145 | // Workaround |
| 146 | int n = 0; |
| 147 | #ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC |
| 148 | std::count(coordinates.begin(), coordinates.end(), static_cast<vtkAbstractArray*>(0), n); |
| 149 | #else |
| 150 | n = std::count(coordinates.begin(), coordinates.end(), static_cast<vtkAbstractArray*>(nullptr)); |
| 151 | #endif |
| 152 | if (n != 0) |
| 153 | { |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | vtkAbstractArray* const values = table->GetColumnByName(this->Implementation->Values.c_str()); |
| 158 | if (!values) |
| 159 | { |
| 160 | vtkErrorMacro(<< "missing value array: " << this->Implementation->Values); |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | vtkSparseArray<double>* const array = vtkSparseArray<double>::New(); |
| 165 | array->Resize( |
| 166 | vtkArrayExtents::Uniform(static_cast<vtkArrayExtents::DimensionT>(coordinates.size()), 0)); |
| 167 | |
| 168 | for (size_t i = 0; i != coordinates.size(); ++i) |
| 169 | { |
| 170 | array->SetDimensionLabel(static_cast<vtkArray::DimensionT>(i), coordinates[i]->GetName()); |
| 171 | } |
| 172 | |
| 173 | vtkArrayCoordinates output_coordinates; |
| 174 | output_coordinates.SetDimensions( |
| 175 | static_cast<vtkArrayCoordinates::DimensionT>(coordinates.size())); |
| 176 | for (vtkIdType i = 0; i != table->GetNumberOfRows(); ++i) |
| 177 | { |
| 178 | for (size_t j = 0; j != coordinates.size(); ++j) |
| 179 | { |
| 180 | output_coordinates[static_cast<vtkArrayCoordinates::DimensionT>(j)] = |
| 181 | coordinates[j]->GetVariantValue(i).ToInt(); |
| 182 | } |
| 183 | array->AddValue(output_coordinates, values->GetVariantValue(i).ToDouble()); |
| 184 | } |
| 185 | |
| 186 | if (this->Implementation->ExplicitOutputExtents) |
nothing calls this directly
no test coverage detected