This repository has been archived by the owner on May 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
qSlicerWorkflowSegmentationModuleWidget.cxx
300 lines (222 loc) · 11 KB
/
qSlicerWorkflowSegmentationModuleWidget.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*==============================================================================
Program: 3D Slicer
Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include <iostream>
// Qt includes
// SlicerQt includes
#include "qSlicerWorkflowSegmentationModuleWidget.h"
#include "ui_qSlicerWorkflowSegmentationModule.h"
#include "qSlicerIO.h"
#include "qSlicerIOManager.h"
#include "qSlicerApplication.h"
#include "qSlicerLayoutManager.h"
#include "qMRMLThreeDWidget.h"
#include <QtGui>
// MRMLWidgets includes
#include <qMRMLUtils.h>
#include "vtkMRMLWorkflowSegmentationNode.h"
#include "vtkMRMLLinearTransformNode.h"
#include "qMRMLNodeComboBox.h"
#include "vtkMRMLViewNode.h"
#include "vtkSlicerWorkflowSegmentationLogic.h"
#include "vtkMRMLWorkflowSegmentationNode.h"
//-----------------------------------------------------------------------------
/// \ingroup Slicer_QtModules_WorkflowSegmentation
class qSlicerWorkflowSegmentationModuleWidgetPrivate: public Ui_qSlicerWorkflowSegmentationModule
{
Q_DECLARE_PUBLIC( qSlicerWorkflowSegmentationModuleWidget );
protected:
qSlicerWorkflowSegmentationModuleWidget* const q_ptr;
public:
qSlicerWorkflowSegmentationModuleWidgetPrivate( qSlicerWorkflowSegmentationModuleWidget& object );
~qSlicerWorkflowSegmentationModuleWidgetPrivate();
vtkSlicerWorkflowSegmentationLogic* logic() const;
// Add embedded widgets here
qSlicerTransformBufferWidget* TransformBufferWidget;
qSlicerWorkflowSegmentationRecorderControlsWidget* RecorderControlsWidget;
qSlicerMessagesWidget* MessagesWidget;
qSlicerWorkflowToolWidget* ToolWidget;
qSlicerWorkflowToolSummaryWidget* ToolSummaryWidget;
std::vector< qSlicerWorkflowGuideDisplayWidget* > WorkflowDisplayWidgets;
};
//-----------------------------------------------------------------------------
// qSlicerWorkflowSegmentationModuleWidgetPrivate methods
qSlicerWorkflowSegmentationModuleWidgetPrivate::qSlicerWorkflowSegmentationModuleWidgetPrivate( qSlicerWorkflowSegmentationModuleWidget& object ) : q_ptr(&object)
{
}
//-----------------------------------------------------------------------------
qSlicerWorkflowSegmentationModuleWidgetPrivate::~qSlicerWorkflowSegmentationModuleWidgetPrivate()
{
}
vtkSlicerWorkflowSegmentationLogic* qSlicerWorkflowSegmentationModuleWidgetPrivate::logic() const
{
Q_Q( const qSlicerWorkflowSegmentationModuleWidget );
return vtkSlicerWorkflowSegmentationLogic::SafeDownCast( q->logic() );
}
//-----------------------------------------------------------------------------
// qSlicerWorkflowSegmentationModuleWidget methods
//-----------------------------------------------------------------------------
qSlicerWorkflowSegmentationModuleWidget::qSlicerWorkflowSegmentationModuleWidget(QWidget* _parent)
: Superclass( _parent )
, d_ptr( new qSlicerWorkflowSegmentationModuleWidgetPrivate( *this ) )
{
}
qSlicerWorkflowSegmentationModuleWidget::~qSlicerWorkflowSegmentationModuleWidget()
{
}
void qSlicerWorkflowSegmentationModuleWidget
::setupEmbeddedWidgets()
{
Q_D(qSlicerWorkflowSegmentationModuleWidget);
// Adding embedded widgets
d->TransformBufferWidget = new qSlicerTransformBufferWidget();
d->BufferGroupBox->layout()->addWidget( d->TransformBufferWidget );
d->TransformBufferWidget->setMRMLScene( NULL );
d->TransformBufferWidget->setMRMLScene( d->logic()->GetMRMLScene() );
d->TransformBufferWidget->setTransformBufferNode( NULL ); // Do not automatically select a node on entering the widget
d->RecorderControlsWidget = new qSlicerWorkflowSegmentationRecorderControlsWidget();
d->ControlsGroupBox->layout()->addWidget( d->RecorderControlsWidget );
d->RecorderControlsWidget->setMRMLScene( NULL );
d->RecorderControlsWidget->setMRMLScene( d->logic()->GetMRMLScene() );
d->MessagesWidget = new qSlicerMessagesWidget();
d->MessagesGroupBox->layout()->addWidget( d->MessagesWidget );
d->MessagesWidget->setMRMLScene( NULL );
d->MessagesWidget->setMRMLScene( d->logic()->GetMRMLScene() );
d->ToolWidget = new qSlicerWorkflowToolWidget();
d->ToolEditorGroupBox->layout()->addWidget( d->ToolWidget );
d->ToolWidget->setMRMLScene( NULL );
d->ToolWidget->setMRMLScene( d->logic()->GetMRMLScene() );
d->ToolSummaryWidget = new qSlicerWorkflowToolSummaryWidget();
d->ToolSummaryGroupBox->layout()->addWidget( d->ToolSummaryWidget );
d->ToolSummaryWidget->setMRMLScene( NULL );
d->ToolSummaryWidget->setMRMLScene( d->logic()->GetMRMLScene() );
// Setting up connections for embedded widgets
// Connect the child widget to the transform buffer node change event (they already observe the modified event)
}
void qSlicerWorkflowSegmentationModuleWidget::setup()
{
Q_D(qSlicerWorkflowSegmentationModuleWidget);
d->setupUi(this);
// Add the embedded widgets
this->setupEmbeddedWidgets();
// Module node selection
connect( d->WorkflowSegmentationNodeComboBox, SIGNAL( currentNodeChanged( vtkMRMLNode* ) ), this, SLOT( mrmlNodeChanged( vtkMRMLNode* ) ) );
// Transform buffer
connect( d->TransformBufferWidget, SIGNAL( transformBufferNodeChanged( vtkMRMLNode* ) ), this, SLOT( onTransformBufferChanged( vtkMRMLNode* ) ) );
// Display
connect( d->TransformBufferWidget, SIGNAL( transformBufferNodeChanged( vtkMRMLNode* ) ), d->RecorderControlsWidget, SLOT( setTransformBufferNode( vtkMRMLNode* ) ) );
connect( d->WorkflowSegmentationNodeComboBox, SIGNAL( currentNodeChanged( vtkMRMLNode* ) ), d->RecorderControlsWidget, SLOT( setWorkflowSegmentationNode( vtkMRMLNode* ) ) );
connect( d->TransformBufferWidget, SIGNAL( transformBufferNodeChanged( vtkMRMLNode* ) ), d->MessagesWidget, SLOT( setTransformBufferNode( vtkMRMLNode* ) ) );
// Advanced
connect( d->RefreshButton, SIGNAL( clicked() ), this, SLOT( createWorkflowDisplaysForExistingNodes() ) );
connect( d->WorkflowSegmentationNodeComboBox, SIGNAL( currentNodeChanged( vtkMRMLNode* ) ), d->ToolSummaryWidget, SLOT( setWorkflowSegmentationNode( vtkMRMLNode* ) ) );
// Workflows
this->createWorkflowDisplaysForExistingNodes();
this->qvtkConnect( d->logic()->GetMRMLScene(), vtkMRMLScene::NodeAddedEvent, this, SLOT( onNodeAdded( vtkObject*, vtkObject* ) ) );
this->qvtkConnect( d->logic()->GetMRMLScene(), vtkMRMLScene::NodeRemovedEvent, this, SLOT( onNodeRemoved( vtkObject*, vtkObject* ) ) );
this->updateWidgetFromMRML();
}
void qSlicerWorkflowSegmentationModuleWidget
::onTransformBufferChanged( vtkMRMLNode* newTransformBuffer )
{
Q_D( qSlicerWorkflowSegmentationModuleWidget );
vtkMRMLWorkflowSegmentationNode* wsNode = vtkMRMLWorkflowSegmentationNode::SafeDownCast( d->WorkflowSegmentationNodeComboBox->currentNode() );
if ( wsNode == NULL )
{
return;
}
if ( newTransformBuffer == NULL )
{
wsNode->SetTransformBufferID( "" );
return;
}
wsNode->SetTransformBufferID( newTransformBuffer->GetID() );
// The Workflow Segmentation node automatically call the "updateWidgetFromMRML" function to deal with the widget
}
void qSlicerWorkflowSegmentationModuleWidget
::mrmlNodeChanged( vtkMRMLNode* wsNode )
{
Q_D( qSlicerWorkflowSegmentationModuleWidget );
this->qvtkDisconnectAll(); // Remove connections to previous node
if ( wsNode != NULL )
{
this->qvtkConnect( wsNode, vtkCommand::ModifiedEvent, this, SLOT( updateWidgetFromMRML() ) );
}
// Reconnect to scene
this->qvtkConnect( d->logic()->GetMRMLScene(), vtkMRMLScene::NodeAddedEvent, this, SLOT( onNodeAdded( vtkObject*, vtkObject* ) ) );
this->qvtkConnect( d->logic()->GetMRMLScene(), vtkMRMLScene::NodeRemovedEvent, this, SLOT( onNodeRemoved( vtkObject*, vtkObject* ) ) );
this->updateWidgetFromMRML();
}
void qSlicerWorkflowSegmentationModuleWidget
::onNodeAdded( vtkObject* caller, vtkObject* node )
{
Q_D( qSlicerWorkflowSegmentationModuleWidget );
// Check if it is a workflow tool node
vtkMRMLWorkflowToolNode* toolNode = vtkMRMLWorkflowToolNode::SafeDownCast( node );
if ( toolNode == NULL )
{
return;
}
qSlicerWorkflowGuideDisplayWidget* currentWidget = new qSlicerWorkflowGuideDisplayWidget( d->WorkflowsCollapsibleButton );
d->WorkflowsCollapsibleButton->layout()->addWidget( currentWidget );
currentWidget->setWorkflowToolNode( toolNode );
d->WorkflowDisplayWidgets.push_back( currentWidget );
}
void qSlicerWorkflowSegmentationModuleWidget
::onNodeRemoved( vtkObject* caller, vtkObject* node )
{
Q_D( qSlicerWorkflowSegmentationModuleWidget );
// Check if it is a workflow tool node
vtkMRMLWorkflowToolNode* toolNode = vtkMRMLWorkflowToolNode::SafeDownCast( node );
if ( toolNode == NULL )
{
return;
}
// Iterate through all widgets and find the right one to remove
for ( int i = 0; i < d->WorkflowDisplayWidgets.size(); i++ )
{
if ( d->WorkflowDisplayWidgets.at( i )->getWorkflowToolNode() == toolNode )
{
d->WorkflowsCollapsibleButton->layout()->removeWidget( d->WorkflowDisplayWidgets.at( i ) );
delete d->WorkflowDisplayWidgets.at( i );
d->WorkflowDisplayWidgets.erase( d->WorkflowDisplayWidgets.begin() + i );
}
}
}
void qSlicerWorkflowSegmentationModuleWidget
::createWorkflowDisplaysForExistingNodes()
{
Q_D( qSlicerWorkflowSegmentationModuleWidget );
// Grab all of the tool nodes
vtkSmartPointer< vtkCollection > toolNodes = vtkSmartPointer< vtkCollection >::Take( d->logic()->GetMRMLScene()->GetNodesByClass( "vtkMRMLWorkflowToolNode" ) );
for ( int i = 0; i < toolNodes->GetNumberOfItems(); i++ )
{
this->onNodeRemoved( d->logic()->GetMRMLScene(), toolNodes->GetItemAsObject( i ) );
this->onNodeAdded( d->logic()->GetMRMLScene(), toolNodes->GetItemAsObject( i ) );
}
}
void qSlicerWorkflowSegmentationModuleWidget
::updateWidgetFromMRML()
{
Q_D( qSlicerWorkflowSegmentationModuleWidget );
// Grab the MRML node
vtkMRMLWorkflowSegmentationNode* wsNode = vtkMRMLWorkflowSegmentationNode::SafeDownCast( d->WorkflowSegmentationNodeComboBox->currentNode() );
if ( wsNode == NULL )
{
return;
}
d->TransformBufferWidget->setTransformBufferNode( wsNode->GetTransformBufferNode() );
d->RecorderControlsWidget->setTransformBufferNode( wsNode->GetTransformBufferNode() );
d->MessagesWidget->setTransformBufferNode( wsNode->GetTransformBufferNode() );
d->RecorderControlsWidget->setWorkflowSegmentationNode( wsNode );
d->ToolSummaryWidget->setWorkflowSegmentationNode( wsNode ); // TODO: Is this necessary
// Everything else taken care of by the child widgets
}