[Insight-developers] image reader standard practice

Damion Shelton dmshelto@andrew.cmu.edu
Mon, 22 Apr 2002 13:01:03 -0400


Hi,

Looks like the standard way of using an image reader is the following 
(grabbed from tripletkmain.cxx, but present in other examples in a similar 
fashion):


  //set mh* file
  loader->SetFileName(metaImageFileName);
  loader->Update();
  input_image  = loader->GetOutput();

Unlike a "normal" pipeline, Update() is called explicitly and the output 
retrieved after the reader updates.

In our code, the syntax is as follows:

  reader = ImageFileReaderType::New();
  reader->DebugOn();
  itk::MetaImageIOFactory::RegisterOneFactory();
  reader->SetFileName("d:/brainweb/brainweb1.mha");
  reader->Update();

This works fine. If we remove "reader->Update();", and instead add a filter 
to the pipeline:

fooFilter->SetInput( reader->GetOutput() );

and call Update() on the filter rather than the reader, the program 
crashes. Given that all other examples explicitly update the reader, is 
that the correct way of doing things? If so, why? This seems to be 
different than the way pipelining is handled elsewhere, and makes it 
somewhat awkward to construct a pipeline (including a reader) without 
actually executing the pipeline.

Thanks,
-Damion-