| 250 | } |
| 251 | |
| 252 | vtkSmartPointer<vtkAbstractArray> ComponentOrNormAsArray(vtkAbstractArray* array, int compOrNorm) |
| 253 | { |
| 254 | vtkSmartPointer<vtkAbstractArray> result; |
| 255 | if (!array) |
| 256 | { |
| 257 | return result; |
| 258 | } |
| 259 | if (compOrNorm == vtkArrayComponents::AllComponents || |
| 260 | (array->GetNumberOfComponents() == 1 && compOrNorm == 0)) |
| 261 | { |
| 262 | // Return the input array; don't create a new one since it would be an identical copy. |
| 263 | result = array; |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | if (auto dataArray = vtkDataArray::SafeDownCast(array)) |
| 268 | { |
| 269 | switch (compOrNorm) |
| 270 | { |
| 271 | case vtkArrayComponents::L1Norm: |
| 272 | result = computeL1Norm(dataArray); |
| 273 | break; |
| 274 | case vtkArrayComponents::L2Norm: |
| 275 | result = computeL2Norm(dataArray); |
| 276 | break; |
| 277 | case vtkArrayComponents::LInfNorm: |
| 278 | result = computeLInfNorm(dataArray); |
| 279 | break; |
| 280 | default: |
| 281 | { |
| 282 | if (compOrNorm >= 0 && compOrNorm < array->GetNumberOfComponents()) |
| 283 | { |
| 284 | result.TakeReference(array->NewInstance()); |
| 285 | result->SetNumberOfComponents(1); |
| 286 | result->SetNumberOfTuples(array->GetNumberOfTuples()); |
| 287 | result->CopyComponent(0, array, compOrNorm); |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | vtkErrorWithObjectMacro(array, "Invalid component " << compOrNorm << " requested."); |
| 292 | } |
| 293 | } |
| 294 | break; |
| 295 | } |
| 296 | if (result) |
| 297 | { |
| 298 | std::string aname = arrayName(array); |
| 299 | std::string cname = componentName(array, compOrNorm); |
| 300 | result->SetName((aname + "_" + cname).c_str()); |
| 301 | } |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | // Variant and string arrays do not provide a norm nor allow an out-of-range component. |
| 306 | if (compOrNorm < 0 || compOrNorm >= array->GetNumberOfComponents()) |
| 307 | { |
| 308 | vtkErrorWithObjectMacro(array, |
| 309 | "Request for an non-existent component or a norm on an array that does not support it."); |
no test coverage detected