------------------------------------------------------------------------------
| 667 | |
| 668 | //------------------------------------------------------------------------------ |
| 669 | int vtkMINCImageAttributes::GetAttributeValueAsInt(const char* variable, const char* attribute) |
| 670 | { |
| 671 | vtkDataArray* array = this->GetAttributeValueAsArray(variable, attribute); |
| 672 | |
| 673 | if (array == nullptr) |
| 674 | { |
| 675 | vtkErrorMacro("The attribute " << variable << ":" << attribute << " was not found."); |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | if (array->GetDataType() == VTK_CHAR) |
| 680 | { |
| 681 | const char* text = this->ConvertDataArrayToString(array); |
| 682 | auto result = vtk::scan_int<int>(std::string_view(text)); |
| 683 | // Check for complete conversion |
| 684 | if (result && *text != '\0') |
| 685 | { |
| 686 | return result->value(); |
| 687 | } |
| 688 | } |
| 689 | else if (array->GetNumberOfTuples() == 1) |
| 690 | { |
| 691 | switch (array->GetDataType()) |
| 692 | { |
| 693 | case VTK_SIGNED_CHAR: |
| 694 | case VTK_UNSIGNED_CHAR: |
| 695 | case VTK_SHORT: |
| 696 | case VTK_INT: |
| 697 | return static_cast<int>(array->GetComponent(0, 0)); |
| 698 | default: |
| 699 | break; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | vtkErrorMacro("GetAttributeValueAsInt() used on non-integer attribute " << variable << ":" |
| 704 | << attribute << "."); |
| 705 | return static_cast<int>(array->GetComponent(0, 0)); |
| 706 | } |
| 707 | |
| 708 | //------------------------------------------------------------------------------ |
| 709 | double vtkMINCImageAttributes::GetAttributeValueAsDouble( |
nothing calls this directly
no test coverage detected