[Insight-users] Viewer Question

Luis Ibanez luis . ibanez at kitware . com
Tue, 10 Jun 2003 20:17:26 -0400


Hi Zein,


You may avoid many problems if you think of your
application as a state machine, and implement it
in the form of a C++ class, for example:

A) Make m_Viewer a member variable of
    your "MyApplicationBase" class.
    e.g.

    class MyApplicationBase {
    public:
       MyViewerType * m_Viewer
       ....
     };


   [NOTE that actualy the notation "m_" is
   reserved for member variable. It is a way
   to differentiate them from local variables.



B) Move the instantiation line:

       m_Viewer = new MyViewerType;

    To the constructor of "MyApplicationBase"



C) Then go to the destructor of MyApplicationBase
    and add a line

        delete m_Viewer;


D) Finally in your method ShowSegmentedImage()
    just do


    m_Viewer->SetImage(m_InputImage);   //m_InputImage is  global
    m_Viewer->SetOverlay1(m_Image);
    m_Viewer->SetLabel(m_Label);
    m_Viewer->Show();



E)  Please don't use globals (like m_InputImage) in your code
     this is a very bad practice, instead, make this input image
     to be a member variable of your class.




With these changes your viewer will be permanently available
in your class, and will popup whenever you need to show a
segmentation. There is not need for constructing and destroying
a viewer each time.


    Regards,


     Luis


--------------------
salah wrote:
> Hello all, 
> 
> I have in my program a method that displays a 3d itk
> image. It simply uses a viewer that is based on the 
> GLSliceView. My method has two inputs: the image
> to display and a label. This is its implementation: 
> 
> void MyApplicationBase::ShowSegmentedImage(const ImageType::Pointer m_Image, char *m_Label )
> {  
> 
>   typedef ice::MyViewer<ImageType, ImageType> MyViewerType;
> 
>   MyViewerType * m_Viewer = new MyViewerType;
> 
>   m_Viewer->SetImage(m_InputImage);   //m_InputImage is  global
>   m_Viewer->SetOverlay1(m_Image);
>   m_Viewer->SetLabel(m_Label);
>   m_Viewer->Show();
>   
> }
> ---------------------------------------------------------------------------------------
> Using this implementation, each time this method is called,
> an instant of the Viewer is created dynamicaly, its parameters
> are defined and the image is shows. 
> Question:
> How can make this code desctruct the created instant soon after
> I close the viewer window??
> 
> Thanks...
> Zein
> _______________________________________________
> Insight-users mailing list
> Insight-users at www . itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>