Commit 2bc6d3620136f408317b788d150ad5a442d7b97b

Authored by Thiago Franco de Moraes
1 parent 4e26411d

Created a method to draw circles

invesalius/data/measures.py
... ... @@ -570,24 +570,19 @@ class LinearMeasure(object):
570 570 canvas: the canvas it's being drawn.
571 571 """
572 572 coord = vtk.vtkCoordinate()
573   - lines = []
  573 + points = []
574 574 for p in self.points:
575 575 coord.SetValue(p)
576 576 cx, cy = coord.GetComputedDisplayValue(canvas.viewer.slice_data.renderer)
577   - cy = -cy
578   - lines.append((cx, cy))
579   - path = gc.CreatePath()
580   - path.AddCircle(cx, cy, 2.5)
581   - gc.StrokePath(path)
582   - gc.FillPath(path)
583   -
584   - if len(lines) > 1:
585   - for (p0, p1) in zip(lines[:-1:], lines[1::]):
  577 + canvas.draw_circle((cx, cy), 2.5)
  578 + points.append((cx, cy))
  579 +
  580 + if len(points) > 1:
  581 + for (p0, p1) in zip(points[:-1:], points[1::]):
586 582 canvas.draw_line(p0, p1)
587 583  
588 584 txt = u"%.3f mm" % self.GetValue()
589   - # gc.DrawText(txt, *lines[0])
590   - canvas.draw_text_box(txt, (lines[0][0], -lines[0][1]))
  585 + canvas.draw_text_box(txt, (points[0][0], points[0][1]))
591 586  
592 587 def GetNumberOfPoints(self):
593 588 return len(self.points)
... ... @@ -832,52 +827,45 @@ class AngularMeasure(object):
832 827 gc: is a wx.GraphicsContext
833 828 canvas: the canvas it's being drawn.
834 829 """
  830 +
835 831 coord = vtk.vtkCoordinate()
836   - lines = []
  832 + points = []
837 833 for p in self.points:
838   - print p
839 834 coord.SetValue(p)
840 835 cx, cy = coord.GetComputedDisplayValue(canvas.viewer.slice_data.renderer)
841   - cy = -cy
842   - lines.append((cx, cy))
843   - path = gc.CreatePath()
844   - path.AddCircle(cx, cy, 2.5)
845   - gc.StrokePath(path)
846   - gc.FillPath(path)
  836 + canvas.draw_circle((cx, cy), 2.5)
  837 + points.append((cx, cy))
847 838  
848   - if len(lines) > 1:
849   - path = gc.CreatePath()
850   -
851   - for (p0, p1) in zip(lines[:-1:], lines[1::]):
  839 + if len(points) > 1:
  840 + for (p0, p1) in zip(points[:-1:], points[1::]):
852 841 canvas.draw_line(p0, p1)
853 842  
854   - if len(lines) == 3:
  843 + if len(points) == 3:
855 844 txt = u"%.3f° / %.3f°" % (self.GetValue(), 360.0 - self.GetValue())
856 845  
857   - path = gc.CreatePath()
  846 + # path = gc.CreatePath()
858 847  
859   - c = np.array(lines[1])
860   - v0 = np.array(lines[0]) - c
861   - v1 = np.array(lines[2]) - c
  848 + # c = np.array(lines[1])
  849 + # v0 = np.array(lines[0]) - c
  850 + # v1 = np.array(lines[2]) - c
862 851  
863   - s0 = np.linalg.norm(v0)
864   - s1 = np.linalg.norm(v1)
  852 + # s0 = np.linalg.norm(v0)
  853 + # s1 = np.linalg.norm(v1)
865 854  
866   - a0 = np.arctan2(v0[1] , v0[0])
867   - a1 = np.arctan2(v1[1] , v1[0])
  855 + # a0 = np.arctan2(v0[1] , v0[0])
  856 + # a1 = np.arctan2(v1[1] , v1[0])
868 857  
869   - if (a1 - a0) % (np.pi*2) < (a0 - a1) % (np.pi*2):
870   - sa = a0
871   - ea = a1
872   - else:
873   - sa = a1
874   - ea = a0
  858 + # if (a1 - a0) % (np.pi*2) < (a0 - a1) % (np.pi*2):
  859 + # sa = a0
  860 + # ea = a1
  861 + # else:
  862 + # sa = a1
  863 + # ea = a0
875 864  
876   - path.AddArc((c[0], c[1]), min(s0, s1), sa, ea)
877   - gc.StrokePath(path)
  865 + # path.AddArc((c[0], c[1]), min(s0, s1), sa, ea)
  866 + # gc.StrokePath(path)
878 867  
879   - # gc.DrawText(txt, *lines[0])
880   - canvas.draw_text_box(txt, (lines[0][0], -lines[0][1]))
  868 + canvas.draw_text_box(txt, (points[0][0], points[0][1]))
881 869  
882 870 def GetNumberOfPoints(self):
883 871 return self.number_of_points
... ...
invesalius/data/viewer_slice.py
... ... @@ -241,13 +241,48 @@ class CanvasRendererCTX:
241 241 return None
242 242 gc = self.gc
243 243  
  244 + p0x, p0y = pos0
  245 + p1x, p1y = pos1
  246 +
  247 + p0y = -p0y
  248 + p1y = -p1y
  249 +
244 250 pen = wx.Pen(wx.Colour(*colour), width, wx.SOLID)
245 251 gc.SetPen(pen)
246 252  
247 253 path = gc.CreatePath()
248   - path.MoveToPoint(*pos0)
249   - path.AddLineToPoint(*pos1)
  254 + path.MoveToPoint(p0x, p0y)
  255 + path.AddLineToPoint(p1x, p1y)
  256 + gc.StrokePath(path)
  257 +
  258 + def draw_circle(self, center, radius, width=2, line_colour=(255, 0, 0, 128), fill_colour=(0, 0, 0, 0)):
  259 + """
  260 + Draw a circle centered at center with the given radius.
  261 +
  262 + Params:
  263 + center: (x, y) position.
  264 + radius: float number.
  265 + width: line width.
  266 + line_colour: RGBA line colour
  267 + fill_colour: RGBA fill colour.
  268 + """
  269 + if self.gc is None:
  270 + return None
  271 + gc = self.gc
  272 +
  273 + pen = wx.Pen(wx.Colour(*line_colour), width, wx.SOLID)
  274 + gc.SetPen(pen)
  275 +
  276 + brush = wx.Brush(wx.Colour(*fill_colour))
  277 + gc.SetBrush(brush)
  278 +
  279 + cx, cy = center
  280 + cy = -cy
  281 +
  282 + path = gc.CreatePath()
  283 + path.AddCircle(cx, cy, 2.5)
250 284 gc.StrokePath(path)
  285 + gc.FillPath(path)
251 286  
252 287  
253 288 def draw_text_box(self, text, pos, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5):
... ...