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/Compress.h"
00020 #include "Poco/Path.h"
00021
00022
00023 #include "mitkNavigationToolWriter.h"
00024 #include <mitkStandaloneDataStorage.h>
00025 #include <mitkProperties.h>
00026 #include <mitkSceneIO.h>
00027 #include <mitkStandardFileLocations.h>
00028
00029
00030 #include <stdio.h>
00031
00032 mitk::NavigationToolWriter::NavigationToolWriter()
00033 {
00034
00035 }
00036
00037 mitk::NavigationToolWriter::~NavigationToolWriter()
00038 {
00039
00040 }
00041
00042 bool mitk::NavigationToolWriter::DoWrite(std::string FileName,mitk::NavigationTool::Pointer Tool)
00043 {
00044
00045 mitk::StandaloneDataStorage::Pointer saveStorage = mitk::StandaloneDataStorage::New();
00046 mitk::DataNode::Pointer thisTool = ConvertToDataNode(Tool);
00047 saveStorage->Add(thisTool);
00048
00049
00050 std::string DataStorageFileName = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + GetFileWithoutPath(FileName) + ".storage";
00051 mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New();
00052 mySceneIO->SaveScene(saveStorage->GetAll(),saveStorage,DataStorageFileName);
00053
00054
00055 std::ofstream file( FileName.c_str(), std::ios::binary | std::ios::out);
00056 if (!file.good())
00057 {
00058 m_ErrorMessage = "Could not open a zip file for writing: '" + FileName + "'";
00059 return false;
00060 }
00061 else
00062 {
00063 Poco::Zip::Compress zipper( file, true );
00064 zipper.addFile(DataStorageFileName,GetFileWithoutPath(DataStorageFileName));
00065 zipper.addFile(Tool->GetCalibrationFile(),GetFileWithoutPath(Tool->GetCalibrationFile()));
00066 zipper.close();
00067 }
00068
00069 return true;
00070 }
00071
00072 mitk::DataNode::Pointer mitk::NavigationToolWriter::ConvertToDataNode(mitk::NavigationTool::Pointer Tool)
00073 {
00074 mitk::DataNode::Pointer thisTool = mitk::DataNode::New();
00075
00076 thisTool->SetName(Tool->GetDataNode()->GetName().c_str());
00077
00078 thisTool->AddProperty("identifier",mitk::StringProperty::New(Tool->GetIdentifier().c_str()));
00079
00080 thisTool->AddProperty("serial number",mitk::StringProperty::New(Tool->GetSerialNumber().c_str()));
00081
00082 thisTool->AddProperty("tracking device type",mitk::IntProperty::New(Tool->GetTrackingDeviceType()));
00083
00084 thisTool->AddProperty("tracking tool type",mitk::IntProperty::New(Tool->GetType()));
00085
00086 thisTool->AddProperty("toolfileName",mitk::StringProperty::New(GetFileWithoutPath(Tool->GetCalibrationFile())));
00087
00088 thisTool->SetData(Tool->GetDataNode()->GetData());
00089
00090
00091
00092
00093 return thisTool;
00094 }
00095
00096 std::string mitk::NavigationToolWriter::GetFileWithoutPath(std::string FileWithPath)
00097 {
00098 std::string returnValue = "";
00099 returnValue = FileWithPath.substr(FileWithPath.rfind("/")+1, FileWithPath.length());
00100
00101 if (returnValue.size() == FileWithPath.size()) returnValue = FileWithPath.substr(FileWithPath.rfind("\\")+1, FileWithPath.length());
00102 return returnValue;
00103 }