00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision: 16010 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkCameraVisualization.h" 00019 #include "mitkNavigationData.h" 00020 #include "mitkTestingMacros.h" 00021 #include "mitkVtkPropRenderer.h" 00022 #include "mitkGlobalInteraction.h" 00023 00024 #include <vtkRenderer.h> 00025 #include <vtkRenderWindow.h> 00026 00027 #include <time.h> 00028 00032 int mitkCameraVisualizationTest(int /* argc */, char* /*argv*/[]) 00033 { 00034 MITK_TEST_BEGIN("CameraVisualization") 00035 00036 // let's create an object of our class 00037 mitk::CameraVisualization::Pointer myFilter = mitk::CameraVisualization::New(); 00038 00039 // Global interaction must(!) be initialized if used 00040 mitk::GlobalInteraction::GetInstance()->Initialize("global"); 00041 00042 // first test: did this work? 00043 // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since 00044 // it makes no sense to continue without an object. 00045 MITK_TEST_CONDITION_REQUIRED(myFilter.IsNotNull(),"Testing instantiation"); 00046 00047 /* create helper objects: navigation data with position as origin, zero quaternion, zero error and data valid */ 00048 srand(time(NULL)); 00049 // generate a random position for the navigation data 00050 mitk::NavigationData::PositionType position; 00051 position[0] = rand()%1000; 00052 position[1] = rand()%1000; 00053 position[2] = rand()%1000; 00054 00055 // generate a random orientation for the navigation data 00056 mitk::NavigationData::OrientationType orientation; 00057 orientation[0] = (rand()%1000)/1000.0; 00058 orientation[1] = (rand()%1000)/1000.0; 00059 orientation[2] = (rand()%1000)/1000.0; 00060 orientation[3] = (rand()%1000)/1000.0; 00061 00062 // generate a random error for the navigation data 00063 mitk::ScalarType error = rand()%10; 00064 00065 // data valid flag of navigation data 00066 int val = rand()%2; 00067 bool valid(0); // this was uninitialized. how was this test ever meant to work?? 00068 if (val==0) 00069 { 00070 valid=false; 00071 } 00072 else if (val==1) 00073 { 00074 valid=true; 00075 } 00076 00077 // set parameters of navigation data 00078 mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New(); 00079 nd1->SetPosition(position); 00080 nd1->SetOrientation(orientation); 00081 nd1->SetPositionAccuracy(error); 00082 nd1->SetDataValid(valid); 00083 00084 // create renderer 00085 vtkRenderWindow* renderWindow = vtkRenderWindow::New(); 00086 mitk::VtkPropRenderer::Pointer renderer = mitk::VtkPropRenderer::New( "TestRenderer",renderWindow, mitk::RenderingManager::GetInstance() ); 00087 00088 myFilter->SetInput(nd1); 00089 MITK_TEST_CONDITION(myFilter->GetInput() == nd1, "Testing Set-/GetInput() input 1"); 00090 00091 // test for exception if renderer not set 00092 MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject) 00093 myFilter->Update(); 00094 MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject) 00095 00096 // set renderer 00097 myFilter->SetRenderer(renderer); 00098 00099 //Update filter 00100 myFilter->Update(); 00101 00102 //Delete renderWindow correctly 00103 renderWindow->Delete(); 00104 00105 // always end with this! 00106 MITK_TEST_END(); 00107 00108 } 00109 00110