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

Fill rois #577

Merged
merged 31 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
55438c4
handle roi filling
Rdornier Jul 3, 2024
e2d88d2
handle opacity
Rdornier Jul 3, 2024
735a5ee
fix bug with color picker
Rdornier Jul 3, 2024
e6663e6
handle ellipse
Rdornier Jul 3, 2024
06012fb
handle polygon/polyline
Rdornier Jul 3, 2024
42fbff0
handle line to avoid errors
Rdornier Jul 3, 2024
0fb5f26
update css
Rdornier Jul 3, 2024
ace4591
remove static files
Rdornier Jul 12, 2024
ea2a045
update gitignore
Rdornier Jul 12, 2024
dcd6dae
read opacity for loaded rois
Rdornier Jul 12, 2024
6d5d511
format opacity to 2 decimal places
Rdornier Jul 12, 2024
df540f6
Merge branch 'ome:master' into fill-rois
Rdornier Aug 12, 2024
7ce2ce9
Merge branch 'ome:master' into fill-rois
Rdornier Aug 21, 2024
b088368
Merge branch 'ome:master' into fill-rois
Rdornier Aug 23, 2024
df6f353
updating figure to pdf
Rdornier Aug 27, 2024
3c605ca
Fix bug on export tiff
Rdornier Aug 28, 2024
23f5008
Fix flake8 build failure by adding whitespace
Rdornier Aug 29, 2024
cde38a5
Check if fillOpacity is given in shape
Rdornier Aug 30, 2024
2a557ad
Merge branch 'ome:master' into fill-rois
Rdornier Sep 3, 2024
05cc298
Merge branch 'master' of https://github.com/Rdornier/omero-figure int…
Rdornier Sep 9, 2024
1535381
Merge branch 'ome:master' into fill-rois
Rdornier Oct 1, 2024
6208bcd
Merge branch 'master' into fill-rois
Rdornier Oct 10, 2024
6fee74b
Merge branch 'fill-rois' of https://github.com/Rdornier/omero-figure …
Rdornier Oct 10, 2024
2a35068
Fix snoopycrimecop conflict
Rdornier Oct 11, 2024
4069931
update gitignore
Rdornier Oct 11, 2024
c03b871
Merge branch 'ome:master' into fill-rois
Rdornier Oct 24, 2024
c7b731c
fix decimal places on opacities
Rdornier Nov 4, 2024
f3277f8
Handle points
Rdornier Nov 4, 2024
237b88b
fix decimal places on opacity where selecting shapes again
Rdornier Nov 4, 2024
3e71003
fix toolbar wrapping thanks to will
Rdornier Nov 4, 2024
fc8e383
correctly read opacity from rois coming from omero
Rdornier Nov 4, 2024
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
21 changes: 18 additions & 3 deletions omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ def draw_polygon(self, shape, closed=True):

if 'fillColor' in shape:
r, g, b, a = self.get_rgba(shape['fillColor'])
if 'fillOpacity' in shape:
a = float(shape['fillOpacity'])
self.canvas.setFillColorRGB(r, g, b, alpha=a)
fill = 1 if closed else 0
else:
Expand Down Expand Up @@ -471,6 +473,8 @@ def draw_ellipse(self, shape):

if 'fillColor' in shape:
r, g, b, a = self.get_rgba(shape['fillColor'])
if 'fillOpacity' in shape:
a = float(shape['fillOpacity'])
self.canvas.setFillColorRGB(r, g, b, alpha=a)
fill = 1
else:
Expand Down Expand Up @@ -646,7 +650,10 @@ def draw_rectangle(self, shape):

# if fill, draw filled polygon without outline, then add line later
# with correct stroke width
rgba = self.get_rgba_int(shape.get('fillColor', '#00000000'))
r, g, b, a = self.get_rgba_int(shape.get('fillColor', '#00000000'))
if 'fillOpacity' in shape:
a = int(float(shape['fillOpacity'])*255)
rgba = (r, g, b, a)

# need to draw on separate image and then paste on to get transparency
bounds = Bounds(*points).round()
Expand Down Expand Up @@ -702,7 +709,10 @@ def draw_polygon(self, shape, closed=True):

# if fill, draw filled polygon without outline, then add line later
# with correct stroke width
rgba = self.get_rgba_int(shape.get('fillColor', '#00000000'))
r, g, b, a = self.get_rgba_int(shape.get('fillColor', '#00000000'))
if 'fillOpacity' in shape:
a = int(float(shape['fillOpacity'])*255)
rgba = (r, g, b, a)

# need to draw on separate image and then paste on to get transparency
bounds = Bounds(*points).round()
Expand Down Expand Up @@ -771,7 +781,12 @@ def draw_ellipse(self, shape):
# Draw outer ellipse, then remove inner ellipse with full opacity
rgba = ShapeToPdfExport.get_rgba_int(shape['strokeColor'])
ellipse_draw.ellipse((0, 0, width, height), fill=rgba)
rgba = self.get_rgba_int(shape.get('fillColor', '#00000000'))

r, g, b, a = self.get_rgba_int(shape.get('fillColor', '#00000000'))
if 'fillOpacity' in shape:
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
if (width - w) >= w:
ellipse_draw.ellipse((w, w, width - w, height - w), fill=rgba)
Expand Down
4 changes: 3 additions & 1 deletion src/css/figure.css
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@

.colorpicker span,
.inset-color span:first-child,
.fill-color span:first-child,
.label-color span:first-child,
.shape-color span:first-child {
border: solid 1px #bbb;
Expand Down Expand Up @@ -1238,7 +1239,8 @@

.roi_toolbar {
overflow: visible;
padding-bottom: 10px;
margin: 15px;
margin-bottom: 5px;
}

.roi_toolbar .pressed {
Expand Down
14 changes: 7 additions & 7 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ <h5 class="modal-title" style="float: left; padding-right: 20px">
</p>
</div>
<form class="roiModalForm" role="form">
<div
id="roi_toolbar"
class="roi_toolbar btn-toolbar"
role="toolbar"
aria-label="..."
></div>
<div class="modal-body row">
<div class="col-8">
<div
id="roi_toolbar"
class="roi_toolbar btn-toolbar"
role="toolbar"
aria-label="..."
></div>
<div id="roiViewer" class="roiViewer">
<!-- Show / add ROIs on image -->
<!-- <div id="roi_image" style="position: absolute"> -->
Expand Down Expand Up @@ -213,7 +213,7 @@ <h5 class="modal-title" style="float: left; padding-right: 20px">
style="color: #999; line-height: 30px"
>
</span>
<div style="clear: both; padding: 5px"></div>
<div style="clear: both"></div>
<div style="padding: 0; height: 550px; overflow-y: auto; position: relative;">
<div id="roiModalRoiList">
<table
Expand Down
11 changes: 11 additions & 0 deletions src/js/models/roi_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ var ShapeModel = Backbone.Model.extend({
intAsHex = ("00000000" + intAsHex).slice(-8);
return '#' + intAsHex.substring(0,6);
}

var rgbint_to_opacity = function(signed_integer) {
if (signed_integer < 0) signed_integer = signed_integer >>> 0;
var intAsHex = signed_integer.toString(16);
intAsHex = ("00000000" + intAsHex).slice(-2);
return parseInt(intAsHex, 16) / 255;
}

shape.id = shape['@id'];
shape.type = shape['@type'].split('#')[1];
delete shape['@id']
Expand All @@ -27,6 +35,9 @@ var ShapeModel = Backbone.Model.extend({
_.each(["StrokeColor", "FillColor", ], function(attr) {
if (shape[attr] !== undefined) {
shape[lowerFirst(attr)] = rgbint_to_css(shape[attr]);
// strokeColor -> strokeOpacity, fillColor -> fillOpacity
let opacityAttr = lowerFirst(attr).replace("Color", "Opacity")
shape[opacityAttr] = rgbint_to_opacity(shape[attr]);
delete shape[attr];
}
});
Expand Down
46 changes: 42 additions & 4 deletions src/js/shape_editor/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
// disclaimer in the documentation // and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS
Expand Down Expand Up @@ -66,6 +66,16 @@ var Ellipse = function Ellipse(options) {
}

this._strokeColor = options.strokeColor;
if(options.fillColor){
this._fillColor = options.fillColor;
}else{
this._fillColor = "#ffffff";
}
if(options.fillOpacity){
this._fillOpacity = options.fillOpacity;
}else{
this._fillOpacity = 0;
}
this._strokeWidth = options.strokeWidth || 2;
this._selected = false;
this._zoomFraction = 1;
Expand All @@ -80,7 +90,7 @@ var Ellipse = function Ellipse(options) {
this.handle_wh = 6;

this.element = this.paper.ellipse();
this.element.attr({ "fill-opacity": 0.01, fill: "#fff", cursor: "pointer" });
this.element.attr({ "fill-opacity": this._fillOpacity, fill: this._fillColor, cursor: "pointer" });

// Drag handling of ellipse
if (this.manager.canEdit) {
Expand Down Expand Up @@ -138,6 +148,8 @@ Ellipse.prototype.toJson = function toJson() {
rotation: this._rotation,
strokeWidth: this._strokeWidth,
strokeColor: this._strokeColor,
fillColor: this._fillColor,
fillOpacity: this._fillOpacity
};
if (this._id) {
rv.id = this._id;
Expand Down Expand Up @@ -204,6 +216,24 @@ Ellipse.prototype.getStrokeWidth = function getStrokeWidth() {
return this._strokeWidth;
};

Ellipse.prototype.setFillColor = function setFillColor(fillColor) {
this._fillColor = fillColor;
this.drawShape();
};

Ellipse.prototype.getFillColor = function getFillColor() {
return this._fillColor;
};

Ellipse.prototype.setFillOpacity = function setFillOpacity(fillOpacity) {
this._fillOpacity = fillOpacity;
this.drawShape();
};

Ellipse.prototype.getFillOpacity = function getFillOpacity() {
return this._fillOpacity;
};

Ellipse.prototype.destroy = function destroy() {
this.element.remove();
this.handles.remove();
Expand Down Expand Up @@ -353,7 +383,9 @@ Ellipse.prototype.updateShapeFromHandles = function updateShapeFromHandles(

Ellipse.prototype.drawShape = function drawShape() {
var strokeColor = this._strokeColor,
strokeW = this._strokeWidth;
strokeW = this._strokeWidth,
fillColor = this._fillColor,
fillOpacity = this._fillOpacity;

var f = this._zoomFraction,
x = this._x * f,
Expand All @@ -368,6 +400,8 @@ Ellipse.prototype.drawShape = function drawShape() {
ry: radiusY,
stroke: strokeColor,
"stroke-width": strokeW,
fill: fillColor,
'fill-opacity': fillOpacity
});
this.element.transform("r" + this._rotation);

Expand Down Expand Up @@ -520,6 +554,8 @@ var CreateEllipse = function CreateEllipse(options) {
CreateEllipse.prototype.startDrag = function startDrag(startX, startY) {
var strokeColor = this.manager.getStrokeColor(),
strokeWidth = this.manager.getStrokeWidth(),
fillColor = this.manager.getFillColor(),
fillOpacity = this.manager.getFillOpacity(),
zoom = this.manager.getZoom();

this.ellipse = new Ellipse({
Expand All @@ -534,6 +570,8 @@ CreateEllipse.prototype.startDrag = function startDrag(startX, startY) {
strokeWidth: strokeWidth,
zoom: zoom,
strokeColor: strokeColor,
fillColor: fillColor,
fillOpacity: fillOpacity
});
};

Expand Down
16 changes: 16 additions & 0 deletions src/js/shape_editor/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ Line.prototype.getStrokeWidth = function getStrokeWidth() {
return this._strokeWidth;
};

Line.prototype.getFillColor = function getFillColor() {
return this._strokeColor;
};

Line.prototype.setFillColor = function setFillColor(fillColor) {
return;
};

Line.prototype.setFillOpacity = function setFillOpacity(fillOpacity) {
return;
};

Line.prototype.getFillOpacity = function getFillOpacity() {
return 1;
};

Line.prototype.destroy = function destroy() {
this.element.remove();
this.handles.remove();
Expand Down
49 changes: 45 additions & 4 deletions src/js/shape_editor/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
// disclaimer in the documentation // and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS
Expand Down Expand Up @@ -49,6 +49,18 @@ var Point = function Point(options) {
}

this._strokeColor = options.strokeColor;

if(options.fillColor){
this._fillColor = options.fillColor;
}else{
this._fillColor = "#ffffff";
}
if(options.fillOpacity){
this._fillOpacity = options.fillOpacity;
}else{
this._fillOpacity = 0;
}

this._strokeWidth = options.strokeWidth || 2;
this._selected = false;
this._zoomFraction = 1;
Expand All @@ -63,7 +75,7 @@ var Point = function Point(options) {
this.handle_wh = 6;

this.element = this.paper.ellipse();
this.element.attr({ "fill-opacity": 0.01, fill: "#fff", cursor: "pointer" });
this.element.attr({ "fill-opacity": this._fillOpacity, fill: this._fillColor, cursor: "pointer" });

// Drag handling of point
if (this.manager.canEdit) {
Expand Down Expand Up @@ -117,6 +129,8 @@ Point.prototype.toJson = function toJson() {
y: this._y,
strokeWidth: this._strokeWidth,
strokeColor: this._strokeColor,
fillColor: this._fillColor,
fillOpacity: this._fillOpacity
};
if (this._id) {
rv.id = this._id;
Expand Down Expand Up @@ -183,6 +197,25 @@ Point.prototype.getStrokeWidth = function getStrokeWidth() {
return this._strokeWidth;
};

Point.prototype.getFillColor = function getFillColor() {
return this._fillColor;
};


Point.prototype.setFillColor = function setFillColor(fillColor) {
this._fillColor = fillColor;
this.drawShape();
};

Point.prototype.setFillOpacity = function setFillOpacity(fillOpacity) {
this._fillOpacity = fillOpacity;
this.drawShape();
};

Point.prototype.getFillOpacity = function getFillOpacity() {
return this._fillOpacity;
};

Point.prototype.destroy = function destroy() {
this.element.remove();
this.handles.remove();
Expand Down Expand Up @@ -327,7 +360,9 @@ Point.prototype.updateShapeFromHandles = function updateShapeFromHandles(

Point.prototype.drawShape = function drawShape() {
var strokeColor = this._strokeColor,
strokeW = this._strokeWidth;
strokeW = this._strokeWidth,
fillColor = this._fillColor,
fillOpacity = this._fillOpacity;

var f = this._zoomFraction,
x = this._x * f,
Expand All @@ -342,6 +377,8 @@ Point.prototype.drawShape = function drawShape() {
ry: radiusY,
stroke: strokeColor,
"stroke-width": strokeW,
fill: fillColor,
'fill-opacity': fillOpacity
});
this.element.transform("r" + this._rotation);

Expand Down Expand Up @@ -440,6 +477,8 @@ var CreatePoint = function CreatePoint(options) {
CreatePoint.prototype.startDrag = function startDrag(startX, startY) {
var strokeColor = this.manager.getStrokeColor(),
strokeWidth = this.manager.getStrokeWidth(),
fillColor = this.manager.getFillColor(),
fillOpacity = this.manager.getFillOpacity(),
zoom = this.manager.getZoom();

this.point = new Point({
Expand All @@ -454,6 +493,8 @@ CreatePoint.prototype.startDrag = function startDrag(startX, startY) {
strokeWidth: strokeWidth,
zoom: zoom,
strokeColor: strokeColor,
fillColor: fillColor,
fillOpacity: fillOpacity
});
};

Expand Down
Loading