Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Poco/Zip/Decompress.h"
00020 #include "Poco/Path.h"
00021
00022
00023 #include "mitkNavigationToolReader.h"
00024 #include "mitkTrackingTypes.h"
00025 #include <mitkStandardFileLocations.h>
00026 #include <mitkSceneIO.h>
00027
00028
00029
00030 mitk::NavigationToolReader::NavigationToolReader(mitk::DataStorage::Pointer dataStorage)
00031 {
00032 m_DataStorage = dataStorage;
00033 }
00034
00035 mitk::NavigationToolReader::~NavigationToolReader()
00036 {
00037
00038 }
00039
00040 mitk::NavigationTool::Pointer mitk::NavigationToolReader::DoRead(std::string filename)
00041 {
00042
00043 std::ifstream file( filename.c_str(), std::ios::binary );
00044 if (!file.good())
00045 {
00046 m_ErrorMessage = "Cannot open '" + filename + "' for reading";
00047 return NULL;
00048 }
00049
00050 std::string tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + "\\" +GetFileWithoutPath(filename);
00051 Poco::Zip::Decompress unzipper( file, Poco::Path( tempDirectory ) );
00052 unzipper.decompressAllFiles();
00053
00054
00055 mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New();
00056 mitk::DataStorage::Pointer loadedStorage = mySceneIO->LoadScene(tempDirectory + Poco::Path::separator() + GetFileWithoutPath(filename) + ".storage");
00057
00058 if (loadedStorage->GetAll()->size()==0 || loadedStorage.IsNull())
00059 {
00060 m_ErrorMessage = "Invalid file: cannot parse tool data.";
00061 return NULL;
00062 }
00063
00064
00065 mitk::DataNode::Pointer myNode = loadedStorage->GetAll()->ElementAt(0);
00066 mitk::NavigationTool::Pointer returnValue = ConvertDataNodeToNavigationTool(myNode, tempDirectory);
00067
00068
00069 std::remove((std::string(tempDirectory + Poco::Path::separator() + GetFileWithoutPath(filename) + ".storage")).c_str());
00070
00071 return returnValue;
00072 }
00073
00074 mitk::NavigationTool::Pointer mitk::NavigationToolReader::ConvertDataNodeToNavigationTool(mitk::DataNode::Pointer node, std::string toolPath)
00075 {
00076 mitk::NavigationTool::Pointer returnValue = mitk::NavigationTool::New();
00077
00078
00079 mitk::DataNode::Pointer newNode = mitk::DataNode::New();
00080 newNode->SetName(node->GetName());
00081 newNode->SetData(node->GetData());
00082 m_DataStorage->Add(newNode);
00083 returnValue->SetDataNode(newNode);
00084
00085
00086 std::string identifier;
00087 node->GetStringProperty("identifier",identifier);
00088 returnValue->SetIdentifier(identifier);
00089
00090
00091 std::string serial;
00092 node->GetStringProperty("serial number",serial);
00093 returnValue->SetSerialNumber(serial);
00094
00095
00096 int device_type;
00097 node->GetIntProperty("tracking device type",device_type);
00098 returnValue->SetTrackingDeviceType(static_cast<mitk::TrackingDeviceType>(device_type));
00099
00100
00101 int type;
00102 node->GetIntProperty("tracking tool type",type);
00103 returnValue->SetType(static_cast<mitk::NavigationTool::NavigationToolType>(type));
00104
00105
00106 std::string calibration_filename;
00107 node->GetStringProperty("toolfileName",calibration_filename);
00108 std::string calibration_filename_with_path = toolPath + Poco::Path::separator() + calibration_filename;
00109 returnValue->SetCalibrationFile(calibration_filename_with_path);
00110
00111 return returnValue;
00112 }
00113
00114 std::string mitk::NavigationToolReader::GetFileWithoutPath(std::string FileWithPath)
00115 {
00116 std::string returnValue = "";
00117 returnValue = FileWithPath.substr(FileWithPath.rfind("/")+1, FileWithPath.length());
00118
00119 if (returnValue.size() == FileWithPath.size()) returnValue = FileWithPath.substr(FileWithPath.rfind("\\")+1, FileWithPath.length());
00120 return returnValue;
00121 }