MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkUSNavigationStepZoneMarking.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 "ui_QmitkUSNavigationStepZoneMarking.h"
15
17
19
22 m_ZoneDisplacementFilter(mitk::NodeDisplacementFilter::New()),
23 m_ReferenceSensorIndex(1),
24 m_CurrentlyAddingZone(false),
26{
27 ui->setupUi(this);
28
29 connect( ui->freezeButton, SIGNAL(SignalFreezed(bool)), this, SLOT(OnFreeze(bool)) );
30 connect( ui->zonesWidget, SIGNAL(ZoneAdded()), this, SLOT(OnZoneAdded()) );
31 connect( ui->zonesWidget, SIGNAL(ZoneRemoved()), this, SLOT(OnZoneRemoved()) );
32 connect(ui->showStructureList, SIGNAL(stateChanged(int)), this, SLOT(OnShowListClicked(int)));
33 ui->zonesLabel->setVisible(false);
34 ui->zonesWidget->setVisible(false);
35}
36
38{
39 ui->zonesLabel->setVisible(state);
40 ui->zonesWidget->setVisible(state);
41}
42
47
57
59{
60 m_ZoneDisplacementFilter->ResetNodes();
61 ui->zonesWidget->OnResetZones();
62 m_ZoneNodes.clear();
63
64 // remove zone nodes from the data storage
65 mitk::DataStorage::Pointer dataStorage = this->GetDataStorage(false);
66 if ( dataStorage.IsNotNull() )
67 {
68 mitk::DataNode::Pointer baseNode = dataStorage->GetNamedNode(QmitkUSAbstractNavigationStep::DATANAME_BASENODE);
69 if ( baseNode.IsNotNull() )
70 {
71 dataStorage->Remove(dataStorage->GetNamedDerivedNode(QmitkUSNavigationMarkerPlacement::DATANAME_ZONES, baseNode));
72 }
73 }
74
75 return true;
76}
77
82
84{
85 m_ZoneDisplacementFilter->ConnectTo(this->GetCombinedModality()->GetNavigationDataSource());
87
89
90 return true;
91}
92
94{
95 ui->freezeButton->Unfreeze();
96
97 return true;
98}
99
101{
102 if (m_NavigationDataSource.IsNull()) { return; }
103
104 m_NavigationDataSource->Update();
105 m_ZoneDisplacementFilter->Update();
106
107 bool valid = m_NavigationDataSource->GetOutput(m_ReferenceSensorIndex)->IsDataValid();
108
109 if (valid)
110 {
111 ui->bodyMarkerTrackingStatusLabel->setStyleSheet(
112 "background-color: #8bff8b; margin-right: 1em; margin-left: 1em; border: 1px solid grey");
113 ui->bodyMarkerTrackingStatusLabel->setText("Body marker is inside the tracking volume.");
114 }
115 else
116 {
117 ui->bodyMarkerTrackingStatusLabel->setStyleSheet(
118 "background-color: #ff7878; margin-right: 1em; margin-left: 1em; border: 1px solid grey");
119 ui->bodyMarkerTrackingStatusLabel->setText("Body marker is not inside the tracking volume.");
120 }
121
122 ui->freezeButton->setEnabled(valid);
123}
124
126{
127 if ( settingsNode.IsNull() ) { return; }
128
129 std::string stateMachineFilename;
130 if ( settingsNode->GetStringProperty("settings.interaction-concept", stateMachineFilename) && stateMachineFilename != m_StateMachineFilename )
131 {
132 m_StateMachineFilename = stateMachineFilename;
133 ui->zonesWidget->SetStateMachineFilename(stateMachineFilename);
134 }
135
136 std::string referenceSensorName;
137 if ( settingsNode->GetStringProperty("settings.reference-name-selected", referenceSensorName) )
138 {
139 m_ReferenceSensorName = referenceSensorName;
140 }
141
143}
144
146{
147 return "Critical Structures";
148}
149
154
156{
157 if (freezed) this->GetCombinedModality()->SetIsFreezed(true);
158
159 ui->zoneAddingExplanationLabel->setEnabled(freezed);
160
161 if ( freezed )
162 {
164 ui->zonesWidget->OnStartAddingZone();
165 // feed reference pose to node displacement filter
166 m_ZoneDisplacementFilter->SetInitialReferencePose(this->GetCombinedModality()->GetNavigationDataSource()->GetOutput(m_ReferenceSensorIndex)->Clone());
167 }
168 else if ( m_CurrentlyAddingZone )
169 {
170 m_CurrentlyAddingZone = false;
171 ui->zonesWidget->OnAbortAddingZone();
172 }
173
174 if (!freezed) this->GetCombinedModality()->SetIsFreezed(false);
175}
176
178{
179 m_CurrentlyAddingZone = false;
180
181 ui->freezeButton->Unfreeze();
182
183 ui->zoneAddingExplanationLabel->setEnabled(ui->freezeButton->isChecked());
184
185 mitk::DataStorage::SetOfObjects::ConstPointer zoneNodesSet = ui->zonesWidget->GetZoneNodes();
186 for (mitk::DataStorage::SetOfObjects::ConstIterator it = zoneNodesSet->Begin();
187 it != zoneNodesSet->End(); ++it)
188 {
189 // add all zones to zone filter which aren't added until now
190 if ( std::find(m_ZoneNodes.begin(), m_ZoneNodes.end(), it->Value()) == m_ZoneNodes.end() )
191 {
192 // logging center point and radius
193 float radius = -1;
194 it->Value()->GetFloatProperty("zone.size", radius);
195 MITK_INFO("QmitkUSNavigationStepZoneMarking")("QmitkUSAbstractNavigationStep")
196 << "Risk zone (" << it->Value()->GetName() << ") added with center "
197 << it->Value()->GetData()->GetGeometry()->GetOrigin() << " and radius " << radius << ".";
198
199 m_ZoneNodes.push_back(it->Value());
200 m_ZoneDisplacementFilter->AddNode(it->Value());
201 }
202 }
203}
204
206{
207 mitk::DataStorage::SetOfObjects::ConstPointer zoneNodesSet = ui->zonesWidget->GetZoneNodes();
208
209 for ( int n = m_ZoneNodes.size() - 1; n >= 0; --n )
210 {
211 bool found = false;
212
213 // test if the node can be found in the set of zone nodes
214 for (mitk::DataStorage::SetOfObjects::ConstIterator itSet = zoneNodesSet->Begin();
215 itSet != zoneNodesSet->End(); ++itSet)
216 {
217 if ( m_ZoneNodes.at(n) == itSet->Value() ) { found = true; break; }
218 }
219
220 if ( ! found )
221 {
222 MITK_INFO("QmitkUSNavigationStepZoneMarking")("QmitkUSAbstractNavigationStep")
223 << "Risk zone (" << m_ZoneNodes.at(n)->GetName() << ") removed.";
224
225 m_ZoneNodes.erase(m_ZoneNodes.begin()+n);
226 m_ZoneDisplacementFilter->RemoveNode(n);
227 }
228 }
229}
230
232{
233 mitk::AbstractUltrasoundTrackerDevice::Pointer combinedModality = this->GetCombinedModality(false);
234 if (combinedModality.IsNotNull())
235 {
236 m_NavigationDataSource = combinedModality->GetNavigationDataSource();
237 }
238
239 ui->freezeButton->SetCombinedModality(combinedModality, m_ReferenceSensorIndex);
240
242}
243
245{
246 if ( m_NavigationDataSource.IsNull() ) { return; }
247
248 if ( ! m_ReferenceSensorName.empty() )
249 {
250 try
251 {
252 //m_ReferenceSensorIndex = m_NavigationDataSource->GetOutputIndex(m_ReferenceSensorName);
254 }
255 catch ( const std::exception &e )
256 {
257 MITK_WARN("QmitkUSAbstractNavigationStep")("QmitkUSNavigationStepZoneMarking")
258 << "Cannot get index for reference sensor name: " << e.what();
259 }
260 }
261
263 {
265 }
266
267 ui->freezeButton->SetCombinedModality(this->GetCombinedModality(false), m_ReferenceSensorIndex);
268}
Abstract base class for navigation step widgets.
itk::SmartPointer< mitk::DataStorage > GetDataStorage(bool throwNull=true)
Returns the data storage set for the navigation step.
NavigationStepState GetNavigationStepState()
Get the current state of the navigation step.
void SignalReadyForNextStep()
Signals that all necessary actions where done. The user can proceed with the next stept after this wa...
itk::SmartPointer< mitk::DataNode > GetNamedDerivedNodeAndCreate(const char *name, const char *sourceName)
Returns node with the given name and the given source node (parent) from the data storage....
itk::SmartPointer< mitk::AbstractUltrasoundTrackerDevice > GetCombinedModality(bool throwNull=true)
Returns the combined modality set for the navigation step.
std::vector< itk::SmartPointer< mitk::NavigationDataToNavigationDataFilter > > FilterVector
Navigation step for marking risk structures. The user can add risk structures by interacting with the...
QString GetTitle() override
Getter for the title of the navigation step. This title should be human readable and can be used to d...
bool OnFinishStep() override
There is nothing to be done.
void OnZoneRemoved()
Triggered when a risk zone was removed. Removes the zone from a member variable and from the node dis...
itk::SmartPointer< mitk::NavigationDataSource > m_NavigationDataSource
bool OnStopStep() override
Resets widget and filter and removes nodes from the data storage.
void OnSettingsChanged(const itk::SmartPointer< mitk::DataNode > settingsNode) override
itk::SmartPointer< mitk::NodeDisplacementFilter > m_ZoneDisplacementFilter
void OnSetCombinedModality() override
Called every time SetCombinedModality() was called. This method may be implemented by a concrete subc...
void OnUpdate() override
Updates just the tracking validity status.
void OnZoneAdded()
Triggered when a risk zone was added. Adds the zone to a member variable and to the node displacement...
bool OnStartStep() override
Initialization of the data storage nodes.
bool OnActivateStep() override
Selects input for the node displacement filter and emits "ReadyForNextStep" signal....
bool OnDeactivateStep() override
Called when the navigation step gets deactivated (-> state started). This method may be implemented b...
std::vector< itk::SmartPointer< mitk::DataNode > > m_ZoneNodes
IGT Exceptions.