Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slider values & fix overflow errors #23

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/surforama/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def launch_surforama(
# set up the viewer with the user-requested images
if image_path is not None:
# load the image if the path was passed
image = mrcfile.read(image_path)
image = mrcfile.read(image_path).astype(float)
volume_layer = viewer.add_image(image)
else:
volume_layer = None
Expand Down
21 changes: 17 additions & 4 deletions src/surforama/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QGroupBox,
QHBoxLayout,
QLabel,
QPushButton,
QSlider,
Expand Down Expand Up @@ -58,6 +59,11 @@ def __init__(
self.slider.setValue(0)
self.slider.valueChanged.connect(self.slide_points)
self.slider.setVisible(False)
self.slider_value = QLabel("0 vx", self)

self.sliderLayout = QHBoxLayout()
self.sliderLayout.addWidget(self.slider)
self.sliderLayout.addWidget(self.slider_value)

# New slider for sampling depth

Expand All @@ -70,6 +76,11 @@ def __init__(
self.update_colors_based_on_sampling
)
self.sampling_depth_slider.setVisible(False)
self.sampling_depth_value = QLabel("10", self)

self.sampling_depth_sliderLayout = QHBoxLayout()
self.sampling_depth_sliderLayout.addWidget(self.sampling_depth_slider)
self.sampling_depth_sliderLayout.addWidget(self.sampling_depth_value)

# make the picking widget
self.picking_widget = QtSurfacePicker(surforama=self, parent=self)
Expand All @@ -85,9 +96,9 @@ def __init__(
self.setLayout(QVBoxLayout())
self.layout().addWidget(self._layer_selection_widget.native)
self.layout().addWidget(QLabel("Extend/contract surface"))
self.layout().addWidget(self.slider)
self.layout().addLayout(self.sliderLayout)
self.layout().addWidget(QLabel("Surface Thickness"))
self.layout().addWidget(self.sampling_depth_slider)
self.layout().addLayout(self.sampling_depth_sliderLayout)
self.layout().addWidget(self.picking_widget)
self.layout().addWidget(self.point_writer_widget)
self.layout().addStretch()
Expand Down Expand Up @@ -157,10 +168,10 @@ def get_point_colors(self, points):
point_values = self.volume[
point_indices[:, 0], point_indices[:, 1], point_indices[:, 2]
]

normalized_values = (point_values - point_values.min()) / (
point_values.max() - point_values.min()
point_values.max() - point_values.min() + np.finfo(float).eps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was causing problems with the integer overflow. After converting tomograms to float, it should not be the case anymore.

)

return normalized_values

def get_point_set(self):
Expand All @@ -185,6 +196,7 @@ def slide_points(self, value):
self.color_values = new_colors
self.vertices = new_positions
self.update_mesh()
self.slider_value.setText(f"{shift} vx")

def update_mesh(self):
self.surface_layer.data = (
Expand Down Expand Up @@ -249,6 +261,7 @@ def update_colors_based_on_sampling(self, value):

self.color_values = new_colors
self.update_mesh()
self.sampling_depth_value.setText(f"{value}")


class QtSurfacePicker(QGroupBox):
Expand Down
2 changes: 1 addition & 1 deletion src/surforama/data/_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def thylakoid_membrane() -> (
tomogram_path = _data_registry.fetch(
"S1_M3b_StII_grow2_1_mesh_data.mrc", progressbar=True
)
tomogram = mrcfile.read(tomogram_path)
tomogram = mrcfile.read(tomogram_path).astype(float)

# get the mesh
mesh_path = _data_registry.fetch(
Expand Down
Loading