Commit 95430b64db4cc766e376512cc42ff0cb5c4e54dd
1 parent
6b213636
Exists in
master
and in
26 other branches
Option to draw arrow in the start and end of lines
Showing
1 changed file
with
36 additions
and
1 deletions
Show diff stats
invesalius/data/viewer_slice.py
| ... | ... | @@ -233,7 +233,7 @@ class CanvasRendererCTX: |
| 233 | 233 | |
| 234 | 234 | self._cv_image.Modified() |
| 235 | 235 | |
| 236 | - def draw_line(self, pos0, pos1, colour=(255, 0, 0, 128), width=2, style=wx.SOLID): | |
| 236 | + def draw_line(self, pos0, pos1, arrow_start=False, arrow_end=False, colour=(255, 0, 0, 128), width=2, style=wx.SOLID): | |
| 237 | 237 | """ |
| 238 | 238 | Draw a line from pos0 to pos1 |
| 239 | 239 | """ |
| ... | ... | @@ -255,6 +255,41 @@ class CanvasRendererCTX: |
| 255 | 255 | path.AddLineToPoint(p1x, p1y) |
| 256 | 256 | gc.StrokePath(path) |
| 257 | 257 | |
| 258 | + font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) | |
| 259 | + font = gc.CreateFont(font) | |
| 260 | + gc.SetFont(font) | |
| 261 | + w, h = gc.GetTextExtent("M") | |
| 262 | + | |
| 263 | + p0 = np.array((p0x, p0y)) | |
| 264 | + p3 = np.array((p1x, p1y)) | |
| 265 | + if arrow_start: | |
| 266 | + v = p3 - p0 | |
| 267 | + v = v / np.linalg.norm(v) | |
| 268 | + iv = np.array((v[1], -v[0])) | |
| 269 | + p1 = p0 + w*v + iv*w/2.0 | |
| 270 | + p2 = p0 + w*v + (-iv)*w/2.0 | |
| 271 | + | |
| 272 | + path = gc.CreatePath() | |
| 273 | + path.MoveToPoint(p0) | |
| 274 | + path.AddLineToPoint(p1) | |
| 275 | + path.MoveToPoint(p0) | |
| 276 | + path.AddLineToPoint(p2) | |
| 277 | + gc.StrokePath(path) | |
| 278 | + | |
| 279 | + if arrow_end: | |
| 280 | + v = p3 - p0 | |
| 281 | + v = v / np.linalg.norm(v) | |
| 282 | + iv = np.array((v[1], -v[0])) | |
| 283 | + p1 = p3 - w*v + iv*w/2.0 | |
| 284 | + p2 = p3 - w*v + (-iv)*w/2.0 | |
| 285 | + | |
| 286 | + path = gc.CreatePath() | |
| 287 | + path.MoveToPoint(p3) | |
| 288 | + path.AddLineToPoint(p1) | |
| 289 | + path.MoveToPoint(p3) | |
| 290 | + path.AddLineToPoint(p2) | |
| 291 | + gc.StrokePath(path) | |
| 292 | + | |
| 258 | 293 | def draw_circle(self, center, radius, width=2, line_colour=(255, 0, 0, 128), fill_colour=(0, 0, 0, 0)): |
| 259 | 294 | """ |
| 260 | 295 | Draw a circle centered at center with the given radius. | ... | ... |