Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Macros
Helper macros for reading MRML node properties from XML attributes.

Macros

#define vtkMRMLReadXMLBeginMacro(atts)
 
#define vtkMRMLReadXMLBooleanMacro(xmlAttributeName, propertyName)
 Macro for reading bool node property from XML. More...
 
#define vtkMRMLReadXMLEndMacro()   }};
 This macro must be placed after the last value reading macro. More...
 
#define vtkMRMLReadXMLEnumMacro(xmlAttributeName, propertyName)
 
#define vtkMRMLReadXMLFloatMacro(xmlAttributeName, propertyName)
 Macro for reading floating-point (float or double) node property from XML. More...
 
#define vtkMRMLReadXMLIntMacro(xmlAttributeName, propertyName)
 Macro for reading int node property from XML. More...
 
#define vtkMRMLReadXMLOwnedMatrix4x4Macro(xmlAttributeName, propertyName)
 
#define vtkMRMLReadXMLStdFloatVectorMacro(xmlAttributeName, propertyName, vectorType)
 Macro for reading an iterable container (float or double) node property from XML. More...
 
#define vtkMRMLReadXMLStdIntVectorMacro(xmlAttributeName, propertyName, vectorType)
 Macro for reading an iterable container (int) node property from XML. More...
 
#define vtkMRMLReadXMLStdStringMacro(xmlAttributeName, propertyName)
 
#define vtkMRMLReadXMLStdStringVectorMacro(xmlAttributeName, propertyName, vectorType)
 Macro for reading an iterable container (of std::string) node property from XML. More...
 
#define vtkMRMLReadXMLStringMacro(xmlAttributeName, propertyName)
 
#define vtkMRMLReadXMLVectorMacro(xmlAttributeName, propertyName, vectorType, vectorSize)
 Macro for reading floating-point (float or double) vector node property from XML. More...
 

Detailed Description

They are To be used in ReadXMLAttributes(const char** atts) method. Arguments of value writing macros:

Macro Definition Documentation

◆ vtkMRMLReadXMLBeginMacro

#define vtkMRMLReadXMLBeginMacro (   atts)
Value:
{ \
const char* xmlReadAttName; \
const char* xmlReadAttValue; \
const char** xmlReadAtts = atts; \
while (*xmlReadAtts != nullptr) \
{ \
xmlReadAttName = *(xmlReadAtts++); \
xmlReadAttValue = *(xmlReadAtts++); \
if (xmlReadAttValue == nullptr) \
{ \
break; \
}

This macro must be placed before the first value reading macro.

Parameters
attsis the C array of of attribute name/value pointer pairs

Definition at line 174 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLBooleanMacro

#define vtkMRMLReadXMLBooleanMacro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
this->Set##propertyName(strcmp(xmlReadAttValue,"true") ? false : true); \
}

Macro for reading bool node property from XML.

Definition at line 193 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLEndMacro

#define vtkMRMLReadXMLEndMacro ( )    }};

This macro must be placed after the last value reading macro.

Definition at line 189 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLEnumMacro

#define vtkMRMLReadXMLEnumMacro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
int propertyValue = this->Get##propertyName##FromString(xmlReadAttValue); \
if (propertyValue >= 0) \
{ \
this->Set##propertyName(propertyValue); \
} \
else \
{ \
vtkErrorMacro("Failed to read " #xmlAttributeName " attribute value from string '" << xmlReadAttValue << "'"); \
} \
}

Macro for reading enum node property from XML. Requires Get(propertyName)FromString method to convert from string to numeric value. XML decoding is not needed as attribute values are already decoded by the XML parser.

Definition at line 218 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLFloatMacro

#define vtkMRMLReadXMLFloatMacro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vtkVariant variantValue(xmlReadAttValue); \
bool valid = false; \
double scalarValue = variantValue.ToDouble(&valid); \
if (valid) \
{ \
this->Set##propertyName(scalarValue); \
} \
else \
{ \
vtkErrorMacro("Failed to read " #xmlAttributeName " attribute value from string '" << xmlReadAttValue << "': float expected"); \
} \
}

Macro for reading floating-point (float or double) node property from XML.

Definition at line 250 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLIntMacro

#define vtkMRMLReadXMLIntMacro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vtkVariant variantValue(xmlReadAttValue); \
bool valid = false; \
int intValue = variantValue.ToInt(&valid); \
if (valid) \
{ \
this->Set##propertyName(intValue); \
} \
else \
{ \
vtkErrorMacro("Failed to read " #xmlAttributeName " attribute value from string '" << xmlReadAttValue << "': integer expected"); \
} \
}

Macro for reading int node property from XML.

Definition at line 233 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLOwnedMatrix4x4Macro

#define vtkMRMLReadXMLOwnedMatrix4x4Macro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vtkNew<vtkMatrix4x4> matrix; \
std::stringstream ss; \
double val; \
ss << xmlReadAttValue; \
for (int row = 0; row < 4; row++) \
{ \
for (int col = 0; col < 4; col++) \
{ \
ss >> val; \
matrix->SetElement(row, col, val); \
} \
} \
this->Get##propertyName()->DeepCopy(matrix); \
}

Macro for reading a vtkMatrix4x4* node property from XML. "Owned" means that the node owns the matrix, the object is always valid and cannot be replaced from outside (there is no public Set...() method for the matrix).

Definition at line 347 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLStdFloatVectorMacro

#define vtkMRMLReadXMLStdFloatVectorMacro (   xmlAttributeName,
  propertyName,
  vectorType 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vectorType vector; \
std::string valueString(xmlReadAttValue); \
size_t separatorPosition = valueString.find(" "); \
while(separatorPosition != std::string::npos) \
{ \
std::string attributeValue = valueString.substr(0, separatorPosition); \
vtkVariant variantValue(attributeValue); \
bool valid = false; \
vectorType::value_type scalarValue = variantValue.ToDouble(&valid); \
if (valid) \
{ \
vector.insert(vector.end(), scalarValue); \
} \
valueString = valueString.substr(separatorPosition+1); \
separatorPosition = valueString.find(" "); \
} \
this->Set##propertyName(vector); \
}

Macro for reading an iterable container (float or double) node property from XML.

Definition at line 283 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLStdIntVectorMacro

#define vtkMRMLReadXMLStdIntVectorMacro (   xmlAttributeName,
  propertyName,
  vectorType 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vectorType vector; \
std::string valueString(xmlReadAttValue); \
size_t separatorPosition = valueString.find(" "); \
while(separatorPosition != std::string::npos) \
{ \
std::string attributeValue = valueString.substr(0, separatorPosition); \
vtkVariant variantValue(attributeValue); \
bool valid = false; \
vectorType::value_type scalarValue = variantValue.ToInt(&valid); \
if (valid) \
{ \
vector.insert(vector.end(), scalarValue); \
} \
valueString = valueString.substr(separatorPosition+1); \
separatorPosition = valueString.find(" "); \
} \
this->Set##propertyName(vector); \
}

Macro for reading an iterable container (int) node property from XML.

Definition at line 306 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLStdStringMacro

#define vtkMRMLReadXMLStdStringMacro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
this->Set##propertyName(xmlReadAttValue); \
}

Macro for reading std::string node property from XML. XML decoding is not needed as attribute values are already decoded by the XML parser.

Definition at line 209 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLStdStringVectorMacro

#define vtkMRMLReadXMLStdStringVectorMacro (   xmlAttributeName,
  propertyName,
  vectorType 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vectorType<std::string> attributeValues; \
std::string valueString(xmlReadAttValue); \
std::vector<std::string> splitXmlReadAttValue = vtksys::SystemTools::SplitString(valueString, ';'); \
for (std::string attributeValue : splitXmlReadAttValue) \
{ \
vtksys::SystemTools::ReplaceString(attributeValue, "%3B", ";"); \
vtksys::SystemTools::ReplaceString(attributeValue, "%25", "%"); \
attributeValues.emplace_back(attributeValue); \
} \
this->Set##propertyName(attributeValues); \
}

Macro for reading an iterable container (of std::string) node property from XML.

Definition at line 329 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLStringMacro

#define vtkMRMLReadXMLStringMacro (   xmlAttributeName,
  propertyName 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
this->Set##propertyName(xmlReadAttValue); \
}

Macro for reading char* node property from XML. XML decoding is not needed as attribute values are already decoded by the XML parser.

Definition at line 201 of file vtkMRMLNodePropertyMacros.h.

◆ vtkMRMLReadXMLVectorMacro

#define vtkMRMLReadXMLVectorMacro (   xmlAttributeName,
  propertyName,
  vectorType,
  vectorSize 
)
Value:
if (!strcmp(xmlReadAttName, #xmlAttributeName)) \
{ \
vectorType vectorValue[vectorSize] = {0}; \
std::stringstream ss; \
ss << xmlReadAttValue; \
for (int i=0; i<vectorSize; i++) \
{ \
vectorType val; \
ss >> val; \
vectorValue[i] = val; \
} \
this->Set##propertyName(vectorValue); \
}

Macro for reading floating-point (float or double) vector node property from XML.

Definition at line 267 of file vtkMRMLNodePropertyMacros.h.