MITK Tutorial - Step 2: Load one or more data sets

step2_result.png

This program shows how to load multiple data sets.

A DataNodeFactory is used to produce nodes containing the data.

The picture above shows the result of the program when reading both the image file and the surface file.

In order to obtain the result the program has to be executed using the image file mitk/Core/Code/Testing/Data/Pic3D.pic.gz and the surface file mitk/Modules/MITKExt/Testing/Data/lungs.vtk.

The code for this example equals the code of Step 1 except for part II and part III that are changed as follows:

  // Part II: Create some data by reading files
  //*************************************************************************
  int i;
  for(i=1; i<argc; ++i)
  {
    // For testing
    if(strcmp(argv[i], "-testing")==0) continue;

    // Create a DataNodeFactory to read a data format supported
    // by the DataNodeFactory (many image formats, surface formats, etc.)
    mitk::DataNodeFactory::Pointer nodeReader=mitk::DataNodeFactory::New();
    const char * filename = argv[i];
    try
    {
      nodeReader->SetFileName(filename);
      nodeReader->Update();
      //*********************************************************************
      // Part III: Put the data into the datastorage
      //*********************************************************************

      // Since the DataNodeFactory directly creates a node,
      // use the datastorage to add the read node
      storage->Add(nodeReader->GetOutput());
    }
    catch(...)
    {
      fprintf( stderr, "Could not open file %s \n\n", filename );
      exit(2);
    }
  }

[Previous step] [Next step] [Main tutorial page]

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines