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

Label on rois #600

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
99b2d64
add text field on rectangle
Rdornier Sep 6, 2024
1a10a0a
Merge branch 'master' of https://github.com/Rdornier/omero-figure int…
Rdornier Sep 9, 2024
d776a58
Merge remote-tracking branch 'origin/master' into label-on-rois
Rdornier Oct 1, 2024
b30646f
Merge branch 'master' into label-on-rois
Rdornier Nov 6, 2024
090f19e
Adding simple text label to rectangles
Rdornier Nov 6, 2024
7095371
adding fontsize
Rdornier Nov 6, 2024
9762e68
adding fill color
Rdornier Nov 6, 2024
bdec709
adding text position
Rdornier Nov 6, 2024
bbd8091
fixing rotation
Rdornier Nov 6, 2024
a6895ce
fixing text offset
Rdornier Nov 6, 2024
ac1c5be
Fixing label position with stroke width and adding corner positions
Rdornier Nov 7, 2024
d0a90bb
Fix text zoom
Rdornier Nov 7, 2024
7206309
add label on ellipses
Rdornier Nov 7, 2024
1347a52
handle rectangle rotation to position text properly
Rdornier Nov 7, 2024
d2f54e1
attempt to align text and shape rotation
Rdornier Nov 7, 2024
10c11a5
Adding toolbar + fixing text-roi overlap bug
Rdornier Nov 8, 2024
a0851fd
refactor text & rect to figure interface
Rdornier Nov 8, 2024
44554fa
adding text to the createShape method
Rdornier Nov 11, 2024
4e796a7
fix color
Rdornier Nov 11, 2024
b0afc1b
adding shape to panel and refactor x/y
Rdornier Nov 11, 2024
d59a4a0
apply zoom fraction on text offset instead of final positon
Rdornier Nov 12, 2024
e2313e5
Fixing roi reloading bug
Rdornier Nov 12, 2024
79d99a3
Fixing text anchor
Rdornier Nov 12, 2024
addeb43
Fixing text display and position on panel
Rdornier Nov 12, 2024
eca7121
Adding text to inset
Rdornier Nov 14, 2024
65a89ab
Automatic increment of inset text
Rdornier Nov 14, 2024
436e22b
delete text and increment text on inset properly
Rdornier Nov 14, 2024
58d4a6d
adding corresponding label to inset
Rdornier Nov 15, 2024
c274811
update gui and fix mousetrap
Rdornier Nov 15, 2024
e2091b9
handle copy-pasting not copying the label
Rdornier Nov 25, 2024
63e17f0
Merge branch 'master' into label-on-rois
Rdornier Nov 25, 2024
963dafa
update toolbar
Rdornier Nov 25, 2024
2204527
fix text getter and setter to be compatible with fill-color
Rdornier Nov 25, 2024
e7da396
Fix number of ROI displayed in the right panel
Rdornier Nov 25, 2024
d749b7f
Fix html layout
Rdornier Nov 25, 2024
23e9723
Merge branch 'ome:master' into label-on-rois
Rdornier Nov 27, 2024
4524d9b
Merge branch 'master' into label-on-rois
Rdornier Nov 27, 2024
e274671
delete temporary text shape when loading rois from omero
Rdornier Nov 27, 2024
83880a7
Adding text to pdf
Rdornier Nov 27, 2024
6975330
Merge branch 'ome:master' into label-on-rois
Rdornier Nov 27, 2024
57dc83f
remove empty spaces
Rdornier Nov 27, 2024
15e5160
Merge branch 'label-on-rois' of https://github.com/Rdornier/omero-fig…
Rdornier Nov 27, 2024
6a396be
Merge branch 'ome:master' into label-on-rois
Rdornier Nov 29, 2024
1bb2a89
Merge branch 'label-on-rois' of https://github.com/Rdornier/omero-fig…
Rdornier Nov 29, 2024
a57f41f
Merge commit 'refs/pull/603/head' of https://github.com/ome/omero-fig…
Rdornier Nov 29, 2024
a0b083f
Fix inset text position
Rdornier Nov 29, 2024
c1ad882
fix inset text according to stroke width
Rdornier Dec 3, 2024
0bb441f
adding scaling factor to inset
Rdornier Dec 3, 2024
30ac73f
synchronizing inset labels
Rdornier Dec 4, 2024
ec6c96b
fix flake 8 errors and markdown
Rdornier Dec 4, 2024
9b9f8b3
fix flake 8 errors
Rdornier Dec 4, 2024
e2a6dc5
handle rotation
Rdornier Dec 9, 2024
080ee54
fix text rotation with inset rotation
Rdornier Dec 9, 2024
3bc7003
Merge branch 'ome:master' into label-on-rois
Rdornier Dec 10, 2024
69cb6a9
Remove unused lines
Rdornier Dec 10, 2024
45d0077
Merge branch 'label-on-rois' of https://github.com/Rdornier/omero-fig…
Rdornier Dec 10, 2024
fd13b0c
Merge branch 'ome:master' into label-on-rois
Rdornier Dec 16, 2024
b4ab613
Merge branch 'label-on-rois' of https://github.com/Rdornier/omero-fig…
Rdornier Dec 16, 2024
49cfdd7
try fixing rotation --> on going
Rdornier Jan 8, 2025
355e252
Merge branch 'ome:master' into label-on-rois
Rdornier Jan 14, 2025
3643b99
Merge branch 'label-on-rois' of https://github.com/Rdornier/omero-fig…
Rdornier Jan 14, 2025
b5cd436
fix PDf export
Rdornier Jan 17, 2025
989108d
Adding tiff export
Rdornier Jan 17, 2025
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.pyc
.DS_Store
.omero
.idea
.vscode
demo/omero_figure/
demo/figure.js
demo/index.html
Expand Down
191 changes: 181 additions & 10 deletions omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import os
from os import path
import zipfile
from math import atan2, atan, sin, cos, sqrt, radians, floor, ceil, log2
from math import atan2, atan, sin, cos, sqrt, radians, floor, ceil, log2, fmod
from copy import deepcopy
import re

Expand Down Expand Up @@ -278,13 +278,14 @@ def draw_point(self, shape):
class ShapeToPdfExport(ShapeExport):
point_radius = 5

def __init__(self, canvas, panel, page, crop, page_height):
def __init__(self, canvas, panel, page, crop, page_height, page_width):

self.canvas = canvas
self.page = page
# The crop region on the original image coordinates...
self.crop = crop
self.page_height = page_height
self.page_width = page_width
# Get a mapping from original coordinates to the actual size of panel
self.scale = float(panel['width']) / crop['width']

Expand All @@ -304,9 +305,9 @@ def panel_to_page_coords(self, shape_x, shape_y):
h_flip = self.panel.get('horizontal_flip', False)
v_flip = self.panel.get('vertical_flip', False)
if h_flip:
shape_x = self.crop['width'] - shape_x + 2*self.crop['x']
shape_x = self.crop['width'] - shape_x + 2 * self.crop['x']
if v_flip:
shape_y = self.crop['height'] - shape_y + 2*self.crop['y']
shape_y = self.crop['height'] - shape_y + 2 * self.crop['y']

rotation = self.panel['rotation']
if v_flip != h_flip:
Expand Down Expand Up @@ -370,6 +371,92 @@ def draw_shape_label(self, shape, bounds):
para.drawOn(
self.canvas, center[0] - w / 2, center[1] - h / 2 + size / 4)

def draw_text(self, shape):
text_coords = self.panel_to_page_coords(shape['x'], shape['y'])
text = ""

if markdown_imported:
# convert markdown to html
text = markdown.markdown(shape.get('text'))

size = shape.get('fontSize', 12)
stroke_width = shape.get('strokeWidth', 2)
r, g, b, a = self.get_rgba(shape['strokeColor'])
# bump up alpha a bit to make text more readable
rgba = (r, g, b, 0.5 + a / 2.0)

x = text_coords["x"]
y = self.page_height - text_coords["y"]
anchor = shape['textAnchor']
aligment = TA_LEFT

if (anchor == 'middle'):
aligment = TA_CENTER
x = x - (self.page_width / 2)
elif (anchor == "end"):
aligment = TA_RIGHT
x = x - self.page_width

style = ParagraphStyle(
'label',
parent=getSampleStyleSheet()['Normal'],
alignment=aligment,
textColor=Color(*rgba),
fontSize=size,
leading=size,
)
para = Paragraph(text, style)
w, h = para.wrap(self.page_width, y)

rotation = shape.get('textRotation', 0)
panel_rotation = shape.get('rotation', 0)
rotation = rotation + panel_rotation

text_position = shape['textPosition']
text_offset_x = stroke_width / 4 + 4
text_offset_y = size / 2 + stroke_width / 4 + 4
outPositions = ["top", "left", "bottom","right"]
inPositions = ["topleft", "bottomleft", "bottomright", "topright"]
rotationIndex = fmod(floor((360 - rotation + 45) / 90), 4)
finalIndex = 0

if text_position in ["bottom", "top", "right", "left"]:
posIndex = outPositions.index(text_position)
finalIndex = int(fmod((posIndex + rotationIndex), 4))
text_position = outPositions[finalIndex]
if text_position in ["topleft", "topright", "bottomleft", "bottomright"]:
posIndex = inPositions.index(text_position)
finalIndex = int(fmod((posIndex + rotationIndex), 4))
text_position = inPositions[finalIndex]

if text_position == "bottom":
dx = 0;
dy = text_offset_y;
if text_position == "left":
dx = -text_offset_x;
dy = 0;
if text_position == "right":
dx = text_offset_x;
dy = 0;
if text_position == "top":
dx = 0;
dy = -stroke_width / 2
if text_position == "topleft":
dx = text_offset_x;
dy = text_offset_y;
if text_position == "topright":
dx = -text_offset_x;
dy = text_offset_y;
if text_position == "bottomleft":
dx = text_offset_x;
dy = -stroke_width / 2
if text_position == "bottomright":
dx = -text_offset_x;
dy = -stroke_width / 2

para.drawOn(self.canvas, x + dx, y - dy)


def draw_line(self, shape):
start = self.panel_to_page_coords(shape['x1'], shape['y1'])
end = self.panel_to_page_coords(shape['x2'], shape['y2'])
Expand Down Expand Up @@ -599,9 +686,9 @@ def get_panel_coords(self, shape_x, shape_y):

# Apply flip transformations to the shape coordinates
if h_flip:
shape_x = self.crop['width'] - shape_x + 2*self.crop['x']
shape_x = self.crop['width'] - shape_x + 2 * self.crop['x']
if v_flip:
shape_y = self.crop['height'] - shape_y + 2*self.crop['y']
shape_y = self.crop['height'] - shape_y + 2 * self.crop['y']

rotation = self.panel['rotation']
if v_flip != h_flip:
Expand Down Expand Up @@ -655,6 +742,90 @@ def draw_shape_label(self, shape, bounds):
xy = (int(center[0] - width / 2.0), int(center[1] - height / 2.0))
self.draw.text(xy, text, fill=rgba, font=font)

def draw_text(self, shape):
text_coords = self.get_panel_coords(shape['x'], shape['y'])
text = ""

text = shape.get('text')

font_size_dpi = scale_to_export_dpi(shape.get('fontSize', 12))
stroke_width = shape.get('strokeWidth', 2)
stroke_width_dpi = scale_to_export_dpi(float(stroke_width))

r, g, b, a = self.get_rgba_int(shape['strokeColor'])
# bump up alpha a bit to make text more readable
rgba = (r, g, b, int(128 + a / 2))
font_name = "FreeSans.ttf"
from omero.gateway import THISPATH
path_to_font = os.path.join(THISPATH, "pilfonts", font_name)
try:
font = ImageFont.truetype(path_to_font, font_size_dpi)
except Exception:
font = ImageFont.load(
'%s/pilfonts/B%0.2d.pil' % (self.GATEWAYPATH, font_size_dpi))

box = font.getbbox(text)
txt_w = box[2] - box[0]
txt_h = box[3] - box[1]

x = text_coords["x"]
y = text_coords["y"]
anchor = shape['textAnchor']

if (anchor == 'middle'):
x = x - txt_w / 2
elif (anchor == "end"):
x = x - txt_w

rotation = shape.get('textRotation', 0)
panel_rotation = shape.get('rotation', 0)
rotation = rotation + panel_rotation

text_position = shape['textPosition']
text_offset_x = scale_to_export_dpi(stroke_width / 4 + 4)
outPositions = ["top", "left", "bottom","right"]
inPositions = ["topleft", "bottomleft", "bottomright", "topright"]
rotationIndex = fmod(floor((360 - rotation + 45) / 90), 4)
finalIndex = 0

if text_position in ["bottom", "top", "right", "left"]:
posIndex = outPositions.index(text_position)
finalIndex = int(fmod((posIndex + rotationIndex), 4))
text_position = outPositions[finalIndex]
if text_position in ["topleft", "topright", "bottomleft", "bottomright"]:
posIndex = inPositions.index(text_position)
finalIndex = int(fmod((posIndex + rotationIndex), 4))
text_position = inPositions[finalIndex]

if text_position == "bottom":
dx = 0;
dy = stroke_width_dpi / 4
if text_position == "left":
dx = -text_offset_x;
dy = -txt_h / 2;
if text_position == "right":
dx = text_offset_x;
dy = -txt_h / 2;
if text_position == "top":
dx = 0;
dy = -font_size_dpi - stroke_width_dpi / 2
if text_position == "topleft":
dx = text_offset_x;
dy = 2;
if text_position == "topright":
dx = -text_offset_x;
dy = 2;
if text_position == "bottomleft":
dx = text_offset_x;
dy = -font_size_dpi - stroke_width_dpi / 2
if text_position == "bottomright":
dx = -text_offset_x;
dy = -font_size_dpi - stroke_width_dpi / 2

xy = (x + dx, y + dy)

self.draw.text(xy, text, fill=rgba, font=font)

def draw_arrow(self, shape):

start = self.get_panel_coords(shape['x1'], shape['y1'])
Expand Down Expand Up @@ -733,7 +904,7 @@ def draw_rectangle(self, shape):
# with correct stroke width
r, g, b, a = self.get_rgba_int(shape.get('fillColor', '#00000000'))
if 'fillOpacity' in shape:
a = int(float(shape['fillOpacity'])*255)
a = int(float(shape['fillOpacity']) * 255)
rgba = (r, g, b, a)

# need to draw on separate image and then paste on to get transparency
Expand Down Expand Up @@ -792,7 +963,7 @@ def draw_polygon(self, shape, closed=True):
# with correct stroke width
r, g, b, a = self.get_rgba_int(shape.get('fillColor', '#00000000'))
if 'fillOpacity' in shape:
a = int(float(shape['fillOpacity'])*255)
a = int(float(shape['fillOpacity']) * 255)
rgba = (r, g, b, a)

# need to draw on separate image and then paste on to get transparency
Expand Down Expand Up @@ -878,7 +1049,7 @@ def draw_ellipse(self, shape):

r, g, b, a = self.get_rgba_int(shape.get('fillColor', '#00000000'))
if 'fillOpacity' in shape:
a = int(float(shape['fillOpacity'])*255)
a = int(float(shape['fillOpacity']) * 255)
rgba = (r, g, b, a)

# when rx is ~zero (for a Point, scaled down) don't need inner ellipse
Expand Down Expand Up @@ -1281,7 +1452,7 @@ def add_rois(self, panel, page):

crop = self.get_crop_region(panel)
ShapeToPdfExport(self.figure_canvas, panel, page, crop,
self.page_height)
self.page_height, self.page_width)

def draw_labels(self, panel, page):
"""
Expand Down
4 changes: 4 additions & 0 deletions src/css/figure.css
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@
padding-left: 3px;
padding-right: 3px;
}
.text-group{
padding-left: 0px;
padding-right: 0px;
}
.navbar-nav > li > a {
padding-bottom: 12px;
padding-top: 12px;
Expand Down
15 changes: 0 additions & 15 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,6 @@ <h5 class="modal-title" style="float: left; padding-right: 20px">
</div>
</div>
<div id="roiModalSidebar" class="col-4" style="padding: 0">
<span
id="roiPageControls"
style="color: #999; line-height: 30px"
>
</span>
<div style="clear: both"></div>
<div style="padding: 0; height: 550px; overflow-y: auto; position: relative;">
<div id="roiModalRoiList">
<table
style="width: 100%"
class="table table-hover table-condensed"
></table>
</div>
<p id="roiModalTip" style="position: absolute; top: 0"></p>
</div>
</div>
</div>
<div class="modal-footer" style="margin-top: 0">
Expand Down
Loading
Loading