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

Method GetAttributeValueAsInt

IO/MINC/vtkMINCImageAttributes.cxx:669–706  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

667
668//------------------------------------------------------------------------------
669int 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//------------------------------------------------------------------------------
709double vtkMINCImageAttributes::GetAttributeValueAsDouble(

Callers

nothing calls this directly

Calls 6

GetDataTypeMethod · 0.45
valueMethod · 0.45
GetNumberOfTuplesMethod · 0.45
GetComponentMethod · 0.45

Tested by

no test coverage detected