00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2009-05-28 17:19:30 +0200 (Do, 28 Mai 2009) $ 00006 Version: $Revision $ 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/Zip/Decompress.h" 00020 #include "Poco/Path.h" 00021 00022 #include "mitkNavigationToolStorageDeserializer.h" 00023 #include <mitkSceneIO.h> 00024 #include <mitkStandardFileLocations.h> 00025 #include "mitkNavigationToolReader.h" 00026 00027 mitk::NavigationToolStorageDeserializer::NavigationToolStorageDeserializer(mitk::DataStorage::Pointer dataStorage) 00028 { 00029 m_DataStorage = dataStorage; 00030 } 00031 00032 mitk::NavigationToolStorageDeserializer::~NavigationToolStorageDeserializer() 00033 { 00034 00035 } 00036 00037 mitk::NavigationToolStorage::Pointer mitk::NavigationToolStorageDeserializer::Deserialize(std::string filename) 00038 { 00039 //decomress zip file into temporary directory 00040 std::ifstream file( filename.c_str(), std::ios::binary ); 00041 if (!file.good()) 00042 { 00043 m_ErrorMessage = "Cannot open '" + filename + "' for reading"; 00044 return NULL; 00045 } 00046 mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(m_DataStorage); 00047 std::string tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + myReader->GetFileWithoutPath(filename); 00048 Poco::Zip::Decompress unzipper( file, Poco::Path( tempDirectory ) ); 00049 unzipper.decompressAllFiles(); 00050 00051 00052 //create DataNodes using the decomressed storage 00053 mitk::SceneIO::Pointer mySceneIO = mitk::SceneIO::New(); 00054 mitk::DataStorage::Pointer readStorage = mySceneIO->LoadScene(tempDirectory + Poco::Path::separator() + myReader->GetFileWithoutPath(filename) + ".storage"); 00055 mitk::NavigationToolStorage::Pointer returnValue = mitk::NavigationToolStorage::New(); 00056 00057 for(unsigned int i=0; i<readStorage->GetAll()->Size(); i++) 00058 { 00059 mitk::NavigationTool::Pointer newTool = myReader->ConvertDataNodeToNavigationTool(readStorage->GetAll()->ElementAt(i),tempDirectory); 00060 if (!returnValue->AddTool(newTool)) 00061 { 00062 m_ErrorMessage = "Error can't parse data storage!"; 00063 return NULL; 00064 } 00065 } 00066 00067 //delete decompressed storage which is not needed any more 00068 std::remove((std::string(tempDirectory + Poco::Path::separator() + myReader->GetFileWithoutPath(filename) + ".storage")).c_str()); 00069 00070 return returnValue; 00071 }