[Insight-users] Tcl wrapping: How to add Observers to Registration
methods.
Luis Ibanez
luis.ibanez@kitware.com
Sat, 12 Apr 2003 18:17:37 -0400
Hi Frank,
You may want to take a look at the Tcl example in
Insight/Wrapping/Tcl/Executable/curvatureFlow.tcl
---
1) In order to connect an Observer to an ITK filter,
you define a Tcl procedure and define this procedure
as the callback for the observer.
It will look like:
$filter AddObserver [itk::ProgressEvent] [itk::createTclCommand {
set p [$filter GetProgress]
set percent [expr {$p * 100}]
setProgress $percent
}]
where "setProgress" is a Tcl procedure that you
can define.
2) The examples in
Insight/Examples/Regitration/ImageRegistration*.tcl
have been updated in order to use an observer and
report the evolution of the transform parameters.
3) About setting the parameters of the transform,
both in C++ and Tcl, the simplest way is to use
the native methods of each transform in order to
define the initial transformation. Once you configure
the transform, you can call GetParameters in this
transform and pass the paramteres to the registration
method using SetInitialTransformParamters().
The parameters array is a serialization of the
transform, it is not intended to be human-readable,
but rather optimizer-readable. It is then pretty
hard to figure out the rigth parameter array even
for simple transforms like the CenteredRigid2D
transforms.
Regards
Luis
-------------------------------------
Frank Lindseth wrote:
> Thanks a lot Luis, I got a bit further.
>
> How am I supposed to set the elements of the transform-parameters (see
> below)?
> And what about setting/getting the offset/itk::Vector elements ?
> For itk::Matrix it looks like I an not able to create an object in TCL,
> is there a general description of
> the mapping between templated C++ and TCL somewhere?
>
> Also, I want to add an optimizer-observer that can print the
> metric-value and transform between
> iterations (in tcl). The C++ code is included below, I have not managed
> to map it to tcl get.
>
> Regards,
>
> Frank
>
> % set t [ itk::create AffineTransform3 ]
> % $t SetIdentity
> % set p [$t GetParameters]
> % puts [$p () 0]
> 1.0
> % set [$p () 0] 0.5
> ------> Obviously not the correct way.
>
> % set o [$t GetOffset]
> % puts [$o () 0]
> No method matches itk::Vector<double,3>::()(int) const
> ------> Obviously not the correct way.
>
> % set m [$t GetMatrix]
> % puts [$m () 0]
> invalid command name "_cxx0x3be9ef0"
> ------> Obviously not the correct way.
>
> % set mm [itk::create Matrix33]
> invalid command name "itk::Matrix33"
>
>
> Observer
> -----------------------------------------------------------------
> typename CommandType::Pointer cmdOptimizer = CommandType::New();
> cmdOptimizer->SetCallbackFunction( this, &Self::optimizerCB );
>
>
> m_cmdOptTag = m_Optimizer->AddObserver( IterationEvent(), cmdOptimizer );
>
>
> ---
> template <typename TFixedImage, typename TMovingImage>
> void
> MIMRegistrator<TFixedImage,TMovingImage>
> ::optimizerCB()
> {
> std::cout << m_Optimizer->GetCurrentIteration() << " = ";
> std::cout << m_Optimizer->GetValue() << " : ";
> std::cout << m_Optimizer->GetCurrentPosition();
> }
>
>