File qt_plot.py changed (mode: 100644) (index f014d26..7932c95) |
... |
... |
class LastShot: |
418 |
418 |
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
419 |
419 |
self.item.setCheckState(QtCore.Qt.Checked) |
self.item.setCheckState(QtCore.Qt.Checked) |
420 |
420 |
self.w.list_view.addItem(self.item) |
self.w.list_view.addItem(self.item) |
421 |
|
self.w.list_view.itemChanged.connect(self.plot) |
|
|
421 |
|
self.w.list_view.itemChanged.connect(self.show_slot) |
422 |
422 |
|
|
|
423 |
|
def show_slot(self, item): |
|
424 |
|
if item is self.item: |
|
425 |
|
self.plot() |
423 |
426 |
|
|
424 |
427 |
def redraw(self): |
def redraw(self): |
425 |
428 |
pos = () |
pos = () |
|
... |
... |
class Circles: |
456 |
459 |
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
457 |
460 |
self.item.setCheckState(QtCore.Qt.Checked) |
self.item.setCheckState(QtCore.Qt.Checked) |
458 |
461 |
self.w.list_view.addItem(self.item) |
self.w.list_view.addItem(self.item) |
459 |
|
self.w.list_view.itemChanged.connect(self.plot) |
|
|
462 |
|
self.w.list_view.itemChanged.connect(self.show_slot) |
460 |
463 |
|
|
461 |
464 |
|
|
462 |
465 |
def redraw(self): |
def redraw(self): |
|
... |
... |
class Circles: |
472 |
475 |
|
|
473 |
476 |
self.plot() |
self.plot() |
474 |
477 |
|
|
475 |
|
|
|
|
478 |
|
def show_slot(self, item): |
|
479 |
|
if item is self.item: |
|
480 |
|
self.plot() |
476 |
481 |
|
|
477 |
482 |
def plot(self): |
def plot(self): |
478 |
483 |
if self.item.checkState(): |
if self.item.checkState(): |
|
... |
... |
class Boundaries: |
512 |
517 |
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
self.item.setFlags(self.item.flags() | QtCore.Qt.ItemIsUserCheckable) |
513 |
518 |
self.item.setCheckState(QtCore.Qt.Checked) |
self.item.setCheckState(QtCore.Qt.Checked) |
514 |
519 |
self.w.list_view.addItem(self.item) |
self.w.list_view.addItem(self.item) |
515 |
|
self.w.list_view.itemChanged.connect(self.plot) |
|
|
520 |
|
self.w.list_view.itemChanged.connect(self.show_slot) |
516 |
521 |
|
|
517 |
522 |
|
|
518 |
523 |
def redraw(self): |
def redraw(self): |
|
... |
... |
class Boundaries: |
531 |
536 |
|
|
532 |
537 |
self.plot() |
self.plot() |
533 |
538 |
|
|
534 |
|
|
|
|
539 |
|
def show_slot(self, item): |
|
540 |
|
if item is self.item: |
|
541 |
|
self.plot() |
535 |
542 |
|
|
536 |
543 |
def plot(self): |
def plot(self): |
537 |
544 |
if self.item.checkState(): |
if self.item.checkState(): |
|
... |
... |
class Triangulation: |
559 |
566 |
self.w.list_view.addItem(self.item) |
self.w.list_view.addItem(self.item) |
560 |
567 |
|
|
561 |
568 |
|
|
562 |
|
self.w.list_view.itemChanged.connect(self.replot) |
|
|
569 |
|
self.w.list_view.itemChanged.connect(self.show_slot) |
563 |
570 |
|
|
564 |
571 |
|
|
565 |
572 |
|
|
566 |
573 |
def redraw(self): |
def redraw(self): |
567 |
574 |
self.simplices = np.empty((0,3), dtype=np.int) |
self.simplices = np.empty((0,3), dtype=np.int) |
568 |
|
self.plot_items = np.empty(0, dtype=object) |
|
|
575 |
|
self.plot_items = [] |
569 |
576 |
self.replot() |
self.replot() |
570 |
577 |
|
|
571 |
578 |
|
|
|
579 |
|
def show_slot(self, item): |
|
580 |
|
if item is self.item: |
|
581 |
|
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
|
582 |
|
for item in self.plot_items: |
|
583 |
|
item.show() |
|
584 |
|
|
|
585 |
|
#оӵ Мед сюредалоз! |
|
586 |
|
self.replot() |
|
587 |
|
|
|
588 |
|
else: #оӵ Медам сюреда! |
|
589 |
|
for item in self.plot_items: |
|
590 |
|
item.hide() |
|
591 |
|
|
572 |
592 |
|
|
573 |
593 |
|
|
574 |
594 |
def replot(self): |
def replot(self): |
|
... |
... |
class Triangulation: |
579 |
599 |
redraw the triangulation |
redraw the triangulation |
580 |
600 |
""" |
""" |
581 |
601 |
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
582 |
|
try: |
|
583 |
|
if len(self.plot_items) < self.w.sample_box.tri.nsimplex: |
|
584 |
|
pos = () |
|
585 |
|
plot_widget = self.w.central_widget |
|
586 |
|
gap = self.w.sample_box.tri.nsimplex - len(self.plot_items) |
|
587 |
|
gap_items = [] |
|
588 |
|
for __ in range(gap): |
|
589 |
|
gap_items.append(plot_widget.plot(pos=pos, pen=0.7)) |
|
590 |
|
self.plot_items = np.append(self.plot_items, gap_items) |
|
591 |
|
|
|
|
602 |
|
try: |
592 |
603 |
self.simplices = self.w.sample_box.tri.simplices |
self.simplices = self.w.sample_box.tri.simplices |
593 |
|
self.draw_triangles(self.simplices, self.plot_items) |
|
|
604 |
|
self.draw_triangles(range(self.w.sample_box.tri.nsimplex)) |
594 |
605 |
|
|
595 |
606 |
except BaseException as e: |
except BaseException as e: |
596 |
|
msg = "error during triangulation drawing" |
|
|
607 |
|
msg = "error during of triangulation replot" |
597 |
608 |
print(self.__class__.__name__ + ":",msg, repr(e)) |
print(self.__class__.__name__ + ":",msg, repr(e)) |
598 |
609 |
|
|
599 |
|
else: |
|
600 |
|
for item in self.plot_items: |
|
601 |
|
item.hide() |
|
602 |
610 |
|
|
603 |
611 |
|
|
604 |
612 |
def update(self): |
def update(self): |
605 |
613 |
# update triangulation |
# update triangulation |
606 |
614 |
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
if (self.w.sample_box.nvar==2) and self.item.checkState(): |
607 |
615 |
try: #оӵ Мед сюредалоз! |
try: #оӵ Мед сюредалоз! |
608 |
|
if len(self.plot_items) < self.w.sample_box.tri.nsimplex: |
|
609 |
|
pos = () |
|
610 |
|
plot_widget = self.w.central_widget |
|
611 |
|
gap = self.w.sample_box.tri.nsimplex - len(self.plot_items) |
|
612 |
|
gap_items = np.empty(gap, dtype=object) |
|
613 |
|
for i in range(gap): |
|
614 |
|
gap_items[i] = plot_widget.plot(pos=pos, pen=0.7) |
|
615 |
|
self.plot_items = np.append(self.plot_items, gap_items) |
|
616 |
|
#č empty není bezpěčný - může obsahovat cokoliv |
|
617 |
|
#č takže budeme se tešit na chvili, kdy to selže |
|
618 |
|
#č jistě to bude nejméné vhodná chvile, nějaká konference... |
|
619 |
|
former_simplices = np.append(self.simplices, np.empty((gap,3), dtype=np.int)) |
|
620 |
|
else: |
|
621 |
|
former_simplices = self.simplices |
|
622 |
|
|
|
|
616 |
|
former_simplices = self.simplices |
623 |
617 |
self.simplices = self.w.sample_box.tri.simplices |
self.simplices = self.w.sample_box.tri.simplices |
|
618 |
|
|
624 |
619 |
#č zkontrolujeme co se změnilo |
#č zkontrolujeme co se změnilo |
625 |
620 |
#č předpokladám, že se počet simplexů přidaním bodů nezměnší |
#č předpokladám, že se počet simplexů přidaním bodů nezměnší |
626 |
|
equal_mask = former_simplices == self.w.sample_box.tri.simplices |
|
627 |
|
#č vůbec nechapu, proč se mi nechce prostě všecko udělat stejně jako v blackboxu? |
|
628 |
|
mask = equal_mask.all(axis=1).flatten() |
|
|
621 |
|
equal_mask = former_simplices == self.w.sample_box.tri.simplices[:len(former_simplices)] |
|
622 |
|
changed_simplices_ids = np.argwhere(~equal_mask.all(axis=1)).flatten() |
|
623 |
|
self.draw_triangles(changed_simplices_ids) |
629 |
624 |
|
|
630 |
|
self.draw_triangles(self.simplices[~mask], self.plot_items[~mask]) |
|
631 |
|
for item in self.plot_items[mask]: |
|
632 |
|
item.show() |
|
|
625 |
|
#č teď nové simplexy |
|
626 |
|
#ё simplexy свежего разлива |
|
627 |
|
self.draw_triangles(range(len(former_simplices), self.w.sample_box.tri.nsimplex)) |
633 |
628 |
|
|
634 |
629 |
except BaseException as e: |
except BaseException as e: |
635 |
|
msg = "error during triangulation drawing" |
|
|
630 |
|
msg = "error during of triangulation update" |
636 |
631 |
print(self.__class__.__name__ + ":",msg, repr(e)) |
print(self.__class__.__name__ + ":",msg, repr(e)) |
637 |
|
|
|
638 |
|
else: #оӵ Медам сюреда! |
|
639 |
|
for item in self.plot_items: |
|
640 |
|
item.hide() |
|
|
632 |
|
|
641 |
633 |
|
|
642 |
634 |
|
|
643 |
635 |
|
|
644 |
|
|
|
645 |
|
def draw_triangles(self, simplices, plot_items): |
|
|
636 |
|
#č já jsem tu všecko překopal protože .plot() a .setData() jsou nejžravejší na čas |
|
637 |
|
#č a nemá žádnou cenu je provadet hned vedle sebe (spouští totéž dvakrát) |
|
638 |
|
def draw_triangles(self, simplex_ids): |
646 |
639 |
# take coordinates in the space, where triangulation has been performed |
# take coordinates in the space, where triangulation has been performed |
647 |
640 |
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) |
648 |
641 |
|
|
|
642 |
|
plot_widget = self.w.central_widget |
|
643 |
|
|
649 |
644 |
if self.w.space == self.w.sample_box.tri_space: |
if self.w.space == self.w.sample_box.tri_space: |
650 |
|
for triangle, plot_item in zip(simplices, plot_items): |
|
|
645 |
|
for simplex_id in simplex_ids: |
|
646 |
|
triangle = self.simplices[simplex_id] |
651 |
647 |
pos = sampled_plan_tri[triangle[[0,1,2,0]]] |
pos = sampled_plan_tri[triangle[[0,1,2,0]]] |
652 |
648 |
|
|
653 |
|
# Update the data |
|
654 |
|
plot_item.setData(pos) |
|
655 |
|
plot_item.show() |
|
|
649 |
|
|
|
650 |
|
if simplex_id < len(self.plot_items): |
|
651 |
|
# Update the data |
|
652 |
|
plot_item = self.plot_items[simplex_id] |
|
653 |
|
plot_item.setData(pos) |
|
654 |
|
#plot_item.show() |
|
655 |
|
else: #č spolehám na korektnost volajícího kódu |
|
656 |
|
#оӵ Суредасько |
|
657 |
|
plot_item = plot_widget.plot(pos, pen=0.7) |
|
658 |
|
self.plot_items.append(plot_item) |
|
659 |
|
|
656 |
660 |
else: |
else: |
657 |
661 |
ns = 100 |
ns = 100 |
658 |
662 |
with pg.BusyCursor(): |
with pg.BusyCursor(): |
659 |
|
for triangle, plot_item in zip(simplices, plot_items): |
|
|
663 |
|
for simplex_id in simplex_ids: |
|
664 |
|
triangle = self.simplices[simplex_id] |
660 |
665 |
# keep the GUI responsive :) |
# keep the GUI responsive :) |
661 |
666 |
# it was quite slow on my target machine |
# it was quite slow on my target machine |
662 |
667 |
self.w.app.processEvents() |
self.w.app.processEvents() |
|
... |
... |
class Triangulation: |
671 |
676 |
tri_bound_tri = np.array((x_tri, y_tri)).T |
tri_bound_tri = np.array((x_tri, y_tri)).T |
672 |
677 |
#č vytvořme sample |
#č vytvořme sample |
673 |
678 |
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) |
|
679 |
|
pos = getattr(tri_bound, self.w.space) |
674 |
680 |
|
|
675 |
|
# Update the data |
|
676 |
|
#print("Суредасько", tri_bound) |
|
677 |
|
plot_item.setData(getattr(tri_bound, self.w.space)) |
|
678 |
|
plot_item.show() |
|
|
681 |
|
if simplex_id < len(self.plot_items): |
|
682 |
|
# Update the data |
|
683 |
|
plot_item = self.plot_items[simplex_id] |
|
684 |
|
plot_item.setData(pos) |
|
685 |
|
#plot_item.show() |
|
686 |
|
else: #č spolehám na korektnost volajícího kódu |
|
687 |
|
#оӵ Суредасько |
|
688 |
|
plot_item = plot_widget.plot(pos, pen=0.7) |
|
689 |
|
self.plot_items.append(plot_item) |
679 |
690 |
|
|
680 |
691 |
|
|
681 |
692 |
|
|