00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ 00006 Version: $Revision: 7837 $ 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 //Poco headers 00019 #include "Poco/Path.h" 00020 00021 //mitk headers 00022 #include "mitkNavigationToolWriter.h" 00023 #include "mitkCommon.h" 00024 #include "mitkTestingMacros.h" 00025 #include "mitkStandardFileLocations.h" 00026 #include "mitkNavigationTool.h" 00027 #include "mitkSTLFileReader.h" 00028 #include "mitkBaseData.h" 00029 #include "mitkDataNode.h" 00030 #include "mitkSurface.h" 00031 #include "mitkStandaloneDataStorage.h" 00032 #include "mitkDataStorage.h" 00033 #include "mitkNavigationToolReader.h" 00034 00035 #include <sstream> 00036 00037 00038 class mitkNavigationToolReaderAndWriterTestClass 00039 { 00040 private: 00041 00042 static mitk::Surface::Pointer testSurface; 00043 00044 public: 00045 00046 static void TestInstantiation() 00047 { 00048 // let's create an object of our class 00049 mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); 00050 MITK_TEST_CONDITION_REQUIRED(myWriter.IsNotNull(),"Testing instantiation") 00051 } 00052 00053 static void TestWrite() 00054 { 00055 //create a NavigationTool which we can write on the harddisc 00056 std::string toolFileName = mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool", "Modules/IGT/Testing/Data"); 00057 MITK_TEST_CONDITION(toolFileName.empty() == false, "Check if tool calibration file exists"); 00058 mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); 00059 myNavigationTool->SetCalibrationFile(toolFileName); 00060 00061 mitk::DataNode::Pointer myNode = mitk::DataNode::New(); 00062 myNode->SetName("ClaronTool"); 00063 00064 //load an stl File 00065 mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); 00066 try 00067 { 00068 stlReader->SetFileName( mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool.stl", "Testing/Data/").c_str() ); 00069 stlReader->Update(); 00070 } 00071 catch (...) 00072 { 00073 MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); 00074 } 00075 00076 if ( stlReader->GetOutput() == NULL ) 00077 { 00078 MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); 00079 } 00080 else 00081 { 00082 testSurface = stlReader->GetOutput(); 00083 myNode->SetData(testSurface); 00084 } 00085 00086 myNavigationTool->SetDataNode(myNode); 00087 myNavigationTool->SetIdentifier("ClaronTool#1"); 00088 myNavigationTool->SetSerialNumber("0815"); 00089 myNavigationTool->SetTrackingDeviceType(mitk::ClaronMicron); 00090 myNavigationTool->SetType(mitk::NavigationTool::Fiducial); 00091 00092 //now create a writer and write it to the harddisc 00093 mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); 00094 std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool.tool"; 00095 00096 MITK_TEST_OUTPUT(<<"---- Testing navigation tool writer ----"); 00097 bool test = myWriter->DoWrite(filename,myNavigationTool); 00098 MITK_TEST_CONDITION_REQUIRED(test,"OK"); 00099 } 00100 00101 static void TestRead() 00102 { 00103 /* 00104 mitk::DataStorage::Pointer testStorage = mitk::StandaloneDataStorage::New(); TODO: DIESE STELLE UNTER LINUX ZUM LAUFEN BRINGEN 00105 mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(testStorage); 00106 mitk::NavigationTool::Pointer readTool = myReader->DoRead(mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool.tool"); 00107 MITK_TEST_OUTPUT(<<"---- Testing navigation tool reader ----"); 00108 MITK_TEST_CONDITION_REQUIRED(readTool->GetDataNode() == testStorage->GetNamedNode(readTool->GetDataNode()->GetName()),"Test if tool was added to storage..."); 00109 MITK_TEST_CONDITION_REQUIRED(readTool->GetDataNode()->GetData()==testSurface,"Test if surface was restored correctly ..."); 00110 */ 00111 //MITK_TEST_CONDITION_REQUIRED(); 00112 } 00113 00114 static void CleanUp() 00115 { 00116 std::remove((mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool.tool").c_str()); 00117 } 00118 00119 }; 00120 00121 mitk::Surface::Pointer mitkNavigationToolReaderAndWriterTestClass::testSurface = NULL; 00122 00124 int mitkNavigationToolReaderAndWriterTest(int /* argc */, char* /*argv*/[]) 00125 { 00126 MITK_TEST_BEGIN("NavigationToolWriter") 00127 00128 mitkNavigationToolReaderAndWriterTestClass::TestInstantiation(); 00129 mitkNavigationToolReaderAndWriterTestClass::TestWrite(); 00130 //mitkNavigationToolReaderAndWriterTestClass::TestRead(); 00131 mitkNavigationToolReaderAndWriterTestClass::CleanUp(); 00132 00133 00134 MITK_TEST_END() 00135 } 00136 00137