MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSCombinedModality.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include "mitkImageReadAccessor.h"
18
19// US Control Interfaces
23
25 NavigationDataSource::Pointer trackingDevice,
26 bool trackedUltrasoundActive)
27 : AbstractUltrasoundTrackerDevice(usDevice, trackingDevice, trackedUltrasoundActive)
28{
29}
30mitk::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();
47 mitk::Image::Pointer image = m_UltrasoundDevice->GetOutput(0);
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}
Abstract class for an easy handling of a combination of an USDevice and a NavigationDataSource....
Connects a mitk::TrackingDevice to a MITK-IGT NavigationData-Filterpipeline.
AffineTransform3D::Pointer GetUSPlaneTransform() override
USCombinedModality(USDevice::Pointer usDevice, itk::SmartPointer< NavigationDataSource > trackingDevice, bool trackedUltrasoundActive=false)
void GenerateData() override
Grabs the next frame from the input. This method is called internally, whenever Update() is invoked b...
void OnFreeze(bool) override
Freezes or unfreezes the CombinedModality.