unveil-python 0.7.2__py3-none-any.whl → 0.7.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
unveil/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """
2
2
  This package contains an UNVEIL, a lightweight tractography viewer implemented in python."""
3
3
 
4
- __version__ = "0.7.2"
4
+ __version__ = "0.7.4"
5
5
  __author__ = 'Nicolas Delinte'
unveil/core.py CHANGED
@@ -239,7 +239,9 @@ class TrkViewer(QWidget):
239
239
  self.flicker = False
240
240
  self.roi_colors = {}
241
241
  self.roi_volumes = {}
242
- self.roi_visibility = {}
242
+ self.visibility = {}
243
+ self.gii_meshes = {}
244
+ self.nii_surface_values = {}
243
245
 
244
246
  def initUI(self):
245
247
  # Create the main layout
@@ -525,6 +527,14 @@ class TrkViewer(QWidget):
525
527
  if not filePath:
526
528
  return
527
529
 
530
+ # Remove previous
531
+ for nii_actor in list(self.actor_types):
532
+ if self.actor_types.get(nii_actor) == 'nii':
533
+ del self.actor_types[nii_actor]
534
+
535
+ actor_name = f"{filePath.split('/')[-1]}"
536
+ self.actor_types[actor_name] = "nii"
537
+
528
538
  print(f"Loaded NIfTI file: {filePath}")
529
539
  img = nib.load(filePath)
530
540
  self.nii_affine = img.affine
@@ -551,11 +561,12 @@ class TrkViewer(QWidget):
551
561
 
552
562
  if hasattr(self, "gii_mesh"):
553
563
  # Sample NIfTI values at each surface vertex
554
- self.nii_surface_values = self.sample_nifti_on_surface(
555
- self.gii_mesh)
564
+ for gii_actor in list(self.actor_types):
565
+ if self.actor_types.get(gii_actor) != 'gii':
566
+ continue
567
+ self.nii_surface_values[gii_actor] = self.sample_nifti_on_surface(
568
+ self.gii_meshes[gii_actor])
556
569
  self.update_gii_viewer(reset_camera=False)
557
- else:
558
- self.nii_surface_values = None
559
570
  self.window().refreshActorList()
560
571
 
561
572
  # Update 2D view with current colormap
@@ -589,7 +600,7 @@ class TrkViewer(QWidget):
589
600
  actor_name = f"{roi_path.split('/')[-1]}"
590
601
  self.actor_types[actor_name] = "roi"
591
602
  self.roi_volumes[actor_name] = roi
592
- self.roi_visibility[actor_name] = True
603
+ self.visibility[actor_name] = True
593
604
 
594
605
  default_color = np.array([1.0, 1.0, 1.0])
595
606
 
@@ -605,35 +616,40 @@ class TrkViewer(QWidget):
605
616
  self.window().ortho_viewer.add_roi(actor_name, roi, default_color)
606
617
 
607
618
  def loadGiftiFile(self):
619
+
608
620
  options = QFileDialog.Options()
609
- filePath, _ = QFileDialog.getOpenFileName(
610
- self, "Open .gii File", "", "Gifti Files (*.gii)", options=options)
621
+ filePaths, _ = QFileDialog.getOpenFileNames(
622
+ self, "Open .gii Files", "", "Gifti Files (*.gii)", options=options)
611
623
 
612
- if not filePath:
624
+ if not filePaths:
613
625
  return
614
626
 
615
- print(f"Loaded GIFTI file: {filePath}")
627
+ for gii_path in filePaths:
628
+ print(f"Loaded Gifti file: {gii_path}")
629
+ actor_name = f"{gii_path.split('/')[-1]}"
630
+ self.actor_types[actor_name] = 'gii'
631
+ self.visibility[actor_name] = True
616
632
 
617
- self.gii_mesh = gifti_to_pyvista(filePath)
633
+ self.gii_meshes[actor_name] = gifti_to_pyvista(gii_path)
618
634
 
619
- self.gii_data = load_gii_data(filePath)
635
+ self.gii_data = load_gii_data(gii_path)
620
636
 
621
- self.giiColorModeComboBox.setCurrentIndex(0)
637
+ self.giiColorModeComboBox.setCurrentIndex(0)
622
638
 
623
- for _ in range(self.giiColorModeComboBox.count()-2):
624
- self.giiColorModeComboBox.removeItem(2)
639
+ for _ in range(self.giiColorModeComboBox.count()-2):
640
+ self.giiColorModeComboBox.removeItem(2)
625
641
 
626
- self.giiColorModeComboBox.addItems(list(self.gii_data.keys()))
642
+ self.giiColorModeComboBox.addItems(list(self.gii_data.keys()))
627
643
 
628
- self.actor_types["gii_surface"] = "gii"
644
+ if hasattr(self, "nii_data"):
645
+ # Sample NIfTI values at each surface vertex
646
+ self.nii_surface_values[actor_name] = self.sample_nifti_on_surface(
647
+ self.gii_meshes[actor_name])
648
+ # self.update_gii_viewer(reset_camera=False)
649
+ else:
650
+ self.nii_surface_values[actor_name] = None
629
651
 
630
- if hasattr(self, "nii_data"):
631
- # Sample NIfTI values at each surface vertex
632
- self.nii_surface_values = self.sample_nifti_on_surface(
633
- self.gii_mesh)
634
- self.update_gii_viewer(reset_camera=False)
635
- else:
636
- self.nii_surface_values = None
652
+ self.gii_mesh = True
637
653
 
638
654
  self.update_gii_viewer(reset_camera=False)
639
655
  self.window().refreshActorList()
@@ -775,9 +791,14 @@ class TrkViewer(QWidget):
775
791
  if vmax <= vmin:
776
792
  vmax = vmin + 1e-6
777
793
 
778
- self.plotter.add_volume(self.grid, cmap=cmap_name, opacity=[0, opacity],
779
- show_scalar_bar=False, name='nii_volume',
780
- reset_camera=reset_camera, clim=[vmin, vmax],
794
+ for nii_actor in list(self.actor_types):
795
+ if self.actor_types.get(nii_actor) == 'nii':
796
+ last_nii_actor = nii_actor
797
+
798
+ self.plotter.add_volume(self.grid, cmap=cmap_name,
799
+ opacity=[0, opacity], show_scalar_bar=False,
800
+ name=last_nii_actor, reset_camera=reset_camera,
801
+ clim=[vmin, vmax],
781
802
  user_matrix=self.nii_affine)
782
803
 
783
804
  def update_gii_viewer(self, reset_camera=False, update_color_range=False):
@@ -792,51 +813,61 @@ class TrkViewer(QWidget):
792
813
 
793
814
  color_mode = self.giiColorModeComboBox.currentText()
794
815
 
795
- if color_mode == "Solid":
796
-
797
- self.plotter.add_mesh(self.gii_mesh, color="ghostwhite",
798
- culling="back", smooth_shading=True,
799
- opacity=opacity, name="gii_surface",
800
- reset_camera=reset_camera,
801
- point_size=0, render_lines_as_tubes=True)
816
+ for gii_actor in list(self.actor_types):
817
+ if self.actor_types.get(gii_actor) != 'gii':
818
+ continue
819
+ if not self.visibility[gii_actor]:
820
+ continue
802
821
 
803
- else:
804
- if color_mode == "NIfTI values":
805
- scalars = self.nii_surface_values
806
- else:
807
- scalars = self.gii_data[color_mode]
822
+ if color_mode == "Solid":
808
823
 
809
- if scalars is None:
810
- self.plotter.add_mesh(self.gii_mesh, color="ghostwhite",
824
+ self.plotter.add_mesh(self.gii_meshes[gii_actor], color="ghostwhite",
811
825
  culling="back", smooth_shading=True,
812
- opacity=opacity, name="gii_surface",
826
+ opacity=opacity, name=gii_actor,
813
827
  reset_camera=reset_camera,
814
828
  point_size=0, render_lines_as_tubes=True)
815
- return
816
-
817
- # Copy the mesh so that the original GIFTI mesh is not modified
818
- surface_mesh = self.gii_mesh.copy(deep=True)
819
- surface_mesh.point_data[color_mode] = scalars
820
-
821
- cmap_name = self.giiColorMapComboBox.currentText()
822
829
 
823
- if update_color_range:
824
- self.update_surface_color_range(scalars)
825
-
826
- vmin = self.giiMinSpinBox.value()
827
- vmax = self.giiMaxSpinBox.value()
828
-
829
- # Protect against an invalid range
830
- if vmax <= vmin:
831
- vmax = vmin + 1e-6
832
-
833
- self.plotter.add_mesh(surface_mesh, scalars=color_mode,
834
- cmap=cmap_name, clim=[vmin, vmax],
835
- culling="back", smooth_shading=True,
836
- opacity=opacity, name="gii_surface",
837
- reset_camera=reset_camera, point_size=0,
838
- render_lines_as_tubes=True,
839
- show_scalar_bar=False)
830
+ else:
831
+ if color_mode == "NIfTI values":
832
+ scalars = self.nii_surface_values[gii_actor]
833
+ else:
834
+ scalars = self.gii_data[color_mode]
835
+
836
+ if scalars is None:
837
+ self.plotter.add_mesh(self.gii_meshes[gii_actor], color="ghostwhite",
838
+ culling="back", smooth_shading=True,
839
+ opacity=opacity, name=gii_actor,
840
+ reset_camera=reset_camera,
841
+ point_size=0, render_lines_as_tubes=True)
842
+ return
843
+
844
+ # Copy the mesh so that the original GIFTI mesh is not modified
845
+ surface_mesh = self.gii_meshes[gii_actor].copy(deep=True)
846
+ surface_mesh.point_data[color_mode] = scalars
847
+
848
+ cmap_name = self.giiColorMapComboBox.currentText()
849
+
850
+ if update_color_range:
851
+ if color_mode == "NIfTI values":
852
+ self.update_surface_color_range(self.nii_data)
853
+ else:
854
+ self.update_surface_color_range(
855
+ self.gii_data[color_mode])
856
+
857
+ vmin = self.giiMinSpinBox.value()
858
+ vmax = self.giiMaxSpinBox.value()
859
+
860
+ # Protect against an invalid range
861
+ if vmax <= vmin:
862
+ vmax = vmin + 1e-6
863
+
864
+ self.plotter.add_mesh(surface_mesh, scalars=color_mode,
865
+ cmap=cmap_name, clim=[vmin, vmax],
866
+ culling="back", smooth_shading=True,
867
+ opacity=opacity, name=gii_actor,
868
+ reset_camera=reset_camera, point_size=0,
869
+ render_lines_as_tubes=True,
870
+ show_scalar_bar=False)
840
871
 
841
872
  self.plotter.render()
842
873
 
@@ -1060,7 +1091,7 @@ class OrthogonalViewer(QWidget):
1060
1091
  self.cmap = "gray"
1061
1092
 
1062
1093
  self.rois = {}
1063
- self.roi_visibility = {}
1094
+ self.visibility = {}
1064
1095
 
1065
1096
  self.background = "white"
1066
1097
 
@@ -1110,7 +1141,7 @@ class OrthogonalViewer(QWidget):
1110
1141
  def add_roi(self, name, roi, color):
1111
1142
 
1112
1143
  self.rois[name] = {"data": roi, "color": color}
1113
- self.roi_visibility[name] = True
1144
+ self.visibility[name] = True
1114
1145
  self.update_views()
1115
1146
 
1116
1147
  def draw_roi(self, ax, roi_slice, color):
@@ -1149,7 +1180,7 @@ class OrthogonalViewer(QWidget):
1149
1180
 
1150
1181
  for name, roi_info in self.rois.items():
1151
1182
 
1152
- if not self.roi_visibility[name]:
1183
+ if not self.visibility[name]:
1153
1184
  continue
1154
1185
 
1155
1186
  roi = roi_info["data"]
@@ -1371,9 +1402,9 @@ class MainWindow(QMainWindow):
1371
1402
  # Insert into the correct group
1372
1403
  if self.viewer.actor_types.get(name) == 'trk':
1373
1404
  group_trk.addChild(item)
1374
- elif name.startswith("nii_"):
1405
+ elif self.viewer.actor_types.get(name) == 'nii':
1375
1406
  group_nii.addChild(item)
1376
- elif name.startswith("gii_"):
1407
+ elif self.viewer.actor_types.get(name) == 'gii':
1377
1408
  group_gii.addChild(item)
1378
1409
  elif self.viewer.actor_types.get(name) == 'roi':
1379
1410
  group_roi.addChild(item)
@@ -1395,8 +1426,8 @@ class MainWindow(QMainWindow):
1395
1426
  except KeyError:
1396
1427
  pass
1397
1428
 
1398
- self.viewer.roi_visibility[actor_name] = visible
1399
- self.ortho_viewer.roi_visibility[actor_name] = visible
1429
+ self.viewer.visibility[actor_name] = visible
1430
+ self.ortho_viewer.visibility[actor_name] = visible
1400
1431
  self.ortho_viewer.update_views()
1401
1432
 
1402
1433
  self.viewer.plotter.render()
unveil/utils.py CHANGED
@@ -31,7 +31,7 @@ def dilate_atlas_labels(atlas, brain_mask=None, dilation_width: float = 1):
31
31
  """
32
32
 
33
33
  # Mask unlabeled voxels inside the brain
34
- unlabeled = np.where(atlas != 0, 1, 0)
34
+ unlabeled = np.where(atlas == 0, 1, 0)
35
35
  if brain_mask is not None:
36
36
  unlabeled *= brain_mask.astype('int32')
37
37
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unveil-python
3
- Version: 0.7.2
3
+ Version: 0.7.4
4
4
  Summary: Implementation of UNVEIL
5
5
  Author-email: Nicolas Delinte <nicolas.delinte@uclouvain.be>
6
6
  License-Expression: GPL-3.0-only
@@ -36,6 +36,8 @@ import unveil.__main__
36
36
  ```
37
37
  or with
38
38
  ```
39
+ python -m unveil
40
+ OR
39
41
  python -c "import unveil.__main__"
40
42
  ```
41
43
  from a terminal with a python environment activated.
@@ -0,0 +1,9 @@
1
+ unveil/__init__.py,sha256=J1fKhCrKwQtR_mB5XedlLC11g9ZyoSHVq4DTjZKmCGs,154
2
+ unveil/__main__.py,sha256=bnkQ3e9iiAhCnxkvJNWcmlAHRDhY21tuZS8UJnz4XEg,180
3
+ unveil/core.py,sha256=Kss3XXIjTGxuO9v1jucO_K3crJ1SmfZnP_-5TBt6lsA,53826
4
+ unveil/utils.py,sha256=gwJoaVrTNYm7EBBJlE78P-54kJiIEn-yCo7B-w0X0iI,1792
5
+ unveil_python-0.7.4.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
6
+ unveil_python-0.7.4.dist-info/METADATA,sha256=xq4zapXLIGo5p1HHxVbx-0ND_SuDyPQXhAxw44P6UdI,2712
7
+ unveil_python-0.7.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ unveil_python-0.7.4.dist-info/top_level.txt,sha256=9wvfQb68TeFLFyrzZWSrNgFDdwE75I--VtoGyvnl3ks,7
9
+ unveil_python-0.7.4.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- unveil/__init__.py,sha256=PAbeYyX5eFdZIG8r58DtglEQT7yuAtjLpjbc_vMdLKU,154
2
- unveil/__main__.py,sha256=bnkQ3e9iiAhCnxkvJNWcmlAHRDhY21tuZS8UJnz4XEg,180
3
- unveil/core.py,sha256=cDd3JF-6Dk5PLZu5PrHNF1pQM-2cCXUqcqrn2n7wp_s,52272
4
- unveil/utils.py,sha256=BUSqyyVDezyrSaG_TsfcO49g7Cedr48NF25P-ctzKWA,1792
5
- unveil_python-0.7.2.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
6
- unveil_python-0.7.2.dist-info/METADATA,sha256=_lc9tRFcjC9QYyxf_yWY5pSskF5Fboj_yM2VQMUDOw0,2690
7
- unveil_python-0.7.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
- unveil_python-0.7.2.dist-info/top_level.txt,sha256=9wvfQb68TeFLFyrzZWSrNgFDdwE75I--VtoGyvnl3ks,7
9
- unveil_python-0.7.2.dist-info/RECORD,,