[Repository Listing] / [Slicer4] / trunk / Modules / Loadable / Transforms / MRMLDM / vtkMRMLLinearTransformsDisplayableManager3D.cxx
 

View of /trunk/Modules/Loadable/Transforms/MRMLDM/vtkMRMLLinearTransformsDisplayableManager3D.cxx

Parent Directory Parent Directory Revision Log Revision Log


Revision 26372  Download Blame
File size: 25853 byte(s)
BUG: Activate picking manager before placing transform editor box widget

Box widget behavior is different with picking manager enabled/disabled. If disabled, then the middle handle can be grabbed to translate the widget.
If enabled, then translation is only possible using shift+click.

It maight be a bug in VTK that the center handle is not accessible when picking manager is enabled.
1 /*==============================================================================
2
3 Program: 3D Slicer
4
5 Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Andras Lasso and Franklin King at
17 PerkLab, Queen's University and was supported through the Applied Cancer
18 Research Unit program of Cancer Care Ontario with funds provided by the
19 Ontario Ministry of Health and Long-Term Care.
20
21 ==============================================================================*/
22
23
24 // MRMLDisplayableManager includes
25 #include "vtkMRMLLinearTransformsDisplayableManager3D.h"
26
27 #include "vtkSlicerTransformLogic.h"
28
29 // MRML includes
30 #include <vtkEventBroker.h>
31 #include <vtkMRMLProceduralColorNode.h>
32 #include <vtkMRMLScene.h>
33 #include <vtkMRMLTransformDisplayNode.h>
34 #include <vtkMRMLTransformNode.h>
35 #include <vtkMRMLViewNode.h>
36
37 // VTK includes
38 #include <vtkBoxRepresentation.h>
39 #include <vtkBoxWidget2.h>
40 #include <vtkCallbackCommand.h>
41 #include <vtkCollection.h>
42 #include <vtkGeneralTransform.h>
43 #include <vtkLineSource.h>
44 #include <vtkMatrix4x4.h>
45 #include <vtkNew.h>
46 #include <vtkObjectFactory.h>
47 #include <vtkPickingManager.h>
48 #include <vtkRenderWindowInteractor.h>
49 #include <vtkRenderer.h>
50 #include <vtkSmartPointer.h>
51 #include <vtkTransform.h>
52
53 const double DEFAULT_SCALE[3] = {100.0, 100.0, 100.0};
54
55 //---------------------------------------------------------------------------
56 vtkStandardNewMacro ( vtkMRMLLinearTransformsDisplayableManager3D );
57
58 //---------------------------------------------------------------------------
59 class vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
60 {
61 public:
62
63 vtkInternal(vtkMRMLLinearTransformsDisplayableManager3D* external);
64 ~vtkInternal();
65
66 struct Pipeline
67 {
68 vtkSmartPointer<vtkBoxWidget2> Widget;
69 vtkSmartPointer<vtkTransform> WidgetDisplayTransform;
70 bool UpdateWidgetBounds;
71 };
72
73 typedef std::map < vtkMRMLTransformDisplayNode*, Pipeline* > PipelinesCacheType;
74 PipelinesCacheType DisplayPipelines;
75
76 typedef std::map < vtkMRMLTransformNode*, std::set< vtkMRMLTransformDisplayNode* > > TransformToDisplayCacheType;
77 TransformToDisplayCacheType TransformToDisplayNodes;
78
79 typedef std::map < vtkBoxWidget2*, vtkMRMLTransformDisplayNode* > WidgetToNodeMapType;
80 WidgetToNodeMapType WidgetMap;
81
82 // Transforms
83 void AddTransformNode(vtkMRMLTransformNode* displayableNode);
84 void RemoveTransformNode(vtkMRMLTransformNode* displayableNode);
85 void UpdateDisplayableTransforms(vtkMRMLTransformNode *node, bool);
86
87 // Display Nodes
88 void AddDisplayNode(vtkMRMLTransformNode*, vtkMRMLTransformDisplayNode*);
89 void UpdateDisplayNode(vtkMRMLTransformDisplayNode* displayNode);
90 void UpdateDisplayNodePipeline(vtkMRMLTransformDisplayNode*, Pipeline*);
91 void RemoveDisplayNode(vtkMRMLTransformDisplayNode* displayNode);
92 void SetTransformDisplayProperty(vtkMRMLTransformDisplayNode *displayNode, vtkActor* actor);
93
94 // Widget
95 void UpdateWidgetDisplayTransform(Pipeline*, vtkMRMLTransformNode*);
96 void UpdateWidgetFromNode(vtkMRMLTransformDisplayNode*, vtkMRMLTransformNode*, Pipeline*);
97 void UpdateNodeFromWidget(vtkBoxWidget2*);
98
99 // Observations
100 void AddObservations(vtkMRMLTransformNode* node);
101 void RemoveObservations(vtkMRMLTransformNode* node);
102 void AddDisplayObservations(vtkMRMLTransformDisplayNode* node);
103 void RemoveDisplayObservations(vtkMRMLTransformDisplayNode* node);
104
105 // Helper functions
106 bool UseDisplayNode(vtkMRMLTransformDisplayNode* displayNode);
107 bool UseDisplayableNode(vtkMRMLTransformNode* node);
108 void ClearDisplayableNodes();
109
110 private:
111 vtkMRMLLinearTransformsDisplayableManager3D* External;
112 bool AddingTransformNode;
113 };
114
115 //---------------------------------------------------------------------------
116 // vtkInternal methods
117
118 //---------------------------------------------------------------------------
119 vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::vtkInternal(vtkMRMLLinearTransformsDisplayableManager3D * external)
120 : External(external)
121 , AddingTransformNode(false)
122 {
123 }
124
125 //---------------------------------------------------------------------------
126 vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::~vtkInternal()
127 {
128 this->ClearDisplayableNodes();
129 }
130
131 //---------------------------------------------------------------------------
132 bool vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::UseDisplayNode(vtkMRMLTransformDisplayNode* displayNode)
133 {
134 // allow annotations to appear only in designated viewers
135 if (displayNode && !displayNode->IsDisplayableInView(this->External->GetMRMLViewNode()->GetID()))
136 {
137 return false;
138 }
139
140 // Check whether DisplayNode should be shown in this view
141 bool use = displayNode && displayNode->IsA("vtkMRMLTransformDisplayNode");
142
143 return use;
144 }
145
146 //---------------------------------------------------------------------------
147 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::AddTransformNode(vtkMRMLTransformNode* node)
148 {
149 if (this->AddingTransformNode)
150 {
151 return;
152 }
153 // Check if node should be used
154 if (!this->UseDisplayableNode(node))
155 {
156 return;
157 }
158
159 this->AddingTransformNode = true;
160 // Add Display Nodes
161 int nnodes = node->GetNumberOfDisplayNodes();
162
163 this->AddObservations(node);
164
165 for (int i=0; i<nnodes; i++)
166 {
167 vtkMRMLTransformDisplayNode *dnode = vtkMRMLTransformDisplayNode::SafeDownCast(node->GetNthDisplayNode(i));
168 if ( this->UseDisplayNode(dnode) )
169 {
170 this->TransformToDisplayNodes[node].insert(dnode);
171 this->AddDisplayNode( node, dnode );
172 }
173 }
174 this->AddingTransformNode = false;
175 }
176
177 //---------------------------------------------------------------------------
178 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::RemoveTransformNode(vtkMRMLTransformNode* node)
179 {
180 if (!node)
181 {
182 return;
183 }
184 vtkInternal::TransformToDisplayCacheType::iterator displayableIt =
185 this->TransformToDisplayNodes.find(node);
186 if(displayableIt == this->TransformToDisplayNodes.end())
187 {
188 return;
189 }
190
191 std::set<vtkMRMLTransformDisplayNode *> dnodes = displayableIt->second;
192 std::set<vtkMRMLTransformDisplayNode *>::iterator diter;
193 for ( diter = dnodes.begin(); diter != dnodes.end(); ++diter)
194 {
195 this->RemoveDisplayNode(*diter);
196 }
197 this->RemoveObservations(node);
198 this->TransformToDisplayNodes.erase(displayableIt);
199 }
200
201 //---------------------------------------------------------------------------
202 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::UpdateDisplayableTransforms(vtkMRMLTransformNode* mNode, bool updateBounds)
203 {
204 // Update the pipeline for all tracked DisplayableNode
205 PipelinesCacheType::iterator pipelinesIter;
206 std::set< vtkMRMLTransformDisplayNode* > displayNodes = this->TransformToDisplayNodes[mNode];
207 std::set< vtkMRMLTransformDisplayNode* >::iterator dnodesIter;
208 for ( dnodesIter = displayNodes.begin(); dnodesIter != displayNodes.end(); dnodesIter++ )
209 {
210 if ( ((pipelinesIter = this->DisplayPipelines.find(*dnodesIter)) != this->DisplayPipelines.end()) )
211 {
212 Pipeline* pipeline = pipelinesIter->second;
213 pipeline->UpdateWidgetBounds |= updateBounds;
214 this->UpdateDisplayNodePipeline(pipelinesIter->first, pipeline);
215 }
216 }
217 }
218
219 //---------------------------------------------------------------------------
220 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::RemoveDisplayNode(vtkMRMLTransformDisplayNode* displayNode)
221 {
222 PipelinesCacheType::iterator actorsIt = this->DisplayPipelines.find(displayNode);
223 if(actorsIt == this->DisplayPipelines.end())
224 {
225 return;
226 }
227 this->RemoveDisplayObservations(displayNode);
228 Pipeline* pipeline = actorsIt->second;
229 this->WidgetMap.erase(pipeline->Widget);
230 delete pipeline;
231 this->DisplayPipelines.erase(actorsIt);
232 }
233
234 //---------------------------------------------------------------------------
235 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::AddDisplayNode(vtkMRMLTransformNode* mNode, vtkMRMLTransformDisplayNode* displayNode)
236 {
237 if (!mNode || !displayNode)
238 {
239 return;
240 }
241
242 // Do not add the display node if it is already associated with a pipeline object.
243 // This happens when a transform node already associated with a display node
244 // is copied into an other (using vtkMRMLNode::Copy()) and is added to the scene afterward.
245 // Related issue are #3428 and #2608
246 PipelinesCacheType::iterator it;
247 it = this->DisplayPipelines.find(displayNode);
248 if (it != this->DisplayPipelines.end())
249 {
250 return;
251 }
252
253 this->AddDisplayObservations(displayNode);
254
255 // Create pipeline
256 Pipeline* pipeline = new Pipeline();
257 pipeline->UpdateWidgetBounds = true;
258 this->DisplayPipelines.insert( std::make_pair(displayNode, pipeline) );
259
260 // Interaction VTK
261 // - Widget
262 pipeline->Widget = vtkSmartPointer<vtkBoxWidget2>::New();
263 vtkNew<vtkBoxRepresentation> WidgetRep;
264 pipeline->Widget->SetRepresentation(WidgetRep.GetPointer());
265 // - Transform
266 pipeline->WidgetDisplayTransform = vtkSmartPointer<vtkTransform>::New();
267 // - Widget events
268 pipeline->Widget->AddObserver(
269 vtkCommand::InteractionEvent, this->External->GetWidgetsCallbackCommand());
270
271 if (this->External->GetInteractor()->GetPickingManager())
272 {
273 if (!(this->External->GetInteractor()->GetPickingManager()->GetEnabled()))
274 {
275 // if the picking manager is not already turned on for this
276 // interactor, enable it
277 this->External->GetInteractor()->GetPickingManager()->EnabledOn();
278 }
279 }
280
281 // Add actor / set renderers and cache
282 pipeline->Widget->SetInteractor(this->External->GetInteractor());
283 pipeline->Widget->SetCurrentRenderer(this->External->GetRenderer());
284 this->WidgetMap.insert( std::make_pair(pipeline->Widget, displayNode) );
285
286 // Update cached matrices. Calls UpdateDisplayNodePipeline
287 this->UpdateDisplayableTransforms(mNode, true);
288 }
289
290 //---------------------------------------------------------------------------
291 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::UpdateDisplayNode(vtkMRMLTransformDisplayNode* displayNode)
292 {
293 // If the DisplayNode already exists, just update.
294 // otherwise, add as new node
295
296 if (!displayNode)
297 {
298 return;
299 }
300 PipelinesCacheType::iterator it;
301 it = this->DisplayPipelines.find(displayNode);
302 if (it != this->DisplayPipelines.end())
303 {
304 this->UpdateDisplayNodePipeline(displayNode, it->second);
305 }
306 else
307 {
308 this->AddTransformNode( vtkMRMLTransformNode::SafeDownCast(displayNode->GetDisplayableNode()) );
309 }
310 }
311
312 //---------------------------------------------------------------------------
313 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
314 ::UpdateWidgetDisplayTransform(
315 Pipeline* pipeline, vtkMRMLTransformNode* transformNode)
316 {
317 // WidgetDisplayTransform is in charge of moving the widget around
318 // the bounding box of the objects under the transform, wherever they
319 // are.
320 assert(pipeline && transformNode);
321
322 std::vector<vtkMRMLDisplayableNode*> transformedNodes;
323 vtkSlicerTransformLogic::GetTransformedNodes(
324 this->External->GetMRMLScene(), transformNode, transformedNodes, true);
325
326 bool validBounds = false;
327 double bounds[6];
328 if (transformedNodes.size() > 0)
329 {
330 vtkSlicerTransformLogic::GetNodesBounds(transformedNodes, bounds);
331 validBounds =
332 (bounds[0] <= bounds[1] || bounds[2] <= bounds[3] || bounds[4] <= bounds[5]);
333 }
334
335 if (validBounds)
336 {
337 // Get the bounding box around the UNTRANSFORMED objects so we have
338 // the actual box around the object.
339 double center[3], scales[3];
340 for (int i = 0; i < 3; ++i)
341 {
342 double scale = 0.5*(bounds[2*i + 1] - bounds[2*i]);
343 center[i] = bounds[2*i] + scale;
344 scales[i] = 4*scale;
345 }
346
347 pipeline->WidgetDisplayTransform->Identity();
348 pipeline->WidgetDisplayTransform->Translate(center);
349 pipeline->WidgetDisplayTransform->Scale(scales);
350 }
351 else
352 {
353 // No objects, just add a default scaling so the widget can be interacted
354 // with more easily.
355 pipeline->WidgetDisplayTransform->Identity();
356 pipeline->WidgetDisplayTransform->Scale(DEFAULT_SCALE);
357 }
358 }
359
360 //---------------------------------------------------------------------------
361 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
362 ::UpdateWidgetFromNode(vtkMRMLTransformDisplayNode* displayNode,
363 vtkMRMLTransformNode* transformNode,
364 Pipeline* pipeline)
365 {
366 assert(displayNode && transformNode && pipeline);
367
368 if (pipeline->UpdateWidgetBounds)
369 {
370 this->UpdateWidgetDisplayTransform(pipeline, transformNode);
371 pipeline->UpdateWidgetBounds = false;
372 }
373
374 vtkNew<vtkMatrix4x4> toWorldMatrix;
375 transformNode->GetMatrixTransformToWorld(toWorldMatrix.GetPointer());
376 vtkNew<vtkTransform> widgetTransform;
377 widgetTransform->Concatenate(toWorldMatrix.GetPointer());
378 widgetTransform->Concatenate(pipeline->WidgetDisplayTransform);
379
380 vtkBoxRepresentation* representation =
381 vtkBoxRepresentation::SafeDownCast(pipeline->Widget->GetRepresentation());
382
383 representation->SetTransform(widgetTransform.GetPointer());
384
385 pipeline->Widget->SetTranslationEnabled(
386 displayNode->GetEditorTranslationEnabled());
387 pipeline->Widget->SetRotationEnabled(
388 displayNode->GetEditorRotationEnabled());
389 pipeline->Widget->SetScalingEnabled(
390 displayNode->GetEditorScalingEnabled());
391 pipeline->Widget->SetMoveFacesEnabled(
392 displayNode->GetEditorScalingEnabled());
393 }
394
395 //---------------------------------------------------------------------------
396 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
397 ::UpdateNodeFromWidget(vtkBoxWidget2* widget)
398 {
399 assert(widget);
400 vtkMRMLTransformDisplayNode* displayNode = this->WidgetMap[widget];
401 assert(displayNode);
402 Pipeline* pipeline = this->DisplayPipelines[displayNode];
403 vtkMRMLTransformNode* node =
404 vtkMRMLTransformNode::SafeDownCast(displayNode->GetDisplayableNode());
405
406 vtkBoxRepresentation* representation =
407 vtkBoxRepresentation::SafeDownCast(widget->GetRepresentation());
408
409 vtkNew<vtkTransform> widgetTransform;
410 representation->GetTransform(widgetTransform.GetPointer());
411
412 vtkNew<vtkTransform> toParent;
413 vtkMRMLTransformNode* parentNode = node->GetParentTransformNode();
414 if (parentNode)
415 {
416 vtkNew<vtkMatrix4x4> worldFromParentMatrix;
417 parentNode->GetMatrixTransformFromWorld(worldFromParentMatrix.GetPointer());
418 toParent->Concatenate(worldFromParentMatrix.GetPointer());
419 }
420 toParent->Concatenate(widgetTransform.GetPointer());
421 toParent->Concatenate(pipeline->WidgetDisplayTransform->GetLinearInverse());
422
423 node->SetMatrixTransformToParent(toParent->GetMatrix());
424 }
425
426 //---------------------------------------------------------------------------
427 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
428 ::UpdateDisplayNodePipeline(
429 vtkMRMLTransformDisplayNode* displayNode,
430 Pipeline* pipeline)
431 {
432 if (!displayNode || !pipeline)
433 {
434 return;
435 }
436
437 vtkMRMLTransformNode* transformNode =
438 vtkMRMLTransformNode::SafeDownCast(displayNode->GetDisplayableNode());
439 if (transformNode==NULL)
440 {
441 pipeline->Widget->SetEnabled(false);
442 return;
443 }
444
445 if (!transformNode->IsLinear())
446 {
447 vtkWarningWithObjectMacro(transformNode,
448 "Cannot show interactive widget: Transform is not linear");
449 pipeline->Widget->SetEnabled(false);
450 return;
451 }
452
453 bool visible = displayNode->GetEditorVisibility();
454 pipeline->Widget->SetEnabled(visible);
455 if (visible)
456 {
457 this->UpdateWidgetFromNode(displayNode, transformNode, pipeline);
458 return;
459 }
460 }
461
462 //---------------------------------------------------------------------------
463 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::AddObservations(vtkMRMLTransformNode* node)
464 {
465 vtkEventBroker* broker = vtkEventBroker::GetInstance();
466 if (!broker->GetObservationExist(node, vtkMRMLDisplayableNode::DisplayModifiedEvent, this->External, this->External->GetMRMLNodesCallbackCommand() ))
467 {
468 broker->AddObservation(node, vtkMRMLDisplayableNode::DisplayModifiedEvent, this->External, this->External->GetMRMLNodesCallbackCommand() );
469 }
470 if (!broker->GetObservationExist(node, vtkMRMLTransformableNode::TransformModifiedEvent, this->External, this->External->GetMRMLNodesCallbackCommand() ))
471 {
472 broker->AddObservation(node, vtkMRMLTransformableNode::TransformModifiedEvent, this->External, this->External->GetMRMLNodesCallbackCommand() );
473 }
474 }
475
476 //---------------------------------------------------------------------------
477 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
478 ::AddDisplayObservations(vtkMRMLTransformDisplayNode* node)
479 {
480 vtkEventBroker* broker = vtkEventBroker::GetInstance();
481 if (!broker->GetObservationExist(node, vtkMRMLTransformDisplayNode::TransformUpdateEditorBoundsEvent, this->External, this->External->GetMRMLNodesCallbackCommand() ))
482 {
483 broker->AddObservation(node, vtkMRMLTransformDisplayNode::TransformUpdateEditorBoundsEvent, this->External, this->External->GetMRMLNodesCallbackCommand() );
484 }
485 }
486
487 //---------------------------------------------------------------------------
488 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::RemoveObservations(vtkMRMLTransformNode* node)
489 {
490 vtkEventBroker* broker = vtkEventBroker::GetInstance();
491 vtkEventBroker::ObservationVector observations;
492 observations = broker->GetObservations(node, vtkMRMLDisplayableNode::DisplayModifiedEvent, this->External, this->External->GetMRMLNodesCallbackCommand() );
493 observations = broker->GetObservations(node, vtkMRMLTransformableNode::TransformModifiedEvent, this->External, this->External->GetMRMLNodesCallbackCommand() );
494 broker->RemoveObservations(observations);
495 }
496
497 //---------------------------------------------------------------------------
498 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
499 ::RemoveDisplayObservations(vtkMRMLTransformDisplayNode* node)
500 {
501 vtkEventBroker* broker = vtkEventBroker::GetInstance();
502 vtkEventBroker::ObservationVector observations;
503 observations = broker->GetObservations(node, vtkMRMLTransformDisplayNode::TransformUpdateEditorBoundsEvent, this->External, this->External->GetMRMLNodesCallbackCommand() );
504 broker->RemoveObservations(observations);
505 }
506
507 //---------------------------------------------------------------------------
508 void vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::ClearDisplayableNodes()
509 {
510 while(this->TransformToDisplayNodes.size() > 0)
511 {
512 this->RemoveTransformNode(this->TransformToDisplayNodes.begin()->first);
513 }
514 }
515
516 //---------------------------------------------------------------------------
517 bool vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal::UseDisplayableNode(vtkMRMLTransformNode* node)
518 {
519 bool use = node && node->IsA("vtkMRMLTransformNode");
520 return use;
521 }
522
523 //---------------------------------------------------------------------------
524 // vtkMRMLLinearTransformsDisplayableManager3D methods
525
526 //---------------------------------------------------------------------------
527 vtkMRMLLinearTransformsDisplayableManager3D::vtkMRMLLinearTransformsDisplayableManager3D()
528 {
529 this->Internal = new vtkInternal(this);
530 }
531
532 //---------------------------------------------------------------------------
533 vtkMRMLLinearTransformsDisplayableManager3D::~vtkMRMLLinearTransformsDisplayableManager3D()
534 {
535 delete this->Internal;
536 this->Internal=NULL;
537 }
538
539 //---------------------------------------------------------------------------
540 void vtkMRMLLinearTransformsDisplayableManager3D::PrintSelf ( ostream& os, vtkIndent indent )
541 {
542 this->Superclass::PrintSelf ( os, indent );
543 os << indent << "vtkMRMLLinearTransformsDisplayableManager3D: "
544 << this->GetClassName() << "\n";
545 }
546
547 //---------------------------------------------------------------------------
548 void vtkMRMLLinearTransformsDisplayableManager3D::OnMRMLSceneNodeAdded(vtkMRMLNode* node)
549 {
550 if ( !node->IsA("vtkMRMLTransformNode") )
551 {
552 return;
553 }
554
555 // Escape if the scene a scene is being closed, imported or connected
556 if (this->GetMRMLScene()->IsBatchProcessing())
557 {
558 this->SetUpdateFromMRMLRequested(1);
559 return;
560 }
561
562 this->Internal->AddTransformNode(vtkMRMLTransformNode::SafeDownCast(node));
563 this->RequestRender();
564 }
565
566 //---------------------------------------------------------------------------
567 void vtkMRMLLinearTransformsDisplayableManager3D::OnMRMLSceneNodeRemoved(vtkMRMLNode* node)
568 {
569 if ( node
570 && (!node->IsA("vtkMRMLTransformNode"))
571 && (!node->IsA("vtkMRMLTransformDisplayNode")) )
572 {
573 return;
574 }
575
576 vtkMRMLTransformNode* transformNode = NULL;
577 vtkMRMLTransformDisplayNode* displayNode = NULL;
578
579 bool modified = false;
580 if ( (transformNode = vtkMRMLTransformNode::SafeDownCast(node)) )
581 {
582 this->Internal->RemoveTransformNode(transformNode);
583 modified = true;
584 }
585 else if ( (displayNode = vtkMRMLTransformDisplayNode::SafeDownCast(node)) )
586 {
587 this->Internal->RemoveDisplayNode(displayNode);
588 modified = true;
589 }
590 if (modified)
591 {
592 this->RequestRender();
593 }
594 }
595
596 //---------------------------------------------------------------------------
597 void vtkMRMLLinearTransformsDisplayableManager3D::ProcessMRMLNodesEvents(vtkObject* caller, unsigned long event, void* callData)
598 {
599 vtkMRMLScene* scene = this->GetMRMLScene();
600
601 if ( scene->IsBatchProcessing() )
602 {
603 return;
604 }
605
606 vtkMRMLTransformNode* displayableNode = vtkMRMLTransformNode::SafeDownCast(caller);
607 vtkMRMLTransformDisplayNode* displayNode = vtkMRMLTransformDisplayNode::SafeDownCast(caller);
608
609 if ( displayableNode )
610 {
611 vtkMRMLNode* callDataNode = reinterpret_cast<vtkMRMLDisplayNode *> (callData);
612 displayNode = vtkMRMLTransformDisplayNode::SafeDownCast(callDataNode);
613
614 if ( displayNode && (event == vtkMRMLDisplayableNode::DisplayModifiedEvent) )
615 {
616 this->Internal->UpdateDisplayNode(displayNode);
617 this->RequestRender();
618 }
619 else if (event == vtkMRMLTransformableNode::TransformModifiedEvent)
620 {
621 this->Internal->UpdateDisplayableTransforms(displayableNode, false);
622 this->RequestRender();
623 }
624 }
625 else if ( displayNode )
626 {
627 displayableNode = vtkMRMLTransformNode::SafeDownCast(displayNode->GetDisplayableNode());
628 if ( displayNode && event == vtkMRMLTransformDisplayNode::TransformUpdateEditorBoundsEvent)
629 {
630 this->Internal->UpdateDisplayableTransforms(displayableNode, true);
631 this->RequestRender();
632 }
633 }
634 else
635 {
636 this->Superclass::ProcessMRMLNodesEvents(caller, event, callData);
637 }
638 }
639
640 //---------------------------------------------------------------------------
641 void vtkMRMLLinearTransformsDisplayableManager3D::UpdateFromMRML()
642 {
643 this->SetUpdateFromMRMLRequested(0);
644
645 vtkMRMLScene* scene = this->GetMRMLScene();
646 if (!scene)
647 {
648 vtkDebugMacro( "vtkMRMLLinearTransformsDisplayableManager3D->UpdateFromMRML: Scene is not set.")
649 return;
650 }
651 this->Internal->ClearDisplayableNodes();
652
653 vtkMRMLTransformNode* mNode = NULL;
654 std::vector<vtkMRMLNode *> mNodes;
655 int nnodes = scene ? scene->GetNodesByClass("vtkMRMLTransformNode", mNodes) : 0;
656 for (int i=0; i<nnodes; i++)
657 {
658 mNode = vtkMRMLTransformNode::SafeDownCast(mNodes[i]);
659 if (mNode && this->Internal->UseDisplayableNode(mNode))
660 {
661 this->Internal->AddTransformNode(mNode);
662 }
663 }
664 this->RequestRender();
665 }
666
667 //---------------------------------------------------------------------------
668 void vtkMRMLLinearTransformsDisplayableManager3D::UnobserveMRMLScene()
669 {
670 this->Internal->ClearDisplayableNodes();
671 }
672
673 //---------------------------------------------------------------------------
674 void vtkMRMLLinearTransformsDisplayableManager3D::OnMRMLSceneStartClose()
675 {
676 this->Internal->ClearDisplayableNodes();
677 }
678
679 //---------------------------------------------------------------------------
680 void vtkMRMLLinearTransformsDisplayableManager3D::OnMRMLSceneEndClose()
681 {
682 this->SetUpdateFromMRMLRequested(1);
683 }
684
685 //---------------------------------------------------------------------------
686 void vtkMRMLLinearTransformsDisplayableManager3D::OnMRMLSceneEndBatchProcess()
687 {
688 this->SetUpdateFromMRMLRequested(1);
689 this->RequestRender();
690 }
691
692 //---------------------------------------------------------------------------
693 void vtkMRMLLinearTransformsDisplayableManager3D::Create()
694 {
695 Superclass::Create();
696 this->SetUpdateFromMRMLRequested(1);
697 }
698
699 //---------------------------------------------------------------------------
700 void vtkMRMLLinearTransformsDisplayableManager3D
701 ::ProcessWidgetsEvents(vtkObject* caller, unsigned long event, void* callData)
702 {
703 Superclass::ProcessWidgetsEvents(caller, event, callData);
704
705 vtkBoxWidget2* boxWidget = vtkBoxWidget2::SafeDownCast(caller);
706 if (boxWidget)
707 {
708 this->Internal->UpdateNodeFromWidget(boxWidget);
709 this->RequestRender();
710 }
711 }
712
713 //---------------------------------------------------------------------------
714 vtkAbstractWidget* vtkMRMLLinearTransformsDisplayableManager3D
715 ::GetWidget(vtkMRMLTransformDisplayNode* displayNode)
716 {
717 vtkMRMLLinearTransformsDisplayableManager3D::vtkInternal
718 ::PipelinesCacheType::iterator pipelineIter =
719 this->Internal->DisplayPipelines.find(displayNode);
720 if (pipelineIter != this->Internal->DisplayPipelines.end())
721 {
722 return pipelineIter->second->Widget;
723 }
724 return NULL;
725 }

  Subversion  TortoiseSVN  ViewVC