author | Francesco Abbate <francesco.bbt@gmail.com> | 2009年12月13日 17:41:07 +0000 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2009年12月13日 17:41:07 +0000 |
commit | d00328bd46965223c83f3880204943d8e5844034 (patch) | |
tree | 86436dedafa24ce7e628df7467ca063237fd7cc5 /agg-plot/plot.cpp | |
parent | 220963841157dd309b3e26c879ad3bb9ba626580 (diff) | |
download | gsl-shell-d00328bd46965223c83f3880204943d8e5844034.tar.gz |
-rw-r--r-- | agg-plot/plot.cpp | 84 |
diff --git a/agg-plot/plot.cpp b/agg-plot/plot.cpp new file mode 100644 index 00000000..6c908c8c --- /dev/null +++ b/agg-plot/plot.cpp @@ -0,0 +1,84 @@ + +#include "utils.h" +#include "plot.h" + +#include "agg_conv_stroke.h" +#include "agg_conv_dash.h" +#include "agg_conv_contour.h" +#include "agg_vcgen_markers_term.h" +#include "agg_bounding_rect.h" + +void +plot::bounding_box(double *px1, double *py1, double *px2, double *py2) +{ + bool is_set = false; + double& m_x1 = *px1; + double& m_y1 = *py1; + double& m_x2 = *px2; + double& m_y2 = *py2; + + for (unsigned j = 0; j < m_elements.size(); j++) + { + drawable& d = m_elements[j]; + + double x1, y1, x2, y2; + d.vs->bounding_box(&x1, &y1, &x2, &y2); + + if (! is_set) + { + m_x1 = x1; + m_x2 = x2; + m_y1 = y1; + m_y2 = y2; + + is_set = true; + } + else if (x2 > m_x2 || x1 < m_x1 || y2 > m_y2 || y1 < m_y1) + { + m_x1 = min(x1, m_x1); + m_y1 = min(y1, m_y1); + m_x2 = max(x2, m_x2); + m_y2 = max(y2, m_y2); + } + } +} + +void +plot::trans_matrix_update() +{ + if (! m_bbox_updated) + { + double x1, y1, x2, y2; + bounding_box(&x1, &y1, &x2, &y2); + + double fx = x2 - x1, fy = y2 - y1; + m_trans.reset(); + m_trans.scale(1/fx, 1/fy); + m_trans.translate(-x1/fx, -y1/fy); + m_bbox_updated = true; + } +} + +void +plot::draw_elements(canvas &canvas) +{ + agg::trans_affine m = m_trans; + viewport_scale(m); + canvas.scale(m); + + for (unsigned j = 0; j < m_elements.size(); j++) + { + drawable& d = m_elements[j]; + vertex_source& vs = d.get_vertex_source(); + vs.apply_transform(m, 1.0); + canvas.draw(vs, d.color); + } +} + +void +plot::viewport_scale(agg::trans_affine& m) +{ + const double xoffs = 0.09375, yoffs = 0.09375; + static agg::trans_affine rsz(1-2*xoffs, 0.0, 0.0, 1-2*yoffs, xoffs, yoffs); + trans_affine_compose (m, rsz); +} |