Commit 9dae93cc9b158d9cd30fe781be098b00e88c5f81

Authored by Thiago Franco de Moraes
1 parent 2bc6d362

Added a method to draw arcs given 2 points and a center

invesalius/data/measures.py
... ... @@ -865,6 +865,7 @@ class AngularMeasure(object):
865 865 # path.AddArc((c[0], c[1]), min(s0, s1), sa, ea)
866 866 # gc.StrokePath(path)
867 867  
  868 + canvas.draw_arc(points[1], points[0], points[2])
868 869 canvas.draw_text_box(txt, (points[0][0], points[0][1]))
869 870  
870 871 def GetNumberOfPoints(self):
... ...
invesalius/data/viewer_slice.py
... ... @@ -320,6 +320,38 @@ class CanvasRendererCTX:
320 320 tpx, tpy = px + border, py + border
321 321 gc.DrawText(text, tpx, tpy)
322 322  
  323 + def draw_arc(self, center, p0, p1, line_colour=(255, 0, 0, 128), width=2):
  324 + if self.gc is None:
  325 + return None
  326 + gc = self.gc
  327 + pen = wx.Pen(wx.Colour(*line_colour), width, wx.SOLID)
  328 + gc.SetPen(pen)
  329 +
  330 + c = np.array(center)
  331 + v0 = np.array(p0) - c
  332 + v1 = np.array(p1) - c
  333 +
  334 + c[1] = -c[1]
  335 + v0[1] = -v0[1]
  336 + v1[1] = -v1[1]
  337 +
  338 + s0 = np.linalg.norm(v0)
  339 + s1 = np.linalg.norm(v1)
  340 +
  341 + a0 = np.arctan2(v0[1] , v0[0])
  342 + a1 = np.arctan2(v1[1] , v1[0])
  343 +
  344 + if (a1 - a0) % (np.pi*2) < (a0 - a1) % (np.pi*2):
  345 + sa = a0
  346 + ea = a1
  347 + else:
  348 + sa = a1
  349 + ea = a0
  350 +
  351 + path = gc.CreatePath()
  352 + path.AddArc((c[0], c[1]), min(s0, s1), sa, ea)
  353 + gc.StrokePath(path)
  354 +
323 355  
324 356 class Viewer(wx.Panel):
325 357  
... ...