6 #include <itkTransformFileReader.h> 7 #include <itkImageFileReader.h> 9 #include <itkMatrixOffsetTransformBase.h> 10 #include <itkStationaryVelocityFieldTransform.h> 11 #include <rpiDisplacementFieldTransform.h> 17 template <
class TScalarType,
unsigned int NDimensions>
21 m_OutputTransform = NULL;
22 m_InvertTransform =
false;
24 m_ExponentiationOrder = 1;
25 m_NumberOfThreads = itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads();
28 template <
class TScalarType,
unsigned int NDimensions>
35 template <
class TScalarType,
unsigned int NDimensions>
40 m_OutputTransform = OutputTransformType::New();
41 std::vector <TransformInformation> transformationList;
43 tinyxml2::XMLDocument doc;
44 tinyxml2::XMLError loadOk = doc.LoadFile(m_Input.c_str());
46 if (loadOk != tinyxml2::XML_SUCCESS)
48 std::string error(
"Unable to read input summary file: ");
50 throw itk::ExceptionObject(__FILE__, __LINE__,error,ITK_LOCATION);
54 tinyxml2::XMLElement *rootNode = doc.FirstChildElement(
"TransformationList" );
58 tinyxml2::XMLElement *trsfNode = rootNode->FirstChildElement(
"Transformation");
63 tinyxml2::XMLElement *typeNode = trsfNode->FirstChildElement(
"Type");
65 throw itk::ExceptionObject(__FILE__, __LINE__,
"Type of transformation not found for a transform in the list",ITK_LOCATION);
67 std::string typeStr = typeNode->GetText();
68 typeStr = typeStr.substr(typeStr.find_first_not_of(
" \n\r\t"));
69 typeStr.erase(typeStr.find_last_not_of(
" \n\r\t")+1);
71 if (typeStr ==
"linear")
73 else if (typeStr ==
"svf")
74 infoTrsf.
trType = SVF_FIELD;
75 else if (typeStr ==
"dense")
76 infoTrsf.
trType = DENSE_FIELD;
79 std::string error(
"Transformation type ");
81 error +=
" not supported...";
82 throw itk::ExceptionObject(__FILE__, __LINE__,error,ITK_LOCATION);
85 tinyxml2::XMLElement *invertNode = trsfNode->FirstChildElement(
"Inversion");
88 std::string invertValue = invertNode->GetText();
89 infoTrsf.
invert = (invertValue !=
"0");
94 if (m_InvertTransform)
97 tinyxml2::XMLElement *fileNode = trsfNode->FirstChildElement(
"Path");
99 throw itk::ExceptionObject(__FILE__, __LINE__,
"File name not found for a transform in the list",ITK_LOCATION);
101 infoTrsf.
fileName = fileNode->GetText();
105 transformationList.push_back(infoTrsf);
107 trsfNode = trsfNode->NextSiblingElement(
"Transformation");
115 if (m_InvertTransform)
117 for (
int i = transformationList.size() - 1;i >= 0;--i)
119 switch (transformationList[i].trType)
122 this->addLinearTransformation(transformationList[i].fileName,transformationList[i].invert);
126 this->addSVFTransformation(transformationList[i].fileName,transformationList[i].invert);
131 this->addDenseTransformation(transformationList[i].fileName,transformationList[i].invert);
138 for (
unsigned int i = 0;i < transformationList.size();++i)
140 switch (transformationList[i].trType)
143 this->addLinearTransformation(transformationList[i].fileName,transformationList[i].invert);
147 this->addSVFTransformation(transformationList[i].fileName,transformationList[i].invert);
152 this->addDenseTransformation(transformationList[i].fileName,transformationList[i].invert);
158 std::cout <<
"Loaded " << m_OutputTransform->GetNumberOfTransforms() <<
" transformations from transform list file: " << m_Input << std::endl;
161 template <
class TScalarType,
unsigned int NDimensions>
166 typedef itk::MatrixOffsetTransformBase <TScalarType,NDimensions> MatrixTransformType;
167 typedef typename MatrixTransformType::Pointer MatrixTransformPointer;
169 itk::TransformFileReader::Pointer reader = itk::TransformFileReader::New();
170 reader->SetFileName(fileName);
173 const itk::TransformFileReader::TransformListType *trsfList = reader->GetTransformList();
174 itk::TransformFileReader::TransformListType::const_iterator tr_it = trsfList->begin();
176 MatrixTransformPointer trsf = dynamic_cast <MatrixTransformType *> ((*tr_it).GetPointer());
180 MatrixTransformPointer tmpInvert = MatrixTransformType::New();
181 trsf->GetInverse(tmpInvert);
186 m_OutputTransform->AddTransform(trsf);
189 template <
class TScalarType,
unsigned int NDimensions>
194 typedef rpi::DisplacementFieldTransform <TScalarType,NDimensions> DenseTransformType;
195 typedef typename DenseTransformType::Pointer DenseTransformPointer;
196 typedef typename DenseTransformType::VectorFieldType DisplacementFieldType;
198 typedef itk::ImageFileReader<DisplacementFieldType> DispReaderType;
199 typename DispReaderType::Pointer trReader = DispReaderType::New();
200 trReader->SetFileName(fileName);
203 DenseTransformPointer dispTrsf = DenseTransformType::New();
204 dispTrsf->SetParametersAsVectorField(trReader->GetOutput());
208 DenseTransformPointer tmpInvert = DenseTransformType::New();
209 dispTrsf->GetInverse(tmpInvert);
211 dispTrsf = tmpInvert;
214 m_OutputTransform->AddTransform(dispTrsf);
217 template <
class TScalarType,
unsigned int NDimensions>
222 typedef itk::StationaryVelocityFieldTransform <TScalarType,NDimensions> SVFTransformType;
223 typedef typename SVFTransformType::Pointer SVFTransformPointer;
224 typedef typename SVFTransformType::VectorFieldType VelocityFieldType;
226 typedef rpi::DisplacementFieldTransform <TScalarType,NDimensions> DenseTransformType;
227 typedef typename DenseTransformType::Pointer DenseTransformPointer;
229 typedef itk::ImageFileReader<VelocityFieldType> SVFReaderType;
230 typename SVFReaderType::Pointer trReader = SVFReaderType::New();
231 trReader->SetFileName(fileName);
234 SVFTransformPointer svfPointer = SVFTransformType::New();
235 svfPointer->SetParametersAsVectorField(trReader->GetOutput());
237 DenseTransformPointer dispTrsf = DenseTransformType::New();
238 anima::GetSVFExponential(svfPointer.GetPointer(),dispTrsf.GetPointer(),m_ExponentiationOrder,m_NumberOfThreads,invert);
240 m_OutputTransform->AddTransform(dispTrsf);
void GetSVFExponential(itk::StationaryVelocityFieldTransform< ScalarType, NDimensions > *baseTrsf, rpi::DisplacementFieldTransform< ScalarType, NDimensions > *resultTransform, unsigned int exponentiationOrder, unsigned int numThreads, bool invert)