Troble loading and reading LinearTransform.h5

Hello, everyone.

I am implementing a pipeline to load a LinearTransform.h5 and convert that into a displacement field. However, I am having a problem loading the transform into a real transform object-pointer to proceed. Please take a look into (part of) code:

#include "itkVersorRigid3DTransform.h"

#include <iostream>
#include <fstream>

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkTransformFileReader.h"
#include "itkImageRegionIterator.h"

    > // Writing Transform
    >   using TransformReaderType = itk::TransformFileReaderTemplate<double>;
    >   TransformReaderType::Pointer transformReader = TransformReaderType::New();
    >   transformReader->SetFileName(argv[3]);
    >   transformReader->Update();
    > 
    >   TransformReaderType::TransformListType * transforms = transformReader->GetTransformList();
    >   auto it = transforms->begin();
    >   std::cout<< "Size:" << (*it). << std::endl;
    > 
    >   // Creating and writing the displacement vector image
    >   // Based on example: https://itk.org/Doxygen/html/Examples_2RegistrationITKv3_2DeformableRegistration8_8cxx-example.html
    > 
    >   using VectorType = itk::Vector<float, Dimension>;
    >   using DisplacementFieldType = itk::Image<VectorType, Dimension>;
    >   DisplacementFieldType::Pointer field = DisplacementFieldType::New();
    >   field->SetRegions(fixedImageReader->GetOutput()->GetBufferedRegion());
    >   field->SetSpacing(fixedImageReader->GetOutput()->GetSpacing());
    >   field->SetOrigin(fixedImageReader->GetOutput()->GetOrigin());
    >   field->SetDirection(fixedImageReader->GetOutput()->GetDirection());
    >   field->Allocate();
    > 
    >   using FieldIteratorType = itk::ImageRegionIterator<DisplacementFieldType>;
    >   FieldIteratorType fi( field, movingImageReader->GetOutput()->GetBufferedRegion());
    >   fi.GoToBegin();
    > 
    >   using TransformType = itk::VersorRigid3DTransform<double>;
    >   TransformType::InputPointType movingPoint;
    >   TransformType::OutputPointType transformedPoint;
    >   DisplacementFieldType::IndexType index;
    >   TransformType::Pointer transform = TransformType::New();
    > 
    > 
    >   VectorType displacement;
    > 
    >   while( !fi.IsAtEnd()){
    >       index = fi.GetIndex();
    >       field->TransformIndexToPhysicalPoint( index, movingPoint );
    >       transforms->begin();
    >       transformedPoint = transforms-> ->TransformPoint( movingPoint );
    >       displacement = transformedPoint - movingPoint;
    >       fi.Set(displacement);
    >       ++fi;
    >   }
    > 
    >   using FieldWriterType = itk::ImageFileWriter<DisplacementFieldType>;
    >   FieldWriterType::Pointer fieldWriter = FieldWriterType::New();
    >   fieldWriter->SetInput(field);
    >   fieldWriter->SetFileName(imagePath + "dispField-q=" + id + ".nrrd");
    >   fieldWriter->Update();
    >   

Thanks in advance!

And what is the problem with this code?

using TransformType = itk::VersorRigid3DTransform<double>;
TransformType::InputPointType movingPoint; 
TransformType::OutputPointType transformedPoint; 
DisplacementFieldType::IndexType index; 
TransformType::Pointer transform = TransformType::New();

The problem is : I do not know how to connect correctly the transform-input-file that I read with the transform pointer object that i created in this last line (above).

Have you seen this example?

Yes, I did read.
Although I got confused with the Idea of reading a List o transforms. I am loading just one. Do we always have to go through a loop to read a single object?

I guess I got it. I read, and then I do a cast to the type I am working (Versor3D).
Although, when I ask the object to print its name class and type it prints as the reader did (Affine), not the type I casted (Versor3D).

Any suggestion?
Thanks.

If affine is what is written in the file, and you want versor, you could read an affine transform and then convert it into versor representation.

All right I did exactly as the example mentioned, Sounds to work at the beginning, But it yelds an error:

tk::ERROR: ImageFileWriter(0x559f0f047c70): Largest possible region does not fully contain requested paste IO regionPaste IO region: ImageIORegion (0x7fff26c0cf20)
      Dimension: 3
      Index: 0 0 0 
      Size: 0 0 0 
    Largest possible region: ImageRegion (0x7fff26c0cfc0)
      Dimension: 3
      Index: [0, 0, 0]
      Size: [0, 0, 0]

Do not know why.

That error is coming from an Image, not a Transform, suggesting the mistake is elsewhere.