Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkNodePredicateDataProperty.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 #include "mitkDataNode.h"
15 #include "mitkExceptionMacro.h"
16 
18 : NodePredicateBase(), m_ValidProperty(p), m_ValidPropertyName(propertyName)
19 {
20  if (m_ValidPropertyName.empty())
21  mitkThrow() << "NodePredicateDataProperty cannot check invalid (empty) property name";
22 }
23 
25 {
26 }
27 
29 {
30  if (node == nullptr)
31  {
32  mitkThrow() << "NodePredicateDataProperty cannot check invalid node";
33  }
34 
35  if (m_ValidPropertyName.empty())
36  {
37  mitkThrow() << "NodePredicateDataProperty cannot check invalid (empty) property name";
38  }
39 
40  bool result = false;
41  auto data = node->GetData();
42  if (data)
43  {
44  if (m_ValidProperty.IsNull())
45  {
46  result = data->GetProperty(m_ValidPropertyName.c_str()).IsNotNull(); // search only for name
47  }
48  else
49  {
50  mitk::BaseProperty::Pointer p = data->GetProperty(m_ValidPropertyName.c_str());
51 
52  if (p.IsNotNull())
53  {
54  result = (*p == *m_ValidProperty);
55  }
56  }
57  }
58  return result;
59 }
bool CheckNode(const mitk::DataNode *node) const override
Checks, if the nodes contains a property that is equal to m_ValidProperty.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Abstract base class for properties.
mitk::BaseProperty::Pointer m_ValidProperty
#define mitkThrow()
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
~NodePredicateDataProperty() override
Standard Destructor.
NodePredicateDataProperty(const char *propertyName, mitk::BaseProperty *p=nullptr)
Constructor to check for a named property.
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64