Medical Imaging Interaction Toolkit  2018.4.99-eed36131
Medical Imaging Interaction Toolkit
mitkPreferenceListReaderOptionsFunctor.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 
14 
16 {
17 
18 }
19 
21 {
22 
23 }
24 
26 {
27 
28 }
29 
31 {
32 
33 }
34 
36 {
37  auto readerItems = loadInfo.m_ReaderSelector.Get();
38 
39  auto selectedID = loadInfo.m_ReaderSelector.GetSelectedId();
40 
41  //check if the pre selected ID is on the blacklist. If true, "un"select.
42  auto finding = std::find(m_BlackList.begin(), m_BlackList.end(), loadInfo.m_ReaderSelector.GetSelected().GetDescription());
43  if (finding != m_BlackList.end())
44  {
45  selectedID = -1;
46  }
47 
48  for (auto reader : readerItems)
49  {
50  finding = std::find(m_BlackList.begin(), m_BlackList.end(), reader.GetDescription());
51 
52  if (finding != m_BlackList.end())
53  {
54  continue;
55  }
56 
57  finding = std::find(m_PreferenceList.begin(), m_PreferenceList.end(), reader.GetDescription());
58 
59  if (finding != m_PreferenceList.end())
60  {
61  selectedID = reader.GetServiceId();
62  break;
63  }
64 
65  if (selectedID==-1)
66  {
67  selectedID = reader.GetServiceId();
68  }
69  }
70 
71  if (selectedID == -1)
72  {
73  mitkThrow() << "No valid reader found. All available readers are black listed.";
74  }
75 
76  if (!loadInfo.m_ReaderSelector.Select(selectedID))
77  {
78  MITK_DEBUG << "Was not able to select reader found by the PreferenceListReaderOptionsFunctor";
79  }
80 
81  auto reader = loadInfo.m_ReaderSelector.GetSelected().GetReader();
82  if (!m_Options.empty() && nullptr != reader)
83  {
84  reader->SetOptions(m_Options);
85  }
86 
87  return true;
88 }
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
std::vector< Item > Get() const
Get a sorted list of file reader items.
virtual void SetOptions(const Options &options)=0
#define mitkThrow()
FileReaderSelector m_ReaderSelector
Definition: mitkIOUtil.h:57
bool operator()(IOUtil::LoadInfo &loadInfo) const override