[Insight-users] Using observer on Transform?
Luis Ibanez
luis.ibanez at kitware.com
Tue Apr 20 12:25:03 EDT 2010
Hi Motes,
The optimizer (by design) doesn't
know anything about the Transforms.
This is basically guided by the SRP
"Single Responsibility Principle"
http://en.wikipedia.org/wiki/Single_responsibility_principle
that is:
one class should do only one thing
and should do it well.
What you may want to do is to simply
customize the Command Observer
to take a pointer to the Transform
as part of the set up procedure.
Then, every time that you get an
event, you could access the Transform
via the extra pointer that you hold.
Note however, that depending of the
optimizer that you are using, you may
NOT want to modify the transform,
and instead you may have to stick to
read-only operations.
For example, the amoeba optimizer
and the OnePlusOneEvolutionary
optimizers will perform intermediate
evaluations of the Metric (and therefore
will use intermediate settings of the
transform) in between sending iterations
events.
Your observer could look like the following
pseudo-code
class myObserver: public Command
{
void SetTransform( const TransformType * tt )
{ this->myTransform = tt; }
void Execute(...blah..)
{
this->myTransform->Print( std::cout );
// or any other const call to the transform API
}
private:
TransformType::ConstPointer myTransform;
};
and in your code you will have to remember to
call SetTransform() in the observer before you
run the registration process.
Regards,
Luis
---------------------------------------------------
On Tue, Apr 20, 2010 at 8:43 AM, motes motes <mort.motes at gmail.com> wrote:
> Typically an observer is connected to an optimizer like:
>
> optimizer->SetNumberOfIterations(number_of_iterations);
> optimizer->MinimizeOn();
> optimizer->AddObserver(itk::IterationEvent(), observer);
>
>
> In the observer its then possible to retrieve the optimizer and read
> (or even modify) the parameters:
>
> void Execute( itk::Object * object, const itk::EventObject &
> event) {
> OptimizerPointer optimizer = dynamic_cast<
> OptimizerPointer >( object );
> if( ! itk::IterationEvent().CheckEvent( &event ) ) {
> return;
> }
> std::cout << optimizer->GetCurrentIteration() << " =
> " <<
> optimizer->GetValue() << " : " << optimizer->GetCurrentPosition() <<
> std::endl;
> // do modifications...
>
>
>
> Now I would like to be able to do the the same thing with a transform
> that I have made.
>
> What I need is to modify some parameters in the transform after a
> certain number of iterations. Is it somehow possible to get the
> transform connected to the image registration method in the above
> Execute method in each iteration?
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100420/c0ff7139/attachment.htm>
More information about the Insight-users
mailing list