-
Notifications
You must be signed in to change notification settings - Fork 60
/
vtkSlicerRoomsEyeViewModuleLogic.cxx
1435 lines (1267 loc) · 69.7 KB
/
vtkSlicerRoomsEyeViewModuleLogic.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*==============================================================================
Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
Queen's University, Kingston, ON, Canada. 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.
This file was originally developed by Csaba Pinter, PerkLab, Queen's University
and was supported through the Applied Cancer Research Unit program of Cancer Care
Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
==============================================================================*/
// RoomsEyeView includes
#include "vtkSlicerRoomsEyeViewModuleLogic.h"
#include "vtkMRMLRoomsEyeViewNode.h"
#include "vtkSlicerIECTransformLogic.h"
// SlicerRT includes
#include "vtkMRMLRTBeamNode.h"
#include "vtkCollisionDetectionFilter.h"
// MRML includes
#include <vtkMRMLScene.h>
#include <vtkMRMLLinearTransformNode.h>
#include <vtkMRMLDisplayNode.h>
#include <vtkMRMLModelNode.h>
#include <vtkMRMLViewNode.h>
#include <vtkMRMLModelHierarchyNode.h>
#include <vtkMRMLModelDisplayNode.h>
// Slicer includes
#include <vtkSlicerModelsLogic.h>
#include <vtkSlicerSegmentationsModuleLogic.h>
// vtkSegmentationCore includes
#include <vtkSegmentationConverter.h>
// VTK includes
#include <vtkSmartPointer.h>
#include <vtkObjectFactory.h>
#include <vtkTransform.h>
#include <vtkAppendPolyData.h>
#include <vtkPolyDataReader.h>
#include <vtksys/SystemTools.hxx>
#include <vtkTransformPolyDataFilter.h>
#include <vtkGeneralTransform.h>
#include <vtkTransformFilter.h>
//----------------------------------------------------------------------------
// Treatment machine component names
const char* vtkSlicerRoomsEyeViewModuleLogic::COLLIMATOR_MODEL_NAME = "Collimator";
const char* vtkSlicerRoomsEyeViewModuleLogic::GANTRY_MODEL_NAME = "Gantry";
const char* vtkSlicerRoomsEyeViewModuleLogic::PATIENTSUPPORT_MODEL_NAME = "PatientSupport";
const char* vtkSlicerRoomsEyeViewModuleLogic::TABLETOP_MODEL_NAME = "TableTop";
const char* vtkSlicerRoomsEyeViewModuleLogic::LINACBODY_MODEL_NAME = "LinacBody";
const char* vtkSlicerRoomsEyeViewModuleLogic::IMAGINGPANELLEFT_MODEL_NAME = "ImagingPanelLeft";
const char* vtkSlicerRoomsEyeViewModuleLogic::IMAGINGPANELRIGHT_MODEL_NAME = "ImagingPanelRight";
const char* vtkSlicerRoomsEyeViewModuleLogic::FLATPANEL_MODEL_NAME = "FlatPanel";
const char* vtkSlicerRoomsEyeViewModuleLogic::APPLICATORHOLDER_MODEL_NAME = "ApplicatorHolder";
const char* vtkSlicerRoomsEyeViewModuleLogic::ELECTRONAPPLICATOR_MODEL_NAME = "ElectronApplicator";
const char* vtkSlicerRoomsEyeViewModuleLogic::ORIENTATION_MARKER_MODEL_NODE_NAME = "RoomsEyeViewOrientationMarker";
// Transform names
//TODO: Add this dynamically to the IEC transform map
static const char* ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME = "AdditionalCollimatorDevicesToCollimatorTransform";
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkSlicerRoomsEyeViewModuleLogic);
//----------------------------------------------------------------------------
vtkSlicerRoomsEyeViewModuleLogic::vtkSlicerRoomsEyeViewModuleLogic()
: GantryPatientCollisionDetection(nullptr)
, GantryTableTopCollisionDetection(nullptr)
, GantryPatientSupportCollisionDetection(nullptr)
, CollimatorPatientCollisionDetection(nullptr)
, CollimatorTableTopCollisionDetection(nullptr)
, AdditionalModelsTableTopCollisionDetection(nullptr)
, AdditionalModelsPatientSupportCollisionDetection(nullptr)
{
this->IECLogic = vtkSlicerIECTransformLogic::New();
this->GantryPatientCollisionDetection = vtkCollisionDetectionFilter::New();
this->GantryTableTopCollisionDetection = vtkCollisionDetectionFilter::New();
this->GantryPatientSupportCollisionDetection = vtkCollisionDetectionFilter::New();
this->CollimatorPatientCollisionDetection = vtkCollisionDetectionFilter::New();
this->CollimatorTableTopCollisionDetection = vtkCollisionDetectionFilter::New();
this->AdditionalModelsTableTopCollisionDetection = vtkCollisionDetectionFilter::New();
this->AdditionalModelsPatientSupportCollisionDetection = vtkCollisionDetectionFilter::New();
}
//----------------------------------------------------------------------------
vtkSlicerRoomsEyeViewModuleLogic::~vtkSlicerRoomsEyeViewModuleLogic()
{
if (this->IECLogic)
{
this->IECLogic->Delete();
this->IECLogic = nullptr;
}
if (this->GantryPatientCollisionDetection)
{
this->GantryPatientCollisionDetection->Delete();
this->GantryPatientCollisionDetection = nullptr;
}
if (this->GantryTableTopCollisionDetection)
{
this->GantryTableTopCollisionDetection->Delete();
this->GantryTableTopCollisionDetection = nullptr;
}
if (this->GantryPatientSupportCollisionDetection)
{
this->GantryPatientSupportCollisionDetection->Delete();
this->GantryPatientSupportCollisionDetection = nullptr;
}
if (this->CollimatorPatientCollisionDetection)
{
this->CollimatorPatientCollisionDetection->Delete();
this->CollimatorPatientCollisionDetection = nullptr;
}
if (this->CollimatorTableTopCollisionDetection)
{
this->CollimatorTableTopCollisionDetection->Delete();
this->CollimatorTableTopCollisionDetection = nullptr;
}
if (this->AdditionalModelsTableTopCollisionDetection)
{
this->AdditionalModelsTableTopCollisionDetection->Delete();
this->AdditionalModelsTableTopCollisionDetection = nullptr;
}
if (this->AdditionalModelsPatientSupportCollisionDetection)
{
this->AdditionalModelsPatientSupportCollisionDetection->Delete();
this->AdditionalModelsPatientSupportCollisionDetection = nullptr;
}
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::RegisterNodes()
{
vtkMRMLScene* scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("RegisterNodes: Invalid MRML scene");
return;
}
if (!scene->IsNodeClassRegistered("vtkMRMLRoomsEyeViewNode"))
{
scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLRoomsEyeViewNode>::New());
}
}
//---------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::SetMRMLSceneInternal(vtkMRMLScene* newScene)
{
this->Superclass::SetMRMLSceneInternal(newScene);
this->IECLogic->SetMRMLScene(newScene);
}
//---------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::BuildRoomsEyeViewTransformHierarchy()
{
vtkMRMLScene* scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("BuildRoomsEyeViewTransformHierarchy: Invalid MRML scene");
return;
}
// Build IEC hierarchy
//TODO: Add the REV transform to the IEC transform map and use it for the GetTransform... functions
this->IECLogic->BuildIECTransformHierarchy();
// Create transform nodes if they do not exist
vtkSmartPointer<vtkMRMLLinearTransformNode> additionalCollimatorDevicesToCollimatorTransformNode;
if (!scene->GetFirstNodeByName(ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME))
{
additionalCollimatorDevicesToCollimatorTransformNode = vtkSmartPointer<vtkMRMLLinearTransformNode>::New();
additionalCollimatorDevicesToCollimatorTransformNode->SetName(ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME);
additionalCollimatorDevicesToCollimatorTransformNode->SetHideFromEditors(1);
std::string singletonTag = std::string("IEC_") + ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME;
additionalCollimatorDevicesToCollimatorTransformNode->SetSingletonTag(singletonTag.c_str());
scene->AddNode(additionalCollimatorDevicesToCollimatorTransformNode);
}
else
{
additionalCollimatorDevicesToCollimatorTransformNode = vtkMRMLLinearTransformNode::SafeDownCast(
scene->GetFirstNodeByName(ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME));
}
// Get IEC transform nodes that are used below
vtkMRMLLinearTransformNode* collimatorToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Collimator, vtkSlicerIECTransformLogic::Gantry);
if (!collimatorToGantryTransformNode)
{
vtkErrorMacro("BuildRoomsEyeViewTransformHierarchy: Failed to access collimatorToGantryTransformNode");
return;
}
// Organize transforms into hierarchy
additionalCollimatorDevicesToCollimatorTransformNode->SetAndObserveTransformNodeID(collimatorToGantryTransformNode->GetID());
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::LoadTreatmentMachineModels(vtkMRMLRoomsEyeViewNode* parameterNode)
{
vtkMRMLScene* scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("LoadTreatmentMachineModels: Invalid scene");
return;
}
if (!parameterNode || !parameterNode->GetTreatmentMachineType())
{
vtkErrorMacro("LoadTreatmentMachineModels: Invalid parameter node");
return;
}
// Make sure the transform hierarchy is in place
this->BuildRoomsEyeViewTransformHierarchy();
std::string moduleShareDirectory = this->GetModuleShareDirectory();
std::string machineType(parameterNode->GetTreatmentMachineType());
std::string treatmentMachineModelsDirectory = moduleShareDirectory + "/" + machineType;
// Create a models logic for convenient loading of components
vtkNew<vtkSlicerModelsLogic> modelsLogic;
modelsLogic->SetMRMLScene(scene);
// Create model hierarchy so that the treatment machine can be shown/hidden easily
std::string rootModelHierarchyNodeName = machineType + std::string("_Components");
vtkSmartPointer<vtkMRMLModelHierarchyNode> rootModelHierarchyNode = vtkMRMLModelHierarchyNode::SafeDownCast(
scene->GetSingletonNode(rootModelHierarchyNodeName.c_str(), "vtkMRMLModelHierarchyNode") );
if (!rootModelHierarchyNode)
{
rootModelHierarchyNode = vtkSmartPointer<vtkMRMLModelHierarchyNode>::New();
scene->AddNode(rootModelHierarchyNode);
rootModelHierarchyNode->SetName(rootModelHierarchyNodeName.c_str());
rootModelHierarchyNode->SetSingletonTag(rootModelHierarchyNodeName.c_str());
}
if (!rootModelHierarchyNode->GetDisplayNode())
{
vtkSmartPointer<vtkMRMLModelDisplayNode> rootModelHierarchyDisplayNode = vtkSmartPointer<vtkMRMLModelDisplayNode>::New();
scene->AddNode(rootModelHierarchyDisplayNode);
rootModelHierarchyNode->SetAndObserveDisplayNodeID( rootModelHierarchyDisplayNode->GetID() );
}
//
// Load treatment machine models
// Collimator - mandatory
std::string collimatorModelSingletonTag = machineType + "_" + COLLIMATOR_MODEL_NAME;
vtkMRMLModelNode* collimatorModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(collimatorModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (collimatorModelNode && !collimatorModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(collimatorModelNode);
collimatorModelNode = nullptr;
}
if (!collimatorModelNode)
{
std::string collimatorModelFilePath = treatmentMachineModelsDirectory + "/" + COLLIMATOR_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(collimatorModelFilePath))
{
collimatorModelNode = modelsLogic->AddModel(collimatorModelFilePath.c_str());
}
if (collimatorModelNode)
{
collimatorModelNode->SetSingletonTag(collimatorModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> collimatorModelHierarchyNode;
scene->AddNode(collimatorModelHierarchyNode);
collimatorModelHierarchyNode->SetModelNodeID(collimatorModelNode->GetID());
collimatorModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
collimatorModelHierarchyNode->HideFromEditorsOn();
}
else
{
vtkErrorMacro("LoadTreatmentMachineModels: Failed to load collimator model");
}
}
// Gantry - mandatory
std::string gantryModelSingletonTag = machineType + "_" + GANTRY_MODEL_NAME;
vtkMRMLModelNode* gantryModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(gantryModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (gantryModelNode && !gantryModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(gantryModelNode);
gantryModelNode = nullptr;
}
if (!gantryModelNode)
{
std::string gantryModelFilePath = treatmentMachineModelsDirectory + "/" + GANTRY_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(gantryModelFilePath))
{
gantryModelNode = modelsLogic->AddModel(gantryModelFilePath.c_str());
}
if (gantryModelNode)
{
gantryModelNode->SetSingletonTag(gantryModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> gantryModelHierarchyNode;
scene->AddNode(gantryModelHierarchyNode);
gantryModelHierarchyNode->SetModelNodeID(gantryModelNode->GetID());
gantryModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
gantryModelHierarchyNode->HideFromEditorsOn();
}
else
{
vtkErrorMacro("LoadTreatmentMachineModels: Failed to load gantry model");
}
}
// Patient support - mandatory
std::string patientSupportModelSingletonTag = machineType + "_" + PATIENTSUPPORT_MODEL_NAME;
vtkMRMLModelNode* patientSupportModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(patientSupportModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (patientSupportModelNode && !patientSupportModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(patientSupportModelNode);
patientSupportModelNode = nullptr;
}
if (!patientSupportModelNode)
{
std::string patientSupportModelFilePath = treatmentMachineModelsDirectory + "/" + PATIENTSUPPORT_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(patientSupportModelFilePath))
{
patientSupportModelNode = modelsLogic->AddModel(patientSupportModelFilePath.c_str());
}
if (patientSupportModelNode)
{
patientSupportModelNode->SetSingletonTag(patientSupportModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> patientSupportModelHierarchyNode;
scene->AddNode(patientSupportModelHierarchyNode);
patientSupportModelHierarchyNode->SetModelNodeID(patientSupportModelNode->GetID());
patientSupportModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
patientSupportModelHierarchyNode->HideFromEditorsOn();
}
else
{
vtkErrorMacro("LoadTreatmentMachineModels: Failed to load patient support model");
}
}
// Table top - mandatory
std::string tableTopModelSingletonTag = machineType + "_" + TABLETOP_MODEL_NAME;
vtkMRMLModelNode* tableTopModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(tableTopModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (tableTopModelNode && !tableTopModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(tableTopModelNode);
tableTopModelNode = nullptr;
}
if (!tableTopModelNode)
{
std::string tableTopModelFilePath = treatmentMachineModelsDirectory + "/" + TABLETOP_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(tableTopModelFilePath))
{
tableTopModelNode = modelsLogic->AddModel(tableTopModelFilePath.c_str());
}
if (tableTopModelNode)
{
tableTopModelNode->SetSingletonTag(tableTopModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> tableTopModelHierarchyNode;
scene->AddNode(tableTopModelHierarchyNode);
tableTopModelHierarchyNode->SetModelNodeID(tableTopModelNode->GetID());
tableTopModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
tableTopModelHierarchyNode->HideFromEditorsOn();
}
else
{
vtkErrorMacro("LoadTreatmentMachineModels: Failed to load table top model");
}
}
// Linac body - optional
std::string linacBodyModelSingletonTag = machineType + "_" + LINACBODY_MODEL_NAME;
vtkMRMLModelNode* linacBodyModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(linacBodyModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (linacBodyModelNode && !linacBodyModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(linacBodyModelNode);
linacBodyModelNode = nullptr;
}
if (!linacBodyModelNode)
{
std::string linacBodyModelFilePath = treatmentMachineModelsDirectory + "/" + LINACBODY_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(linacBodyModelFilePath))
{
linacBodyModelNode = modelsLogic->AddModel(linacBodyModelFilePath.c_str());
}
if (linacBodyModelNode)
{
linacBodyModelNode->SetSingletonTag(linacBodyModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> linacBodyModelHierarchyNode;
scene->AddNode(linacBodyModelHierarchyNode);
linacBodyModelHierarchyNode->SetModelNodeID(linacBodyModelNode->GetID());
linacBodyModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
linacBodyModelHierarchyNode->HideFromEditorsOn();
}
}
// Imaging panel left - optional
std::string imagingPanelLeftModelSingletonTag = machineType + "_" + IMAGINGPANELLEFT_MODEL_NAME;
vtkMRMLModelNode* imagingPanelLeftModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(imagingPanelLeftModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (imagingPanelLeftModelNode && !imagingPanelLeftModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(imagingPanelLeftModelNode);
imagingPanelLeftModelNode = nullptr;
}
if (!imagingPanelLeftModelNode)
{
std::string imagingPanelLeftModelFilePath = treatmentMachineModelsDirectory + "/" + IMAGINGPANELLEFT_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(imagingPanelLeftModelFilePath))
{
imagingPanelLeftModelNode = modelsLogic->AddModel(imagingPanelLeftModelFilePath.c_str());
}
if (imagingPanelLeftModelNode)
{
imagingPanelLeftModelNode->SetSingletonTag(imagingPanelLeftModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> imagingPanelLeftModelHierarchyNode;
scene->AddNode(imagingPanelLeftModelHierarchyNode);
imagingPanelLeftModelHierarchyNode->SetModelNodeID(imagingPanelLeftModelNode->GetID());
imagingPanelLeftModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
imagingPanelLeftModelHierarchyNode->HideFromEditorsOn();
}
}
// Imaging panel right - optional
std::string imagingPanelRightModelSingletonTag = machineType + "_" + IMAGINGPANELRIGHT_MODEL_NAME;
vtkMRMLModelNode* imagingPanelRightModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(imagingPanelRightModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (imagingPanelRightModelNode && !imagingPanelRightModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(imagingPanelRightModelNode);
imagingPanelRightModelNode = nullptr;
}
if (!imagingPanelRightModelNode)
{
std::string imagingPanelRightModelFilePath = treatmentMachineModelsDirectory + "/" + IMAGINGPANELRIGHT_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(imagingPanelRightModelFilePath))
{
imagingPanelRightModelNode = modelsLogic->AddModel(imagingPanelRightModelFilePath.c_str());
}
if (imagingPanelRightModelNode)
{
imagingPanelRightModelNode->SetSingletonTag(imagingPanelRightModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> imagingPanelRightModelHierarchyNode;
scene->AddNode(imagingPanelRightModelHierarchyNode);
imagingPanelRightModelHierarchyNode->SetModelNodeID(imagingPanelRightModelNode->GetID());
imagingPanelRightModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
imagingPanelRightModelHierarchyNode->HideFromEditorsOn();
}
}
// Flat panel - optional
std::string flatPanelModelSingletonTag = machineType + "_" + FLATPANEL_MODEL_NAME;
vtkMRMLModelNode* flatPanelModelNode = vtkMRMLModelNode::SafeDownCast(
scene->GetSingletonNode(flatPanelModelSingletonTag.c_str(), "vtkMRMLModelNode") );
if (flatPanelModelNode && !flatPanelModelNode->GetPolyData())
{
// Remove node if contains empty polydata (e.g. after closing scene), so that it can be loaded again
scene->RemoveNode(flatPanelModelNode);
flatPanelModelNode = nullptr;
}
if (!flatPanelModelNode)
{
std::string flatPanelModelFilePath = treatmentMachineModelsDirectory + "/" + FLATPANEL_MODEL_NAME + ".stl";
if (vtksys::SystemTools::FileExists(flatPanelModelFilePath))
{
flatPanelModelNode = modelsLogic->AddModel(flatPanelModelFilePath.c_str());
}
if (flatPanelModelNode)
{
flatPanelModelNode->SetSingletonTag(flatPanelModelSingletonTag.c_str());
vtkNew<vtkMRMLModelHierarchyNode> flatPanelModelHierarchyNode;
scene->AddNode(flatPanelModelHierarchyNode);
flatPanelModelHierarchyNode->SetModelNodeID(flatPanelModelNode->GetID());
flatPanelModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
flatPanelModelHierarchyNode->HideFromEditorsOn();
}
}
if ( !collimatorModelNode || !collimatorModelNode->GetPolyData()
|| !gantryModelNode || !gantryModelNode->GetPolyData()
|| !patientSupportModelNode || !patientSupportModelNode->GetPolyData()
|| !tableTopModelNode || !tableTopModelNode->GetPolyData() )
{
vtkErrorMacro("LoadTreatmentMachineModels: Failed to load every mandatory treatment machine component");
return;
}
// Setup treatment machine model display and transforms
this->SetupTreatmentMachineModels();
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::SetupTreatmentMachineModels()
{
if (!this->GetMRMLScene())
{
vtkErrorMacro("SetupTreatmentMachineModels: Invalid scene");
return;
}
//TODO: Store treatment machine component color and other properties in JSON
// Display all pieces of the treatment room and sets each piece a color to provide realistic representation
// Gantry - mandatory
vtkMRMLModelNode* gantryModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(GANTRY_MODEL_NAME) );
if (!gantryModel)
{
vtkErrorMacro("SetupTreatmentMachineModels: Unable to access gantry model");
return;
}
vtkMRMLLinearTransformNode* gantryToFixedReferenceTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Gantry, vtkSlicerIECTransformLogic::FixedReference);
gantryModel->SetAndObserveTransformNodeID(gantryToFixedReferenceTransformNode->GetID());
gantryModel->CreateDefaultDisplayNodes();
gantryModel->GetDisplayNode()->SetColor(0.95, 0.95, 0.95);
// Collimator - mandatory
vtkMRMLModelNode* collimatorModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(COLLIMATOR_MODEL_NAME) );
if (!collimatorModel)
{
vtkErrorMacro("SetupTreatmentMachineModels: Unable to access collimator model");
return;
}
vtkMRMLLinearTransformNode* collimatorToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Collimator, vtkSlicerIECTransformLogic::Gantry);
collimatorModel->SetAndObserveTransformNodeID(collimatorToGantryTransformNode->GetID());
collimatorModel->CreateDefaultDisplayNodes();
collimatorModel->GetDisplayNode()->SetColor(0.7, 0.7, 0.95);
// Patient support - mandatory
vtkMRMLModelNode* patientSupportModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(PATIENTSUPPORT_MODEL_NAME) );
if (!patientSupportModel)
{
vtkErrorMacro("SetupTreatmentMachineModels: Unable to access patient support model");
return;
}
vtkMRMLLinearTransformNode* patientSupportToPatientSupportRotationTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::PatientSupport, vtkSlicerIECTransformLogic::PatientSupportRotation);
patientSupportModel->SetAndObserveTransformNodeID(patientSupportToPatientSupportRotationTransformNode->GetID());
patientSupportModel->CreateDefaultDisplayNodes();
patientSupportModel->GetDisplayNode()->SetColor(0.85, 0.85, 0.85);
// Table top - mandatory
vtkMRMLModelNode* tableTopModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(TABLETOP_MODEL_NAME) );
if (!tableTopModel)
{
vtkErrorMacro("SetupTreatmentMachineModels: Unable to access table top model");
return;
}
vtkMRMLLinearTransformNode* tableTopToTableTopEccentricRotationTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::TableTop, vtkSlicerIECTransformLogic::TableTopEccentricRotation);
tableTopModel->SetAndObserveTransformNodeID(tableTopToTableTopEccentricRotationTransformNode->GetID());
tableTopModel->CreateDefaultDisplayNodes();
tableTopModel->GetDisplayNode()->SetColor(0, 0, 0);
// Linac body - optional
vtkMRMLModelNode* linacBodyModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(LINACBODY_MODEL_NAME) );
if (linacBodyModel)
{
vtkMRMLLinearTransformNode* fixedReferenceToRasTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::FixedReference, vtkSlicerIECTransformLogic::RAS);
linacBodyModel->SetAndObserveTransformNodeID(fixedReferenceToRasTransformNode->GetID());
linacBodyModel->CreateDefaultDisplayNodes();
linacBodyModel->GetDisplayNode()->SetColor(0.9, 0.9, 0.9);
}
// Imaging panel left - optional
vtkMRMLModelNode* leftImagingPanelModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(IMAGINGPANELLEFT_MODEL_NAME) );
if (leftImagingPanelModel)
{
vtkMRMLLinearTransformNode* leftImagingPanelToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::LeftImagingPanel, vtkSlicerIECTransformLogic::Gantry);
leftImagingPanelModel->SetAndObserveTransformNodeID(leftImagingPanelToGantryTransformNode->GetID());
leftImagingPanelModel->CreateDefaultDisplayNodes();
leftImagingPanelModel->GetDisplayNode()->SetColor(0.95, 0.95, 0.95);
}
// Imaging panel right - optional
vtkMRMLModelNode* rightImagingPanelModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(IMAGINGPANELRIGHT_MODEL_NAME) );
if (rightImagingPanelModel)
{
vtkMRMLLinearTransformNode* rightImagingPanelToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::RightImagingPanel, vtkSlicerIECTransformLogic::Gantry);
rightImagingPanelModel->SetAndObserveTransformNodeID(rightImagingPanelToGantryTransformNode->GetID());
rightImagingPanelModel->CreateDefaultDisplayNodes();
rightImagingPanelModel->GetDisplayNode()->SetColor(0.95, 0.95, 0.95);
}
// Flat panel - optional
vtkMRMLModelNode* flatPanelModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(FLATPANEL_MODEL_NAME) );
if (flatPanelModel)
{
vtkMRMLLinearTransformNode* flatPanelToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::FlatPanel, vtkSlicerIECTransformLogic::Gantry);
flatPanelModel->SetAndObserveTransformNodeID(flatPanelToGantryTransformNode->GetID());
flatPanelModel->CreateDefaultDisplayNodes();
flatPanelModel->GetDisplayNode()->SetColor(0.95, 0.95, 0.95);
}
//
// Set up collision detection between components
this->GantryTableTopCollisionDetection->SetInputData(0, gantryModel->GetPolyData());
this->GantryTableTopCollisionDetection->SetInputData(1, tableTopModel->GetPolyData());
this->GantryPatientSupportCollisionDetection->SetInputData(0, gantryModel->GetPolyData());
this->GantryPatientSupportCollisionDetection->SetInputData(1, patientSupportModel->GetPolyData());
this->CollimatorTableTopCollisionDetection->SetInputData(0, collimatorModel->GetPolyData());
this->CollimatorTableTopCollisionDetection->SetInputData(1, tableTopModel->GetPolyData());
//TODO: Whole patient (segmentation, CT) will need to be transformed when the table top is transformed
//vtkMRMLLinearTransformNode* patientModelTransforms = vtkMRMLLinearTransformNode::SafeDownCast(
// this->GetMRMLScene()->GetFirstNodeByName("TableTopEccentricRotationToPatientSupportTransform"));
//patientModel->SetAndObserveTransformNodeID(patientModelTransforms->GetID());
// Patient model is set when calculating collisions, as it can be changed dynamically
this->GantryPatientCollisionDetection->SetInputData(0, gantryModel->GetPolyData());
this->CollimatorPatientCollisionDetection->SetInputData(0, collimatorModel->GetPolyData());
// Set identity transform for patient (parent transform is taken into account when getting poly data from segmentation)
vtkNew<vtkTransform> identityTransform;
identityTransform->Identity();
this->GantryPatientCollisionDetection->SetTransform(1, vtkLinearTransform::SafeDownCast(identityTransform));
this->CollimatorPatientCollisionDetection->SetTransform(1, vtkLinearTransform::SafeDownCast(identityTransform));
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::LoadBasicCollimatorMountedDevices()
{
if (!this->GetMRMLScene())
{
vtkErrorMacro("LoadBasicCollimatorMountedDevices: Invalid scene");
return;
}
std::string moduleShareDirectory = this->GetModuleShareDirectory();
std::string additionalDevicesDirectory = moduleShareDirectory + "/" + "AdditionalTreatmentModels";
// Create a models logic for convenient loading of components
vtkNew<vtkSlicerModelsLogic> modelsLogic;
modelsLogic->SetMRMLScene(this->GetMRMLScene());
// Create model hierarchy so that the treatment machine can be shown/hidden easily
vtkNew<vtkMRMLModelHierarchyNode> rootModelHierarchyNode;
this->GetMRMLScene()->AddNode(rootModelHierarchyNode);
rootModelHierarchyNode->SetName("Additional treatment machine devices");
vtkNew<vtkMRMLModelDisplayNode> rootModelHierarchyDisplayNode;
this->GetMRMLScene()->AddNode(rootModelHierarchyDisplayNode);
rootModelHierarchyNode->SetAndObserveDisplayNodeID( rootModelHierarchyDisplayNode->GetID() );
//
// Load basic additional device models
std::string applicatorHolderModelFilePath = additionalDevicesDirectory + "/" + APPLICATORHOLDER_MODEL_NAME + ".stl";
vtkMRMLModelNode* applicatorHolderModelNode = modelsLogic->AddModel(applicatorHolderModelFilePath.c_str());
vtkNew<vtkMRMLModelHierarchyNode> applicatorHolderModelHierarchyNode;
this->GetMRMLScene()->AddNode(applicatorHolderModelHierarchyNode);
applicatorHolderModelHierarchyNode->SetModelNodeID(applicatorHolderModelNode->GetID());
applicatorHolderModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
applicatorHolderModelHierarchyNode->HideFromEditorsOn();
applicatorHolderModelHierarchyNode->SetSingletonTag("BasicCollimatorMountedDevices");
std::string electronApplicatorModelFilePath = additionalDevicesDirectory + "/" + ELECTRONAPPLICATOR_MODEL_NAME + ".stl";
vtkMRMLModelNode* electronApplicatorModelNode = modelsLogic->AddModel(electronApplicatorModelFilePath.c_str());
vtkNew<vtkMRMLModelHierarchyNode> electronApplicatorModelHierarchyNode;
this->GetMRMLScene()->AddNode(electronApplicatorModelHierarchyNode);
electronApplicatorModelHierarchyNode->SetModelNodeID(electronApplicatorModelNode->GetID());
electronApplicatorModelHierarchyNode->SetParentNodeID(rootModelHierarchyNode->GetID());
electronApplicatorModelHierarchyNode->HideFromEditorsOn();
electronApplicatorModelHierarchyNode->SetSingletonTag("BasicCollimatorMountedDevices");
// Setup basic additional device model display and transforms
this->SetupBasicCollimatorMountedDeviceModels();
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::SetupBasicCollimatorMountedDeviceModels()
{
if (!this->GetMRMLScene())
{
vtkErrorMacro("SetupBasicCollimatorMountedDeviceModels: Invalid scene");
return;
}
//TODO: Separate to a function and call it from LoadBasicCollimatorMountedDevices
vtkMRMLModelNode* applicatorHolderModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(APPLICATORHOLDER_MODEL_NAME));
if (!applicatorHolderModel)
{
vtkErrorMacro("SetupBasicCollimatorMountedDeviceModels: Unable to access applicator holder model");
return;
}
vtkMRMLLinearTransformNode* applicatorHolderModelTransformNode = vtkMRMLLinearTransformNode::SafeDownCast( //TODO:
this->GetMRMLScene()->GetFirstNodeByName(ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME));
applicatorHolderModel->SetAndObserveTransformNodeID(applicatorHolderModelTransformNode->GetID());
applicatorHolderModel->CreateDefaultDisplayNodes();
applicatorHolderModel->GetDisplayNode()->VisibilityOff();
vtkMRMLModelNode* electronApplicatorModel = vtkMRMLModelNode::SafeDownCast(
this->GetMRMLScene()->GetFirstNodeByName(ELECTRONAPPLICATOR_MODEL_NAME));
if (!electronApplicatorModel)
{
vtkErrorMacro("SetupBasicCollimatorMountedDeviceModels: Unable to access electron applicator model");
return;
}
vtkMRMLLinearTransformNode* electronApplicatorModelTransformNode = vtkMRMLLinearTransformNode::SafeDownCast( //TODO:
this->GetMRMLScene()->GetFirstNodeByName(ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME));
electronApplicatorModel->SetAndObserveTransformNodeID(electronApplicatorModelTransformNode->GetID());
electronApplicatorModel->CreateDefaultDisplayNodes();
electronApplicatorModel->GetDisplayNode()->VisibilityOff();
//TODO: Additional device collision detection is broken, because the transforms of the additional devices are not
// taken into account, so the appended model will contain randomly placed devices
//TODO: Add additional models to patient collision detection
//vtkSmartPointer<vtkAppendPolyData> additionalDeviceAppending = vtkSmartPointer<vtkAppendPolyData>::New();
//vtkPolyData* inputs[] = { applicatorHolderModel->GetPolyData(), electronApplicatorModel->GetPolyData() };
//vtkSmartPointer<vtkPolyData> output = vtkSmartPointer<vtkPolyData>::New();
//vtkSmartPointer<vtkMRMLModelNode> outputModel = vtkSmartPointer<vtkMRMLModelNode>::New();
//additionalDeviceAppending->ExecuteAppend(output, inputs, 2);
//this->GetMRMLScene()->AddNode(outputModel);
//outputModel->SetAndObservePolyData(output);
//this->AdditionalModelsTableTopCollisionDetection->SetInputData(0, outputModel->GetPolyData());
//this->AdditionalModelsTableTopCollisionDetection->SetInputData(1, tableTopModel->GetPolyData());
//this->AdditionalModelsTableTopCollisionDetection->SetMatrix(0, this->CollimatorToWorldTransformMatrix);
//this->AdditionalModelsTableTopCollisionDetection->SetMatrix(1, this->TableTopToWorldTransformMatrix);
//this->AdditionalModelsTableTopCollisionDetection->Update();
//this->AdditionalModelsPatientSupportCollisionDetection->SetInputData(0, outputModel->GetPolyData());
//this->AdditionalModelsPatientSupportCollisionDetection->SetInputData(1, patientSupportModel->GetPolyData());
//this->AdditionalModelsPatientSupportCollisionDetection->SetMatrix(0, this->CollimatorToWorldTransformMatrix);
//this->AdditionalModelsPatientSupportCollisionDetection->SetMatrix(1, this->TableTopToWorldTransformMatrix);
//this->AdditionalModelsPatientSupportCollisionDetection->Update();
}
//-----------------------------------------------------------------------------
vtkMRMLModelNode* vtkSlicerRoomsEyeViewModuleLogic::UpdateTreatmentOrientationMarker()
{
vtkNew<vtkAppendPolyData> appendFilter;
vtkMRMLModelNode* gantryModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(GANTRY_MODEL_NAME));
vtkMRMLModelNode* collimatorModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(COLLIMATOR_MODEL_NAME));
vtkMRMLModelNode* patientSupportModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(PATIENTSUPPORT_MODEL_NAME));
vtkMRMLModelNode* tableTopModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(TABLETOP_MODEL_NAME));
if ( !gantryModel->GetPolyData() || !collimatorModel->GetPolyData() || !patientSupportModel->GetPolyData() || !tableTopModel->GetPolyData() )
{
// Orientation marker cannot be assembled if poly data is missing from the mandatory model nodes.
// This is possible and can be completely valid, for example after closing the scene (because the model nodes are singletons)
return nullptr;
}
//
// Mandatory models
// Gantry
vtkNew<vtkPolyData> gantryModelPolyData;
gantryModelPolyData->DeepCopy(gantryModel->GetPolyData());
vtkMRMLLinearTransformNode* gantryToFixedReferenceTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Gantry, vtkSlicerIECTransformLogic::FixedReference);
vtkNew<vtkTransformFilter> gantryTransformFilter;
gantryTransformFilter->SetInputData(gantryModelPolyData);
vtkNew<vtkGeneralTransform> gantryToFixedReferenceTransform;
gantryToFixedReferenceTransformNode->GetTransformFromWorld(gantryToFixedReferenceTransform);
gantryToFixedReferenceTransform->Inverse();
gantryTransformFilter->SetTransform(gantryToFixedReferenceTransform);
gantryTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(gantryTransformFilter->GetOutput()));
// Collimator
vtkNew<vtkPolyData> collimatorModelPolyData;
collimatorModelPolyData->DeepCopy(collimatorModel->GetPolyData());
vtkMRMLLinearTransformNode* collimatorToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Collimator, vtkSlicerIECTransformLogic::Gantry);
vtkNew<vtkTransformFilter> collimatorTransformFilter;
collimatorTransformFilter->SetInputData(collimatorModelPolyData);
vtkNew<vtkGeneralTransform> collimatorToGantryTransform;
collimatorToGantryTransformNode->GetTransformFromWorld(collimatorToGantryTransform);
collimatorToGantryTransform->Inverse();
collimatorTransformFilter->SetTransform(collimatorToGantryTransform);
collimatorTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(collimatorTransformFilter->GetOutput()));
// Patient support
vtkNew<vtkPolyData> patientSupportModelPolyData;
patientSupportModelPolyData->DeepCopy(patientSupportModel->GetPolyData());
vtkMRMLLinearTransformNode* patientSupportToPatientSupportRotationTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::PatientSupport, vtkSlicerIECTransformLogic::PatientSupportRotation);
vtkNew<vtkTransformFilter> patientSupportTransformFilter;
patientSupportTransformFilter->SetInputData(patientSupportModelPolyData);
vtkNew<vtkGeneralTransform> patientSupportToPatientSupportRotationTransform;
patientSupportToPatientSupportRotationTransformNode->GetTransformFromWorld(patientSupportToPatientSupportRotationTransform);
patientSupportToPatientSupportRotationTransform->Inverse();
patientSupportTransformFilter->SetTransform(patientSupportToPatientSupportRotationTransform);
patientSupportTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(patientSupportTransformFilter->GetOutput()));
// Table top
vtkNew<vtkPolyData> tableTopModelPolyData;
tableTopModelPolyData->DeepCopy(tableTopModel->GetPolyData());
vtkMRMLLinearTransformNode* tableTopToTableTopEccentricRotationTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::TableTop, vtkSlicerIECTransformLogic::TableTopEccentricRotation);
vtkNew<vtkTransformFilter> tableTopTransformFilter;
tableTopTransformFilter->SetInputData(tableTopModelPolyData);
vtkNew<vtkGeneralTransform> tableTopModelTransform;
tableTopToTableTopEccentricRotationTransformNode->GetTransformFromWorld(tableTopModelTransform);
tableTopModelTransform->Inverse();
tableTopTransformFilter->SetTransform(tableTopModelTransform);
tableTopTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(tableTopTransformFilter->GetOutput()));
// Optional models
vtkMRMLModelNode* leftImagingPanelModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(IMAGINGPANELLEFT_MODEL_NAME));
if (leftImagingPanelModel)
{
vtkNew<vtkPolyData> leftImagingPanelModelPolyData;
leftImagingPanelModelPolyData->DeepCopy(leftImagingPanelModel->GetPolyData());
vtkMRMLLinearTransformNode* leftImagingPanelToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::LeftImagingPanel, vtkSlicerIECTransformLogic::Gantry);
vtkNew<vtkTransformFilter> leftImagingPanelTransformFilter;
leftImagingPanelTransformFilter->SetInputData(leftImagingPanelModelPolyData);
vtkNew<vtkGeneralTransform> leftImagingPanelToGantryTransform;
leftImagingPanelToGantryTransformNode->GetTransformFromWorld(leftImagingPanelToGantryTransform);
leftImagingPanelToGantryTransform->Inverse();
leftImagingPanelTransformFilter->SetTransform(leftImagingPanelToGantryTransform);
leftImagingPanelTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(leftImagingPanelTransformFilter->GetOutput()));
}
vtkMRMLModelNode* rightImagingPanelModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(IMAGINGPANELRIGHT_MODEL_NAME));
if (rightImagingPanelModel)
{
vtkNew<vtkPolyData> rightImagingPanelModelPolyData;
rightImagingPanelModelPolyData->DeepCopy(rightImagingPanelModel->GetPolyData());
vtkMRMLLinearTransformNode* rightImagingPanelToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::RightImagingPanel, vtkSlicerIECTransformLogic::Gantry);
vtkNew<vtkTransformFilter> rightImagingPanelTransformFilter;
rightImagingPanelTransformFilter->SetInputData(rightImagingPanelModelPolyData);
vtkNew<vtkGeneralTransform> rightImagingPanelToGantryTransform;
rightImagingPanelToGantryTransformNode->GetTransformFromWorld(rightImagingPanelToGantryTransform);
rightImagingPanelToGantryTransform->Inverse();
rightImagingPanelTransformFilter->SetTransform(rightImagingPanelToGantryTransform);
rightImagingPanelTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(rightImagingPanelTransformFilter->GetOutput()));
}
vtkMRMLModelNode* flatPanelModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(FLATPANEL_MODEL_NAME));
if (flatPanelModel)
{
vtkNew<vtkPolyData> flatPanelModelPolyData;
flatPanelModelPolyData->DeepCopy(flatPanelModel->GetPolyData());
vtkMRMLLinearTransformNode* flatPanelToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::FlatPanel, vtkSlicerIECTransformLogic::Gantry);
vtkNew<vtkTransformFilter> flatPanelTransformFilter;
flatPanelTransformFilter->SetInputData(flatPanelModelPolyData);
vtkNew<vtkGeneralTransform> flatPanelToGantryTransform;
flatPanelToGantryTransformNode->GetTransformFromWorld(flatPanelToGantryTransform);
flatPanelToGantryTransform->Inverse();
flatPanelTransformFilter->SetTransform(flatPanelToGantryTransform);
flatPanelTransformFilter->Update();
appendFilter->AddInputData(vtkPolyData::SafeDownCast(flatPanelTransformFilter->GetOutput()));
}
vtkNew<vtkPolyData> orientationMarkerPolyData;
appendFilter->Update();
orientationMarkerPolyData->DeepCopy(appendFilter->GetOutput());
// Get or create orientation marker model node
vtkSmartPointer<vtkMRMLModelNode> orientationMarkerModel =
vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(ORIENTATION_MARKER_MODEL_NODE_NAME));
if (!orientationMarkerModel)
{
orientationMarkerModel = vtkSmartPointer<vtkMRMLModelNode>::New();
orientationMarkerModel->SetName(ORIENTATION_MARKER_MODEL_NODE_NAME);
this->GetMRMLScene()->AddNode(orientationMarkerModel);
}
orientationMarkerModel->SetAndObservePolyData(orientationMarkerPolyData);
return orientationMarkerModel.GetPointer();
}
//----------------------------------------------------------------------------
bool vtkSlicerRoomsEyeViewModuleLogic::GetPatientBodyPolyData(vtkMRMLRoomsEyeViewNode* parameterNode, vtkPolyData* patientBodyPolyData)
{
if (!parameterNode)
{
vtkErrorMacro("GetPatientBodyPolyData: Invalid parameter set node");
return false;
}
if (!patientBodyPolyData)
{
vtkErrorMacro("GetPatientBodyPolyData: Invalid output poly data");
return false;
}
// Get patient body segmentation
vtkMRMLSegmentationNode* segmentationNode = parameterNode->GetPatientBodySegmentationNode();
if (!segmentationNode || !parameterNode->GetPatientBodySegmentID())
{
return false;
}
// Get closed surface representation for patient body
return vtkSlicerSegmentationsModuleLogic::GetSegmentRepresentation(
segmentationNode, parameterNode->GetPatientBodySegmentID(),
vtkSegmentationConverter::GetSegmentationClosedSurfaceRepresentationName(),
patientBodyPolyData );
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::UpdateCollimatorToGantryTransform(vtkMRMLRoomsEyeViewNode* parameterNode)
{
if (!parameterNode)
{
vtkErrorMacro("UpdateFixedReferenceIsocenterToCollimatorRotatedTransform: Invalid parameter set node");
return;
}
vtkMRMLLinearTransformNode* collimatorToGantryTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Collimator, vtkSlicerIECTransformLogic::Gantry);
vtkNew<vtkTransform> collimatorToGantryTransform;
collimatorToGantryTransform->RotateZ(parameterNode->GetCollimatorRotationAngle());
collimatorToGantryTransformNode->SetAndObserveTransformToParent(collimatorToGantryTransform);
}
//----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::UpdateGantryToFixedReferenceTransform(vtkMRMLRoomsEyeViewNode* parameterNode)
{
if (!parameterNode)
{
vtkErrorMacro("UpdateGantryToFixedReferenceTransform: Invalid parameter set node");
return;
}
vtkMRMLLinearTransformNode* gantryToFixedReferenceTransformNode =
this->IECLogic->GetTransformNodeBetween(vtkSlicerIECTransformLogic::Gantry, vtkSlicerIECTransformLogic::FixedReference);
vtkNew<vtkTransform> gantryToFixedReferenceTransform;
gantryToFixedReferenceTransform->RotateY(parameterNode->GetGantryRotationAngle());
gantryToFixedReferenceTransformNode->SetAndObserveTransformToParent(gantryToFixedReferenceTransform);
}
//-----------------------------------------------------------------------------
void vtkSlicerRoomsEyeViewModuleLogic::UpdateLeftImagingPanelToGantryTransform(vtkMRMLRoomsEyeViewNode* parameterNode)
{
if (!parameterNode)
{
vtkErrorMacro("UpdateLeftImagingPanelToGantryTransform: Invalid parameter set node");
return;
}
vtkMRMLModelNode* leftImagingPanelModel = vtkMRMLModelNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(IMAGINGPANELLEFT_MODEL_NAME));