Spaces:
Running
Running
add curso
Browse files
comic_panel_extractor/static/annotator.html
CHANGED
|
@@ -1397,31 +1397,11 @@
|
|
| 1397 |
updatePolygonCursor(x, y) {
|
| 1398 |
if (this.selectedBoxIndex >= 0 && this.annotations[this.selectedBoxIndex].type === 'segmentation') {
|
| 1399 |
const handle = this.getResizeHandle(x, y);
|
| 1400 |
-
|
| 1401 |
-
|
| 1402 |
-
if (edgeHandleIndex >= 0) {
|
| 1403 |
-
this.canvas.style.cursor = handle.cursor;
|
| 1404 |
-
return;
|
| 1405 |
-
}
|
| 1406 |
-
|
| 1407 |
-
const pointIndex = this.getPolygonPointAtPosition(x, y);
|
| 1408 |
-
if (pointIndex >= 0) {
|
| 1409 |
-
this.canvas.style.cursor = handle.cursor;
|
| 1410 |
-
return;
|
| 1411 |
-
}
|
| 1412 |
-
|
| 1413 |
-
const edgeIndex = this.getPolygonEdgeAtPosition(x, y);
|
| 1414 |
-
if (edgeIndex >= 0) {
|
| 1415 |
-
this.canvas.style.cursor = 'pointer';
|
| 1416 |
-
return;
|
| 1417 |
-
}
|
| 1418 |
-
|
| 1419 |
-
if (this.isPointInPolygon(x, y, this.annotations[this.selectedBoxIndex].points)) {
|
| 1420 |
-
this.canvas.style.cursor = handle.cursor;
|
| 1421 |
-
return;
|
| 1422 |
-
}
|
| 1423 |
}
|
| 1424 |
|
|
|
|
| 1425 |
const polygonIndex = this.getPolygonAtPosition(x, y);
|
| 1426 |
if (polygonIndex >= 0) {
|
| 1427 |
this.canvas.style.cursor = 'pointer';
|
|
@@ -1430,6 +1410,7 @@
|
|
| 1430 |
}
|
| 1431 |
}
|
| 1432 |
|
|
|
|
| 1433 |
updateCursor(x, y) {
|
| 1434 |
if (this.selectedBoxIndex >= 0) {
|
| 1435 |
const handle = this.getResizeHandle(x, y);
|
|
@@ -1450,7 +1431,37 @@
|
|
| 1450 |
getResizeHandle(x, y) {
|
| 1451 |
if (this.selectedBoxIndex < 0) return { cursor: 'move' };
|
| 1452 |
|
| 1453 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1454 |
const handleSize = 8;
|
| 1455 |
const tolerance = 5;
|
| 1456 |
|
|
@@ -1473,6 +1484,77 @@
|
|
| 1473 |
return { cursor: 'move' };
|
| 1474 |
}
|
| 1475 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1476 |
getBoxAtPosition(x, y) {
|
| 1477 |
for (let i = this.annotations.length - 1; i >= 0; i--) {
|
| 1478 |
const box = this.annotations[i];
|
|
|
|
| 1397 |
updatePolygonCursor(x, y) {
|
| 1398 |
if (this.selectedBoxIndex >= 0 && this.annotations[this.selectedBoxIndex].type === 'segmentation') {
|
| 1399 |
const handle = this.getResizeHandle(x, y);
|
| 1400 |
+
this.canvas.style.cursor = handle.cursor;
|
| 1401 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1402 |
}
|
| 1403 |
|
| 1404 |
+
// Check for unselected polygons
|
| 1405 |
const polygonIndex = this.getPolygonAtPosition(x, y);
|
| 1406 |
if (polygonIndex >= 0) {
|
| 1407 |
this.canvas.style.cursor = 'pointer';
|
|
|
|
| 1410 |
}
|
| 1411 |
}
|
| 1412 |
|
| 1413 |
+
|
| 1414 |
updateCursor(x, y) {
|
| 1415 |
if (this.selectedBoxIndex >= 0) {
|
| 1416 |
const handle = this.getResizeHandle(x, y);
|
|
|
|
| 1431 |
getResizeHandle(x, y) {
|
| 1432 |
if (this.selectedBoxIndex < 0) return { cursor: 'move' };
|
| 1433 |
|
| 1434 |
+
const annotation = this.annotations[this.selectedBoxIndex];
|
| 1435 |
+
|
| 1436 |
+
// Handle polygon cursor logic with directional resize cursors
|
| 1437 |
+
if (annotation.type === 'segmentation') {
|
| 1438 |
+
const tolerance = 8;
|
| 1439 |
+
|
| 1440 |
+
// Check for corner points with directional resize cursors
|
| 1441 |
+
const pointIndex = this.getPolygonPointAtPosition(x, y, tolerance);
|
| 1442 |
+
if (pointIndex >= 0) {
|
| 1443 |
+
const resizeCursor = this.getPolygonCornerResizeCursor(pointIndex, annotation.points);
|
| 1444 |
+
return { cursor: resizeCursor, type: 'point', index: pointIndex };
|
| 1445 |
+
}
|
| 1446 |
+
|
| 1447 |
+
// Check for edges with directional resize cursors
|
| 1448 |
+
const edgeIndex = this.getPolygonEdgeAtPosition(x, y, 5);
|
| 1449 |
+
if (edgeIndex >= 0) {
|
| 1450 |
+
const edgeResizeCursor = this.getPolygonEdgeResizeCursor(edgeIndex, annotation.points);
|
| 1451 |
+
return { cursor: edgeResizeCursor, type: 'edge', index: edgeIndex };
|
| 1452 |
+
}
|
| 1453 |
+
|
| 1454 |
+
// Check if inside polygon (for moving entire polygon)
|
| 1455 |
+
if (this.isPointInPolygon(x, y, annotation.points)) {
|
| 1456 |
+
return { cursor: 'move', type: 'polygon-interior' };
|
| 1457 |
+
}
|
| 1458 |
+
|
| 1459 |
+
// Default cursor for segmentation mode
|
| 1460 |
+
return { cursor: 'crosshair', type: 'default' };
|
| 1461 |
+
}
|
| 1462 |
+
|
| 1463 |
+
// Original bbox logic remains the same
|
| 1464 |
+
const box = annotation;
|
| 1465 |
const handleSize = 8;
|
| 1466 |
const tolerance = 5;
|
| 1467 |
|
|
|
|
| 1484 |
return { cursor: 'move' };
|
| 1485 |
}
|
| 1486 |
|
| 1487 |
+
getPolygonCornerResizeCursor(pointIndex, points) {
|
| 1488 |
+
if (points.length < 3) return 'move';
|
| 1489 |
+
|
| 1490 |
+
// Calculate polygon bounding box
|
| 1491 |
+
const bounds = this.getPolygonBounds(points);
|
| 1492 |
+
const currentPoint = points[pointIndex];
|
| 1493 |
+
|
| 1494 |
+
// Determine position relative to bounding box center
|
| 1495 |
+
const centerX = bounds.left + bounds.width / 2;
|
| 1496 |
+
const centerY = bounds.top + bounds.height / 2;
|
| 1497 |
+
|
| 1498 |
+
const isLeft = currentPoint.x < centerX;
|
| 1499 |
+
const isRight = currentPoint.x > centerX;
|
| 1500 |
+
const isTop = currentPoint.y < centerY;
|
| 1501 |
+
const isBottom = currentPoint.y > centerY;
|
| 1502 |
+
|
| 1503 |
+
// Return appropriate resize cursor
|
| 1504 |
+
if (isTop && isLeft) return 'nw-resize';
|
| 1505 |
+
if (isTop && isRight) return 'ne-resize';
|
| 1506 |
+
if (isBottom && isLeft) return 'sw-resize';
|
| 1507 |
+
if (isBottom && isRight) return 'se-resize';
|
| 1508 |
+
if (isTop) return 'n-resize';
|
| 1509 |
+
if (isBottom) return 's-resize';
|
| 1510 |
+
if (isLeft) return 'w-resize';
|
| 1511 |
+
if (isRight) return 'e-resize';
|
| 1512 |
+
|
| 1513 |
+
return 'move'; // Center point or fallback
|
| 1514 |
+
}
|
| 1515 |
+
getPolygonBounds(points) {
|
| 1516 |
+
if (points.length === 0) return { left: 0, top: 0, width: 0, height: 0 };
|
| 1517 |
+
|
| 1518 |
+
let minX = points[0].x, maxX = points[0].x;
|
| 1519 |
+
let minY = points[0].y, maxY = points[0].y;
|
| 1520 |
+
|
| 1521 |
+
for (let i = 1; i < points.length; i++) {
|
| 1522 |
+
minX = Math.min(minX, points[i].x);
|
| 1523 |
+
maxX = Math.max(maxX, points[i].x);
|
| 1524 |
+
minY = Math.min(minY, points[i].y);
|
| 1525 |
+
maxY = Math.max(maxY, points[i].y);
|
| 1526 |
+
}
|
| 1527 |
+
|
| 1528 |
+
return {
|
| 1529 |
+
left: minX,
|
| 1530 |
+
top: minY,
|
| 1531 |
+
width: maxX - minX,
|
| 1532 |
+
height: maxY - minY
|
| 1533 |
+
};
|
| 1534 |
+
}
|
| 1535 |
+
|
| 1536 |
+
getPolygonEdgeResizeCursor(edgeIndex, points) {
|
| 1537 |
+
if (points.length < 2) return 'move';
|
| 1538 |
+
|
| 1539 |
+
// Get the two points that form this edge
|
| 1540 |
+
const point1 = points[edgeIndex];
|
| 1541 |
+
const point2 = points[(edgeIndex + 1) % points.length];
|
| 1542 |
+
|
| 1543 |
+
// Calculate edge direction
|
| 1544 |
+
const deltaX = Math.abs(point2.x - point1.x);
|
| 1545 |
+
const deltaY = Math.abs(point2.y - point1.y);
|
| 1546 |
+
|
| 1547 |
+
// Determine if edge is more horizontal or vertical
|
| 1548 |
+
if (deltaX > deltaY) {
|
| 1549 |
+
// More horizontal edge - allow vertical resizing
|
| 1550 |
+
return 'ns-resize';
|
| 1551 |
+
} else {
|
| 1552 |
+
// More vertical edge - allow horizontal resizing
|
| 1553 |
+
return 'ew-resize';
|
| 1554 |
+
}
|
| 1555 |
+
}
|
| 1556 |
+
|
| 1557 |
+
|
| 1558 |
getBoxAtPosition(x, y) {
|
| 1559 |
for (let i = this.annotations.length - 1; i >= 0; i--) {
|
| 1560 |
const box = this.annotations[i];
|