static void TestBasicFunctionality()
  {
  // let's create an object of our class  
  mitk::InternalTrackingTool::Pointer internalTrackingTool = InternalTrackingToolTestClass::New().GetPointer();
  
  // first test: did this work?
  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
  // it makes no sense to continue without an object.
  MITK_TEST_CONDITION_REQUIRED(internalTrackingTool.IsNotNull(),"Testing instantiation");

    // test for Enable()
  internalTrackingTool->Enable();
  MITK_TEST_CONDITION((internalTrackingTool->IsEnabled()==true),"Testing of Enable()");

  srand(time(NULL));
  // generate a random position to test Set/GetPosition()
  mitk::Point3D position;
  position[0] = rand()%1000;
  position[1] = rand()%1000;
  position[2] = rand()%1000;
  internalTrackingTool->SetPosition(position);
  mitk::Point3D returnedPosition;
  returnedPosition.Fill(0);
  internalTrackingTool->GetPosition(returnedPosition);
  MITK_TEST_CONDITION((position==returnedPosition),"Testing of Set/GetPosition()");

  // generate a random orientation to test Set/GetOrientation()
  mitk::Quaternion orientation;
  orientation[0] = (rand()%1000)/1000.0;
  orientation[1] = (rand()%1000)/1000.0;
  orientation[2] = (rand()%1000)/1000.0;
  orientation[3] = (rand()%1000)/1000.0;
  internalTrackingTool->SetOrientation(orientation);
  mitk::Quaternion returnedOrientation(0,0,0,0);
  internalTrackingTool->GetOrientation(returnedOrientation);
  MITK_TEST_CONDITION((orientation==returnedOrientation),"Testing of Set/GetQuaternion()");

  // test Set/GetTrackingError()
  float trackingError = rand()%2;
  internalTrackingTool->SetTrackingError(trackingError);
  MITK_TEST_CONDITION((internalTrackingTool->GetTrackingError()==trackingError),"Testing of Set/GetTrackingError()");
  // test Set/GetDataValid()
  internalTrackingTool->SetDataValid(true);
  MITK_TEST_CONDITION((internalTrackingTool->IsDataValid()==true),"Testing of SetDataValid and IsDataValid() for parameter 'true'");
  internalTrackingTool->SetDataValid(false);
  MITK_TEST_CONDITION((internalTrackingTool->IsDataValid()==false),"Testing of SetDataValid and IsDataValid() for parameter 'false'");

  internalTrackingTool->Disable();
  MITK_TEST_CONDITION((internalTrackingTool->IsEnabled()==false),"Testing of Disable()");
  }
 static void TestMicroserviceRegister()
   {
   MyNavigationDataSourceTest::Pointer myFilter = MyNavigationDataSourceTest::New();
   myFilter->CreateOutput();
   mitk::NavigationData::PositionType initialPos;
   mitk::FillVector3D(initialPos, 1.0, 2.0, 3.0);
   mitk::NavigationData::OrientationType initialOri(0.1, 0.2, 0.3, 0.4);
   mitk::ScalarType initialError(22.22);
   bool initialValid(true);
   mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
   nd1->SetPosition(initialPos);
   nd1->SetOrientation(initialOri);
   nd1->SetPositionAccuracy(initialError);
   nd1->SetDataValid(initialValid);
   myFilter->RegisterAsMicroservice();
   MITK_TEST_CONDITION(myFilter->GetMicroserviceID()!="","Testing if microservice was registered successfully.");
   }
//Try to select a vertex at position (within a epsilon of course) where no vertex is.
//So the selected verted member should be null.
static void TestSelectVertexAtWrongPosition()
{
  mitk::ContourModel::Pointer contour = mitk::ContourModel::New();

  MITK_TEST_CONDITION_REQUIRED(contour->GetSelectedVertex() == NULL, "selected vertex is NULL");
  mitk::Point3D p;
  p[0] = p[1] = p[2] = 0;

  contour->AddVertex(p);

  mitk::Point3D p2;
  p2[0] = p2[1] = p2[2] = 2;

  contour->SelectVertexAt(p2, 0.1);

  MITK_TEST_CONDITION(contour->GetSelectedVertex() == NULL, "Vertex was not selected");
}
Exemple #4
0
  /*
  Train the classifier with the dataset of breastcancer patients from the
  LibSVM Libary
  */
  void TrainSVMClassifier_BreastCancerDataSet_shouldReturnTrue()
  {
    /* Declarating an featurematrixdataset, the first matrix
    of the matrixpair is the trainingmatrix and the second one is the testmatrix.*/
    std::pair<MatrixDoubleType,MatrixDoubleType> matrixDouble;
    matrixDouble = convertCSVToMatrix<double>(GetTestDataFilePath("Classification/FeaturematrixBreastcancer.csv"),';',0.5,true);
    m_TrainingMatrixX = matrixDouble.first;
    m_TestXPredict = matrixDouble.second;

    /* The declaration of the labelmatrixdataset is equivalent to the declaration
    of the featurematrixdataset.*/
    std::pair<MatrixIntType,MatrixIntType> matrixInt;
    matrixInt = convertCSVToMatrix<int>(GetTestDataFilePath("Classification/LabelmatrixBreastcancer.csv"),';',0.5,false);
    m_TrainingLabelMatrixY = matrixInt.first;
    m_TestYPredict = matrixInt.second;

    /* Setting of the SVM-Parameters*/
    classifier = mitk::LibSVMClassifier::New();
    classifier->SetGamma(1/(double)(m_TrainingMatrixX.cols()));
    classifier->SetSvmType(0);
    classifier->SetKernelType(2);

    /* Train the classifier, by giving trainingdataset for the labels and features.
    The result in an colunmvector of the labels.*/
    classifier->Train(m_TrainingMatrixX,m_TrainingLabelMatrixY);
    Eigen::MatrixXi classes = classifier->Predict(m_TestXPredict);

    /* Testing the matching between the calculated colunmvector and the result
    of the SVM */
    unsigned int maxrows = classes.rows();

    bool isYPredictVector = false;
    int count = 0;

    for(int i= 0; i < maxrows; i++){
      if(classes(i,0) == m_TestYPredict(i,0)){
        isYPredictVector = true;
        count++;
      }
    }
    MITK_INFO << 100*count/(double)(maxrows) << "%";
    MITK_TEST_CONDITION(isIntervall<int>(m_TestYPredict,classes,75,100),"Testvalue is in range.");
  }
static void NavigationDataToPointSetFilterSetInput_SimplePoint_EqualsGroundTruth()
{
  Setup();

  mitk::NavigationData::Pointer nd_in = mitk::NavigationData::New();
  const mitk::NavigationData* nd_out = mitk::NavigationData::New();
  mitk::NavigationData::PositionType point;

  point[0] = 1.0;
  point[1] = 2.0;
  point[2] = 3.0;
  nd_in->SetPosition(point);

  m_NavigationDataToPointSetFilter->SetInput(nd_in);
  nd_out = m_NavigationDataToPointSetFilter->GetInput();

  MITK_TEST_CONDITION(nd_out->GetPosition() == nd_in->GetPosition(),
    "Testing get/set input");
}
  static void TestMethodsWithInvalidParameters()
  {
    mitk::LevelWindowManager::Pointer manager;
    manager = mitk::LevelWindowManager::New();
    mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New();
    manager->SetDataStorage(ds);

    bool success = false;
    mitk::LevelWindowProperty::Pointer levelWindowProperty = mitk::LevelWindowProperty::New();
    try
    {
      manager->SetLevelWindowProperty(levelWindowProperty);
    }
    catch(mitk::Exception e)
    {
      success = true;
    }
    MITK_TEST_CONDITION(success,"Testing mitk::LevelWindowManager SetLevelWindowProperty with invalid parameter");
  }
int mitkImageVtkMapper2DLookupTableTest(int argc, char *argv[])
{
  // load all arguments into a datastorage, take last argument as reference rendering
  // setup a renderwindow of fixed size X*Y
  // render the datastorage
  // compare rendering to reference image
  MITK_TEST_BEGIN("mitkImageVtkMapper2DLookupTableTest")

  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);

  // define an arbitrary lookupTable
  vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
  // use linear interpolation
  lookupTable->SetRampToLinear();
  // use the scalar range of the image to have a nice lookuptable
  lookupTable->SetTableRange(0, 255);
  lookupTable->Build();

  // Fill in a few known colors, the rest will be generated
  lookupTable->SetTableValue(0, 1.0, 0.0, 0.0, 1.0);   // map from red
  lookupTable->SetTableValue(255, 0.0, 0.0, 1.0, 1.0); // to blue

  mitk::LookupTable::Pointer myLookupTable = mitk::LookupTable::New();
  myLookupTable->SetVtkLookupTable(lookupTable);

  // set the rendering mode to use the transfer function
  renderingHelper.SetImageProperty("Image Rendering.Mode",
                                   mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::LOOKUPTABLE_COLOR));
  // set the property for the image
  renderingHelper.SetImageProperty("LookupTable", mitk::LookupTableProperty::New(myLookupTable));

  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
  MITK_TEST_CONDITION(renderingHelper.CompareRenderWindowAgainstReference(argc, argv, 20.0) == true,
                      "CompareRenderWindowAgainstReference test result positive?");

  // use this to generate a reference screenshot or save the file:
  if (false)
  {
    renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/tmp/output.png");
  }

  MITK_TEST_END();
}
int mitkPointSetVtkMapper2DTransformedPointsTest(int argc, char* argv[])
{
  // load all arguments into a datastorage, take last argument as reference rendering
  // setup a renderwindow of fixed size X*Y
  // render the datastorage
  // compare rendering to reference image
  MITK_TEST_BEGIN("mitkPointSetVtkMapper2DTransformedPointsTest")

  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);

  renderingHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal);

  mitk::DataNode* dataNode = renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("PointSet"));

  if(dataNode)
  {
    mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*> ( dataNode->GetData() );

    if(pointSet)
    {
    mitk::Point3D origin = pointSet->GetGeometry()->GetOrigin();

    origin[1] += 10;
    origin[2] += 15;

    pointSet->GetGeometry()->SetOrigin(origin);
    pointSet->Modified();
    dataNode->Update();
    }
  }

  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRenderingTestHelper
  MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" );

  //use this to generate a reference screenshot or save the file:
  if(false)
  {
    renderingHelper.SaveReferenceScreenShot("D:/test/output.png");
  }

  MITK_TEST_END();
}
/**Documentation
 *  test for the class "ToFCameraPMDMITKPlayerController".
 */
int mitkToFCameraPMDMITKPlayerControllerTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFCameraPMDMITKPlayerController");

  mitk::ToFCameraPMDMITKPlayerController::Pointer testObject = mitk::ToFCameraPMDMITKPlayerController::New();
  MITK_TEST_CONDITION_REQUIRED(!(testObject.GetPointer() == NULL) ,"Testing initialization class");
  MITK_TEST_CONDITION_REQUIRED(testObject->GetCaptureHeight()== 200 ,"Testing initialization of CaptureHeight");
  MITK_TEST_CONDITION_REQUIRED(testObject->GetCaptureWidth()== 200 ,"Testing initialization of CaptureWidth");
  // test empty file behavior
  std::string testFile = "";
  testObject->SetInputFileName(testFile);
  MITK_TEST_CONDITION_REQUIRED(testObject->OpenCameraConnection(),"Testing open camera without valid data");
  //MITK_TEST_CONDITION_REQUIRED(!testObject->CloseCameraConnection(),"Testing closing of connection");

  //test valid data behavior
  //CAVE: The following test cases are valid once rawData recording is fixed. Currently the
  //      functionality is not working therefor the test cases are excluded!!

  //std::string filePath = MITK_TOF_DATA_DIR;
  //testFile = "/aa_raw.pic";
  //filePath.append(testFile);
  //testObject->SetInputFileName(filePath);
  //MITK_TEST_CONDITION_REQUIRED( testObject->OpenCameraConnection(),"Testing open camera with valid data");
  //MITK_TEST_CONDITION_REQUIRED( testObject->GetIntegrationTime() == 2500,"Testing correct setting of integration time!");
  //MITK_TEST_CONDITION_REQUIRED( testObject->GetModulationFrequency() == 20,"Testing correct setting of modulation frequency!");
  //
  ////test source data passing and updating!
  //int size = testObject->GetSourceDataStructSize();
  //MITK_TEST_CONDITION_REQUIRED( size != 0 , "Testing correct setting of source data size!" )
  //char* sourceData = NULL;
  //testObject->GetSourceData( sourceData );
  //MITK_TEST_CONDITION_REQUIRED( sourceData == NULL, "Testing setting of source data without update camera!");
  //testObject->UpdateCamera();
  //sourceData = new char[size];
  //testObject->GetSourceData(sourceData);
  //MITK_TEST_CONDITION_REQUIRED( sourceData != NULL, "Testing setting of source data with update camera!");
  //delete[] sourceData;
  MITK_TEST_CONDITION( testObject->CloseCameraConnection(),"Closing Connection!");

  MITK_TEST_END();

}git st
  void TestGoToSnapshotException()
  {
    //testing GoToSnapShot for exception
    mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer2 = mitk::NavigationDataSequentialPlayer::New();
    std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2Tools.xml");
    mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
    myTestPlayer2->SetNavigationDataSet(reader->Read(file));

    bool exceptionThrown2=false;
    try
    {
      unsigned int invalidSnapshot = 1000;
      myTestPlayer2->GoToSnapshot(invalidSnapshot);
    }
    catch(mitk::IGTException)
    {
      exceptionThrown2=true;
    }
    MITK_TEST_CONDITION(exceptionThrown2, "Testing if exception is thrown when GoToSnapShot method is called with an index that doesn't exist.");
  }
Exemple #11
0
int mitkCopyToPythonAsItkImageTest(int /*argc*/, char* argv[])
{
  MITK_TEST_BEGIN("mitkCopyToPythonAsItkImageTest")

  //get the context of the python module
  us::Module* module = us::ModuleRegistry::GetModule("mitkPython");
  us::ModuleContext* context = module->GetModuleContext();
  //get the service which is generated in the PythonModuleActivator
  us::ServiceReference<mitk::IPythonService> serviceRef = context->GetServiceReference<mitk::IPythonService>();
  mitk::PythonService* pythonService = dynamic_cast<mitk::PythonService*>( context->GetService(serviceRef) );
  MITK_TEST_CONDITION(pythonService->IsItkPythonWrappingAvailable() == true, "Is Python available?");

  mitk::Image::Pointer testImage = mitk::IOUtil::LoadImage(std::string(argv[1]));

  //give it a name in python
  std::string nameOfImageInPython("mitkImage");

  MITK_TEST_CONDITION( pythonService->CopyToPythonAsItkImage( testImage, nameOfImageInPython) == true, "Valid image copied to python import should return true.");
  mitk::Image::Pointer pythonImage = pythonService->CopyItkImageFromPython(nameOfImageInPython);


  mitk::Index3D index;
  index[0] = 128;
  index[1] = 128;
  index[2] = 24;

  try{
    // pic3D of type char
    mitk::ImagePixelReadAccessor<char,3> pythonImageAccesor(pythonImage);

    //TODO Use the assert comparison methods once we have them implemented and remove GetPixelValueByIndex
    MITK_TEST_CONDITION( pythonImageAccesor.GetDimension(0) == 256, "Is the 1st dimension of Pic3D still 256?");
    MITK_TEST_CONDITION( pythonImageAccesor.GetDimension(1) == 256, "Is the 2nd dimension of Pic3D still 256?");
    MITK_TEST_CONDITION( pythonImageAccesor.GetDimension(2) == 49, "Is the 3rd dimension of Pic3D still 49?");

    MITK_TEST_CONDITION( pythonImageAccesor.GetPixelByIndex(index) == 96, "Is the value of Pic3D at (128,128,24) still 96?");
  }catch(...)
  {
    MITK_TEST_CONDITION( false, "Image is not readable! ");
  }

  MITK_TEST_END()
}
Exemple #12
0
int mitkImageVtkMapper2DTest(int argc, char* argv[])
{
  // load all arguments into a datastorage, take last argument as reference rendering
  // setup a renderwindow of fixed size X*Y
  // render the datastorage
  // compare rendering to reference image
  MITK_TEST_BEGIN("mitkImageVtkMapper2DTest")

  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);

  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
  MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" );

  //use this to generate a reference screenshot or save the file:
  if(false)
  {
    renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/RenderingTestData/output.png");
  }

  MITK_TEST_END();
}
void TestAllProperties(const mitk::PropertyList* propList)
{
  assert(propList);

  /* try to serialize each property in the list, then deserialize again and check for equality */
  for (mitk::PropertyList::PropertyMap::const_iterator it = propList->GetMap()->begin(); it != propList->GetMap()->end(); ++it)
  {
    const mitk::BaseProperty* prop = it->second;
    // construct name of serializer class
    std::string serializername = std::string(prop->GetNameOfClass()) + "Serializer";
    std::list<itk::LightObject::Pointer> allSerializers = itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str());
    MITK_TEST_CONDITION(allSerializers.size() > 0, std::string("Creating serializers for ") + serializername);
    if (allSerializers.size() == 0)
    {
      MITK_TEST_OUTPUT( << "serialization not possible, skipping " << prop->GetNameOfClass());
      continue;
    }
    if (allSerializers.size() > 1)
    {
      MITK_TEST_OUTPUT (<< "Warning: " << allSerializers.size() << " serializers found for " << prop->GetNameOfClass() << "testing only the first one.");
    }
int mitkImageVtkMapper2DSwivelTest(int argc, char* argv[])
{
  //load all arguments into a datastorage, take last argument as reference
  //setup a renderwindow of fixed size X*Y
  //render the datastorage
  //compare rendering to reference image
  MITK_TEST_BEGIN("mitkImageVtkMapper2DSwivelTest")

  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
  //center point for rotation
  mitk::Point3D centerPoint;
  centerPoint.Fill(0.0f);
  //vector for rotating the slice
  mitk::Vector3D rotationVector;
  rotationVector.SetElement(0, 0.2);
  rotationVector.SetElement(1, 0.3);
  rotationVector.SetElement(2, 0.5);
  //sets a swivel direction for the image

  //new version of setting the center point:
  mitk::Image::Pointer image = static_cast<mitk::Image*>(renderingHelper.GetDataStorage()->GetNode(mitk::NodePredicateDataType::New("Image"))->GetData());

  //get the center point of the image
  centerPoint = image->GetGeometry()->GetCenter();

  //rotate the image arround its own center
  renderingHelper.ReorientSlices(centerPoint, rotationVector);

  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
  MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" );

  //use this to generate a reference screenshot or save the file:
  if(false)
  {
    renderingHelper.SaveReferenceScreenShot("/media/hdd/thomasHdd/Pictures/RenderingTestData/pic3dSwivel640x480REF.png");
  }

  MITK_TEST_END();
}
//Test to move the whole contour
static void TestMoveContour()
{
  mitk::ContourModel::Pointer contour = mitk::ContourModel::New();

  mitk::Point3D p;
  p[0] = p[1] = p[2] = 0;

  contour->AddVertex(p);


  mitk::Point3D p2;
  p2[0] = p2[1] = p2[2] = 0;

  contour->AddVertex(p2);


  mitk::Vector3D v;
  v[0] = 1;
  v[1] = 3;
  v[2] = -1;

  contour->ShiftContour(v);

  mitk::ContourModel::VertexIterator it = contour->IteratorBegin();
  mitk::ContourModel::VertexIterator end = contour->IteratorEnd();

  bool correctlyMoved = false;

  while(it != end)
  {

    correctlyMoved &= (*it)->Coordinates[0] == (v[0]) &&
      (*it)->Coordinates[1] == (v[1]) &&
      (*it)->Coordinates[2] == (v[2]);
  }

  MITK_TEST_CONDITION(correctlyMoved, "Contour has been moved");
}
//Test concatenating two contours
static void TestConcatenate()
{
  mitk::ContourModel::Pointer contour = mitk::ContourModel::New();

  mitk::Point3D p;
  p[0] = p[1] = p[2] = 0;

  contour->AddVertex(p);


  mitk::Point3D p2;
  p2[0] = p2[1] = p2[2] = 1;

  contour->AddVertex(p2);


  mitk::ContourModel::Pointer contour2 = mitk::ContourModel::New();

  mitk::Point3D p3;
  p3[0] = -2;
  p3[1] = 10;
  p3[2] = 0;

  contour2->AddVertex(p3);


  mitk::Point3D p4;
  p4[0] = -3;
  p4[1] = 6;
  p4[2] = -5;

  contour2->AddVertex(p4);

  contour->Concatenate(contour2);

  MITK_TEST_CONDITION(contour->GetNumberOfVertices() == 4, "two contours were concatenated");
}
static void TestTooltipFunctionality()
  {
  mitk::InternalTrackingTool::Pointer internalTrackingTool = InternalTrackingToolTestClass::New().GetPointer();
  mitk::Point3D toolTipPos; mitk::FillVector3D(toolTipPos,1,1,1);
  mitk::Quaternion toolTipQuat = mitk::Quaternion(0,0,0,1);
  internalTrackingTool->SetToolTip(toolTipPos,toolTipQuat);

  mitk::Point3D positionInput; mitk::FillVector3D(positionInput,5,6,7);

  internalTrackingTool->SetPosition(positionInput);

  mitk::Point3D positionOutput;

  internalTrackingTool->GetPosition(positionOutput);

  MITK_TEST_CONDITION(((positionOutput[0] == 6)&&
                       (positionOutput[0] == 6)&&
                       (positionOutput[0] == 6)&&
                       (positionOutput[0] == 6)),
                       "Testing tooltip definition."
                     );


  }
//try to access an invalid timestep
static void TestInvalidTimeStep()
{
  mitk::ContourModel::Pointer contour = mitk::ContourModel::New();
  mitk::Point3D p;
  p[0] = p[1] = p[2] = 0;

  contour->AddVertex(p);


  mitk::Point3D p2;
  p2[0] = p2[1] = p2[2] = 1;

  contour->AddVertex(p2);

  int invalidTimeStep = 42;

  MITK_TEST_CONDITION_REQUIRED(contour->IsEmptyTimeStep(invalidTimeStep), "invalid timestep required");

  MITK_TEST_FOR_EXCEPTION(std::exception, contour->IteratorBegin(-1));

  contour->Close(invalidTimeStep);
  MITK_TEST_CONDITION(contour->IsClosed() == false, "test close for timestep 0");
  MITK_TEST_CONDITION(contour->IsClosed(invalidTimeStep) == false, "test close at invalid timestep");

  contour->SetClosed(true, invalidTimeStep);
  MITK_TEST_CONDITION(contour->GetNumberOfVertices(invalidTimeStep) == -1, "test number of vertices at invalid timestep");

  contour->AddVertex(p2, invalidTimeStep);
  MITK_TEST_CONDITION(contour->GetNumberOfVertices(invalidTimeStep) == -1, "test add vertex at invalid timestep");

  contour->InsertVertexAtIndex(p2, 0, false, invalidTimeStep);
  MITK_TEST_CONDITION(contour->GetNumberOfVertices(invalidTimeStep) == -1, "test insert vertex at invalid timestep");

  MITK_TEST_CONDITION(contour->SelectVertexAt(0, invalidTimeStep) == NULL, "test select vertex at invalid timestep");

  MITK_TEST_CONDITION(contour->RemoveVertexAt(0, invalidTimeStep) == false, "test remove vertex at invalid timestep");

}
Exemple #19
0
/*
Test writing picture formats like *.bmp, *.png, *.tiff or *.jpg
NOTE: Saving as picture format must ignore PixelType comparison - not all bits per components are supported (see specification of the format)
*/
void TestPictureWriting(mitk::Image* image, const std::string& filename, const std::string& extension)
{
  const std::string fullFileName = AppendExtension(filename, extension.c_str());

  mitk::Image::Pointer singleSliceImage = NULL;
  if( image->GetDimension() == 3 )
  {
    mitk::ExtractSliceFilter::Pointer extractFilter = mitk::ExtractSliceFilter::New();
    extractFilter->SetInput( image );
    extractFilter->SetWorldGeometry( image->GetSlicedGeometry()->GetPlaneGeometry(0) );

    extractFilter->Update();
    singleSliceImage = extractFilter->GetOutput();

    // test 3D writing in format supporting only 2D
    mitk::FileWriterRegistry::Write(image, fullFileName);

    // test images
    unsigned int foundImagesCount = 0;

    //if the image only contains one sinlge slice the itkImageSeriesWriter won't add a number like filename.XX.extension
    if(image->GetDimension(2) == 1)
    {
      std::stringstream series_filenames;
        series_filenames << filename << extension;
        mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage( series_filenames.str() );
        if( compareImage.IsNotNull() )
        {
          foundImagesCount++;
          MITK_TEST_CONDITION(CompareImageMetaData( singleSliceImage, compareImage, false ), "Image meta data unchanged after writing and loading again. "); //ignore bits per component
        }
        remove( series_filenames.str().c_str() );
    }
    else //test the whole slice stack
    {
      for( unsigned int i=0; i< image->GetDimension(2); i++)
      {
        std::stringstream series_filenames;
        series_filenames << filename << "." << i+1 << extension;
        mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage( series_filenames.str() );
        if( compareImage.IsNotNull() )
        {
          foundImagesCount++;
          MITK_TEST_CONDITION(CompareImageMetaData( singleSliceImage, compareImage, false ), "Image meta data unchanged after writing and loading again. "); //ignore bits per component
        }
        remove( series_filenames.str().c_str() );
      }
    }
    MITK_TEST_CONDITION( foundImagesCount == image->GetDimension(2), "All 2D-Slices of a 3D image were stored correctly.");
  }
  else if( image->GetDimension() == 2 )
  {
    singleSliceImage = image;
  }

  // test 2D writing
  if( singleSliceImage.IsNotNull() )
  {
    try
    {
      mitk::FileWriterRegistry::Write(singleSliceImage, fullFileName);

      mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage(fullFileName.c_str());
      MITK_TEST_CONDITION_REQUIRED( compareImage.IsNotNull(), "Image stored was succesfully loaded again");

      MITK_TEST_CONDITION_REQUIRED( CompareImageMetaData(singleSliceImage, compareImage, false ), "Image meta data unchanged after writing and loading again. ");//ignore bits per component
      remove(AppendExtension(filename, extension.c_str()).c_str());
    }
    catch(itk::ExceptionObject &e)
    {
      MITK_TEST_FAILED_MSG(<< "Exception during file writing for ." << extension << ": " << e.what() );
    }

  }

}
/**Documentation
 *  test for the class "NavigationDataRecorder".
 */
int mitkNavigationDataRecorderTest(int /* argc */, char* /*argv*/[])
{
    MITK_TEST_BEGIN("NavigationDataRecorder");
    std::string tmp = "";
    std::ostringstream* stream = new std::ostringstream( std::ostringstream::trunc );
    stream->setf( std::ios::fixed, std::ios::floatfield );

    // let's create an object of our class
    mitk::NavigationDataRecorder::Pointer recorder = mitk::NavigationDataRecorder::New();

    // first test: did this work?
    // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
    // it makes no sense to continue without an object.
    MITK_TEST_CONDITION_REQUIRED(recorder.IsNotNull(), "Testing instantiation");

    MITK_TEST_CONDITION(recorder->GetInputs().size() == 0, "testing initial number of inputs");
    MITK_TEST_CONDITION(recorder->GetOutputs().size() == 0, "testing initial number of outputs");

    mitk::NavigationData::Pointer naviData = mitk::NavigationData::New();
    recorder->AddNavigationData( naviData );
    //recorder->SetFileName("e:/test");
    //recorder->SetRecordingMode( mitk::NavigationDataRecorder::NormalFile );
    recorder->StartRecording( stream );
    for ( unsigned int i=0; i<5; i++ )
    {
        mitk::Point3D pnt;
        pnt[0] = i + 1;
        pnt[1] = i + 1/2;
        pnt[2] = i +1*3;


        naviData->SetPosition(pnt);
        //naviData->Modified();
        recorder->Update();

        //Sleep(80 + i*10);

    }

    recorder->StopRecording();

    std::string str = stream->str();
    int pos = str.find( "ToolCount=" );
    std::string sub = stream->str().substr(pos+11, 1);
    MITK_TEST_CONDITION( sub.compare("1") == 0, "check if number of inputs is correct by stringstream");

    pos = str.find( "X=" );
    sub = stream->str().substr(pos+3, 1);
    MITK_TEST_CONDITION( sub.compare("1") == 0, "check if the X coordinate is correct");


    pos = str.find( "Y=" );
    sub = stream->str().substr(pos+3, 1);
    MITK_TEST_CONDITION( sub.compare("0") == 0, "check if the Y coordinate is correct");


    pos = str.find( "Z=" );
    sub = stream->str().substr(pos+3, 1);
    MITK_TEST_CONDITION( sub.compare("3") == 0, "check if the Z coordinate is correct");


    recorder->SetFileName("blablabla");
    const char* string = recorder->GetFileName();
    MITK_TEST_CONDITION( strcmp(string, "blablabla") == 0, "check if set- and getName-methods work");

    // always end with this!
    MITK_TEST_END();
}
Exemple #21
0
static void TestMode3D(mitk::NavigationDataToPointSetFilter::Pointer myNavigationDataToPointSetFilter)
{
  myNavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode3D);

  //Build up test data
  mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New();
  mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
  mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New();
  mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New();

  mitk::NavigationData::PositionType point0;
  point0[0] = 1.0;
  point0[1] = 2.0;
  point0[2] = 3.0;
  nd0->SetPosition(point0);
  nd0->SetDataValid(true);

  mitk::NavigationData::PositionType point1;
  point1[0] = 4.0;
  point1[1] = 5.0;
  point1[2] = 6.0;
  nd1->SetPosition(point1);
  nd1->SetDataValid(true);

  mitk::NavigationData::PositionType point2;
  point2[0] = 7.0;
  point2[1] = 8.0;
  point2[2] = 9.0;
  nd2->SetPosition(point2);
  nd2->SetDataValid(true);

  mitk::NavigationData::PositionType point3;
  point3[0] = 10.0;
  point3[1] = 11.0;
  point3[2] = 12.0;
  nd3->SetPosition(point3);
  nd3->SetDataValid(true);

  myNavigationDataToPointSetFilter->SetInput(0, nd0);
  myNavigationDataToPointSetFilter->SetInput(1, nd1);
  myNavigationDataToPointSetFilter->SetInput(2, nd2);
  myNavigationDataToPointSetFilter->SetInput(3, nd3);

  //Process
  mitk::PointSet::Pointer pointSet0 = myNavigationDataToPointSetFilter->GetOutput(0);
  mitk::PointSet::Pointer pointSet1 = myNavigationDataToPointSetFilter->GetOutput(1);
  mitk::PointSet::Pointer pointSet2 = myNavigationDataToPointSetFilter->GetOutput(2);
  mitk::PointSet::Pointer pointSet3 = myNavigationDataToPointSetFilter->GetOutput(3);

  pointSet0->Update();

  MITK_TEST_OUTPUT(<< "Testing the conversion of navigation data object to PointSets in Mode 3D:");
  MITK_TEST_CONDITION(mitk::Equal(pointSet0->GetPoint(0), point0), "Pointset 0 correct?");
  MITK_TEST_CONDITION(mitk::Equal(pointSet1->GetPoint(0), point1), "Pointset 1 correct?");
  MITK_TEST_CONDITION(mitk::Equal(pointSet2->GetPoint(0), point2), "Pointset 2 correct?");
  MITK_TEST_CONDITION(mitk::Equal(pointSet3->GetPoint(0), point3), "Pointset 3 correct?");

    //pointSet0->GetPoint(0)[0] == 1.0  && pointSet0->GetPoint(0)[1] == 2.0  && pointSet0->GetPoint(0)[2] == 3.0 &&
    //                  pointSet1->GetPoint(0)[0] == 4.0  && pointSet1->GetPoint(0)[1] == 5.0  && pointSet1->GetPoint(0)[2] == 6.0 &&
    //                  pointSet2->GetPoint(0)[0] == 7.0  && pointSet2->GetPoint(0)[1] == 8.0  && pointSet2->GetPoint(0)[2] == 9.0 &&
    //                  pointSet3->GetPoint(0)[0] == 10.0 && pointSet3->GetPoint(0)[1] == 11.0 && pointSet3->GetPoint(0)[2] == 12.0
    //, "Testing the conversion of navigation data object to PointSets in Mode 3D" );

}
Exemple #22
0
static void TestMode4D(mitk::NavigationDataToPointSetFilter::Pointer myNavigationDataToPointSetFilter)
{
  myNavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode4D);
  myNavigationDataToPointSetFilter->SetRingBufferSize(2);

  //Build up test data
  mitk::NavigationData::Pointer nd = mitk::NavigationData::New();
  mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New();
  mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New();
  mitk::NavigationData::Pointer nd4 = mitk::NavigationData::New();

  mitk::NavigationData::PositionType point;

  point[0] = 1.0;
  point[1] = 2.0;
  point[2] = 3.0;
  nd->SetPosition(point);

  point[0] = 4.0;
  point[1] = 5.0;
  point[2] = 6.0;
  nd2->SetPosition(point);

  point[0] = 7.0;
  point[1] = 8.0;
  point[2] = 9.0;
  nd3->SetPosition(point);

  point[0] = 10.0;
  point[1] = 11.0;
  point[2] = 12.0;
  nd4->SetPosition(point);

  myNavigationDataToPointSetFilter->SetInput(0, nd);
  myNavigationDataToPointSetFilter->SetInput(1, nd2);

  mitk::PointSet::Pointer pointSet = myNavigationDataToPointSetFilter->GetOutput();
  pointSet->Update();

  MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 1.0 && pointSet->GetPoint(0,0)[1] == 2.0 && pointSet->GetPoint(0,0)[2] == 3.0 &&
    pointSet->GetPoint(1,0)[0] == 4.0 && pointSet->GetPoint(1,0)[1] == 5.0 && pointSet->GetPoint(1,0)[2] == 6.0
    , "Testing the conversion of navigation data object to one point set in Mode 4D in first timestep" );

  myNavigationDataToPointSetFilter->SetInput(0, nd3);
  myNavigationDataToPointSetFilter->SetInput(1, nd4);
  myNavigationDataToPointSetFilter->Update();
  pointSet = myNavigationDataToPointSetFilter->GetOutput();

  MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 1.0 && pointSet->GetPoint(0,0)[1] == 2.0 && pointSet->GetPoint(0,0)[2] == 3.0 &&
    pointSet->GetPoint(1,0)[0] == 4.0 && pointSet->GetPoint(1,0)[1] == 5.0 && pointSet->GetPoint(1,0)[2] == 6.0 &&
    pointSet->GetPoint(0,1)[0] == 7.0 && pointSet->GetPoint(0,1)[1] == 8.0 && pointSet->GetPoint(0,1)[2] == 9.0 &&
    pointSet->GetPoint(1,1)[0] == 10.0 && pointSet->GetPoint(1,1)[1] == 11.0 && pointSet->GetPoint(1,1)[2] == 12.0
    , "Testing the conversion of navigation data object to one point set in Mode 4D in second timestep" );

  myNavigationDataToPointSetFilter->SetInput(0, nd3);
  //nd3->Modified(); //necessary because the generate data is only called when input has changed...
  myNavigationDataToPointSetFilter->SetInput(1, nd4);
  //nd4->Modified();
  //myNavigationDataToPointSetFilter->Update();
  pointSet = myNavigationDataToPointSetFilter->GetOutput();
  pointSet->Update();

  MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 7.0 && pointSet->GetPoint(0,0)[1] == 8.0 && pointSet->GetPoint(0,0)[2] == 9.0 &&
    pointSet->GetPoint(1,0)[0] == 10.0 && pointSet->GetPoint(1,0)[1] == 11.0 && pointSet->GetPoint(1,0)[2] == 12.0 &&
    pointSet->GetPoint(0,1)[0] == 7.0 && pointSet->GetPoint(0,1)[1] == 8.0 && pointSet->GetPoint(0,1)[2] == 9.0 &&
    pointSet->GetPoint(1,1)[0] == 10.0 && pointSet->GetPoint(1,1)[1] == 11.0 && pointSet->GetPoint(1,1)[2] == 12.0
    , "Testing the correct ring buffer behavior" );
}
int mitkTextOverlay3DRendering3DTest(int argc, char* argv[])
{
  // load all arguments into a datastorage, take last argument as reference rendering
  // setup a renderwindow of fixed size X*Y
  // render the datastorage
  // compare rendering to reference image
  MITK_TEST_BEGIN("mitkTextOverlay3DRendering3DTest")

  mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
//  renderingHelper.SetAutomaticallyCloseRenderWindow(false);

  renderingHelper.SetMapperIDToRender3D();

  mitk::BaseRenderer* renderer = mitk::BaseRenderer::GetInstance(renderingHelper.GetVtkRenderWindow());
  mitk::OverlayManager::Pointer overlayManager = mitk::OverlayManager::New();
  renderer->SetOverlayManager(overlayManager);

  mitk::PointSet::Pointer pointset = mitk::PointSet::New();

  // This vector is used to define an offset for the annotations, in order to show them with a margin to the actual coordinate.
  mitk::Point3D offset;
  offset[0] = .5;
  offset[1] = .5;
  offset[2] = .5;

  //Just a loop to create some points
  for(int i=0 ; i < 5 ; i++){
      //To each point, a TextOverlay3D is created
      mitk::TextOverlay3D::Pointer textOverlay3D = mitk::TextOverlay3D::New();
      mitk::Point3D point;
      point[0] = i*2;
      point[1] = i*3;
      point[2] = -i*5;
      pointset->InsertPoint(i, point);
      textOverlay3D->SetText("A Point");

      // The Position is set to the point coordinate to create an annotation to the point in the PointSet.
      textOverlay3D->SetPosition3D(point);

      // move the annotation away from the actual point
      textOverlay3D->SetOffsetVector(offset);

      overlayManager->AddOverlay(textOverlay3D.GetPointer());
  }

  // also show the created pointset
  mitk::DataNode::Pointer datanode = mitk::DataNode::New();
  datanode->SetData(pointset);
  datanode->SetName("pointSet");
  renderingHelper.AddNodeToStorage(datanode);

  //use this to generate a reference screenshot or save the file:
  bool generateReferenceScreenshot = false;
  if(generateReferenceScreenshot)
  {
    renderingHelper.SaveReferenceScreenShot("/home/christoph/Pictures/RenderingTestData/mitkTextOverlay3DRendering3DTest_ball.png");
  }

  //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
  MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" );

  MITK_TEST_END();
}
Exemple #24
0
/**
*  test for "ImageWriter".
*
*  argc and argv are the command line parameters which were passed to
*  the ADD_TEST command in the CMakeLists.txt file. For the automatic
*  tests, argv is either empty for the simple tests or contains the filename
*  of a test image for the image tests (see CMakeLists.txt).
*/
int mitkImageWriterTest(int  argc , char* argv[])
{
  // always start with this!
  MITK_TEST_BEGIN("ImageWriter")

  // let's create an object of our class
  mitk::ImageWriter::Pointer myImageWriter = mitk::ImageWriter::New();

  // first test: did this work?
  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
  // it makes no sense to continue without an object.
  MITK_TEST_CONDITION_REQUIRED(myImageWriter.IsNotNull(),"Testing instantiation")

  // write your own tests here and use the macros from mitkTestingMacros.h !!!
  // do not write to std::cout and do not return from this function yourself!

  // load image
  MITK_TEST_CONDITION_REQUIRED(argc > 1, "File to load has been specified");


  mitk::Image::Pointer image = NULL;

  try
  {
    MITK_TEST_OUTPUT(<< "Loading file: " << argv[1]);
    image = mitk::IOUtil::LoadImage( argv[1] );
  }
  catch (itk::ExceptionObject & ex)
  {
    MITK_TEST_FAILED_MSG(<< "Exception during file loading: " << ex.GetDescription());
  }


  MITK_TEST_CONDITION_REQUIRED(image.IsNotNull(),"loaded image not NULL")
  std::stringstream filename_stream;

#ifdef WIN32
  filename_stream << "test" << _getpid();
#else
  filename_stream << "test" << getpid();
#endif


  std::string filename = filename_stream.str();
  std::cout << filename << std::endl;

  // test set/get methods
  myImageWriter->SetInput(image);
  MITK_TEST_CONDITION_REQUIRED(myImageWriter->GetInput()==image,"test Set/GetInput()");
  myImageWriter->SetFileName(filename);
  MITK_TEST_CONDITION_REQUIRED(!strcmp(myImageWriter->GetFileName(),filename.c_str()),"test Set/GetFileName()");
  myImageWriter->SetFilePrefix("pref");
  MITK_TEST_CONDITION_REQUIRED(!strcmp(myImageWriter->GetFilePrefix(),"pref"),"test Set/GetFilePrefix()");
  myImageWriter->SetFilePattern("pattern");
  MITK_TEST_CONDITION_REQUIRED(!strcmp(myImageWriter->GetFilePattern(),"pattern"),"test Set/GetFilePattern()");

  // write ITK .mhd image (2D and 3D only)
  if( image->GetDimension() <= 3 )
  {
    try
    {
      myImageWriter->SetExtension(".mhd");
      myImageWriter->Update();

      mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage( AppendExtension(filename, ".mhd").c_str() );
      MITK_TEST_CONDITION_REQUIRED( compareImage.IsNotNull(), "Image stored in MHD format was succesfully loaded again! ");

      std::string rawExtension = ".raw";
      std::fstream rawPartIn;
      rawPartIn.open(AppendExtension(filename, ".raw").c_str());
      if( !rawPartIn.is_open() )
      {
        rawExtension = ".zraw";
        rawPartIn.open(AppendExtension(filename, ".zraw").c_str());
      }

      MITK_TEST_CONDITION_REQUIRED(rawPartIn.is_open(),"Write .raw file");
      rawPartIn.close();

      // delete
      remove(AppendExtension(filename, ".mhd").c_str());
      remove(AppendExtension(filename, rawExtension.c_str()).c_str());
    }
    catch (...)
    {
      MITK_TEST_FAILED_MSG(<< "Exception during .mhd file writing");
    }
  }

  //testing more component image writing as nrrd files
  try
  {
    myImageWriter->SetExtension(".nrrd");
    myImageWriter->Update();
    std::fstream fin;
    mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage(AppendExtension(filename, ".nrrd").c_str());
    MITK_TEST_CONDITION_REQUIRED(compareImage.IsNotNull(), "Image stored in NRRD format was succesfully loaded again");
    fin.close();
    remove(AppendExtension(filename, ".nrrd").c_str());
  }
  catch(...)
  {
    MITK_TEST_FAILED_MSG(<< "Exception during .nrrd file writing");
  }


  mitk::Image::Pointer singleSliceImage = NULL;
  if( image->GetDimension() == 3 )
  {
    mitk::ExtractSliceFilter::Pointer extractFilter = mitk::ExtractSliceFilter::New();
    extractFilter->SetInput( image );
    extractFilter->SetWorldGeometry( image->GetSlicedGeometry()->GetGeometry2D(0) );

    extractFilter->Update();
    singleSliceImage = extractFilter->GetOutput();

    // test 3D writing in format supporting only 2D
    myImageWriter->SetExtension(".png");
    myImageWriter->Update();

    // test images
    unsigned int foundImagesCount = 0;
    for( unsigned int i=0; i< image->GetDimension(2); i++)
    {
      std::stringstream series_filenames;
      series_filenames << filename << "." << i+1 << ".png";
      mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage( series_filenames.str() );
      if( compareImage.IsNotNull() )
      {
        foundImagesCount++;
        MITK_TEST_CONDITION(CompareImageMetaData( singleSliceImage, compareImage ), "Image meta data unchanged after writing and loading again. ");
      }
      remove( series_filenames.str().c_str() );
    }
    MITK_TEST_CONDITION( foundImagesCount == image->GetDimension(2), "All 2D-Slices of a 3D image were stored correctly as PNGs.");
  }
  else if( image->GetDimension() == 2 )
  {
    singleSliceImage = image;
  }

  // test 2D writing
  if( singleSliceImage.IsNotNull() )
  {
    try
    {
      myImageWriter->SetInput( singleSliceImage );
      myImageWriter->SetExtension(".png");
      myImageWriter->Update();

      mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage( AppendExtension(filename, ".png").c_str());
      MITK_TEST_CONDITION_REQUIRED( compareImage.IsNotNull(), "Image stored in PNG format was succesfully loaded again");

      MITK_TEST_CONDITION_REQUIRED( CompareImageMetaData(singleSliceImage, compareImage ), "Image meta data unchanged after writing and loading again. ");
      remove(AppendExtension(filename, ".png").c_str());
    }
    catch(itk::ExceptionObject &e)
    {
      MITK_TEST_FAILED_MSG(<< "Exception during .png file writing: " << e.what() );
    }

  }


  // test for exception handling
  try
  {
    MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
    myImageWriter->SetInput(image);
    myImageWriter->SetFileName("/usr/bin");
    myImageWriter->Update();
    MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)
  }
  catch(...) {
    //this means that a wrong exception (i.e. no itk:Exception) has been thrown
    MITK_TEST_FAILED_MSG(<< "Wrong exception (i.e. no itk:Exception) caught during write");
  }

  // always end with this!
  MITK_TEST_END();
}
Exemple #25
0
//## Documentation
//## main testing method
int mitkPixelTypeTest(int /*argc*/, char* /*argv*/[])
{
  MITK_TEST_BEGIN("PixelTypeTest");

  MITK_INFO << "ptype = mitk::MakePixelType<int, int, 5>();";
  MITK_INFO << "itkPtype = mitk::MakePixelType<ItkImageType>();\n with  itk::Image<itk::FixedArray< int, 5>, 3> ItkImageType";

  mitk::PixelType ptype = mitk::MakePixelType<int, int, 5>();
  typedef itk::Image<itk::FixedArray< int, 5>, 3> ItkImageType;
  mitk::PixelType itkPtype = mitk::MakePixelType<ItkImageType>();

  MITK_TEST_CONDITION_REQUIRED( ptype.GetComponentType() == itk::ImageIOBase::INT, "GetComponentType()");
 // MITK_TEST_CONDITION( ptype.GetPixelTypeId() == typeid(ItkImageType), "GetPixelTypeId()");

  MITK_INFO << ptype.GetPixelTypeAsString();
  MITK_INFO << typeid(ItkImageType).name();

  MITK_TEST_CONDITION_REQUIRED( ptype.GetBpe() == 8*sizeof(int)*5, "[ptype] GetBpe()");
  MITK_TEST_CONDITION_REQUIRED( ptype.GetNumberOfComponents() == 5, "[ptype]GetNumberOfComponents()");
  MITK_TEST_CONDITION_REQUIRED( ptype.GetBitsPerComponent() == 8*sizeof(int), "[ptype]GetBitsPerComponent()");

  MITK_TEST_CONDITION_REQUIRED( itkPtype.GetBpe() == 8*sizeof(int)*5, "[itkPType] GetBpe()");
  MITK_TEST_CONDITION_REQUIRED( itkPtype.GetNumberOfComponents() == 5, "[itkPType] GetNumberOfComponents()");
  MITK_TEST_CONDITION_REQUIRED( itkPtype.GetBitsPerComponent() == 8*sizeof(int), "[itkPType] GetBitsPerComponent()");

  // MITK_TEST_CONDITION_REQUIRED( itkPtype == ptype, "[itkPtype = ptype]");

  //MITK_TEST_CONDITION( ptype.GetPixelTypeAsString().compare("unknown") == 0, "GetPixelTypeAsString()");
  {

    {
      mitk::PixelType ptype2( ptype);
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetComponentType() == itk::ImageIOBase::INT, "ptype2( ptype)- GetComponentType()");
      MITK_TEST_CONDITION( ptype2.GetPixelType() == ptype.GetPixelType(), "ptype2( ptype)-GetPixelType(");
      MITK_TEST_CONDITION( ptype2.GetComponentType() == ptype.GetComponentType(), "ptype2( ptype)-GetComponentType(");
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetBpe() == 8*sizeof(int)*5, "ptype2( ptype)-GetBpe()");
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetNumberOfComponents() == 5, "ptype2( ptype)-GetNumberOfComponents()");
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetBitsPerComponent() == 8*sizeof(int), "ptype2( ptype)-GetBitsPerComponent()");
 //     MITK_TEST_CONDITION_REQUIRED( ptype.GetPixelTypeAsString().compare("unknown") == 0, "ptype2( ptype)-GetPixelTypeAsString()");
    }

    {
      mitk::PixelType ptype2 = ptype;
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetComponentType() == itk::ImageIOBase::INT, "ptype2 = ptype- GetComponentType()");
      MITK_TEST_CONDITION( ptype2.GetPixelType() == ptype.GetPixelType(), "ptype2 = ptype- GetPixelType(");
      MITK_TEST_CONDITION( ptype2.GetComponentType() == ptype.GetComponentType(), "ptype2( ptype)-GetComponentType(");
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetBpe() == 8*sizeof(int)*5, "ptype2 = ptype- GetBpe()");
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetNumberOfComponents() == 5, "ptype2 = ptype- GetNumberOfComponents()");
      MITK_TEST_CONDITION_REQUIRED( ptype2.GetBitsPerComponent() == 8*sizeof(int), "ptype2 = ptype- GetBitsPerComponent()");
 //     MITK_TEST_CONDITION_REQUIRED( ptype.GetPixelTypeAsString().compare("unknown") == 0, "ptype2 = ptype- GetPixelTypeAsString()");
    }

    {
      mitk::PixelType ptype2 = ptype;
      MITK_TEST_CONDITION_REQUIRED( ptype == ptype2, "operator ==");
      //MITK_TEST_CONDITION_REQUIRED( ptype == typeid(int), "operator ==");
      //mitk::PixelType ptype3 = mitk::MakePixelType<char, char ,5>;
      //MITK_TEST_CONDITION_REQUIRED( ptype != ptype3, "operator !=");
      //MITK_TEST_CONDITION_REQUIRED( *ptype3 != typeid(int), "operator !=");
    }
  }

  // test instantiation
  typedef itk::Image< MyObscurePixelType > MyObscureImageType;
  mitk::PixelType obscurePixelType = mitk::MakePixelType< MyObscureImageType >();

  MITK_TEST_CONDITION( obscurePixelType.GetPixelType() == itk::ImageIOBase::UNKNOWNPIXELTYPE, "PixelTypeId is 'UNKNOWN' ");
  MITK_TEST_CONDITION( obscurePixelType.GetNumberOfComponents() == MyObscurePixelType::Length, "Lenght was set correctly");
  MITK_TEST_CONDITION( obscurePixelType.GetComponentType() == mitk::MapPixelComponentType<MyObscurePixelType::ValueType>::value, "ValueType corresponds."   );

  typedef itk::VectorImage< short, 3> VectorImageType;
  mitk::PixelType vectorPixelType = mitk::MakePixelType< VectorImageType >( 78 );
  //vectorPixelType.SetVectorLength( 78 );

  typedef itk::Image< itk::Vector< short, 7> > FixedVectorImageType;
  mitk::PixelType fixedVectorPixelType = mitk::MakePixelType< FixedVectorImageType >();

  mitk::PixelType scalarPixelType = mitk::MakeScalarPixelType< float >();

  // test ImageTypeTrait traits class
  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<int, 3>::ImageType) == typeid(itk::Image<int, 3>), "ImageTypeTrait");
  MITK_TEST_CONDITION((mitk::ImageTypeTrait<int, 3>::IsVectorImage == false), "ImageTypeTrait");

  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::FixedArray<short, 2>, 3>::ImageType) == typeid(itk::Image<itk::FixedArray<short, 2>, 3>), "ImageTypeTrait");
  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::FixedArray<short, 2>, 3>::IsVectorImage == false), "ImageTypeTrait");

  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::VariableLengthVector<short>, 3>::ImageType) == typeid(itk::VectorImage<short, 3>), "ImageTypeTrait");
  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::VariableLengthVector<short>, 3>::IsVectorImage == true), "ImageTypeTrait");

  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::Image<int, 3> >::ImageType) == typeid(itk::Image<int, 3>), "ImageTypeTrait");
  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::Image<int, 3> >::IsVectorImage == false), "ImageTypeTrait");

  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::Image<itk::FixedArray<short, 2>, 3> >::ImageType) == typeid(itk::Image<itk::FixedArray<short, 2>, 3>), "ImageTypeTrait");
  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::Image<itk::FixedArray<short, 2>, 3> >::IsVectorImage == false), "ImageTypeTrait");

  MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait<itk::VectorImage<short, 3> >::ImageType) == typeid(itk::VectorImage<short, 3>), "ImageTypeTrait");
  MITK_TEST_CONDITION((mitk::ImageTypeTrait<itk::VectorImage<short, 3> >::IsVectorImage == true), "ImageTypeTrait");

  // test CastableTo

  MITK_TEST_END();
}
static void TestPlanarPolygonPlacement( mitk::PlanarPolygon::Pointer planarPolygon )
{
  // Test for correct minimum number of control points in cross-mode
  MITK_TEST_CONDITION( planarPolygon->GetMinimumNumberOfControlPoints() == 3, "Minimum number of control points" );

  // Test for correct maximum number of control points in cross-mode
  MITK_TEST_CONDITION( planarPolygon->GetMaximumNumberOfControlPoints() == 1000, "Maximum number of control points" );

  // Initial placement of PlanarPolygon
  mitk::Point2D p0;
  p0[0] = 00.0; p0[1] = 0.0;
  planarPolygon->PlaceFigure( p0 );

  // Add second control point
  mitk::Point2D p1;
  p1[0] = 50.0; p1[1] = 00.0;
  planarPolygon->SetControlPoint(1, p1 );

  // Add third control point
  mitk::Point2D p2;
  p2[0] = 50.0; p2[1] = 50.0;
  planarPolygon->AddControlPoint( p2 );

  // Add fourth control point
  mitk::Point2D p3;
  p3[0] = 0.0; p3[1] = 50.0;
  planarPolygon->AddControlPoint( p3 );

  // Test for number of control points
  MITK_TEST_CONDITION( planarPolygon->GetNumberOfControlPoints() == 4, "Number of control points after placement" );

  // Test if PlanarFigure is closed
  MITK_TEST_CONDITION( planarPolygon->IsClosed(), "planar polygon should not be closed, yet, right?" );
  
  planarPolygon->SetClosed(true);

  MITK_TEST_CONDITION( planarPolygon->IsClosed(), "planar polygon should be closed after function call, right?" );
  
  // Test for number of polylines
  const mitk::PlanarFigure::PolyLineType polyLine0 = planarPolygon->GetPolyLine( 0 );
  mitk::PlanarFigure::PolyLineType::const_iterator iter = polyLine0.begin();
  MITK_TEST_CONDITION( planarPolygon->GetPolyLinesSize() == 1, "Number of polylines after placement" );

  // Get polylines and check if the generated coordinates are OK
  const mitk::Point2D& pp0 = iter->Point;
  ++iter;
  const mitk::Point2D& pp1 = iter->Point;
  MITK_TEST_CONDITION( ((pp0 == p0) && (pp1 == p1))
    || ((pp0 == p1) && (pp1 == p0)), "Correct polyline 1" );

    
  // Test for number of measurement features
  planarPolygon->EvaluateFeatures();
  MITK_TEST_CONDITION( planarPolygon->GetNumberOfFeatures() == 2, "Number of measurement features" );

  // Test for correct feature evaluation
  double length0 = 4 * 50.0; // circumference
  MITK_TEST_CONDITION( fabs( planarPolygon->GetQuantity( 0 ) - length0) < mitk::eps, "Size of longest diameter" );

  double length1 = 50.0 * 50.0 ; // area
  MITK_TEST_CONDITION( fabs( planarPolygon->GetQuantity( 1 ) - length1) < mitk::eps, "Size of short axis diameter" );
}
/**Documentation
 *  test for the class "NavigationDataToNavigationDataFilter".
 */
int mitkNavigationDataToNavigationDataFilterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("NavigationDataToNavigationDataFilter")

  // let's create an object of our class
  mitk::NavigationDataToNavigationDataFilter::Pointer myFilter = NavigationDataToNavigationDataFilterTestClass::New().GetPointer(); // create testing subclass, but treat it like the real NavigationDataToNavigationDataFilter

  MITK_TEST_CONDITION_REQUIRED(myFilter.IsNotNull(),"Testing instantiation");

  /* create helper objects: navigation data with position as origin, zero quaternion, zero error and data valid */
  mitk::NavigationData::PositionType initialPos;
  mitk::FillVector3D(initialPos, 1.0, 2.0, 3.0);
  mitk::NavigationData::OrientationType initialOri(0.1, 0.2, 0.3, 0.4);
  mitk::ScalarType initialError(22.22);
  bool initialValid(true);
  mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New();
  nd0->SetPosition(initialPos);
  nd0->SetOrientation(initialOri);
  nd0->SetPositionAccuracy(initialError);
  nd0->SetDataValid(initialValid);
  nd0->SetName("testName");

  MITK_TEST_CONDITION(myFilter->GetOutput() == NULL, "testing GetOutput()");

  MITK_TEST_CONDITION(myFilter->GetInput() == NULL, "testing GetInput() without SetInput()");
  MITK_TEST_CONDITION(myFilter->GetInput(0) == NULL, "testing GetInput(0) without SetInput()");

  myFilter->SetInput(nd0);
  MITK_TEST_CONDITION(myFilter->GetInput() == nd0, "testing Set-/GetInput()");
  MITK_TEST_CONDITION(myFilter->GetInput(0) == nd0, "testing Set-/GetInput(0)");
  MITK_TEST_CONDITION(myFilter->GetOutput() != NULL, "testing GetOutput() after SetInput()");
  MITK_TEST_CONDITION(myFilter->GetOutput(0) != NULL, "testing GetOutput() after SetInput()");
  MITK_TEST_CONDITION(myFilter->GetOutput(0) != nd0, "testing GetOutput() different object than input");

  // check getInput() string input
  MITK_TEST_CONDITION(myFilter->GetInput("invalidName") == NULL, "testing GetInput(string) invalid string");
  MITK_TEST_CONDITION(myFilter->GetInput("testName") == nd0, "testing GetInput(string) valid string");

  // check getInputIndex() string input
  bool throwsException = false;
  try {
    myFilter->GetInputIndex("invalidName");
  }
  catch(std::invalid_argument e) {
    throwsException = true;
  }
  MITK_TEST_CONDITION_REQUIRED(throwsException, "testing GetInputIndex(string) invalid string");

  MITK_TEST_CONDITION(myFilter->GetInputIndex("testName") == 0, "testing GetInputIndex(string) valid string");


  mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
  nd1->Graft(nd0);
  nd1->SetDataValid(false);
  myFilter->SetInput(1, nd1);
  MITK_TEST_CONDITION(myFilter->GetInput(1) == nd1, "testing Set-/GetInput(1)");
  MITK_TEST_CONDITION(myFilter->GetInput(0) == nd0, "testing Set-/GetInput(0) again");
  MITK_TEST_CONDITION(myFilter->GetOutput(1) != NULL, "testing GetOutput() after SetInput()");
  MITK_TEST_CONDITION(myFilter->GetOutput(0) != myFilter->GetOutput(1), "testing GetOutput(0) different object than GetOutput(1)");

  myFilter->SetInput(10, nd1);
  MITK_TEST_CONDITION(myFilter->GetNumberOfInputs() == 11, "testing SetInput(10) produces 11 outputs");
  MITK_TEST_CONDITION(myFilter->GetInput(10) == nd1, "testing Set-/GetInput(10)");

  myFilter->SetInput(10, NULL);
  MITK_TEST_CONDITION(myFilter->GetNumberOfInputs() == 10, "testing SetInput(10, NULL) removes output with index 10");

  myFilter->SetInput(1, NULL);
  MITK_TEST_CONDITION(myFilter->GetNumberOfInputs() == 10, "testing SetInput(1, NULL) does not change number of outputs");

  // always end with this!
  MITK_TEST_END();
}
/**Documentation
 *  test for the class "NavigationDataSource".
 */
int mitkTrackingDeviceSourceTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("TrackingDeviceSource");

  // let's create an object of our class
  mitk::TrackingDeviceSource::Pointer mySource = mitk::TrackingDeviceSource::New();

  // first test: did this work?
  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
  // it makes no sense to continue without an object.
  MITK_TEST_CONDITION_REQUIRED(mySource.IsNotNull(), "Testing instantiation");

  mySource->SetTrackingDevice(NULL);
  MITK_TEST_CONDITION(mySource->GetTrackingDevice() == NULL, "Testing Set/GetTrackingDevice(NULL)");
  MITK_TEST_CONDITION(mySource->GetNumberOfOutputs() == 0, "Testing GetNumberOfOutputs with NULL td");
  MITK_TEST_FOR_EXCEPTION(std::invalid_argument, mySource->Connect());
  MITK_TEST_FOR_EXCEPTION(std::invalid_argument, mySource->StartTracking());

  mitk::VirtualTrackingDevice::Pointer tracker = mitk::VirtualTrackingDevice::New();
  tracker->SetRefreshRate(10);


  mySource->SetTrackingDevice(tracker);
  MITK_TEST_CONDITION(mySource->GetTrackingDevice() == tracker.GetPointer(), "Testing Set/GetTrackingDevice(tracker)");
  MITK_TEST_CONDITION(mySource->GetNumberOfOutputs() == 0, "Testing GetNumberOfOutputs with no tool tracker");
  tracker = mitk::VirtualTrackingDevice::New();
  mitk::ReferenceCountWatcher::Pointer watch = new mitk::ReferenceCountWatcher(tracker);

  tracker->AddTool("T0");
  tracker->AddTool("T1");
  mySource->SetTrackingDevice(tracker);
  MITK_TEST_CONDITION(mySource->GetTrackingDevice() == tracker.GetPointer(), "Testing Set/GetTrackingDevice(tracker2)");
  MITK_TEST_CONDITION(mySource->GetNumberOfOutputs() == 2, "Testing GetNumberOfOutputs with 2 tools tracker");
  MITK_TEST_CONDITION(mySource->IsConnected() == false, "Testing IsConnected()");
  mySource->Connect();
  MITK_TEST_CONDITION(mySource->IsConnected() == true, "Testing Connect()/IsConnected()");
  MITK_TEST_CONDITION(tracker->GetState() == mitk::TrackingDevice::Ready, "Testing Connect()/IsConnected() 2");
  mySource->Disconnect();
  MITK_TEST_CONDITION(mySource->IsConnected() == false, "Testing Disconnect()/IsConnected()");
  MITK_TEST_CONDITION(tracker->GetState() == mitk::TrackingDevice::Setup, "Testing Disconnect()/IsConnected() 2");

  mySource->Connect();
  mySource->StartTracking();
  MITK_TEST_CONDITION(mySource->IsConnected() == true, "Testing StartTracking()/IsConnected()");
  MITK_TEST_CONDITION(mySource->IsTracking() == true, "Testing StartTracking()/IsTracking()");
  MITK_TEST_CONDITION(tracker->GetState() == mitk::TrackingDevice::Tracking, "Testing StartTracking()/IsTracking() 2");

  unsigned long modTime = mySource->GetMTime();
  mySource->UpdateOutputInformation();
  MITK_TEST_CONDITION(mySource->GetMTime() != modTime, "Testing if UpdateOutputInformation() modifies the object");

  //test getOutput()
  mitk::NavigationData* nd0 = mySource->GetOutput();
  MITK_TEST_CONDITION_REQUIRED(nd0!=NULL,"Testing GetOutput() [1]");
  nd0 = mySource->GetOutput(nd0->GetName());
  MITK_TEST_CONDITION_REQUIRED(nd0!=NULL,"Testing GetOutput() [2]");

  //test getOutputIndex()
  MITK_TEST_CONDITION(mySource->GetOutputIndex(nd0->GetName())==0,"Testing GetOutputIndex()");

  //test GraftNthOutput()
  mitk::NavigationData::Pointer ndCopy = mitk::NavigationData::New();
  mySource->GraftNthOutput(1,nd0);
  ndCopy = mySource->GetOutput(1);
  MITK_TEST_CONDITION(std::string(ndCopy->GetName())==std::string(nd0->GetName()),"Testing GraftNthOutput()");

  //test GetParameters()
  mitk::PropertyList::ConstPointer p = mySource->GetParameters();
  MITK_TEST_CONDITION(p.IsNotNull(),"Testing GetParameters()");

  nd0->Update();
  mitk::NavigationData::PositionType pos = nd0->GetPosition();
  unsigned long tmpMTime0 = nd0->GetMTime();
  itksys::SystemTools::Delay(500); // allow the tracking thread to advance the tool position
  nd0->Update();
  mitk::NavigationData::PositionType newPos = nd0->GetPosition();
  if(nd0->GetMTime() == tmpMTime0) //tool not modified yet
  {
    MITK_TEST_CONDITION(mitk::Equal(newPos, pos) == true, "Testing if output changes on each update");
  }
  else
  {
    MITK_TEST_CONDITION(mitk::Equal(newPos, pos) == false, "Testing if output changes on each update");
  }

  mySource->StopTracking();
  mySource->Disconnect();

  tracker = mitk::VirtualTrackingDevice::New();
  mySource->SetTrackingDevice(tracker);
  MITK_TEST_CONDITION(watch->GetReferenceCount() == 0, "Testing if reference to previous tracker object is released");
  watch = NULL;

  MITK_TEST_FOR_EXCEPTION(std::runtime_error, mySource->StartTracking()); // new tracker, needs Connect() before StartTracking()

  mySource->Connect();
  mySource->StartTracking();
 // itksys::SystemTools::Delay(800); // wait for tracking thread to start properly //DEBUG ONLY  --> race condition. will the thread start before the object is destroyed? --> maybe hold a smartpointer?
  try
  {
    mySource = NULL;  // delete source
    tracker = NULL;   // delete tracker --> both should not result in any exceptions or deadlocks
  }
  catch (...)
  {
    MITK_TEST_FAILED_MSG(<< "exception during destruction of source or tracker!");
  }

  // always end with this!
  MITK_TEST_END();
}
Exemple #29
0
int mitkVectorTest(int /*argc*/, char* /*argv*/[])
{
  MITK_TEST_BEGIN("mitkVector");
  // test itk vector equality methods
  itk::Vector<float,3> itkVector_1;
  itkVector_1[0] = 4.6;
  itkVector_1[1] = 9.76543;
  itkVector_1[2] = 746.09;

  itk::Vector<float,3> itkVector_2;
  itk::Vector<float,3> itkVector_3;
  for (int i=0; i<3; i++)
  {
    itkVector_2[i] = itkVector_1[i] - mitk::eps*1.1;
    itkVector_3[i] = itkVector_1[i] - mitk::eps*0.9;
  }

  MITK_TEST_CONDITION(mitk::Equal(itkVector_1,itkVector_1), "Test vector equality using the same vector with mitk::eps");
  MITK_TEST_CONDITION(!mitk::Equal(itkVector_1,itkVector_2), "Test vector equality using different vectors with an element-wise difference greater than mitk::eps");
  MITK_TEST_CONDITION( mitk::Equal(itkVector_1, itkVector_2, mitk::eps*1.2f), "Vectors are equal for higher epsilon tolerance ( 1.2 * mitk::eps )");
  MITK_TEST_CONDITION(mitk::Equal(itkVector_1,itkVector_3), "Test vector equality using different vectors with an element-wise difference less than mitk::eps");
  // test itk point equality methods
  itk::Point<float,3> itkPoint_1;
  itk::Point<float,3> itkPoint_2;
  itk::Point<float,3> itkPoint_3;
  for (int i=0; i<3; i++)
  {
    itkPoint_1[i] = itkVector_1[i];
    itkPoint_2[i] = itkVector_2[i];
    itkPoint_3[i] = itkVector_3[i];
  }
  MITK_TEST_CONDITION(mitk::Equal(itkPoint_1,itkPoint_1), "Test point equality using the same point with mitk::eps");
  MITK_TEST_CONDITION(!mitk::Equal(itkPoint_1,itkPoint_2), "Test point equality using different points with an element-wise difference greater than mitk::eps");
  MITK_TEST_CONDITION( mitk::Equal(itkPoint_1, itkPoint_2, mitk::eps * 1.2f), "Points are equal for higher epsilon tolerance ( 1.2 * mitk::eps )");
  MITK_TEST_CONDITION(mitk::Equal(itkPoint_1,itkPoint_3), "Test point equality using different points with an element-wise difference less than mitk::eps");
  // test mitk vnl vector equality methods
  mitk::VnlVector mitk_vnl_vector_1(3);
  mitk::VnlVector mitk_vnl_vector_2(3);
  mitk::VnlVector mitk_vnl_vector_3(3);
  for (int i=0; i<3; i++)
  {
    mitk_vnl_vector_1.put(i,itkVector_1[i]);
    mitk_vnl_vector_2.put(i,itkVector_2[i]);
    mitk_vnl_vector_3.put(i,itkVector_1[i]);
  }

  MITK_TEST_CONDITION(mitk::Equal(mitk_vnl_vector_1,mitk_vnl_vector_1), "Test mitk vnl vector equality using the same mitk vnl vector with mitk::eps");
  MITK_TEST_CONDITION(!mitk::Equal(mitk_vnl_vector_1,mitk_vnl_vector_2), "Test mitk vnl vector equality using different mitk vnl vectors with an element-wise difference greater than mitk::eps");
  MITK_TEST_CONDITION( mitk::Equal(mitk_vnl_vector_1, mitk_vnl_vector_2, true, mitk::eps*1.2), "Vnl vectors are equal for higher epsilon tolerance ( 1.2 * mitk::eps )");
  MITK_TEST_CONDITION(mitk::Equal(mitk_vnl_vector_1,mitk_vnl_vector_3), "Test mitk vnl vector equality using different mitk vnl vectors with an element-wise difference less than mitk::eps");

  // test vnl_vector equality method
  typedef mitk::ScalarType VnlValueType;
  vnl_vector_fixed<VnlValueType,7> vnlVector_1;
  vnlVector_1[3] = 56.98;
  vnlVector_1[4] = 22.32;
  vnlVector_1[5] = 1.00;
  vnlVector_1[6] = 746.09;
  vnl_vector_fixed<VnlValueType,7> vnlVector_2;
  vnl_vector_fixed<VnlValueType,7> vnlVector_3;
  for (int i=0; i<7; i++)
  {
    if (i<3)
    {
      vnlVector_1.put(i,itkVector_1[i]);
    }

    vnlVector_2[i] = vnlVector_1[i] - mitk::eps * 1.1f;
    vnlVector_3[i] = vnlVector_1[i] - mitk::eps * 0.9f;
  }

  MITK_TEST_CONDITION( (mitk::Equal<VnlValueType, 7>(vnlVector_1,vnlVector_1)), "vnl_fixed : v_1 == v_1 ");
  // the v_2 is constructed so that the equality test fails for mitk::eps, the norm of the difference between the vectors is 7 * eps/6.9
  MITK_TEST_CONDITION(!(mitk::Equal<VnlValueType, 7>(vnlVector_1,vnlVector_2)), "vnl_fixed : v_1 != v_2 with mitk::eps ");
  // increase the epsilon value used for testing equality - should now pass  ( 1.2 * mitk::eps > 7 * mitk::eps/6.9 )
  MITK_TEST_CONDITION( (mitk::Equal<VnlValueType, 7>(vnlVector_1,vnlVector_2, mitk::eps*1.2f)) , "vnl_fixed : v_1 == v_2 with eps = 1.2 * mitk::eps ");
  MITK_TEST_CONDITION( (mitk::Equal<VnlValueType, 7>(vnlVector_1,vnlVector_3, mitk::eps)), "vnl_fixed : v_1 == v_3 with eps = 0.8 * mitk::eps ");
  MITK_TEST_CONDITION(!(mitk::Equal<VnlValueType, 7>(vnlVector_1,vnlVector_3, mitk::eps*0.8f)), "vnl_fixed : v_1 != v_3 with eps = 0.8 * mitk::eps ");

  // test scalar equality method
  double scalar1 = 0.5689;
  double scalar2 = scalar1 + mitk::eps;
  double scalar3 = scalar1 + mitk::eps*0.95;
  MITK_TEST_CONDITION(mitk::Equal(scalar1,scalar1), "Test scalar equality using the same scalar with mitk::eps");
  MITK_TEST_CONDITION(!mitk::Equal(scalar1,scalar2), "Test scalar equality using the different scalars with a difference greater than mitk::eps");
  MITK_TEST_CONDITION(mitk::Equal(scalar1,scalar3), "Test scalar equality using the different scalars with a difference less than mitk::eps");

  // test matrix equality methods
  vnl_matrix_fixed<mitk::ScalarType,3,3> vnlMatrix3x3_1;
  vnlMatrix3x3_1(0,0) = 1.1;
  vnlMatrix3x3_1(0,1) = 0.4;
  vnlMatrix3x3_1(0,2) = 5.3;
  vnlMatrix3x3_1(1,0) = 2.7;
  vnlMatrix3x3_1(1,1) = 3578.56418;
  vnlMatrix3x3_1(1,2) = 123.56;
  vnlMatrix3x3_1(2,0) = 546.89;
  vnlMatrix3x3_1(2,1) = 0.0001;
  vnlMatrix3x3_1(2,2) = 1.0;
  vnl_matrix_fixed<mitk::ScalarType,3,3> vnlMatrix3x3_2;
  vnlMatrix3x3_2(0,0) = 1.1000009;
  vnlMatrix3x3_2(0,1) = 0.4000009;
  vnlMatrix3x3_2(0,2) = 5.3000009;
  vnlMatrix3x3_2(1,0) = 2.7000009;
  vnlMatrix3x3_2(1,1) = 3578.5641809;
  vnlMatrix3x3_2(1,2) = 123.5600009;
  vnlMatrix3x3_2(2,0) = 546.8900009;
  vnlMatrix3x3_2(2,1) = 0.0001009;
  vnlMatrix3x3_2(2,2) = 1.0000009;

  mitk::ScalarType epsilon = 0.000001;
  MITK_TEST_CONDITION(mitk::MatrixEqualElementWise(vnlMatrix3x3_1,vnlMatrix3x3_1,0.0),"Test for matrix equality with given epsilon=0.0 and exactly the same matrix elements");
  MITK_TEST_CONDITION(!mitk::MatrixEqualElementWise(vnlMatrix3x3_1,vnlMatrix3x3_2,0.0),"Test for matrix equality with given epsilon=0.0 and slightly different matrix elements");
  MITK_TEST_CONDITION(mitk::MatrixEqualElementWise(vnlMatrix3x3_1,vnlMatrix3x3_2,epsilon),"Test for matrix equality with given epsilon and slightly different matrix elements");
  MITK_TEST_CONDITION(!mitk::MatrixEqualRMS(vnlMatrix3x3_1,vnlMatrix3x3_2,0.0),"Test for matrix equality with given epsilon=0.0 and slightly different matrix elements");
  MITK_TEST_CONDITION(mitk::MatrixEqualRMS(vnlMatrix3x3_1,vnlMatrix3x3_2,epsilon),"Test for matrix equality with given epsilon and slightly different matrix elements");

  MITK_TEST_END();
}
/**Documentation
 *  test for the class "NavigationDataToMessageFilter".
 */
int mitkNavigationDataToMessageFilterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("NavigationDataToMessageFilter");
  /* first tests with one input */
  {
    // let's create an object of our class
    mitk::NavigationDataToMessageFilter::Pointer myFilter = mitk::NavigationDataToMessageFilter::New();

    // first test: did this work?
    // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
    // it makes no sense to continue without an object.
    MITK_TEST_CONDITION_REQUIRED(myFilter.IsNotNull(),"Testing instantiation");

    /* create helper objects: navigation data with position as origin, zero quaternion, zero error and data valid */
    mitk::NavigationData::PositionType initialPos;
    mitk::FillVector3D(initialPos, 1.0, 2.0, 3.0);
    mitk::NavigationData::OrientationType initialOri(1.0, 2.0, 3.0, 4.0);

    mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
    nd1->SetPosition(initialPos);
    nd1->SetOrientation(initialOri);
    nd1->SetPositionAccuracy(11.111);
    nd1->SetTimeStamp(64.46);
    nd1->SetDataValid(true);

    myFilter->SetInput(nd1);
    MITK_TEST_CONDITION(myFilter->GetInput() == nd1, "testing Set-/GetInput()");

    mitk::NavigationData* output = myFilter->GetOutput();
    MITK_TEST_CONDITION_REQUIRED(output != NULL, "Testing GetOutput()");


    /* register message receiver */
    MessageReceiverClass answers(1);
    myFilter->AddPositionChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::PositionType, unsigned int>(&answers, &MessageReceiverClass::OnPositionChanged));
    myFilter->AddOrientationChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::OrientationType, unsigned int>(&answers, &MessageReceiverClass::OnOrientationChanged));
    myFilter->AddErrorChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::CovarianceMatrixType, unsigned int>(&answers, &MessageReceiverClass::OnErrorChanged));
    myFilter->AddTimeStampChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::TimeStampType, unsigned int>(&answers, &MessageReceiverClass::OnTimeStampChanged));
    myFilter->AddDataValidChangedListener(mitk::MessageDelegate2<MessageReceiverClass, bool, unsigned int>(&answers, &MessageReceiverClass::OnDataValidChanged));


    output->Update(); // execute filter
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetPosition(), nd1->GetPosition()), "Testing PositionChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetOrientation(), nd1->GetOrientation()), "Testing OrientationChanged message");
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->GetCovErrorMatrix() == nd1->GetCovErrorMatrix(), "Testing ErrorChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetTimeStamp(), nd1->GetTimeStamp()), "Testing TimeStampChanged message");
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->IsDataValid() == nd1->IsDataValid(), "Testing PositionChanged message");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 5, "Correct number of messages send?");

    /* change one input parameter */
    nd1->SetDataValid(false);
    output->Update(); // re-execute filter
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->IsDataValid() == nd1->IsDataValid(), "Testing PositionChanged message");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 6, "only necessary messages send?");  // only datavalid message re-send

    /* changing two input parameters */
    mitk::FillVector3D(initialPos, 11.0, 21.0, 31.0);
    nd1->SetPosition(initialPos); // change only one parameter
    nd1->SetTimeStamp(55.55); // change only one parameter
    output->Update(); // re-execute filter
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetPosition(), nd1->GetPosition()), "Testing PositionChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetTimeStamp(), nd1->GetTimeStamp()), "Testing TimeStampChanged message");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 8, "only necessary messages send?");  // only 2 new messages send

    /* try to add a second input */
    //MITK_TEST_OUTPUT_NO_ENDL( << "Exception on adding second input? --> ");
    //mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New();
    //MITK_TEST_FOR_EXCEPTION(std::invalid_argument, myFilter->SetInput(1, nd2));

  }
  /* now test with multiple inputs */
  {
    MITK_TEST_OUTPUT( << "Now, perform tests with multiple inputs");

    mitk::NavigationDataToMessageFilter::Pointer myFilter = mitk::NavigationDataToMessageFilter::New();

    /* create helper objects: navigation data with position as origin, zero quaternion, zero error and data valid */
    mitk::NavigationData::PositionType initialPos;
    mitk::FillVector3D(initialPos, 1.0, 1.0, 1.0);
    mitk::NavigationData::OrientationType initialOri(1.0, 1.0, 1.0, 1.0);

    mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New();
    nd0->SetPosition(initialPos);
    nd0->SetOrientation(initialOri);
    nd0->SetPositionAccuracy(11.111);
    nd0->SetTimeStamp(64.46);
    nd0->SetDataValid(true);

    mitk::FillVector3D(initialPos, 2.0, 2.0, 2.0);
    mitk::NavigationData::OrientationType initialOri2(1.0, 1.0, 1.0, 1.0);
    mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
    nd1->SetPosition(initialPos);
    nd1->SetOrientation(initialOri2);
    nd1->SetPositionAccuracy(22.222);
    nd1->SetTimeStamp(222.2);
    nd1->SetDataValid(true);

    myFilter->SetInput(0, nd0);
    myFilter->SetInput(1, nd1);
    MITK_TEST_CONDITION(myFilter->GetInput(0) == nd0, "testing Set-/GetInput(0)");
    MITK_TEST_CONDITION(myFilter->GetInput(1) == nd1, "testing Set-/GetInput(1)");

    mitk::NavigationData* output0 = myFilter->GetOutput(0);
    mitk::NavigationData* output1 = myFilter->GetOutput(1);
    MITK_TEST_CONDITION_REQUIRED(output0 != NULL, "Testing GetOutput(0)");
    MITK_TEST_CONDITION_REQUIRED(output1 != NULL, "Testing GetOutput(1)");

    /* register message receiver */
    MessageReceiverClass answers(2);
    myFilter->AddPositionChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::PositionType, unsigned int>(&answers, &MessageReceiverClass::OnPositionChanged));
    myFilter->AddOrientationChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::OrientationType, unsigned int>(&answers, &MessageReceiverClass::OnOrientationChanged));
    myFilter->AddErrorChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::CovarianceMatrixType, unsigned int>(&answers, &MessageReceiverClass::OnErrorChanged));
    myFilter->AddTimeStampChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::TimeStampType, unsigned int>(&answers, &MessageReceiverClass::OnTimeStampChanged));
    myFilter->AddDataValidChangedListener(mitk::MessageDelegate2<MessageReceiverClass, bool, unsigned int>(&answers, &MessageReceiverClass::OnDataValidChanged));

    output0->Update(); // execute filter. This should send messages for both inputs
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetPosition(), nd0->GetPosition()), "Testing PositionChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetOrientation(), nd0->GetOrientation()), "Testing OrientationChanged message");
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->GetCovErrorMatrix() == nd0->GetCovErrorMatrix(), "Testing ErrorChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[0]->GetTimeStamp(), nd0->GetTimeStamp()), "Testing TimeStampChanged message");
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->IsDataValid() == nd0->IsDataValid(), "Testing PositionChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[1]->GetPosition(), nd1->GetPosition()), "Testing PositionChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[1]->GetOrientation(), nd1->GetOrientation()), "Testing OrientationChanged message");
    MITK_TEST_CONDITION( answers.m_ReceivedData[1]->GetCovErrorMatrix() == nd1->GetCovErrorMatrix(), "Testing ErrorChanged message");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[1]->GetTimeStamp(), nd1->GetTimeStamp()), "Testing TimeStampChanged message");
    MITK_TEST_CONDITION( answers.m_ReceivedData[1]->IsDataValid() == nd1->IsDataValid(), "Testing PositionChanged message");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 10, "Correct number of messages send?");
    MITK_TEST_OUTPUT( << "answers.m_MessagesReceived = " << answers.m_MessagesReceived);
    /* change one input parameter */
    nd0->SetDataValid(false);
    output0->Update(); // re-execute filter
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->IsDataValid() == nd0->IsDataValid(), "Testing PositionChanged message for input 0");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 11, "only necessary messages send?");  // only datavalid message for input 0 re-send

    /* remove one listener and check that message is not send */
    myFilter->RemoveTimeStampChangedListener(mitk::MessageDelegate2<MessageReceiverClass, mitk::NavigationData::TimeStampType, unsigned int>(&answers, &MessageReceiverClass::OnTimeStampChanged));
    mitk::NavigationData::TimeStampType oldValue = nd1->GetTimeStamp();
    nd1->SetTimeStamp(999.9);
    myFilter->Update();
    MITK_TEST_CONDITION( ! mitk::Equal(answers.m_ReceivedData[1]->GetTimeStamp(), nd1->GetTimeStamp()), "Testing if TimeStamp message is _not_ send after RemoveListener (!= new value)");
    MITK_TEST_CONDITION( mitk::Equal(answers.m_ReceivedData[1]->GetTimeStamp(), oldValue), "Testing if TimeStamp message is _not_ send after RemoveListener (== old value)");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 11, "no new messages send?");  // no new message send?
    /* other messages are still send? */
    nd1->SetDataValid(false);
    myFilter->Update();
    MITK_TEST_CONDITION( answers.m_ReceivedData[1]->IsDataValid() == nd1->IsDataValid(), "Other messages still send? ->Testing PositionChanged message for input 1 again");
    MITK_TEST_CONDITION( answers.m_MessagesReceived == 12, "only necessary messages send?");  // only DataValid message for input 1 re-send
    /* check if other output still has its old value */
    MITK_TEST_CONDITION( answers.m_ReceivedData[0]->IsDataValid() == nd0->IsDataValid(), "Testing PositionChanged message for input 0");
  }
  // The end
  MITK_TEST_END();
}