[Insight-users] A question about GetCurrentPosition()

Luis Ibanez luis.ibanez at kitware.com
Fri Aug 6 22:05:22 EDT 2004


Hi Jay,

Thanks for posting your code,

Here is what seems to be happening:

     You are printing out arrays
     of parameters with zero size.

This may be happening if you are using a transform
such as the Identity transform for registration.

    1) What Transform are you using ?
    2) What ImageMetric are you using ?

Did you connect the components to the RegistrationMethod
as illustrated in the Registration chapter of the ITK
Software Guide ?


      http://www.itk.org/ItkSoftwareGuide.pdf


  Please let us know,



    Thanks


       Luis


-----------------
Jay Li wrote:

> Hi, Luis,
>  
> Sorry I didn't put my code in the previous email. Here's the code.
>  
>  
> // Class modified to save parameters in the process of registration
> class CommandIterationUpdate : public itk::Command
> {
> public:
>   typedef  CommandIterationUpdate   Self;
>   typedef  itk::Command             Superclass;
>   typedef itk::SmartPointer<Self>  Pointer;
>   itkNewMacro( Self );
>   itk::Optimizer::ParametersType  X[100]; // Array to save the first 
> parameter of GetCurrentPosition
>   double MTC[100];                        // Array to save the metric value
> protected:
>   CommandIterationUpdate() {};
> public:
>   typedef itk::RegularStepGradientDescentOptimizer     OptimizerType;
>   typedef   const OptimizerType   *    OptimizerPointer;
>   void Execute(itk::Object *caller, const itk::EventObject & event)
>     {
>       Execute( (const itk::Object *)caller, event);
>     }
>   void Execute(const itk::Object * object, const itk::EventObject & event)
>     {
>  
>   int i=0;
>       OptimizerPointer optimizer =
>         dynamic_cast< OptimizerPointer >( object );
>       if( typeid( event ) != typeid( itk::IterationEvent ) )
>         {
>         return;
>         }
>       std::cout << optimizer->GetCurrentIteration() << "   ";
>       i= optimizer->GetCurrentIteration();
>   
>    // Metric
>    std::cout << optimizer->GetValue() << "   ";
>    MTC[i] = optimizer->GetValue();
>      
>    // the first parameter of GetCurrentPosition
>    std::cout << optimizer->GetCurrentPosition()[0] << std::endl;
>    X[i] = optimizer->GetCurrentPosition()[0];
>     }
> };
>  
> // Code to save parameters to a file
>  // Print the the first parameter of GetCurrentPosition to the file
>   vcl_ofstream Parameterfile ("C:\\Angle.txt");
>   if (Parameterfile.is_open())
>   {  
>    int i = 0;
>    for(i=0;i<numberOfIterations;i++)
>    {
>          Parameterfile << observer->X[i]<<std::endl;
>          Parameterfile<< observer->MTC[i]<<std::endl;
>    }
>     Parameterfile.close();
>   }
>  
> Here's the output of the file Angle.txt
>  
> []
> 2098.33
> []
> 1840.37
> []
> 1561.14
> []
> 556.306
> []
> 492.576
> []
> 422.589
> []
> 341.925
> []
> 249.167
> []
> 131.887
> []
> 69.1155
> []
> 60.9398
> []
> 60.4099
> []
> 61.379
> []
> 60.7183
> []
> 60.3914
> []
> 60.3819
> []
> 60.3803
> []
> 60.3868
> []
> 60.3816
> []
> -6.27744e+066
> Thanks a lot.
> /Regards,/
> // 
> /Jay/
> 
> */Luis Ibanez <luis.ibanez at kitware.com>/* wrote:
> 
> 
>     Hi Jay,
> 
>     How can you get square brackets when
>     you write a number to a file ?
> 
>     Please post to the list the lines of code that
>     you are using for writing the CurrentPosition
>     to the file.
> 
>     Thanks
> 
> 
>     Luis
> 
> 
> 
>     ---------------------
>     Jay Li wrote:
> 
>      > Dear all,
>      >
>      > Here I have a question about the GetCurrentPosition().
>      > I'm trying to save the first parameter of this
>      > function to a file. I used the
>      > optimizer->GetCurrentPosition()[0] to show the first
>      > parameter on the screen, but when I tried to save it
>      > to a file, I always got squre brackets. I also tried
>      > to save GetCurrentPosition()[1], this time it gave me
>      > an array of a lot numbers with the same value
>      > -6.27744e+066. Could anyone please give me some hints?
>      >
>      > Thanks a lot!
>      >
>      > Jay
>      >
>      >
> 
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users






More information about the Insight-users mailing list