Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkImageStatisticsContainerManager.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 
15 #include "mitkNodePredicateAnd.h"
16 #include "mitkNodePredicateOr.h"
18 #include "mitkNodePredicateNot.h"
21 
23 {
24  if (!dataStorage) {
25  mitkThrow() << "data storage is nullptr!";
26  }
27  if (!image) {
28  mitkThrow() << "Image is nullptr";
29  }
30 
32 
33  if (predicate) {
34  auto nodePredicateImageStatisticsContainer = mitk::NodePredicateDataType::New(ImageStatisticsContainer::GetStaticNameOfClass());
35  predicate = mitk::NodePredicateAnd::New(predicate, nodePredicateImageStatisticsContainer);
36 
37  auto statisticContainerCandidateNodes = dataStorage->GetSubset(predicate);
38  mitk::DataStorage::SetOfObjects::Pointer statisticContainerCandidateNodesFiltered;
39 
40  statisticContainerCandidateNodesFiltered = mitk::DataStorage::SetOfObjects::New();
41  for (const auto& node : *statisticContainerCandidateNodes) {
42  statisticContainerCandidateNodesFiltered->push_back(node);
43  }
44 
45  if (statisticContainerCandidateNodesFiltered->empty()) {
46  return nullptr;
47  }
48 
49  auto newestElement = statisticContainerCandidateNodesFiltered->front();
50  if (statisticContainerCandidateNodesFiltered->size() > 1) {
51  //in case of multiple found statistics, return only newest one
52  auto newestIter = std::max_element(std::begin(*statisticContainerCandidateNodesFiltered), std::end(*statisticContainerCandidateNodesFiltered), [](mitk::DataNode::Pointer a, mitk::DataNode::Pointer b) {
53  return a->GetData()->GetMTime() < b->GetData()->GetMTime();
54  });
55  newestElement = *newestIter;
56  MITK_WARN << "multiple statistics (" << statisticContainerCandidateNodesFiltered->size() << ") for image/mask found. Returning only newest one.";
57  for (const auto& node : *statisticContainerCandidateNodesFiltered) {
58  MITK_DEBUG << node->GetName() << ", timestamp: " << node->GetData()->GetMTime();
59  }
60  }
61  return dynamic_cast<mitk::ImageStatisticsContainer*>(newestElement->GetData());
62  }
63  else {
64  return nullptr;
65  }
66 }
67 
69 {
70  if (!image) {
71  mitkThrow() << "Image is nullptr";
72  }
73 
75  mitk::NodePredicateBase::ConstPointer predicate = imageRule->GetSourcesDetector(image);
76 
78  if (mask)
79  {
80  auto maskPredicate = maskRule->GetSourcesDetector(mask);
81  predicate = mitk::NodePredicateAnd::New(predicate, maskPredicate);
82  }
83  else
84  {
85  auto maskPredicate = mitk::NodePredicateNot::New(maskRule->GetConnectedSourcesDetector());
86  predicate = mitk::NodePredicateAnd::New(predicate, maskPredicate);
87  }
88 
89  return predicate;
90 }
Data management class that handles &#39;was created by&#39; relations.
static Pointer New()
Base of all data objects.
Definition: mitkBaseData.h:37
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
static Pointer New(const RuleIDType &_arg)
static const char * GetStaticNameOfClass()
Definition: mitkBaseData.h:41
static mitk::ImageStatisticsContainer::ConstPointer GetImageStatistics(const mitk::DataStorage *dataStorage, const mitk::BaseData *image, const mitk::BaseData *mask=nullptr)
Returns the StatisticContainer for the given image and mask.
#define MITK_WARN
Definition: mitkLogMacros.h:19
#define mitkThrow()
SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const
returns a set of data objects that meet the given condition(s)
static Pointer New(const mitk::NodePredicateBase *_arg)
mitk::Image::Pointer image
static Pointer New(const char *_arg)
mitk::Image::Pointer mask
static mitk::NodePredicateBase::ConstPointer GetPredicateForSources(const mitk::BaseData *image, const mitk::BaseData *mask=nullptr)
Container class for storing a StatisticsObject for each timestep.