Skip to content

flow_display

Alexandre Marcireau edited this page Jun 20, 2018 · 4 revisions

In header "../third_party/chameleon/source/flow_display.hpp"

chameleon::flow_display displays a stream of flow events. It has a transparent background to be rendered over another display.

namespace chameleon {
    class flow_display : public QQuickItem {
        Q_OBJECT
        Q_INTERFACES(QQmlParserStatus)
        Q_PROPERTY(QSize canvas_size READ canvas_size WRITE set_canvas_size)
        Q_PROPERTY(float speed_to_length READ speed_to_length WRITE set_speed_to_length)
        Q_PROPERTY(float decay READ decay WRITE set_decay)
        public:
        flow_display();

        /// set_canvas_size defines the display coordinates.
        /// The canvas size will be passed to the openGL renderer, therefore it should only be set during qml
        /// construction.
        virtual void set_canvas_size(QSize canvas_size);

        /// canvas_size returns the currently used canvas_size.
        virtual QSize canvas_size() const;

        /// set_speed_to_length defines the length in pixels of the arrow representing a one-pixel-per-microsecond
        /// speed. The speed to length will be passed to the openGL renderer, therefore it should only be set
        /// during qml construction.
        virtual void set_speed_to_length(float speed_to_length);

        /// speed_to_length returns the currently used speed_to_length.
        virtual float speed_to_length() const;

        /// set_decay defines the flow decay.
        /// The decay will be passed to the openGL renderer, therefore it should only be set during qml construction.
        virtual void set_decay(float decay);

        /// decay returns the currently used decay.
        virtual float decay() const;

        /// paint_area returns the paint area in window coordinates.
        virtual QRectF paint_area() const;

        /// push adds an event to the display.
        template <typename Event>
        void push(Event event);

        /// componentComplete is called when all the qml values are bound.
        virtual void componentComplete() override;
        
        signals:

        /// paintAreaChanged notifies a paint area change.
        void paintAreaChanged(QRectF paint_area);

        public slots:

        /// sync adapts the renderer to external changes.
        void sync();

        /// cleanup frees the owned renderer.
        void cleanup();

        /// trigger_draw requests a window refresh.
        void trigger_draw();
    };
}
  • canvas_size is the pixel array size. As an example, if x is in the range [0, 319] and y is in the range [0, 239], canvas_size must be QSize(320, 240).
  • speed_to_length is used to convert the flow event speeds to their representation length. It is expressed in pixels per pixel-per-microsecond.
  • decay is the exponential decay's time constant in microseconds.
  • Event must have at least the properties t, x, y, vx and vy.
  • begin and end are the begin and past-the-end iterators to a range of canvas_size.width() * canvas_size.height() objects with at least the properties t, vx and vy. The object associated with the pixel at coordinates [x, y] must be at the index x + y * canvas_size.width() in the range.
  • paint_area is the rectangle in which the events will actually be drawn. paint_area has the same shape (ratio of width over height) as canvas_size.

chameleon::flow_display is associated with a chameleon::flow_display_renderer to handle OpenGL calls.

namespace chameleon {
    class flow_display_renderer : public QObject, public QOpenGLFunctions_3_3_Core {
        Q_OBJECT
        public:
        flow_display_renderer(QSize canvas_size, float speed_to_length, float decay);

        /// set_rendering_area defines the rendering area.
        virtual void set_rendering_area(QRectF paint_area, int window_height);

        /// push adds an event to the display.
        template <typename Event>
        void push(Event event);

        /// assign sets all the pixels at once.
        template <typename Iterator>
        void assign(Iterator begin, Iterator end);

        public slots:

        /// paint sends commands to the GPU.
        void paint();
    };
}
  • window_height is the total window height (used to convert from Qt coordinates to OpenGL coordinates).

A typical QML instantiation has the following syntax:

FlowDisplay {
    canvas_size: "320x240" // required
    speed_to_length: 1e6 // optional, defaults to 1e6
    decay: 1e5 // optional, defaults to 1e5
    background_color: "#000000" // optional, defaults to "#000000"
}
Clone this wiki locally