diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationTool.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationTool.cpp index d1841f6fa4..aea800d59f 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationTool.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationTool.cpp @@ -1,43 +1,63 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkNavigationTool.h" +#include "Poco/File.h" mitk::NavigationTool::NavigationTool() { m_Type = mitk::NavigationTool::Unknown; m_Identifier = "None"; m_TrackingDeviceType = mitk::TrackingSystemNotSpecified; + m_CalibrationFile = "none"; + m_SerialNumber = ""; } mitk::NavigationTool::~NavigationTool() { + + } +void mitk::NavigationTool::SetCalibrationFile(const std::string filename) + { + //check if file does exist: + if (filename=="") + { + m_CalibrationFile = "none"; + } + else + { + Poco::File myFile(filename); + if (myFile.exists()) + m_CalibrationFile = filename; + else + m_CalibrationFile = "none"; + } } std::string mitk::NavigationTool::GetToolName() { if (this->m_DataNode.IsNull()) {return "";} else {return m_DataNode->GetName();} } mitk::Surface::Pointer mitk::NavigationTool::GetToolSurface() { if (this->m_DataNode.IsNull()) {return NULL;} else if (this->m_DataNode->GetData() == NULL) {return NULL;} else {return dynamic_cast(m_DataNode->GetData());} } \ No newline at end of file diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationTool.h b/Modules/IGT/IGTToolManagement/mitkNavigationTool.h index a70358f0e2..c1cbe5dd67 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationTool.h +++ b/Modules/IGT/IGTToolManagement/mitkNavigationTool.h @@ -1,123 +1,123 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-08-11 15:15:02 +0200 (Di, 11 Aug 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef NAVIGATIONTOOL_H_INCLUDED #define NAVIGATIONTOOL_H_INCLUDED //itk headers #include #include //mitk headers #include #include #include #include #include #include namespace mitk { /**Documentation * \brief An object of this class represents a navigation tool in the view of the software. * A few informations like an identifier, a toolname, a surface and a itk spatial * object are stored in such an object. The classes NavigationToolReader and * are availiable to write/read tools to/from the harddisc. If you need a collection * of navigation tools the class NavigationToolStorage could be used. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationTool : public itk::Object { public: mitkClassMacro(NavigationTool,itk::Object); itkNewMacro(Self); enum NavigationToolType {Instrument, Fiducial, Skinmarker, Unknown}; //## getter and setter ## //NavigationToolType: itkGetMacro(Type,NavigationToolType); itkSetMacro(Type,NavigationToolType); //Identifier: itkGetMacro(Identifier,std::string); itkSetMacro(Identifier,std::string); //Datatreenode: itkGetMacro(DataNode,mitk::DataNode::Pointer); itkSetMacro(DataNode,mitk::DataNode::Pointer); //SpatialObject: itkGetMacro(SpatialObject,itk::SpatialObject<3>::Pointer); itkSetMacro(SpatialObject,itk::SpatialObject<3>::Pointer); //TrackingTool: itkGetMacro(TrackingTool,mitk::TrackingTool::Pointer); itkSetMacro(TrackingTool,mitk::TrackingTool::Pointer); //CalibrationFile: itkGetMacro(CalibrationFile,std::string); - itkSetMacro(CalibrationFile,std::string); + void SetCalibrationFile(const std::string filename); //itkSetMacro(CalibrationFile,std::string); //SerialNumber: itkGetMacro(SerialNumber,std::string); itkSetMacro(SerialNumber,std::string); //TrackingDeviceType: itkGetMacro(TrackingDeviceType,mitk::TrackingDeviceType); itkSetMacro(TrackingDeviceType,mitk::TrackingDeviceType); //ToolName (only getter): /** @return Returns the name of this navigation tool. Returns an empty string if there is * no name (for example because the data node has not been set yet). * * Note: There is no setter for the name, * because the name of the corresponding data node is used as tool name. So if you * want to modify the name of this navigation tool only get the data node and modify * its name. */ std::string GetToolName(); //ToolSurface (only getter): /** @return Returns the surface of this navigation tool. Returns NULL if there is * no surface (for example because the data node has not been set yet). * * Note: There is no setter for the surface, * because the surface is the data of the corresponding data node. So if you * want to set a new surface only get the data node and modify its data. */ mitk::Surface::Pointer GetToolSurface(); //####################### protected: NavigationTool(); ~NavigationTool(); //## data structure of a navigation tool object ## std::string m_Identifier; NavigationToolType m_Type; /** @brief This DataNode holds a toolname and a tool surface */ mitk::DataNode::Pointer m_DataNode; /** @brief This member variable holds a mathamatical description of the tool */ itk::SpatialObject<3>::Pointer m_SpatialObject; /** @brief This member variable holds a pointer to the corresponding tracking tool in the hardware. */ mitk::TrackingTool::Pointer m_TrackingTool; /** @brief The path to the calibration file of the tool. */ std::string m_CalibrationFile; /** @brief A unique serial number of the tool which is needed to identify the tool correctly. This is very important * in case of the NDI Aurora System. */ std::string m_SerialNumber; /** @brief This member holds the tracking device type of the tool. */ mitk::TrackingDeviceType m_TrackingDeviceType; //################################################# }; } // namespace mitk #endif //NAVIGATIONTOOL \ No newline at end of file diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp index be1c159c84..08f16eede0 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp @@ -1,121 +1,128 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //Poco headers #include "Poco/Zip/Decompress.h" #include "Poco/Path.h" //mitk headers #include "mitkNavigationToolReader.h" #include "mitkTrackingTypes.h" #include #include mitk::NavigationToolReader::NavigationToolReader(mitk::DataStorage::Pointer dataStorage) { m_DataStorage = dataStorage; } mitk::NavigationToolReader::~NavigationToolReader() { } mitk::NavigationTool::Pointer mitk::NavigationToolReader::DoRead(std::string filename) { //decompress all files into a temporary directory std::ifstream file( filename.c_str(), std::ios::binary ); if (!file.good()) { m_ErrorMessage = "Cannot open '" + filename + "' for reading"; return NULL; } - std::string tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "\\" +GetFileWithoutPath(filename); + std::string tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + "toolFilesByNavigationToolReader" + Poco::Path::separator() + GetFileWithoutPath(filename); Poco::Zip::Decompress unzipper( file, Poco::Path( tempDirectory ) ); unzipper.decompressAllFiles(); //use SceneSerialization to load the DataStorage mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New(); mitk::DataStorage::Pointer loadedStorage = mySceneIO->LoadScene(tempDirectory + Poco::Path::separator() + GetFileWithoutPath(filename) + ".storage"); if (loadedStorage->GetAll()->size()==0 || loadedStorage.IsNull()) { m_ErrorMessage = "Invalid file: cannot parse tool data."; return NULL; } //convert the DataStorage back to a NavigationTool-Object mitk::DataNode::Pointer myNode = loadedStorage->GetAll()->ElementAt(0); mitk::NavigationTool::Pointer returnValue = ConvertDataNodeToNavigationTool(myNode, tempDirectory); //delete the data-storage file which is not needed any more. The toolfile must be left in the temporary directory becauses it is linked in the datatreenode of the tool std::remove((std::string(tempDirectory + Poco::Path::separator() + GetFileWithoutPath(filename) + ".storage")).c_str()); return returnValue; } mitk::NavigationTool::Pointer mitk::NavigationToolReader::ConvertDataNodeToNavigationTool(mitk::DataNode::Pointer node, std::string toolPath) { mitk::NavigationTool::Pointer returnValue = mitk::NavigationTool::New(); //DateTreeNode with Name and Surface mitk::DataNode::Pointer newNode = mitk::DataNode::New(); newNode->SetName(node->GetName()); newNode->SetData(node->GetData()); m_DataStorage->Add(newNode); returnValue->SetDataNode(newNode); //Identifier std::string identifier; node->GetStringProperty("identifier",identifier); returnValue->SetIdentifier(identifier); //Serial Number std::string serial; node->GetStringProperty("serial number",serial); returnValue->SetSerialNumber(serial); //Tracking Device int device_type; node->GetIntProperty("tracking device type",device_type); returnValue->SetTrackingDeviceType(static_cast(device_type)); //Tool Type int type; node->GetIntProperty("tracking tool type",type); returnValue->SetType(static_cast(type)); //Calibration File Name std::string calibration_filename; node->GetStringProperty("toolfileName",calibration_filename); - std::string calibration_filename_with_path = toolPath + Poco::Path::separator() + calibration_filename; - returnValue->SetCalibrationFile(calibration_filename_with_path); + if (calibration_filename=="none") + { + returnValue->SetCalibrationFile("none"); + } + else + { + std::string calibration_filename_with_path = toolPath + Poco::Path::separator() + calibration_filename; + returnValue->SetCalibrationFile(calibration_filename_with_path); + } return returnValue; } std::string mitk::NavigationToolReader::GetFileWithoutPath(std::string FileWithPath) { std::string returnValue = ""; returnValue = FileWithPath.substr(FileWithPath.rfind("/")+1, FileWithPath.length()); //dirty hack: Windows path seperators if (returnValue.size() == FileWithPath.size()) returnValue = FileWithPath.substr(FileWithPath.rfind("\\")+1, FileWithPath.length()); return returnValue; } \ No newline at end of file diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp index ec81ddefdd..11cb5aa1b8 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp @@ -1,71 +1,86 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //Poco headers #include "Poco/Zip/Decompress.h" #include "Poco/Path.h" +#include "Poco/File.h" #include "mitkNavigationToolStorageDeserializer.h" #include #include #include "mitkNavigationToolReader.h" mitk::NavigationToolStorageDeserializer::NavigationToolStorageDeserializer(mitk::DataStorage::Pointer dataStorage) { m_DataStorage = dataStorage; + //create temp directory for this reader + m_tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + "tempNavigationToolDeserializer"; + Poco::File myFile(m_tempDirectory); + myFile.createDirectory(); } mitk::NavigationToolStorageDeserializer::~NavigationToolStorageDeserializer() { - + //remove temp directory + Poco::File myFile(m_tempDirectory); + if (myFile.exists()) myFile.remove(); } mitk::NavigationToolStorage::Pointer mitk::NavigationToolStorageDeserializer::Deserialize(std::string filename) { //decomress zip file into temporary directory - std::ifstream file( filename.c_str(), std::ios::binary ); - if (!file.good()) + decomressFiles(filename,m_tempDirectory); + + //now read all files and convert them to navigation tools + mitk::NavigationToolStorage::Pointer returnValue = mitk::NavigationToolStorage::New(); + bool cont = true; + for (int i=0; cont==true; i++) { - m_ErrorMessage = "Cannot open '" + filename + "' for reading"; - return NULL; + std::string fileName = m_tempDirectory + Poco::Path::separator() + "NavigationTool" + convertIntToString(i) + ".tool"; + mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(m_DataStorage); + mitk::NavigationTool::Pointer readTool = myReader->DoRead(fileName); + if (readTool.IsNull()) cont = false; + else returnValue->AddTool(readTool); + //delete file + std::remove(fileName.c_str()); } - mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(m_DataStorage); - std::string tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + myReader->GetFileWithoutPath(filename); - Poco::Zip::Decompress unzipper( file, Poco::Path( tempDirectory ) ); - unzipper.decompressAllFiles(); - + return returnValue; + } - //create DataNodes using the decomressed storage - mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New(); - mitk::DataStorage::Pointer readStorage = mySceneIO->LoadScene(tempDirectory + Poco::Path::separator() + myReader->GetFileWithoutPath(filename) + ".storage"); - mitk::NavigationToolStorage::Pointer returnValue = mitk::NavigationToolStorage::New(); +std::string mitk::NavigationToolStorageDeserializer::convertIntToString(int i) + { + std::string s; + std::stringstream out; + out << i; + s = out.str(); + return s; + } - for(unsigned int i=0; iGetAll()->Size(); i++) +bool mitk::NavigationToolStorageDeserializer::decomressFiles(std::string filename,std::string path) + { + std::ifstream file( filename.c_str(), std::ios::binary ); + if (!file.good()) { - mitk::NavigationTool::Pointer newTool = myReader->ConvertDataNodeToNavigationTool(readStorage->GetAll()->ElementAt(i),tempDirectory); - if (!returnValue->AddTool(newTool)) - { - m_ErrorMessage = "Error can't parse data storage!"; - return NULL; - } + m_ErrorMessage = "Cannot open '" + filename + "' for reading"; + return false; } - - //delete decompressed storage which is not needed any more - std::remove((std::string(tempDirectory + Poco::Path::separator() + myReader->GetFileWithoutPath(filename) + ".storage")).c_str()); - - return returnValue; + Poco::Zip::Decompress unzipper( file, Poco::Path( path ) ); + unzipper.decompressAllFiles(); + file.close(); + return true; } diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.h b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.h index f3dd1bf01b..2b43439239 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.h +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.h @@ -1,63 +1,69 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-08-11 15:15:02 +0200 (Di, 11 Aug 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef NAVIGATIONTOOLSTORAGEDESERIALIZER_H_INCLUDED #define NAVIGATIONTOOLSTORAGEDESERIALIZER_H_INCLUDED //itk headers #include //mitk headers #include #include #include "mitkNavigationToolStorage.h" #include namespace mitk { /**Documentation * \brief This class offers methods to load an object of the class NavigationToolStorage * from the harddisc. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationToolStorageDeserializer : public itk::Object { public: mitkClassMacro(NavigationToolStorageDeserializer,itk::Object); mitkNewMacro1Param(Self,mitk::DataStorage::Pointer); /** * @brief Loads a collection of navigation tools represented by a mitk::NavigationToolStorage * from a file. * @return Returns the storage which was loaded or NULL if there was an error in the loading process. * */ mitk::NavigationToolStorage::Pointer Deserialize(std::string filename); itkGetMacro(ErrorMessage,std::string); protected: NavigationToolStorageDeserializer(mitk::DataStorage::Pointer dataStorage); ~NavigationToolStorageDeserializer(); std::string m_ErrorMessage; mitk::DataStorage::Pointer m_DataStorage; + std::string m_tempDirectory; + + std::string convertIntToString(int i); + + bool decomressFiles(std::string file,std::string path); + }; } // namespace mitk #endif //NAVIGATIONTOOLSTORAGEDESERIALIZER \ No newline at end of file diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.cpp index d04860f2af..286ff52d79 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.cpp @@ -1,78 +1,84 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //Poco headers #include "Poco/Zip/Compress.h" +#include "Poco/Path.h" +#include "Poco/File.h" #include "mitkNavigationToolStorageSerializer.h" #include "mitkNavigationToolWriter.h" #include #include #include +#include + mitk::NavigationToolStorageSerializer::NavigationToolStorageSerializer() { - + //create temp directory + m_tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + "tempNavigationToolSerializer"; + Poco::File myFile(m_tempDirectory); + myFile.createDirectory(); } mitk::NavigationToolStorageSerializer::~NavigationToolStorageSerializer() { - + //remove temp directory + Poco::File myFile(m_tempDirectory); + if (myFile.exists()) myFile.remove(); } bool mitk::NavigationToolStorageSerializer::Serialize(std::string filename, mitk::NavigationToolStorage::Pointer storage) { - //convert whole data to a mitk::DataStorage - mitk::StandaloneDataStorage::Pointer saveStorage = mitk::StandaloneDataStorage::New(); + //save every tool to temp directory mitk::NavigationToolWriter::Pointer myToolWriter = mitk::NavigationToolWriter::New(); - for(int i=0; iGetToolCount();i++) - { - mitk::DataNode::Pointer thisTool = myToolWriter->ConvertToDataNode(storage->GetTool(i)); - saveStorage->Add(thisTool); + { + std::string fileName = m_tempDirectory + Poco::Path::separator() + "NavigationTool" + convertIntToString(i) + ".tool"; + if (!myToolWriter->DoWrite(fileName,storage->GetTool(i))) return false; } - //use SceneSerialization to save the DataStorage - std::string DataStorageFileName = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + myToolWriter->GetFileWithoutPath(filename) + ".storage"; - mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New(); - mySceneIO->SaveScene(saveStorage->GetAll(),saveStorage,DataStorageFileName); - - //then put the storage and the toolfiles into a zip-archive + //add all files to zip archive std::ofstream file( filename.c_str(), std::ios::binary | std::ios::out); if (!file.good()) { m_ErrorMessage = "Could not open a zip file for writing: '" + filename + "'"; return false; } - else - { - Poco::Zip::Compress zipper( file, true ); - zipper.addFile(DataStorageFileName,myToolWriter->GetFileWithoutPath(DataStorageFileName)); - for (int i=0; iGetToolCount();i++) + Poco::Zip::Compress zipper( file, true ); + for (int i=0; iGetToolCount();i++) { - //check if filename already exits - for (int j=0; jGetFileWithoutPath(storage->GetTool(i)->GetCalibrationFile()) == myToolWriter->GetFileWithoutPath(storage->GetTool(j)->GetCalibrationFile())) break; - - //add calibration file to zip archive - std::string calibrationFile = storage->GetTool(i)->GetCalibrationFile(); - if (calibrationFile!="") zipper.addFile(calibrationFile,myToolWriter->GetFileWithoutPath(storage->GetTool(i)->GetCalibrationFile())); + std::string fileName = m_tempDirectory + Poco::Path::separator() + "NavigationTool" + convertIntToString(i) + ".tool"; + zipper.addFile(fileName,myToolWriter->GetFileWithoutPath(fileName)); + //delete file: + std::remove(fileName.c_str()); } - zipper.close(); - } - + zipper.close(); + file.close(); + return true; + } + +std::string mitk::NavigationToolStorageSerializer::convertIntToString(int i) + { + std::string s; + std::stringstream out; + out << i; + s = out.str(); + return s; } \ No newline at end of file diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.h b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.h index 325a2a5b22..26690e6b42 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.h +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorageSerializer.h @@ -1,59 +1,63 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-08-11 15:15:02 +0200 (Di, 11 Aug 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef NAVIGATIONTOOLSTORAGESERIALIZER_H_INCLUDED #define NAVIGATIONTOOLSTORAGESERIALIZER_H_INCLUDED //itk headers #include //mitk headers #include #include "mitkNavigationToolStorage.h" #include namespace mitk { /**Documentation * \brief This class offers methods to save an object of the class NavigationToolStorage * to the harddisc. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationToolStorageSerializer : public itk::Object { public: mitkClassMacro(NavigationToolStorageSerializer,itk::Object); itkNewMacro(Self); /** * @brief Saves a mitk navigation tool storage to a file. * @return Returns true if the file was saved successfully. False if not. */ bool Serialize(std::string filename, mitk::NavigationToolStorage::Pointer storage); itkGetMacro(ErrorMessage,std::string); protected: NavigationToolStorageSerializer(); ~NavigationToolStorageSerializer(); std::string m_ErrorMessage; + std::string convertIntToString(int i); + + std::string m_tempDirectory; + }; } // namespace mitk #endif //NAVIGATIONTOOLSTORAGESERIALIZER \ No newline at end of file diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolWriter.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationToolWriter.cpp index 54ba68d60b..f2134fdff5 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolWriter.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolWriter.cpp @@ -1,104 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ Version: $Revision $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //Poco headers #include "Poco/Zip/Compress.h" #include "Poco/Path.h" //mitk headers #include "mitkNavigationToolWriter.h" #include #include #include #include //std headers #include mitk::NavigationToolWriter::NavigationToolWriter() { } mitk::NavigationToolWriter::~NavigationToolWriter() { } bool mitk::NavigationToolWriter::DoWrite(std::string FileName,mitk::NavigationTool::Pointer Tool) { //convert whole data to a mitk::DataStorage mitk::StandaloneDataStorage::Pointer saveStorage = mitk::StandaloneDataStorage::New(); mitk::DataNode::Pointer thisTool = ConvertToDataNode(Tool); saveStorage->Add(thisTool); //use SceneSerialization to save the DataStorage std::string DataStorageFileName = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + GetFileWithoutPath(FileName) + ".storage"; mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New(); mySceneIO->SaveScene(saveStorage->GetAll(),saveStorage,DataStorageFileName); //now put the DataStorage and the Toolfile in a ZIP-file std::ofstream file( FileName.c_str(), std::ios::binary | std::ios::out); if (!file.good()) { m_ErrorMessage = "Could not open a zip file for writing: '" + FileName + "'"; return false; } else { Poco::Zip::Compress zipper( file, true ); zipper.addFile(DataStorageFileName,GetFileWithoutPath(DataStorageFileName)); - zipper.addFile(Tool->GetCalibrationFile(),GetFileWithoutPath(Tool->GetCalibrationFile())); + if (Tool->GetCalibrationFile()!="none") zipper.addFile(Tool->GetCalibrationFile(),GetFileWithoutPath(Tool->GetCalibrationFile())); zipper.close(); } + + //delete the data storage + std::remove(DataStorageFileName.c_str()); return true; } mitk::DataNode::Pointer mitk::NavigationToolWriter::ConvertToDataNode(mitk::NavigationTool::Pointer Tool) { mitk::DataNode::Pointer thisTool = mitk::DataNode::New(); //Name if (Tool->GetDataNode().IsNull()) thisTool->SetName("none"); else thisTool->SetName(Tool->GetDataNode()->GetName().c_str()); //Identifier thisTool->AddProperty("identifier",mitk::StringProperty::New(Tool->GetIdentifier().c_str())); //Serial Number thisTool->AddProperty("serial number",mitk::StringProperty::New(Tool->GetSerialNumber().c_str())); //Tracking Device thisTool->AddProperty("tracking device type",mitk::IntProperty::New(Tool->GetTrackingDeviceType())); //Tool Type thisTool->AddProperty("tracking tool type",mitk::IntProperty::New(Tool->GetType())); //Calibration File Name thisTool->AddProperty("toolfileName",mitk::StringProperty::New(GetFileWithoutPath(Tool->GetCalibrationFile()))); //Surface if (Tool->GetDataNode().IsNotNull()) if (Tool->GetDataNode()->GetData()!=NULL) thisTool->SetData(Tool->GetDataNode()->GetData()); //Material is not needed, to avoid errors in scene serialization we have to do this: - //thisTool->ReplaceProperty("material",NULL); + thisTool->ReplaceProperty("material",NULL); return thisTool; } std::string mitk::NavigationToolWriter::GetFileWithoutPath(std::string FileWithPath) { std::string returnValue = ""; returnValue = FileWithPath.substr(FileWithPath.rfind("/")+1, FileWithPath.length()); //dirty hack: Windows path seperators if (returnValue.size() == FileWithPath.size()) returnValue = FileWithPath.substr(FileWithPath.rfind("\\")+1, FileWithPath.length()); return returnValue; } diff --git a/Modules/IGT/Testing/mitkNavigationToolReaderAndWriterTest.cpp b/Modules/IGT/Testing/mitkNavigationToolReaderAndWriterTest.cpp index 8741b8436e..075dd94e3a 100644 --- a/Modules/IGT/Testing/mitkNavigationToolReaderAndWriterTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationToolReaderAndWriterTest.cpp @@ -1,138 +1,223 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ Version: $Revision: 7837 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //Poco headers #include "Poco/Path.h" //mitk headers #include "mitkNavigationToolWriter.h" #include "mitkCommon.h" #include "mitkTestingMacros.h" #include "mitkStandardFileLocations.h" #include "mitkNavigationTool.h" #include "mitkSTLFileReader.h" #include "mitkBaseData.h" #include "mitkDataNode.h" #include "mitkSurface.h" #include "mitkStandaloneDataStorage.h" #include "mitkDataStorage.h" #include "mitkNavigationToolReader.h" #include +#include class mitkNavigationToolReaderAndWriterTestClass { private: static mitk::Surface::Pointer testSurface; public: static void TestInstantiation() { // let's create an object of our class mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); MITK_TEST_CONDITION_REQUIRED(myWriter.IsNotNull(),"Testing instantiation") } static void TestWrite() { + //testcase with first test tool: a claron tool + //create a NavigationTool which we can write on the harddisc std::string toolFileName = mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool", "Modules/IGT/Testing/Data"); - MITK_TEST_CONDITION(toolFileName.empty() == false, "Check if tool calibration file exists"); + MITK_TEST_CONDITION(toolFileName.empty() == false, "Check if tool calibration of claron tool file exists"); mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); myNavigationTool->SetCalibrationFile(toolFileName); mitk::DataNode::Pointer myNode = mitk::DataNode::New(); myNode->SetName("ClaronTool"); - //load an stl File - mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); - try - { - stlReader->SetFileName( mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool.stl", "Testing/Data/").c_str() ); - stlReader->Update(); - } - catch (...) - { - MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); - } - - if ( stlReader->GetOutput() == NULL ) - { - MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); - } - else - { - testSurface = stlReader->GetOutput(); - myNode->SetData(testSurface); - } + //load an stl File + mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); + try + { + stlReader->SetFileName( mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool.stl", "Testing/Data/").c_str() ); + stlReader->Update(); + } + catch (...) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + + if ( stlReader->GetOutput() == NULL ) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + else + { + testSurface = stlReader->GetOutput(); + myNode->SetData(testSurface); + } myNavigationTool->SetDataNode(myNode); myNavigationTool->SetIdentifier("ClaronTool#1"); myNavigationTool->SetSerialNumber("0815"); myNavigationTool->SetTrackingDeviceType(mitk::ClaronMicron); myNavigationTool->SetType(mitk::NavigationTool::Fiducial); //now create a writer and write it to the harddisc mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool.tool"; - MITK_TEST_OUTPUT(<<"---- Testing navigation tool writer ----"); + MITK_TEST_OUTPUT(<<"---- Testing navigation tool writer with first test tool (claron tool) ----"); bool test = myWriter->DoWrite(filename,myNavigationTool); MITK_TEST_CONDITION_REQUIRED(test,"OK"); } static void TestRead() { mitk::DataStorage::Pointer testStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(testStorage); mitk::NavigationTool::Pointer readTool = myReader->DoRead(mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool.tool"); - MITK_TEST_OUTPUT(<<"---- Testing navigation tool reader ----"); + MITK_TEST_OUTPUT(<<"---- Testing navigation tool reader with first test tool (claron tool) ----"); //Test if there was created a new tool MITK_TEST_CONDITION_REQUIRED(readTool->GetDataNode() == testStorage->GetNamedNode(readTool->GetDataNode()->GetName()),"Test if tool was added to storage..."); //Test if the surfaces do have the same number of vertexes (it would be better to test for real equality of the surfaces!) MITK_TEST_CONDITION_REQUIRED(dynamic_cast(readTool->GetDataNode()->GetData())->GetSizeOfPolyDataSeries()==testSurface->GetSizeOfPolyDataSeries(),"Test if surface was restored correctly ..."); + + MITK_TEST_CONDITION_REQUIRED(readTool->GetType()==mitk::NavigationTool::Fiducial,"Testing Tool Type"); + + MITK_TEST_CONDITION_REQUIRED(readTool->GetTrackingDeviceType()==mitk::ClaronMicron,"Testing Tracking Device Type"); + + MITK_TEST_CONDITION_REQUIRED(readTool->GetSerialNumber()=="0815","Testing Serial Number"); + + std::ifstream TestFile(readTool->GetCalibrationFile().c_str()); + MITK_TEST_CONDITION_REQUIRED(TestFile,"Testing If Calibration File Exists"); + + } + + static void TestWrite2() + { + //testcase with second test tool: an aurora tool + //create a NavigationTool which we can write on the harddisc + mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); + + mitk::DataNode::Pointer myNode = mitk::DataNode::New(); + myNode->SetName("AuroraTool"); + + //load an stl File + mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); + try + { + stlReader->SetFileName( mitk::StandardFileLocations::GetInstance()->FindFile("EMTool.stl", "Testing/Data/").c_str() ); + stlReader->Update(); + } + catch (...) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + + if ( stlReader->GetOutput() == NULL ) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + else + { + testSurface = stlReader->GetOutput(); + myNode->SetData(testSurface); + } + + myNavigationTool->SetDataNode(myNode); + myNavigationTool->SetIdentifier("AuroraTool#1"); + myNavigationTool->SetSerialNumber("0816"); + myNavigationTool->SetTrackingDeviceType(mitk::NDIAurora); + myNavigationTool->SetType(mitk::NavigationTool::Instrument); + + //now create a writer and write it to the harddisc + mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); + std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool2.tool"; + + MITK_TEST_OUTPUT(<<"---- Testing navigation tool writer with second tool (aurora tool) ----"); + bool test = myWriter->DoWrite(filename,myNavigationTool); + MITK_TEST_CONDITION_REQUIRED(test,"OK"); + } + + static void TestRead2() + { + mitk::DataStorage::Pointer testStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); + mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(testStorage); + mitk::NavigationTool::Pointer readTool = myReader->DoRead(mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool2.tool"); + MITK_TEST_OUTPUT(<<"---- Testing navigation tool reader with second tool (aurora tool) ----"); + + //Test if there was created a new tool + MITK_TEST_CONDITION_REQUIRED(readTool->GetDataNode() == testStorage->GetNamedNode(readTool->GetDataNode()->GetName()),"Test if tool was added to storage..."); + + //Test if the surfaces do have the same number of vertexes (it would be better to test for real equality of the surfaces!) + MITK_TEST_CONDITION_REQUIRED(dynamic_cast(readTool->GetDataNode()->GetData())->GetSizeOfPolyDataSeries()==testSurface->GetSizeOfPolyDataSeries(),"Test if surface was restored correctly ..."); + + //Test if the tool type is the same + MITK_TEST_CONDITION_REQUIRED(readTool->GetType()==mitk::NavigationTool::Instrument,"Testing Tool Type"); + + MITK_TEST_CONDITION_REQUIRED(readTool->GetTrackingDeviceType()==mitk::NDIAurora,"Testing Tracking Device Type"); + + MITK_TEST_CONDITION_REQUIRED(readTool->GetSerialNumber()=="0816","Testing Serial Number"); + + MITK_TEST_CONDITION_REQUIRED(readTool->GetCalibrationFile()=="none","Testing Calibration File"); + } static void CleanUp() { std::remove((mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool.tool").c_str()); + std::remove((mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestTool2.tool").c_str()); } }; mitk::Surface::Pointer mitkNavigationToolReaderAndWriterTestClass::testSurface = NULL; /** This function is testing the TrackingVolume class. */ int mitkNavigationToolReaderAndWriterTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationToolWriter") mitkNavigationToolReaderAndWriterTestClass::TestInstantiation(); mitkNavigationToolReaderAndWriterTestClass::TestWrite(); mitkNavigationToolReaderAndWriterTestClass::TestRead(); + mitkNavigationToolReaderAndWriterTestClass::TestWrite2(); + mitkNavigationToolReaderAndWriterTestClass::TestRead2(); mitkNavigationToolReaderAndWriterTestClass::CleanUp(); - MITK_TEST_END() } diff --git a/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerTest.cpp b/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerTest.cpp index 0f24925226..d509e1d162 100644 --- a/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerTest.cpp @@ -1,110 +1,216 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ Version: $Revision: 7837 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //Poco headers #include "Poco/Path.h" #include #include #include #include #include #include +#include + +#include "mitkNavigationToolStorage.h" class NavigationToolStorageSerializerAndDeserializerTestClass { public: static void TestInstantiation() { // let's create objects of our classes mitk::NavigationToolStorageSerializer::Pointer testSerializer = mitk::NavigationToolStorageSerializer::New(); MITK_TEST_CONDITION_REQUIRED(testSerializer.IsNotNull(),"Testing instantiation of NavigationToolStorageSerializer") mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! mitk::NavigationToolStorageDeserializer::Pointer testDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); MITK_TEST_CONDITION_REQUIRED(testDeserializer.IsNotNull(),"Testing instantiation of NavigationToolStorageDeserializer") } static void TestWriteSimpleToolStorage() { //create Tool Storage mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); //first tool mitk::NavigationTool::Pointer myTool1 = mitk::NavigationTool::New(); myTool1->SetIdentifier("001"); myStorage->AddTool(myTool1); //second tool mitk::NavigationTool::Pointer myTool2 = mitk::NavigationTool::New(); myTool2->SetIdentifier("002"); myStorage->AddTool(myTool2); //third tool mitk::NavigationTool::Pointer myTool3 = mitk::NavigationTool::New(); myTool3->SetIdentifier("003"); myStorage->AddTool(myTool3); //create Serializer mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); //create filename std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestStorage.storage"; //test serialization bool success = mySerializer->Serialize(filename,myStorage); - MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of tool storage"); + MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of simple tool storage"); } static void TestReadSimpleToolStorage() { mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestStorage.storage"); - MITK_TEST_CONDITION_REQUIRED(readStorage.IsNotNull(),"Testing deserialization of tool storage"); - MITK_TEST_CONDITION_REQUIRED(readStorage->GetToolCount()==3,"Testing number of tools in storage"); + MITK_TEST_CONDITION_REQUIRED(readStorage.IsNotNull(),"Testing deserialization of simple tool storage"); + MITK_TEST_CONDITION_REQUIRED(readStorage->GetToolCount()==3," ..Testing number of tools in storage"); //TODO: why is the order of tools changed is save/load process?? bool foundtool1 = false; bool foundtool2 = false; bool foundtool3 = false; for(int i=0; i<3; i++) { if ((readStorage->GetTool(i)->GetIdentifier()=="001")) foundtool1 = true; else if ((readStorage->GetTool(i)->GetIdentifier()=="002")) foundtool2 = true; else if ((readStorage->GetTool(i)->GetIdentifier()=="003")) foundtool3 = true; } - MITK_TEST_CONDITION_REQUIRED(foundtool1&&foundtool2&&foundtool3,"Testing if identifiers of tools where saved / loaded successfully"); + MITK_TEST_CONDITION_REQUIRED(foundtool1&&foundtool2&&foundtool3," ..Testing if identifiers of tools where saved / loaded successfully"); } static void CleanUp() { std::remove((mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestStorage.storage").c_str()); + std::remove((mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestStorage2.storage").c_str()); + } + + static void TestWriteComplexToolStorage() + { + + //create first tool + mitk::Surface::Pointer testSurface; + std::string toolFileName = mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool", "Modules/IGT/Testing/Data"); + MITK_TEST_CONDITION(toolFileName.empty() == false, "Check if tool calibration of claron tool file exists"); + mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); + myNavigationTool->SetCalibrationFile(toolFileName); + + mitk::DataNode::Pointer myNode = mitk::DataNode::New(); + myNode->SetName("ClaronTool"); + + //load an stl File + mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); + try + { + stlReader->SetFileName( mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool.stl", "Testing/Data/").c_str() ); + stlReader->Update(); + } + catch (...) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + + if ( stlReader->GetOutput() == NULL ) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + else + { + testSurface = stlReader->GetOutput(); + myNode->SetData(testSurface); + } + + myNavigationTool->SetDataNode(myNode); + myNavigationTool->SetIdentifier("ClaronTool#1"); + myNavigationTool->SetSerialNumber("0815"); + myNavigationTool->SetTrackingDeviceType(mitk::ClaronMicron); + myNavigationTool->SetType(mitk::NavigationTool::Fiducial); + + //create second tool + mitk::NavigationTool::Pointer myNavigationTool2 = mitk::NavigationTool::New(); + mitk::Surface::Pointer testSurface2; + + mitk::DataNode::Pointer myNode2 = mitk::DataNode::New(); + myNode2->SetName("AuroraTool"); + + //load an stl File + try + { + stlReader->SetFileName( mitk::StandardFileLocations::GetInstance()->FindFile("EMTool.stl", "Testing/Data/").c_str() ); + stlReader->Update(); + } + catch (...) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + + if ( stlReader->GetOutput() == NULL ) + { + MITK_TEST_FAILED_MSG(<<"Cannot read stl file."); + } + else + { + testSurface2 = stlReader->GetOutput(); + myNode2->SetData(testSurface2); + } + + myNavigationTool2->SetDataNode(myNode2); + myNavigationTool2->SetIdentifier("AuroraTool#1"); + myNavigationTool2->SetSerialNumber("0816"); + myNavigationTool2->SetTrackingDeviceType(mitk::NDIAurora); + myNavigationTool2->SetType(mitk::NavigationTool::Instrument); + + //create navigation tool storage + mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); + myStorage->AddTool(myNavigationTool); + myStorage->AddTool(myNavigationTool2); + + //create Serializer + mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); + + //create filename + std::string filename = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestStorage2.storage"; + + //test serialization + bool success = mySerializer->Serialize(filename,myStorage); + MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of complex tool storage"); + + } + + static void TestReadComplexToolStorage() + { + mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! + mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); + mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(mitk::StandardFileLocations::GetInstance()->GetOptionDirectory()+Poco::Path::separator()+".."+Poco::Path::separator()+"TestStorage2.storage"); + MITK_TEST_CONDITION_REQUIRED(readStorage.IsNotNull(),"Testing deserialization of complex tool storage"); + MITK_TEST_CONDITION_REQUIRED(readStorage->GetToolCount()==2," ..Testing number of tools in storage"); } }; /** This function is testing the TrackingVolume class. */ int mitkNavigationToolStorageSerializerAndDeserializerTest(int /* argc */, char* /*argv*/[]) { - MITK_TEST_BEGIN("NavigationToolStorageSerializerAndDeserializer") + MITK_TEST_BEGIN("NavigationToolStorageSerializerAndDeserializer"); NavigationToolStorageSerializerAndDeserializerTestClass::TestInstantiation(); NavigationToolStorageSerializerAndDeserializerTestClass::TestWriteSimpleToolStorage(); NavigationToolStorageSerializerAndDeserializerTestClass::TestReadSimpleToolStorage(); + NavigationToolStorageSerializerAndDeserializerTestClass::TestWriteComplexToolStorage(); + NavigationToolStorageSerializerAndDeserializerTestClass::TestReadComplexToolStorage(); NavigationToolStorageSerializerAndDeserializerTestClass::CleanUp(); - - MITK_TEST_END() + MITK_TEST_END(); } diff --git a/Modules/IGT/Testing/mitkNavigationToolTest.cpp b/Modules/IGT/Testing/mitkNavigationToolTest.cpp index 2e6c5e2d59..44da32d256 100644 --- a/Modules/IGT/Testing/mitkNavigationToolTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationToolTest.cpp @@ -1,80 +1,80 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ Version: $Revision: 7837 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkNavigationTool.h" #include "mitkCommon.h" #include "mitkTestingMacros.h" #include "mitkDataNode.h" #include "mitkTrackingTool.h" #include class mitkNavigationToolTestClass { public: static void TestInstantiation() { // let's create an object of our class mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); MITK_TEST_CONDITION_REQUIRED(myNavigationTool.IsNotNull(),"Testing instantiation") } static void TestGetterAndSetter() { mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); //initialize a few things mitk::DataNode::Pointer myNode = mitk::DataNode::New(); myNode->SetName("TestNodeName"); itk::SpatialObject<3>::Pointer mySpatialObject = itk::SpatialObject<3>::New(); //set everything myNavigationTool->SetType(mitk::NavigationTool::Instrument); myNavigationTool->SetIdentifier("Tool#15"); myNavigationTool->SetDataNode(myNode); myNavigationTool->SetSpatialObject(mySpatialObject); //notice: cannot test Get/SetTrackingTool because this class cannot be instantiated alone myNavigationTool->SetCalibrationFile("Test.srom"); myNavigationTool->SetSerialNumber("0815"); myNavigationTool->SetTrackingDeviceType(mitk::NDIAurora); //test getter MITK_TEST_CONDITION(myNavigationTool->GetType()==mitk::NavigationTool::Instrument,"Testing getter and setter of type."); MITK_TEST_CONDITION(myNavigationTool->GetIdentifier()=="Tool#15","Testing getter and setter of identifier."); MITK_TEST_CONDITION(myNavigationTool->GetDataNode()==myNode,"Testing getter and setter of dataNode."); MITK_TEST_CONDITION(myNavigationTool->GetSpatialObject()==mySpatialObject,"Testing getter and setter of itk spatial object."); - MITK_TEST_CONDITION(myNavigationTool->GetCalibrationFile()=="Test.srom","Testing getter and setter of calibration file."); + MITK_TEST_CONDITION(myNavigationTool->GetCalibrationFile()=="none","Testing getter and setter of calibration file."); //should be none, because file does not exist MITK_TEST_CONDITION(myNavigationTool->GetSerialNumber()=="0815","Testing getter and setter of serial number."); MITK_TEST_CONDITION(myNavigationTool->GetTrackingDeviceType()==mitk::NDIAurora,"Testing getter and setter of tracking device type."); MITK_TEST_CONDITION(myNavigationTool->GetToolName()=="TestNodeName","Testing method GetToolName()."); } }; /** This function is testing the TrackingVolume class. */ int mitkNavigationToolTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationTool") mitkNavigationToolTestClass::TestInstantiation(); mitkNavigationToolTestClass::TestGetterAndSetter(); MITK_TEST_END() }