[Insight-users] Save data in binary file format in CommandIterationUpdate class

Alireza Akhondi-asl a_akhundi at yahoo.com
Mon Sep 29 11:51:27 EDT 2008


Hi
I use it in this form (but in ASCII form).
Regards
Alireza

#include <fstream> 


class CommandIterationUpdate : public itk::Command
{
public:
    typedef  CommandIterationUpdate   Self;
    typedef  itk::Command             Superclass;
    typedef itk::SmartPointer<Self>  Pointer;
    itkNewMacro( Self );
   std::ofstream out;



protected:
   CommandIterationUpdate() {out.open("results.bin",std::ios_base::binary);};
    ~CommandIterationUpdate() {out.close();};
public:
    typedef itk::PowellOptimizer         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)
    {
        OptimizerPointer optimizer =dynamic_cast< OptimizerPointer >( object );
        if( ! itk::IterationEvent().CheckEvent( &event ) )
        {
            return;
        }
        std::cout << optimizer->GetValue() << "   ";
        out << optimizer->GetValue() << "   ";
        std::cout << optimizer->GetCurrentPosition() << std::endl;
        out << optimizer->GetCurrentPosition() << std::endl;
    }
};


int main( int argc, char *argv[] )
{

.
.
.
    CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
    optimizer->AddObserver( itk::IterationEvent(), observer );
.
.
.
       std::cout <<  "final registration of all labels: " << optimizer->GetValue()  << " " <<registration->GetLastTransformParameters() << std::endl;
       observer->out <<  "final registration of all labels: " << optimizer->GetValue() << " " << registration->GetLastTransformParameters() << std::endl;

.
.
.
}



----- Original Message ----
From: Paolo <img-registration at live.com>
To: insight-users at itk.org
Sent: Monday, September 29, 2008 6:20:01 AM
Subject: [Insight-users] Save data in binary file format in CommandIterationUpdate class

 
Hello,
   as in examples, I implemented a CommandIterationUpdate class for tracking on screen the registration process.
I actually modifying my code in such a way I could provide a filename to the constructor in order to binary store the different values of the registration process at each execute call. Does someone have an idea how to do it ? I've been unsuccessful doing it until now.. :(

Thx in advance ! P.



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080929/47c2cfcd/attachment.htm>


More information about the Insight-users mailing list