Page MenuHomePhabricator

SceneReaderInterface.patch

Authored By
wald
Jan 27 2010, 6:09 PM
Size
11 KB
Referenced Files
None
Subscribers
None

SceneReaderInterface.patch

Index: Core/Code/Algorithms/mitkCoreObjectFactory.cpp
===================================================================
--- Core/Code/Algorithms/mitkCoreObjectFactory.cpp (revision 21094)
+++ Core/Code/Algorithms/mitkCoreObjectFactory.cpp (working copy)
@@ -70,8 +70,6 @@
#define CREATE_CPP( TYPE, NAME ) else if ( className == NAME ) {pointer = new TYPE(); pointer->Register();}
#define CREATE_ITK( TYPE, NAME ) else if ( className == NAME ) pointer = TYPE::New();
-mitk::CoreObjectFactory::FileWriterList mitk::CoreObjectFactory::m_FileWriters;
-
itk::Object::Pointer mitk::CoreObjectFactory::CreateCoreObject( const std::string& className )
{
itk::Object::Pointer pointer;
@@ -345,6 +343,16 @@
}
return allWriters;
}
+
+mitk::CoreObjectFactory::SceneReaderList mitk::CoreObjectFactory::GetSceneReaders() {
+ SceneReaderList allReaders = m_SceneReaders;
+ for (ExtraFactoriesList::iterator it = m_ExtraFactories.begin(); it != m_ExtraFactories.end() ; it++ ) {
+ SceneReaderList list2 = (*it)->GetSceneReaders();
+ allReaders.merge(list2);
+ }
+ return allReaders;
+}
+
void mitk::CoreObjectFactory::MapEvent(const mitk::Event*, const int) {
}
Index: Core/Code/Algorithms/mitkCoreObjectFactory.h
===================================================================
--- Core/Code/Algorithms/mitkCoreObjectFactory.h (revision 21094)
+++ Core/Code/Algorithms/mitkCoreObjectFactory.h (working copy)
@@ -37,6 +37,7 @@
virtual const char* GetFileExtensions();
virtual const char* GetSaveFileExtensions();
virtual FileWriterList GetFileWriters();
+ virtual SceneReaderList GetSceneReaders();
virtual itk::Object::Pointer CreateCoreObject( const std::string& className );
virtual void MapEvent(const mitk::Event* event, const int eventID);
virtual void RegisterExtraFactory(CoreObjectFactoryBase::Pointer factory);
@@ -45,7 +46,7 @@
CoreObjectFactory();
typedef std::list<mitk::CoreObjectFactoryBase::Pointer> ExtraFactoriesList;
ExtraFactoriesList m_ExtraFactories;
- static FileWriterList m_FileWriters;
+ FileWriterList m_FileWriters;
std::string m_FileExtensions;
std::string m_SaveFileExtensions;
Index: Core/Code/Algorithms/mitkCoreObjectFactoryBase.h
===================================================================
--- Core/Code/Algorithms/mitkCoreObjectFactoryBase.h (revision 21094)
+++ Core/Code/Algorithms/mitkCoreObjectFactoryBase.h (working copy)
@@ -22,6 +22,7 @@
#include <itkObjectFactoryBase.h>
#include <itkVersion.h>
#include "mitkFileWriterWithInformation.h"
+#include "mitkSceneReaderInterface.h"
namespace mitk {
@@ -36,6 +37,8 @@
{
public:
typedef std::list<mitk::FileWriterWithInformation::Pointer> FileWriterList;
+ typedef std::list<mitk::SceneReaderInterface::Pointer> SceneReaderList;
+
mitkClassMacro(CoreObjectFactoryBase,itk::ObjectFactoryBase);
virtual Mapper::Pointer CreateMapper(mitk::DataTreeNode* node, MapperSlotId slotId) = 0;
virtual void SetDefaultProperties(mitk::DataTreeNode* node) = 0;
@@ -53,8 +56,12 @@
FileWriterList GetFileWriters() {
return m_FileWriters;
}
+ SceneReaderList GetSceneReaders() {
+ return m_SceneReaders;
+ }
protected:
FileWriterList m_FileWriters;
+ SceneReaderList m_SceneReaders;
};
template <class T>
Index: Core/Code/files.cmake
===================================================================
--- Core/Code/files.cmake (revision 21094)
+++ Core/Code/files.cmake (working copy)
@@ -3,6 +3,7 @@
Algorithms/itkLocalVariationImageFilter.h
Algorithms/itkTotalVariationDenoisingImageFilter.h
Algorithms/itkTotalVariationSingleIterationImageFilter.h
+ IO/mitkSceneReaderInterface.h
)
SET(CPP_FILES
Index: CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkDnDFrameWidget.cpp
===================================================================
--- CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkDnDFrameWidget.cpp (revision 21094)
+++ CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkDnDFrameWidget.cpp (working copy)
@@ -54,7 +54,7 @@
bool clearDataStorageFirst(false);
mitk::ProgressBar::GetInstance()->AddStepsToDo(2);
- ds = sceneIO->LoadScene( fileName->toLocalFile().toLocal8Bit().constData(), ds, clearDataStorageFirst );
+ //ds = sceneIO->LoadScene( fileName->toLocalFile().toLocal8Bit().constData(), ds, clearDataStorageFirst );
dsmodified = true;
mitk::ProgressBar::GetInstance()->Progress(2);
}
Index: CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFileOpenAction.cpp
===================================================================
--- CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFileOpenAction.cpp (revision 21094)
+++ CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkFileOpenAction.cpp (working copy)
@@ -131,7 +131,7 @@
bool clearDataStorageFirst(false);
mitk::ProgressBar::GetInstance()->AddStepsToDo(2);
- dataStorage = sceneIO->LoadScene( fileName->toLocal8Bit().constData(), dataStorage, clearDataStorageFirst );
+ //dataStorage = sceneIO->LoadScene( fileName->toLocal8Bit().constData(), dataStorage, clearDataStorageFirst );
dsmodified = true;
mitk::ProgressBar::GetInstance()->Progress(2);
}
Index: Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp
===================================================================
--- Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp (revision 21094)
+++ Modules/IGT/IGTToolManagement/mitkNavigationToolReader.cpp (working copy)
@@ -54,7 +54,7 @@
//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");
+ //mitk::DataStorage::Pointer loadedStorage = mySceneIO->LoadScene(tempDirectory + Poco::Path::separator() + GetFileWithoutPath(filename) + ".storage");
if (loadedStorage->GetAll()->size()==0 || loadedStorage.IsNull())
{
Index: Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp
===================================================================
--- Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp (revision 21094)
+++ Modules/IGT/IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp (working copy)
@@ -52,7 +52,7 @@
//create DataTreeNodes 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::DataStorage::Pointer readStorage = mySceneIO->LoadScene(tempDirectory + Poco::Path::separator() + myReader->GetFileWithoutPath(filename) + ".storage");
mitk::NavigationToolStorage::Pointer returnValue = mitk::NavigationToolStorage::New();
for(int i=0; i<readStorage->GetAll()->Size(); i++)
Index: Modules/SceneSerialization/mitkSceneIO.cpp
===================================================================
--- Modules/SceneSerialization/mitkSceneIO.cpp (revision 21094)
+++ Modules/SceneSerialization/mitkSceneIO.cpp (working copy)
@@ -72,6 +72,38 @@
return uniquename;
}
+bool mitk::SceneIO::CanReadScene( const char* fileName ) const
+{
+ std::stringstream ss;
+ ss << fileName;
+
+ // test input filename
+ if ( ss.str().empty() )
+ {
+ return false;
+ }
+
+ // test if filename can be read
+ std::ifstream file( fileName, std::ios::binary );
+ if (!file.good())
+ {
+ return false;
+ }
+ return true;
+}
+
+const char* mitk::SceneIO::GetFileExtension() const
+{
+ return ".mitk";
+}
+
+void mitk::SceneIO::AddSceneFileContentToDataStorage(const char* fileName, DataStorage* dataStorage)
+{
+ std::stringstream ss;
+ ss << fileName;
+ LoadScene( ss.str(), dataStorage, false );
+}
+
mitk::DataStorage::Pointer mitk::SceneIO::LoadScene( const std::string& filename,
DataStorage* pStorage,
bool clearStorageFirst )
Index: Modules/SceneSerialization/mitkSceneIO.h
===================================================================
--- Modules/SceneSerialization/mitkSceneIO.h (revision 21094)
+++ Modules/SceneSerialization/mitkSceneIO.h (working copy)
@@ -19,6 +19,7 @@
#ifndef mitkSceneIO_h_included
#define mitkSceneIO_h_included
+#include "mitkSceneReaderInterface.h"
#include "SceneSerializationExports.h"
#include "mitkDataStorage.h"
@@ -34,7 +35,7 @@
class BaseData;
class PropertyList;
-class SceneSerialization_EXPORT SceneIO : public itk::Object
+class SceneSerialization_EXPORT SceneIO : public SceneReaderInterface
{
public:
@@ -43,21 +44,26 @@
typedef DataStorage::SetOfObjects FailedBaseDataListType;
- /**
- * \brief Load a scene of objects from file
- * \return DataStorage with all scene objects and their relations. If loading failed, query GetFailedNodes() and GetFailedProperties() for more detail.
- *
- * Attempts to read the provided file and create objects with
- * parent/child relations into a DataStorage.
- *
- * \param filename full filename of the scene file
- * \param storage If given, this DataStorage is used instead of a newly created one
- * \param clearStorageFirst If set, the provided DataStorage will be cleared before populating it with the loaded objects
- */
- virtual DataStorage::Pointer LoadScene( const std::string& filename,
- DataStorage* storage = NULL,
- bool clearStorageFirst = false );
+ //##Documentation
+ //## @brief Returns if the SceneReader is able to load the given file
+ //##
+ //##
+ //##
+ virtual bool CanReadScene(const char* fileName) const;
+
+ //##Documentation
+ //## @brief Loads the content of the scene file to the data storage
+ //##
+ //## Internally calls the method LoadScene
+ //##
+ virtual void AddSceneFileContentToDataStorage(const char* fileName, DataStorage* dataStorage);
+
+ //##Documentation
+ //## @brief Returns the possible file extension
+ //##
+ virtual const char* GetFileExtension() const;
+
/**
* \brief Save a scene of objects to file
* \return True if complete success, false if any problem occurred. Note that a scene file might still be written if false is returned,
@@ -99,6 +105,21 @@
SceneIO();
virtual ~SceneIO();
+ /**
+ * \brief Load a scene of objects from file
+ * \return DataStorage with all scene objects and their relations. If loading failed, query GetFailedNodes() and GetFailedProperties() for more detail.
+ *
+ * Attempts to read the provided file and create objects with
+ * parent/child relations into a DataStorage.
+ *
+ * \param filename full filename of the scene file
+ * \param storage If given, this DataStorage is used instead of a newly created one
+ * \param clearStorageFirst If set, the provided DataStorage will be cleared before populating it with the loaded objects
+ */
+ virtual DataStorage::Pointer LoadScene( const std::string& filename,
+ DataStorage* storage = NULL,
+ bool clearStorageFirst = false );
+
std::string CreateEmptyTempDirectory();
TiXmlElement* SaveBaseData( BaseData* data, const std::string& filenamehint, bool& error);

File Metadata

Mime Type
application/octet-stream
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
371
Default Alt Text
SceneReaderInterface.patch (11 KB)

Event Timeline

second adaption of the SceneIO SceneReader mechanism