Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
Medical Imaging Interaction Toolkit
mitkUSCombinedModality.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 "mitkImageReadAccessor.h"
15 #include "mitkUSCombinedModality.h"
18 
19 // US Control Interfaces
23 
25  NavigationDataSource::Pointer trackingDevice,
26  bool trackedUltrasoundActive)
27  : AbstractUltrasoundTrackerDevice(usDevice, trackingDevice, trackedUltrasoundActive)
28 {
29 }
30 mitk::AffineTransform3D::Pointer mitk::USCombinedModality::GetUSPlaneTransform()
31 {
32  return this->GetCalibration();
33 }
34 
36 
38 {
39  if (this->GetIsFreezed())
40  {
41  return;
42  } // if the image is freezed: do nothing
43 
44  // get next image from ultrasound image source
45  // FOR LATER: Be aware if the for loop behaves correct, if the UltrasoundDevice has more than 1 output.
46  m_UltrasoundDevice->Update();
48  if (image.IsNull() || !image->IsInitialized()) // check the image
49  {
50  MITK_WARN << "Invalid image in USCombinedModality, aborting!";
51  return;
52  }
53 
54  // get output and initialize it if it wasn't initialized before
55  mitk::Image::Pointer output = this->GetOutput();
56  if (!output->IsInitialized())
57  {
58  output->Initialize(image);
59  }
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 
65  // and update calibration (= transformation of the image)
66  std::string calibrationKey = this->GetIdentifierForCurrentCalibration();
67  if (!calibrationKey.empty())
68  {
69  std::map<std::string, mitk::AffineTransform3D::Pointer>::iterator calibrationIterator =
70  m_Calibrations.find(calibrationKey);
71  if (calibrationIterator != m_Calibrations.end())
72  {
73  // transform image according to callibration if one is set
74  // for current configuration of probe and depth
75  this->GetOutput()->GetGeometry()->SetIndexToWorldTransform(calibrationIterator->second);
76  }
77  }
78  output->GetGeometry()->SetSpacing(image->GetGeometry()->GetSpacing()); // copy spacing because this might also change
79 }
80 
82 {
83  mitk::TrackingDeviceSource::Pointer trackingDeviceSource = dynamic_cast<mitk::TrackingDeviceSource*>(m_TrackingDeviceDataSource.GetPointer());
84  if (trackingDeviceSource.IsNull())
85  {
86  MITK_WARN("USCombinedModality")("USDevice") << "Cannot freeze tracking.";
87  }
88  else
89  {
90  if (freeze) { trackingDeviceSource->Freeze(); }
91  else { trackingDeviceSource->UnFreeze(); }
92  }
93 
94  if (m_UltrasoundDevice.IsNull())
95  {
96  MITK_ERROR("USCombinedModality")("USDevice") << "UltrasoundDevice must not be null.";
97  mitkThrow() << "UltrasoundDevice must not be null.";
98  }
99  m_UltrasoundDevice->SetIsFreezed(freeze);
100 }
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
void GenerateData() override
Grabs the next frame from the input. This method is called internally, whenever Update() is invoked b...
#define MITK_ERROR
Definition: mitkLogMacros.h:20
USCombinedModality(USDevice::Pointer usDevice, itk::SmartPointer< NavigationDataSource > trackingDevice, bool trackedUltrasoundActive=false)
AffineTransform3D::Pointer GetUSPlaneTransform() override
#define MITK_WARN
Definition: mitkLogMacros.h:19
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
AffineTransform3D::Pointer GetCalibration()
Getter for calibration data of the currently active depth and probe.
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.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:138
void OnFreeze(bool) override
Freezes or unfreezes the CombinedModality.