Classes | Public Types | Static Public Member Functions

PlanarFigureIOTestClass Class Reference

Helper class for testing PlanarFigure reader and writer classes. More...

List of all members.

Classes

class  PropertyMapEntryCompare

Public Types

typedef std::list
< mitk::PlanarFigure::Pointer
PlanarFigureList

Static Public Member Functions

static PlanarFigureList CreatePlanarFigures ()
static void VerifyPlanarFigures (PlanarFigureList &planarFigures1, PlanarFigureList &planarFigures2)
static bool ComparePlanarFigures (mitk::PlanarFigure *figure1, mitk::PlanarFigure *figure2)
static void SerializePlanarFigures (PlanarFigureList &planarFigures, std::string &fileName)
static PlanarFigureList DeserializePlanarFigures (std::string &fileName)

Detailed Description

Helper class for testing PlanarFigure reader and writer classes.

Definition at line 37 of file mitkPlanarFigureIOTest.cpp.


Member Typedef Documentation

Definition at line 41 of file mitkPlanarFigureIOTest.cpp.


Member Function Documentation

static bool PlanarFigureIOTestClass::ComparePlanarFigures ( mitk::PlanarFigure figure1,
mitk::PlanarFigure figure2 
) [inline, static]

Definition at line 142 of file mitkPlanarFigureIOTest.cpp.

References mitk::Geometry3D::GetBounds(), mitk::PlanarFigure::GetControlPoint(), mitk::PlanarFigure::GetGeometry2D(), mitk::Geometry3D::GetIndexToWorldTransform(), mitk::PlanarFigure::GetNumberOfControlPoints(), mitk::Geometry3D::GetOrigin(), mitk::BaseData::GetPropertyList(), mitk::Geometry3D::GetSpacing(), MITK_INFO, and MITK_TEST_CONDITION_REQUIRED.

Referenced by VerifyPlanarFigures().

  {
    // Test if PlanarFigures are of same type; otherwise return
    if ( strcmp( figure1->GetNameOfClass(), figure2->GetNameOfClass() ) != 0 )
    {
      return false;
    }

    const char* figureName = figure1->GetNameOfClass();

    // Test for equal number of control points
    MITK_TEST_CONDITION_REQUIRED( 
      figure1->GetNumberOfControlPoints() == figure2->GetNumberOfControlPoints(),
      figureName << ": Testing number of control points" );

    // Test if all control points are equal
    for ( unsigned int i = 0; i < figure1->GetNumberOfControlPoints(); ++i )
    {
      mitk::Point2D& point1 = figure1->GetControlPoint( i );
      mitk::Point2D& point2 = figure2->GetControlPoint( i );

      MITK_TEST_CONDITION_REQUIRED( 
        point1.EuclideanDistanceTo( point2 ) < mitk::eps, 
        figureName << ": Testing equality of control point " << i );
    }


    // Test for equal number of properties
    typedef mitk::PropertyList::PropertyMap PropertyMap;
    const PropertyMap* properties1 = figure1->GetPropertyList()->GetMap();
    const PropertyMap* properties2 = figure2->GetPropertyList()->GetMap();

    MITK_TEST_CONDITION_REQUIRED( 
      properties1->size() == properties2->size(),
      figureName << ": Testing number of properties" );

    MITK_INFO << "List 1:";
    for (PropertyMap::const_iterator i1 = properties1->begin(); i1 != properties1->end(); ++i1)
    {
      std::cout << i1->first << std::endl;
    }

    MITK_INFO << "List 2:";
    for (PropertyMap::const_iterator i2 = properties2->begin(); i2 != properties2->end(); ++i2)
    {
      std::cout << i2->first << std::endl;
    }

    MITK_INFO << "-------";

    // Test if all properties are equal
    MITK_TEST_CONDITION_REQUIRED( 
      std::equal( properties1->begin(), properties1->end(), properties2->begin(), PropertyMapEntryCompare() ),
      figureName << ": Testing equality of properties");
 
    // Test if Geometry is equal
    const mitk::PlaneGeometry* planeGeometry1 = dynamic_cast<const mitk::PlaneGeometry*>(figure1->GetGeometry2D());
    const mitk::PlaneGeometry* planeGeometry2 = dynamic_cast<const mitk::PlaneGeometry*>(figure2->GetGeometry2D());

    // Test Geometry transform parameters
    bool parametersEqual = true;
    typedef mitk::AffineGeometryFrame3D::TransformType TransformType;
    const TransformType* affineGeometry1 = planeGeometry1->GetIndexToWorldTransform();
    const TransformType::ParametersType& parameters1 = affineGeometry1->GetParameters();
    const TransformType::ParametersType& parameters2 = planeGeometry2->GetIndexToWorldTransform()->GetParameters();
    for ( unsigned int i = 0; i < affineGeometry1->GetNumberOfParameters(); ++i )
    {
      if ( fabs(parameters1.GetElement( i ) - parameters2.GetElement( i )) > mitk::eps )
      {
        parametersEqual = false;
      }
    }

    MITK_TEST_CONDITION_REQUIRED( 
      parametersEqual,
      figureName << ": Testing if Geometry transform parameters are equal");


    // Test Geometry bounds
    bool boundsEqual = true;
    typedef mitk::Geometry3D::BoundsArrayType BoundsArrayType;
    const BoundsArrayType& bounds1 = planeGeometry1->GetBounds();
    const BoundsArrayType& bounds2 = planeGeometry2->GetBounds();
    for ( unsigned int i = 0; i < 6; ++i )
    {
      if ( fabs(bounds1.GetElement( i ) - bounds2.GetElement( i )) > mitk::eps )
      {
        boundsEqual = false;
      };
    }

    MITK_TEST_CONDITION_REQUIRED( 
      boundsEqual,
      figureName << ": Testing if Geometry bounds are equal");


    // Test Geometry spacing and origin
    mitk::Vector3D spacing1 = planeGeometry1->GetSpacing();
    mitk::Vector3D spacing2 = planeGeometry2->GetSpacing();

    MITK_TEST_CONDITION_REQUIRED( 
      (spacing1 - spacing2).GetNorm() < mitk::eps,
      figureName << ": Testing if Geometry spacing is equal");


    mitk::Point3D origin1 = planeGeometry1->GetOrigin();
    mitk::Point3D origin2 = planeGeometry2->GetOrigin();

    MITK_TEST_CONDITION_REQUIRED( 
      origin1.EuclideanDistanceTo( origin2 ) < mitk::eps,
      figureName << ": Testing if Geometry origin are equal");


    return true;
  }
static PlanarFigureList PlanarFigureIOTestClass::CreatePlanarFigures (  ) [inline, static]

Definition at line 43 of file mitkPlanarFigureIOTest.cpp.

References mitk::PlanarRectangle::New(), mitk::PlanarPolygon::New(), mitk::PlanarLine::New(), mitk::PlanarFourPointAngle::New(), mitk::PlanarCross::New(), mitk::PlanarCircle::New(), mitk::PlanarAngle::New(), and mitk::PlaneGeometry::New().

Referenced by mitkPlanarFigureIOTest().

  {
    PlanarFigureList planarFigures;

    // Create PlaneGeometry on which to place the PlanarFigures
    mitk::PlaneGeometry::Pointer planeGeometry = mitk::PlaneGeometry::New();
    planeGeometry->InitializeStandardPlane( 100.0, 100.0 );

    // Create a few sample points for PlanarFigure placement
    mitk::Point2D p0; p0[0] = 20.0; p0[1] = 20.0;
    mitk::Point2D p1; p1[0] = 80.0; p1[1] = 80.0;
    mitk::Point2D p2; p2[0] = 90.0; p2[1] = 10.0;
    mitk::Point2D p3; p3[0] = 10.0; p3[1] = 90.0;

    // Create PlanarAngle
    mitk::PlanarAngle::Pointer planarAngle = mitk::PlanarAngle::New();
    planarAngle->SetGeometry2D( planeGeometry );
    planarAngle->PlaceFigure( p0 );
    planarAngle->SetCurrentControlPoint( p1 );
    planarAngle->AddControlPoint( p2 );
    planarFigures.push_back( planarAngle.GetPointer() );
    
    // Create PlanarCircle
    mitk::PlanarCircle::Pointer planarCircle = mitk::PlanarCircle::New();
    planarCircle->SetGeometry2D( planeGeometry );
    planarCircle->PlaceFigure( p0 );
    planarCircle->SetCurrentControlPoint( p1 );
    planarFigures.push_back( planarCircle.GetPointer() );
    
    // Create PlanarCross
    mitk::PlanarCross::Pointer planarCross = mitk::PlanarCross::New();
    planarCross->SetSingleLineMode( false );
    planarCross->SetGeometry2D( planeGeometry );
    planarCross->PlaceFigure( p0 );
    planarCross->SetCurrentControlPoint( p1 );
    planarCross->AddControlPoint( p2 );
    planarCross->AddControlPoint( p3 );
    planarFigures.push_back( planarCross.GetPointer() );
    
    // Create PlanarFourPointAngle
    mitk::PlanarFourPointAngle::Pointer planarFourPointAngle = mitk::PlanarFourPointAngle::New();
    planarFourPointAngle->SetGeometry2D( planeGeometry );
    planarFourPointAngle->PlaceFigure( p0 );
    planarFourPointAngle->SetCurrentControlPoint( p1 );
    planarFourPointAngle->AddControlPoint( p2 );
    planarFourPointAngle->AddControlPoint( p3 );
    planarFigures.push_back( planarFourPointAngle.GetPointer() );
    
    // Create PlanarLine
    mitk::PlanarLine::Pointer planarLine = mitk::PlanarLine::New();
    planarLine->SetGeometry2D( planeGeometry );
    planarLine->PlaceFigure( p0 );
    planarLine->SetCurrentControlPoint( p1 );
    planarFigures.push_back( planarLine.GetPointer() );
    
    // Create PlanarPolygon
    mitk::PlanarPolygon::Pointer planarPolygon = mitk::PlanarPolygon::New();
    planarPolygon->SetClosed( false );
    planarPolygon->SetGeometry2D( planeGeometry );
    planarPolygon->PlaceFigure( p0 );
    planarPolygon->SetCurrentControlPoint( p1 );
    planarPolygon->AddControlPoint( p2 );
    planarPolygon->AddControlPoint( p3 );
    planarFigures.push_back( planarPolygon.GetPointer() );
    
    // Create PlanarRectangle
    mitk::PlanarRectangle::Pointer planarRectangle = mitk::PlanarRectangle::New();
    planarRectangle->SetGeometry2D( planeGeometry );
    planarRectangle->PlaceFigure( p0 );
    planarRectangle->SetCurrentControlPoint( p1 );
    planarFigures.push_back( planarRectangle.GetPointer() );

    return planarFigures;
  }
static PlanarFigureList PlanarFigureIOTestClass::DeserializePlanarFigures ( std::string &  fileName ) [inline, static]

Definition at line 284 of file mitkPlanarFigureIOTest.cpp.

References MITK_TEST_CONDITION_REQUIRED, and mitk::PlanarFigureReader::New().

Referenced by mitkPlanarFigureIOTest().

  {
    // Read in the planar figures
    mitk::PlanarFigureReader::Pointer reader = mitk::PlanarFigureReader::New();
    reader->SetFileName( fileName.c_str() );
    reader->Update();

    MITK_TEST_CONDITION_REQUIRED( 
      reader->GetSuccess(),
      "Testing if reading was successful");


    // Store them in the list and return it
    PlanarFigureList planarFigures;
    for ( unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i )
    {
      mitk::PlanarFigure* figure = reader->GetOutput( i );
      planarFigures.push_back( figure );
    }

    return planarFigures;
  }
static void PlanarFigureIOTestClass::SerializePlanarFigures ( PlanarFigureList planarFigures,
std::string &  fileName 
) [inline, static]

Definition at line 259 of file mitkPlanarFigureIOTest.cpp.

References MITK_TEST_CONDITION_REQUIRED, and mitk::PlanarFigureWriter::New().

Referenced by mitkPlanarFigureIOTest().

  {
    //std::string  sceneFileName = Poco::Path::temp() + /*Poco::Path::separator() +*/ "scene.zip";
    std::cout << "File name: " << fileName << std::endl;

    mitk::PlanarFigureWriter::Pointer writer = mitk::PlanarFigureWriter::New();
    writer->SetFileName( fileName.c_str() );

    unsigned int i;
    PlanarFigureList::iterator it;
    for ( it = planarFigures.begin(), i = 0;
          it != planarFigures.end();
          ++it, ++i )
    {
      writer->SetInput( i, *it );
    }

    writer->Update();

    MITK_TEST_CONDITION_REQUIRED( 
      writer->GetSuccess(),
      "Testing if writing was successful");
  }
static void PlanarFigureIOTestClass::VerifyPlanarFigures ( PlanarFigureList planarFigures1,
PlanarFigureList planarFigures2 
) [inline, static]

Definition at line 119 of file mitkPlanarFigureIOTest.cpp.

References ComparePlanarFigures(), and MITK_TEST_CONDITION_REQUIRED.

Referenced by mitkPlanarFigureIOTest().

  {
    PlanarFigureList::iterator it1, it2;

    for ( it1 = planarFigures1.begin(); it1 != planarFigures1.end(); ++it1 )
    {
      bool planarFigureFound = false;
      for ( it2 = planarFigures2.begin(); it2 != planarFigures2.end(); ++it2 )
      {
        // Compare PlanarFigures (returns false if different types)
        if ( ComparePlanarFigures( *it1, *it2 ) )
        {
          planarFigureFound = true;
        }
      }

      // Test if (at least) on PlanarFigure of the first type was found in the second list
      MITK_TEST_CONDITION_REQUIRED( 
        planarFigureFound,
        "Testing if " << (*it1)->GetNameOfClass() << " has a counterpart" );
    }
  }

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