Skip to content

Commit 4239084

Browse files
committed
moves some input checking from the demo scripts into the corresponding methods
1 parent 20462e3 commit 4239084

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

demo/get_apr_interactive_demo.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ def main():
2626
fpath = io_int.get_tiff_file_name() # get image file path from gui (data type must be float32 or uint16)
2727
img = skio.imread(fpath)
2828

29-
while img.ndim < 3:
30-
img = np.expand_dims(img, axis=0)
31-
3229
# Set some parameters (only Ip_th, grad_th and sigma_th are set interactively)
3330
par = pyapr.APRParameters()
3431
par.rel_error = 0.1 # relative error threshold

demo/raycast_demo.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ def main():
2121
# Read APR and particles from file
2222
pyapr.io.read(fpath_apr, apr, parts)
2323

24-
# Raycast viewer currently only works for ShortParticles
25-
if isinstance(parts, pyapr.FloatParticles):
26-
tmp = pyapr.ShortParticles()
27-
tmp.copy(parts)
28-
parts = tmp
29-
3024
# Launch the raycast viewer
3125
pyapr.viewer.raycast_viewer(apr, parts)
3226

pyapr/converter/converter_methods.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def get_apr_interactive(image, rel_error=0.1, gradient_smoothing=2, verbose=True
5353
'input image has been replaced with a C-contiguous copy of itself')
5454
image = np.ascontiguousarray(image)
5555

56+
while image.ndim < 3:
57+
image = np.expand_dims(image, axis=0)
58+
5659
# Initialize objects
5760
io_int = pyapr.InteractiveIO()
5861
apr = pyapr.APR()
@@ -105,6 +108,9 @@ def find_parameters_interactive(image, rel_error=0.1, gradient_smoothing=0, verb
105108
'input image has been replaced with a C-contiguous copy of itself')
106109
image = np.ascontiguousarray(image)
107110

111+
while image.ndim < 3:
112+
image = np.expand_dims(image, axis=0)
113+
108114
# Initialize objects
109115
io_int = pyapr.filegui.InteractiveIO()
110116
apr = pyapr.APR()

pyapr/viewer/partsViewer.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,26 +349,20 @@ def imageHoverEvent(self, event):
349349
self.cursor.setText(text_string)
350350

351351

352-
def parts_viewer(aAPR, Parts):
353-
pg.setConfigOption('background', 'w')
354-
pg.setConfigOption('foreground', 'k')
352+
def parts_viewer(apr, parts):
355353

356354
app = QtGui.QApplication.instance()
357355
if app is None:
358356
app = QtGui.QApplication([])
359357

358+
pg.setConfigOption('background', 'w')
359+
pg.setConfigOption('foreground', 'k')
360360
pg.setConfigOption('imageAxisOrder', 'row-major')
361361

362-
## Create window with GraphicsView widget
362+
# Create window with GraphicsView widget
363363
win = MainWindow()
364-
365364
win.add_level_toggle()
366-
367-
win.init_APR(aAPR, Parts)
368-
365+
win.init_APR(apr, parts)
369366
win.show()
370367

371368
app.exec_()
372-
373-
return None
374-

pyapr/viewer/raycastViewer.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ def valuechangeAniso(self):
285285

286286
def raycast_viewer(apr, parts):
287287

288+
# Raycast viewer currently only works for ShortParticles
289+
if isinstance(parts, pyapr.FloatParticles):
290+
print('Warning: raycast_viewer is currently only implemented for ShortParticles. '
291+
'Using a uint16 copy of the input particles.')
292+
parts_short = pyapr.ShortParticles()
293+
parts_short.copy(parts)
294+
else:
295+
parts_short = parts
296+
288297
pg.setConfigOption('background', 'w')
289298
pg.setConfigOption('foreground', 'k')
290299
pg.setConfigOption('imageAxisOrder', 'row-major')
@@ -293,31 +302,23 @@ def raycast_viewer(apr, parts):
293302
if app is None:
294303
app = QtGui.QApplication([])
295304

296-
## Create window with GraphicsView widget
305+
# Create window with GraphicsView widget
297306
win = MainWindowImage()
298-
299307
win.show()
300-
301308
win.apr_ref = apr
302-
303309
win.app_ref = app
304310

305311
raycaster = pyapr.viewer.raycaster()
306-
307312
raycaster.set_z_anisotropy(1)
308313
raycaster.set_radius(0.1)
309314

310315
win.view.setMouseEnabled(False, False)
311-
312316
win.raycaster_ref = raycaster
313-
314317
win.raycaster_ref.set_angle(win.current_theta)
315318
win.raycaster_ref.set_phi(win.current_phi)
316319

317320
tree_parts = pyapr.FloatParticles()
318-
319321
pyapr.viewer.get_down_sample_parts(apr, parts, tree_parts)
320322

321-
win.set_image(apr, parts, tree_parts)
322-
323+
win.set_image(apr, parts_short, tree_parts)
323324
app.exec_()

0 commit comments

Comments
 (0)