forked from fgbossema/INTACT_blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINTACT_Panel.py
641 lines (514 loc) · 21.9 KB
/
INTACT_Panel.py
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
from os.path import join, dirname, exists, abspath
import bpy
ADDON_DIR = dirname(abspath(__file__))
Addon_Version_Path = join(ADDON_DIR, "Resources", "INTACT_Version.txt")
if exists(Addon_Version_Path):
with open(Addon_Version_Path, "r") as rf:
lines = rf.readlines()
Addon_Version_Date = lines[0].split(";")[0]
else:
Addon_Version_Date = " "
# Selected icons :
red_icon = "COLORSET_01_VEC"
orange_icon = "COLORSET_02_VEC"
green_icon = "COLORSET_03_VEC"
blue_icon = "COLORSET_04_VEC"
violet_icon = "COLORSET_06_VEC"
yellow_icon = "COLORSET_09_VEC"
yellow_point = "KEYTYPE_KEYFRAME_VEC"
blue_point = "KEYTYPE_BREAKDOWN_VEC"
class INTACT_PT_MainPanel(bpy.types.Panel):
""" INTACT Main Panel"""
bl_idname = "INTACT_PT_MainPanel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "INTACT"
bl_label = "INTACT INFORMATION"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
# Draw Addon UI :
layout = self.layout
box = layout.box()
row = box.row()
row.alert = True
row.alignment = "CENTER"
row.label(text=f"WINDOWS VERSION : {Addon_Version_Date}")
row = box.row()
row.alignment = "LEFT"
row.label(text="Description of plugin:")
row = box.row()
row.alignment = "LEFT"
row.label(text="A plugin designed for visualising CT scans and surface scans of cultural heritage objects.")
row = box.row()
row.alignment = "LEFT"
row.label(text="The plugin is associated with the article by Bossema et. al.: 'Fusing 3D imaging modalities for the internal and external investigation of multi-material museum objects.'")
row = box.row()
row.alignment = "LEFT"
row.label(text="The most current version can be found on Github. We welcome contributions via that channel.")
row = box.row()
row.alignment = "LEFT"
row.label(text="The plugin can be used and adjusted freely, if used for an article or other publication we would appreciate if you would cite above mentioned article and Github repository.'")
row = box.row()
row.alignment = "LEFT"
row.label(text="The plugin has the following submodules")
row = box.row()
row.alignment = "LEFT"
row.label(text="1. Loading CT data.")
row = box.row()
row.alignment = "LEFT"
row.label(text="2. Loading surface scan data.")
row = box.row()
row.alignment = "LEFT"
row.label(text="3. CT mesh generation.")
row = box.row()
row.alignment = "LEFT"
row.label(text="4. Registration.")
row = box.row()
row.alignment = "LEFT"
row.label(text="5. Interactive visualisation.")
row = box.row()
row.alignment = "LEFT"
row.label(text="6. Images and output.")
row = box.row()
row.alignment = "LEFT"
row.label(text="Designed and developed by Paul van Laar, Francien Bossema & Kimberly Meechan.")
row = box.row()
row.alignment = "LEFT"
row.label(text="ACKNOWLEDGEMENTS")
row = box.row()
row.alignment = "LEFT"
row.label(text="Issam Dakir, whose plugin BDENTAL served as the base for this plugin.")
row = box.row()
row.alignment = "LEFT"
row.label(text="See: https://github.com/issamdakir/BDENTAL ")
row = box.row()
row.alignment = "LEFT"
row.label(text="Niels Klop, whose plugin ICP Registration/Alignment was the base for the Registration module.")
row = box.row()
row.alignment = "LEFT"
row.label(text="See: https://3d-operators.com/")
class INTACT_WorkingDIR(bpy.types.Panel):
""" INTACT Workin dir"""
bl_idname = "INTACT_PT_workingdir"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "INTACT"
bl_label = "WORKING DIRECTORY"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
# Draw Addon UI :
layout = self.layout
INTACT_Props = context.scene.INTACT_Props
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Project Directory :")
col = split.column()
col.prop(INTACT_Props, "UserProjectDir", text="")
class INTACT_PT_ScanPanel(bpy.types.Panel):
""" INTACT CT load"""
bl_idname = "INTACT_PT_ScanPanel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "INTACT"
bl_label = "1. CT SCAN LOAD"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
INTACT_Props = context.scene.INTACT_Props
# Draw Addon UI :
layout = self.layout
if not INTACT_Props.UserProjectDir:
row = layout.row()
row.alignment = "LEFT"
row.label(text="Please select working directory in INTACT panel.")
if INTACT_Props.UserProjectDir:
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Scan Data Type :")
col = split.column()
col.prop(INTACT_Props, "DataType", text="")
if INTACT_Props.DataType == "TIFF Stack":
row = layout.row()
split = row.split()
col = split.column()
col.label(text="TIFF Directory :")
col = split.column()
col.prop(INTACT_Props, "UserTiffDir", text="")
# input for resolution
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Resolution (voxel size in mm) :")
col = split.column()
col.prop(INTACT_Props, "Resolution", text="")
if INTACT_Props.UserTiffDir:
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("intact.volume_render", icon="IMPORT")
if INTACT_Props.DataType == "DICOM Series":
row = layout.row()
split = row.split()
col = split.column()
col.label(text="DICOM Directory :")
col = split.column()
col.prop(INTACT_Props, "UserDcmDir", text="")
if INTACT_Props.UserDcmDir:
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("intact.volume_render", icon="IMPORT")
if INTACT_Props.DataType == "NRRD File":
row = layout.row()
split = row.split()
col = split.column()
col.label(text="NRRD File:")
col = split.column()
col.prop(INTACT_Props, "UserImageFile", text="")
if INTACT_Props.UserImageFile:
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("intact.volume_render", icon="IMPORT")
if context.object:
if context.object.name.startswith("IT") and context.object.name.endswith(
"CTVolume"
):
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Color of volume render:")
col = split.column()
col.prop(INTACT_Props, "CTcolor", text="")
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Shading of volume render:")
col = split.column()
col.prop(INTACT_Props, "ColorPos", text="", slider=True)
row = layout.row()
row.label(text="Threshold:")
row = layout.row()
row.prop(INTACT_Props, "Threshold", text="THRESHOLD", slider=True)
class INTACT_PT_SurfacePanel(bpy.types.Panel):
""" INTACT Surface load"""
bl_idname = "INTACT_PT_SurfacePanel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "INTACT"
bl_label = "2. SURFACE SCAN LOAD"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
INTACT_Props = context.scene.INTACT_Props
# Draw Addon UI :
layout = self.layout
if not INTACT_Props.UserProjectDir:
row = layout.row()
row.alignment = "LEFT"
row.label(text="Please select working directory in INTACT panel.")
else:
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Surface scan directory (.obj file) :")
col = split.column()
col.prop(INTACT_Props, "UserObjDir", text="")
if INTACT_Props.UserObjDir:
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("intact.obj_render", icon="IMPORT")
class INTACT_PT_CTmeshPanel(bpy.types.Panel):
bl_category = "INTACT"
bl_label = "3. CT MESH GENERATION"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "objectmode"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
INTACT_Props = context.scene.INTACT_Props
condition_CT = False
for obj in context.scene.objects:
if obj.name.endswith("CTVolume"):
condition_CT = True
if not condition_CT:
row = layout.row()
row.label(text="Please load your CT data first.")
if condition_CT:
row = layout.row()
split = row.split()
col = split.column()
col.label(text="CT Volume:")
col = split.column()
col.prop(INTACT_Props, "CT_Vol", text="")
row = layout.row()
row.label(text="If the CT volume has moved, reset it's position.")
row = layout.row()
row.operator("intact.reset_ctvolume_position")
row = layout.row()
row.label(text="Determine the threshold to separate air and object.")
row = layout.row()
row.prop(INTACT_Props, "Threshold", text="THRESHOLD", slider=True)
layout.separator()
row = layout.row()
row.label(text="Choose color for segmentation, then click SEGMENTATION. ")
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Color of segmentation:")
col = split.column()
col.prop(INTACT_Props, "Thres1SegmentColor", text="")
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("intact.multitresh_segment")
elif (condition_CT and not obj.name.endswith("CTVolume")):
row = layout.row()
row.label(text="Please select CT volume for segmentation.")
class OBJECT_PT_ICP_panel(bpy.types.Panel):
bl_category = "INTACT"
bl_label = "4. REGISTRATION"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "objectmode"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
INTACT_Props = context.scene.INTACT_Props
condition_CT = False
condition_surface = False
for obj in context.scene.objects:
if obj.name.endswith("CTVolume"):
condition_CT = True
if obj.name.startswith("IT_surface"):
condition_surface = True
if obj.name.endswith("SEGMENTATION"):
condition_seg = True
if not (condition_CT or condition_surface):
row = layout.row()
row.label(text="Please load your data first.")
elif (condition_surface and not condition_CT):
row = layout.row()
row.label(text="Please load CT scan.")
elif (condition_CT and not condition_surface):
row = layout.row()
row.label(text="Please load a surface scan.")
condition_segment = False
if context.object:
for obj in context.scene.objects:
if obj.name.endswith("SEGMENTATION"):
condition_segment = True
if (condition_CT and condition_surface and not condition_segment):
row = layout.row()
row.label(text="Please select CT volume and make segmentation.")
if (condition_CT and condition_segment and not condition_surface):
row = layout.row()
row.label(text="Please load a surface scan.")
if (condition_surface and condition_segment):
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Surface scan to register:")
col = split.column()
col.prop(INTACT_Props, "Surf_3D", text="")
row = layout.row()
split = row.split()
col = split.column()
col.label(text="CT Segmentation:")
col = split.column()
col.prop(INTACT_Props, "Seg", text="")
# fine alignment panel
layout.label(text="ICP Alignment")
layout.label(text="Manually move the surface scan for a rough alignment first.")
layout.label(text="Check the boxes below to allow scaling of the surface scan or to use only selected vertices.")
layout.prop(context.scene, "allowScaling", text="Allow Scaling")
layout.prop(context.scene, "vertexSelect", text="Use Vertex Selections")
layout.prop(context.scene, "iterations", text="Iterations")
layout.prop(context.scene, "outlierPerc", text="Outlier %")
layout.prop(context.scene, "downsamplingPerc", text="Downsampling %")
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("object.icp")
class OBJECT_PT_Visualisation_Panel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_category = "INTACT"
bl_label = "5. INTERACTIVE VISUALISATION"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "objectmode"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
row = layout.row()
INTACT_Props = context.scene.INTACT_Props
condition_CT = False
condition_surface = False
for obj in context.scene.objects:
if obj.name.endswith("CTVolume"):
condition_CT = True
if obj.name.startswith("IT_surface"):
condition_surface = True
if not (condition_CT or condition_surface):
row = layout.row()
row.label(text="Please load your data first.")
if (condition_CT or condition_surface):
row = layout.row()
split = row.split()
col = split.column()
col.label(text="CT Volume:")
col = split.column()
col.prop(INTACT_Props, "CT_Vol", text="")
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Surface scan:")
col = split.column()
col.prop(INTACT_Props, "Surf_3D", text="")
row = layout.row()
split = row.split()
col = split.column()
col.label(text="CT Segmentation:")
col = split.column()
col.prop(INTACT_Props, "Seg", text="")
Box = layout.box()
row = Box.row()
row.alignment = "CENTER"
row.scale_y = 2
row.operator("intact.addslices", icon="EMPTY_AXIS")
row = layout.row()
row.label(text="Slices contrast adjustment")
row = layout.row()
row.label(text="Slice min value:")
row = layout.row()
row.prop(INTACT_Props, "Slice_min", text="Minimum value", slider=True)
row = layout.row()
row.label(text="Slice max value:")
row = layout.row()
row.prop(INTACT_Props, "Slice_max", text="Maximum value", slider=True)
if (condition_CT or condition_surface):
layout.label(text="Make cropping cube:")
layout.operator("intact.cropping_cube_creation", text="Create Cropping Cube")
row = layout.row()
row.prop(INTACT_Props, "Track_slices_to_cropping_cube", text="Track slices")
# disable checkbox while there are no slices + no cropping cube
row.enabled = INTACT_Props.Axial_Slice is not None and INTACT_Props.Cropping_Cube is not None
row = layout.row()
row.prop(INTACT_Props, "Remove_slice_outside_object", text="Crop slices outside object")
# disable checkbox while there are no slices + no cropping cube
row.enabled = INTACT_Props.Axial_Slice is not None and INTACT_Props.Cropping_Cube is not None
row = layout.row()
row.label(text="Open viewing in multiple directions.")
row = layout.row()
row.operator("intact.multiview")
row = layout.row()
row.label(text="Display settings:")
layout.prop(INTACT_Props, "Surface_scan_roughness", text="Surface scan roughness")
layout.prop(INTACT_Props, "Slice_thickness", text="Slice thickness")
class OBJECT_PT_Image_Panel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_category = "INTACT"
bl_label = "6. IMAGES AND OUTPUT"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "objectmode"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
row = layout.row()
INTACT_Props = context.scene.INTACT_Props
condition_CT = False
condition_surface = False
for obj in context.scene.objects:
if obj.name.endswith("CTVolume"):
condition_CT = True
if obj.name.startswith("IT_surface"):
condition_surface = True
if not (condition_CT and condition_surface):
row = layout.row()
row.label(text="Please load your data first.")
if (condition_CT or condition_surface):
row = layout.row()
row.label(text="Quick screenshot:")
layout.operator("intact.take_screenshot", text="Take Screenshot")
row = layout.row()
row.label(text="Camera setup:")
layout.prop(INTACT_Props, "Resolution_x", text="Resolution x (pixels)")
layout.prop(INTACT_Props, "Resolution_y", text="Resolution y (pixels)")
if not INTACT_Props.Set_camera_enabled:
icon = "PLAY"
txt = 'Set Camera Position'
else:
icon = "PAUSE"
txt = 'Confirm Camera Position'
layout.prop(INTACT_Props, 'Set_camera_enabled', text=txt, icon=icon, toggle=True)
row = layout.row()
row.label(text="Render options:")
layout.prop(INTACT_Props, 'Lighting_strength', text="Lighting strength")
layout.prop(INTACT_Props, 'Background_colour', text="Background colour")
row = layout.row()
row.label(text="Render image/movie:")
layout.operator("intact.render_image", text="Render image")
row = layout.row()
split = row.split()
col = split.column()
col.label(text="Movie filename:")
col = split.column()
col.prop(INTACT_Props, "Movie_filename", text="")
row = layout.row(align=True)
row.label(text="Axis")
row.prop_enum(INTACT_Props, "Movie_rotation_axis", "X")
row.prop_enum(INTACT_Props, "Movie_rotation_axis", "Y")
row.prop_enum(INTACT_Props, "Movie_rotation_axis", "Z")
layout.operator("intact.render_turntable", text="Render turntable movie")
#################################################################################################
# Registration :
#################################################################################################
classes = [
INTACT_PT_MainPanel,
INTACT_WorkingDIR,
INTACT_PT_ScanPanel,
INTACT_PT_SurfacePanel,
INTACT_PT_CTmeshPanel,
OBJECT_PT_ICP_panel,
OBJECT_PT_Visualisation_Panel,
OBJECT_PT_Image_Panel
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
# icp panel
bpy.types.Scene.allowScaling = bpy.props.BoolProperty(
default=False,
description="Allow uniform scaling of the moving object")
bpy.types.Scene.vertexSelect = bpy.props.BoolProperty(
default=False,
description="Use only selected vertices for registration")
bpy.types.Scene.iterations = bpy.props.IntProperty(
default=50, min=1,
description="Number of iterations")
bpy.types.Scene.outlierPerc = bpy.props.IntProperty(
default=20, min=0, max=99,
description="Outlier percentage")
bpy.types.Scene.downsamplingPerc = bpy.props.IntProperty(
default=0, min=0, max=99,
description="Downsampling percentage")
# export transformations panel
bpy.types.Scene.exportTransformation = bpy.props.EnumProperty(
name="Export Transformation",
items=[
("combined", "Combined Transformation", "Export the combined initial and ICP transformation"),
("roughAlignment", "Initial Transformation", "Export only the initial transformation"),
("fineAlignment", "ICP Transformation", "Export only the ICP transformation")
])
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)