Skip to content

dvs_display

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

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

chameleon::dvs_display displays a stream of DVS events.

namespace chameleon {
    class dvs_display : public QQuickItem {
        Q_OBJECT
        Q_INTERFACES(QQmlParserStatus)
        Q_PROPERTY(QSize canvas_size READ canvas_size WRITE set_canvas_size)
        Q_PROPERTY(float decay READ decay WRITE set_decay)
        Q_PROPERTY(QColor increase_color READ increase_color WRITE set_increase_color)
        Q_PROPERTY(QColor idle_color READ idle_color WRITE set_idle_color)
        Q_PROPERTY(QColor decrease_color READ decrease_color WRITE set_decrease_color)
        Q_PROPERTY(QColor background_color READ background_color WRITE set_background_color)
        Q_PROPERTY(QRectF paint_area READ paint_area)
        public:
        dvs_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_decay defines the pixel 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;

        /// set_increase_color defines the color used to represent increasing light.
        /// The increase color will be passed to the openGL renderer, therefore it should only be set during qml
        /// construction.
        virtual void set_increase_color(QColor increase_color);

        /// increase_color returns the currently used increase_color.
        virtual QColor increase_color() const;

        /// set_idle_color defines the color used to represent idle pixels.
        /// The idle color will be passed to the openGL renderer, therefore it should only be set during qml
        /// construction.
        virtual void set_idle_color(QColor idle_color);

        /// idle_color returns the currently used idle_color.
        virtual QColor idle_color() const;

        /// set_decrease_color defines the color used to represent decreasing light.
        /// The decrease color will be passed to the openGL renderer, therefore it should only be set during qml
        /// construction.
        virtual void set_decrease_color(QColor decrease_color);

        /// decrease_color returns the currently used decrease_color.
        virtual QColor decrease_color() const;

        /// set_background_color defines the background color used to compensate the parent's shape.
        /// The background color will be passed to the openGL renderer, therefore it should only be set during qml
        /// construction.
        virtual void set_background_color(QColor background_color);

        /// background_color returns the currently used background_color.
        virtual QColor background_color() 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);

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

        /// 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).
  • decay is the exponential decay's time constant in microseconds.
  • increase_color is the color used to represent increasing light. An exponential decay is used as weight to linearly combine increase_color and idle_color on pixels where the last event is a light increase.
  • idle_color is the color used to represent idle pixels.
  • decrease_color is the color used to represent decreasing light. An exponential decay is used as weight to linearly combine decrease_color and idle_color on pixels where the last event is a light decrease.
  • background_color is the color used to fill the component's strips used to compensate for the parent shape.
  • Event must have at least the properties t, x, y and is_increase.
  • 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 and is_increase. 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::dvs_display is associated with a chameleon::dvs_display_renderer to handle OpenGL calls.

namespace chameleon {
    class dvs_display_renderer : public QObject, public QOpenGLFunctions_3_3_Core {
        Q_OBJECT
        public:
        dvs_display_renderer(
            QSize canvas_size,
            float decay,
            QColor increase_color,
            QColor idle_color,
            QColor decrease_color,
            QColor background_color);

        /// set_rendering_area defines the rendering area.
        virtual void set_rendering_area(QRectF clear_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();
    };
}
  • clear_area is the rectangle in which the display must be drawn, in screen coordinates.
  • window_height is the total window height (used to convert from Qt coordinates to OpenGL coordinates).

A typical QML instantiation has the following syntax:

DvsDisplay {
    canvas_size: "320x240" // required
    decay: 1e5 // optional, defaults to 1e5
    increase_color: "#ffffff" // optional, defaults to "#ffffff"
    idle_color: "#808080" // optional, defaults to "#808080"
    decrease_color: "#000000" // optional, defaults to "#000000"
    background_color: "#000000" // optional, defaults to "#000000"
}
Clone this wiki locally