Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkSceneReader.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkSceneReader.h"
18 
19 bool mitk::SceneReader::LoadScene(TiXmlDocument &document, const std::string &workingDirectory, DataStorage *storage)
20 {
21  // find version node --> note version in some variable
22  int fileVersion = 1;
23  TiXmlElement *versionObject = document.FirstChildElement("Version");
24  if (versionObject)
25  {
26  if (versionObject->QueryIntAttribute("FileVersion", &fileVersion) != TIXML_SUCCESS)
27  {
28  MITK_ERROR << "Scene file " << workingDirectory + "/index.xml"
29  << " does not contain version information! Trying version 1 format." << std::endl;
30  }
31  }
32 
33  std::stringstream sceneReaderClassName;
34  sceneReaderClassName << "SceneReaderV" << fileVersion;
35 
36  std::list<itk::LightObject::Pointer> sceneReaders =
37  itk::ObjectFactoryBase::CreateAllInstance(sceneReaderClassName.str().c_str());
38  if (sceneReaders.size() < 1)
39  {
40  MITK_ERROR << "No scene reader found for scene file version " << fileVersion;
41  }
42  if (sceneReaders.size() > 1)
43  {
44  MITK_WARN << "Multiple scene readers found for scene file version " << fileVersion
45  << ". Using arbitrary first one.";
46  }
47 
48  for (auto iter = sceneReaders.begin(); iter != sceneReaders.end(); ++iter)
49  {
50  if (SceneReader *reader = dynamic_cast<SceneReader *>(iter->GetPointer()))
51  {
52  if (!reader->LoadScene(document, workingDirectory, storage))
53  {
54  MITK_ERROR << "There were errors while loading scene file "
55  << workingDirectory + "/index.xml. Your data may be corrupted";
56  return false;
57  }
58  else
59  {
60  return true;
61  }
62  }
63  }
64  return false;
65 }
Data management class that handles 'was created by' relations.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
virtual bool LoadScene(TiXmlDocument &document, const std::string &workingDirectory, DataStorage *storage)
#define MITK_WARN
Definition: mitkLogMacros.h:23