unveil-python 0.5.0__tar.gz → 0.5.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unveil-python
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Implementation of UNVEIL
5
5
  Author-email: Nicolas Delinte <nicolas.delinte@uclouvain.be>
6
6
  License-Expression: GPL-3.0-only
@@ -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.5.0"
4
+ __version__ = "0.5.1"
5
5
  __author__ = 'Nicolas Delinte'
@@ -194,6 +194,21 @@ class TrkViewer(QWidget):
194
194
  self.x = 0
195
195
  self.y = 0
196
196
  self.z = 0
197
+ self.colormap_list = ['gray',
198
+ 'viridis', 'plasma', 'inferno', 'magma', 'cividis',
199
+ 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges',
200
+ 'Reds', 'bone', 'pink', 'spring', 'summer',
201
+ 'autumn', 'winter', 'cool', 'Wistia', 'hot',
202
+ 'afmhot', 'gist_heat', 'copper', 'RdBu', 'RdYlBu',
203
+ 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic',
204
+ 'berlin', 'managua', 'vanimo', 'twilight',
205
+ 'twilight_shifted', 'hsv', 'Pastel1', 'Pastel2',
206
+ 'Paired', 'Accent', 'okabe_ito', 'Dark2', 'Set1',
207
+ 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', 'tab20c',
208
+ 'flag', 'prism', 'ocean', 'gist_earth', 'terrain',
209
+ 'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap',
210
+ 'cubehelix', 'brg', 'gist_rainbow', 'rainbow',
211
+ 'jet', 'turbo', 'nipy_spectral', 'gist_ncar']
197
212
  self.initUI()
198
213
  self.background = 'white'
199
214
  self.color_blind = False
@@ -254,7 +269,7 @@ class TrkViewer(QWidget):
254
269
  self.showPointsCheckbox.stateChanged.connect(self.update_trk_viewer)
255
270
  control_layout.addWidget(self.showPointsCheckbox)
256
271
 
257
- self.colorMapLabel = QLabel('Color Map:')
272
+ self.colorMapLabel = QLabel('Tract Color Mode:')
258
273
  control_layout.addWidget(self.colorMapLabel)
259
274
 
260
275
  self.colorMapComboBox = QComboBox()
@@ -262,13 +277,17 @@ class TrkViewer(QWidget):
262
277
  self.colorMapComboBox.currentIndexChanged.connect(
263
278
  self.update_trk_viewer)
264
279
  control_layout.addWidget(self.colorMapComboBox)
265
- self.colorMapEdit = QLineEdit()
266
- self.colorMapEdit.textChanged.connect(self.update_trk_viewer)
267
- self.colorMapEdit.setToolTip(
268
- 'Insert color map name. Name must be in the matplotlib library. Scalar nii.gz must be loaded.')
269
- control_layout.addWidget(self.colorMapEdit)
270
280
 
271
- self.volume_label = QLabel('Volume')
281
+ self.tractColorMapLabel = QLabel('Tract Colormap (Scalar):')
282
+ control_layout.addWidget(self.tractColorMapLabel)
283
+
284
+ self.tractColorMapComboBox = QComboBox()
285
+ self.tractColorMapComboBox.addItems(self.colormap_list)
286
+ self.tractColorMapComboBox.currentIndexChanged.connect(
287
+ self.update_trk_viewer)
288
+ control_layout.addWidget(self.tractColorMapComboBox)
289
+
290
+ self.volume_label = QLabel('Volume Opacity')
272
291
  control_layout.addWidget(self.volume_label)
273
292
 
274
293
  self.nii_opacitySlider = QSlider(Qt.Orientation.Horizontal, self)
@@ -278,6 +297,15 @@ class TrkViewer(QWidget):
278
297
  self.nii_opacitySlider.sliderReleased.connect(self.update_nii_viewer)
279
298
  control_layout.addWidget(self.nii_opacitySlider)
280
299
 
300
+ self.niiColorMapLabel = QLabel('Global Volume Colormap:')
301
+ control_layout.addWidget(self.niiColorMapLabel)
302
+
303
+ self.niiColorMapComboBox = QComboBox()
304
+ self.niiColorMapComboBox.addItems(self.colormap_list)
305
+ self.niiColorMapComboBox.currentIndexChanged.connect(
306
+ self.on_nii_colormap_changed)
307
+ control_layout.addWidget(self.niiColorMapComboBox)
308
+
281
309
  self.showSlicesCheckbox = QCheckBox('Show Slices')
282
310
  self.showSlicesCheckbox.stateChanged.connect(self.update_nii_viewer)
283
311
  control_layout.addWidget(self.showSlicesCheckbox)
@@ -368,8 +396,10 @@ class TrkViewer(QWidget):
368
396
  self.update_nii_viewer(reset_camera=False)
369
397
  self.window().refreshActorList()
370
398
 
399
+ # Update 2D view with current colormap
371
400
  self.nii_data[self.nii_data == 0] = None
372
401
  self.window().ortho_viewer.set_volume(self.nii_data, self.nii_affine)
402
+ self.window().ortho_viewer.set_colormap(self.niiColorMapComboBox.currentText())
373
403
 
374
404
  def loadROIFile(self):
375
405
  """Load one or multiple ROI nifti volumes and render as surfaces."""
@@ -491,20 +521,25 @@ class TrkViewer(QWidget):
491
521
  self.plotter.render()
492
522
  offscreen.close()
493
523
 
524
+ def on_nii_colormap_changed(self):
525
+ self.update_nii_viewer()
526
+ if hasattr(self.window(), 'ortho_viewer'):
527
+ self.window().ortho_viewer.set_colormap(self.niiColorMapComboBox.currentText())
528
+
494
529
  def update_trk_viewer(self, reset_camera: bool = False):
495
530
 
496
531
  opacity = self.opacitySlider.value() / 100.0
497
532
  show_points = self.showPointsCheckbox.isChecked()
498
533
 
499
- color_map = self.colorMapComboBox.currentText()
500
- if color_map == 'flesh':
534
+ color_mode = self.colorMapComboBox.currentText()
535
+ if color_mode == 'flesh':
501
536
  color_map = 'flesh'
502
537
  scalar = None
503
- elif color_map == 'rgb':
538
+ elif color_mode == 'rgb':
504
539
  color_map = 'plasma'
505
540
  scalar = None
506
541
  else:
507
- color_map = self.colorMapEdit.text()
542
+ color_map = self.tractColorMapComboBox.currentText()
508
543
  scalar = self.nii_data
509
544
 
510
545
  for file in list(self.actor_types):
@@ -518,14 +553,15 @@ class TrkViewer(QWidget):
518
553
 
519
554
  def _update_slice(self, axis, actor_name):
520
555
 
521
- if self.showSlicesCheckbox.isChecked():
556
+ if self.showSlicesCheckbox.isChecked() and self.grid is not None:
522
557
 
523
558
  center = (self.XSlider.value(), self.YSlider.value(),
524
559
  self.ZSlider.value())
525
560
 
526
561
  slice_mesh = self.grid.slice(axis, origin=center)
562
+ cmap_name = self.niiColorMapComboBox.currentText()
527
563
 
528
- self.plotter.add_mesh(slice_mesh, cmap='grey', name=actor_name,
564
+ self.plotter.add_mesh(slice_mesh, cmap=cmap_name, name=actor_name,
529
565
  show_scalar_bar=False, point_size=0,
530
566
  render_lines_as_tubes=True,
531
567
  reset_camera=False,
@@ -535,25 +571,41 @@ class TrkViewer(QWidget):
535
571
  self.plotter.remove_actor(actor_name)
536
572
 
537
573
  def update_nii_viewer(self, reset_camera: bool = False):
574
+ if self.grid is None:
575
+ return
538
576
 
539
577
  self._update_slice('x', 'nii_x')
540
578
  self._update_slice('y', 'nii_y')
541
579
  self._update_slice('z', 'nii_z')
542
580
 
543
581
  opacity = self.nii_opacitySlider.value()/1000
544
- self.plotter.add_volume(self.grid, cmap='gray', opacity=[0, opacity],
582
+ cmap_name = self.niiColorMapComboBox.currentText()
583
+
584
+ self.plotter.add_volume(self.grid, cmap=cmap_name, opacity=[0, opacity],
545
585
  show_scalar_bar=False, name='nii_volume',
546
586
  reset_camera=reset_camera,
547
587
  user_matrix=self.nii_affine)
548
588
 
549
- def update_gii_viewer(self, reset_camera: bool = False):
589
+ def update_gii_viewer(self, reset_camera=False):
550
590
 
551
- opacity = self.gii_opacitySlider.value()/100
552
- self.plotter.add_mesh(self.gii_mesh, color="ghostwhite",
553
- culling='back', smooth_shading=True,
554
- opacity=opacity, name='gii_surface',
555
- reset_camera=reset_camera, point_size=0,
556
- render_lines_as_tubes=True,)
591
+ if not hasattr(self, "gii_mesh"):
592
+ return
593
+
594
+ opacity = self.gii_opacitySlider.value() / 100
595
+
596
+ self.plotter.add_mesh(
597
+ self.gii_mesh,
598
+ color="ghostwhite",
599
+ culling="back",
600
+ smooth_shading=True,
601
+ opacity=opacity,
602
+ name="gii_surface",
603
+ reset_camera=reset_camera,
604
+ point_size=0,
605
+ render_lines_as_tubes=True,
606
+ )
607
+
608
+ # self.plotter.render()
557
609
 
558
610
 
559
611
  class OrthogonalViewer(QWidget):
@@ -563,6 +615,7 @@ class OrthogonalViewer(QWidget):
563
615
 
564
616
  self.volume = None
565
617
  self.affine = None
618
+ self.cmap = "gray"
566
619
 
567
620
  self.rois = {}
568
621
  self.roi_visibility = {}
@@ -608,6 +661,10 @@ class OrthogonalViewer(QWidget):
608
661
 
609
662
  self.update_views()
610
663
 
664
+ def set_colormap(self, cmap_name):
665
+ self.cmap = cmap_name
666
+ self.update_views()
667
+
611
668
  def add_roi(self, name, roi, color):
612
669
 
613
670
  self.rois[name] = {"data": roi, "color": color}
@@ -644,9 +701,9 @@ class OrthogonalViewer(QWidget):
644
701
  for ax in (self.ax_axial, self.ax_coronal, self.ax_sagittal):
645
702
  ax.axis("off")
646
703
 
647
- self.ax_axial.imshow(np.rot90(axial), cmap="gray", vmin=0)
648
- self.ax_coronal.imshow(np.rot90(coronal), cmap="gray", vmin=0)
649
- self.ax_sagittal.imshow(np.rot90(sagittal), cmap="gray", vmin=0)
704
+ self.ax_axial.imshow(np.rot90(axial), cmap=self.cmap, vmin=0)
705
+ self.ax_coronal.imshow(np.rot90(coronal), cmap=self.cmap, vmin=0)
706
+ self.ax_sagittal.imshow(np.rot90(sagittal), cmap=self.cmap, vmin=0)
650
707
 
651
708
  for name, roi_info in self.rois.items():
652
709
 
@@ -662,14 +719,6 @@ class OrthogonalViewer(QWidget):
662
719
 
663
720
  self.canvas.draw_idle()
664
721
 
665
- # self.window().viewer.XSlider.setValue(self.x)
666
- # self.window().viewer.YSlider.setValue(self.y)
667
- # self.window().viewer.ZSlider.setValue(self.z)
668
-
669
- # self.window().viewer._update_slice('x', 'nii_x')
670
- # self.window().viewer._update_slice('y', 'nii_y')
671
- # self.window().viewer._update_slice('z', 'nii_z')
672
-
673
722
  def take_screenshot(self):
674
723
 
675
724
  options = QFileDialog.Options()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unveil-python
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Implementation of UNVEIL
5
5
  Author-email: Nicolas Delinte <nicolas.delinte@uclouvain.be>
6
6
  License-Expression: GPL-3.0-only
File without changes
File without changes
File without changes