3 #include <itkObjectFactoryBase.h> 10 tinyxml2::XMLDocument doc;
11 tinyxml2::XMLError loadOk = doc.LoadFile(fileName.c_str());
13 std::replace(fileName.begin(),fileName.end(),
'\\',
'/');
14 std::string basePath, baseName;
15 std::size_t lastSlashPos = fileName.find_last_of(
"/");
17 if (lastSlashPos != std::string::npos)
18 basePath.append(fileName.begin(),fileName.begin() + lastSlashPos);
20 if (basePath.length() != 0)
21 basePath = basePath +
"/";
23 std::size_t lastDotPos = fileName.find_last_of(
".");
24 baseName.append(fileName.begin() + lastSlashPos, fileName.begin() + lastDotPos);
26 if (loadOk != tinyxml2::XML_SUCCESS)
27 return itk::ImageIOBase::UNKNOWNCOMPONENTTYPE;
30 tinyxml2::XMLElement *modelNode = doc.FirstChildElement(
"Model" );
32 return itk::ImageIOBase::UNKNOWNCOMPONENTTYPE;
34 tinyxml2::XMLElement *weightsNode = modelNode->FirstChildElement(
"Weights" );
37 return itk::ImageIOBase::UNKNOWNCOMPONENTTYPE;
39 std::string weightsFileName = basePath + baseName +
"/";
40 weightsFileName += weightsNode->GetText();
42 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(weightsFileName.c_str(),
43 itk::ImageIOFactory::ReadMode);
46 return itk::ImageIOBase::UNKNOWNCOMPONENTTYPE;
48 imageIO->SetFileName(weightsFileName.c_str());
52 imageIO->ReadImageInformation();
54 catch(itk::ExceptionObject &e)
56 return itk::ImageIOBase::UNKNOWNCOMPONENTTYPE;
59 return imageIO->GetComponentType();
itk::ImageIOBase::IOComponentType ANIMAMCM_EXPORT GetMCMComponentType(std::string fileName)