MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkTrackedUltrasound.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
14#include "mitkImageReadAccessor.h"
19
20
21
22
24 NavigationDataSource::Pointer trackingDevice,
25 bool trackedUltrasoundActive )
26 : AbstractUltrasoundTrackerDevice( usDevice, trackingDevice, trackedUltrasoundActive )
27{
28}
29
33
34mitk::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();
49 mitk::Image::Pointer image = m_UltrasoundDevice->GetOutput(i);
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}
Abstract class for an easy handling of a combination of an USDevice and a NavigationDataSource....
void OnFreeze(bool) override
Freezes or unfreezes the TrackedUltrasound device.
AffineTransform3D::Pointer GetUSPlaneTransform() override
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)
Connects a mitk::TrackingDevice to a MITK-IGT NavigationData-Filterpipeline.