How to get intermediate transform parameter?

Hi,
I am following the example DeformableRegistration12 : ITK: Examples/RegistrationITKv4/DeformableRegistration12.cxx , to register two images. Is there any way to get the intermediate transform parameters or intermediate registered image after each iteration.

Thanks,

Have you tried adding OptimizerType::ParametersType finalParameters = transform->GetParameters(); or writing the transform to file somwhere here? You will need access to transform, either by making a global parameter or saving a pointer to it in CommandIterationUpdate class.

I tried to add it in here as follows.

class CommandIterationUpdate : public itk::Command
{
public:
  using Self = CommandIterationUpdate;
  using Superclass = itk::Command;
  using Pointer = itk::SmartPointer<Self>;
  itkNewMacro(Self);

protected:
  CommandIterationUpdate() = default;

public:
  using OptimizerType = itk::LBFGSBOptimizerv4;
  using OptimizerPointer = const OptimizerType *;
  using TransformType = itk::BSplineTransform<double, 2, 3>;
  using TransformPointer = const TransformType *;

  void
  Execute(itk::Object * caller, const itk::EventObject & event) override
  {
    Execute((const itk::Object *)caller, event);
  }

  void
  Execute(const itk::Object * object, const itk::EventObject & event) override
  {
    auto optimizer = static_cast<OptimizerPointer>(object);
    auto transform = static_cast<TransformPointer>(object);
    if (!(itk::IterationEvent().CheckEvent(&event)))
    {
      return;
    }
    std::cout << optimizer->GetCurrentIteration() << "   ";
    std::cout << optimizer->GetCurrentMetricValue() << "   ";
    std::cout << optimizer->GetInfinityNormOfProjectedGradient() << std::endl;
    auto finalParameters = transform->GetParameters();
    std::cout <<finalParameters;
  }
};

But it is throwing the following error.

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

And i tried to create another class CommandIterationUpdate for transform. But it is not giving printing the parameter value.

class CommandIterationUpdate1 : public itk::Command
{
public:
  using Self = CommandIterationUpdate1;
  using Superclass = itk::Command;
  using Pointer = itk::SmartPointer<Self>;
  itkNewMacro(Self);

protected:
  CommandIterationUpdate1() = default;

public:
  using TransformType = itk::BSplineTransform<double, 2, 3>;
  using TransformPointer = const TransformType *;

  void
  Execute(itk::Object * caller, const itk::EventObject & event) override
  {
    Execute((const itk::Object *)caller, event);
  }

  void
  Execute(const itk::Object * object, const itk::EventObject & event) override
  {
(object);
    auto transform = static_cast<TransformPointer>(object);
    if (!(itk::IterationEvent().CheckEvent(&event)))
    {
      return;
    }
    auto finalParameters = transform->GetParameters();
    std::cout <<finalParameters;
  }
};