File qt_gui/gl_plot.py changed (mode: 100644) (index d6aced1..b7c45ec) |
... |
... |
import pandas as pd # required for estimation graph |
13 |
13 |
from scipy import spatial |
from scipy import spatial |
14 |
14 |
|
|
15 |
15 |
from .. import estimation as stm |
from .. import estimation as stm |
|
16 |
|
from .. import convex_hull as khull |
|
17 |
|
from .. import simplex as six |
16 |
18 |
from . import qt_gui |
from . import qt_gui |
17 |
19 |
from . import qt_plot |
from . import qt_plot |
18 |
20 |
|
|
|
... |
... |
class Grid: |
267 |
269 |
|
|
268 |
270 |
|
|
269 |
271 |
|
|
270 |
|
|
|
|
272 |
|
#č mění se význám, semantika třídy |
|
273 |
|
#č teď to není nástroj pro kontrolu skříňky, ale |
|
274 |
|
#č ale pro zobrazování hezkých obrázků |
|
275 |
|
#č teď se mi to víc hodí do krámu |
271 |
276 |
class ConvexHull(gl.GLMeshItem): |
class ConvexHull(gl.GLMeshItem): |
272 |
277 |
def __init__(self, w): |
def __init__(self, w): |
273 |
278 |
## Mesh item will automatically compute face normals. |
## Mesh item will automatically compute face normals. |
|
... |
... |
class ConvexHull(gl.GLMeshItem): |
278 |
283 |
self.w = w |
self.w = w |
279 |
284 |
#č já asi nechcu ani snažit sa něčo zobraziť |
#č já asi nechcu ani snažit sa něčo zobraziť |
280 |
285 |
#č z více dimenzí |
#č z více dimenzí |
281 |
|
if self.w.sample_box.nvar == 3: |
|
282 |
|
self.w.box_runned.connect(self.plot) |
|
|
286 |
|
if self.w.sample_box.nvar == 3: |
|
287 |
|
self.w.slice_changed.connect(self.plot) |
|
288 |
|
#č slice_changed postačí, zahrnuje i box_runned |
|
289 |
|
#self.w.box_runned.connect(self.plot) |
283 |
290 |
self.w.space_changed.connect(self.plot) |
self.w.space_changed.connect(self.plot) |
284 |
291 |
self.w.redraw_called.connect(self.redraw) |
self.w.redraw_called.connect(self.redraw) |
285 |
292 |
|
|
|
... |
... |
class ConvexHull(gl.GLMeshItem): |
298 |
305 |
|
|
299 |
306 |
|
|
300 |
307 |
def redraw(self): |
def redraw(self): |
301 |
|
try: |
|
302 |
|
self.plot() |
|
303 |
|
self.w.central_widget.addItem(self) |
|
304 |
|
except BaseException as e: |
|
305 |
|
msg = "Redraw failed " |
|
306 |
|
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
|
307 |
|
print(error_msg) |
|
|
308 |
|
self.plot() |
|
309 |
|
self.w.central_widget.addItem(self) |
308 |
310 |
|
|
309 |
311 |
def recalculate(self): |
def recalculate(self): |
310 |
|
if (self.w.sample_box.nsim != len(self.w.sample_box.convex_hull.points)): |
|
311 |
|
#č ConvexHull nemichá vzorky a nedělá ďupy - byla to chyba v Blackboxu |
|
312 |
|
print(self.__class__.__name__ + \ |
|
313 |
|
": convex hull points mismatch. Switching to the failsafe code.") |
|
314 |
|
sampled_plan_tri = getattr(self.w.sample_box, self.w.sample_box.tri_space) |
|
315 |
|
tree = spatial.cKDTree(sampled_plan_tri) |
|
316 |
|
self.points = self.w.sample_box.convex_hull.points |
|
317 |
|
dd, ii = tree.query(self.points, k=1, p=2) |
|
318 |
|
|
|
319 |
|
self.simplices = self.w.sample_box.convex_hull.simplices |
|
320 |
|
box_facets = ii[self.simplices.flatten()].reshape(-1, 3) |
|
321 |
|
self.events = self.w.sample_box.get_events(box_facets) |
|
322 |
|
|
|
323 |
|
|
|
324 |
|
nodes_colors = np.empty((self.w.sample_box.nsim, 4)) |
|
325 |
|
nodes_colors[self.w.sample_box.failsi] = np.array([253, 93, 97, 0])/255 |
|
326 |
|
nodes_colors[~self.w.sample_box.failsi] = np.array([67, 255, 81, 0])/255 |
|
327 |
|
|
|
328 |
|
|
|
329 |
|
self.vertex_colors = nodes_colors[ii] |
|
330 |
|
|
|
331 |
|
else: #č reabilitace ConvexHull |
|
332 |
|
self.points = self.w.sample_box.convex_hull.points |
|
333 |
|
self.simplices = self.w.sample_box.convex_hull.simplices |
|
334 |
|
self.events = self.w.sample_box.get_events(self.simplices) |
|
335 |
|
|
|
336 |
|
|
|
337 |
|
nodes_colors = np.empty((self.w.sample_box.nsim, 4)) |
|
338 |
|
nodes_colors[self.w.sample_box.failsi] = np.array([253, 93, 97, 0])/255 |
|
339 |
|
nodes_colors[~self.w.sample_box.failsi] = np.array([67, 255, 81, 0])/255 |
|
340 |
|
|
|
341 |
|
|
|
342 |
|
self.vertex_colors = nodes_colors |
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
|
|
312 |
|
nsim = self.w.slider.value() |
|
313 |
|
sample_box = self.w.sample_box[:nsim] |
|
314 |
|
|
|
315 |
|
qhull = khull.QHull(sample_box, space=self.w.space, incremental=False) |
346 |
316 |
|
|
|
317 |
|
|
|
318 |
|
self.points = qhull.points |
|
319 |
|
self.simplices = qhull.simplices |
|
320 |
|
self.events = six.get_events(sample_box, self.simplices) |
|
321 |
|
|
|
322 |
|
nodes_colors = np.empty((self.w.sample_box.nsim, 4)) |
|
323 |
|
nodes_colors[self.w.sample_box.failsi] = np.array([253, 93, 97, 0])/255 |
|
324 |
|
nodes_colors[~self.w.sample_box.failsi] = np.array([67, 255, 81, 0])/255 |
|
325 |
|
|
|
326 |
|
self.vertex_colors = nodes_colors |
|
327 |
|
|
347 |
328 |
# marker |
# marker |
348 |
329 |
self.nsim = self.w.sample_box.nsim |
self.nsim = self.w.sample_box.nsim |
349 |
330 |
|
|
|
331 |
|
#č kus kódu jako historická památka |
|
332 |
|
#č doposud si pamatuji, jak jsem tu kvůli vlástní chybě bojoval s ConvexHull'em |
|
333 |
|
#č pak ConvexHull byl reabilitován |
|
334 |
|
## if (self.w.sample_box.nsim != len(self.w.sample_box.convex_hull.points)): |
|
335 |
|
## #č ConvexHull nemichá vzorky a nedělá ďupy - byla to chyba v Blackboxu |
|
336 |
|
## print(self.__class__.__name__ + \ |
|
337 |
|
## ": convex hull points mismatch. Switching to the failsafe code.") |
|
338 |
|
## sampled_plan_tri = getattr(self.w.sample_box, self.w.sample_box.tri_space) |
|
339 |
|
## tree = spatial.cKDTree(sampled_plan_tri) |
|
340 |
|
## self.points = self.w.sample_box.convex_hull.points |
|
341 |
|
## dd, ii = tree.query(self.points, k=1, p=2) |
|
342 |
|
## |
|
343 |
|
## self.simplices = self.w.sample_box.convex_hull.simplices |
|
344 |
|
## box_facets = ii[self.simplices.flatten()].reshape(-1, 3) |
|
345 |
|
## self.events = self.w.sample_box.get_events(box_facets) |
|
346 |
|
## |
|
347 |
|
## |
|
348 |
|
## nodes_colors = np.empty((self.w.sample_box.nsim, 4)) |
|
349 |
|
## nodes_colors[self.w.sample_box.failsi] = np.array([253, 93, 97, 0])/255 |
|
350 |
|
## nodes_colors[~self.w.sample_box.failsi] = np.array([67, 255, 81, 0])/255 |
|
351 |
|
## |
|
352 |
|
## |
|
353 |
|
## self.vertex_colors = nodes_colors[ii] |
|
354 |
|
|
|
355 |
|
|
350 |
356 |
|
|
351 |
357 |
def plot(self): |
def plot(self): |
352 |
|
try: |
|
353 |
|
if (self.failure_item.checkState() + self.success_item.checkState())\ |
|
354 |
|
and (self.w.space == self.w.sample_box.tri_space): |
|
355 |
|
|
|
356 |
|
if self.nsim != self.w.sample_box.nsim: |
|
|
358 |
|
if (self.failure_item.checkState() + self.success_item.checkState())\ |
|
359 |
|
and (self.w.slider.value() > 3): |
|
360 |
|
try: |
|
361 |
|
if self.nsim != self.w.slider.value(): |
357 |
362 |
self.recalculate() |
self.recalculate() |
358 |
363 |
|
|
359 |
364 |
#face_colors = np.empty((len(self.simplices), 4), dtype=np.int16) |
#face_colors = np.empty((len(self.simplices), 4), dtype=np.int16) |
|
... |
... |
class ConvexHull(gl.GLMeshItem): |
377 |
382 |
drawEdges=True, edgeColor=(1, 1, 0, 1)) |
drawEdges=True, edgeColor=(1, 1, 0, 1)) |
378 |
383 |
|
|
379 |
384 |
self.show() |
self.show() |
380 |
|
else: |
|
381 |
|
self.hide() |
|
382 |
|
except BaseException as e: |
|
383 |
|
msg = "nepovedlo se nám spočítat konvexní obálku " |
|
384 |
|
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
|
385 |
|
print(error_msg) |
|
|
385 |
|
except BaseException as e: |
|
386 |
|
msg = "nepovedlo se nám spočítat konvexní obálku " |
|
387 |
|
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
|
388 |
|
print(error_msg) |
|
389 |
|
else: |
|
390 |
|
self.hide() |
|
391 |
|
|
386 |
392 |
|
|
387 |
393 |
|
|
388 |
|
|
|
|
394 |
|
#č mění se význám, semantika třídy |
|
395 |
|
#č teď to není nástroj pro kontrolu skříňky, ale |
|
396 |
|
#č ale pro zobrazování hezkých obrázků |
|
397 |
|
#č teď se mi to víc hodí do krámu |
389 |
398 |
class Facets(gl.GLMeshItem): |
class Facets(gl.GLMeshItem): |
390 |
399 |
def __init__(self, w): |
def __init__(self, w): |
391 |
400 |
## Mesh item will automatically compute face normals. |
## Mesh item will automatically compute face normals. |
|
... |
... |
class Facets(gl.GLMeshItem): |
397 |
406 |
#č já asi nechcu ani snažit sa něčo zobraziť |
#č já asi nechcu ani snažit sa něčo zobraziť |
398 |
407 |
#č z více dimenzí |
#č z více dimenzí |
399 |
408 |
if self.w.sample_box.nvar == 3: |
if self.w.sample_box.nvar == 3: |
400 |
|
self.w.box_runned.connect(self.plot) |
|
|
409 |
|
self.w.slice_changed.connect(self.plot) |
|
410 |
|
#č slice_changed postačí, zahrnuje i box_runned |
|
411 |
|
#self.w.box_runned.connect(self.plot) |
401 |
412 |
self.w.space_changed.connect(self.plot) |
self.w.space_changed.connect(self.plot) |
402 |
413 |
self.w.redraw_called.connect(self.redraw) |
self.w.redraw_called.connect(self.redraw) |
403 |
414 |
|
|
|
... |
... |
class Facets(gl.GLMeshItem): |
416 |
427 |
|
|
417 |
428 |
|
|
418 |
429 |
def redraw(self): |
def redraw(self): |
419 |
|
try: |
|
420 |
|
self.plot() |
|
421 |
|
self.w.central_widget.addItem(self) |
|
422 |
|
except BaseException as e: |
|
423 |
|
msg = "Redraw failed " |
|
424 |
|
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
|
425 |
|
print(error_msg) |
|
|
430 |
|
self.plot() |
|
431 |
|
self.w.central_widget.addItem(self) |
426 |
432 |
|
|
427 |
433 |
def recalculate(self): |
def recalculate(self): |
428 |
434 |
self.points = self.w.sample_box.tri.points |
self.points = self.w.sample_box.tri.points |
|
... |
... |
class Facets(gl.GLMeshItem): |
480 |
486 |
self.hide() |
self.hide() |
481 |
487 |
|
|
482 |
488 |
except BaseException as e: |
except BaseException as e: |
|
489 |
|
self.hide() |
483 |
490 |
msg = "nepovedlo se nám spočítat stěny " |
msg = "nepovedlo se nám spočítat stěny " |
484 |
491 |
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
485 |
492 |
print(error_msg) |
print(error_msg) |
486 |
493 |
|
|
487 |
494 |
|
|
488 |
|
|
|
|
495 |
|
#č mění se význám, semantika třídy |
|
496 |
|
#č teď to není nástroj pro kontrolu skříňky, ale |
|
497 |
|
#č ale pro zobrazování hezkých obrázků |
|
498 |
|
#č teď se mi to víc hodí do krámu |
489 |
499 |
class Wireframe(gl.GLMeshItem): |
class Wireframe(gl.GLMeshItem): |
490 |
500 |
def __init__(self, w): |
def __init__(self, w): |
491 |
501 |
super().__init__(smooth=False, drawFaces=False, drawEdges=True) |
super().__init__(smooth=False, drawFaces=False, drawEdges=True) |
|
... |
... |
class Wireframe(gl.GLMeshItem): |
495 |
505 |
#č já asi nechcu ani snažit sa něčo zobraziť |
#č já asi nechcu ani snažit sa něčo zobraziť |
496 |
506 |
#č z více dimenzí |
#č z více dimenzí |
497 |
507 |
if self.w.sample_box.nvar == 3: |
if self.w.sample_box.nvar == 3: |
498 |
|
self.w.box_runned.connect(self.plot) |
|
|
508 |
|
self.w.slice_changed.connect(self.plot) |
|
509 |
|
#č slice_changed postačí, zahrnuje i box_runned |
|
510 |
|
#self.w.box_runned.connect(self.plot) |
499 |
511 |
self.w.space_changed.connect(self.plot) |
self.w.space_changed.connect(self.plot) |
500 |
512 |
self.w.redraw_called.connect(self.redraw) |
self.w.redraw_called.connect(self.redraw) |
501 |
513 |
|
|
|
... |
... |
class Wireframe(gl.GLMeshItem): |
509 |
521 |
|
|
510 |
522 |
|
|
511 |
523 |
def redraw(self): |
def redraw(self): |
512 |
|
try: |
|
513 |
|
self.plot() |
|
514 |
|
self.w.central_widget.addItem(self) |
|
515 |
|
except BaseException as e: |
|
516 |
|
msg = "Redraw failed " |
|
517 |
|
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
|
518 |
|
print(error_msg) |
|
|
524 |
|
self.plot() |
|
525 |
|
self.w.central_widget.addItem(self) |
519 |
526 |
|
|
520 |
527 |
def recalculate(self): |
def recalculate(self): |
521 |
528 |
self.points = self.w.sample_box.tri.points |
self.points = self.w.sample_box.tri.points |
|
... |
... |
class Wireframe(gl.GLMeshItem): |
543 |
550 |
else: |
else: |
544 |
551 |
self.hide() |
self.hide() |
545 |
552 |
except BaseException as e: |
except BaseException as e: |
|
553 |
|
self.hide() |
546 |
554 |
msg = "nepovedlo se nám spočítat stěny " |
msg = "nepovedlo se nám spočítat stěny " |
547 |
555 |
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
548 |
556 |
print(error_msg) |
print(error_msg) |