[Insight-users] getting started II

Iván Macía imacia at vicomtech.es
Mon Mar 14 09:01:27 EST 2005


Hi Laurent,

You should use

 reader->SetFileName ( argv[1] );    

instead of 

 reader->SetFileName ( "argv[1]" );  

Don't forget either to delete the allocated memory for vtk objects

 renderWindowInteractor->Start();
 
 viewer->Delete();
 renderWindowInteractor->Delete();

 return 0;

Hope that helps

Ivan
 
 
 
     
-----Mensaje original-----
De: insight-users-bounces at itk.org [mailto:insight-users-bounces at itk.org]
En nombre de laurent.paul at club-internet.fr
Enviado el: lunes, 14 de marzo de 2005 15:09
Para: insight-users at itk.org
Asunto: [Insight-users] getting started II


Hi!

I'm new in the ITK community. So i began by getting started. 
I got a problem with the second lesson.
I create the Cmakelists, no problem.
I create the myproject.cxx, no problem.
When I compile, no problem. I copied itkImageToVTKImageFilter.h,
itkImageToVTKImageFilter.txx, itkVTKImageToImageFilter.h,
itkVTKImageToImageFilter.txx in my source directory. 
I run the myproject.exe in a cmd window giving an image as argument.
At run time, the program crashes. The following pop-up message appears:

Debug error!
Program : C:\...\myproject.exe
Abnormal program termination
Abandon    Retry    Ignore

When i modify the source code, giving the file name in the SetFileName()
method, the program runs and display the requested image.

Perhaps I give a false argument to the program, so it can't open the
file...?

Here the code used:

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"

int main( int argc, char **argv)
{
    typedef itk::Image <unsigned char,2> ImageType;   //short
    typedef itk::ImageFileReader <ImageType> ReaderType;
    typedef itk::ImageToVTKImageFilter <ImageType> ConnectorType;

    ReaderType::Pointer reader = ReaderType::New();
    ConnectorType::Pointer connector = ConnectorType::New();

    reader->SetFileName ( "argv[1]" );      //or ("C:BrainT1Slice.png");
    connector->SetInput ( reader->GetOutput() );

    vtkImageViewer* viewer= vtkImageViewer::New();
    vtkRenderWindowInteractor* renderWindowInteractor=
vtkRenderWindowInteractor::New();

    viewer->SetInput ( connector->GetOutput() );
    viewer->Render();
    viewer->SetColorWindow ( 255);
    viewer->SetColorLevel ( 128);
    viewer->SetupInteractor (renderWindowInteractor);

    renderWindowInteractor->Start();

    return 0;
} 



More information about the Insight-users mailing list