60 Log::error(
Say(
"%s: could not find MHD file '%s'.\n" ) << __FUNCTION__ << file->
path() );
67 std::vector<String> keyval;
73 entry.
split(
'=', keyval,
true );
74 if ( keyval.size() == 2 ) {
77 keyvals->
set( keyval[0] ) = keyval[1];
83 fvec3 center_of_rotation;
84 fvec3 element_spacing;
85 int width=0, height=0, depth=0, bytealign=1;
90 for( std::map<String, String>::const_iterator it = keyvals->
keyValueMap().begin(); it != keyvals->
keyValueMap().end(); ++it )
92 const String& key = it->first;
93 const String& val = it->second;
95 if ( key ==
"ObjectType" ) {
96 if ( val !=
"Image" ) {
97 Log::error(
Say(
"%s: ObjectType must be Image ('%s').\n") << __FUNCTION__ << file->
path() );
101 if ( key ==
"NDims" ) {
103 Log::error(
Say(
"%s: NDims must be 3 ('%s').\n") << __FUNCTION__ << file->
path() );
108 if ( key ==
"BinaryData" ) {
109 if ( val !=
"True" ) {
110 Log::error(
Say(
"%s: BinaryData must be True ('%s').\n") << __FUNCTION__ << file->
path() );
114 if ( key ==
"BinaryDataByteOrderMSB" ) {
115 if ( val !=
"False" ) {
116 Log::error(
Say(
"%s: BinaryDataByteOrderMSB must be False ('%s').\n") << __FUNCTION__ << file->
path() );
120 if ( key ==
"CompressedData" ) {
121 if ( val !=
"False" ) {
122 Log::error(
Say(
"%s: CompressedData must be False ('%s').\n") << __FUNCTION__ << file->
path() );
126 if ( key ==
"TransformMatrix" ) {
127 if ( val !=
"1 0 0 0 1 0 0 0 1" ) {
128 Log::error(
Say(
"%s: TransformMatrix must be set to identity matrix ('%s').\n") << __FUNCTION__ << file->
path() );
132 if ( key ==
"Offset" ) {
133 if ( sscanf( val.
toStdString().c_str(),
"%d %d %d", &offset.
x(), &offset.
y(), &offset.
z() ) != 3 ) {
134 Log::error(
Say(
"%s: invalid Offset value, must be three ints ('%s').\n") << __FUNCTION__ << file->
path() );
138 if ( key ==
"CenterOfRotation" ) {
139 if ( sscanf( val.
toStdString().c_str(),
"%f %f %f", ¢er_of_rotation.
x(), ¢er_of_rotation.
y(), ¢er_of_rotation.
z() ) != 3 ) {
140 Log::error(
Say(
"%s: invalid CenterOfRotation value, must be three floats ('%s') (%n).\n") << __FUNCTION__ << file->
path() );
144 if ( key ==
"ElementSpacing" ) {
145 if ( sscanf( val.
toStdString().c_str(),
"%f %f %f", &element_spacing.
x(), &element_spacing.
y(), &element_spacing.
z() ) != 3 ) {
146 Log::error(
Say(
"%s: invalid ElementSpacing value, must be three floats ('%s').\n") << __FUNCTION__ << file->
path() );
150 if ( key ==
"DimSize" ) {
151 if ( sscanf( val.
toStdString().c_str(),
"%d %d %d", &width, &height, &depth ) != 3 ) {
152 Log::error(
Say(
"%s: invalid DimSize value, must be three ints ('%s').\n") << __FUNCTION__ << file->
path() );
156 if ( key ==
"AnatomicalOrientation" ) {
159 if ( key ==
"ElementType" ) {
160 if ( val !=
"MET_SHORT" ) {
161 Log::error(
Say(
"%s: invalid ElementType value, only MET_SHORT is supported ('%s').\n") << __FUNCTION__ << file->
path() );
165 if ( key ==
"ElementDataFile" ) {
179 Log::error(
Say(
"loadMHD('%s'): could not find RAW file '%s'.\n") << file->
path() << raw_file );
String toLowerCase() const
Returns the lower-case version of a String.
const std::map< String, String > & keyValueMap() const
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
VLCORE_EXPORT bool isMHD(VirtualFile *file)
An abstract class representing a file.
bool readLine(std::string &utf8)
A simple String formatting class.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
const T_Scalar & z() const
VLCORE_EXPORT ref< Image > loadRAW(VirtualFile *file, long long file_offset, int width, int height, int depth, int bytealign, EImageFormat format, EImageType type)
Loads a raw image file.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
String extractPath() const
If the String contains a file path the function returns the path with trailing slash, without the file name.
virtual ref< VirtualFile > locateFile(const String &full_path, const String &alternate_path=String()) const
Looks for a VirtualFile on the disk and in the currently active FileSystem.
const String & path() const
Returns the path of the file.
Visualization Library main namespace.
The TextStream class can be used to conveniently read or parse utf8-encoded text files.
const T_Scalar & y() const
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
VLCORE_EXPORT ref< Image > loadMHD(VirtualFile *file)
void split(wchar_t separator, std::vector< String > &fields, bool remove_empty_fields=false) const
Splits a String into a set of fields. The fields are separated by the specified separator and are ret...
void setTags(KeyValues *tags)
A set of key/value couples that can be used to attach extra information to an image like DICOM inform...
const T_Scalar & x() const
The ref<> class is used to reference-count an Object.
std::string toStdString() const
Returns a UTF8 encoded std::string.
String & set(const String &key)
bool endsWith(const String &str) const
Returns true if a String ends with the specified String str.
A set of key/value pairs usually used to associate generic information, tags, attributes etc...