Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkTrackedUltrasound.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 "mitkTrackedUltrasound.h"
14 #include "mitkImageReadAccessor.h"
19 
20 
21 
22 
24  NavigationDataSource::Pointer trackingDevice,
25  bool trackedUltrasoundActive )
26  : AbstractUltrasoundTrackerDevice( usDevice, trackingDevice, trackedUltrasoundActive )
27 {
28 }
29 
31 {
32 }
33 
34 mitk::AffineTransform3D::Pointer mitk::TrackedUltrasound::GetUSPlaneTransform()
35 {
36  return m_UltrasoundDevice->GetOutput(0)->GetGeometry()->GetIndexToWorldTransform();
37 }
38 
40 {
41  //Call Update auf US-Device + evtl. auf Tracker (???)
42 
43  if (this->GetIsFreezed()) { return; } //if the image is freezed: do nothing
44 
45  //get next image from ultrasound image source
46  //FOR LATER: Be aware if the for loop behaves correct, if the UltrasoundDevice has more than 1 output.
47  int i = 0;
48  m_UltrasoundDevice->Update();
50  if (image.IsNull() || !image->IsInitialized()) //check the image
51  {
52  MITK_WARN << "Invalid image in TrackedUltrasound, aborting!";
53  return;
54  }
55  //___MITK_INFO << "GetSpacing: " << image->GetGeometry()->GetSpacing();
56 
57  //get output and initialize it if it wasn't initialized before
58  mitk::Image::Pointer output = this->GetOutput(i);
59  if (!output->IsInitialized()) { output->Initialize(image); }
60 
61  //now update image data
62  mitk::ImageReadAccessor inputReadAccessor(image, image->GetSliceData(0, 0, 0));
63  output->SetSlice(inputReadAccessor.GetData()); //copy image data
64  output->GetGeometry()->SetSpacing(image->GetGeometry()->GetSpacing()); //copy spacing because this might also change
65 
66  //and update calibration (= transformation of the image)
67  std::string calibrationKey = this->GetIdentifierForCurrentCalibration();
68  if (!calibrationKey.empty())
69  {
70  std::map<std::string, mitk::AffineTransform3D::Pointer>::iterator calibrationIterator
71  = m_Calibrations.find(calibrationKey);
72  if (calibrationIterator != m_Calibrations.end())
73  {
74  // transform image according to callibration if one is set
75  // for current configuration of probe and depth
76  m_DisplacementFilter->SetTransformation(calibrationIterator->second);
77  //Setze Update auf Displacementfilter ????
78  }
79  }
80 }
81 
83 {
84  mitk::TrackingDeviceSource::Pointer trackingDeviceSource = dynamic_cast<mitk::TrackingDeviceSource*>(m_TrackingDeviceDataSource.GetPointer());
85  if (trackingDeviceSource.IsNull())
86  {
87  MITK_WARN("TrackedUltrasound")("USDevice") << "Cannot freeze tracking.";
88  }
89  else
90  {
91  if (freeze) { trackingDeviceSource->Freeze(); }
92  else { trackingDeviceSource->UnFreeze(); }
93  }
94 
95  if (m_UltrasoundDevice.IsNull())
96  {
97  MITK_ERROR("TrackedUltrasound")("USDevice") << "UltrasoundDevice must not be null.";
98  mitkThrow() << "UltrasoundDevice must not be null.";
99  }
100  m_UltrasoundDevice->SetIsFreezed(freeze);
101 }
void OnFreeze(bool) override
Freezes or unfreezes the TrackedUltrasound device.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
#define MITK_WARN
Definition: mitkLogMacros.h:19
itk::SmartPointer< mitk::NavigationDataDisplacementFilter > m_DisplacementFilter
void GenerateData() override
Grabs the next frame from the input. This method is called internally, whenever Update() is invoked b...
TrackedUltrasound(USDevice::Pointer usDevice, itk::SmartPointer< NavigationDataSource > trackingDevice, bool trackedUltrasoundActive=true)
std::map< std::string, AffineTransform3D::Pointer > m_Calibrations
#define mitkThrow()
Abstract class for an easy handling of a combination of an USDevice and a NavigationDataSource. This class can be used as an ImageSource subclass. Additionally tracking data be retrieved from the NavigationDataSource returned by GetTrackingDevice().
mitk::Image::Pointer image
Connects a mitk::TrackingDevice to a MITK-IGT NavigationData-Filterpipeline.
OutputType * GetOutput()
Get the output data of this image source object.
itk::SmartPointer< NavigationDataSource > m_TrackingDeviceDataSource
ImageReadAccessor class to get locked read access for a particular image part.
AffineTransform3D::Pointer GetUSPlaneTransform() override