Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkSceneReader.h"
14 
15 bool mitk::SceneReader::LoadScene(TiXmlDocument &document, const std::string &workingDirectory, DataStorage *storage)
16 {
17  // find version node --> note version in some variable
18  int fileVersion = 1;
19  TiXmlElement *versionObject = document.FirstChildElement("Version");
20  if (versionObject)
21  {
22  if (versionObject->QueryIntAttribute("FileVersion", &fileVersion) != TIXML_SUCCESS)
23  {
24  MITK_ERROR << "Scene file " << workingDirectory + "/index.xml"
25  << " does not contain version information! Trying version 1 format." << std::endl;
26  }
27  }
28 
29  std::stringstream sceneReaderClassName;
30  sceneReaderClassName << "SceneReaderV" << fileVersion;
31 
32  std::list<itk::LightObject::Pointer> sceneReaders =
33  itk::ObjectFactoryBase::CreateAllInstance(sceneReaderClassName.str().c_str());
34  if (sceneReaders.size() < 1)
35  {
36  MITK_ERROR << "No scene reader found for scene file version " << fileVersion;
37  }
38  if (sceneReaders.size() > 1)
39  {
40  MITK_WARN << "Multiple scene readers found for scene file version " << fileVersion
41  << ". Using arbitrary first one.";
42  }
43 
44  for (auto iter = sceneReaders.begin(); iter != sceneReaders.end(); ++iter)
45  {
46  if (auto *reader = dynamic_cast<SceneReader *>(iter->GetPointer()))
47  {
48  if (!reader->LoadScene(document, workingDirectory, storage))
49  {
50  MITK_ERROR << "There were errors while loading scene file "
51  << workingDirectory + "/index.xml. Your data may be corrupted";
52  return false;
53  }
54  else
55  {
56  return true;
57  }
58  }
59  }
60  return false;
61 }
Data management class that handles &#39;was created by&#39; relations.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
virtual bool LoadScene(TiXmlDocument &document, const std::string &workingDirectory, DataStorage *storage)
#define MITK_WARN
Definition: mitkLogMacros.h:19