Skip to content

Commit

Permalink
Merge pull request #140 from SenteraLLC/feature/better-hitboxes
Browse files Browse the repository at this point in the history
[WS-440] [WS-615] Feature/better hitboxes
  • Loading branch information
TrevorBurgoyne authored Apr 12, 2024
2 parents 52a782b + b446fc8 commit a459d9f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 20 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented here.

Nothing yet.

## [0.10.3] - April 11th, 2024
- Improvements to hitboxes for polygons, points, and bboxes. The cursor must now actually be inside the annotation before showing the edit dialogs.
- Fix duplicate keybinds for increase/decrease of line size and brush size
- `[` and `]` now decrement/increment brush size
- `alt+scroll` still decrements/increments brush size
- `-` and `=` still decrements/increments line size

## [0.10.2] - April 10th, 2024
- Fix bug where using the erase tool to completely erase a polygon would sometimes cause an error.
- Fix npm publishing error from 0.10.1
Expand Down
2 changes: 1 addition & 1 deletion dist/ulabel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ulabel.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ulabel",
"description": "An image annotation tool.",
"version": "0.10.2",
"version": "0.10.3",
"main": "dist/ulabel.js",
"module": "dist/ulabel.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export class Configuration {

public toggle_erase_mode_keybind: string = "e"

public increase_brush_size_keybind: string = "="
public increase_brush_size_keybind: string = "]"

public decrease_brush_size_keybind: string = "-"
public decrease_brush_size_keybind: string = "["

constructor(...kwargs: {[key: string]: unknown}[]) {
this.modify_config(...kwargs)
Expand Down
14 changes: 14 additions & 0 deletions src/geometric_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ export class GeometricUtils {
return turf.booleanPointInPolygon(turf.point(point), turf.polygon([poly]));
}

// Check if a point is within a ulabel complex polygon
public static point_is_within_polygon_annotation(point: Point2D, annotation_object: object): boolean {
// Check if a point is within any of the filled regions (non-holes)
for (let i = 0; i < annotation_object["spatial_payload"].length; i++) {
if (
annotation_object["spatial_payload_holes"][i] === false &&
GeometricUtils.point_is_within_simple_polygon(point, annotation_object["spatial_payload"][i])
) {
return true;
}
}
return false;
}

// Convert a bbox to a simple polygon by adding the last point
public static bbox_to_simple_polygon(bbox: ULabelSpatialPayload2D): ULabelSpatialPayload2D {
// bbox is just two points, so we need to add the other two as well as the final point
Expand Down
62 changes: 48 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5581,21 +5581,22 @@ export class ULabel {
};
let minsize = Infinity;
// TODO(3d)
for (var edi = 0; edi < this.subtasks[this.state["current_subtask"]]["annotations"]["ordering"].length; edi++) {
let id = this.subtasks[this.state["current_subtask"]]["annotations"]["ordering"][edi];
if (this.subtasks[this.state["current_subtask"]]["annotations"]["access"][id]["deprecated"]) continue;
let cbox = this.subtasks[this.state["current_subtask"]]["annotations"]["access"][id]["containing_box"];
let frame = this.subtasks[this.state["current_subtask"]]["annotations"]["access"][id]["frame"];
for (let edi = 0; edi < this.subtasks[this.state["current_subtask"]]["annotations"]["ordering"].length; edi++) {
const annotation_id = this.subtasks[this.state["current_subtask"]]["annotations"]["ordering"][edi];
let annotation = this.subtasks[this.state["current_subtask"]]["annotations"]["access"][annotation_id];
if (annotation["deprecated"]) continue;
let cbox = annotation["containing_box"];
let frame = annotation["frame"];
const spatial_type = annotation["spatial_type"];
if (cbox) {
cbox["tlz"] = this.state["current_frame"];
cbox["brz"] = this.state["current_frame"];
if (frame != null) {
cbox["tlz"] = frame;
cbox["brz"] = frame;
}
else {
if (this.subtasks[this.state["current_subtask"]]["annotations"]["access"][id]["spatial_type"] === "bbox3") {
let pts = this.subtasks[this.state["current_subtask"]]["annotations"]["access"][id]["spatial_payload"];
} else {
if (spatial_type === "bbox3") {
let pts = annotation["spatial_payload"];
cbox["tlz"] = Math.min(pts[0][2], pts[1][2]);
cbox["brz"] = Math.max(pts[0][2], pts[1][2]);
}
Expand All @@ -5611,13 +5612,46 @@ export class ULabel {
(this.state["current_frame"] >= cbox["tlz"]) &&
(this.state["current_frame"] <= cbox["brz"])
) {
ret["candidate_ids"].push(id);
let boxsize = (cbox["brx"] - cbox["tlx"]) * (cbox["bry"] - cbox["tly"]);
if (boxsize < minsize) {
minsize = boxsize;
let found_perfect_match = false;
let boxsize;
switch (spatial_type) {
case "polygon":
// Check if the mouse is within the polygon
if (GeometricUtils.point_is_within_polygon_annotation([gblx, gbly], annotation)) {
found_perfect_match = true;
}
break;
case "bbox":
case "point":
if (
gblx >= cbox["tlx"] &&
gblx <= cbox["brx"] &&
gbly >= cbox["tly"] &&
gbly <= cbox["bry"]
) {
found_perfect_match = true;
}
break;
default:
boxsize = (cbox["brx"] - cbox["tlx"]) * (cbox["bry"] - cbox["tly"]);
if (boxsize < minsize) {
minsize = boxsize;
ret["best"] = {
"annid": annotation_id
};
}
break;
}

if (!found_perfect_match) {
ret["candidate_ids"].push(annotation_id);
} else {
// This should be the only candidate
ret["candidate_ids"] = [annotation_id];
ret["best"] = {
"annid": id
"annid": annotation_id
};
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ULABEL_VERSION = "0.10.2";
export const ULABEL_VERSION = "0.10.3";

0 comments on commit a459d9f

Please sign in to comment.