Medical Imaging Interaction Toolkit  2018.4.99-b585543d
Medical Imaging Interaction Toolkit
mitkDICOMIOHelper.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 "mitkDICOMIOHelper.h"
14 
15 #include <mitkImage.h>
17 
18 #include <usGetModuleContext.h>
19 #include <usModuleContext.h>
20 
21 namespace mitk
22 {
24  {
25  mitk::IDICOMTagsOfInterest *result = nullptr;
26 
27  us::ModuleContext *context = us::GetModuleContext();
28  if (context == nullptr)
29  {
30  MITK_WARN << "No dicom context found.";
31  return result;
32  }
33  std::vector<us::ServiceReference<mitk::IDICOMTagsOfInterest>> toiRegisters =
34  context->GetServiceReferences<mitk::IDICOMTagsOfInterest>();
35  if (!toiRegisters.empty())
36  {
37  if (toiRegisters.size() > 1)
38  {
39  MITK_WARN << "Multiple DICOM tags of interest services found. Using just one.";
40  }
41  result = us::GetModuleContext()->GetService<mitk::IDICOMTagsOfInterest>(toiRegisters.front());
42  }
43 
44  return result;
45  }
46 
49  {
50  std::vector<mitk::DICOMDatasetAccess::FindingsListType> findings;
51  for (const auto &entry : pathsOfInterest)
52  {
53  findings.push_back(frames.front()->GetTagValueAsString(entry));
54  }
55  return findings;
56  }
57 
59  {
60  for (const auto &finding : findings)
61  {
62  for (const auto &entry : finding)
63  {
64  const std::string propertyName = mitk::DICOMTagPathToPropertyName(entry.path);
66  property->SetValue(entry.value);
67  image->SetProperty(propertyName.c_str(), property);
68  }
69  }
70  }
71 }
MITKDICOMREADER_EXPORT FindingsListVectorType ExtractPathsOfInterest(const DICOMTagPathList &pathsOfInterest, const DICOMDatasetAccessingImageFrameList &frames)
Base of all data objects.
Definition: mitkBaseData.h:37
std::vector< mitk::DICOMDatasetAccess::FindingsListType > FindingsListVectorType
DataCollection - Class to facilitate loading/accessing structured data.
Interface of DICOM tags of interest service.
void * GetService(const ServiceReferenceBase &reference)
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
MITKDICOMREADER_EXPORT std::string DICOMTagPathToPropertyName(const DICOMTagPath &tagPath)
#define MITK_WARN
Definition: mitkLogMacros.h:19
mitk::Image::Pointer image
std::vector< DICOMTagPath > DICOMTagPathList
MITKDICOMREADER_EXPORT void SetProperties(BaseDataPointer image, const FindingsListVectorType &findings)
std::vector< DICOMDatasetAccessingImageFrameInfo::Pointer > DICOMDatasetAccessingImageFrameList
MITKDICOMREADER_EXPORT mitk::IDICOMTagsOfInterest * GetDicomTagsOfInterestService()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.