Quickstart Visualization

Visualization implies to have a GUI, which will help to display many things: graphs, text, 3D representations, … This software provides a clean interface to PyQt. PyQt works that way:

  • A QMainWindow that includes layouts, (ex: horizontal, vertical, grid, …)
  • Layouts can include widgets.
  • Widgets can be anything: buttons, menu, opengl 3D representation, graphs, … Several high-level widgets are proposed, check optimeed.visualize.widgets .

Simple gui using OpenGL:

"""
OpenGL is a classic for 3D visualization, but can be tedious to setup.
Optimeed already provides several codes for easier interfacing. Here's how.
"""

# We already know these imports ...
from optimeed.core import ListDataStruct
from optimeed.core import LinkDataGraph, HowToPlotGraph
from optimeed.visualize import Widget_graphsVisual, MainWindow

# Now for the openGL imports:
from optimeed.visualize.widgets import Widget_openGL  # And we put all of that inside a widget
from optimeed.visualize.openGL import DeviceDrawerInterface, Bronze_material
from optimeed.visualize.openGL.openGL_library import glPushMatrix, draw_simple_rectangle, glPopMatrix, glTranslate
from optimeed.visualize.onclick import Onclick_animate, Animate_openGL  # And we put the widget inside an action


class MyDevice:
    def __init__(self, length, height):
        self.length = length
        self.height = height
        self.surface = self.length * self.height


# The drawer class
class DeviceDrawer(DeviceDrawerInterface):
    """Drawer of the device"""
    def __init__(self):
        self.theDevice = None

    def draw(self, theDevice):
        glPushMatrix()  # Remove the previous matrices transformations
        glTranslate(-5, -5, 0)
        Bronze_material.activateMaterialProperties()  # Change colour aspect of the material, here it will look like bronze
        draw_simple_rectangle(theDevice.length, theDevice.height)  # Thats the interesting line
        glPopMatrix()  # Push back previous matrices transformations

    def get_init_camera(self, theDevice):
        tipAngle = 0
        viewAngle = 0
        zoomLevel = 0.1
        return tipAngle, viewAngle, zoomLevel


# From now on, that's the same as before
theDataStruct = ListDataStruct()
for xi in range(10):
    for yi in range(10):
        theDataStruct.add_data(MyDevice(xi, yi))

theDataLink = LinkDataGraph()
_ = theDataLink.add_collection(theDataStruct)

howToPlot = HowToPlotGraph('length', 'surface', {'x_label': "length [m]", 'y_label': "surface [m^2]", 'is_scattered': True})
theDataLink.add_graph(howToPlot)
theGraphs = theDataLink.get_graphs()

theActionsOnClick = list()

# That's where the fun begins
openGlDrawing = Widget_openGL()  # First we define the widget
openGlDrawing.set_deviceDrawer(DeviceDrawer())  # We set the drawer to the widget
theActionsOnClick.append(Onclick_animate(theDataLink, Animate_openGL(openGlDrawing)))  # And we create an action out of it

# Same as before
myWidgetGraphsVisuals = Widget_graphsVisual(theGraphs, actionsOnClick=theActionsOnClick, highlight_last=True, refresh_time=-1)  # The widget to display the graphs
myWindow = MainWindow([myWidgetGraphsVisuals])  # A Window (that will contain the widget)
myWindow.run(True)

# Now click on a point.
# Click on "show all"
# Watch the graph and animation together