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