[Insight-users] fltk viewer

Samuel Rodríguez Bescos srodrigu@gbt.tfo.upm.es
Wed, 18 Sep 2002 13:17:11 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C25F15.B29D4B40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I think the problem is realted with the fltk. You want the program  =
finish when you close the Viewer window. Don't you?.
For that, I think  you have to write the next code line:

........previous code.......

m_AnyViewer->Show();

Fl::run();   ***This line makes that the program doesn't continue until =
all the windows of your program are closed.****

(.....) more code.....


 I hope this help you,

Samuel
  ----- Original Message -----=20
  From: Zein Salah=20
  To: ITK Users=20
  Sent: Wednesday, September 18, 2002 12:34 PM
  Subject: [Insight-users] fltk viewer


  Hello friends,

  I have written a very simple program that just reads a meta file and =
displays it using the fltkimage viewer.

  the program reads the file correctly, displays it. BUT I can not see =
the displayed files because the fltk viewer panel ends execution very =
fast, it just flashes once and then disappears.

  Do anybody have an idea, where the problem is.=20

  Here is my program:

  =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
  #include <iostream>

  #include <itkImage.h>
  #include <itkImageFileReader.h>
  #include <fltkImageViewer.h>

  #include <FL/Fl.H>
  #include <FL/fl_file_chooser.H>


  ///////////////////////////////////////////////////////////
  void LoadShowImage(char *filename)
  {

    typedef fltk::ImageViewer< float, unsigned char >      =
ImageViewerType;
    typedef float                                                        =
   PixelType;
    typedef itk::Image<PixelType, 3>                             =
ImageType;=20
    typedef itk::ImageFileReader< ImageType >              =
VolumeReaderType;

     std::cout << "Loading File: " << filename << std::endl;
     VolumeReaderType::Pointer   m_Reader =3D VolumeReaderType::New();
     m_Reader->SetFileName( filename );
     m_Reader->Update();

     ImageViewerType  *m_AnyViewer=3D new ImageViewerType;
     m_AnyViewer->SetImage( m_Reader->GetOutput() );
     m_AnyViewer->Show();

     std::cout << "Image [ " << filename << " ] Showed ..." << =
std::endl;

  }

  ////////////////////////////////////////////////////////////
  int main(int argc, char **argv)
  {
     char *fName;
  =20
     if(argc =3D=3D 1)
     {
        fName =3D fl_file_chooser("Pick a MetaImage file", "*.mh*", =
".");
        if(fName =3D=3D NULL || strlen(fName)<1)
        {
           return 0;
        }
     } else if(argv[1][0] !=3D '-') {
        fName =3D argv[argc-1];
     }=20

     LoadShowImage(fName);
   =20
     return 1;
  }




  =
->8<------------->8<------------->8<------------->8<------------->8<-----=
-------->8<-
  Zein I. Salah=20
  Universit=E4t T=FCbingen, WSI-GRIS=20
  Sand 14=20
  72076 T=FCbingen=20
  Email: salah@gris.uni-tuebingen.de  / zeinsalah@hotmail.com
  Tel.: (07071) 29 75465 (GRIS) , (07071) 96 44 39 (privat)=20

------=_NextPart_000_0010_01C25F15.B29D4B40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I think the problem is realted with the =
fltk. You=20
want the program&nbsp; finish when you close the Viewer window. Don't=20
you?.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>For that, I think &nbsp;you have to =
write the next=20
code line:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>........previous =
code.......</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial color=3D#ff0000 =
size=3D2>m_AnyViewer-&gt;Show();</FONT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Fl::run();&nbsp;&nbsp; ***<FONT =
face=3DArial=20
size=3D2>This line makes that the program doesn't continue until all the =
windows=20
of your program are closed.****</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>(.....) more code.....</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;I hope this help =
you,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Samuel</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dsalah@gris.uni-tuebingen.de=20
  href=3D"mailto:salah@gris.uni-tuebingen.de">Zein Salah</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20
  title=3Dinsight-users@public.kitware.com=20
  href=3D"mailto:insight-users@public.kitware.com">ITK Users</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, September 18, =
2002 12:34=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Insight-users] fltk=20
viewer</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>Hello friends,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>I have written&nbsp;a very simple =
program that=20
  just reads a meta file and displays it using the fltkimage=20
viewer.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>the program reads the file correctly, =
displays=20
  it. BUT I can not see the displayed files because the fltk viewer =
panel ends=20
  execution very fast, it just flashes once and then =
disappears.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Do anybody have an idea, where the =
problem is.=20
  </FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Here is my program:</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#ff0000=20
  =
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D*/<BR>#include=20
  &lt;iostream&gt;</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#ff0000 size=3D2>#include=20
  &lt;itkImage.h&gt;<BR>#include =
&lt;itkImageFileReader.h&gt;<BR>#include=20
  &lt;fltkImageViewer.h&gt;</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#ff0000 size=3D2>#include=20
  &lt;FL/Fl.H&gt;<BR>#include &lt;FL/fl_file_chooser.H&gt;</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2>
  <DIV><BR><FONT=20
  =
color=3D#ff0000>/////////////////////////////////////////////////////////=
//<BR>void=20
  LoadShowImage(char *filename)<BR>{</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#ff0000>&nbsp; typedef fltk::ImageViewer&lt; float, =
unsigned=20
  char &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageViewerType;<BR>&nbsp; =
typedef=20
  =
float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
  PixelType;<BR>&nbsp; typedef itk::Image&lt;PixelType,=20
  =
3&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;=20
  &nbsp; ImageType; <BR>&nbsp; typedef itk::ImageFileReader&lt; =
ImageType=20
  =
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;=20
  VolumeReaderType;</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#ff0000>&nbsp;&nbsp; std::cout &lt;&lt; "Loading =
File: "=20
  &lt;&lt; filename &lt;&lt; std::endl;<BR>&nbsp;&nbsp;=20
  VolumeReaderType::Pointer&nbsp;&nbsp; m_Reader =3D=20
  VolumeReaderType::New();<BR>&nbsp;&nbsp; m_Reader-&gt;SetFileName( =
filename=20
  );<BR>&nbsp;&nbsp; m_Reader-&gt;Update();</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#ff0000>&nbsp;&nbsp; ImageViewerType&nbsp; =
*m_AnyViewer=3D new=20
  ImageViewerType;<BR>&nbsp;&nbsp; m_AnyViewer-&gt;SetImage(=20
  m_Reader-&gt;GetOutput() );<BR>&nbsp;&nbsp;=20
  m_AnyViewer-&gt;Show();</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#ff0000>&nbsp;&nbsp; std::cout &lt;&lt; "Image [ " =
&lt;&lt;=20
  filename &lt;&lt; " ] Showed ..." &lt;&lt; std::endl;</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#ff0000>}</FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT=20
  =
color=3D#ff0000>/////////////////////////////////////////////////////////=
///<BR>int=20
  main(int argc, char **argv)<BR>{<BR>&nbsp;&nbsp; char=20
  *fName;<BR>&nbsp;<BR>&nbsp;&nbsp; if(argc =3D=3D 1)<BR>&nbsp;&nbsp;=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fName =3D fl_file_chooser("Pick a =
MetaImage=20
  file", "*.mh*", ".");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(fName =
=3D=3D NULL ||=20
  strlen(fName)&lt;1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
  0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; } else =
if(argv[1][0] !=3D=20
  '-') {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fName =3D =
argv[argc-1];<BR>&nbsp;&nbsp;=20
  } </FONT></DIV>
  <DIV><FONT color=3D#ff0000></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#ff0000>&nbsp;&nbsp; =
LoadShowImage(fName);<BR>&nbsp;=20
  <BR>&nbsp;&nbsp; return 1;<BR>}<BR></FONT></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial=20
  =
size=3D2>-&gt;8&lt;-------------&gt;8&lt;-------------&gt;8&lt;----------=
---&gt;8&lt;-------------&gt;8&lt;-------------&gt;8&lt;-<BR>Zein=20
  I. Salah <BR>Universit=E4t T=FCbingen, WSI-GRIS <BR>Sand 14 <BR>72076 =
T=FCbingen=20
  <BR>Email: <A=20
  =
href=3D"mailto:salah@gris.uni-tuebingen.de">salah@gris.uni-tuebingen.de</=
A>&nbsp;=20
  / <A =
href=3D"mailto:zeinsalah@hotmail.com">zeinsalah@hotmail.com</A><BR>Tel.: =

  (07071) 29 75465 (GRIS) , (07071) 96 44 39 (privat)=20
</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0010_01C25F15.B29D4B40--