Commit 4e26411d23c552318b94e754bb547236d67b8a13
1 parent
90e1222d
Exists in
master
and in
26 other branches
Created a method to draw line
Showing
2 changed files
with
74 additions
and
63 deletions
Show diff stats
invesalius/data/measures.py
... | ... | @@ -582,12 +582,8 @@ class LinearMeasure(object): |
582 | 582 | gc.FillPath(path) |
583 | 583 | |
584 | 584 | if len(lines) > 1: |
585 | - path = gc.CreatePath() | |
586 | - | |
587 | - path.MoveToPoint(*lines[0]) | |
588 | - for p in lines[1::]: | |
589 | - path.AddLineToPoint(*p) | |
590 | - gc.StrokePath(path) | |
585 | + for (p0, p1) in zip(lines[:-1:], lines[1::]): | |
586 | + canvas.draw_line(p0, p1) | |
591 | 587 | |
592 | 588 | txt = u"%.3f mm" % self.GetValue() |
593 | 589 | # gc.DrawText(txt, *lines[0]) |
... | ... | @@ -852,10 +848,8 @@ class AngularMeasure(object): |
852 | 848 | if len(lines) > 1: |
853 | 849 | path = gc.CreatePath() |
854 | 850 | |
855 | - path.MoveToPoint(*lines[0]) | |
856 | - for p in lines[1::]: | |
857 | - path.AddLineToPoint(*p) | |
858 | - gc.StrokePath(path) | |
851 | + for (p0, p1) in zip(lines[:-1:], lines[1::]): | |
852 | + canvas.draw_line(p0, p1) | |
859 | 853 | |
860 | 854 | if len(lines) == 3: |
861 | 855 | txt = u"%.3f° / %.3f°" % (self.GetValue(), 360.0 - self.GetValue()) | ... | ... |
invesalius/data/viewer_slice.py
... | ... | @@ -89,7 +89,7 @@ class ContourMIPConfig(wx.Panel): |
89 | 89 | " order to compound the" |
90 | 90 | " visualization instead of" |
91 | 91 | " ascending order."))) |
92 | - | |
92 | + | |
93 | 93 | txt_mip_size = wx.StaticText(self, -1, _("Number of slices"), style=wx.ALIGN_CENTER_HORIZONTAL) |
94 | 94 | self.txt_mip_border = wx.StaticText(self, -1, _("Sharpness")) |
95 | 95 | |
... | ... | @@ -113,7 +113,7 @@ class ContourMIPConfig(wx.Panel): |
113 | 113 | self.mip_size_spin.Bind(wx.EVT_SPINCTRL, self.OnSetMIPSize) |
114 | 114 | self.border_spin.Bind(wx.EVT_SPINCTRL, self.OnSetMIPBorder) |
115 | 115 | self.inverted.Bind(wx.EVT_CHECKBOX, self.OnCheckInverted) |
116 | - | |
116 | + | |
117 | 117 | Publisher.subscribe(self._set_projection_type, 'Set projection type') |
118 | 118 | |
119 | 119 | def OnSetMIPSize(self, evt): |
... | ... | @@ -136,7 +136,7 @@ class ContourMIPConfig(wx.Panel): |
136 | 136 | self.inverted.Enable() |
137 | 137 | else: |
138 | 138 | self.inverted.Disable() |
139 | - | |
139 | + | |
140 | 140 | if tprojection in (const.PROJECTION_CONTOUR_MIP, |
141 | 141 | const.PROJECTION_CONTOUR_MIDA): |
142 | 142 | self.border_spin.Enable() |
... | ... | @@ -233,7 +233,24 @@ class CanvasRendererCTX: |
233 | 233 | |
234 | 234 | self._cv_image.Modified() |
235 | 235 | |
236 | - def draw_text_box(self, text, pos, font=None, txt_colour=(0.0, 0.0, 0.0), bg_colour=(128, 0, 0, 128), border=5): | |
236 | + def draw_line(self, pos0, pos1, colour=(255, 0, 0, 128), width=2, style=wx.SOLID): | |
237 | + """ | |
238 | + Draw a line from pos0 to pos1 | |
239 | + """ | |
240 | + if self.gc is None: | |
241 | + return None | |
242 | + gc = self.gc | |
243 | + | |
244 | + pen = wx.Pen(wx.Colour(*colour), width, wx.SOLID) | |
245 | + gc.SetPen(pen) | |
246 | + | |
247 | + path = gc.CreatePath() | |
248 | + path.MoveToPoint(*pos0) | |
249 | + path.AddLineToPoint(*pos1) | |
250 | + gc.StrokePath(path) | |
251 | + | |
252 | + | |
253 | + def draw_text_box(self, text, pos, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5): | |
237 | 254 | """ |
238 | 255 | Draw text inside a text box. |
239 | 256 | |
... | ... | @@ -281,7 +298,7 @@ class Viewer(wx.Panel): |
281 | 298 | |
282 | 299 | self._number_slices = const.PROJECTION_MIP_SIZE |
283 | 300 | self._mip_inverted = False |
284 | - | |
301 | + | |
285 | 302 | self.style = None |
286 | 303 | self.last_position_mouse_move = () |
287 | 304 | self.state = const.STATE_DEFAULT |
... | ... | @@ -354,7 +371,7 @@ class Viewer(wx.Panel): |
354 | 371 | self.menu.caller = self |
355 | 372 | self.PopupMenu(self.menu) |
356 | 373 | evt.Skip() |
357 | - | |
374 | + | |
358 | 375 | def SetPopupMenu(self, menu): |
359 | 376 | self.menu = menu |
360 | 377 | |
... | ... | @@ -440,14 +457,14 @@ class Viewer(wx.Panel): |
440 | 457 | (slc.window_width, slc.window_level)) |
441 | 458 | |
442 | 459 | def SetWLText(self, window_width, window_level): |
443 | - value = STR_WL%(window_level, window_width) | |
460 | + value = STR_WL%(window_level, window_width) | |
444 | 461 | if (self.wl_text): |
445 | 462 | self.wl_text.SetValue(value) |
446 | 463 | #self.interactor.Render() |
447 | 464 | |
448 | 465 | def EnableText(self): |
449 | 466 | if not (self.wl_text): |
450 | - proj = project.Project() | |
467 | + proj = project.Project() | |
451 | 468 | colour = const.ORIENTATION_COLOUR[self.orientation] |
452 | 469 | |
453 | 470 | # Window & Level text |
... | ... | @@ -460,7 +477,7 @@ class Viewer(wx.Panel): |
460 | 477 | values = [_('P'), _('A'), _('T'), _('B')] |
461 | 478 | else: |
462 | 479 | values = [_('R'), _('L'), _('T'), _('B')] |
463 | - | |
480 | + | |
464 | 481 | left_text = self.left_text = vtku.TextZero() |
465 | 482 | left_text.ShadowOff() |
466 | 483 | left_text.SetColour(colour) |
... | ... | @@ -539,30 +556,30 @@ class Viewer(wx.Panel): |
539 | 556 | |
540 | 557 | elif(croll > 91 and croll <= 135): |
541 | 558 | self.RenderTextDirection([_("LP"), _("AL"), _("RA"), _("PR")]) |
542 | - | |
559 | + | |
543 | 560 | elif(croll > 135 and croll <= 177): |
544 | 561 | self.RenderTextDirection([_("PL"), _("LA"), _("AR"), _("RP")]) |
545 | - | |
562 | + | |
546 | 563 | elif(croll >= -180 and croll <= -178) or (croll < 180 and croll > 177): |
547 | 564 | self.RenderTextDirection([_("P"), _("L"), _("A"), _("R")]) |
548 | - | |
565 | + | |
549 | 566 | elif(croll >= -177 and croll <= -133): |
550 | 567 | self.RenderTextDirection([_("PR"), _("LP"), _("AL"), _("RA")]) |
551 | - | |
568 | + | |
552 | 569 | elif(croll >= -132 and croll <= -101): |
553 | 570 | self.RenderTextDirection([_("RP"), _("PL"), _("LA"), _("AR")]) |
554 | 571 | |
555 | 572 | elif(croll >= -101 and croll <= -87): |
556 | 573 | self.RenderTextDirection([_("R"), _("P"), _("L"), _("A")]) |
557 | - | |
574 | + | |
558 | 575 | elif(croll >= -86 and croll <= -42): |
559 | 576 | self.RenderTextDirection([_("RA"), _("PR"), _("LP"), _("AL")]) |
560 | - | |
577 | + | |
561 | 578 | elif(croll >= -41 and croll <= -2): |
562 | 579 | self.RenderTextDirection([_("AR"), _("RP"), _("PL"), _("LA")]) |
563 | 580 | |
564 | 581 | elif(self.orientation == "CORONAL"): |
565 | - | |
582 | + | |
566 | 583 | if (croll >= -2 and croll <= 1): |
567 | 584 | self.RenderTextDirection([_("T"), _("R"), _("B"), _("L")]) |
568 | 585 | |
... | ... | @@ -577,25 +594,25 @@ class Viewer(wx.Panel): |
577 | 594 | |
578 | 595 | elif(croll > 91 and croll <= 135): |
579 | 596 | self.RenderTextDirection([_("LB"), _("TL"), _("RT"), _("BR")]) |
580 | - | |
597 | + | |
581 | 598 | elif(croll > 135 and croll <= 177): |
582 | 599 | self.RenderTextDirection([_("BL"), _("LT"), _("TR"), _("RB")]) |
583 | - | |
600 | + | |
584 | 601 | elif(croll >= -180 and croll <= -178) or (croll < 180 and croll > 177): |
585 | 602 | self.RenderTextDirection([_("B"), _("L"), _("T"), _("R")]) |
586 | - | |
603 | + | |
587 | 604 | elif(croll >= -177 and croll <= -133): |
588 | 605 | self.RenderTextDirection([_("BR"), _("LB"), _("TL"), _("RT")]) |
589 | - | |
606 | + | |
590 | 607 | elif(croll >= -132 and croll <= -101): |
591 | 608 | self.RenderTextDirection([_("RB"), _("BL"), _("LT"), _("TR")]) |
592 | 609 | |
593 | 610 | elif(croll >= -101 and croll <= -87): |
594 | 611 | self.RenderTextDirection([_("R"), _("B"), _("L"), _("T")]) |
595 | - | |
612 | + | |
596 | 613 | elif(croll >= -86 and croll <= -42): |
597 | 614 | self.RenderTextDirection([_("RT"), _("BR"), _("LB"), _("TL")]) |
598 | - | |
615 | + | |
599 | 616 | elif(croll >= -41 and croll <= -2): |
600 | 617 | self.RenderTextDirection([_("TR"), _("RB"), _("BL"), _("LT")]) |
601 | 618 | |
... | ... | @@ -603,13 +620,13 @@ class Viewer(wx.Panel): |
603 | 620 | |
604 | 621 | if(croll >= -101 and croll <= -87): |
605 | 622 | self.RenderTextDirection([_("T"), _("P"), _("B"), _("A")]) |
606 | - | |
623 | + | |
607 | 624 | elif(croll >= -86 and croll <= -42): |
608 | 625 | self.RenderTextDirection([_("TA"), _("PT"), _("BP"), _("AB")]) |
609 | - | |
626 | + | |
610 | 627 | elif(croll >= -41 and croll <= -2): |
611 | 628 | self.RenderTextDirection([_("AT"), _("TP"), _("PB"), _("BA")]) |
612 | - | |
629 | + | |
613 | 630 | elif (croll >= -2 and croll <= 1): |
614 | 631 | self.RenderTextDirection([_("A"), _("T"), _("P"), _("B")]) |
615 | 632 | |
... | ... | @@ -624,16 +641,16 @@ class Viewer(wx.Panel): |
624 | 641 | |
625 | 642 | elif(croll > 91 and croll <= 135): |
626 | 643 | self.RenderTextDirection([_("BP"), _("AB"), _("TA"), _("PT")]) |
627 | - | |
644 | + | |
628 | 645 | elif(croll > 135 and croll <= 177): |
629 | 646 | self.RenderTextDirection([_("PB"), _("BA"), _("AT"), _("TP")]) |
630 | - | |
647 | + | |
631 | 648 | elif(croll >= -180 and croll <= -178) or (croll < 180 and croll > 177): |
632 | 649 | self.RenderTextDirection([_("P"), _("B"), _("A"), _("T")]) |
633 | - | |
650 | + | |
634 | 651 | elif(croll >= -177 and croll <= -133): |
635 | 652 | self.RenderTextDirection([_("PT"), _("BP"), _("AB"), _("TA")]) |
636 | - | |
653 | + | |
637 | 654 | elif(croll >= -132 and croll <= -101): |
638 | 655 | self.RenderTextDirection([_("TP"), _("PB"), _("BA"), _("AT")]) |
639 | 656 | |
... | ... | @@ -668,12 +685,12 @@ class Viewer(wx.Panel): |
668 | 685 | def Navigation(self, pubsub_evt): |
669 | 686 | # Get point from base change |
670 | 687 | x, y, z = pubsub_evt.data |
671 | - coord_cross = x, y, z | |
688 | + coord_cross = x, y, z | |
672 | 689 | position = self.slice_data.actor.GetInput().FindPoint(x, y, z) |
673 | 690 | coord_cross = self.slice_data.actor.GetInput().GetPoint(position) |
674 | - coord = self.calcultate_scroll_position(position) | |
691 | + coord = self.calcultate_scroll_position(position) | |
675 | 692 | Publisher.sendMessage('Update cross position', coord_cross) |
676 | - | |
693 | + | |
677 | 694 | self.ScrollSlice(coord) |
678 | 695 | self.interactor.Render() |
679 | 696 | |
... | ... | @@ -698,7 +715,7 @@ class Viewer(wx.Panel): |
698 | 715 | #for slice_data in self.slice_data_list: |
699 | 716 | #if slice_data.renderer is render: |
700 | 717 | #return slice_data |
701 | - # WARN: Return the only slice_data used in this slice_viewer. | |
718 | + # WARN: Return the only slice_data used in this slice_viewer. | |
702 | 719 | return self.slice_data |
703 | 720 | |
704 | 721 | def calcultate_scroll_position(self, position): |
... | ... | @@ -825,7 +842,7 @@ class Viewer(wx.Panel): |
825 | 842 | 'Hide text actors on viewers') |
826 | 843 | Publisher.subscribe(self.OnExportPicture,'Export picture to file') |
827 | 844 | Publisher.subscribe(self.SetDefaultCursor, 'Set interactor default cursor') |
828 | - | |
845 | + | |
829 | 846 | Publisher.subscribe(self.AddActors, 'Add actors ' + str(ORIENTATIONS[self.orientation])) |
830 | 847 | Publisher.subscribe(self.RemoveActors, 'Remove actors ' + str(ORIENTATIONS[self.orientation])) |
831 | 848 | Publisher.subscribe(self.OnSwapVolumeAxes, 'Swap volume axes') |
... | ... | @@ -851,11 +868,11 @@ class Viewer(wx.Panel): |
851 | 868 | |
852 | 869 | def SetDefaultCursor(self, pusub_evt): |
853 | 870 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) |
854 | - | |
871 | + | |
855 | 872 | def OnExportPicture(self, pubsub_evt): |
856 | 873 | Publisher.sendMessage('Begin busy cursor') |
857 | 874 | view_prop_list = [] |
858 | - view_prop_list.append(self.slice_data.box_actor) | |
875 | + view_prop_list.append(self.slice_data.box_actor) | |
859 | 876 | self.slice_data.renderer.RemoveViewProp(self.slice_data.box_actor) |
860 | 877 | |
861 | 878 | id, filename, filetype = pubsub_evt.data |
... | ... | @@ -917,7 +934,7 @@ class Viewer(wx.Panel): |
917 | 934 | def CloseProject(self): |
918 | 935 | for slice_data in self.slice_data_list: |
919 | 936 | del slice_data |
920 | - | |
937 | + | |
921 | 938 | self.slice_data_list = [] |
922 | 939 | self.layout = (1, 1) |
923 | 940 | self.orientation_texts = [] |
... | ... | @@ -929,10 +946,10 @@ class Viewer(wx.Panel): |
929 | 946 | def OnSetInteractorStyle(self, pubsub_evt): |
930 | 947 | state = pubsub_evt.data |
931 | 948 | self.SetInteractorStyle(state) |
932 | - | |
949 | + | |
933 | 950 | if (state != const.SLICE_STATE_EDITOR): |
934 | 951 | Publisher.sendMessage('Set interactor default cursor') |
935 | - | |
952 | + | |
936 | 953 | def __bind_events_wx(self): |
937 | 954 | self.scroll.Bind(wx.EVT_SCROLL, self.OnScrollBar) |
938 | 955 | self.scroll.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnScrollBarRelease) |
... | ... | @@ -1162,15 +1179,15 @@ class Viewer(wx.Panel): |
1162 | 1179 | def set_scroll_position(self, position): |
1163 | 1180 | self.scroll.SetThumbPosition(position) |
1164 | 1181 | self.OnScrollBar() |
1165 | - | |
1182 | + | |
1166 | 1183 | def UpdateSlice3D(self, pos): |
1167 | 1184 | original_orientation = project.Project().original_orientation |
1168 | 1185 | pos = self.scroll.GetThumbPosition() |
1169 | 1186 | Publisher.sendMessage('Change slice from slice plane',\ |
1170 | 1187 | (self.orientation, pos)) |
1171 | - | |
1188 | + | |
1172 | 1189 | def OnScrollBar(self, evt=None, update3D=True): |
1173 | - pos = self.scroll.GetThumbPosition() | |
1190 | + pos = self.scroll.GetThumbPosition() | |
1174 | 1191 | self.set_slice_number(pos) |
1175 | 1192 | if update3D: |
1176 | 1193 | self.UpdateSlice3D(pos) |
... | ... | @@ -1179,14 +1196,14 @@ class Viewer(wx.Panel): |
1179 | 1196 | # the actual orientation. |
1180 | 1197 | focal_point = self.cross.GetFocalPoint() |
1181 | 1198 | Publisher.sendMessage('Update cross position', focal_point) |
1182 | - Publisher.sendMessage('Update slice viewer') | |
1199 | + Publisher.sendMessage('Update slice viewer') | |
1183 | 1200 | else: |
1184 | - self.interactor.Render() | |
1201 | + self.interactor.Render() | |
1185 | 1202 | if evt: |
1186 | 1203 | if self._flush_buffer: |
1187 | 1204 | self.slice_.apply_slice_buffer_to_mask(self.orientation) |
1188 | 1205 | evt.Skip() |
1189 | - | |
1206 | + | |
1190 | 1207 | def OnScrollBarRelease(self, evt): |
1191 | 1208 | pos = self.scroll.GetThumbPosition() |
1192 | 1209 | evt.Skip() |
... | ... | @@ -1212,7 +1229,7 @@ class Viewer(wx.Panel): |
1212 | 1229 | if (evt.GetKeyCode() == wx.WXK_UP and pos > min): |
1213 | 1230 | self.OnScrollForward() |
1214 | 1231 | self.OnScrollBar() |
1215 | - | |
1232 | + | |
1216 | 1233 | elif (evt.GetKeyCode() == wx.WXK_DOWN and pos < max): |
1217 | 1234 | self.OnScrollBackward() |
1218 | 1235 | self.OnScrollBar() |
... | ... | @@ -1236,7 +1253,7 @@ class Viewer(wx.Panel): |
1236 | 1253 | Publisher.sendMessage('Set projection type', projections[evt.GetKeyCode()]) |
1237 | 1254 | Publisher.sendMessage('Reload actual slice') |
1238 | 1255 | skip = False |
1239 | - | |
1256 | + | |
1240 | 1257 | self.UpdateSlice3D(pos) |
1241 | 1258 | self.interactor.Render() |
1242 | 1259 | |
... | ... | @@ -1246,18 +1263,18 @@ class Viewer(wx.Panel): |
1246 | 1263 | def OnScrollForward(self, evt=None, obj=None): |
1247 | 1264 | pos = self.scroll.GetThumbPosition() |
1248 | 1265 | min = 0 |
1249 | - | |
1266 | + | |
1250 | 1267 | if(pos > min): |
1251 | 1268 | if self._flush_buffer: |
1252 | 1269 | self.slice_.apply_slice_buffer_to_mask(self.orientation) |
1253 | 1270 | pos = pos - 1 |
1254 | 1271 | self.scroll.SetThumbPosition(pos) |
1255 | 1272 | self.OnScrollBar() |
1256 | - | |
1273 | + | |
1257 | 1274 | def OnScrollBackward(self, evt=None, obj=None): |
1258 | 1275 | pos = self.scroll.GetThumbPosition() |
1259 | 1276 | max = self.slice_.GetMaxSliceNumber(self.orientation) |
1260 | - | |
1277 | + | |
1261 | 1278 | if(pos < max): |
1262 | 1279 | if self._flush_buffer: |
1263 | 1280 | self.slice_.apply_slice_buffer_to_mask(self.orientation) |
... | ... | @@ -1266,7 +1283,7 @@ class Viewer(wx.Panel): |
1266 | 1283 | self.OnScrollBar() |
1267 | 1284 | |
1268 | 1285 | def OnSize(self, evt): |
1269 | - w, h = evt.GetSize() | |
1286 | + w, h = evt.GetSize() | |
1270 | 1287 | w = float(w) |
1271 | 1288 | h = float(h) |
1272 | 1289 | if self.slice_data: |
... | ... | @@ -1303,7 +1320,7 @@ class Viewer(wx.Panel): |
1303 | 1320 | self.mip_ctrls.Hide() |
1304 | 1321 | self.GetSizer().Remove(self.mip_ctrls) |
1305 | 1322 | self.Layout() |
1306 | - | |
1323 | + | |
1307 | 1324 | def OnSetOverwriteMask(self, pubsub_evt): |
1308 | 1325 | value = pubsub_evt.data |
1309 | 1326 | self.overwrite_mask = value |
... | ... | @@ -1360,7 +1377,7 @@ class Viewer(wx.Panel): |
1360 | 1377 | # orientation |
1361 | 1378 | axis0, axis1 = pubsub_evt.data |
1362 | 1379 | cursor = self.slice_data.cursor |
1363 | - spacing = cursor.spacing | |
1380 | + spacing = cursor.spacing | |
1364 | 1381 | if (axis0, axis1) == (2, 1): |
1365 | 1382 | cursor.SetSpacing((spacing[1], spacing[0], spacing[2])) |
1366 | 1383 | elif (axis0, axis1) == (2, 0): | ... | ... |