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

Allow polygons with holes to be specified. #844

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions girder_annotation/docs/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ When closed, this is a polygon. When open, this is a continuous line.
[56,-45,6]
],
"closed": true, # Boolean. Default is false. Optional
"holes": [ # Only used if closed is true. A list of a list of
# coordinates. Each list of coordinates is a
# separate hole within the main polygon, and is expected
# to be contained within it and not cross the main
# polygon or other holes.
[
[10,10,0],
[20,30,0],
[10,30,0]
]
],
"fillColor": "rgba(0, 255, 0, 1)" # String. See note about colors. Optional
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ class AnnotationSchema:
'description': 'polyline is open if closed flag is '
'not specified'
},
'holes': {
'type': 'array',
'description':
'If closed is true, this is a list of polylines that are '
'treated as holes in the base polygon. These should not '
'cross each other and should be contained within the base '
'polygon.',
'items': {
'type': 'array',
'items': coordSchema,
'minItems': 3,
},
},
},
'required': ['type', 'points'],
'additionalProperties': False
Expand Down Expand Up @@ -976,6 +989,15 @@ def _similarElementStructure(self, a, b, parentKey=None): # noqa
if not self._similarElementStructure(a[k], b[k], k):
return False
elif isinstance(a, list):
if parentKey == 'holes':
for hidx in range(len(b)):
for idx in range(len(b[hidx])):
if (len(b[hidx][idx]) != 3 or
not isinstance(b[hidx][idx][0], self.numberInstance) or
not isinstance(b[hidx][idx][1], self.numberInstance) or
not isinstance(b[hidx][idx][2], self.numberInstance)):
return False
return True
if len(a) != len(b):
if parentKey not in {'points', 'values'} or len(a) < 2 or len(b) < 2:
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ export default function polyline(json) {
var annotationType;

if (json.closed) {
type = 'Polygon';
points.push(points[0]);
coordinates = [points];
if (json.holes) {
const holes = (json.holes || []).map((hole) => {
let result = hole.map((p) => _.first(p, 2));
result.push(result[0]);
return result;
});
coordinates = coordinates.concat(holes);
}
type = 'Polygon';
annotationType = 'polygon';
} else {
type = 'LineString';
Expand Down