1 #include <tclap/CmdLine.h> 6 #include <itkTransformFileReader.h> 7 #include <itkImageFileReader.h> 9 int main(
int ac,
const char **av)
11 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
13 TCLAP::MultiArg<std::string> inputArg(
"i",
"input",
"multiple input transform names",
true,
"input files",cmd);
14 TCLAP::MultiArg<unsigned int> invertArg(
"I",
"invert",
"multiple invert transform arguments",
false,
"invert inputs",cmd);
16 TCLAP::ValueArg<std::string> outputArg(
"o",
"output",
"output xml filename",
true,
"",
"output filename",cmd);
18 TCLAP::SwitchArg denseArg(
"D",
"dense",
"Non linear transfroms are dense fields (default: they are SVFs)",cmd,
false);
24 catch (TCLAP::ArgException& e)
26 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
30 std::vector <std::string> inputNames = inputArg.getValue();
31 std::vector <unsigned int> inputInverts = invertArg.getValue();
33 bool useInvert = (inputInverts.size() == inputNames.size());
35 std::ofstream outputFile(outputArg.getValue().c_str());
36 outputFile <<
"<?xml version=\"1.0\"?>" << std::endl;
37 outputFile <<
"<TransformationList>" << std::endl;
39 for (
unsigned int i = 0;i < inputNames.size();++i)
42 bool linearSuccess =
true;
45 itk::TransformFileReader::Pointer trReader = itk::TransformFileReader::New();
46 trReader->SetFileName(inputNames[i]);
50 catch (itk::ExceptionObject &e)
52 linearSuccess =
false;
57 outputFile <<
"<Transformation>" << std::endl;
58 outputFile <<
"<Type>linear</Type>" << std::endl;
61 outputFile <<
"<Inversion>" << inputInverts[i] <<
"</Inversion>" << std::endl;
63 outputFile <<
"<Inversion>0</Inversion>" << std::endl;
65 outputFile <<
"<Path>" << inputNames[i] <<
"</Path>" << std::endl;
66 outputFile <<
"</Transformation>" << std::endl;
72 bool nonLinearSuccess =
true;
73 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(inputNames[i].c_str(), itk::ImageIOFactory::ReadMode);
76 nonLinearSuccess =
false;
80 outputFile <<
"<Transformation>" << std::endl;
83 outputFile <<
"<Type>dense</Type>" << std::endl;
85 outputFile <<
"<Type>svf</Type>" << std::endl;
88 outputFile <<
"<Inversion>" << inputInverts[i] <<
"</Inversion>" << std::endl;
90 outputFile <<
"<Inversion>0</Inversion>" << std::endl;
92 outputFile <<
"<Path>" << inputNames[i] <<
"</Path>" << std::endl;
93 outputFile <<
"</Transformation>" << std::endl;
99 std::cerr << inputNames[i] <<
" is not a readable transform, exiting" << std::endl;
103 outputFile <<
"</TransformationList>" << std::endl;
106 std::cout <<
"Generated an XML file " << outputArg.getValue() <<
" with " << inputNames.size() <<
" transformations..." << std::endl;