Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkUSImageSource.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkUSImageSource.h"
18 #include "mitkProperties.h"
19 
20 const char* mitk::USImageSource::IMAGE_PROPERTY_IDENTIFIER = "id_nummer";
21 
23  : m_OpenCVToMitkFilter(mitk::OpenCVToMitkImageFilter::New()),
24  m_MitkToOpenCVFilter(nullptr),
25  m_ImageFilter(mitk::BasicCombinationOpenCVImageFilter::New()),
26  m_CurrentImageId(0),
27  m_ImageFilterMutex(itk::FastMutexLock::New())
28 {
29 }
30 
32 {
33 }
34 
36 {
37  m_ImageFilter->PushFilter(filter);
38 }
39 
41 {
42  return m_ImageFilter->RemoveFilter(filter);
43 }
44 
46 {
47  return m_ImageFilter->GetIsFilterOnTheList(filter);
48 }
49 
51 {
52  mitk::Image::Pointer result;
53 
54  // Get next image and apply OpenCV based filters beforehand
55  if (m_ImageFilter.IsNotNull() && !m_ImageFilter->GetIsEmpty())
56  {
57  cv::Mat image;
58  this->GetNextRawImage(image);
59 
60  if (!image.empty())
61  {
62  m_ImageFilterMutex->Lock();
63  m_ImageFilter->FilterImage(image, m_CurrentImageId);
64  m_ImageFilterMutex->Unlock();
65 
66  // convert to MITK image
67  this->m_OpenCVToMitkFilter->SetOpenCVMat(image);
68  this->m_OpenCVToMitkFilter->Update();
69 
70  // OpenCVToMitkImageFilter returns a standard mitk::image.
71  result = this->m_OpenCVToMitkFilter->GetOutput();
72  }
73  }
74  // Get next image without filtering
75  else
76  {
77  // mitk image can be received direclty if no filtering is necessary
78  this->GetNextRawImage(result);
79  }
80 
81  if (result.IsNotNull())
82  {
83  result->SetProperty(IMAGE_PROPERTY_IDENTIFIER, mitk::IntProperty::New(m_CurrentImageId));
84  m_CurrentImageId++;
85 
86  // Everything as expected, return result
87  return result;
88  }
89  else
90  {
91  //MITK_WARN("mitkUSImageSource") << "Result image is not set.";
92  return mitk::Image::New();
93  }
94 }
95 
97 {
98  // create filter object if it does not exist yet
99  if (!m_MitkToOpenCVFilter)
100  {
101  m_MitkToOpenCVFilter = mitk::ImageToOpenCVImageFilter::New();
102  }
103 
104  // get mitk image through virtual method of the subclass
105  mitk::Image::Pointer mitkImg;
106  this->GetNextRawImage(mitkImg);
107 
108  if (mitkImg.IsNull() || !mitkImg->IsInitialized())
109  {
110  image = cv::Mat();
111  return;
112  }
113 
114  // convert mitk::Image to an OpenCV image
115  m_MitkToOpenCVFilter->SetImage(mitkImg);
116  image = m_MitkToOpenCVFilter->GetOpenCVMat();
117 }
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
bool RemoveFilter(AbstractOpenCVImageFilter::Pointer filter)
bool GetIsFilterInThePipeline(AbstractOpenCVImageFilter::Pointer filter)
Filter for creating MITK RGB Images from an OpenCV image.
static Pointer New()
virtual void GetNextRawImage(cv::Mat &)
Set the given OpenCV image matrix to the next image received from the device or file.
static Pointer New()
void PushFilter(AbstractOpenCVImageFilter::Pointer filter)
mitk::Image::Pointer GetNextImage()
Retrieves the next frame. This will typically be the next frame in a file or the last cached file in ...
static const char * IMAGE_PROPERTY_IDENTIFIER
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.