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

Add checks for (non-)simple polygons #634

Merged
merged 40 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0d05256
Add check for invalid shapes
lehecht Aug 3, 2023
a821c82
Show message for invalid shapes
lehecht Aug 3, 2023
92ff004
Rename method for more clarity
lehecht Aug 3, 2023
f65c261
Remove case that is not reachable
lehecht Aug 9, 2023
b5078d1
Add event listener only once
lehecht Aug 9, 2023
af7dfc3
Simplify event listener method
lehecht Aug 9, 2023
2fdf82a
Concatenate x,y coordinates before size check
lehecht Aug 9, 2023
50c15ae
Remove duplicated coordinates
lehecht Aug 10, 2023
e9ac4f6
Remove superfluous checks for rectangles, ellipses and lines
lehecht Sep 22, 2023
66f4040
Move magic wand methods to MagicWandInteraction.js
lehecht Oct 2, 2023
0940d4c
Add jsts library
lehecht Oct 2, 2023
b164600
Disallow self intersecting polygons
lehecht Oct 11, 2023
0c7a70d
Remove unused imports
lehecht Oct 12, 2023
1c2ba0b
Move polygon validation methods to own class
lehecht Oct 13, 2023
1894844
Rename event for more clarity
lehecht Oct 13, 2023
ca61495
Add polygon validation for video annotations
lehecht Oct 13, 2023
1457ae2
Fix bug with nested polygon parts
lehecht Oct 16, 2023
0316882
Format code
lehecht Oct 16, 2023
7781541
Use value instead of variable
lehecht Oct 17, 2023
43f564d
Remove superfluous magicwand polygon validation
lehecht Oct 17, 2023
0c8b012
Move polygon validation call to drawInteractions.vue
lehecht Oct 17, 2023
669e94c
Transform self-intersecting polygons to simple ones
lehecht Oct 27, 2023
34f3884
Fix missing/unused imports
lehecht Oct 27, 2023
a8ddfd1
Remove unused method
lehecht Oct 27, 2023
3f41193
Remove unused methods
lehecht Oct 27, 2023
66f2fe0
Make polygonValiator a static class
lehecht Oct 30, 2023
398a5ae
Remove redundant return statement
lehecht Nov 2, 2023
4abce21
Replace class export by methods export
lehecht Nov 2, 2023
4996b71
Apply changes from code review
mzur Nov 7, 2023
27a7055
Convert JSTS Monkey import to side-effect import
mzur Nov 7, 2023
86dfe03
Remove unnecessary if-else condition
lehecht Nov 8, 2023
99758f2
Fix bug with intersecting polygons after modification
lehecht Nov 10, 2023
bcefe6d
Rename method to shorten name
lehecht Nov 14, 2023
bdeb64c
Add comments
lehecht Nov 14, 2023
f1e7730
Add comments
lehecht Nov 16, 2023
86b5cea
Make code more readable
lehecht Nov 16, 2023
7a340c6
Add Polygon check after modifying video polygons
lehecht Nov 16, 2023
4fc7573
Edit comments
lehecht Nov 16, 2023
9db8277
Implement alternative handling of polygons with holes
mzur Nov 17, 2023
fabfa21
Merge pull request #700 from biigle/non-simple-polygon-bug-patch-1
mzur Nov 21, 2023
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
16 changes: 16 additions & 0 deletions resources/assets/js/annotations/annotatorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,22 @@ export default {
dismissCrossOriginError() {
this.crossOriginError = false;
},
handleInvalidShape(shape){
let vertexCount;
switch(shape){
case 'Polygon':
vertexCount = 'at least 3';
break;
case 'Rectangle':
vertexCount = '4';
break;
case 'LineString':
shape = 'Line';
vertexCount = 'at least 2';
break;
}
Messages.danger(`Invalid Shape. ${shape} needs ${vertexCount} non-overlapping vertices.`);
},
},
watch: {
async imageId(id) {
Expand Down
33 changes: 31 additions & 2 deletions resources/assets/js/annotations/components/annotationCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ export default {
return this.convertPointsFromOlToDb(points);
},
handleNewFeature(e) {
if (this.hasSelectedLabel) {
let validDrawing = this.hasValidPoints(e);

if (this.hasSelectedLabel && validDrawing) {
let geometry = e.feature.getGeometry();
e.feature.set('color', this.selectedLabel.color);

Expand All @@ -529,10 +531,37 @@ export default {
shape: geometry.getType(),
points: this.getPoints(geometry),
}, removeCallback);
} else {
} else if (validDrawing) {
this.annotationSource.removeFeature(e.feature);
} else {
let source = this.annotationSource;
source.on('change', (evtChange) => {
if (evtChange.target.getState() === 'ready' && source.hasFeature(e.feature)) {
source.removeFeature(e.feature);
this.$emit('has-invalid-shape', e.feature.getGeometry().getType());
}

});
mzur marked this conversation as resolved.
Show resolved Hide resolved
}
},
hasValidPoints(e) {
let geometry = e.feature.getGeometry();
let points = geometry.getCoordinates();

switch (geometry.getType()) {
case 'LineString':
return this.getShapeCoordinateSetSize(points) >= 2;
case 'Rectangle':
return this.getShapeCoordinateSetSize(points[0]) === 4;
case 'Polygon':
return this.getShapeCoordinateSetSize(points[0]) >= 3;
default:
return true;
}
},
getShapeCoordinateSetSize(points){
return new Set(points.map(xy => String(xy))).size;
},
deleteSelectedAnnotations() {
if (!this.modifyInProgress && this.hasSelectedAnnotations && confirm('Are you sure you want to delete all selected annotations?')) {
this.$emit('delete', this.selectedAnnotations);
Expand Down
1 change: 1 addition & 0 deletions resources/views/annotations/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
v-on:delete="handleDeleteAnnotations"
v-on:measuring="fetchImagesArea"
v-on:requires-selected-label="handleRequiresSelectedLabel"
v-on:has-invalid-shape="handleInvalidShape"
ref="canvas"
inline-template>
@include('annotations.show.annotationCanvas')
Expand Down