コード例 #1
0
int mitkImageTest(int argc, char* argv[])
{

  MITK_TEST_BEGIN(mitkImageTest);

  //Create Image out of nowhere
  mitk::Image::Pointer imgMem;
  mitk::PixelType pt(typeid(int));
  unsigned int dim[]={100,100,20};

  std::cout << "Testing creation of Image: ";
  imgMem=mitk::Image::New();
  if(imgMem.IsNull())
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing Initialize(const mitk::PixelType& type, unsigned int dimension, unsigned int *dimensions): ";
  imgMem->Initialize(mitk::PixelType(typeid(int)), 3, dim);
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing IsInitialized(): ";
  if(imgMem->IsInitialized()==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetData(): ";
  int *p = (int*)imgMem->GetData();
  if(p==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Filling image: ";
  unsigned int i;
  unsigned int size = dim[0]*dim[1]*dim[2];
  for(i=0; i<size; ++i, ++p)
    *p= (signed int)i;
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Getting it again and compare with filled values: ";
  int *p2 = (int*)imgMem->GetData();
  if(p2==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  for(i=0; i<size; ++i, ++p2)
  {
    if(*p2!= (signed int)i )
    {
      std::cout<<"[FAILED]"<<std::endl;
      return EXIT_FAILURE;
    }
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing IsInitialized(): ";
  if(imgMem->IsInitialized()==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  
  std::cout << "Testing GetSliceData() and compare with filled values: ";
  p2 = (int*)imgMem->GetSliceData(dim[2]/2)->GetData();
  unsigned int xy_size = dim[0]*dim[1];
  unsigned int start_mid_slice = (dim[2]/2)*xy_size;
  for(i=0; i<xy_size; ++i, ++p2)
  {
    if(*p2!=(signed int)(i+start_mid_slice))
    {
      std::cout<<"[FAILED]"<<std::endl;
      return EXIT_FAILURE;
    }
  }
  std::cout<<"[PASSED]"<<std::endl;

  //----
  mitkIpPicDescriptor *pic_slice=mitkIpPicClone(imgMem->GetSliceData(dim[2]/2)->GetPicDescriptor());
  imgMem=mitk::Image::New();

  std::cout << "Testing reinitializing via Initialize(const mitk::PixelType& type, unsigned int dimension, unsigned int *dimensions): ";
  imgMem->Initialize(mitk::PixelType(typeid(int)), 3, dim);
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing slice-wise filling via SetPicSlice(): ";
  for(i=0;i<dim[2];++i)
  {
    imgMem->SetPicSlice(pic_slice, i, 0, 0);
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Getting it again and compare with filled values: ";
  p2 = (int*)imgMem->GetData();
  if(p2==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  for(i=0; i<size; ++i, ++p2)
  {
    if(*p2!= (signed int)((i%xy_size)+start_mid_slice))
    {
      std::cout<<"[FAILED]"<<std::endl;
      return EXIT_FAILURE;
    }
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing IsInitialized(): ";
  if(imgMem->IsInitialized()==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Setting a copy of the volume once again: ";
  imgMem->SetPicVolume(mitkIpPicClone(imgMem->GetVolumeData(0)->GetPicDescriptor()),0);
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Set a slice with different content via SetPicSlice(): ";
  memset(pic_slice->data,0,xy_size*sizeof(int));
  imgMem->SetPicSlice(pic_slice, 1);

  std::cout << "Getting the volume again and compare the check the changed slice: ";
  p2 = (int*)imgMem->GetData();
  if(p2==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  p2+=xy_size;
  for(i=0; i<xy_size; ++i, ++p2)
  {
    if(*p2!=0)
    {
      std::cout<<"[FAILED]"<<std::endl;
      return EXIT_FAILURE;
    }
  }
  std::cout<<"[PASSED]"<<std::endl;


  std::cout << "Setting volume again: ";
  imgMem->SetVolume(imgMem->GetData());
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Set a slice with different content via SetSlice(): ";
  memset(pic_slice->data,0,xy_size*sizeof(int));
  imgMem->SetSlice(pic_slice->data, 0);

  std::cout << "Getting the volume again and compare the check the changed slice: ";
  p2 = (int*)imgMem->GetData();
  if(p2==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  for(i=0; i<xy_size; ++i, ++p2)
  {
    if(*p2!=0)
    {
      std::cout<<"[FAILED]"<<std::endl;
      return EXIT_FAILURE;
    }
  }
  std::cout<<"[PASSED]"<<std::endl;



  //std::cout << "Testing SetVolume(): ";
  //imgMem->SetVolume(data);
  //std::cout<<"[PASSED]"<<std::endl;

  mitkIpPicFree(pic_slice);

  //-----------------
  // geometry information for image
  mitk::Point3D origin;
  mitk::Vector3D right, bottom;
  mitk::Vector3D spacing;
  mitk::FillVector3D(origin, 17.0, 19.92, 7.83);
  mitk::FillVector3D(right, 1.0, 2.0, 3.0);
  mitk::FillVector3D(bottom, 0.0, -3.0, 2.0);
  mitk::FillVector3D(spacing, 0.78, 0.91, 2.23);

  std::cout << "Testing InitializeStandardPlane(rightVector, downVector, spacing): " << std::flush;
  mitk::PlaneGeometry::Pointer planegeometry = mitk::PlaneGeometry::New();
  planegeometry->InitializeStandardPlane(100, 100, right, bottom, &spacing);
  planegeometry->SetOrigin(origin);
  std::cout << "done" << std::endl;

  std::cout << "Testing Initialize(const mitk::PixelType& type, const mitk::Geometry3D& geometry, unsigned int slices) with PlaneGeometry and GetData(): ";
  imgMem->Initialize(mitk::PixelType(typeid(int)), *planegeometry);
  p = (int*)imgMem->GetData();
  if(p==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing Initialize(const mitk::PixelType& type, int sDim, const mitk::PlaneGeometry& geometry) and GetData(): ";
  imgMem->Initialize(mitk::PixelType(typeid(int)), 40, *planegeometry);
  p = (int*)imgMem->GetData();
  if(p==NULL)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  //-----------------
  // testing origin information and methods
  std::cout << "Testing correctness of origin via GetGeometry()->GetOrigin(): ";
  if( mitk::Equal(imgMem->GetGeometry()->GetOrigin(), origin) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of origin via GetTimeSlicedGeometry()->GetOrigin(): ";
  if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetOrigin(), origin) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  mitk::FillVector3D(origin, 37.0, 17.92, 27.83);
  std::cout << "Setting origin via SetOrigin(origin): ";
  imgMem->SetOrigin(origin);
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of changed origin via GetGeometry()->GetOrigin(): ";
  if( mitk::Equal(imgMem->GetGeometry()->GetOrigin(), origin) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of changed origin via GetTimeSlicedGeometry()->GetOrigin(): ";
  if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetOrigin(), origin) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of changed origin via GetSlicedGeometry()->GetGeometry2D(0)->GetOrigin(): ";
  if( mitk::Equal(imgMem->GetSlicedGeometry()->GetGeometry2D(0)->GetOrigin(), origin) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  //-----------------
  // testing spacing information and methods
  std::cout << "Testing correctness of spacing via GetGeometry()->GetSpacing(): ";
  if( mitk::Equal(imgMem->GetGeometry()->GetSpacing(), spacing) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of spacing via GetTimeSlicedGeometry()->GetSpacing(): ";
  if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetSpacing(), spacing) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  mitk::FillVector3D(spacing, 7.0, 0.92, 1.83);
  std::cout << "Setting spacing via SetSpacing(spacing): ";
  imgMem->SetSpacing(spacing);
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of changed spacing via GetGeometry()->GetSpacing(): ";
  if( mitk::Equal(imgMem->GetGeometry()->GetSpacing(), spacing) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of changed spacing via GetTimeSlicedGeometry()->GetSpacing(): ";
  if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetSpacing(), spacing) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing correctness of changed spacing via GetSlicedGeometry()->GetGeometry2D(0)->GetSpacing(): ";
  if( mitk::Equal(imgMem->GetSlicedGeometry()->GetGeometry2D(0)->GetSpacing(), spacing) == false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  //-----------------
  MITK_TEST_OUTPUT(<< "Testing SetImportChannel");
  mitk::Image::Pointer vecImg = mitk::Image::New();
  vecImg->Initialize(*imgMem->GetPixelType().GetTypeId(), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/ );
  vecImg->SetImportChannel(imgMem->GetData(), 0, mitk::Image::CopyMemory );
  vecImg->SetImportChannel(imgMem->GetData(), 1, mitk::Image::CopyMemory );
  std::cout<<"[PASSED]"<<std::endl;

  MITK_TEST_OUTPUT(<< " Testing whether IsValidSlice returns valid after SetImportChannel");
  MITK_TEST_CONDITION_REQUIRED( vecImg->IsValidSlice(0,0,1) , "");

  MITK_TEST_OUTPUT(<< " Testing whether CopyMemory worked");
  MITK_TEST_CONDITION_REQUIRED(imgMem->GetData() != vecImg->GetData(), "");

  MITK_TEST_OUTPUT(<< " Testing destruction after SetImportChannel");
  vecImg = NULL; 
  std::cout<<"[PASSED]"<<std::endl;

  //-----------------
  MITK_TEST_OUTPUT(<< "Testing initialization via vtkImageData");
  MITK_TEST_OUTPUT(<< " Setting up vtkImageData");
  vtkImageData* vtkimage = vtkImageData::New();
  vtkimage->Initialize();
  vtkimage->SetDimensions( 2, 3, 4);
  double vtkorigin[] =  {-350,-358.203, -1363.5};
  vtkimage->SetOrigin(vtkorigin);
  mitk::Point3D vtkoriginAsMitkPoint;
  mitk::vtk2itk(vtkorigin, vtkoriginAsMitkPoint);
  double vtkspacing[] =  {1.367, 1.367, 2};
  vtkimage->SetSpacing(vtkspacing);
  vtkimage->SetScalarType( VTK_SHORT );
  vtkimage->AllocateScalars();
  std::cout<<"[PASSED]"<<std::endl;
  
  MITK_TEST_OUTPUT(<< " Testing mitk::Image::Initialize(vtkImageData*, ...)");
  mitk::Image::Pointer mitkByVtkImage = mitk::Image::New();
  mitkByVtkImage ->Initialize(vtkimage);
  MITK_TEST_CONDITION_REQUIRED(mitkByVtkImage->IsInitialized(), "");

  MITK_TEST_OUTPUT(<< " vtkimage->Delete");
  vtkimage->Delete();
  std::cout<<"[PASSED]"<<std::endl;

  MITK_TEST_OUTPUT(<< " Testing whether spacing has been correctly initialized from vtkImageData");
  mitk::Vector3D spacing2 = mitkByVtkImage->GetGeometry()->GetSpacing();
  mitk::Vector3D vtkspacingAsMitkVector;
  mitk::vtk2itk(vtkspacing, vtkspacingAsMitkVector);
  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(spacing2,vtkspacingAsMitkVector), "");

  MITK_TEST_OUTPUT(<< " Testing whether GetSlicedGeometry(0)->GetOrigin() has been correctly initialized from vtkImageData");
  mitk::Point3D origin2 = mitkByVtkImage->GetSlicedGeometry(0)->GetOrigin();
  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2,vtkoriginAsMitkPoint), "");

  MITK_TEST_OUTPUT(<< " Testing whether GetGeometry()->GetOrigin() has been correctly initialized from vtkImageData");
  origin2 = mitkByVtkImage->GetGeometry()->GetOrigin();
  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2,vtkoriginAsMitkPoint), "");

  MITK_TEST_OUTPUT(<< " Testing whether GetTimeSlicedGeometry()->GetOrigin() has been correctly initialized from vtkImageData");
  origin2 = mitkByVtkImage->GetTimeSlicedGeometry()->GetOrigin();
  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2,vtkoriginAsMitkPoint), "");

  // TODO test the following initializers on channel-incorporation
  //  void mitk::Image::Initialize(const mitk::PixelType& type, unsigned int dimension, unsigned int *dimensions, unsigned int channels)
  //  void mitk::Image::Initialize(const mitk::PixelType& type, int sDim, const mitk::Geometry2D& geometry2d, bool flipped, unsigned int channels, int tDim )
  //  void mitk::Image::Initialize(const mitk::Image* image) 
  //  void mitk::Image::Initialize(const mitkIpPicDescriptor* pic, int channels, int tDim, int sDim)

  //mitk::Image::Pointer vecImg = mitk::Image::New();
  //vecImg->Initialize(PixelType(typeid(float), 6, itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/, false /*shiftBoundingBoxMinimumToZero*/ );
  //vecImg->Initialize(PixelType(typeid(itk::Vector<float,6>)), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/, false /*shiftBoundingBoxMinimumToZero*/ );

  // testing access by index coordinates and by world coordinates
  
  mitk::DataNode::Pointer node;      
  mitk::DataNodeFactory::Pointer nodeReader = mitk::DataNodeFactory::New();
  MITK_TEST_CONDITION_REQUIRED(argc == 2, "Check if test image is accessible!"); 
  const std::string filename = std::string(argv[1]);
  try
  {
    nodeReader->SetFileName(filename);
    nodeReader->Update();
    node = nodeReader->GetOutput();      
  }
  catch(...) {
    MITK_TEST_FAILED_MSG(<< "Could not read file for testing: " << filename);
    return NULL;
  }  

  mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(node->GetData());
    
  // test by index coordinates
  mitk::Index3D index;
  mitk::FillVector3D(index, 55, 39, 50);
  MITK_TEST_OUTPUT(<< "Testing mitk::Image::GetPixelValueByIndex");
  double val = image->GetPixelValueByIndex(index);
  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(val,112.22475433349609), "");
  
  //test by world coordinates
  MITK_TEST_OUTPUT(<< "Testing mitk::Image::GetPixelValueByWorldCoordinate");
  mitk::Point3D point;
  mitk::FillVector3D(point, -5.93752, 18.7199, 6.74218);
  val = image->GetPixelValueByWorldCoordinate(point);
  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(val,94.456184387207031), "");

  MITK_TEST_OUTPUT(<< "Convert to index and access value by mitk::Image::GetPixelValueByIndex again");
  mitk::Index3D index2;
  image->GetGeometry()->WorldToIndex(point, index2);
  float val2 = image->GetPixelValueByIndex(index2);
  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(val2,94.456184387207031), "");

  //access via itk
  MITK_TEST_OUTPUT(<< "Test conversion to itk::Image");
  typedef itk::Image<float,3> ItkFloatImage3D;
  ItkFloatImage3D::Pointer itkimage;
  mitk::CastToItkImage(image, itkimage);
  std::cout<<"[PASSED]"<<std::endl;
 
  MITK_TEST_OUTPUT(<< "Testing world->itk-physical->world consistency");
  mitk::Point3D itkPhysicalPoint;
  image->GetGeometry()->WorldToItkPhysicalPoint(point, itkPhysicalPoint);

  mitk::Point3D backTransformedPoint;
  image->GetGeometry()->ItkPhysicalPointToWorld(itkPhysicalPoint, backTransformedPoint);
  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(point,backTransformedPoint), "");

  MITK_TEST_OUTPUT(<< "Compare value of pixel returned by mitk in comparison to itk");
  itk::Index<3> idx;  
  itkimage->TransformPhysicalPointToIndex(itkPhysicalPoint, idx);
  float valByItk = itkimage->GetPixel(idx);

  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(valByItk,94.456184387207031), "");

  mitk::Image::Pointer cloneImage = image->Clone();
  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetDimension() == image->GetDimension(), "Clone (testing dimension)");
  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetPixelType() == image->GetPixelType(), "Clone (testing pixel type)");
  
  for (unsigned int i = 0u; i < cloneImage->GetDimension(); ++i)
  {
    MITK_TEST_CONDITION_REQUIRED(cloneImage->GetDimension(i) == image->GetDimension(i), "Clone (testing dimension " << i << ")");
  }

  
  MITK_TEST_END();

  return EXIT_SUCCESS;
}
コード例 #2
0
//test related to tutorial Step5.cpp
int mitkNodeDependentPointSetInteractorTest(int argc, char* argv[])
{
  MITK_TEST_BEGIN("NodeDependentPointSetInteractor");

  // Global interaction must(!) be initialized if used
  mitk::GlobalInteraction::GetInstance()->Initialize("global");

  // Create a DataStorage
  mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New();
  MITK_TEST_CONDITION_REQUIRED(ds.IsNotNull(),"Instantiating DataStorage");

  //read two images and store to datastorage
  //these two images are used as node the interactors depend on. If the visibility property of one node if false, the 
  //associated interactor may not change the data
  mitk::DataNode::Pointer node1, node2;      
  mitk::DataNodeFactory::Pointer nodeReader = mitk::DataNodeFactory::New();
  
  MITK_TEST_CONDITION_REQUIRED(argc >= 3, "Test if a files to load has been specified");


  try
  {
    //file 1
    const std::string filename1 = argv[1];
    nodeReader->SetFileName(filename1);
    nodeReader->Update();
    node1 = nodeReader->GetOutput();
    ds->Add(node1);

    //file 2
    const std::string filename2 = argv[2];
    nodeReader->SetFileName(filename2);
    nodeReader->Update();
    node2 = nodeReader->GetOutput();
    ds->Add(node2);
  }
  catch(...) {
    MITK_TEST_FAILED_MSG(<< "Could not read file for testing");
    return NULL;
  }

  //check for the two images
  mitk::NodePredicateDataType::Pointer predicate(mitk::NodePredicateDataType::New("Image"));
  mitk::DataStorage::SetOfObjects::ConstPointer allImagesInDS = ds->GetSubset(predicate);
  MITK_TEST_CONDITION_REQUIRED(allImagesInDS->Size()==2,"load images to data storage");

  // Create PointSet and a node for it
  mitk::PointSet::Pointer pointSet1 = mitk::PointSet::New();
  mitk::DataNode::Pointer pointSetNode1 = mitk::DataNode::New();
  pointSetNode1->AddProperty( "unselectedcolor", mitk::ColorProperty::New(0.0f, 1.0f, 0.0f));
  pointSetNode1->SetData(pointSet1);
  mitk::NodeDepententPointSetInteractor::Pointer interactor1 = mitk::NodeDepententPointSetInteractor::New("pointsetinteractor", pointSetNode1, node1); 
  MITK_TEST_CONDITION_REQUIRED(interactor1.IsNotNull(),"Instanciating NodeDependentPointSetInteractor");
  // Add the node to the tree
  ds->Add(pointSetNode1);
  mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor1);

  mitk::PointSet::Pointer pointSet2 = mitk::PointSet::New();
  mitk::DataNode::Pointer pointSetNode2 = mitk::DataNode::New();
  pointSetNode2->AddProperty( "unselectedcolor", mitk::ColorProperty::New(0.0f, 0.0f, 1.0f));
  pointSetNode2->SetData(pointSet2);
  mitk::NodeDepententPointSetInteractor::Pointer interactor2 = mitk::NodeDepententPointSetInteractor::New("pointsetinteractor", pointSetNode2, node2); 
  MITK_TEST_CONDITION_REQUIRED(interactor2.IsNotNull(),"Instanciating NodeDependentPointSetInteractor");
  // Add the node to the tree
  ds->Add(pointSetNode2);
  mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor2);  

  //check for the two pointsets
  mitk::NodePredicateDataType::Pointer predicatePS(mitk::NodePredicateDataType::New("PointSet"));
  mitk::DataStorage::SetOfObjects::ConstPointer allImagesInDSPS = ds->GetSubset(predicatePS);
  MITK_TEST_CONDITION_REQUIRED(allImagesInDSPS->Size()==2,"create associated pointsets to data storage");

  //create two RenderWindows
  mitk::RenderingManager::Pointer myRenderingManager = mitk::RenderingManager::New();
  vtkRenderWindow* vtkRenWin1 = vtkRenderWindow::New();
  mitk::VtkPropRenderer::Pointer br1 = mitk::VtkPropRenderer::New("testingBR", vtkRenWin1, myRenderingManager);
  mitk::BaseRenderer::AddInstance(vtkRenWin1,br1);
  myRenderingManager->AddRenderWindow(vtkRenWin1);
  mitk::BaseRenderer::Pointer renderer1 = mitk::BaseRenderer::GetInstance(vtkRenWin1);

  vtkRenderWindow* vtkRenWin2 = vtkRenderWindow::New();
  mitk::VtkPropRenderer::Pointer br2 = mitk::VtkPropRenderer::New("testingBR", vtkRenWin2, myRenderingManager);
  mitk::BaseRenderer::AddInstance(vtkRenWin2,br2);
  myRenderingManager->AddRenderWindow(vtkRenWin2);
  mitk::BaseRenderer::Pointer renderer2 = mitk::BaseRenderer::GetInstance(vtkRenWin2);

  //set properties for renderWindow 1 and 2
  //1:
  node1->SetBoolProperty("visible", true, renderer1); 
  node2->SetBoolProperty("visible", false, renderer1); 
  //2:
  node1->SetBoolProperty("visible", false, renderer2); 
  node2->SetBoolProperty("visible", true, renderer2); 

  
  //***************************************************
  //now start to test if only an event send from renderwindow 1 can interact with interactor 1 and vice versa

  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==0,"Checking empty pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==0,"Checking empty pointset 2.");

  //sending an event to interactor1
  mitk::Point3D pos3D;
  mitk::Point2D pos2D;
  pos3D[0]= 10.0;  pos3D[1]= 20.0;  pos3D[2]= 30.0;
  pos2D[0]= 100;  pos2D[0]= 200;

  //add to pointset 1
  SendPositionEvent(renderer1, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==1,"1 Checking addition of point to pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==0,"2 Checking empty pointset 2");

  //add to pointset 2
  SendPositionEvent(renderer2, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==1,"3 Checking untouched state of pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==1,"4 Checking addition of point to pointset 2");

  //add to pointset 2
  SendPositionEvent(renderer2, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==1,"5 Checking untouched state of pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==2,"6 Checking addition of point to pointset 2");

  //add to pointset 2
  SendPositionEvent(renderer2, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==1,"7 Checking untouched state of pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==3,"8 Checking addition of point to pointset 2");
  
  //add to pointset 1
  SendPositionEvent(renderer1, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_ShiftButton, mitk::Key_none, pos2D, pos3D);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==2,"9 Checking addition of point to pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==3,"10 Checking untouched state of pointset 2");

  //trying to delete points
  mitk::Event* delEvent1 = new mitk::Event(renderer1, mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete);
  mitk::Event* delEvent2 = new mitk::Event(renderer2, mitk::Type_KeyPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_Delete);
  
  mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent2);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==2,"11 Checking untouched state of pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==2,"12 Checking detected point in pointset 2");

  mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent1);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==1,"11 Checking deleted point in pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==2,"12 Checking untouched state of pointset 2");
  
  mitk::GlobalInteraction::GetInstance()->GetEventMapper()->MapEvent(delEvent2);
  MITK_TEST_CONDITION_REQUIRED(pointSet1->GetPointSet()->GetNumberOfPoints()==1,"13 Checking untouched state of pointset 1");
  MITK_TEST_CONDITION_REQUIRED(pointSet2->GetPointSet()->GetNumberOfPoints()==1,"14 Checking detected point in pointset 2");

  mitk::GlobalInteraction::GetInstance()->RemoveInteractor(interactor1);
  mitk::GlobalInteraction::GetInstance()->RemoveInteractor(interactor2);
  delete delEvent1;
  delete delEvent2;
  
  myRenderingManager->RemoveRenderWindow(vtkRenWin1);
  myRenderingManager->RemoveRenderWindow(vtkRenWin2);
  vtkRenWin1->Delete();
  vtkRenWin2->Delete();

  //destroy RenderingManager
  myRenderingManager = NULL;


  MITK_TEST_END()
}
コード例 #3
0
int mitkEventMapperTest(int argc, char* argv[])
{
  MITK_TEST_BEGIN("EventMapper");

  MITK_TEST_CONDITION_REQUIRED(argc >= 3, "Test if a file to load has been specified");

  //construct IDs to be checked
  auto  mouseButtonPressEvent = new mitk::Event(nullptr, mitk::Type_MouseButtonPress, mitk::BS_LeftButton, mitk::BS_NoButton, mitk::Key_none);
  const int mouseButtonPressID = 1;
  //there is no combination Type_MouseButtonPress and Keys, so use this to be sure to have unique events
  auto  uniqueEventFile1 = new mitk::Event(nullptr, mitk::Type_MouseButtonPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_R);
  const int uniqueEventIDFile1 = 13000;
  auto  uniqueEventFile2 = new mitk::Event(nullptr, mitk::Type_MouseButtonPress, mitk::BS_NoButton, mitk::BS_NoButton, mitk::Key_N);
  const int uniqueEventIDFile2 = 13001;


  //create statemachinefactory
  mitk::EventMapper* eventMapper = mitk::EventMapper::New();

  //load standard behavior
  MITK_TEST_CONDITION_REQUIRED(eventMapper->LoadStandardBehavior(),"Testing LoadStandardBehavior(): ")
  std::cout<<"StyleName: " << eventMapper->GetStyleName()<<"\n";

  mitk::StateEvent stateEvent;
  stateEvent.Set(0, mouseButtonPressEvent);
  eventMapper->RefreshStateEvent(&stateEvent);
  MITK_TEST_CONDITION_REQUIRED(stateEvent.GetId() == mouseButtonPressID,"Testing event mapping of standard xml-file: ")

//  std::string xmlFileName1( "TestStateMachine1.xml" );
  std::string xmlFileName1( argv[1] );
  MITK_TEST_CONDITION_REQUIRED(!xmlFileName1.empty(),"Getting xml file 1: ")
  MITK_TEST_CONDITION_REQUIRED(eventMapper->LoadBehavior(xmlFileName1),"Parsing xml file 1 should throw warning: ")
  //test dubicate file loading
  MITK_TEST_CONDITION_REQUIRED(eventMapper->LoadBehavior(xmlFileName1) == true,"Double parsing should be avoided and not throw warnings.")

  stateEvent.Set(0, uniqueEventFile1);
  eventMapper->RefreshStateEvent(&stateEvent);
  MITK_TEST_CONDITION_REQUIRED(stateEvent.GetId() == uniqueEventIDFile1,"Testing event mapping of first additionally loaded xml-file: ")

  //global still accessible?
  stateEvent.Set(0, mouseButtonPressEvent);
  eventMapper->RefreshStateEvent(&stateEvent);
  MITK_TEST_CONDITION_REQUIRED(stateEvent.GetId() == mouseButtonPressID,"Testing if standard information still available: ")


//  std::string xmlFileName2( "TestStateMachine2.xml" );
  std::string xmlFileName2( argv[2] );
  MITK_TEST_CONDITION_REQUIRED(!xmlFileName2.empty(),"Getting xml file 2: ")
  MITK_TEST_CONDITION_REQUIRED(eventMapper->LoadBehavior(xmlFileName2),"Parsing xml file 2. Warning of double entry should be thrown: ")

  stateEvent.Set(0, uniqueEventFile2);
  eventMapper->RefreshStateEvent(&stateEvent);
  MITK_TEST_CONDITION_REQUIRED(stateEvent.GetId() == uniqueEventIDFile2,"Testing event mapping of second additionally loaded xml-file: ")

  //global still accessible?
  stateEvent.Set(0, mouseButtonPressEvent);
  eventMapper->RefreshStateEvent(&stateEvent);
  MITK_TEST_CONDITION_REQUIRED(stateEvent.GetId() == mouseButtonPressID,"Testing if standard information still available: ")

  eventMapper->Delete();

  // always end with this!
  MITK_TEST_END();
}
コード例 #4
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");
  }

  TestPictureWriting(image, filename, ".png");
  TestPictureWriting(image, filename, ".jpg");
  TestPictureWriting(image, filename, ".tiff");
  TestPictureWriting(image, filename, ".bmp");

  // 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();
}
コード例 #5
0
static void NavigationDataToPointSetFilterContructor_DefaultCall_IsNotEmpty()
{
  Setup();
  MITK_TEST_CONDITION_REQUIRED(m_NavigationDataToPointSetFilter.IsNotNull(), "Testing instantiation");
  //I think this test is meaningless, because it will never ever fail. I keep it for know just to be save.
}
コード例 #6
0
int mitkBaseDataTest(int /*argc*/, char* /*argv*/[])
{

  MITK_TEST_BEGIN("BaseData")

  //Create a BaseData implementation
  MITK_INFO << "Creating a base data instance...";
  mitk::BaseDataTestImplementation::Pointer baseDataImpl = mitk::BaseDataTestImplementation::New();

  MITK_TEST_CONDITION_REQUIRED(baseDataImpl.IsNotNull(),"Testing instantiation");
  MITK_TEST_CONDITION(baseDataImpl->IsInitialized(), "BaseDataTestImplementation is initialized");
  MITK_TEST_CONDITION(baseDataImpl->IsEmpty(), "BaseDataTestImplementation is initialized and empty");
  MITK_TEST_CONDITION(baseDataImpl->GetExternalReferenceCount()== baseDataImpl->GetReferenceCount(), "Checks external reference count!");
  
  mitk::BaseDataTestImplementation::Pointer cloneBaseData = baseDataImpl->Clone();
  MITK_TEST_CONDITION_REQUIRED(cloneBaseData.IsNotNull(),"Testing instantiation of base data clone");
  MITK_TEST_CONDITION(cloneBaseData->IsInitialized(), "Clone of BaseDataTestImplementation is initialized");
  MITK_TEST_CONDITION(cloneBaseData->IsEmpty(), "Clone of BaseDataTestImplementation is initialized and empty");
  MITK_TEST_CONDITION(cloneBaseData->GetExternalReferenceCount()== cloneBaseData->GetReferenceCount(), "Checks external reference count of base data clone!");

  MITK_INFO << "Testing setter and getter for geometries...";

  //test method GetTimeSlicedGeometry()
  MITK_TEST_CONDITION(baseDataImpl->GetTimeSlicedGeometry(), "Testing creation of TimeSlicedGeometry");

  mitk::TimeSlicedGeometry* geo = NULL;
  baseDataImpl->SetGeometry(geo);

  MITK_TEST_CONDITION(baseDataImpl->GetTimeSlicedGeometry() == NULL, "Reset Geometry");

  mitk::TimeSlicedGeometry::Pointer geo2 = mitk::TimeSlicedGeometry::New();
  baseDataImpl->SetGeometry(geo2);
  baseDataImpl->InitializeTimeSlicedGeometry(2);
  MITK_TEST_CONDITION(baseDataImpl->GetTimeSlicedGeometry() == geo2, "Correct Reinit of TimeslicedGeometry");
  
  //test method GetGeometry(int timeStep)  
  MITK_TEST_CONDITION(baseDataImpl->GetGeometry(1) != NULL, "... and single Geometries");
    
  //test method Expand(unsigned int timeSteps)
  baseDataImpl->Expand(5);
  MITK_TEST_CONDITION(baseDataImpl->GetTimeSteps() == 5, "Expand the geometry to further time slices!");
  
  //test method GetUpdatedGeometry(int timeStep);
  mitk::Geometry3D::Pointer geo3 = mitk::Geometry3D::New();
  mitk::TimeSlicedGeometry::Pointer timeSlicedGeometry = baseDataImpl->GetTimeSlicedGeometry();
  if (timeSlicedGeometry.IsNotNull() )
  {
    timeSlicedGeometry->SetGeometry3D(geo3, 1);
  }

  MITK_TEST_CONDITION(baseDataImpl->GetUpdatedGeometry(1) == geo3, "Set Geometry for time step 1");
  MITK_TEST_CONDITION(baseDataImpl->GetMTime()!= 0, "Check if modified time is set");  
  baseDataImpl->SetClonedGeometry(geo3, 1);

  float x[3];
  x[0] = 2; 
  x[1] = 4; 
  x[2] = 6;
  mitk::Point3D p3d(x);
  baseDataImpl->SetOrigin(p3d);
  geo3->SetOrigin(p3d);

  MITK_TEST_CONDITION(baseDataImpl->GetGeometry(1)->GetOrigin() == geo3->GetOrigin(), "Testing Origin set");
  
  cloneBaseData = baseDataImpl->Clone();
  MITK_TEST_CONDITION(cloneBaseData->GetGeometry(1)->GetOrigin() == geo3->GetOrigin(), "Testing origin set in clone!");

  MITK_TEST_CONDITION(!baseDataImpl->IsEmptyTimeStep(1), "Is not empty before clear()!");
  baseDataImpl->Clear();
  MITK_TEST_CONDITION(baseDataImpl->IsEmptyTimeStep(1), "...but afterwards!");
  //test method Set-/GetProperty()
  baseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty"));
  //baseDataImpl->SetProperty("visibility", mitk::BoolProperty::New());
  MITK_TEST_CONDITION(baseDataImpl->GetProperty("property38")->GetValueAsString() == "testproperty","Check if base property is set correctly!");
  
  cloneBaseData = baseDataImpl->Clone();
  MITK_TEST_CONDITION(cloneBaseData->GetProperty("property38")->GetValueAsString() == "testproperty", "Testing origin set in clone!");

  //test method Set-/GetPropertyList
  mitk::PropertyList::Pointer propertyList = mitk::PropertyList::New();
  propertyList->SetFloatProperty("floatProperty1", 123.45);
  propertyList->SetBoolProperty("visibility",true);
  propertyList->SetStringProperty("nameXY","propertyName");
  baseDataImpl->SetPropertyList(propertyList);
  bool value = false;
  MITK_TEST_CONDITION(baseDataImpl->GetPropertyList() == propertyList, "Check if base property list is set correctly!");
  MITK_TEST_CONDITION(baseDataImpl->GetPropertyList()->GetBoolProperty("visibility", value) == true, "Check if base property is set correctly in the property list!");
  
  //test method UpdateOutputInformation()
   baseDataImpl->UpdateOutputInformation();
  MITK_TEST_CONDITION(baseDataImpl->GetUpdatedTimeSlicedGeometry() == geo2, "TimeSlicedGeometry update!");
  //Test method CopyInformation()
  mitk::BaseDataTestImplementation::Pointer newBaseData =  mitk::BaseDataTestImplementation::New();
  newBaseData->CopyInformation(baseDataImpl);
  MITK_TEST_CONDITION_REQUIRED(  newBaseData->GetTimeSlicedGeometry()->GetTimeSteps() == 5, "Check copying of of Basedata Data Object!");
  
  MITK_TEST_END()
}
コード例 #7
0
int mitkPlaneGeometryTest(int /*argc*/, char* /*argv*/[])
{
  int result;

  /*
  // the following can be used to reproduce a bug in ITK matrix inversion
  // which was found while investigating bug #1210.
  result = TestCase1210();
  if(result!=EXIT_SUCCESS)
    return result;
  */

  mitk::PlaneGeometry::Pointer planegeometry = mitk::PlaneGeometry::New();
 
  mitk::Point3D origin;
  mitk::Vector3D right, bottom, normal;
  mitk::ScalarType width, height;
  mitk::ScalarType widthInMM, heightInMM, thicknessInMM;

  width  = 100;    widthInMM  = width;
  height = 200;    heightInMM = height;
  thicknessInMM = 1.0;
  mitk::FillVector3D(origin, 4.5,              7.3, 11.2);
  mitk::FillVector3D(right,  widthInMM,          0, 0);
  mitk::FillVector3D(bottom,         0, heightInMM, 0);
  mitk::FillVector3D(normal,         0,          0, thicknessInMM);

  std::cout << "Testing InitializeStandardPlane(rightVector, downVector, spacing = NULL): "<<std::endl;
  planegeometry->InitializeStandardPlane(right.Get_vnl_vector(), bottom.Get_vnl_vector());

  std::cout << "Testing width, height and thickness (in units): ";
  if((mitk::Equal(planegeometry->GetExtent(0),width)==false) || 
     (mitk::Equal(planegeometry->GetExtent(1),height)==false) || 
     (mitk::Equal(planegeometry->GetExtent(2),1)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm): ";
  if((mitk::Equal(planegeometry->GetExtentInMM(0),widthInMM)==false) || 
     (mitk::Equal(planegeometry->GetExtentInMM(1),heightInMM)==false) || 
     (mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector(): ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;



  std::cout << "Testing InitializeStandardPlane(rightVector, downVector, spacing = {1.0, 1.0, 1.5}): "<<std::endl;
  mitk::Vector3D spacing;
  thicknessInMM = 1.5;
  normal.Normalize(); normal *= thicknessInMM;
  mitk::FillVector3D(spacing, 1.0, 1.0, thicknessInMM);
  planegeometry->InitializeStandardPlane(right.Get_vnl_vector(), bottom.Get_vnl_vector(), &spacing);

  std::cout << "Testing width, height and thickness (in units): ";
  if((mitk::Equal(planegeometry->GetExtent(0),width)==false) || 
     (mitk::Equal(planegeometry->GetExtent(1),height)==false) || 
     (mitk::Equal(planegeometry->GetExtent(2),1)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm): ";
  if((mitk::Equal(planegeometry->GetExtentInMM(0),widthInMM)==false) || 
     (mitk::Equal(planegeometry->GetExtentInMM(1),heightInMM)==false) || 
     (mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector(): ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;



  std::cout << "Testing SetExtentInMM(2, ...), querying by GetExtentInMM(2): ";
  thicknessInMM = 3.5;
  normal.Normalize(); normal *= thicknessInMM;
  planegeometry->SetExtentInMM(2, thicknessInMM);
  if(mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing SetExtentInMM(2, ...), querying by GetAxisVector(2) and comparing to normal: ";
  if(mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing SetOrigin: ";
  planegeometry->SetOrigin(origin);
  if(mitk::Equal(planegeometry->GetOrigin(), origin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() after SetOrigin: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
  if(result!=EXIT_SUCCESS)
    return result;



  std::cout << "Changing the IndexToWorldTransform to a rotated version by SetIndexToWorldTransform() (keep origin): "<<std::endl;
  mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New();
  mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;
  vnlmatrix = planegeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix();
  mitk::VnlVector axis(3);
  mitk::FillVector3D(axis, 1.0, 1.0, 1.0); axis.normalize();
  vnl_quaternion<mitk::ScalarType> rotation(axis, 0.223);
  vnlmatrix = rotation.rotation_matrix_transpose()*vnlmatrix;
  mitk::Matrix3D matrix;
  matrix = vnlmatrix;
  transform->SetMatrix(matrix);
  transform->SetOffset(planegeometry->GetIndexToWorldTransform()->GetOffset());
  
  right.Set_vnl_vector( rotation.rotation_matrix_transpose()*right.Get_vnl_vector() );
  bottom.Set_vnl_vector(rotation.rotation_matrix_transpose()*bottom.Get_vnl_vector());
  normal.Set_vnl_vector(rotation.rotation_matrix_transpose()*normal.Get_vnl_vector());
  planegeometry->SetIndexToWorldTransform(transform);

  //The origin changed,because m_Origin=m_IndexToWorldTransform->GetOffset()+GetAxisVector(2)*0.5
  //and the AxisVector changes due to the rotation. In other words: the rotation was done around 
  //the corner of the box, not around the planes origin. Now change it to a rotation around
  //the origin, simply by re-setting the origin to the original one:
  planegeometry->SetOrigin(origin);
  mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0);

  std::cout << "Testing whether SetIndexToWorldTransform kept origin: ";
  if(mitk::Equal(planegeometry->GetOrigin(), origin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }

  MITK_TEST_OUTPUT( << "Testing consistancy of index and world coordinates. ");
  mitk::Point2D point; point[0] = 4; point[1] = 3;
  mitk::Point2D dummy;
  planegeometry->WorldToIndex(point, dummy);
  planegeometry->IndexToWorld(dummy, dummy);
  MITK_TEST_CONDITION_REQUIRED(dummy == point, "");

  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of rotated version: ";
  if((mitk::Equal(planegeometry->GetExtentInMM(0),widthInMM)==false) || 
     (mitk::Equal(planegeometry->GetExtentInMM(1),heightInMM)==false) || 
     (mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of rotated version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(),planegeometry->GetExtentInMM(0))==false) || 
     (mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(),planegeometry->GetExtentInMM(1))==false) || 
     (mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(),planegeometry->GetExtentInMM(2))==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
  if(result!=EXIT_SUCCESS)
    return result;

  std::cout << "Testing SetSizeInUnits() of rotated version: "<<std::endl;
  width  *= 2;
  height *= 3;
  planegeometry->SetSizeInUnits(width, height);

  std::cout << "Testing width, height and thickness (in units): ";
  if((mitk::Equal(planegeometry->GetExtent(0),width)==false) || 
     (mitk::Equal(planegeometry->GetExtent(1),height)==false) || 
     (mitk::Equal(planegeometry->GetExtent(2),1)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of version with changed size in units: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), thicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of version with changed size in units: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(),planegeometry->GetExtentInMM(0))==false) || 
     (mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(),planegeometry->GetExtentInMM(1))==false) || 
     (mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(),planegeometry->GetExtentInMM(2))==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
  if(result!=EXIT_SUCCESS)
    return result;



  std::cout << "Testing Clone(): ";
  mitk::PlaneGeometry::Pointer clonedplanegeometry = dynamic_cast<mitk::PlaneGeometry*>(planegeometry->Clone().GetPointer());
  if((clonedplanegeometry.IsNull()) || (clonedplanegeometry->GetReferenceCount()!=1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing origin of cloned version: ";
  if(mitk::Equal(clonedplanegeometry->GetOrigin(), origin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  
  std::cout << "Testing width, height and thickness (in units) of cloned version: ";
  if((mitk::Equal(clonedplanegeometry->GetExtent(0),width)==false) || 
     (mitk::Equal(clonedplanegeometry->GetExtent(1),height)==false) || 
     (mitk::Equal(clonedplanegeometry->GetExtent(2),1)==false)
    )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of cloned version: ";
  if(!mitk::Equal(clonedplanegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(clonedplanegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(clonedplanegeometry->GetExtentInMM(2), thicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of cloned version: ";
  if((mitk::Equal(clonedplanegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(clonedplanegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(clonedplanegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(clonedplanegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
  if(result!=EXIT_SUCCESS)
    return result;
    
  
  // Clone, move, rotate and test for 'IsParallel' and 'IsOnPlane'
  std::cout << "Testing Clone(): ";
  mitk::PlaneGeometry::Pointer clonedplanegeometry2 = dynamic_cast<mitk::PlaneGeometry*>(planegeometry->Clone().GetPointer());
  if((clonedplanegeometry2.IsNull()) || (clonedplanegeometry2->GetReferenceCount()!=1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "Testing if cloned and original version are at the same place: ";
  if(mitk::Equal(clonedplanegeometry2->IsOnPlane(planegeometry), true) ==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  
  std::cout << "Testing if the origin is on the plane: ";
  if(mitk::Equal(clonedplanegeometry2->IsOnPlane(origin), true)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  
  mitk::VnlVector newaxis(3);
  mitk::FillVector3D(newaxis, 1.0, 1.0, 1.0); newaxis.normalize();
  vnl_quaternion<mitk::ScalarType> rotation2(newaxis, 0.0);
  
  mitk::Vector3D clonednormal = clonedplanegeometry2->GetNormal();
  mitk::Point3D clonedorigin = clonedplanegeometry2->GetOrigin();
  
  mitk::RotationOperation* planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), 180.0 );
  
  clonedplanegeometry2->ExecuteOperation( planerot ); 
  
  std::cout << "Testing whether the flipped plane is still the original plane: ";
  if( mitk::Equal( clonedplanegeometry2->IsOnPlane(planegeometry), true )==false )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  
  clonedorigin += clonednormal;
  clonedplanegeometry2->SetOrigin( clonedorigin );
 
  std::cout << "Testing if the translated (cloned, flipped) plane is parallel to its origin plane: ";
  if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), true )==false )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  

  delete planerot;
  
  planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), 0.5 );
  clonedplanegeometry2->ExecuteOperation( planerot ); 
  
  std::cout << "Testing if a non-paralell plane gets recognized as not paralell  [rotation +0.5 degree] : ";
  if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), false )==false )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  
  delete planerot;
  
  planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), -1.0 );
  clonedplanegeometry2->ExecuteOperation( planerot ); 
  
  std::cout << "Testing if a non-paralell plane gets recognized as not paralell  [rotation -0.5 degree] : ";
  if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), false )==false )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  delete planerot;

  planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), 360.5 );
  clonedplanegeometry2->ExecuteOperation( planerot ); 
  
  std::cout << "Testing if a non-paralell plane gets recognized as not paralell  [rotation 360 degree] : ";
  if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), true )==false )
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;


  std::cout << "Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Transversal, zPosition = 0, frontside=true): " <<std::endl;
  planegeometry->InitializeStandardPlane(clonedplanegeometry);

  std::cout << "Testing origin of transversally initialized version: ";
  if(mitk::Equal(planegeometry->GetOrigin(), origin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetCornerPoint(0) of transversally initialized version: ";
  if(mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in units) of transversally initialized version (should be same as in mm due to unit spacing, except for thickness, which is always 1): ";
  if(!mitk::Equal(planegeometry->GetExtent(0), width) || !mitk::Equal(planegeometry->GetExtent(1), height) || !mitk::Equal(planegeometry->GetExtent(2), 1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of transversally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), thicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of transversally initialized version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom);
  if(result!=EXIT_SUCCESS)
    return result;



  mitk::Vector3D newright, newbottom, newnormal;
  mitk::ScalarType newthicknessInMM;
  std::cout << "Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Frontal, zPosition = 0, frontside=true): " <<std::endl;
  planegeometry->InitializeStandardPlane(clonedplanegeometry, mitk::PlaneGeometry::Frontal);
  newright = right; 
  newbottom = normal; newbottom.Normalize();  newbottom *= thicknessInMM;
  newthicknessInMM = heightInMM/height*1.0/*extent in normal direction is 1*/;
  newnormal = -bottom; newnormal.Normalize(); newnormal *= newthicknessInMM;

  std::cout << "Testing GetCornerPoint(0) of frontally initialized version: ";
  if(mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  //ok, corner was fine, so we can dare to believe the origin is ok.
  origin = planegeometry->GetOrigin();

  std::cout << "Testing width, height and thickness (in units) of frontally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtent(0), width) || !mitk::Equal(planegeometry->GetExtent(1), 1) || !mitk::Equal(planegeometry->GetExtent(2), 1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of frontally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), newthicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of frontally initialized version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, width, 1, widthInMM, thicknessInMM, origin, newright, newbottom);
  if(result!=EXIT_SUCCESS)
    return result;



  std::cout << "Changing plane to in-plane unit spacing using SetSizeInUnits: " <<std::endl;
  planegeometry->SetSizeInUnits(planegeometry->GetExtentInMM(0), planegeometry->GetExtentInMM(1));

  std::cout << "Testing origin of unit spaced, frontally initialized version: ";
  if(mitk::Equal(planegeometry->GetOrigin(), origin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtent(0), widthInMM) || !mitk::Equal(planegeometry->GetExtent(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtent(2), 1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), newthicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of unit spaced, frontally initialized version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom);
  if(result!=EXIT_SUCCESS)
    return result;



  std::cout << "Changing plane to unit spacing also in normal direction using SetExtentInMM(2, 1.0): " <<std::endl;
  planegeometry->SetExtentInMM(2, 1.0);
  newnormal.Normalize();

  std::cout << "Testing origin of unit spaced, frontally initialized version: ";
  if(mitk::Equal(planegeometry->GetOrigin(), origin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtent(0), widthInMM) || !mitk::Equal(planegeometry->GetExtent(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtent(2), 1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), 1.0))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of unit spaced, frontally initialized version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom);
  if(result!=EXIT_SUCCESS)
    return result;



  std::cout << "Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Sagittal, zPosition = 0, frontside=true): " <<std::endl;
  planegeometry->InitializeStandardPlane(clonedplanegeometry, mitk::PlaneGeometry::Sagittal);
  newright = bottom;
  newthicknessInMM = widthInMM/width*1.0/*extent in normal direction is 1*/;
  newnormal = right; newnormal.Normalize(); newnormal *= newthicknessInMM;

  std::cout << "Testing GetCornerPoint(0) of sagitally initialized version: ";
  if(mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;
  //ok, corner was fine, so we can dare to believe the origin is ok.
  origin = planegeometry->GetOrigin();

  std::cout << "Testing width, height and thickness (in units) of sagitally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtent(0), height) || !mitk::Equal(planegeometry->GetExtent(1), 1) || !mitk::Equal(planegeometry->GetExtent(2), 1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of sagitally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), newthicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of sagitally initialized version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, height, 1, heightInMM, thicknessInMM, origin, newright, newbottom);
  if(result!=EXIT_SUCCESS)
    return result;



  //set origin back to the one of the transversal slice:
  origin = clonedplanegeometry->GetOrigin();
  std::cout << "Testing backside initialization: InitializeStandardPlane(clonedplanegeometry, planeorientation = Transversal, zPosition = 0, frontside=false, rotated=true): " <<std::endl;
  planegeometry->InitializeStandardPlane(clonedplanegeometry, mitk::PlaneGeometry::Transversal, 0, false, true);
  mitk::Point3D backsideorigin;
  backsideorigin=origin+clonedplanegeometry->GetAxisVector(1);//+clonedplanegeometry->GetAxisVector(2);

  std::cout << "Testing origin of backsidedly, transversally initialized version: ";
  if(mitk::Equal(planegeometry->GetOrigin(), backsideorigin)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetCornerPoint(0) of sagitally initialized version: ";
  mitk::Point3D backsidecornerpoint0;
  backsidecornerpoint0 = cornerpoint0+clonedplanegeometry->GetAxisVector(1);//+clonedplanegeometry->GetAxisVector(2);
  if(mitk::Equal(planegeometry->GetCornerPoint(0), backsidecornerpoint0)==false)
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in units) of backsidedly, transversally initialized version (should be same as in mm due to unit spacing, except for thickness, which is always 1): ";
  if(!mitk::Equal(planegeometry->GetExtent(0), width) || !mitk::Equal(planegeometry->GetExtent(1), height) || !mitk::Equal(planegeometry->GetExtent(2), 1))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing width, height and thickness (in mm) of backsidedly, transversally initialized version: ";
  if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), thicknessInMM))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  std::cout << "Testing GetAxisVector() of backsidedly, transversally initialized version: ";
  if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), -bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), -normal)==false))
  {
    std::cout<<"[FAILED]"<<std::endl;
    return EXIT_FAILURE;
  }
  std::cout<<"[PASSED]"<<std::endl;

  result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, backsideorigin, right, -bottom);
  if(result!=EXIT_SUCCESS)
    return result;


  // test method mitk::PlaneGeometry::ProjectPointOntoPlane()
  // (see also bug #3409)
  result = TestProjectPointOntoPlane();
  if(result!=EXIT_SUCCESS)
    return result;


  // testing mitk::PlaneGeometry::IntersectionPoint()
  std::cout << std::endl;
  std::cout << "Testing IntersectionPoint using given plane and given line:  ";
    result = TestIntersectionPoint();
    if (result != EXIT_SUCCESS) {
        std::cout << "[FAILED]" << std::endl;
        return result;
    }
  
  std::cout<<"[PASSED]"<<std::endl<<std::endl;
    
  
  
  std::cout<<"[TEST DONE]"<<std::endl;
  return EXIT_SUCCESS;
}
コード例 #8
0
int mitkImageGeneratorTest(int /*argc*/, char* /*argv*/[])
{
    MITK_TEST_BEGIN("ToFImageWriter");

    //create some images with arbitrary parameters (corner cases)
    mitk::Image::Pointer image2Da = mitk::ImageGenerator::GenerateRandomImage<float>(120, 205, 0, 0, 577, 23);
    mitk::Image::Pointer image2Db = mitk::ImageGenerator::GenerateRandomImage<unsigned char>(1, 1, 0, 0);
    mitk::Image::Pointer image3Da = mitk::ImageGenerator::GenerateRandomImage<int>(512, 205, 1, 0);
    mitk::Image::Pointer image3Db = mitk::ImageGenerator::GenerateRandomImage<double>(512, 532, 112, 0);
    mitk::Image::Pointer image4Da = mitk::ImageGenerator::GenerateRandomImage<float>(120, 205, 78, 1);
    mitk::Image::Pointer image4Db = mitk::ImageGenerator::GenerateRandomImage<unsigned char>(550, 33, 78, 150);

    MITK_TEST_CONDITION_REQUIRED(image2Da->GetDimension() == 2, "Testing if the dimension is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image2Db->GetDimension() == 2, "Testing if the dimension is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Da->GetDimension() == 2, "Testing if the dimension is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Db->GetDimension() == 3, "Testing if the dimension is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Da->GetDimension() == 3, "Testing if the dimension is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Db->GetDimension() == 4, "Testing if the dimension is set correctly.");

    MITK_TEST_CONDITION_REQUIRED(image2Da->GetDimension(0) == 120, "Testing if the dimensions are set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image2Db->GetDimension(1) == 1, "Testing if the dimensions are set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Da->GetDimension(2) == 1, "Testing if the dimensions are set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Db->GetDimension(2) == 112, "Testing if the dimensions are set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Da->GetDimension(3) == 1, "Testing if the dimensions are set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Db->GetDimension(3) == 150, "Testing if the dimensions are set correctly.");

    itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR;

    MITK_TEST_CONDITION_REQUIRED(image2Da->GetPixelType().GetTypeId() == typeid(float), "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image2Da->GetPixelType().GetPixelTypeId() == scalarType, "Testing if the pixel type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image2Db->GetPixelType().GetTypeId() == typeid(unsigned char), "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image2Db->GetPixelType().GetPixelTypeId() == scalarType, "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Da->GetPixelType().GetTypeId() == typeid(int), "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Da->GetPixelType().GetPixelTypeId() == scalarType, "Testing if the pixel type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Db->GetPixelType().GetTypeId() == typeid(double), "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image3Db->GetPixelType().GetPixelTypeId() == scalarType, "Testing if the pixel type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Da->GetPixelType().GetTypeId() == typeid(float), "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Da->GetPixelType().GetPixelTypeId() == scalarType, "Testing if the pixel type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Db->GetPixelType().GetTypeId() == typeid(unsigned char), "Testing if the data type is set correctly.");
    MITK_TEST_CONDITION_REQUIRED(image4Db->GetPixelType().GetPixelTypeId() == scalarType, "Testing if the pixel type is set correctly.");

    MITK_TEST_CONDITION_REQUIRED(image2Da->GetStatistics()->GetScalarValueMax() <= 577, "Testing if max value holds");
    MITK_TEST_CONDITION_REQUIRED(image2Da->GetStatistics()->GetScalarValueMin() >= 23, "Testing if min value holds");

    MITK_TEST_CONDITION_REQUIRED(image3Da->GetStatistics()->GetScalarValueMax() <= 1000, "Testing if max value holds");
    MITK_TEST_CONDITION_REQUIRED(image3Da->GetStatistics()->GetScalarValueMin() >= 0, "Testing if min value holds");

    MITK_TEST_END();
}
コード例 #9
0
int mitkVirtualTrackingDeviceTest(int /* argc */, char* /*argv*/[])
{
  // always start with this!
  MITK_TEST_BEGIN("VirtualTrackingDevice");

  // let's create an object of our class  
  mitk::VirtualTrackingDevice::Pointer tracker = mitk::VirtualTrackingDevice::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(tracker.IsNotNull(),"Testing instantiation\n");


  MITK_TEST_CONDITION_REQUIRED(tracker->GetState() == mitk::TrackingDevice::Setup ,"Checking tracking device state == setup.\n");

  //CloseConnection
  MITK_TEST_CONDITION( (tracker->CloseConnection()), "Testing behavior of method CloseConnection().");

  //StartTracking
  MITK_TEST_CONDITION( tracker->StartTracking() == false, "Testing behavior of method StartTracking().");

  tracker->SetRefreshRate(43);
  MITK_TEST_CONDITION( tracker->GetRefreshRate() == 43, "Testing Set-/GetRefreshRate()");

  MITK_TEST_CONDITION( tracker->GetToolCount() == 0, "Testing GetToolCount() before AddTool()");

  MITK_TEST_CONDITION( tracker->AddTool("Tool0"), "Testing AddTool() for tool 0.");
  MITK_TEST_CONDITION( tracker->GetToolCount() == 1, "Testing GetToolCount() after AddTool()");

  mitk::TrackingTool::Pointer tool = tracker->GetTool(0);
  MITK_TEST_CONDITION_REQUIRED( tool.IsNotNull(), "Testing GetTool() for tool 0.");
  
  MITK_TEST_CONDITION( tracker->GetToolByName("Tool0") == tool.GetPointer(), "Testing GetTool() equals GetToolByName() for tool 0.");

  mitk::ScalarType bounds[6] = {0.0, 10.0, 1.0, 20.0, 3.0, 30.0};
  tracker->SetBounds(bounds);
  MITK_TEST_CONDITION( tracker->GetBounds()[0] == bounds[0]
                    && tracker->GetBounds()[1] == bounds[1]
                    && tracker->GetBounds()[2] == bounds[2]
                    && tracker->GetBounds()[3] == bounds[3]
                    && tracker->GetBounds()[4] == bounds[4]
                    && tracker->GetBounds()[5] == bounds[5]
                    , "Testing Set-/GetBounds()");
  MITK_TEST_CONDITION( tracker->AddTool("Tool1"), "Testing AddTool() for tool 1.");
  MITK_TEST_CONDITION( tracker->GetToolCount() == 2, "Testing GetToolCount() after AddTool()");

  tracker->SetToolSpeed(0, 0.1); // no exception expected
  tracker->SetToolSpeed(1, 0.1); // no exception expected
  MITK_TEST_FOR_EXCEPTION(std::invalid_argument, tracker->SetToolSpeed(2, 0.1));  // exception expected

  mitk::ScalarType lengthBefore = tracker->GetSplineChordLength(0); // no exception expected
  MITK_TEST_FOR_EXCEPTION(std::invalid_argument, tracker->GetSplineChordLength(2));  // exception expected
  

  MITK_TEST_CONDITION( tracker->OpenConnection() == true, "Testing OpenConnection().");
  MITK_TEST_CONDITION( tracker->GetSplineChordLength(0)  == lengthBefore, "Testing GetSplineChordLength() after initalization");

  //StartTracking
  mitk::Point3D posBefore0;
  tool->GetPosition(posBefore0);
  mitk::Point3D posBefore1;
  tracker->GetToolByName("Tool1")->GetPosition(posBefore1);

  mitk::Point3D posAfter0;
  tool->GetPosition(posAfter0);
  MITK_TEST_CONDITION( mitk::Equal(posBefore0, posAfter0) == true, "Testing if position value is constant before StartTracking()");


  MITK_TEST_CONDITION( tracker->StartTracking() == true, "Testing behavior of method StartTracking().");
  itksys::SystemTools::Delay(500); // wait for tracking thread to start generating positions
  
  tool->GetPosition(posAfter0);
  MITK_TEST_CONDITION( mitk::Equal(posBefore0, posAfter0) == false, "Testing if tracking is producing new position values in tool 0.");
  
  mitk::Point3D posAfter1;
  tracker->GetToolByName("Tool1")->GetPosition(posAfter1);
  MITK_TEST_CONDITION( mitk::Equal(posBefore1, posAfter1) == false, "Testing if tracking is producing new position values in tool 1.");

  // add tool while tracking is in progress
  tracker->AddTool("while Running");

  itksys::SystemTools::Delay(100); // wait for tracking thread to start generating positions
  tracker->GetToolByName("while Running")->GetPosition(posBefore0);
  unsigned long tmpMTime = tracker->GetToolByName("while Running")->GetMTime();
  itksys::SystemTools::Delay(100); // wait for tracking thread to start generating positions
  tracker->GetToolByName("while Running")->GetPosition(posAfter0);
  MITK_INFO << "If this test fails, please reopen bug 8033 and commit this output: ";
  MITK_INFO << std::setprecision(16) << "Value of posBefore0 " << posBefore0;
  MITK_INFO << std::setprecision(16) << "Value of posAfter0 " << posAfter0;
  MITK_INFO << std::setprecision(16) << "tmpTime " << tmpMTime;
  MITK_INFO << std::setprecision(16) << "current time " << tracker->GetToolByName("while Running")->GetMTime();
  if(tracker->GetToolByName("while Running")->GetMTime() == tmpMTime) //tool not modified yet
  {
    //hence the tool was not modified, the position has to be equal
    MITK_TEST_CONDITION( mitk::Equal(posBefore0, posAfter0) == true, "Testing if the position values for the 'while running' tool remain the same.");
  }
  else //tool was modified => position should have changed
  {
    MITK_TEST_CONDITION( mitk::Equal(posBefore0, posAfter0) == false, "Testing if tracking is producing new position values for 'while running' tool.");
  }

  // always end with this!
  MITK_TEST_END();
}
コード例 #10
0
ファイル: mitkExceptionTest.cpp プロジェクト: 0r/MITK
static void TestRethrowInformation()
    //this method is ONLY to test methods of mitk::Exception and no code example
    //normally exceptions should only be instantiated and thrown by using the exception macros!
    {
    //first: testing rethrow information methods, when no information is stored

    //case 1.1: method GetNumberOfRethrows()
    mitk::Exception e = mitk::Exception("test.cpp",155,"","");
    MITK_TEST_CONDITION_REQUIRED(e.GetNumberOfRethrows()==0,"Testing GetNumberOfRethrows() with empty rethrow information");

    //case 1.2: GetRethrowData() with negative number
    {
    std::string file = "invalid";
    int line = -1;
    std::string message = "invalid";
    e.GetRethrowData(-1,file,line,message);
    MITK_TEST_CONDITION_REQUIRED(((file == "")&&(line==0)&&(message == "")),"Testing GetRethrowData() with invalid rethrow number (negative).");
    }

    //case 1.3: GetRethrowData() with number 0
    {
    std::string file = "invalid";
    int line= -1;
    std::string message = "invalid";
    e.GetRethrowData(0,file,line,message);
    MITK_TEST_CONDITION_REQUIRED(((file == "")&&(line==0)&&(message == "")),"Testing GetRethrowData() with non-existing rethrow number (0).");
    }

    //case 1.4: GetRethrowData() with number 1
    {
    std::string file = "invalid";
    int line= -1;
    std::string message = "invalid";
    e.GetRethrowData(1,file,line,message);
    MITK_TEST_CONDITION_REQUIRED(((file == "")&&(line==0)&&(message == "")),"Testing GetRethrowData() with non-existing rethrow number (1).");
    }


    //second: add rethrow data
    e.AddRethrowData("test2.cpp",10,"Rethrow one");
    MITK_TEST_CONDITION_REQUIRED(e.GetNumberOfRethrows()==1,"Testing adding of rethrow data.");
    e.AddRethrowData("test3.cpp",15,"Rethrow two");
    MITK_TEST_CONDITION_REQUIRED(e.GetNumberOfRethrows()==2,"Testing adding of more rethrow data.");

    //third: test if this rethrow data was stored properly
    {
    std::string file = "invalid";
    int line= -1;
    std::string message = "invalid";
    e.GetRethrowData(0,file,line,message);
    MITK_TEST_CONDITION_REQUIRED(((file == "test2.cpp")&&(line==10)&&(message == "Rethrow one")),"Testing stored information of first rethrow.");
    }

    {
    std::string file = "invalid";
    int line= -1;
    std::string message = "invalid";
    e.GetRethrowData(1,file,line,message);
    MITK_TEST_CONDITION_REQUIRED(((file == "test3.cpp")&&(line==15)&&(message == "Rethrow two")),"Testing stored information of second rethrow.");
    }


    }
コード例 #11
0
/**Documentation
 *  test for the class "ToFImageWriter".
 */
int mitkToFNrrdImageWriterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFNrrdImageWriter");

  mitk::ToFNrrdImageWriter::Pointer tofNrrdWriter = mitk::ToFNrrdImageWriter::New();
  // testing correct initialization
  MITK_TEST_CONDITION_REQUIRED(tofNrrdWriter.GetPointer(), "Testing initialization of test object!");
  MITK_TEST_CONDITION_REQUIRED(tofNrrdWriter->GetExtension() == ".nrrd", "testing initialization of extension member variable!");

  //GENERATE TEST DATA
  ////run the test with some unusual parameters
  unsigned int dimX = 255;
  unsigned int dimY = 178;
  unsigned int pixelNumber = dimX*dimY;
  unsigned int numOfFrames = 23; //or numberOfSlices
  ////create 3 images filled with random values
  mitk::Image::Pointer distanceImage = mitk::ImageGenerator::GenerateRandomImage<float>(dimX, dimY, numOfFrames,1.0, 1.0f, 1.0f);
  mitk::Image::Pointer amplitudeImage = mitk::ImageGenerator::GenerateRandomImage<float>(dimX, dimY, numOfFrames,1.0, 1.0f, 2000.0f);
  mitk::Image::Pointer intensityImage = mitk::ImageGenerator::GenerateRandomImage<float>(dimX, dimY, numOfFrames,1.0, 1.0f, 100000.0f);

  //SET NEEDED PARAMETER
  //file names on the disc
  std::string distanceImageFileName("distImg.nrrd");
  std::string amplitudeImageFileName("amplImg.nrrd");
  std::string intensityImageFileName("intImg.nrrd");

  // set file name methods
  tofNrrdWriter->SetDistanceImageFileName(distanceImageFileName);
  tofNrrdWriter->SetAmplitudeImageFileName(amplitudeImageFileName);
  tofNrrdWriter->SetIntensityImageFileName(intensityImageFileName);
  tofNrrdWriter->SetToFCaptureWidth(dimX);
  tofNrrdWriter->SetToFCaptureHeight(dimY);
  tofNrrdWriter->SetToFImageType(mitk::ToFNrrdImageWriter::ToFImageType3D);
  tofNrrdWriter->SetRGBImageSelected(false);

  //buffer for each slice
  float* distanceArray;
  float* amplitudeArray;
  float* intensityArray;

  float* distanceArrayRead;
  float* amplitudeArrayRead;
  float* intensityArrayRead;

  tofNrrdWriter->Open(); //open file/stream

  for(unsigned int i = 0; i < numOfFrames ; i++)
  {
    distanceArray = (float*)distanceImage->GetSliceData(i, 0, 0)->GetData();
    amplitudeArray = (float*)amplitudeImage->GetSliceData(i, 0, 0)->GetData();
    intensityArray = (float*)intensityImage->GetSliceData(i, 0, 0)->GetData();

    //write (or add) the three slices to the file
    tofNrrdWriter->Add(distanceArray, amplitudeArray, intensityArray);
  }

  tofNrrdWriter->Close(); //close file


  //read in the three images from disc
  mitk::ItkImageFileReader::Pointer fileReader = mitk::ItkImageFileReader::New();
  fileReader->SetFileName(distanceImageFileName);
  fileReader->Update();
  mitk::Image::Pointer distanceImageRead = fileReader->GetOutput();

  fileReader = mitk::ItkImageFileReader::New();
  fileReader->SetFileName(amplitudeImageFileName);
  fileReader->Update();
  mitk::Image::Pointer amplitudeImageRead = fileReader->GetOutput();

  fileReader = mitk::ItkImageFileReader::New();
  fileReader->SetFileName(intensityImageFileName);
  fileReader->Update();
  mitk::Image::Pointer intensityImageRead = fileReader->GetOutput();

  bool readingCorrect = true;
  //  for all frames...
  for(unsigned int j=0; j < numOfFrames; j++)
  {
    //get one slice of each image and compare it
    //original data
    distanceArray = (float*)distanceImage->GetSliceData(j, 0, 0)->GetData();
    amplitudeArray = (float*)amplitudeImage->GetSliceData(j, 0, 0)->GetData();
    intensityArray = (float*)intensityImage->GetSliceData(j, 0, 0)->GetData();

    //data read from disc
    distanceArrayRead = (float*)distanceImageRead->GetSliceData(j, 0, 0)->GetData();
    amplitudeArrayRead = (float*)amplitudeImageRead->GetSliceData(j, 0, 0)->GetData();
    intensityArrayRead = (float*)intensityImageRead->GetSliceData(j, 0, 0)->GetData();

    //for all pixels
    for(unsigned int i=0; i<pixelNumber; i++)
    {
      //compare if input == output
      if(!mitk::Equal(distanceArrayRead[i], distanceArray[i]) ||
         !mitk::Equal(amplitudeArrayRead[i], amplitudeArray[i]) ||
         !mitk::Equal(intensityArrayRead[i], intensityArray[i]))
      {
        readingCorrect = false;
      }
    }
  }

  remove( distanceImageFileName.c_str() );
  remove( amplitudeImageFileName.c_str() );
  remove( intensityImageFileName.c_str() );
  MITK_TEST_CONDITION_REQUIRED(readingCorrect, "Testing if the output values are correct.");

  //delete created image files

  MITK_TEST_END();
}
コード例 #12
0
ファイル: mitkExceptionTest.cpp プロジェクト: 0r/MITK
  static void TestMitkThrowMacro()
    {

    bool exceptionThrown = false;
    ExceptionTestClass::Pointer myExceptionTestObject = ExceptionTestClass::New();

    //case 1: test throwing

    try
     {
     myExceptionTestObject->throwExceptionWithThrowMacro();
     }
    catch(mitk::Exception)
     {
     exceptionThrown = true;
     }
    MITK_TEST_CONDITION_REQUIRED(exceptionThrown,"Testing mitkThrow()");

    //case 2: test message text

    exceptionThrown = false;
    std::string messageText = "";

    try
     {
     myExceptionTestObject->throwExceptionWithThrowMacro("test123");
     }
    catch(mitk::Exception e)
     {
     exceptionThrown = true;
     messageText = e.GetDescription();

     }
    MITK_TEST_CONDITION_REQUIRED((exceptionThrown && (messageText=="test123")),"Testing message test of mitkThrow()");

    //case 3: specialized exception / command mitkThrow(mitk::Exception)

    exceptionThrown = false;
    messageText = "";

    try
     {
     myExceptionTestObject->throwSpecializedExceptionWithThrowMacro("test123");
     }
    catch(mitk::Exception e)
     {
     exceptionThrown = true;
     messageText = e.GetDescription();
     }
    MITK_TEST_CONDITION_REQUIRED(exceptionThrown && messageText=="test123","Testing special exception with mitkThrow(mitk::Exception)");

    //case 4: specialized exception / command mitkThrow(mitk::SpecializedException)

    exceptionThrown = false;
    messageText = "";

    try
     {
     myExceptionTestObject->throwSpecializedExceptionWithThrowMacro2("test123");
     }
    catch(SpecializedTestException e)
     {
     exceptionThrown = true;
     messageText = e.GetDescription();
     }
    MITK_TEST_CONDITION_REQUIRED(exceptionThrown && messageText=="test123","Testing special exception with mitkThrow(mitk::SpecializedException)");

    }
コード例 #13
0
/**Documentation
 *  test for the class "ToFImageCsvWriter".
 */
int mitkToFImageCsvWriterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFImageCsvWriter");
  mitk::ToFImageCsvWriter::Pointer csvWriter = mitk::ToFImageCsvWriter::New();
  MITK_TEST_CONDITION_REQUIRED(csvWriter.GetPointer(), "Testing initialization of test object!");
  MITK_TEST_CONDITION_REQUIRED(csvWriter->GetExtension() == ".csv", "Testing correct initialization of member variable extension!");

  srand(time(0));

  unsigned int dimX = 100 + rand()%100;
  unsigned int dimY = 100 + rand()%100;
  unsigned int pixelNumber = dimX*dimY;
  unsigned int numOfFrames = 1 + rand()%100;

  MITK_INFO<<dimX;
  MITK_INFO<<dimY;
  MITK_INFO<<numOfFrames;

  mitk::Image::Pointer distanceImage = mitk::ImageGenerator::GenerateRandomImage<float>(dimX, dimY, numOfFrames);
  mitk::Image::Pointer amplitudeImage = mitk::ImageGenerator::GenerateRandomImage<float>(dimX, dimY, numOfFrames);
  mitk::Image::Pointer intensityImage = mitk::ImageGenerator::GenerateRandomImage<float>(dimX, dimY, numOfFrames);


  std::string distanceImageFileName("distImg.csv");
  std::string amplitudeImageFileName("amplImg.csv");
  std::string intensityImageFileName("intImg.csv");

  csvWriter->SetDistanceImageFileName(distanceImageFileName);
  csvWriter->SetAmplitudeImageFileName(amplitudeImageFileName);
  csvWriter->SetIntensityImageFileName(intensityImageFileName);

  csvWriter->SetToFCaptureWidth(dimX);
  csvWriter->SetToFCaptureHeight(dimY);
  csvWriter->SetToFImageType(mitk::ToFImageWriter::ToFImageType3D);

  mitk::ImageSliceSelector::Pointer distanceSelector = mitk::ImageSliceSelector::New();
  mitk::ImageSliceSelector::Pointer amplitudeSelector = mitk::ImageSliceSelector::New();
  mitk::ImageSliceSelector::Pointer intensitySelector = mitk::ImageSliceSelector::New();

  mitk::Image::Pointer tmpDistance;
  mitk::Image::Pointer tmpAmplitude;
  mitk::Image::Pointer tmpIntensity;

  distanceSelector->SetInput(distanceImage);
  amplitudeSelector->SetInput(amplitudeImage);
  intensitySelector->SetInput(intensityImage);

  //buffer
  float* distanceArray;
  float* amplitudeArray;
  float* intensityArray;

  csvWriter->Open(); //open file/stream
  for(unsigned int i = 0; i<numOfFrames; i++)
  { //write values to file/stream
    distanceSelector->SetSliceNr(i);
    distanceSelector->Update();
    mitk::ImageReadAccessor tmpDistAcc(distanceSelector->GetOutput());
    distanceArray = (float*) tmpDistAcc.GetData();

    amplitudeSelector->SetSliceNr(i);
    amplitudeSelector->Update();
    mitk::ImageReadAccessor tmpAmplAcc(amplitudeSelector->GetOutput());
    amplitudeArray = (float*)tmpAmplAcc.GetData();

    intensitySelector->SetSliceNr(i);
    intensitySelector->Update();
    mitk::ImageReadAccessor tmpIntenAcc(intensitySelector->GetOutput());
    intensityArray = (float*)tmpIntenAcc.GetData();

    csvWriter->Add(distanceArray, amplitudeArray, intensityArray);
  }
  csvWriter->Close(); //close file

  FILE* distanceInfile = NULL;
  FILE* amplitudeInfile = NULL;
  FILE* intensityInfile = NULL;

  //open file again
  OpenCsvFile(&(distanceInfile), distanceImageFileName);
  OpenCsvFile(&(amplitudeInfile), amplitudeImageFileName);
  OpenCsvFile(&(intensityInfile), intensityImageFileName);

  float distVal = 0.0, amplVal = 0.0, intenVal = 0.0;
  int dErr = 0, aErr = 0, iErr = 0;
  bool readingCorrect = true;

  //for all frames...
  for(unsigned int j=0; j<numOfFrames; j++)
  {
    distanceSelector->SetSliceNr(j);
    distanceSelector->Update();
    mitk::ImageReadAccessor tmpDistAcc(distanceSelector->GetOutput());
    distanceArray = (float*) tmpDistAcc.GetData();

    amplitudeSelector->SetSliceNr(j);
    amplitudeSelector->Update();
    mitk::ImageReadAccessor tmpAmplAcc(amplitudeSelector->GetOutput());
    amplitudeArray = (float*)tmpAmplAcc.GetData();

    intensitySelector->SetSliceNr(j);
    intensitySelector->Update();
    mitk::ImageReadAccessor tmpIntenAcc(intensitySelector->GetOutput());
    intensityArray = (float*)tmpIntenAcc.GetData();

    //for all pixels
    for(unsigned int i=0; i<pixelNumber; i++)
    {
      if (i==0 && j==0)
      {      //no comma at the beginning of the document
        dErr = fscanf (distanceInfile, "%f", &distVal);
        aErr = fscanf (amplitudeInfile, "%f", &amplVal);
        iErr = fscanf (intensityInfile, "%f", &intenVal);
      }
      else
      {      //comma seperated values now
        dErr = fscanf (distanceInfile, ",%f", &distVal);
        aErr = fscanf (amplitudeInfile, ",%f", &amplVal);
        iErr = fscanf (intensityInfile, ",%f", &intenVal);
      }

      //check if reading error or EOF occurs
      if (dErr==0 || dErr==EOF)
      {
        MITK_TEST_CONDITION_REQUIRED((dErr!=0 && dErr!=EOF), "Testing open and read csv distance file");
      }
      if (aErr==0 || aErr==EOF)
      {
        MITK_TEST_CONDITION_REQUIRED((aErr!=0 && aErr!=EOF), "Testing open and read csv amplitude file");
      }
      if (iErr==0 || iErr==EOF)
      {
        MITK_TEST_CONDITION_REQUIRED((iErr!=0 && iErr!=EOF), "Testing open and read csv intensity file");
      }

      //compare if input == output
      if(!mitk::Equal(distVal,distanceArray[i],0.00001) || !mitk::Equal(amplVal, amplitudeArray[i],0.00001) || !mitk::Equal(intenVal, intensityArray[i],0.00001))
      {
        readingCorrect = false;
      }
    }
  }
  MITK_TEST_CONDITION_REQUIRED(readingCorrect, "Testing if the output values are correct.");

  //check if end of file is reached
  dErr = fscanf (distanceInfile, ",%f", &distVal);
  aErr = fscanf (amplitudeInfile, ",%f", &amplVal);
  iErr = fscanf (intensityInfile, ",%f", &intenVal);
  MITK_TEST_CONDITION_REQUIRED((dErr==EOF), "Testing EOF distance file");
  MITK_TEST_CONDITION_REQUIRED((aErr==EOF), "Testing EOF amplitude file");
  MITK_TEST_CONDITION_REQUIRED((iErr==EOF), "Testing EOF intensity file");

  //close testing files
  CloseCsvFile(distanceInfile);
  CloseCsvFile(amplitudeInfile);
  CloseCsvFile(intensityInfile);

  remove( distanceImageFileName.c_str() );
  remove( amplitudeImageFileName.c_str() );
  remove( intensityImageFileName.c_str() );

  MITK_TEST_END();
}
コード例 #14
0
/**Documentation
 *  test for the class "ToFCameraPMDCamCubeController".
 */
int mitkToFCameraPMDCamCubeControllerTest(int /* argc */, char* /*argv*/[])
{

  MITK_TEST_BEGIN("ToFCameraPMDCamCubeController");
  mitk::ToFCameraPMDCamCubeController::Pointer camCubeController = mitk::ToFCameraPMDCamCubeController::New();
  try
  {

  MITK_TEST_CONDITION_REQUIRED(camCubeController.IsNotNull(),"Testing initialzation!");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->GetCaptureHeight()== 200 ,"Testing initialization of CaptureHeight");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->GetCaptureWidth()== 200 ,"Testing initialization of CaptureWidth");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->OpenCameraConnection(),"Testing opening of camera connection!");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->UpdateCamera(),"Testing UpdateCamera()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetDistanceOffset(0.5f),"Testing SetDistanceOffset()");
  MITK_TEST_OUTPUT(<<"Call GetDistanceOffset()");
  MITK_INFO<<camCubeController->GetDistanceOffset();
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetRegionOfInterest(3,5,200,201),"Testing SetRegionOfInterest()");
  MITK_TEST_OUTPUT(<<"Call GetRegionOfInterest()");
  MITK_INFO<<camCubeController->GetRegionOfInterest();
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetExposureMode(0),"Testing SetExposureMode()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetFieldOfView(35.7f),"Testing SetFieldOfView()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetFPNCalibration(true),"Testing SetFPNCalibration()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetFPPNCalibration(true),"Testing SetFPPNCalibration()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetLinearityCalibration(true),"Testing SetLinearityCalibration()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->SetLensCalibration(true),"Testing SetLensCalibration()");
  MITK_TEST_CONDITION_REQUIRED(camCubeController->CloseCameraConnection(),"Testing closing of camera connection!");
  }
  catch(std::exception &e)
  {
      MITK_INFO << e.what();
  }

  MITK_TEST_END();
}
コード例 #15
0
/**Documentation
 *  test for the class "NavigationDataVisualizationByBaseDataTransformFilter".
 */
int mitkCameraVisualizationTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("CameraVisualization")

  // let's create an object of our class
  mitk::CameraVisualization::Pointer myFilter = mitk::CameraVisualization::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 */
  srand(time(NULL));
  // generate a random position for the navigation data
  mitk::NavigationData::PositionType position;
  position[0] = rand()%1000;
  position[1] = rand()%1000;
  position[2] = rand()%1000;

  // generate a random orientation for the navigation data
  mitk::NavigationData::OrientationType 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;

  // generate a random error for the navigation data
  mitk::ScalarType error = rand()%10;

  // data valid flag of navigation data
  int val = rand()%2;
  bool valid(0); // this was uninitialized. how was this test ever meant to work??
  if (val==0)
  {
    valid=false;
  }
  else if (val==1)
  {
    valid=true;
  }

  // set parameters of navigation data
  mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
  nd1->SetPosition(position);
  nd1->SetOrientation(orientation);
  nd1->SetPositionAccuracy(error);
  nd1->SetDataValid(valid);

  // create renderer
  vtkRenderWindow* renderWindow = vtkRenderWindow::New();
  mitk::VtkPropRenderer::Pointer renderer = mitk::VtkPropRenderer::New( "TestRenderer",renderWindow, mitk::RenderingManager::GetInstance() );

  myFilter->SetInput(nd1);
  MITK_TEST_CONDITION(myFilter->GetInput() == nd1, "Testing Set-/GetInput() input 1");

  // test for exception if renderer not set
  MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
    myFilter->Update();
  MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)

  // set renderer
  myFilter->SetRenderer(renderer);

  //Update filter
  myFilter->Update();

  //Delete renderWindow correctly
  renderWindow->Delete();

  // always end with this!
  MITK_TEST_END();

}
コード例 #16
0
/**Documentation
 *  test for the class "ToFImageWriter".
 */
int mitkToFImageWriterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFImageWriter");

  //testing initialization of object
  mitk::ToFImageWriter::Pointer tofWriter = mitk::ToFImageWriter::New();
  MITK_TEST_CONDITION_REQUIRED(tofWriter.GetPointer(), "Testing initialization of test object!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetExtension()!= "", "Test initialization of member extension!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetDistanceImageFileName()== "", "Test initialization of member distanceImageFileName!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetAmplitudeImageFileName()== "", "Test initialization of member amplitudeImageFileName!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetIntensityImageFileName()== "", "Test initialization of member intnensityImageFileName!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetDistanceImageSelected()==true, "Test initialization of member distanceImageSelected!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetAmplitudeImageSelected()==false, "Test initialization of member amplitudeImageSelected!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetIntensityImageSelected()==false, "Test initialization of member intensityImageSelected!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetRGBImageSelected()==false, "Test initialization of member rgbImageSelected!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetToFCaptureWidth()== 200, "Test initialization of member captureWidth!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetToFCaptureHeight()== 200, "Test initialization of member captureHeight!");
  MITK_TEST_CONDITION_REQUIRED(tofWriter->GetToFImageType()== mitk::ToFImageWriter::ToFImageType3D, "Test initialization of member ToFImageType!");

  //set member parameter and test again
  unsigned int dimX = 255;
  unsigned int dimY = 188;
  std::string distanceImageFileName("distImg.pic");
  std::string amplitudeImageFileName("amplImg.pic");
  std::string intensityImageFileName("intImg.pic");
  std::string rgbImageFileName("rgbImg.pic");
  std::string fileExtension(".test");
  bool distanceImageSelected = false;
  bool amplitudeImageSelected = false;
  bool intensityImageSelected = false;
  bool rgbImageSelected = false;

  tofWriter->SetToFCaptureWidth(dimX);
  tofWriter->SetToFCaptureHeight(dimY);
  tofWriter->SetDistanceImageFileName(distanceImageFileName);
  tofWriter->SetAmplitudeImageFileName(amplitudeImageFileName);
  tofWriter->SetIntensityImageFileName(intensityImageFileName);
  tofWriter->SetRGBImageFileName(rgbImageFileName);
  tofWriter->SetExtension(fileExtension);
  tofWriter->SetDistanceImageSelected(distanceImageSelected);
  tofWriter->SetAmplitudeImageSelected(amplitudeImageSelected);
  tofWriter->SetIntensityImageSelected(intensityImageSelected);
  tofWriter->SetRGBImageSelected(rgbImageSelected);
  tofWriter->SetToFImageType(mitk::ToFImageWriter::ToFImageType2DPlusT);

  MITK_TEST_CONDITION_REQUIRED(distanceImageFileName==tofWriter->GetDistanceImageFileName(), "Testing set/get distance image file name");
  MITK_TEST_CONDITION_REQUIRED(amplitudeImageFileName==tofWriter->GetAmplitudeImageFileName(), "Testing set/get amplitude image file name");
  MITK_TEST_CONDITION_REQUIRED(intensityImageFileName==tofWriter->GetIntensityImageFileName(), "Testing set/get intensity image file name");
  MITK_TEST_CONDITION_REQUIRED(rgbImageFileName==tofWriter->GetRGBImageFileName(), "Testing set/get rgb image file name");
  MITK_TEST_CONDITION_REQUIRED(dimX==tofWriter->GetToFCaptureWidth(), "Testing set/get CaptureWidth");
  MITK_TEST_CONDITION_REQUIRED(dimY==tofWriter->GetToFCaptureHeight(), "Testing set/get CaptureHeight");
  MITK_TEST_CONDITION_REQUIRED(distanceImageSelected==tofWriter->GetDistanceImageSelected(), "Testing set/get distance image selection");
  MITK_TEST_CONDITION_REQUIRED(amplitudeImageSelected==tofWriter->GetAmplitudeImageSelected(), "Testing set/get amplitude image selection");
  MITK_TEST_CONDITION_REQUIRED(intensityImageSelected==tofWriter->GetIntensityImageSelected(), "Testing set/get intensity image selection");
  MITK_TEST_CONDITION_REQUIRED(rgbImageSelected==tofWriter->GetRGBImageSelected(), "Testing set/get rgb image selection");
  MITK_TEST_CONDITION_REQUIRED(fileExtension==tofWriter->GetExtension(), "Testing set/get file extension");
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType2DPlusT==tofWriter->GetToFImageType(), "Testing set/get ToFImageType");

  MITK_TEST_END();
}
コード例 #17
0
int mitkUnstructuredGridTest(int /* argc */, char* /*argv*/[])
{
  // always start with this!
  MITK_TEST_BEGIN("UnstructuredGrid")

  // let's create an object of our class  
  mitk::UnstructuredGrid::Pointer testObject = mitk::UnstructuredGrid::New();
  MITK_TEST_CONDITION_REQUIRED(testObject.IsNotNull(),"Testing instantiation")
  MITK_TEST_CONDITION_REQUIRED( testObject->VerifyRequestedRegion(), "Requested region verification after initialization!");

  //create a clone object 
  mitk::UnstructuredGrid::Pointer cloneObject = testObject->Clone();
  MITK_TEST_CONDITION_REQUIRED(cloneObject.IsNotNull(),"Testing instantiation of clone")
  MITK_TEST_CONDITION_REQUIRED( cloneObject->VerifyRequestedRegion(), "Requested region verification after initialization of clone!");

    // set some grid data to the class
  vtkUnstructuredGrid* grid = vtkUnstructuredGrid::New();
  testObject->SetVtkUnstructuredGrid(grid);
  MITK_TEST_CONDITION_REQUIRED(testObject->GetVtkUnstructuredGrid()== grid, "Testing Set/Get vtkUnstructuredGrid");

  // specify a region and set it to the test object
  mitk::UnstructuredGrid::RegionType* ugRegion = new mitk::UnstructuredGrid::RegionType;
  mitk::UnstructuredGrid::RegionType::SizeType size;
  size[0] = 100;
  size[1] = 100;
  size[2] = 100;
  size[3] = 100;
  size[4] = 100;

  mitk::UnstructuredGrid::RegionType::IndexType index;
  index[0] = 0;
  index[1] = 0;
  index[2] = 0;

  ugRegion->SetSize(size);
  ugRegion->SetIndex(index);
  testObject->SetRequestedRegion(ugRegion);
  testObject->UpdateOutputInformation();
  MITK_TEST_CONDITION_REQUIRED(testObject->GetRequestedRegion().GetSize() == ugRegion->GetSize(), "Testing Set/Get of Requested Region by RegionType1!");
  MITK_TEST_CONDITION_REQUIRED(testObject->GetRequestedRegion().GetIndex() == ugRegion->GetIndex(), "Testing Set/Get of Requested Region by RegionType2!");
  // VerifyRequested Region should be false due to the chosen size parameter!
  MITK_TEST_CONDITION_REQUIRED(!testObject->VerifyRequestedRegion(), "Requested Region verification!");

  mitk::UnstructuredGrid::Pointer copyObject = mitk::UnstructuredGrid::New();
  copyObject->CopyInformation(testObject);
  copyObject->SetRequestedRegion(testObject);
  MITK_TEST_CONDITION_REQUIRED(copyObject->GetLargestPossibleRegion() == testObject->GetLargestPossibleRegion(), "Testing generation of copy object");
  MITK_TEST_CONDITION_REQUIRED(copyObject->GetRequestedRegion().GetSize() == ugRegion->GetSize(), "Testing SetRequestedRegion by DataObject1");
  MITK_TEST_CONDITION_REQUIRED(copyObject->GetRequestedRegion().GetIndex() == ugRegion->GetIndex(), "Testing SetRequestedRegion by DataObject2");


  cloneObject = testObject->Clone();
  MITK_TEST_CONDITION_REQUIRED(cloneObject->GetRequestedRegion() == testObject->GetRequestedRegion(), "Testing region cloning!");
  MITK_TEST_CONDITION_REQUIRED(cloneObject->GetVtkUnstructuredGrid()== grid, "Testing Get/Set-VtkUnstructuredGrid cloning");
  MITK_TEST_CONDITION_REQUIRED(cloneObject->GetRequestedRegion().GetSize() == ugRegion->GetSize(), "Testing Set/Get of Requested Region by RegionType1 in clone!");
  MITK_TEST_CONDITION_REQUIRED(cloneObject->GetRequestedRegion().GetIndex() == ugRegion->GetIndex(), "Testing Set/Get of Requested Region by RegionType2 in clone!");
  // VerifyRequested Region should be false due to the chosen size parameter!
  MITK_TEST_CONDITION_REQUIRED(!cloneObject->VerifyRequestedRegion(), "Requested Region verification!");

  // test this at the very end otherwise several other test cases need to be adapted!!
  testObject->SetRequestedRegionToLargestPossibleRegion();
  MITK_TEST_CONDITION_REQUIRED(testObject->GetRequestedRegion().GetSize() == testObject->GetLargestPossibleRegion().GetSize(), "Testing Set/Get LargestPossibleRegion!");

  // always end with this!
  MITK_TEST_END()
}
コード例 #18
0
int mitkPersistenceTest(int /*argc*/, char* /*argv*/[])
{
    MITK_TEST_BEGIN("PersistenceTest")
    // dummy load of SceneIO, otherwise PersistenceService won't be available
    //mitk::PersistenceService::LoadModule();

    MITK_INFO << "Testing availability of the PersistenceService.";
    PERSISTENCE_GET_SERVICE_MACRO
    MITK_TEST_CONDITION_REQUIRED(persistenceService, "IPersistenceService available")

    MITK_INFO << "Initialize testable parameter values.";

    Poco::File defaultPersistenceFile(persistenceService->GetDefaultPersistenceFile());
    PersistenceTestClass autoLoadTestClass;
    autoLoadTestClass.id = testClassId;
    if( defaultPersistenceFile.exists() && persistenceService->GetAutoLoadAndSave() )
    {
        MITK_INFO << "Testing auto load/save of the PersistenceService.";
        defaultPersistenceFile.remove();
        autoLoadTestClass.FromPropertyList();

        testParams( autoLoadTestClass, "autoLoadTestClass" );
    }

    MITK_INFO << "Removing left-over test files.";
    Poco::File testTempFile("PersistenceTestFile.mitk");
    if( testTempFile.exists() )
        testTempFile.remove(false);

    Poco::File testXmlTempFile("PersistenceTestFile.xml");
    if( testXmlTempFile.exists() )
        testXmlTempFile.remove(false);

    MITK_INFO << "Testing standard write to scene file/xml file.";
    PersistenceTestClass testClass;
    testClass.id = testClassId;
    testClass.param1 = param1;
    testClass.param2 = param2;
    testClass.param3 = param3;
    MITK_TEST_CONDITION_REQUIRED( testClass.Save(testTempFile.path()), "testClass.Save(testTempFile.path())");
    MITK_TEST_CONDITION_REQUIRED( testClass.Save(testXmlTempFile.path()), "testClass.Save(testTempFile.path())");

    MITK_INFO << "Testing read from scene file.";
    MITK_TEST_CONDITION_REQUIRED( persistenceService->RemovePropertyList(testClassId), "persistenceService->RemovePropertyList(testClassId)");
    PersistenceTestClass testClass2;
    testClass2.id = testClassId;
    MITK_TEST_CONDITION_REQUIRED( testClass2.Load(testTempFile.path()), "testClass2.Load(testTempFile.path())");

    testParams( testClass2, "testClass2" );

    MITK_INFO << "Testing read from xml file.";
    MITK_TEST_CONDITION_REQUIRED( persistenceService->RemovePropertyList(testClassId), "persistenceService->RemovePropertyList(testClassId)");
    PersistenceTestClass testClass3;
    testClass3.id = testClassId;
    MITK_TEST_CONDITION_REQUIRED( testClass3.Load(testXmlTempFile.path()), "testClass3.Load(testXmlTempFile.path())");

    testParams( testClass3, "testClass3" );

    MITK_INFO << "Testing appendChanges functionality with scene load/write.";
    MITK_TEST_CONDITION_REQUIRED( persistenceService->RemovePropertyList(testClassId), "persistenceService->RemovePropertyList(testClassId)");
    MITK_TEST_CONDITION_REQUIRED( persistenceService->Save(testTempFile.path(), true), "persistenceService->Save(testTempFile.path())");
    MITK_TEST_CONDITION_REQUIRED( persistenceService->Load(testTempFile.path()), "persistenceService->Load(testTempFile.path())");

    PersistenceTestClass testClass4;
    testClass4.id = testClassId;
    testClass4.FromPropertyList();
    testParams( testClass4, "testClass4" );

    MITK_INFO << "Testing appendChanges functionality with xml load/write.";
    MITK_TEST_CONDITION_REQUIRED( persistenceService->RemovePropertyList(testClassId), "persistenceService->RemovePropertyList(testClassId)");
    MITK_TEST_CONDITION_REQUIRED( persistenceService->Save(testXmlTempFile.path(), true), "persistenceService->Save(testXmlTempFile.path())");
    MITK_TEST_CONDITION_REQUIRED( persistenceService->Load(testXmlTempFile.path()), "persistenceService->Load(testXmlTempFile.path())");

    PersistenceTestClass testClass5;
    testClass5.id = testClassId;
    testClass5.FromPropertyList();
    testParams( testClass5, "testClass5" );

    MITK_INFO << "Testing observer functionality.";
    TestPropertyListReplacedObserver testObserver;
    testObserver.m_Id = testClassId;
    persistenceService->AddPropertyListReplacedObserver( &testObserver );
    persistenceService->Load(testTempFile.path());
    MITK_TEST_CONDITION( testObserver.counter == 2, "testObserver.counter == 2, testObserver.counter is " << testObserver.counter );

    MITK_INFO << "Cleaning test files.";
    if( testXmlTempFile.exists() )
        testXmlTempFile.remove(false);
    if( testTempFile.exists() )
        testTempFile.remove(false);

    autoLoadTestClass.param1 = param1;
    autoLoadTestClass.param2 = param2;
    autoLoadTestClass.param3 = param3;
    autoLoadTestClass.ToPropertyList();
    MITK_TEST_END()
}
コード例 #19
0
int mitkToFImageRecorderTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFImageRecorder");

  mitk::ToFImageRecorder::Pointer tofImageRecorder = mitk::ToFImageRecorder::New();

  MITK_TEST_OUTPUT(<< "Test itk-Set/Get-Makros");
  std::string testFileName_Distance = "test_DistanceImage.nrrd";
  std::string testFileName_Amplitude = "test_AmplitudeImage.nrrd";
  std::string testFileName_Intensity = "test_IntensityImage.nrrd";
  std::string requiredName_Distance;
  std::string requiredName_Amplitude;
  std::string requiredName_Intensity;

  tofImageRecorder->SetDistanceImageFileName(testFileName_Distance);
  requiredName_Distance = tofImageRecorder->GetDistanceImageFileName();
  MITK_TEST_CONDITION_REQUIRED(requiredName_Distance==testFileName_Distance,"Test for distance image file name");

  tofImageRecorder->SetAmplitudeImageFileName(testFileName_Amplitude);
  requiredName_Amplitude = tofImageRecorder->GetAmplitudeImageFileName();
  MITK_TEST_CONDITION_REQUIRED(requiredName_Amplitude==testFileName_Amplitude,"Test for amplitude image file name");

  tofImageRecorder->SetIntensityImageFileName(testFileName_Intensity);
  requiredName_Intensity = tofImageRecorder->GetIntensityImageFileName();
  MITK_TEST_CONDITION_REQUIRED(requiredName_Intensity==testFileName_Intensity,"Test for intensity image file name");

  bool distanceImageSelected = false;
  bool amplitudeImageSelected = false;
  bool intensityImageSelected = false;
  bool requiredDistanceImageSelected = false;
  bool requiredAmplitudeImageSelected = false;
  bool requiredIntensityImageSelected = false;

  tofImageRecorder->SetDistanceImageSelected(distanceImageSelected);
  requiredDistanceImageSelected = tofImageRecorder->GetDistanceImageSelected();
  MITK_TEST_CONDITION_REQUIRED(distanceImageSelected==requiredDistanceImageSelected,"Test for distance selection");

  tofImageRecorder->SetAmplitudeImageSelected(amplitudeImageSelected);
  requiredAmplitudeImageSelected = tofImageRecorder->GetAmplitudeImageSelected();
  MITK_TEST_CONDITION_REQUIRED(amplitudeImageSelected==requiredAmplitudeImageSelected,"Test for amplitude selection");

  tofImageRecorder->SetIntensityImageSelected(intensityImageSelected);
  requiredIntensityImageSelected = tofImageRecorder->GetIntensityImageSelected();
  MITK_TEST_CONDITION_REQUIRED(intensityImageSelected==requiredIntensityImageSelected,"Test for intensity selection");

  int numOfFrames = 7;
  tofImageRecorder->SetNumOfFrames(numOfFrames);
  MITK_TEST_CONDITION_REQUIRED(numOfFrames==tofImageRecorder->GetNumOfFrames(),"Test for get/set number of frames");

  std::string fileFormat = ".nrrd";
  tofImageRecorder->SetFileFormat(fileFormat);
  MITK_TEST_CONDITION_REQUIRED(fileFormat==tofImageRecorder->GetFileFormat(),"Test for get/set the file format");



  MITK_TEST_OUTPUT(<< "Test other methods");

  tofImageRecorder->SetRecordMode(mitk::ToFImageRecorder::Infinite);
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageRecorder::Infinite==tofImageRecorder->GetRecordMode(),"Test for get/set the record mode");

  mitk::ToFCameraDevice* testDevice = NULL;
  tofImageRecorder->SetCameraDevice(testDevice);
  MITK_TEST_CONDITION_REQUIRED(testDevice == tofImageRecorder->GetCameraDevice(),"Test for get/set the camera device");


  tofImageRecorder->SetToFImageType(mitk::ToFImageWriter::ToFImageType2DPlusT);
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType2DPlusT==tofImageRecorder->GetToFImageType(), "Testing set/get ToFImageType");

  tofImageRecorder->SetToFImageType(mitk::ToFImageWriter::ToFImageType3D);
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType3D==tofImageRecorder->GetToFImageType(), "Testing set/get ToFImageType");



  MITK_TEST_OUTPUT(<< "Test recording");

  tofImageRecorder = mitk::ToFImageRecorder::New();
  std::string dirName = MITK_TOF_DATA_DIR;
  mitk::ToFCameraMITKPlayerDevice::Pointer tofCameraMITKPlayerDevice = mitk::ToFCameraMITKPlayerDevice::New();
  tofImageRecorder->SetCameraDevice(tofCameraMITKPlayerDevice);
  MITK_TEST_CONDITION_REQUIRED(tofCameraMITKPlayerDevice == tofImageRecorder->GetCameraDevice(), "Testing set/get CameraDevice with ToFCameraPlayerDevice");

  std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_DistanceImage.pic";
  std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_AmplitudeImage.pic";
  std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_IntensityImage.pic";

  tofCameraMITKPlayerDevice->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName));
  tofCameraMITKPlayerDevice->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName));
  tofCameraMITKPlayerDevice->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName));

  MITK_TEST_OUTPUT(<< "Test ConnectCamera()");
  tofCameraMITKPlayerDevice->ConnectCamera();
  MITK_TEST_OUTPUT(<< "Test StartCamera()");
  tofCameraMITKPlayerDevice->StartCamera();

  std::string distanceTestFileName = dirName + "test_distance.nrrd";
  std::string amplitudeTestFileName = dirName + "test_amplitude.nrrd";
  std::string intensityTestFileName = dirName + "test_intensity.nrrd";

  tofImageRecorder->SetDistanceImageFileName(distanceTestFileName);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetDistanceImageFileName() == distanceTestFileName, "Testing Set/GetDistanceImageFileName()");
  tofImageRecorder->SetAmplitudeImageFileName(amplitudeTestFileName);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetAmplitudeImageFileName() == amplitudeTestFileName, "Testing Set/GetAmplitudeImageFileName()");
  tofImageRecorder->SetIntensityImageFileName(intensityTestFileName);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetIntensityImageFileName() == intensityTestFileName, "Testing Set/GetIntensityImageFileName()");
  tofImageRecorder->SetRecordMode(mitk::ToFImageRecorder::PerFrames);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetRecordMode() == mitk::ToFImageRecorder::PerFrames, "Testing Set/GetRecordMode()");
  tofImageRecorder->SetNumOfFrames(20);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetNumOfFrames() == 20, "Testing Set/GetNumOfFrames()");
  tofImageRecorder->SetFileFormat(".nrrd");
  MITK_TEST_OUTPUT(<< "Test StartRecording()");
  tofImageRecorder->StartRecording();
  tofImageRecorder->WaitForThreadBeingTerminated(); // wait to allow recording
  MITK_TEST_OUTPUT(<< "Test StopRecording()");
  tofImageRecorder->StopRecording();

  MITK_TEST_OUTPUT(<< "Test StopCamera()");
  tofCameraMITKPlayerDevice->StopCamera();
  MITK_TEST_OUTPUT(<< "Test DisconnectCamera()");
  tofCameraMITKPlayerDevice->DisconnectCamera();

  // Load images (recorded and original ones) with PicFileReader for comparison
  mitk::ItkImageFileReader::Pointer nrrdReader = mitk::ItkImageFileReader::New();
  mitk::PicFileReader::Pointer picFileReader = mitk::PicFileReader::New();
  mitk::Image::Pointer originalImage = NULL;
  mitk::Image::Pointer recordedImage = NULL;
  
  MITK_TEST_OUTPUT(<< "Read original distance image using PicFileReader");
  picFileReader->SetFileName(distanceFileName);
  picFileReader->Update();
  originalImage = picFileReader->GetOutput()->Clone();

  MITK_TEST_OUTPUT(<< "Read recorded distance image using ItkImageFileReader");
  nrrdReader->SetFileName(distanceTestFileName);
  nrrdReader->Update();
  recordedImage = nrrdReader->GetOutput()->Clone();

  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height");
  int numFramesOrig = originalImage->GetDimension(2);
  int numFramesRec = recordedImage->GetDimension(2);
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames");

  MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved distance image");


  MITK_TEST_OUTPUT(<< "Read original amplitude image using PicFileReader");
  picFileReader->SetFileName(amplitudeFileName);
  picFileReader->Update();
  originalImage = picFileReader->GetOutput()->Clone();

  MITK_TEST_OUTPUT(<< "Read recorded amplitude image using ItkImageFileReader");
  nrrdReader->SetFileName(amplitudeTestFileName);
  nrrdReader->Update();
  recordedImage = nrrdReader->GetOutput()->Clone();

  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames");

  MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved amplitude image");


  MITK_TEST_OUTPUT(<< "Read original intensity image using PicFileReader");
  picFileReader->SetFileName(intensityFileName);
  picFileReader->Update();
  originalImage = picFileReader->GetOutput()->Clone();

  MITK_TEST_OUTPUT(<< "Read recorded intensity image using ItkImageFileReader");
  nrrdReader->SetFileName(intensityTestFileName);
  nrrdReader->Update();
  recordedImage = nrrdReader->GetOutput()->Clone();

  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames");

  MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved intensity image");

  //clean up and delete saved image files
  if( remove( distanceTestFileName.c_str() ) != 0 )
  {
    MITK_ERROR<<"File: test_distance.nrrd not successfully deleted!";
  }
  if( remove( amplitudeTestFileName.c_str() ) != 0 )
  {
    MITK_ERROR<<"File: test_amplitude.nrrd not successfully deleted!";
  }
  if( remove( intensityTestFileName.c_str() ) != 0 )
  {
    MITK_ERROR<<"File: test_intensity.nrrd not successfully deleted!";
  }

  MITK_TEST_END();
}
コード例 #20
0
/**Documentation
 *  test for the class "NavigationDataReferenceTransformFilter".
 */
int mitkNavigationDataReferenceTransformFilterTest(int /* argc */, char* /*argv*/[])
{

  MITK_TEST_BEGIN("NavigationDataReferenceTransformFilter")

  // let's create an object of our class
  mitk::NavigationDataReferenceTransformFilter::Pointer myFilter = mitk::NavigationDataReferenceTransformFilter::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: positions of the ND sources*/
  mitk::NavigationData::PositionType sourcePos1,sourcePos2, sourcePos3, targetPos1, targetPos2, targetPos3;
  mitk::FillVector3D(sourcePos1, 11.1, 11.1, 11.1);
  mitk::FillVector3D(sourcePos2, 22.2, 22.2, 22.2);
  mitk::FillVector3D(sourcePos3, 33.3, 33.3, 33.3);
  mitk::FillVector3D(targetPos1, -1.1, -2.2, -3.3);
  mitk::FillVector3D(targetPos2, -4.4, -5.5, -6.6);
  mitk::FillVector3D(targetPos3, -7.7, -8.8, -9.9);

  /*create helper objects: orientations of the ND sources*/
  mitk::NavigationData::OrientationType sourceOri1(0.1, 0.1, 0.1, 0.1);
  mitk::NavigationData::OrientationType sourceOri2(0.2, 0.2, 0.2, 0.2);
  mitk::NavigationData::OrientationType sourceOri3(0.3, 0.3, 0.3, 0.3);
  mitk::NavigationData::OrientationType targetOri1(0.4, 0.4, 0.4, 0.4);
  mitk::NavigationData::OrientationType targetOri2(0.5, 0.5, 0.5, 0.5);
  mitk::NavigationData::OrientationType targetOri3(0.6, 0.6, 0.6, 0.6);

  /*create helper objects: ND position accurancy and validity bool*/
  mitk::ScalarType initialError(0.0);
  bool initialValid(true);

  /*create helper objects: NDs for the source and target NDs*/
  mitk::NavigationData::Pointer snd1 = mitk::NavigationData::New();
  snd1->SetPosition(sourcePos1);
  snd1->SetOrientation(sourceOri1);
  snd1->SetPositionAccuracy(initialError);
  snd1->SetDataValid(initialValid);

  mitk::NavigationData::Pointer snd2 = mitk::NavigationData::New();
  snd2->SetPosition(sourcePos2);
  snd2->SetOrientation(sourceOri2);
  snd2->SetPositionAccuracy(initialError);
  snd2->SetDataValid(initialValid);

  mitk::NavigationData::Pointer snd3 = mitk::NavigationData::New();
  snd3->SetPosition(sourcePos3);
  snd3->SetOrientation(sourceOri3);
  snd3->SetPositionAccuracy(initialError);
  snd3->SetDataValid(initialValid);

  mitk::NavigationData::Pointer tnd1 = mitk::NavigationData::New();
  tnd1->SetPosition(targetPos1);
  tnd1->SetOrientation(targetOri1);
  tnd1->SetPositionAccuracy(initialError);
  tnd1->SetDataValid(initialValid);

  mitk::NavigationData::Pointer tnd2 = mitk::NavigationData::New();
  tnd2->SetPosition(targetPos2);
  tnd2->SetOrientation(targetOri2);
  tnd2->SetPositionAccuracy(initialError);
  tnd2->SetDataValid(initialValid);

  mitk::NavigationData::Pointer tnd3 = mitk::NavigationData::New();
  tnd3->SetPosition(targetPos3);
  tnd3->SetOrientation(targetOri3);
  tnd3->SetPositionAccuracy(initialError);
  tnd3->SetDataValid(initialValid);

  std::vector<mitk::NavigationData::Pointer> emptySourceNDs;

  std::vector<mitk::NavigationData::Pointer> oneSourceNDs;
  oneSourceNDs.push_back(snd1);

  std::vector<mitk::NavigationData::Pointer> twoSourceNDs;
  twoSourceNDs.push_back(snd1);
  twoSourceNDs.push_back(snd2);

  std::vector<mitk::NavigationData::Pointer> threeSourceNDs;
  threeSourceNDs.push_back(snd1);
  threeSourceNDs.push_back(snd2);
  threeSourceNDs.push_back(snd3);

  std::vector<mitk::NavigationData::Pointer> emptyTargetNDs;

  std::vector<mitk::NavigationData::Pointer> oneTargetNDs;
  oneTargetNDs.push_back(tnd1);

  std::vector<mitk::NavigationData::Pointer> twoTargetNDs;
  twoTargetNDs.push_back(tnd1);
  twoTargetNDs.push_back(tnd2);

  std::vector<mitk::NavigationData::Pointer> threeTargetNDs;
  threeTargetNDs.push_back(tnd1);
  threeTargetNDs.push_back(tnd2);
  threeTargetNDs.push_back(tnd3);

  // ------------------ setting no NDs ------------------

  myFilter->SetSourceNavigationDatas(emptySourceNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetSourceLandmarks()->IsEmpty() == true, "Testing behaviour if setting no source NDs");

  myFilter->SetSourceNavigationDatas(emptyTargetNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetTargetLandmarks()->IsEmpty() == true, "Testing behaviour if setting no target NDs");

  // ------------------ setting one ND ------------------
  myFilter->SetSourceNavigationDatas(oneSourceNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetSourceLandmarks()->GetSize() == 3, "Testing if 3 source points are generated from one source ND");

  myFilter->SetTargetNavigationDatas(oneTargetNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetTargetLandmarks()->GetSize() == 3, "Testing if 3 target points are generated from one target ND");

  // ------------------ setting two NDs ------------------
  myFilter->SetSourceNavigationDatas(twoSourceNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetSourceLandmarks()->GetSize() == 6, "Testing if 6 source points are generated from two source NDs");

  myFilter->SetTargetNavigationDatas(twoTargetNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetTargetLandmarks()->GetSize() == 6, "Testing if 6 target points are generated from two target NDs");

  // ------------------ setting three NDs ------------------
  myFilter->SetSourceNavigationDatas(threeSourceNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetSourceLandmarks()->GetSize() == 3, "Testing if 3 source NDs are passed to 3 source points");

  myFilter->SetTargetNavigationDatas(threeTargetNDs);
  MITK_TEST_CONDITION_REQUIRED(myFilter->GetTargetLandmarks()->GetSize() == 3, "Testing if 3 target NDs are passed to 3 target points");



  // ------------------ setting different number of NDs for source and target ------------------
  bool firstInitialize = myFilter->InitializeTransform();
  myFilter->SetTargetNavigationDatas(twoTargetNDs);
  MITK_TEST_CONDITION_REQUIRED((firstInitialize == true && myFilter->InitializeTransform() == false), "Testing if initialization is denied, if different number of source and target NDs are set");

  // ------------------ reinit of this filter ------------------
  bool sourcePointsSet = myFilter->GetSourceLandmarks()->GetSize() > 0;
  bool targetPointsSet = myFilter->GetTargetLandmarks()->GetSize() > 0;
  MITK_TEST_CONDITION_REQUIRED(sourcePointsSet && targetPointsSet, "Testing if there are source and target landmarks set in the superclass");

  myFilter->ReinitFilter();
  bool sourcePointsCleared = myFilter->GetSourceLandmarks()->GetSize() == 0;
  bool targetPointsCleared = myFilter->GetTargetLandmarks()->GetSize() == 0;
  MITK_TEST_CONDITION_REQUIRED(sourcePointsCleared && targetPointsCleared, "Testing if reinit of filter was successful");

  // ------------------ testing the point generation ------------------

  myFilter->SetSourceNavigationDatas(oneSourceNDs); // set the ND with sourcePos1 and sourceOri1 for that the points will be generated

  itk::QuaternionRigidTransform<double>::Pointer quaternionTransform = itk::QuaternionRigidTransform<double>::New();
  vnl_quaternion<double> const vnlQuatIn(sourceOri1.x(), sourceOri1.y(), sourceOri1.z(), sourceOri1.r());
  quaternionTransform->SetRotation(vnlQuatIn);

  mitk::Point3D pointA;
  mitk::Point3D pointB;
  mitk::Point3D pointC;
  //initializing three points with position(0|0|0)
  pointA.Fill(0);
  pointB.Fill(0);
  pointC.Fill(0);
  // changing position off all points in order to make them orthogonal
  pointA[0] = 1;
  pointB[1] = 1;
  pointC[2] = 1;

  // quaternion transform the points
  pointA = quaternionTransform->GetRotationMatrix() * pointA;
  pointB = quaternionTransform->GetRotationMatrix() * pointB;
  pointC = quaternionTransform->GetRotationMatrix() * pointC;

  bool firstPoint0Same = sourcePos1[0] == myFilter->GetSourceLandmarks()->GetPoint(0)[0] - pointA[0];
  bool firstPoint1Same = sourcePos1[1] == myFilter->GetSourceLandmarks()->GetPoint(0)[1] - pointA[1];
  bool firstPoint2Same = sourcePos1[2] == myFilter->GetSourceLandmarks()->GetPoint(0)[2] - pointA[2];

  bool firstPointCorrect = firstPoint0Same && firstPoint1Same && firstPoint2Same;

  bool secondPoint0Same = sourcePos1[0] == myFilter->GetSourceLandmarks()->GetPoint(1)[0] - pointB[0];
  bool secondPoint1Same = sourcePos1[1] == myFilter->GetSourceLandmarks()->GetPoint(1)[1] - pointB[1];
  bool secondPoint2Same = sourcePos1[2] == myFilter->GetSourceLandmarks()->GetPoint(1)[2] - pointB[2];

  bool secondPointCorrect = secondPoint0Same && secondPoint1Same && secondPoint2Same;

  bool thirdPoint0Same = sourcePos1[0] == myFilter->GetSourceLandmarks()->GetPoint(2)[0] - pointC[0];
  bool thirdPoint1Same = sourcePos1[1] == myFilter->GetSourceLandmarks()->GetPoint(2)[1] - pointC[1];
  bool thirdPoint2Same = sourcePos1[2] == myFilter->GetSourceLandmarks()->GetPoint(2)[2] - pointC[2];

  bool thirdPointCorrect = thirdPoint0Same && thirdPoint1Same && thirdPoint2Same;

  //MITK_TEST_CONDITION_REQUIRED(firstPointCorrect && secondPointCorrect && thirdPointCorrect, "Testing if point generation is correct");


  // deleting helper objects
  myFilter = NULL;
  quaternionTransform = NULL;
  snd1 = NULL;
  snd2 = NULL;
  snd3 = NULL;
  tnd1 = NULL;
  tnd2 = NULL;
  tnd3 = NULL;

    // always end with this!
  MITK_TEST_END();
}
コード例 #21
0
int mitkMVConstrainedCostFunctionDecoratorTest(int  /*argc*/, char*[] /*argv[]*/)
{
	MITK_TEST_BEGIN("mitkMVConstrainedCostFunctionDecoratorTest")

  mitk::SimpleBarrierConstraintChecker::Pointer checker = mitk::SimpleBarrierConstraintChecker::New();
  mitk::MVConstrainedCostFunctionDecorator::Pointer decorator = mitk::MVConstrainedCostFunctionDecorator::New();
  TestCostFunction::Pointer innerCF = TestCostFunction::New();
  mitk::LinearModel::Pointer model = mitk::LinearModel::New();
  decorator->SetModel(model);
  innerCF->SetModel(model);

  mitk::MVModelFitCostFunction::SignalType signal(5);
  signal.Fill(0.0);
  decorator->SetSample(signal);
  innerCF->SetSample(signal);
  
  mitk::LinearModel::TimeGridType grid(5);
  grid[0] = 0;
  grid[1] = 1;
  grid[2] = 2;
  grid[3] = 3;
  grid[4] = 4;

  model->SetTimeGrid(grid);

  mitk::SimpleBarrierConstraintChecker::ParametersType p1(2);
  p1[0] = 0;
  p1[1] = 50;
  mitk::SimpleBarrierConstraintChecker::ParametersType p2(2);
  p2[0] = 10;
  p2[1] = 50;
  mitk::SimpleBarrierConstraintChecker::ParametersType p3(2);
  p3[0] = 100;
  p3[1] = 50;
  mitk::SimpleBarrierConstraintChecker::ParametersType p4(2);
  p4[0] = 2;
  p4[1] = 50;

  checker->SetLowerBarrier(0,1,4);
  checker->SetUpperBarrier(0,100);

  double defaultMaxPenalty = 1e15;

  ///////////////////////
  //Tests

  //check freshly created checker; 
  MITK_TEST_CONDITION_REQUIRED(decorator->GetWrappedCostFunction() == NULL,
								 "Testing GetWrappedCostFunction for new decorator.");
  MITK_TEST_CONDITION_REQUIRED(decorator->GetConstraintChecker() == NULL,
								 "Testing GetWrappedCostFunction for new decorator.");
  MITK_TEST_CONDITION_REQUIRED(decorator->GetFailureThreshold() == defaultMaxPenalty,
								 "Testing GetWrappedCostFunction for new decorator.");

  MITK_TEST_FOR_EXCEPTION(mitk::Exception, decorator->GetValue(p1));
  decorator->SetWrappedCostFunction(innerCF);
  MITK_TEST_FOR_EXCEPTION(mitk::Exception, decorator->GetValue(p1));
  decorator->SetWrappedCostFunction(NULL);
  decorator->SetConstraintChecker(checker);
  MITK_TEST_FOR_EXCEPTION(mitk::Exception, decorator->GetValue(p1));
  decorator->SetWrappedCostFunction(innerCF);


  mitk::MVModelFitCostFunction::MeasureType measure = decorator->GetValue(p1);
  MITK_TEST_CONDITION_REQUIRED(measure[0] == defaultMaxPenalty, "Testing measure 1 with parameters p1.");
  MITK_TEST_CONDITION_REQUIRED(measure[1] == defaultMaxPenalty, "Testing measure 2 with parameters p1.");
  MITK_TEST_CONDITION_REQUIRED(measure[2] == defaultMaxPenalty, "Testing measure 3 with parameters p1.");
  MITK_TEST_CONDITION_REQUIRED(measure[3] == defaultMaxPenalty, "Testing measure 3 with parameters p1.");
  MITK_TEST_CONDITION_REQUIRED(measure[4] == defaultMaxPenalty, "Testing measure 3 with parameters p1.");
  MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 0, "Checking calls with parameters p1.");

  measure = decorator->GetValue(p2);
  MITK_TEST_CONDITION_REQUIRED(measure[0] == 10, "Testing measure 1 with parameters p2.");
  MITK_TEST_CONDITION_REQUIRED(measure[1] == 50, "Testing measure 2 with parameters p2.");
  MITK_TEST_CONDITION_REQUIRED(measure[2] == 70, "Testing measure 3 with parameters p2.");
  MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 1, "Checking calls with parameters p2.");

  measure = decorator->GetValue(p3);
  MITK_TEST_CONDITION_REQUIRED(measure[0] == defaultMaxPenalty, "Testing measure 1 with parameters p3.");
  MITK_TEST_CONDITION_REQUIRED(measure[1] == defaultMaxPenalty, "Testing measure 2 with parameters p3.");
  MITK_TEST_CONDITION_REQUIRED(measure[2] == defaultMaxPenalty, "Testing measure 3 with parameters p3.");
  MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 1, "Checking calls with parameters p3.");

  decorator->SetActivateFailureThreshold(false);
  measure = decorator->GetValue(p3);
  MITK_TEST_CONDITION_REQUIRED(measure[0] == 100+defaultMaxPenalty, "Testing measure 1 with parameters p3 (deactiveated threshold).");
  MITK_TEST_CONDITION_REQUIRED(measure[1] == 50+defaultMaxPenalty, "Testing measure 2 with parameters p3 (deactiveated threshold).");
  MITK_TEST_CONDITION_REQUIRED(measure[2] == 250+defaultMaxPenalty, "Testing measure 3 with parameters p3 (deactiveated threshold).");
  MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls ==2, "Checking calls with parameters p3 (deactiveated threshold).");
  decorator->SetActivateFailureThreshold(true);

  measure = decorator->GetValue(p4);
  MITK_TEST_CONDITION_REQUIRED(measure[0] == 2+(-1*log(1/4.)), "Testing measure 1 with parameters p4.");
  MITK_TEST_CONDITION_REQUIRED(measure[1] == 50+(-1*log(1/4.)), "Testing measure 2 with parameters p4.");
  MITK_TEST_CONDITION_REQUIRED(measure[2] == 54+(-1*log(1/4.)), "Testing measure 3 with parameters p4.");
  MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 3, "Checking calls with parameters p4.");


  MITK_TEST_END()
}
コード例 #22
0
/**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(0);
  MITK_TEST_CONDITION(nd0!=NULL,"Testing GetOutput() [1]");
  nd0 = mySource->GetOutput(nd0->GetName());
  MITK_TEST_CONDITION(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();
}
コード例 #23
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)
{
   mitk::ImageWriter::Pointer myImageWriter = mitk::ImageWriter::New();
   myImageWriter->SetFileName(AppendExtension(filename, extension.c_str()) );
   myImageWriter->SetFilePrefix("pref");
   myImageWriter->SetFilePattern("pattern");
   myImageWriter->SetInput(image);


   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->Update();

    // 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
    {
      myImageWriter->SetInput( singleSliceImage );
      myImageWriter->Update();

      mitk::Image::Pointer compareImage = mitk::IOUtil::LoadImage( AppendExtension(filename, extension.c_str()).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() );
    }

  }

}
コード例 #24
0
ファイル: mitkSurfaceTest.cpp プロジェクト: 0r/MITK
int mitkSurfaceTest(int /*argc*/, char* /*argv*/[])
{

  MITK_TEST_BEGIN("Surface");

  mitk::Surface::Pointer surface = mitk::Surface::New();
  MITK_TEST_CONDITION_REQUIRED( surface.GetPointer(), "Testing initialization!" );

  mitk::Surface::Pointer cloneSurface = surface->Clone();
  MITK_TEST_CONDITION_REQUIRED( cloneSurface.GetPointer(), "Testing clone surface initialization!" );

  vtkSphereSource* sphereSource = vtkSphereSource::New();
  sphereSource->SetCenter(0,0,0);
  sphereSource->SetRadius(5.0);
  sphereSource->SetThetaResolution(10);
  sphereSource->SetPhiResolution(10);
  sphereSource->Update();

  vtkPolyData* polys = sphereSource->GetOutput();
  MITK_TEST_CONDITION_REQUIRED(surface->GetVtkPolyData() == nullptr, "Testing initial state of vtkPolyData");
  surface->SetVtkPolyData( polys );
  sphereSource->Delete();
  MITK_TEST_CONDITION_REQUIRED(surface->GetVtkPolyData()!= nullptr, "Testing set vtkPolyData");

  cloneSurface= nullptr;
  cloneSurface = surface->Clone();
  MITK_TEST_CONDITION_REQUIRED(cloneSurface->GetVtkPolyData()!= nullptr, "Testing set vtkPolyData of cloned surface!");
  cloneSurface = nullptr;

    double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
    polys->ComputeBounds();
    polys->GetBounds( bounds );

    surface->UpdateOutputInformation();
    surface->SetRequestedRegionToLargestPossibleRegion();
    mitk::BoundingBox* bb = const_cast<mitk::BoundingBox*>(surface->GetGeometry()->GetBoundingBox());
    mitk::BoundingBox::BoundsArrayType surfBounds = bb->GetBounds();

    bool passed = false;
    if ( bounds[0] == surfBounds[0] && bounds[1] == surfBounds[1]
      && bounds[2] == surfBounds[2] && bounds[3] == surfBounds[3]
      && bounds[4] == surfBounds[4] && bounds[5] == surfBounds[5] )
    {
      passed = true;
    }
    MITK_TEST_CONDITION_REQUIRED(passed, "Testing GetBoundingBox()!");

  surface->Expand(5);
  surface->Update();
  surface->SetRequestedRegionToLargestPossibleRegion();
  mitk::Surface::RegionType requestedRegion = surface->GetRequestedRegion();
  MITK_TEST_CONDITION_REQUIRED(requestedRegion.GetSize(3) == 5, "Testing mitk::Surface::Expand( timesteps ): ");

  double boundsMat[5][6];

  for (int i=0;i<5;i++) {
    vtkSphereSource* sphereSource = vtkSphereSource::New();
    sphereSource->SetCenter(0,0,0);
    sphereSource->SetRadius(1.0 * (i+1.0));
    sphereSource->SetThetaResolution(10);
    sphereSource->SetPhiResolution(10);
    sphereSource->Update();
    sphereSource->GetOutput()->ComputeBounds();
    sphereSource->GetOutput()->GetBounds( boundsMat[i] );
    surface->SetVtkPolyData( sphereSource->GetOutput(),i );
    sphereSource->Delete();
  }

  surface->UpdateOutputInformation();
  surface->SetRequestedRegionToLargestPossibleRegion();

  passed = true;
  for (int i=0;i<5;i++)
  {
    mitk::BoundingBox::BoundsArrayType surfBounds = (const_cast<mitk::BoundingBox*>(surface->GetTimeGeometry()->GetGeometryForTimeStep(i)->GetBoundingBox()))->GetBounds();

    if ( boundsMat[i][0] != surfBounds[0]
    || boundsMat[i][1] != surfBounds[1]
    || boundsMat[i][2] != surfBounds[2]
    || boundsMat[i][3] != surfBounds[3]
    || boundsMat[i][4] != surfBounds[4]
    || boundsMat[i][5] != surfBounds[5] )
    {
      passed = false;
      break;
    }
  }
  MITK_TEST_CONDITION_REQUIRED(passed, "Testing mitk::Surface::Testing 4D surface data creation!" );

  const mitk::TimeGeometry* inputTimeGeometry = surface->GetUpdatedTimeGeometry();

  int time = 3;
  int timestep=0;
  timestep = inputTimeGeometry->TimePointToTimeStep( time );
  MITK_TEST_CONDITION_REQUIRED(time == timestep, "Testing correctness of geometry for surface->GetUpdatedTimeGeometry()!");

  sphereSource = vtkSphereSource::New();
  sphereSource->SetCenter(0,0,0);
  sphereSource->SetRadius( 100.0 );
  sphereSource->SetThetaResolution(10);
  sphereSource->SetPhiResolution(10);
  sphereSource->Update();
  surface->SetVtkPolyData( sphereSource->GetOutput(), 3 );
  sphereSource->Delete();

  inputTimeGeometry = surface->GetUpdatedTimeGeometry();
  time = 3;
  timestep=0;

  timestep = inputTimeGeometry->TimePointToTimeStep( time );
  MITK_TEST_CONDITION_REQUIRED(time == timestep, "Explicitly changing the data of timestep 3 and checking for timebounds correctness of surface's geometry again!");

  unsigned int numberoftimesteps = surface->GetTimeSteps();
  mitk::Surface::Pointer dummy = mitk::Surface::New();
  dummy->Graft(surface);
  MITK_TEST_CONDITION_REQUIRED( dummy->GetVtkPolyData() != nullptr, "Testing copying a Surface with Graft()!");
  MITK_TEST_CONDITION_REQUIRED( dummy->GetTimeSteps() == numberoftimesteps, "orig-numberofTimeSteps:" << numberoftimesteps << "  copy-numberofTimeSteps:" << dummy->GetTimeSteps());

  surface = nullptr;
  MITK_TEST_CONDITION_REQUIRED( surface.IsNull(), "Testing destruction of surface!");

  MITK_TEST_END();
}
コード例 #25
0
/**Documentation
* \brief Test for all PropertySerializer classes.
*
*/
int mitkPropertySerializationTest(int /* argc */, char * /*argv*/ [])
{
  MITK_TEST_BEGIN("PropertySerializationTest");

  mitk::PropertyListSerializer::Pointer serializer =
    mitk::PropertyListSerializer::New(); // make sure something from the lib is actually used (registration of
                                         // serializers)

  /* build list of properties that will be serialized and deserialized */
  mitk::PropertyList::Pointer propList = mitk::PropertyList::New();
  propList->SetProperty("booltrue", mitk::BoolProperty::New(true));
  propList->SetProperty("boolfalse", mitk::BoolProperty::New(false));
  propList->SetProperty("int", mitk::IntProperty::New(-32));
  propList->SetProperty("float", mitk::FloatProperty::New(-31.337));
  propList->SetProperty("double", mitk::DoubleProperty::New(-31.337));
  propList->SetProperty("string", mitk::StringProperty::New("Hello MITK"));
  mitk::Point3D p3d;
  mitk::FillVector3D(p3d, 1.0, 2.2, -3.3);
  propList->SetProperty("p3d", mitk::Point3dProperty::New(p3d));
  mitk::Point3I p3i;
  mitk::FillVector3D(p3i, 1, 2, -3);
  propList->SetProperty("p3i", mitk::Point3iProperty::New(p3i));
  mitk::Point4D p4d;
  mitk::FillVector4D(p4d, 1.5, 2.6, -3.7, 4.44);
  propList->SetProperty("p4d", mitk::Point4dProperty::New(p4d));
  mitk::Vector3D v3d;
  mitk::FillVector3D(v3d, 1.0, 2.2, -3.3);
  propList->SetProperty("v3d", mitk::Vector3DProperty::New(v3d));
  propList->SetProperty("annotation", mitk::AnnotationProperty::New("My Annotation", p3d));
  propList->SetProperty("clipping", mitk::ClippingProperty::New(p3d, v3d));
  propList->SetProperty("color", mitk::ColorProperty::New(1.0, 0.2, 0.2));
  // mitk::EnumerationProperty::Pointer en = mitk::EnumerationProperty::New();
  // en->AddEnum("PC", 1); en->AddEnum("Playstation", 2); en->AddEnum("Wii", 111); en->AddEnum("XBox", 7);
  // en->SetValue("XBox");
  // propList->SetProperty("enum", en);
  /*
  propList->SetProperty("gridrep", mitk::GridRepresentationProperty::New(2));
  propList->SetProperty("gridvol", mitk::GridVolumeMapperProperty::New(0));
  propList->SetProperty("OrganTypeProperty", mitk::OrganTypeProperty::New("Larynx"));
  */
  propList->SetProperty("modality", mitk::ModalityProperty::New("Color Doppler"));
  // propList->SetProperty("OdfNormalizationMethodProperty", mitk::OdfNormalizationMethodProperty::New("Global
  // Maximum"));
  // propList->SetProperty("OdfScaleByProperty", mitk::OdfScaleByProperty::New("Principal Curvature"));
  propList->SetProperty("PlaneOrientationProperty",
                        mitk::PlaneOrientationProperty::New("Arrows in positive direction"));
  propList->SetProperty("VtkInterpolationProperty", mitk::VtkInterpolationProperty::New("Gouraud"));
  propList->SetProperty("VtkRepresentationProperty", mitk::VtkRepresentationProperty::New("Surface"));
  propList->SetProperty("VtkResliceInterpolationProperty", mitk::VtkResliceInterpolationProperty::New("Cubic"));
  propList->SetProperty("VtkScalarModeProperty", mitk::VtkScalarModeProperty::New("PointFieldData"));
  propList->SetProperty("VtkVolumeRenderingProperty", mitk::VtkVolumeRenderingProperty::New("COMPOSITE"));
  mitk::BoolLookupTable blt;
  blt.SetTableValue(0, true);
  blt.SetTableValue(1, false);
  blt.SetTableValue(2, true);
  propList->SetProperty("BoolLookupTableProperty", mitk::BoolLookupTableProperty::New(blt));
  mitk::FloatLookupTable flt;
  flt.SetTableValue(0, 3.1);
  flt.SetTableValue(1, 3.3);
  flt.SetTableValue(2, 7.0);
  propList->SetProperty("FloatLookupTableProperty", mitk::FloatLookupTableProperty::New(flt));
  mitk::IntLookupTable ilt;
  ilt.SetTableValue(0, 3);
  ilt.SetTableValue(1, 2);
  ilt.SetTableValue(2, 11);
  propList->SetProperty("IntLookupTableProperty", mitk::IntLookupTableProperty::New(ilt));
  mitk::StringLookupTable slt;
  slt.SetTableValue(0, "Hello");
  slt.SetTableValue(1, "MITK");
  slt.SetTableValue(2, "world");
  propList->SetProperty("StringLookupTableProperty", mitk::StringLookupTableProperty::New(slt));
  propList->SetProperty("GroupTagProperty", mitk::GroupTagProperty::New());
  propList->SetProperty("LevelWindowProperty", mitk::LevelWindowProperty::New(mitk::LevelWindow(100.0, 50.0)));
  mitk::LookupTable::Pointer lt = mitk::LookupTable::New();
  lt->ChangeOpacityForAll(0.25);
  lt->ChangeOpacity(17, 0.88);
  propList->SetProperty("LookupTableProperty", mitk::LookupTableProperty::New(lt));
  propList->SetProperty("StringProperty", mitk::StringProperty::New("Oh why, gruel world"));
  // mitk::TransferFunction::Pointer tf = mitk::TransferFunction::New();
  // tf->SetTransferFunctionMode(1);
  // propList->SetProperty("TransferFunctionProperty", mitk::TransferFunctionProperty::New(tf));

  MITK_TEST_CONDITION_REQUIRED(propList->GetMap()->size() > 0, "Initialize PropertyList");

  TestAllProperties(propList);

  /* test default property lists of basedata objects */
  // activate the following tests after MaterialProperty is deleted

  mitk::DataNode::Pointer node = mitk::DataNode::New();
  node->SetData(mitk::PointSet::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Image::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Surface::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::VtkWidgetRendering::New());
  TestAllProperties(node->GetPropertyList());

  /*
  node->SetData(mitk::Contour::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::ContourSet::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Mesh::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Cone::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Cuboid::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Cylinder::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Ellipsoid::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::ExtrudedContour::New());
  TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::Plane::New());
  TestAllProperties(node->GetPropertyList());
  //node->SetData(mitk::TrackingVolume::New());  // TrackingVolume is in IGT Module, it does not have special
  properties, therefore we skip it here
  //TestAllProperties(node->GetPropertyList());
  node->SetData(mitk::UnstructuredGrid::New());
  TestAllProperties(node->GetPropertyList());
  */

  /* untested base data types:
    BaseDataTestImplementation
    RenderWindowFrame
    GeometryData
    mitk::PlaneGeometryData
    GradientBackground
    ItkBaseDataAdapter
    SlicedData
    OdfImage
    SeedsImage
    TensorImage
    BoundingObject
    BoundingObjectGroup
    */

  MITK_TEST_END();
}
コード例 #26
0
/**Documentation
 *  Test if fiber transfortaiom methods work correctly
 */
int mitkFiberExtractionTest(int argc, char* argv[])
{
    MITK_TEST_BEGIN("mitkFiberExtractionTest");

    /// \todo Fix VTK memory leaks. Bug 18097.
    vtkDebugLeaks::SetExitError(0);

    MITK_INFO << "argc: " << argc;
    MITK_TEST_CONDITION_REQUIRED(argc==13,"check for input data");

    omp_set_num_threads(1);
    try{
        mitk::FiberBundle::Pointer groundTruthFibs = dynamic_cast<mitk::FiberBundle*>( mitk::IOUtil::Load(argv[1]).front().GetPointer() );
        mitk::FiberBundle::Pointer testFibs = dynamic_cast<mitk::FiberBundle*>( mitk::IOUtil::Load(argv[2]).front().GetPointer() );

        // test planar figure based extraction
        mitk::DataNode::Pointer pf1 = mitk::IOUtil::LoadDataNode(argv[3]);
        mitk::DataNode::Pointer pf2 = mitk::IOUtil::LoadDataNode(argv[4]);
        mitk::DataNode::Pointer pf3 = mitk::IOUtil::LoadDataNode(argv[5]);

        mitk::StandaloneDataStorage::Pointer storage = mitk::StandaloneDataStorage::New();

        mitk::PlanarFigureComposite::Pointer pfc2 = mitk::PlanarFigureComposite::New();
        pfc2->setOperationType(mitk::PlanarFigureComposite::OR);
        mitk::DataNode::Pointer pfcNode2 = mitk::DataNode::New();
        pfcNode2->SetData(pfc2);
        mitk::DataStorage::SetOfObjects::Pointer set2 = mitk::DataStorage::SetOfObjects::New();
        set2->push_back(pfcNode2);

        mitk::PlanarFigureComposite::Pointer pfc1 = mitk::PlanarFigureComposite::New();
        pfc1->setOperationType(mitk::PlanarFigureComposite::AND);
        mitk::DataNode::Pointer pfcNode1 = mitk::DataNode::New();
        pfcNode1->SetData(pfc1);
        mitk::DataStorage::SetOfObjects::Pointer set1 = mitk::DataStorage::SetOfObjects::New();
        set1->push_back(pfcNode1);

        storage->Add(pfcNode2);
        storage->Add(pf1, set2);
        storage->Add(pfcNode1, set2);
        storage->Add(pf2, set1);
        storage->Add(pf3, set1);

        MITK_INFO << "TEST1";
        mitk::FiberBundle::Pointer extractedFibs = groundTruthFibs->ExtractFiberSubset(pfcNode2, storage);
        MITK_INFO << "TEST2";
        MITK_TEST_CONDITION_REQUIRED(extractedFibs->Equals(testFibs),"check planar figure extraction");

        MITK_INFO << "TEST3";
        // test subtraction and addition
        mitk::FiberBundle::Pointer notExtractedFibs = groundTruthFibs->SubtractBundle(extractedFibs);

        MITK_INFO << argv[11];
        testFibs = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::Load(argv[11]).front().GetPointer());
        MITK_TEST_CONDITION_REQUIRED(notExtractedFibs->Equals(testFibs),"check bundle subtraction");

        mitk::FiberBundle::Pointer joinded = extractedFibs->AddBundle(notExtractedFibs);
        testFibs = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::Load(argv[12]).front().GetPointer());
        MITK_TEST_CONDITION_REQUIRED(joinded->Equals(testFibs),"check bundle addition");

        // test binary image based extraction
        mitk::Image::Pointer mitkRoiImage = dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(argv[6]).front().GetPointer());
        typedef itk::Image< unsigned char, 3 >    itkUCharImageType;
        itkUCharImageType::Pointer itkRoiImage = itkUCharImageType::New();
        mitk::CastToItkImage(mitkRoiImage, itkRoiImage);

        //        mitk::FiberBundle::Pointer inside = groundTruthFibs->RemoveFibersOutside(itkRoiImage, false);
        //        mitk::IOUtil::SaveBaseData(inside, mitk::IOUtil::GetTempPath()+"inside.fib");
        //        mitk::FiberBundle::Pointer outside = groundTruthFibs->RemoveFibersOutside(itkRoiImage, true);
        //        mitk::IOUtil::SaveBaseData(outside, mitk::IOUtil::GetTempPath()+"outside.fib");

        mitk::FiberBundle::Pointer passing = groundTruthFibs->ExtractFiberSubset(itkRoiImage, true);
        mitk::IOUtil::SaveBaseData(passing, mitk::IOUtil::GetTempPath()+"passing.fib");
        mitk::FiberBundle::Pointer ending = groundTruthFibs->ExtractFiberSubset(itkRoiImage, false);
        //        mitk::IOUtil::SaveBaseData(ending, mitk::IOUtil::GetTempPath()+"ending.fib");

        //        testFibs = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::LoadDataNode(argv[7])->GetData());
        //        MITK_TEST_CONDITION_REQUIRED(inside->Equals(testFibs),"check inside mask extraction")

        //        testFibs = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::LoadDataNode(argv[8])->GetData());
        //        MITK_TEST_CONDITION_REQUIRED(outside->Equals(testFibs),"check outside mask extraction")

        testFibs = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::Load(argv[9]).front().GetPointer());
        MITK_TEST_CONDITION_REQUIRED(passing->Equals(testFibs),"check passing mask extraction");

        testFibs = dynamic_cast<mitk::FiberBundle*>(mitk::IOUtil::Load(argv[10]).front().GetPointer());
        MITK_TEST_CONDITION_REQUIRED(ending->Equals(testFibs),"check ending in mask extraction");
    }
    catch(...) {
        return EXIT_FAILURE;
    }

    // always end with this!
    MITK_TEST_END();
}
コード例 #27
0
int mitkToFCompositeFilterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFCompositeFilter");

  //initialize composite filter
  mitk::ToFCompositeFilter::Pointer compositeFilter = mitk::ToFCompositeFilter::New();

  //Initialize threshold filter
  ThresholdFilterType::Pointer thresholdFilter = ThresholdFilterType::New();
  int threshold_min = 5;
  int threshold_max = 100;
  thresholdFilter->SetOutsideValue(0.0);
  thresholdFilter->SetLower(threshold_min);
  thresholdFilter->SetUpper(threshold_max);
  compositeFilter->SetThresholdFilterParameter(threshold_min, threshold_max);

  //Initialize spatial median filter
  MedianFilterType::Pointer medianFilter = MedianFilterType::New();

  //Initialize bilateral filter
  BilateralImageFilterType::Pointer bilateralFilter = BilateralImageFilterType::New();
  float domainSigma = 4;
  float rangeSigma = 50;
  float kernelRadius = 3;
  bilateralFilter->SetDomainSigma(domainSigma);
  bilateralFilter->SetRangeSigma(rangeSigma);
  bilateralFilter->SetRadius(kernelRadius);
  compositeFilter->SetBilateralFilterParameter(domainSigma,rangeSigma,kernelRadius);

  //Initialize pipeline
  ItkImageType_2D::Pointer itkInputImage = ItkImageType_2D::New();
  mitk::Image::Pointer mitkInputImage = mitk::Image::New();
  CreateRandomDistanceImage(100,100,itkInputImage,mitkInputImage);
  ItkImageType_2D::Pointer itkOutputImage;
  compositeFilter->SetInput(mitkInputImage);
  mitk::Image::Pointer mitkOutputImage = compositeFilter->GetOutput();


  //-------------------------------------------------------------------------------------------------------

  //Apply first filter only (threshold)

  //standard variant
  thresholdFilter->SetInput(itkInputImage);
  itkOutputImage = thresholdFilter->GetOutput();
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyThresholdFilter(true);
  compositeFilter->SetApplyMedianFilter(false);
  compositeFilter->SetApplyTemporalMedianFilter(false);
  compositeFilter->SetApplyBilateralFilter(false);
  mitkOutputImage->Update();

  //compare output
  mitk::Image::Pointer itkOutputImageConverted;
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);

  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(*itkOutputImageConverted, *mitkOutputImage, mitk::eps, true),
                                "Test threshold filter in pipeline");

  //-------------------------------------------------------------------------------------------------------

  //Apply first and second filter

  //standard variant
  medianFilter->SetInput(thresholdFilter->GetOutput());
  itkOutputImage = medianFilter->GetOutput();
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyMedianFilter(true);
  mitkOutputImage->Update();

  //compare output
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);

  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(*itkOutputImageConverted, *mitkOutputImage, mitk::eps, true),
                               "Test threshold and median filter in pipeline");


  //-------------------------------------------------------------------------------------------------------

  //Apply first three filters

  //standard variant
  bilateralFilter->SetInput(medianFilter->GetOutput());
  itkOutputImage = bilateralFilter->GetOutput();
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyBilateralFilter(true);
  mitkOutputImage->Update();

  //compare output
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);

  MITK_TEST_CONDITION_REQUIRED( mitk::Equal(*itkOutputImageConverted, *mitkOutputImage, mitk::eps, true),
                               "Test threshold filter, bilateral filter and temporal median filter in pipeline");


  //-------------------------------------------------------------------------------------------------------
  // TODO: Rewrite this. This don't make sense. the itk reference applies a median filter
  // and threshold filter afterwards. The composite filter does it in the other directtion.
  // also the input of random image stacks is never set into the composite filter

  //Apply all filters

  //generate image stack
//  ItkImageType_3D::Pointer itkInputImage3D = ItkImageType_3D::New();
//  mitk::Image::Pointer mitkImage3D = mitk::Image::New();
//  CreateRandomDistanceImageStack(100,100,12,itkInputImage3D,mitkImage3D);
//
//  //standard variant
//  ItkImageType_2D::Pointer medianFilteredImage = ItkImageType_2D::New();
//  ApplyTemporalMedianFilter(mitkImage3D,medianFilteredImage);
//  thresholdFilter->SetInput(medianFilteredImage);
//  itkOutputImage->Update();
//
//  //variant with composite filter
//  compositeFilter->SetApplyTemporalMedianFilter(true);
//  mitkOutputImage->Update();
//
//  //compare output
//  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);
//  pipelineSuccess = CompareImages(itkOutputImageConverted,mitkOutputImage);
//  MITK_TEST_CONDITION_REQUIRED(pipelineSuccess,"Test all filters in pipeline");


//-------------------------------------------------------------------------------------------------------

  //Check set/get functions
  mitk::Image::Pointer newImage = mitk::Image::New();
  mitk::Image::Pointer returnedImage;
  compositeFilter->SetInput(newImage);
  returnedImage = compositeFilter->GetInput();
  MITK_TEST_CONDITION_REQUIRED(newImage == returnedImage,"Get/Set empty image");

  compositeFilter->SetApplyTemporalMedianFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyTemporalMedianFilter()==false,"Get/Set ApplyTemporalMedianFilter");

  compositeFilter->SetApplyMedianFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyMedianFilter()==false,"Get/Set ApplyMedianFilter");

  compositeFilter->SetApplyThresholdFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyThresholdFilter()==false,"Get/Set ApplyThresholdFilter");

  compositeFilter->SetApplyBilateralFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyBilateralFilter()==false,"Get/Set ApplyBilateralFilter");

//-------------------------------------------------------------------------------------------------------

  MITK_TEST_END();

}
コード例 #28
0
int mitkFiberfoxSignalGenerationTest(int argc, char* argv[])
{
    MITK_TEST_BEGIN("mitkFiberfoxSignalGenerationTest");

    MITK_TEST_CONDITION_REQUIRED(argc>=19,"check for input data");

    // input fiber bundle
    FiberBundleXReader::Pointer fibReader = FiberBundleXReader::New();
    fibReader->SetFileName(argv[1]);
    fibReader->Update();
    FiberBundleX::Pointer fiberBundle = dynamic_cast<FiberBundleX*>(fibReader->GetOutput());

    // reference diffusion weighted images
    mitk::DiffusionImage<short>::Pointer stickBall = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[2])->GetData());
    mitk::DiffusionImage<short>::Pointer stickAstrosticks = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[3])->GetData());
    mitk::DiffusionImage<short>::Pointer stickDot = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[4])->GetData());
    mitk::DiffusionImage<short>::Pointer tensorBall = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[5])->GetData());
    mitk::DiffusionImage<short>::Pointer stickTensorBall = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[6])->GetData());
    mitk::DiffusionImage<short>::Pointer stickTensorBallAstrosticks = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[7])->GetData());
    mitk::DiffusionImage<short>::Pointer gibbsringing = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[8])->GetData());
    mitk::DiffusionImage<short>::Pointer ghost = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[9])->GetData());
    mitk::DiffusionImage<short>::Pointer aliasing = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[10])->GetData());
    mitk::DiffusionImage<short>::Pointer eddy = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[11])->GetData());
    mitk::DiffusionImage<short>::Pointer linearmotion = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[12])->GetData());
    mitk::DiffusionImage<short>::Pointer randommotion = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[13])->GetData());
    mitk::DiffusionImage<short>::Pointer spikes = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[14])->GetData());
    mitk::DiffusionImage<short>::Pointer riciannoise = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[15])->GetData());
    mitk::DiffusionImage<short>::Pointer chisquarenoise = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[16])->GetData());
    mitk::DiffusionImage<short>::Pointer distortions = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(argv[17])->GetData());
    mitk::Image::Pointer mitkFMap = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(argv[18])->GetData());
    typedef itk::Image<double, 3> ItkDoubleImgType;
    ItkDoubleImgType::Pointer fMap = ItkDoubleImgType::New();
    mitk::CastToItkImage<ItkDoubleImgType>(mitkFMap, fMap);

    FiberfoxParameters<double> parameters;
    parameters.m_DoSimulateRelaxation = true;
    parameters.m_SignalScale = 10000;
    parameters.m_ImageRegion = stickBall->GetVectorImage()->GetLargestPossibleRegion();
    parameters.m_ImageSpacing = stickBall->GetVectorImage()->GetSpacing();
    parameters.m_ImageOrigin = stickBall->GetVectorImage()->GetOrigin();
    parameters.m_ImageDirection = stickBall->GetVectorImage()->GetDirection();
    parameters.m_Bvalue = stickBall->GetB_Value();
    parameters.SetGradienDirections(stickBall->GetDirections());

    // intra and inter axonal compartments
    mitk::StickModel<double> stickModel;
    stickModel.SetBvalue(parameters.m_Bvalue);
    stickModel.SetT2(110);
    stickModel.SetDiffusivity(0.001);
    stickModel.SetGradientList(parameters.GetGradientDirections());

    mitk::TensorModel<double> tensorModel;
    tensorModel.SetT2(110);
    stickModel.SetBvalue(parameters.m_Bvalue);
    tensorModel.SetDiffusivity1(0.001);
    tensorModel.SetDiffusivity2(0.00025);
    tensorModel.SetDiffusivity3(0.00025);
    tensorModel.SetGradientList(parameters.GetGradientDirections());

    // extra axonal compartment models
    mitk::BallModel<double> ballModel;
    ballModel.SetT2(80);
    ballModel.SetBvalue(parameters.m_Bvalue);
    ballModel.SetDiffusivity(0.001);
    ballModel.SetGradientList(parameters.GetGradientDirections());

    mitk::AstroStickModel<double> astrosticksModel;
    astrosticksModel.SetT2(80);
    astrosticksModel.SetBvalue(parameters.m_Bvalue);
    astrosticksModel.SetDiffusivity(0.001);
    astrosticksModel.SetRandomizeSticks(true);
    astrosticksModel.SetSeed(0);
    astrosticksModel.SetGradientList(parameters.GetGradientDirections());

    mitk::DotModel<double> dotModel;
    dotModel.SetT2(80);
    dotModel.SetGradientList(parameters.GetGradientDirections());

    // noise models
    mitk::RicianNoiseModel<double>* ricianNoiseModel = new mitk::RicianNoiseModel<double>();
    ricianNoiseModel->SetNoiseVariance(1000000);
    ricianNoiseModel->SetSeed(0);

    // Rician noise
    mitk::ChiSquareNoiseModel<double>* chiSquareNoiseModel = new mitk::ChiSquareNoiseModel<double>();
    chiSquareNoiseModel->SetNoiseVariance(1000000);
    chiSquareNoiseModel->SetSeed(0);

    try {
        // Stick-Ball
        parameters.m_FiberModelList.push_back(&stickModel);
        parameters.m_NonFiberModelList.push_back(&ballModel);
        StartSimulation(parameters, fiberBundle, stickBall, argv[2]);

        // Srick-Astrosticks
        parameters.m_NonFiberModelList.clear();
        parameters.m_NonFiberModelList.push_back(&astrosticksModel);
        StartSimulation(parameters, fiberBundle, stickAstrosticks, argv[3]);

        // Stick-Dot
        parameters.m_NonFiberModelList.clear();
        parameters.m_NonFiberModelList.push_back(&dotModel);
        StartSimulation(parameters, fiberBundle, stickDot, argv[4]);

        // Tensor-Ball
        parameters.m_FiberModelList.clear();
        parameters.m_FiberModelList.push_back(&tensorModel);
        parameters.m_NonFiberModelList.clear();
        parameters.m_NonFiberModelList.push_back(&ballModel);
        StartSimulation(parameters, fiberBundle, tensorBall, argv[5]);

        // Stick-Tensor-Ball
        parameters.m_FiberModelList.clear();
        parameters.m_FiberModelList.push_back(&stickModel);
        parameters.m_FiberModelList.push_back(&tensorModel);
        parameters.m_NonFiberModelList.clear();
        parameters.m_NonFiberModelList.push_back(&ballModel);
        StartSimulation(parameters, fiberBundle, stickTensorBall, argv[6]);

        // Stick-Tensor-Ball-Astrosticks
        parameters.m_NonFiberModelList.push_back(&astrosticksModel);
        StartSimulation(parameters, fiberBundle, stickTensorBallAstrosticks, argv[7]);

        // Gibbs ringing
        parameters.m_FiberModelList.clear();
        parameters.m_FiberModelList.push_back(&stickModel);
        parameters.m_NonFiberModelList.clear();
        parameters.m_NonFiberModelList.push_back(&ballModel);
        parameters.m_DoAddGibbsRinging = true;
        StartSimulation(parameters, fiberBundle, gibbsringing, argv[8]);

        // Ghost
        parameters.m_DoAddGibbsRinging = false;
        parameters.m_KspaceLineOffset = 0.25;
        StartSimulation(parameters, fiberBundle, ghost, argv[9]);

        // Aliasing
        parameters.m_KspaceLineOffset = 0;
        parameters.m_CroppingFactor = 0.4;
        parameters.m_SignalScale = 1000;
        StartSimulation(parameters, fiberBundle, aliasing, argv[10]);

        // Eddy currents
        parameters.m_CroppingFactor = 1;
        parameters.m_SignalScale = 10000;
        parameters.m_EddyStrength = 0.05;
        StartSimulation(parameters, fiberBundle, eddy, argv[11]);

        // Motion (linear)
        parameters.m_EddyStrength = 0.0;
        parameters.m_DoAddMotion = true;
        parameters.m_DoRandomizeMotion = false;
        parameters.m_Translation[1] = 10;
        parameters.m_Rotation[2] = 90;
        StartSimulation(parameters, fiberBundle, linearmotion, argv[12]);

        // Motion (random)
        parameters.m_DoRandomizeMotion = true;
        parameters.m_Translation[1] = 5;
        parameters.m_Rotation[2] = 45;
        StartSimulation(parameters, fiberBundle, randommotion, argv[13]);

        // Spikes
        parameters.m_DoAddMotion = false;
        parameters.m_Spikes = 5;
        parameters.m_SpikeAmplitude = 1;
        StartSimulation(parameters, fiberBundle, spikes, argv[14]);

        // Rician noise
        parameters.m_Spikes = 0;
        parameters.m_NoiseModel = ricianNoiseModel;
        StartSimulation(parameters, fiberBundle, riciannoise, argv[15]);
        delete parameters.m_NoiseModel;

        // Chi-square noise
        parameters.m_NoiseModel = chiSquareNoiseModel;
        StartSimulation(parameters, fiberBundle, chisquarenoise, argv[16]);
        delete parameters.m_NoiseModel;

        // Distortions
        parameters.m_NoiseModel = NULL;
        parameters.m_FrequencyMap = fMap;
        StartSimulation(parameters, fiberBundle, distortions, argv[17]);
    }
    catch (std::exception &e)
    {
        MITK_TEST_CONDITION_REQUIRED(false, e.what());
    }

    // always end with this!
    MITK_TEST_END();
}
コード例 #29
0
ファイル: mitkMessageTest.cpp プロジェクト: Cdebus/MITK
int mitkMessageTest(int /* argc */, char * /*argv*/ [])
{
  MITK_TEST_BEGIN("Message")

  mitk::mitkMessageTestTestClass::MessageSenderClass sender;
  mitk::mitkMessageTestTestClass::MessageReceiverClass receiver;

  MITK_TEST_CONDITION_REQUIRED(true, "Testing instantiation");

  receiver.RegisterObservers(sender);

  MITK_TEST_CONDITION_REQUIRED(true, "Testing registration to messages");

  MITK_TEST_CONDITION_REQUIRED((sender.DoWaveHand(), // This is called "comma operator". Don't ask, read!
                                receiver.HandWaved()),
                               "Message without parameters");
  receiver.Amnesia();

  MITK_TEST_CONDITION_REQUIRED((sender.DoShowFinger(), receiver.HandWaved()), "Message without parameters");
  receiver.Amnesia();

  MITK_TEST_CONDITION_REQUIRED((sender.DoSay("Blooodworsch"), receiver.WordsSaid() == "Blooodworsch"),
                               "Message with std::string parameter");
  receiver.Amnesia();

  MITK_TEST_CONDITION_REQUIRED((sender.DoWalk(2.67), (receiver.MetersWalked() - 2.67) < 0.0001),
                               "Message with double parameter");
  receiver.Amnesia();

  mitk::mitkMessageTestTestClass::Package package(8);
  MITK_TEST_CONDITION_REQUIRED((sender.DoGivePackage(package), receiver.PackageReceived() == package),
                               "Message with class parameter");
  receiver.Amnesia();

  MITK_TEST_CONDITION_REQUIRED(
    (sender.DoShoutAgeAndFootSize(46, 30.5), (receiver.Age() == 46 && (receiver.FootSize() - 30.5 < 0.0001))),
    "Message with int AND float parameter");
  receiver.Amnesia();

  mitk::mitkMessageTestTestClass::NewtonMachine newtonMachine;
  mitk::mitkMessageTestTestClass::Observer observer1(&newtonMachine);
  mitk::mitkMessageTestTestClass::Observer observer2(&newtonMachine);

  // This will send two events to registered observers
  newtonMachine.StartAnalysis();
  MITK_TEST_CONDITION(observer1.m_MachineStarted == true, "Message from Message Macro send to receiver 1");
  MITK_TEST_CONDITION(observer2.m_MachineStarted == true, "Message from Message Macro send to receiver 2");

  MITK_TEST_CONDITION(observer1.m_Law.GetDescription() == std::string("Unit tests are mandatory!"),
                      "Message1 from Message Macro send to receiver 1");
  MITK_TEST_CONDITION(observer2.m_Law.GetDescription() == std::string("Unit tests are mandatory!"),
                      "Message1 from Message Macro send to receiver 2");

  // This will send one event to registered observers
  newtonMachine.StopAnalysis();
  MITK_TEST_CONDITION(observer1.m_MachineStopped == true, "Message1 from Message Macro send to receiver 1");
  MITK_TEST_CONDITION(observer1.m_Error == true, "Message1 parameter from Message Macro send to receiver 1");

  MITK_TEST_CONDITION(observer2.m_MachineStopped == true, "Message1 from Message Macro send to receiver 2");
  MITK_TEST_CONDITION(observer2.m_Error == true, "Message1 parameter from Message Macro send to receiver 2");

  /* Message with return type tests are work in progess... */
  // bool patentSuccessful = newtonMachine.PatentLaw();   // what with return types from multiple observers?

  // MITK_TEST_CONDITION((observer1.m_PatentReviewed == true) && (patentSuccessful == false),
  //  "Message with return type from Message Macro send to receiver 1");
  //
  // MITK_TEST_CONDITION((observer2.m_PatentReviewed == true) && (patentSuccessful == false),
  //  "Message with return type from Message Macro send to receiver 2");

  MITK_TEST_END();
}
コード例 #30
0
 static void TestInstantiation()
 {
   mitk::LevelWindowManager::Pointer manager;
   manager = mitk::LevelWindowManager::New();
   MITK_TEST_CONDITION_REQUIRED(manager.IsNotNull(),"Testing mitk::LevelWindowManager::New()");
 }