File qt_plot.py changed (mode: 100644) (index e93295d..a584209) |
... |
... |
class QtGuiPlot2D(QtGui.QMainWindow): |
222 |
222 |
self.view_items.append(LastShot(self)) |
self.view_items.append(LastShot(self)) |
223 |
223 |
self.view_items.append(Circles(self)) |
self.view_items.append(Circles(self)) |
224 |
224 |
self.view_items.append(Boundaries(self)) |
self.view_items.append(Boundaries(self)) |
|
225 |
|
self.view_items.append(ConvexHull2D(self)) |
225 |
226 |
self.view_items.append(Triangulation(self)) |
self.view_items.append(Triangulation(self)) |
226 |
227 |
|
|
227 |
228 |
|
|
|
... |
... |
class Boundaries: |
618 |
619 |
item.hide() |
item.hide() |
619 |
620 |
|
|
620 |
621 |
|
|
|
622 |
|
|
|
623 |
|
|
621 |
624 |
class Triangulation: |
class Triangulation: |
622 |
625 |
def __init__(self, w): |
def __init__(self, w): |
623 |
626 |
|
|
|
... |
... |
class Triangulation: |
634 |
637 |
|
|
635 |
638 |
|
|
636 |
639 |
self.w.list_view.itemChanged.connect(self.show_slot) |
self.w.list_view.itemChanged.connect(self.show_slot) |
|
640 |
|
|
|
641 |
|
self.spatial = 'tri' |
637 |
642 |
|
|
638 |
643 |
|
|
639 |
644 |
|
|
|
... |
... |
class Triangulation: |
665 |
670 |
when we need to completely |
when we need to completely |
666 |
671 |
redraw the triangulation |
redraw the triangulation |
667 |
672 |
""" |
""" |
668 |
|
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
|
669 |
|
try: |
|
670 |
|
self.simplices = self.w.sample_box.tri.simplices |
|
|
673 |
|
if self.item.checkState(): |
|
674 |
|
try: |
|
675 |
|
spatial = getattr(self.w.sample_box, self.spatial) |
|
676 |
|
self.simplices = spatial.simplices |
671 |
677 |
for item in self.plot_items: |
for item in self.plot_items: |
672 |
678 |
item.hide() |
item.hide() |
673 |
|
self.draw_triangles(range(self.w.sample_box.tri.nsimplex)) |
|
|
679 |
|
self.draw_simplices(range(len(self.simplices))) |
674 |
680 |
|
|
675 |
681 |
except BaseException as e: |
except BaseException as e: |
676 |
|
msg = "error during of triangulation replot" |
|
|
682 |
|
msg = "error during replot" |
677 |
683 |
print(self.__class__.__name__ + ":",msg, repr(e)) |
print(self.__class__.__name__ + ":",msg, repr(e)) |
678 |
684 |
|
|
679 |
685 |
|
|
680 |
686 |
|
|
681 |
687 |
def update(self): |
def update(self): |
682 |
688 |
# update triangulation |
# update triangulation |
683 |
|
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
|
|
689 |
|
if self.item.checkState(): |
684 |
690 |
try: #оӵ Мед сюредалоз! |
try: #оӵ Мед сюредалоз! |
685 |
691 |
former_simplices = self.simplices |
former_simplices = self.simplices |
686 |
|
self.simplices = self.w.sample_box.tri.simplices |
|
|
692 |
|
spatial = getattr(self.w.sample_box, self.spatial) |
|
693 |
|
self.simplices = spatial.simplices |
687 |
694 |
|
|
688 |
|
#č zkontrolujeme co se změnilo |
|
689 |
|
#č předpokladám, že se počet simplexů přidaním bodů nezměnší |
|
690 |
|
equal_mask = former_simplices == self.w.sample_box.tri.simplices[:len(former_simplices)] |
|
691 |
|
changed_simplices_ids = np.argwhere(~equal_mask.all(axis=1)).flatten() |
|
692 |
|
self.draw_triangles(changed_simplices_ids) |
|
693 |
|
|
|
694 |
|
#č teď nové simplexy |
|
695 |
|
#ё simplexy свежего разлива |
|
696 |
|
self.draw_triangles(range(len(former_simplices), self.w.sample_box.tri.nsimplex)) |
|
|
695 |
|
#č počet simplexů může se přidaním bodů změnšit |
|
696 |
|
#č (hlavně u ConvexHull, ale coplanar taky může vyskočit) |
|
697 |
|
if len(self.simplices) < len(former_simplices): |
|
698 |
|
self.replot() |
|
699 |
|
else: |
|
700 |
|
#č zkontrolujeme co se změnilo |
|
701 |
|
equal_mask = former_simplices == self.simplices[:len(former_simplices)] |
|
702 |
|
changed_simplices_ids = np.argwhere(~equal_mask.all(axis=1)).flatten() |
|
703 |
|
self.draw_simplices(changed_simplices_ids) |
|
704 |
|
|
|
705 |
|
#č teď nové simplexy |
|
706 |
|
#ё simplexy свежего разлива |
|
707 |
|
self.draw_simplices(range(len(former_simplices), len(self.simplices))) |
697 |
708 |
|
|
698 |
709 |
except BaseException as e: |
except BaseException as e: |
699 |
|
msg = "error during of triangulation update" |
|
|
710 |
|
msg = "error during update" |
700 |
711 |
print(self.__class__.__name__ + ":",msg, repr(e)) |
print(self.__class__.__name__ + ":",msg, repr(e)) |
701 |
712 |
|
|
|
713 |
|
|
702 |
714 |
|
|
|
715 |
|
|
|
716 |
|
def set_plot_data(self, pos, simplex_id): |
|
717 |
|
if simplex_id < len(self.plot_items): |
|
718 |
|
# Update the data |
|
719 |
|
plot_item = self.plot_items[simplex_id] |
|
720 |
|
plot_item.setData(pos) |
|
721 |
|
plot_item.show() |
|
722 |
|
else: #č spolehám na korektnost volajícího kódu |
|
723 |
|
#оӵ Суредасько |
|
724 |
|
plot_widget = self.w.central_widget |
|
725 |
|
plot_item = plot_widget.plot(pos, pen=0.7) |
|
726 |
|
self.plot_items.append(plot_item) |
703 |
727 |
|
|
704 |
728 |
|
|
705 |
729 |
#č já jsem tu všecko překopal protože .plot() a .setData() jsou nejžravejší na čas |
#č já jsem tu všecko překopal protože .plot() a .setData() jsou nejžravejší na čas |
706 |
730 |
#č a nemá žádnou cenu je provadet hned vedle sebe (spouští totéž dvakrát) |
#č a nemá žádnou cenu je provadet hned vedle sebe (spouští totéž dvakrát) |
707 |
|
def draw_triangles(self, simplex_ids): |
|
|
731 |
|
def draw_simplices(self, simplex_ids): |
708 |
732 |
# take coordinates in the space, where triangulation has been performed |
# take coordinates in the space, where triangulation has been performed |
709 |
733 |
sampled_plan_tri = getattr(self.w.sample_box, self.w.sample_box.tri_space) |
sampled_plan_tri = getattr(self.w.sample_box, self.w.sample_box.tri_space) |
710 |
734 |
|
|
711 |
|
plot_widget = self.w.central_widget |
|
712 |
|
|
|
713 |
735 |
if self.w.space == self.w.sample_box.tri_space: |
if self.w.space == self.w.sample_box.tri_space: |
714 |
736 |
for simplex_id in simplex_ids: |
for simplex_id in simplex_ids: |
715 |
737 |
triangle = self.simplices[simplex_id] |
triangle = self.simplices[simplex_id] |
716 |
738 |
pos = sampled_plan_tri[triangle[[0,1,2,0]]] |
pos = sampled_plan_tri[triangle[[0,1,2,0]]] |
717 |
739 |
|
|
718 |
|
|
|
719 |
|
if simplex_id < len(self.plot_items): |
|
720 |
|
# Update the data |
|
721 |
|
plot_item = self.plot_items[simplex_id] |
|
722 |
|
plot_item.setData(pos) |
|
723 |
|
plot_item.show() |
|
724 |
|
else: #č spolehám na korektnost volajícího kódu |
|
725 |
|
#оӵ Суредасько |
|
726 |
|
plot_item = plot_widget.plot(pos, pen=0.7) |
|
727 |
|
self.plot_items.append(plot_item) |
|
|
740 |
|
self.set_plot_data(pos, simplex_id) |
728 |
741 |
|
|
729 |
742 |
else: |
else: |
730 |
743 |
ns = 100 |
ns = 100 |
|
... |
... |
class Triangulation: |
747 |
760 |
tri_bound = self.w.sample_box.f_model.new_sample(tri_bound_tri, space=self.w.sample_box.tri_space) |
tri_bound = self.w.sample_box.f_model.new_sample(tri_bound_tri, space=self.w.sample_box.tri_space) |
748 |
761 |
pos = getattr(tri_bound, self.w.space) |
pos = getattr(tri_bound, self.w.space) |
749 |
762 |
|
|
750 |
|
if simplex_id < len(self.plot_items): |
|
751 |
|
# Update the data |
|
752 |
|
plot_item = self.plot_items[simplex_id] |
|
753 |
|
plot_item.setData(pos) |
|
754 |
|
plot_item.show() |
|
755 |
|
else: #č spolehám na korektnost volajícího kódu |
|
756 |
|
#оӵ Суредасько |
|
757 |
|
plot_item = plot_widget.plot(pos, pen=0.7) |
|
758 |
|
self.plot_items.append(plot_item) |
|
|
763 |
|
self.set_plot_data(pos, simplex_id) |
|
764 |
|
|
|
765 |
|
|
|
766 |
|
|
|
767 |
|
|
|
768 |
|
class ConvexHull2D(Triangulation): |
|
769 |
|
def __init__(self, w): |
|
770 |
|
|
|
771 |
|
self.w = w |
|
772 |
|
if self.w.sample_box.nvar == 2: |
|
773 |
|
self.w.box_runned.connect(self.update) |
|
774 |
|
self.w.space_changed.connect(self.replot) |
|
775 |
|
self.w.redraw_called.connect(self.redraw) |
|
776 |
|
|
|
777 |
|
self.item = QtGui.QListWidgetItem('Convex hull') |
|
778 |
|
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
|
779 |
|
self.item.setCheckState(QtCore.Qt.Checked) |
|
780 |
|
self.w.list_view.addItem(self.item) |
|
781 |
|
|
|
782 |
|
|
|
783 |
|
self.w.list_view.itemChanged.connect(self.show_slot) |
|
784 |
|
|
|
785 |
|
self.spatial = 'convex_hull' |
|
786 |
|
|
|
787 |
|
|
|
788 |
|
|
|
789 |
|
def redraw(self): |
|
790 |
|
self.simplices = np.empty((0,2), dtype=np.int) |
|
791 |
|
self.plot_items = [] |
|
792 |
|
self.replot() |
|
793 |
|
|
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
|
797 |
|
|
|
798 |
|
#č já jsem tu všecko překopal protože .plot() a .setData() jsou nejžravejší na čas |
|
799 |
|
#č a nemá žádnou cenu je provadet hned vedle sebe (spouští totéž dvakrát) |
|
800 |
|
def draw_simplices(self, simplex_ids): |
|
801 |
|
|
|
802 |
|
# convex hull should be made in the same space as triangulation, I guess |
|
803 |
|
# take coordinates in the triangulation space |
|
804 |
|
sampled_plan_tri = getattr(self.w.sample_box, self.w.sample_box.tri_space) |
|
805 |
|
|
|
806 |
|
plot_widget = self.w.central_widget |
|
807 |
|
|
|
808 |
|
if self.w.space == self.w.sample_box.tri_space: |
|
809 |
|
for simplex_id in simplex_ids: |
|
810 |
|
pos = sampled_plan_tri[self.simplices[simplex_id]] |
|
811 |
|
|
|
812 |
|
self.set_plot_data(pos, simplex_id) |
|
813 |
|
|
|
814 |
|
else: |
|
815 |
|
ns = 100 |
|
816 |
|
#оӵ кулэ ӧвӧл обновлять экран карыны |
|
817 |
|
for simplex_id in simplex_ids: |
|
818 |
|
start_id, end_id = self.simplices[simplex_id] |
|
819 |
|
|
|
820 |
|
x_bound = np.linspace(sampled_plan_tri[start_id,0], sampled_plan_tri[end_id,0], ns, endpoint=True) |
|
821 |
|
y_bound = np.linspace(sampled_plan_tri[start_id,1], sampled_plan_tri[end_id,1], ns, endpoint=True) |
759 |
822 |
|
|
|
823 |
|
# sample compatible |
|
824 |
|
#оӵ малы транспонировать кароно? Озьы кулэ! |
|
825 |
|
bound_tri = np.vstack((x_bound, y_bound)).T |
|
826 |
|
#č vytvořme sample |
|
827 |
|
bound = self.w.sample_box.f_model.new_sample(bound_tri, space=self.w.sample_box.tri_space) |
|
828 |
|
pos = getattr(bound, self.w.space) |
|
829 |
|
|
|
830 |
|
self.set_plot_data(pos, simplex_id) |
|
831 |
|
|
|
832 |
|
|
760 |
833 |
|
|
761 |
834 |
|
|
762 |
835 |
|
|