1 /*=========================================================================
3 * Copyright RTK Consortium
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *=========================================================================*/
19 #include "rtkImagXXMLFileReader.h"
22 #include <itksys/SystemTools.hxx>
23 #include <itkMetaDataObject.h>
30 CanReadFile(const char *name)
32 if(!itksys::SystemTools::FileExists(name) ||
33 itksys::SystemTools::FileIsDirectory(name) ||
34 itksys::SystemTools::FileLength(name) == 0)
41 StartElement(const char * name, const char ** atts)
43 #define ENCAPLULATE_META_DATA_INT(metaName) \
44 if(itksys::SystemTools::Strucmp(atts[i], metaName) == 0) { \
45 double d = atof(atts[i+1]); \
46 itk::EncapsulateMetaData<int>(m_Dictionary, metaName, d); \
49 #define ENCAPLULATE_META_DATA_STRING(metaName) \
50 if(itksys::SystemTools::Strucmp(atts[i], metaName) == 0) { \
51 itk::EncapsulateMetaData<std::string>(m_Dictionary, metaName, atts[i+1]); \
54 if(std::string(name) == std::string("image") )
56 for(int i=0; atts[i] != NULL; i+=2)
58 ENCAPLULATE_META_DATA_STRING("name");
59 ENCAPLULATE_META_DATA_INT("bitDepth");
60 ENCAPLULATE_META_DATA_STRING("pixelFormat");
61 ENCAPLULATE_META_DATA_STRING("byteOrder");
62 ENCAPLULATE_META_DATA_STRING("modality");
63 ENCAPLULATE_META_DATA_STRING("matrixTransform");
64 ENCAPLULATE_META_DATA_INT("dimensions");
65 ENCAPLULATE_META_DATA_INT("sequence");
66 ENCAPLULATE_META_DATA_STRING("rawFile");
69 if(std::string(name) == std::string("size") )
71 for(int i=0; atts[i] != NULL; i+=2)
73 ENCAPLULATE_META_DATA_INT("x");
74 ENCAPLULATE_META_DATA_INT("y");
75 ENCAPLULATE_META_DATA_INT("z");
78 if(std::string(name) == std::string("spacing") )
80 #define ENCAPLULATE_META_DATA_DOUBLE(metaName) \
81 if(itksys::SystemTools::Strucmp(atts[i], metaName) == 0) { \
82 double d = atof(atts[i+1]); \
83 itk::EncapsulateMetaData<double>(m_Dictionary, std::string("spacing_") + std::string(metaName), d); \
85 for(int i=0; atts[i] != NULL; i+=2)
87 ENCAPLULATE_META_DATA_DOUBLE("x");
88 ENCAPLULATE_META_DATA_DOUBLE("y");
89 ENCAPLULATE_META_DATA_DOUBLE("z");
92 m_CurCharacterData = "";
97 EndElement(const char *name)
103 CharacterDataHandler(const char *inData, int inLength)
105 for(int i = 0; i < inLength; i++)
106 m_CurCharacterData = m_CurCharacterData + inData[i];