render_svg.hpp 2.22 KB
Newer Older
1
#ifndef RENDER_SVG
2
#define RENDER_SVG
3 4


Pascal Noisette's avatar
Pascal Noisette committed
5 6 7
#include <iostream>
#include <sstream>
#include <fstream>
8

Pascal Noisette's avatar
Pascal Noisette committed
9 10
#define BUFFER_SIZE 2048 //character number stored before flush the _buffer
#define LEVEL 110        //distance between two containers
Pascal Noisette's avatar
Pascal Noisette committed
11 12
#define MARGIN 10        //distance between two object
#define ARROWSIZE 4      //spike size
13

Pascal Noisette's avatar
Pascal Noisette committed
14
typedef unsigned long Element_count ;
Pascal Noisette's avatar
Pascal Noisette committed
15
typedef unsigned long Element_pos;
Pascal Noisette's avatar
Pascal Noisette committed
16
typedef unsigned char Element_col;
17 18 19 20 21


class Svg{


22
private:
23 24
    std::ostringstream _buffer;
    std::ofstream _svg_file;
Pascal Noisette's avatar
Pascal Noisette committed
25
    inline void print();
Pascal Noisette's avatar
Pascal Noisette committed
26 27 28
    inline void rectangle(unsigned long w, unsigned long h,unsigned long x1,unsigned long y1,  unsigned int r,   unsigned int g,   unsigned int b );
    inline void line(unsigned long x1,unsigned long y1,unsigned long x2,unsigned long y2);
    inline void triangle(unsigned long x1,unsigned long y1,unsigned long x2,unsigned long y2, unsigned long x3,unsigned long y3);
29 30
public:
    /*!
31 32
     * \brief SVG header buiding
     */
33
    void init(const char *path);
34

35
    /*!
36 37
     * \brief SVG bottom file buiding
     */
38
    void end();
39 40


41
    /*!
42 43 44 45 46 47
     * \brief Draw a container according to the parameters
     * \param x the x position of the container
     * \param y the y position of the container
     * \param w the width of the container
     * \param h the height of the container
     */
48 49 50 51 52 53 54 55 56 57 58 59
    void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) ;

    /*!
     * \brief Draw a state of the trace.
     * \param r the red color rate of the state.
     * \param g the green color rate of the state.
     * \param b the blue color rate of the state.
     * \param start the beginning time of the state.
     * \param end the ending time of the state.
     * \param level refer to the container which state belongs to.
     */
    void draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b) ;
Pascal Noisette's avatar
Pascal Noisette committed
60 61 62 63 64 65 66

    /*!
    * \brief Draw an arrow
    *
    */
    void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);

67 68 69
};

#endif // RENDER_SVG