Skip to content
Snippets Groups Projects
Commit 929a2491 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: helper methods to convert strings into PixelTypes

parent 68a028db
No related branches found
No related tags found
No related merge requests found
......@@ -85,6 +85,10 @@ public:
/** Static method to convert pixel type into string */
static std::string ConvertPixelTypeToString(ComplexImagePixelType type);
/** Convert a string into a ComplexImagePixelType (returns false if the
* conversion fails) */
static bool ConvertStringToPixelType(const std::string &value, ComplexImagePixelType &type);
/** Return true if a filename is set */
bool HasValue() const ITK_OVERRIDE;
......
......@@ -86,6 +86,10 @@ public:
/** Static method to convert pixel type into string */
static std::string ConvertPixelTypeToString(ImagePixelType type);
/** Converts a string into a pixel type (returns false if the conversion
* fails) */
static bool ConvertStringToPixelType(const std::string &value, ImagePixelType &type);
/** Return true if a filename is set */
bool HasValue() const ITK_OVERRIDE;
......
......@@ -73,6 +73,18 @@ ComplexOutputImageParameter::ConvertPixelTypeToString(ComplexImagePixelType type
return ret;
}
bool
ComplexOutputImageParameter::ConvertStringToPixelType(const std::string &value, ComplexImagePixelType &type)
{
if (value == "cfloat")
type = ComplexImagePixelType_float;
else if (value == "cdouble")
type = ComplexImagePixelType_double;
else
return false;
return true;
}
void ComplexOutputImageParameter::InitializeWriters()
{
m_ComplexFloatWriter = ComplexFloatWriterType::New();
......
......@@ -98,6 +98,28 @@ std::string OutputImageParameter::ConvertPixelTypeToString(ImagePixelType type)
return ret;
}
bool
OutputImageParameter::ConvertStringToPixelType(const std::string &value, ImagePixelType &type)
{
if (value == "uint8")
type = ImagePixelType_uint8;
else if (value == "int16")
type = ImagePixelType_int16;
else if (value == "uint16")
type = ImagePixelType_uint16;
else if (value == "int32")
type = ImagePixelType_int32;
else if (value == "uint32")
type = ImagePixelType_uint32;
else if (value == "float")
type = ImagePixelType_float;
else if (value == "double")
type = ImagePixelType_double;
else
return false;
return true;
}
void OutputImageParameter::InitializeWriters()
{
m_UInt8Writer = UInt8WriterType::New();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment