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

Make point, line and two-point linestrip shapes selectable #1502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ynjxsjmh
Copy link

@Ynjxsjmh Ynjxsjmh commented Sep 28, 2024

Currenly, point, line and two-point linestrip won't be selected by mouse left click, which leads to hard deletion. The main problem is that self.makePath().contains(point) doesn't consider these three special condition. These three shapes don't possess enclosing structures like rectangle and circle.

labelme/labelme/shape.py

Lines 326 to 355 in b9c83ff

def containsPoint(self, point):
if self.mask is not None:
y = np.clip(
int(round(point.y() - self.points[0].y())),
0,
self.mask.shape[0] - 1,
)
x = np.clip(
int(round(point.x() - self.points[0].x())),
0,
self.mask.shape[1] - 1,
)
return self.mask[y, x]
return self.makePath().contains(point)
def makePath(self):
if self.shape_type in ["rectangle", "mask"]:
path = QtGui.QPainterPath()
if len(self.points) == 2:
path.addRect(QtCore.QRectF(self.points[0], self.points[1]))
elif self.shape_type == "circle":
path = QtGui.QPainterPath()
if len(self.points) == 2:
raidus = labelme.utils.distance(self.points[0] - self.points[1])
path.addEllipse(self.points[0], raidus, raidus)
else:
path = QtGui.QPainterPath(self.points[0])
for p in self.points[1:]:
path.lineTo(p)
return path

To solve this, I add judgement to check if the clicked point is near these shapes.

@Ynjxsjmh
Copy link
Author

@wkentaro Hi, could you take some time to view my two prs? I don't know how to trigger checks on github, but they pass the test on my local machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant