Skip to content

Commit

Permalink
add func: parallel_to_sequential
Browse files Browse the repository at this point in the history
  • Loading branch information
nachifur committed Aug 25, 2021
1 parent 73798a9 commit a15167f
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 112 deletions.
4 changes: 2 additions & 2 deletions MulimgViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def OnInit(self):
self.type = 0 # init show MulimgViewer
return True

def UpdateUI(self, type, input_path=None):
def UpdateUI(self, type, input_path=None, parallel_to_sequential=False):
# type=1: PathSelectFrame
# type=0: MulimgViewer
# type=-1: Close
Expand All @@ -50,7 +50,7 @@ def UpdateUI(self, type, input_path=None):
if len(input_path) != 0:
# refresh one_dir_mul_dir_manual path
self.frame[0].ImgManager.init(
input_path, 1)
input_path, 1,parallel_to_sequential)
self.frame[1].refresh_txt(input_path)

self.frame[0].show_img_init()
Expand Down
83 changes: 56 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,21 @@ def save_img(self, event):
self.SetStatusText_(["Save", "-1", "-1", "-1"])

def refresh(self, event):
self.SetStatusText_(["Refresh", "-1", "-1", "-1"])
if self.ImgManager.img_num != 0:
self.show_img_init()
self.show_img()
else:
self.SetStatusText_(
["-1", "", "***Error: First, need to select the input dir***", "-1"])
self.SetStatusText_(["Refresh", "-1", "-1", "-1"])

def one_dir_mul_dir_auto(self, event):
self.SetStatusText_(["Input", "", "", "-1"])
dlg = wx.DirDialog(None, "Parallel auto choose input dir", "",
wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
if dlg.ShowModal() == wx.ID_OK:
self.ImgManager.init(dlg.GetPath(), 0)
self.ImgManager.init(
dlg.GetPath(), 0, self.parallel_to_sequential.Value)
self.show_img_init()
self.ImgManager.set_action_count(0)
self.show_img()
Expand All @@ -215,7 +216,7 @@ def one_dir_mul_dir_manual(self, event):
input_path = None
except:
input_path = None
self.UpdateUI(1, input_path)
self.UpdateUI(1, input_path, self.parallel_to_sequential.Value)
self.choice_input_mode.SetSelection(2)
self.SetStatusText_(["Input", "-1", "-1", "-1"])

Expand Down Expand Up @@ -259,7 +260,8 @@ def input_flist_parallel_manual(self, event):
if dlg.ShowModal() == wx.ID_OK:
with open(dlg.GetPath(), "r") as f:
input_path = f.read().split('\n')
self.ImgManager.init(input_path[0:-1], 1)
self.ImgManager.init(
input_path[0:-1], 1, self.parallel_to_sequential.Value)
self.show_img_init()
self.ImgManager.set_action_count(0)
self.show_img()
Expand Down Expand Up @@ -469,7 +471,8 @@ def img_left_click(self, event):
# flip
if self.flip.Value:
x, y = event.GetPosition()
self.ImgManager.flip(self.get_img_id_from_point([x, y]),FLIP_TOP_BOTTOM = self.checkBox_orientation.Value)
self.ImgManager.flip(self.get_img_id_from_point(
[x, y]), FLIP_TOP_BOTTOM=self.checkBox_orientation.Value)
self.refresh(event)

self.SetStatusText_(["Flip", "-1", "-1", "-1"])
Expand Down Expand Up @@ -527,7 +530,8 @@ def img_left_release(self, event):
show_scale = [float(x) for x in show_scale]
points = self.ImgManager.ImgF.sort_box_point(
[x_0, y_0, x, y], show_scale, self.ImgManager.img_resolution_origin, first_point=True)
self.xy_magnifier.append(points+show_scale+[self.title_down_up.Value and self.title_show.Value])
self.xy_magnifier.append(
points+show_scale+[self.title_down_up.Value and self.title_show.Value])
self.refresh(event)

def img_right_click(self, event):
Expand All @@ -543,7 +547,8 @@ def img_right_click(self, event):
show_scale = self.show_scale.GetLineText(0).split(',')
show_scale = [float(x) for x in show_scale]
points = self.move_box_point(x, y, show_scale)
self.xy_magnifier.append(points+show_scale+[self.title_down_up.Value and self.title_show.Value])
self.xy_magnifier.append(
points+show_scale+[self.title_down_up.Value and self.title_show.Value])
except:
self.SetStatusText_(
["-1", "Drawing a box need click left mouse button!", "-1", "-1"])
Expand Down Expand Up @@ -580,11 +585,11 @@ def get_center_box(self, box, more=False):
def magnifier_fc(self, event):
self.start_flag = 0
i_cur = 0
status_toggle = [self.magnifier,self.rotation,self.flip]
status_toggle = [self.magnifier, self.rotation, self.flip]
if status_toggle[i_cur].Value:
self.SetCursor(wx.Cursor(wx.CURSOR_CROSS))
for i in range(len(status_toggle)):
if i!=i_cur and status_toggle[i].Value:
if i != i_cur and status_toggle[i].Value:
status_toggle[i].Value = False
self.SetStatusText_(["Magnifier", "-1", "-1", "-1"])
else:
Expand All @@ -593,11 +598,11 @@ def magnifier_fc(self, event):

def rotation_fc(self, event):
i_cur = 1
status_toggle = [self.magnifier,self.rotation,self.flip]
status_toggle = [self.magnifier, self.rotation, self.flip]
if status_toggle[i_cur].Value:
self.SetCursor(wx.Cursor(wx.CURSOR_POINT_RIGHT))
for i in range(len(status_toggle)):
if i!=i_cur and status_toggle[i].Value:
if i != i_cur and status_toggle[i].Value:
status_toggle[i].Value = False
self.SetStatusText_(["Rotate", "-1", "-1", "-1"])
else:
Expand All @@ -606,11 +611,12 @@ def rotation_fc(self, event):

def flip_fc(self, event):
i_cur = 2
status_toggle = [self.magnifier,self.rotation,self.flip]
status_toggle = [self.magnifier, self.rotation, self.flip]
if status_toggle[i_cur].Value:
self.SetCursor(wx.Cursor((wx.Image(str(Path("img")/"flip_cursor.png"),wx.BITMAP_TYPE_PNG))))
self.SetCursor(
wx.Cursor((wx.Image(str(Path("img")/"flip_cursor.png"), wx.BITMAP_TYPE_PNG))))
for i in range(len(status_toggle)):
if i!=i_cur and status_toggle[i].Value:
if i != i_cur and status_toggle[i].Value:
status_toggle[i].Value = False
self.SetStatusText_(["Flip", "-1", "-1", "-1"])
else:
Expand All @@ -623,10 +629,14 @@ def show_img_init(self):
# setting
self.ImgManager.layout_params = layout_params
if self.ImgManager.type == 0 or self.ImgManager.type == 1:
if self.parallel_sequential.Value:
self.ImgManager.set_count_per_action(layout_params[1])
if self.parallel_to_sequential.Value:
self.ImgManager.set_count_per_action(
layout_params[0]*layout_params[1]*layout_params[2])
else:
self.ImgManager.set_count_per_action(1)
if self.parallel_sequential.Value:
self.ImgManager.set_count_per_action(layout_params[1])
else:
self.ImgManager.set_count_per_action(1)
elif self.ImgManager.type == 2 or self.ImgManager.type == 3:
self.ImgManager.set_count_per_action(
layout_params[0]*layout_params[1]*layout_params[2])
Expand Down Expand Up @@ -689,10 +699,11 @@ def set_img_layout(self):
if title_setting[0]:
if self.ImgManager.type == 0 or self.ImgManager.type == 1:
# one_dir_mul_dir_auto / one_dir_mul_dir_manual
if self.parallel_sequential.Value:
if self.parallel_sequential.Value or self.parallel_to_sequential.Value:
title_setting[2:6] = [False, True, True, False]
else:
title_setting[2:6] = [False, True, False, False]

elif self.ImgManager.type == 2:
# one_dir_mul_img
title_setting[2:6] = [False, False, True, False]
Expand Down Expand Up @@ -724,15 +735,20 @@ def set_img_layout(self):
self.show_original.Value, # 16
title_setting, # 17
self.show_crop.Value, # 18
self.parallel_to_sequential.Value, # 19
self.checkBox_orientation.Value]

def show_img(self):
# check layout_params change
try:
if self.layout_params_old[0:3] != self.ImgManager.layout_params[0:3]:
if self.layout_params_old[0:3] != self.ImgManager.layout_params[0:3] or (self.layout_params_old[19] != self.ImgManager.layout_params[19]):
action_count = self.ImgManager.action_count
if self.ImgManager.type == 0 or self.ImgManager.type == 1:
parallel_to_sequential = self.parallel_to_sequential.Value
else:
parallel_to_sequential = False
self.ImgManager.init(
self.ImgManager.input_path, self.ImgManager.type)
self.ImgManager.input_path, self.ImgManager.type, parallel_to_sequential)
self.show_img_init()
self.ImgManager.set_action_count(action_count)
self.index_table.show_id_table(
Expand Down Expand Up @@ -789,14 +805,14 @@ def show_img(self):
["-1", str(self.ImgManager.action_count), str(self.ImgManager.img_resolution[0])+"x"+str(self.ImgManager.img_resolution[1])+" pixels / "+str(self.ImgManager.name_list[self.ImgManager.img_count])+"-"+str(self.ImgManager.name_list[self.ImgManager.img_num-1]), "-1"])
else:
self.SetStatusText_(
["-1", str(self.ImgManager.action_count), str(self.ImgManager.img_resolution[0])+"x"+str(self.ImgManager.img_resolution[1])+" pixels / "+str(self.ImgManager.name_list[self.ImgManager.action_count]), "-1"])
["-1", str(self.ImgManager.action_count), str(self.ImgManager.img_resolution[0])+"x"+str(self.ImgManager.img_resolution[1])+" pixels / "+self.ImgManager.get_stitch_name(), "-1"])

if flag == 1:
self.SetStatusText_(
["-1", str(self.ImgManager.action_count), "***Error: "+str(self.ImgManager.name_list[self.ImgManager.action_count]) + ", during stitching images***", "-1"])
if flag == 2:
self.SetStatusText_(
["-1", "-1","No image is displayed! Check Show orignal/Show 🔍️/Show title.", "-1"])
["-1", "-1", "No image is displayed! Check Show orignal/Show 🔍️/Show title.", "-1"])
else:
self.SetStatusText_(
["-1", "-1", "***Error: no image in this dir! Maybe you can choose parallel mode!***", "-1"])
Expand Down Expand Up @@ -885,13 +901,18 @@ def change_img_stitch_mode(self, event):
def get_img_id_from_point(self, xy):
# get img_id from grid points
xy_grid = np.array(self.ImgManager.xy_grid)
xy_grid_x = xy_grid[:,0].reshape(2,2)
xy_grid_y = xy_grid[:,1].reshape(2,2)
num_per_img = int(self.num_per_img.GetLineText(0))
img_num_per_row = int(self.img_num_per_row.GetLineText(0))
img_num_per_column = int(self.img_num_per_column.GetLineText(0))
col = num_per_img*img_num_per_row
row = img_num_per_column
xy_grid_x = xy_grid[:, 0].reshape(row, col)
xy_grid_y = xy_grid[:, 1].reshape(row, col)

xy_cur = np.array([xy])
xy_cur = np.repeat(xy_cur, xy_grid.shape[0], axis=0)
xy_cur_x = xy_cur[:,0].reshape(2,2)
xy_cur_y = xy_cur[:,1].reshape(2,2)
xy_cur_x = xy_cur[:, 0].reshape(row, col)
xy_cur_y = xy_cur[:, 1].reshape(row, col)

if self.checkBox_orientation.Value:
xy_grid_x = xy_grid_x.T
Expand All @@ -911,8 +932,16 @@ def get_img_id_from_point(self, xy):
id_list.append(-1)
return max(id_list)

def title_down_up_func(self, event):
def title_down_up_fc(self, event):
if self.title_down_up.Value:
self.title_down_up.SetLabel('Up ')
else:
self.title_down_up.SetLabel('Down')

def parallel_sequential_fc(self,event):
if self.parallel_sequential.Value:
self.parallel_to_sequential.Value=False

def parallel_to_sequential_fc( self, event ):
if self.parallel_to_sequential.Value:
self.parallel_sequential.Value=False
12 changes: 10 additions & 2 deletions main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,10 @@ def __init__( self, parent ):
self.rotation.Bind( wx.EVT_TOGGLEBUTTON, self.rotation_fc )
self.flip.Bind( wx.EVT_TOGGLEBUTTON, self.flip_fc )
self.choice_normalized_size.Bind( wx.EVT_CHOICE, self.change_img_stitch_mode )
self.parallel_sequential.Bind( wx.EVT_CHECKBOX, self.parallel_sequential_fc )
self.parallel_to_sequential.Bind( wx.EVT_CHECKBOX, self.parallel_to_sequential_fc )
self.select_img_box.Bind( wx.EVT_CHECKBOX, self.select_img_box_func )
self.title_down_up.Bind( wx.EVT_CHECKBOX, self.title_down_up_func )
self.title_down_up.Bind( wx.EVT_CHECKBOX, self.title_down_up_fc )
self.colourPicker_gap.Bind( wx.EVT_COLOURPICKER_CHANGED, self.colour_change )
self.background_slider.Bind( wx.EVT_SCROLL, self.background_alpha )
self.foreground_slider.Bind( wx.EVT_SCROLL, self.foreground_alpha )
Expand Down Expand Up @@ -791,10 +793,16 @@ def flip_fc( self, event ):
def change_img_stitch_mode( self, event ):
event.Skip()

def parallel_sequential_fc( self, event ):
event.Skip()

def parallel_to_sequential_fc( self, event ):
event.Skip()

def select_img_box_func( self, event ):
event.Skip()

def title_down_up_func( self, event ):
def title_down_up_fc( self, event ):
event.Skip()

def colour_change( self, event ):
Expand Down
Loading

0 comments on commit a15167f

Please sign in to comment.