Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkPropertyFilters.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 "mitkPropertyFilters.h"
14 #include <mitkPropertyFilter.h>
15 #include <utility>
16 
18 {
19 }
20 
22 {
23 }
24 
25 bool mitk::PropertyFilters::AddFilter(const PropertyFilter &filter, const std::string &className, bool overwrite)
26 {
27  if (!filter.IsEmpty())
28  {
29  std::pair<std::map<std::string, PropertyFilter>::iterator, bool> ret =
30  m_Filters.insert(std::make_pair(className, filter));
31 
32  if (!ret.second && overwrite)
33  {
34  ret.first->second = filter;
35  ret.second = true;
36  }
37 
38  return ret.second;
39  }
40 
41  return false;
42 }
43 
44 std::map<std::string, mitk::BaseProperty::Pointer> mitk::PropertyFilters::ApplyFilter(
45  const std::map<std::string, BaseProperty::Pointer> &propertyMap, const std::string &className) const
46 {
47  std::map<std::string, BaseProperty::Pointer> ret = propertyMap;
48  PropertyFilter filter = this->GetFilter("");
49 
50  if (!filter.IsEmpty())
51  ret = filter.Apply(ret);
52 
53  if (!className.empty())
54  {
55  filter = this->GetFilter(className);
56 
57  if (!filter.IsEmpty())
58  ret = filter.Apply(ret);
59  }
60 
61  return ret;
62 }
63 
64 mitk::PropertyFilter mitk::PropertyFilters::GetFilter(const std::string &className) const
65 {
66  auto iter = m_Filters.find(className);
67 
68  if (iter != m_Filters.end())
69  return iter->second;
70 
71  return PropertyFilter();
72 }
73 
74 bool mitk::PropertyFilters::HasFilter(const std::string &className) const
75 {
76  return m_Filters.find(className) != m_Filters.end();
77 }
78 
80 {
81  m_Filters.clear();
82 }
83 
84 void mitk::PropertyFilters::RemoveFilter(const std::string &className)
85 {
86  m_Filters.erase(className);
87 }
PropertyFilter GetFilter(const std::string &className) const override
Get the current property filter.
void RemoveAllFilters() override
Remove all property filters.
std::map< std::string, BaseProperty::Pointer > ApplyFilter(const std::map< std::string, BaseProperty::Pointer > &propertyMap, const std::string &className) const override
Apply property filter to property list.
bool HasFilter(const std::string &className) const override
Check if a specific data node class name has a property filter.
bool AddFilter(const PropertyFilter &filter, const std::string &className, bool overwrite) override
Add a property filter.
bool IsEmpty() const
Check if filter is empty.
void RemoveFilter(const std::string &className) override
Remove property filter for a specific data node class name.
std::map< std::string, BaseProperty::Pointer > Apply(const std::map< std::string, BaseProperty::Pointer > &propertyMap) const
Apply the filter to a property list.
Consists of blacklist and whitelist entries.