Public Member Functions | Protected Member Functions | Protected Attributes

mitkSegmentationInterpolationTestClass Class Reference

List of all members.

Public Member Functions

 mitkSegmentationInterpolationTestClass ()
 ~mitkSegmentationInterpolationTestClass ()
bool Test ()

Protected Member Functions

bool CreateNewInterpolator ()
bool CreateSegmentation ()
bool ClearSegmentation ()
bool CreateTwoSlices (int)
bool TestInterpolation (int)
bool DeleteInterpolator ()
bool LoadTestImages ()
bool CompareInterpolationsToDefinedReference ()
mitk::Image::Pointer LoadImage (const std::string &filename)

Protected Attributes

mitk::SegmentationInterpolationController::Pointer m_Interpolator
mitk::Image::Pointer m_Image
mitk::Image::Pointer m_ManualSlices
mitk::Image::Pointer m_InterpolatedSlices
unsigned int dim [3]
int pad [3]

Detailed Description

Definition at line 25 of file mitkSegmentationInterpolationTest.cpp.


Constructor & Destructor Documentation

mitkSegmentationInterpolationTestClass::mitkSegmentationInterpolationTestClass (  ) [inline]

Definition at line 28 of file mitkSegmentationInterpolationTest.cpp.

{}
mitkSegmentationInterpolationTestClass::~mitkSegmentationInterpolationTestClass (  ) [inline]

Definition at line 29 of file mitkSegmentationInterpolationTest.cpp.

{}

Member Function Documentation

bool mitkSegmentationInterpolationTestClass::ClearSegmentation (  ) [protected]

Definition at line 107 of file mitkSegmentationInterpolationTest.cpp.

References dim, and m_Image.

Referenced by Test().

{
  int* p = (int*)m_Image->GetData(); // pointer to pixel data
  int size = dim[0]*dim[1]*dim[2];
  for(int i=0; i<size; ++i, ++p) *p=0; // fill image with zeros
  
  return true;
}
bool mitkSegmentationInterpolationTestClass::CompareInterpolationsToDefinedReference (  ) [protected]

Definition at line 310 of file mitkSegmentationInterpolationTest.cpp.

References CompareImageSliceTestHelper::CompareSlice(), m_InterpolatedSlices, m_Interpolator, and m_ManualSlices.

Referenced by Test().

{
  std::cout << "  (II) Setting segmentation volume... " << std::flush;

  m_Interpolator->SetSegmentationVolume( m_ManualSlices );

  std::cout << "OK" << std::endl;
    
  std::cout << "  (II) Testing interpolation result for slice " << std::flush;

  for (unsigned int slice = 1; slice < 98; ++slice)
  {
    if (slice % 2 == 0) continue; // these were manually drawn, no interpolation possible

    std::cout << slice << " " << std::flush;

    mitk::Image::Pointer interpolation = m_Interpolator->Interpolate( 2, slice, 0 );

    if ( interpolation.IsNull() )
    {
      std::cerr << "  (EE) Interpolated image is NULL." << std::endl;
      return false;
    }

    if ( !CompareImageSliceTestHelper::CompareSlice( m_InterpolatedSlices, 2, slice, interpolation ) )
    {
      std::cerr << "  (EE) interpolated image is not identical to reference in slice " << slice << std::endl;
      return false;
    }
  }

  std::cout << std::endl;
  std::cout << "  (II) Interpolations are the same as the saved references." << std::endl;

  return true;
}
bool mitkSegmentationInterpolationTestClass::CreateNewInterpolator (  ) [protected]

Definition at line 73 of file mitkSegmentationInterpolationTest.cpp.

References m_Interpolator, and mitk::SegmentationInterpolationController::New().

Referenced by Test().

{
  std::cout << "Instantiation" << std::endl;

// instantiation
  m_Interpolator = mitk::SegmentationInterpolationController::New();
  if (m_Interpolator.IsNotNull())
  {
    std::cout << "  (II) Instantiation works." << std::endl;
  }
  else
  {
    std::cout << " Instantiation test failed!" << std::endl;
    return false;
  }

  return true;
}
bool mitkSegmentationInterpolationTestClass::CreateSegmentation (  ) [protected]

Definition at line 92 of file mitkSegmentationInterpolationTest.cpp.

References dim, m_Image, mitk::Image::New(), and pad.

Referenced by Test().

{
  m_Image = mitk::Image::New();
  dim[0]=15;
  dim[1]=20;
  dim[2]=25;
  pad[0]=2;
  pad[1]=3;
  pad[2]=4;

  m_Image->Initialize(mitk::PixelType(typeid(int)), 3, dim);

  return true;
}
bool mitkSegmentationInterpolationTestClass::CreateTwoSlices ( int  slicedim ) [protected]

Creates a square segmentation in slices 0 and 2.

Definition at line 120 of file mitkSegmentationInterpolationTest.cpp.

References dim, m_Image, m_Interpolator, and pad.

Referenced by Test().

{
  int* p = (int*)m_Image->GetData(); // pointer to pixel data

  int size = dim[0]*dim[1]*dim[2];
  for(int i=0; i<size; ++i, ++p)
  {
    int x,y,z;
    int xdim,ydim;
    switch (slicedim)
    {
      case 0:
        z = i % dim[0];
        y = i / dim[0] %  dim[1];
        x = i / (dim[1]*dim[0]);
        xdim = 2;
        ydim = 1;
        break;
      case 1:
        x = i % dim[0];
        z = i / dim[0] %  dim[1];
        y = i / (dim[1]*dim[0]);
        xdim = 0;
        ydim = 2;
        break;
      case 2:
      default:
        x = i % dim[0];
        y = i / dim[0] %  dim[1];
        z = i / (dim[1]*dim[0]);
        xdim = 0;
        ydim = 1;
        break;
    }
      
    if ( ((z == 0) || (z == 2)) && (x >= pad[xdim]) && (x < ( (signed) dim[xdim]-pad[xdim])) && (y >= pad[ydim]) && (y < ( (signed) dim[ydim]-pad[ydim])) )
    {
      *p = 1;
    }
    else
    {
      *p = 0;
    }
  }

  m_Interpolator->SetSegmentationVolume( m_Image );
  std::cout << "  (II) SetSegmentationVolume works (slicedim " << slicedim << ")" << std::endl;

  return true;
}
bool mitkSegmentationInterpolationTestClass::DeleteInterpolator (  ) [protected]

Definition at line 235 of file mitkSegmentationInterpolationTest.cpp.

References m_Interpolator.

Referenced by Test().

{
  std::cout << "Object destruction" << std::endl;

// freeing
  m_Interpolator = NULL;
    
  std::cout << "  (II) Freeing works." << std::endl;
  return true;
}
mitk::Image::Pointer mitkSegmentationInterpolationTestClass::LoadImage ( const std::string &  filename ) [protected]

Definition at line 279 of file mitkSegmentationInterpolationTest.cpp.

References mitk::DataNodeFactory::New().

Referenced by LoadTestImages().

{
  mitk::Image::Pointer image = NULL;
  mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New();
  try
  {
    factory->SetFileName( filename );
    factory->Update();

    if(factory->GetNumberOfOutputs()<1)
    {
      std::cerr<<"File " << filename << " could not be loaded [FAILED]"<<std::endl;
      return NULL;
    }
    mitk::DataNode::Pointer node = factory->GetOutput( 0 );
    image = dynamic_cast<mitk::Image*>(node->GetData());
    if(image.IsNull())
    {
      std::cout<<"File " << filename << " is not an image! [FAILED]"<<std::endl;
      return NULL;
    }
  }
  catch ( itk::ExceptionObject & ex )
  {
    std::cerr << "Exception: " << ex << "[FAILED]" << std::endl;
    return NULL;
  }

  return image;
}
bool mitkSegmentationInterpolationTestClass::LoadTestImages (  ) [protected]

Definition at line 246 of file mitkSegmentationInterpolationTest.cpp.

References mitk::StandardFileLocations::GetInstance(), LoadImage(), m_InterpolatedSlices, and m_ManualSlices.

Referenced by Test().

{
  std::string filename1 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_manual.pic.gz", "../mitk/Core/Testing/Data/");
  if ( filename1.empty() )
  {
    filename1 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_manual.pic.gz", "Testing/Data/");
  }
  
  std::cout << "Found test image (manual slices) in '" << filename1 << "'" << std::endl;
  
  std::string filename2 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_result.pic.gz", "../mitk/Core/Testing/Data/");
  if ( filename2.empty() )
  {
    filename2 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_result.pic.gz", "Testing/Data/");
  }
  
  std::cout << "Found test image (reference for interpolation) in '" << filename2 << "'" << std::endl;
  
  if ( filename1.empty() || filename2.empty() )
  {
    return false;
  }
  else
  {
    m_ManualSlices = LoadImage( filename1 );
    m_InterpolatedSlices = LoadImage( filename2 );

    return ( m_ManualSlices.IsNotNull() && m_InterpolatedSlices.IsNotNull() );
  }

  return true;
}
bool mitkSegmentationInterpolationTestClass::Test (  ) [inline]
bool mitkSegmentationInterpolationTestClass::TestInterpolation ( int  slicedim ) [protected]

Checks if interpolation would create a square in slice 1

Definition at line 174 of file mitkSegmentationInterpolationTest.cpp.

References dim, int(), ipMITKSegmentationTYPE, m_Interpolator, and pad.

Referenced by Test().

{
  int slice = 1;
  mitk::Image::Pointer interpolated = m_Interpolator->Interpolate( slicedim, slice, 0 ); // interpolate second slice transversal
  if (interpolated.IsNull())
  {
    std::cerr << "  (EE) Interpolation did not return anything for slicedim == " << slicedim << " (although it should)." << std::endl;
    return false;
  }

  int xdim,ydim;
  switch (slicedim)
  {
    case 0:
      xdim = 1;
      ydim = 2; // different than above!
      break;
    case 1:
      xdim = 0;
      ydim = 2;
      break;
    case 2:
    default:
      xdim = 0;
      ydim = 1;
      break;
  }
 
  ipMITKSegmentationTYPE* p = (ipMITKSegmentationTYPE*)interpolated->GetData(); // pointer to pixel data

  int size = dim[xdim]*dim[ydim];
  if ( (signed) interpolated->GetDimension(0) * (signed) interpolated->GetDimension(1) != size )
  {
    std::cout << "  (EE) Size of interpolated image differs from original segmentation..." << std::endl;
    return false;
  }

  for(int i=0; i<size; ++i, ++p)
  {
    int x,y;
    x = i % dim[xdim];
    y = i / dim[xdim];

    //if (x == 0) std::cout << std::endl;
      
    ipMITKSegmentationTYPE value = *p;
   
    //if (value == 1) std::cout << "O"; else std::cout << ".";

    if ( (x >= pad[xdim]) && (x < ((signed) dim[xdim]-pad[xdim])) && (y >= pad[ydim]) && (y < ((signed) dim[ydim]-pad[ydim])) && (value != 1) )
    {
      std::cout << "  (EE) Interpolation of a square figure failed" << std::endl;
      std::cout << "  Value at " << x << " " << y << ": " << (int)value << std::endl;
      return false;
    }
  }
 
  std::cout << "  (II) Interpolation of a square figure works like expected (slicedim " << slicedim << ")" << std::endl;
  return true;
}

Member Data Documentation

unsigned int mitkSegmentationInterpolationTestClass::dim[3] [protected]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines