mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 02:07:51 -06:00
Clean up snapshot code
This commit is contained in:
parent
d0cf7f04bf
commit
37b904a3c4
1 changed files with 10 additions and 7 deletions
|
@ -73,10 +73,11 @@ class Snapshot:
|
||||||
satisfied = False
|
satisfied = False
|
||||||
size = None
|
size = None
|
||||||
fovy = 30
|
fovy = 30
|
||||||
|
min_x, min_y, max_x, max_y = 0, 0, 0, 0
|
||||||
|
|
||||||
while not satisfied:
|
while not satisfied:
|
||||||
if size is not None:
|
if size is not None:
|
||||||
satisfied = True # always be satisfied after second try
|
satisfied = True # Always be satisfied after second try
|
||||||
projection_matrix = Matrix()
|
projection_matrix = Matrix()
|
||||||
# Somehow the aspect ratio is also influenced in reverse by the screen width/height
|
# Somehow the aspect ratio is also influenced in reverse by the screen width/height
|
||||||
# So you have to set it to render_width/render_height to get 1
|
# So you have to set it to render_width/render_height to get 1
|
||||||
|
@ -92,16 +93,18 @@ class Snapshot:
|
||||||
if size > 0.5 or satisfied:
|
if size > 0.5 or satisfied:
|
||||||
satisfied = True
|
satisfied = True
|
||||||
else:
|
else:
|
||||||
# make it big and allow for some empty space around
|
# Make it big and allow for some empty space around
|
||||||
fovy *= 0.5 # strangely enough this messes up the aspect ratio: fovy *= size * 1.1
|
fovy *= 0.5 # strangely enough this messes up the aspect ratio: fovy *= size * 1.1
|
||||||
|
width = max_x - min_x
|
||||||
# make it a square
|
height = max_y - min_y
|
||||||
if max_x - min_x >= max_y - min_y:
|
# Make it a square
|
||||||
|
if width >= height:
|
||||||
# make y bigger
|
# make y bigger
|
||||||
min_y, max_y = int((max_y + min_y) / 2 - (max_x - min_x) / 2), int((max_y + min_y) / 2 + (max_x - min_x) / 2)
|
min_y, max_y = int(height / 2 - width / 2), int(height / 2 + width / 2)
|
||||||
else:
|
else:
|
||||||
# make x bigger
|
# make x bigger
|
||||||
min_x, max_x = int((max_x + min_x) / 2 - (max_y - min_y) / 2), int((max_x + min_x) / 2 + (max_y - min_y) / 2)
|
min_x, max_x = int(width / 2 - height / 2), int(width / 2 + height / 2)
|
||||||
|
|
||||||
cropped_image = pixel_output.copy(min_x, min_y, max_x - min_x, max_y - min_y)
|
cropped_image = pixel_output.copy(min_x, min_y, max_x - min_x, max_y - min_y)
|
||||||
|
|
||||||
# Scale it to the correct size
|
# Scale it to the correct size
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue