Skip to content

Commit

Permalink
ENH: Refactor antsTransformInfo to add some error handling and comput…
Browse files Browse the repository at this point in the history
…e determinant
  • Loading branch information
gdevenyi committed May 30, 2024
1 parent 35d9381 commit b8e9b5d
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions Examples/antsTransformInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "antsCommandLineParser.h"
#include "itkTransformFileReader.h"
#include "itkAffineTransform.h"


#include <sstream>

Expand Down Expand Up @@ -72,16 +74,52 @@ antsTransformInfo(std::vector<std::string> args, std::ostream * /*out_stream = n
};
Cleanup_argv cleanup_argv(argv, argc + 1);

using ReadScalarType = double;

for (int i = 1; i < argc; i++)
{

std::cout << "Transform file: " << argv[i] << std::endl;

itk::TransformFileReader::Pointer reader = itk::TransformFileReader::New();
using TransformReaderType = itk::TransformFileReaderTemplate<ReadScalarType>;
auto reader = TransformReaderType::New();

reader->SetFileName(argv[i]);
reader->Update();
try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error while reading the transform file" << std::endl;
std::cerr << excp << std::endl;
std::cerr << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

const TransformReaderType::TransformListType * transforms = reader->GetTransformList();
std::cout << "Number of transforms = " << transforms->size() << std::endl;

std::cout << *(reader->GetTransformList()->begin()) << std::endl;
unsigned int Dimension = transforms->front()->GetInputSpaceDimension();


for (auto it = transforms->begin(); it != transforms->end(); ++it)
{
if (Dimension == 3)
{
using TransformType3D = itk::MatrixOffsetTransformBase<double, 3, 3>;
TransformType3D* itktx3d = dynamic_cast<TransformType3D*>((*it).GetPointer());
itktx3d->Print(std::cout);
std::cout << "Determinant: " << vnl_determinant(itktx3d->GetMatrix().GetVnlMatrix()) << std::endl;
}
else if (Dimension == 2)
{
using TransformType2D = itk::MatrixOffsetTransformBase<double, 2, 2>;
TransformType2D* itktx2d = dynamic_cast<TransformType2D*>((*it).GetPointer());
itktx2d->Print(std::cout);
std::cout << "Determinant: " << vnl_determinant(itktx2d->GetMatrix().GetVnlMatrix()) << std::endl;
}
}
}

return EXIT_SUCCESS;
Expand Down

0 comments on commit b8e9b5d

Please sign in to comment.