[Insight-users] A question about GetCurrentPosition()

Jay Li chyumm at yahoo.com
Wed Aug 4 11:30:05 EDT 2004


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 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20040804/5ae5a752/attachment.htm


More information about the Insight-users mailing list