Boost logo

Boost-Commit :

From: JakeVoytko_at_[hidden]
Date: 2007-08-08 13:31:23


Author: jakevoytko
Date: 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
New Revision: 38508
URL: http://svn.boost.org/trac/boost/changeset/38508

Log:
Added basic handing for numerical limits and plot window clipping
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 7 +---
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/numeric_limits_handling.hpp | 22 ++++++++++---
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp | 2
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 8 ++--
   sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp | 6 +--
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 33 +++++++++++++++++--
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 65 ++++++++++++++++++++++++++++++++++-----
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 11 +++---
   8 files changed, 116 insertions(+), 38 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -179,11 +179,6 @@
         }
     }
 
- void limit_style( )
- {
-
- }
-
     void _draw_x_axis()
     {
         double y1(0.);
@@ -437,10 +432,12 @@
         if(detail::limit_NaN(_x))
         {
             _x = 0;
+ _transform_x(_x);
         }
         if(detail::limit_NaN(_y))
         {
             _y = 0;
+ _transform_y(_y);
         }
     }
 

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/numeric_limits_handling.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/numeric_limits_handling.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/numeric_limits_handling.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -15,23 +15,35 @@
 namespace svg{
 namespace detail{
 
-bool limit_max(double a)
+inline bool limit_max(double a)
 {
     return (a == std::numeric_limits<double>::max()
          || a == std::numeric_limits<double>::infinity());
 }
 
-bool limit_min(double a)
+inline bool limit_min(double a)
 {
     return (a == std::numeric_limits<double>::min()
         || a == -std::numeric_limits<double>::infinity()
         || a == std::numeric_limits<double>::denorm_min());
 }
 
-bool limit_NaN(double a)
+inline bool limit_NaN(double a)
 {
- return (a == std::numeric_limits<double>::quiet_NaN()
- || a == std::numeric_limits<double>::signaling_NaN());
+ // Ternary operator used to remove warning of performance of casting
+ // int to bool.
+ return _isnan(a) ? true : false;
+}
+
+inline bool is_limit(double a)
+{
+ return limit_max(a) || limit_min(a) || limit_NaN(a);
+}
+
+inline bool pair_is_limit(std::pair<double, double> a)
+{
+ return limit_max(a.first) || limit_min(a.first) || limit_NaN(a.first)
+ || limit_max(a.second) || limit_min(a.second) || limit_NaN(a.second);
 }
 
 }

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_style_detail.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -18,7 +18,7 @@
     PLOT_X_MAJOR_GRID, PLOT_Y_AXIS, PLOT_X_AXIS,
     PLOT_Y_MINOR_TICKS, PLOT_X_MINOR_TICKS, PLOT_Y_MAJOR_TICKS,
     PLOT_X_MAJOR_TICKS, PLOT_PLOT_LABELS, PLOT_Y_LABEL, PLOT_X_LABEL,
- PLOT_PLOT_LINES, PLOT_PLOT_POINTS,
+ PLOT_PLOT_LINES, PLOT_PLOT_POINTS, PLOT_LIMIT_POINTS,
     PLOT_LEGEND_BACKGROUND, PLOT_LEGEND_POINTS, PLOT_LEGEND_TEXT,
     PLOT_TITLE, SVG_PLOT_DOC_CHILDREN};
 

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -57,7 +57,7 @@
 
         if(clip_name.size())
         {
- s_out << " clip-path=\"url(#" << id_name << ")\"";
+ s_out << " clip-path=\"url(#" << clip_name << ")\"";
         }
     }
 
@@ -75,7 +75,7 @@
    void id(const std::string& _id) { id_name = _id; }
    std::string id( ) { return id_name; }
 
- void clip_id(const std::string& _id) { id_name = _id; }
+ void clip_id(const std::string& _id) { clip_name = _id; }
    std::string clip_id() { return clip_name; }
 };
 
@@ -268,11 +268,11 @@
 
     void write(std::ostream& rhs)
     {
- rhs << "<clip-path id=\"" << element_id << "\">" <<std::endl;
+ rhs << "<clipPath id=\"" << element_id << "\">" <<std::endl;
 
         rect.write(rhs);
 
- rhs<<std::endl<<"</clip-path>";
+ rhs<<std::endl<<"</clipPath>";
     }
 };
 

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -156,11 +156,9 @@
         return *(static_cast<path_element*>(&(document[(unsigned int)(document.size()-1)])));
     }
 
- svg& clip_path(const rect_element& _rect, g_element& _g,
- const std::string& _id)
+ svg& clip_path(const rect_element& _rect, const std::string& _id)
     {
- document.push_back(new clip_path_element(_id,_rect));
- _g.clip(_id);
+ clip_paths.push_back(clip_path_element(_id,_rect));
 
         return *this;
     }

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -48,11 +48,9 @@
 namespace boost {
 namespace svg {
 
-
 // -----------------------------------------------------------------
 // Parameter names for plot() function
 // -----------------------------------------------------------------
-
     
 #if defined (BOOST_MSVC)
 # pragma warning(push)
@@ -103,14 +101,39 @@
 struct svg_plot_series
 {
     std::vector<double> series;
+ std::vector<double> series_limits;
+
     std::string title;
     plot_point_style point_style;
     
+
+ // -------------------------------------------------------------
+ // Scan each data point between the iterators that are passed,
+ // sorting them into the correcet std::veector
+ // -------------------------------------------------------------
     template <class T>
     svg_plot_series(T _begin, T _end, const std::string& _title,
                     const plot_point_style& _style):
- series(_begin, _end), title(_title), point_style(_style)
+ title(_title), point_style(_style)
     {
+ double temp;
+
+ for(T i = _begin;
+ i != _end;
+ ++i)
+ {
+ temp = *i;
+
+ if(is_limit(temp))
+ {
+ series_limits.push_back(temp);
+ }
+
+ else
+ {
+ series.push_back(temp);
+ }
+ }
     }
 };
 
@@ -350,9 +373,11 @@
     image.get_g_element(detail::PLOT_X_MAJOR_TICKS)
         .style().stroke_color(black).stroke_width(2);
 
+ image.get_g_element(detail::PLOT_LIMIT_POINTS)
+ .style().stroke_color(lightgray).fill_color(whitesmoke);
+
     image.get_g_element(detail::PLOT_X_MINOR_TICKS)
         .style().stroke_width(1);
-
 }
 
 // -----------------------------------------------------------------

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -27,6 +27,7 @@
 
 #include "svg_style.hpp"
 #include "detail/axis_plot_frame.hpp"
+#include "detail/numeric_limits_handling.hpp"
 #include "svg.hpp"
 
 #if defined (BOOST_MSVC)
@@ -92,6 +93,8 @@
 struct svg_2d_plot_series
 {
     std::multimap<double, double> series;
+ std::multimap<double, double> series_limits;
+
     std::string title;
     plot_point_style point_style;
     plot_line_style line_style;
@@ -102,12 +105,24 @@
                        std::string _title,
                        const plot_point_style& _point,
                        const plot_line_style& _line):
- series(_begin,_end),
                        title(_title),
                        point_style(_point),
                        line_style(_line)
     {
+ for(T i = _begin;
+ i != _end;
+ ++i)
+ {
+ if(detail::pair_is_limit(*i))
+ {
+ series_limits.insert(*i);
+ }
 
+ else
+ {
+ series.insert(*i);
+ }
+ }
     }
 };
 
@@ -320,11 +335,11 @@
         path_element& major_grid_path =
             image.get_g_element(detail::PLOT_Y_MAJOR_GRID).path();
 
- if(show_y_axis_lines)
- {
- image.get_g_element(detail::PLOT_Y_AXIS).
- line(plot_y1, x_axis, plot_x2, x_axis);
- }
+ //if(show_y_axis_lines)
+ //{
+ //image.get_g_element(detail::PLOT_Y_AXIS).
+ // line(plot_y1, x_axis, plot_x2, x_axis);
+ //}
 
         // y_minor_jump is the interval between minor ticks.
         double y_minor_jump = y_major/((double)(y_num_minor + 1.) );
@@ -456,6 +471,8 @@
         g_element& g_ptr = image.get_g_element(detail::PLOT_PLOT_LINES)
                                 .add_g_element();
 
+ g_ptr.clip_id(plot_window_clip);
+
         g_ptr.style().stroke_color(series.line_style.color);
         path_element& path = g_ptr.path();
 
@@ -522,6 +539,8 @@
 
         g_element& g_ptr = image.get_g_element(detail::PLOT_PLOT_LINES).add_g_element();
 
+ g_ptr.clip_id(plot_window_clip);
+
         g_ptr.style().stroke_color(series.line_style.color);
 
         path_element& path = g_ptr.path();
@@ -603,7 +622,7 @@
     {
         _clear_all();
 
- // draw background
+ // Draw background.
         image.get_g_element(detail::PLOT_BACKGROUND).push_back(
                      new rect_element(0, 0, image.get_x_size(),
                      image.get_y_size()));
@@ -612,6 +631,14 @@
         _calculate_plot_window();
         _calculate_transform();
 
+ // Define the clip path for the plot window.
+ // We don't want to allow overlap of the plot window lines, thus the
+ // minor adjustments.
+
+ image.clip_path(rect_element(plot_x1 + 1, plot_y1 + 1,
+ plot_x2 - plot_x1 - 2, plot_y2 - plot_y1 - 2),
+ plot_window_clip);
+
         if(use_axis)
         {
             _draw_y_axis();
@@ -628,11 +655,11 @@
             _draw_x_label();
         }
 
- // draw lines
+ // Draw lines between non-limit points
 
         _draw_plot_lines();
 
- // draw points
+ // Draw non-limit points.
         double x(0.), y(0.);
         for(unsigned int i=0; i<series.size(); ++i)
         {
@@ -657,6 +684,23 @@
                 }
             }
         }
+
+ // Draw limit points.
+ for(unsigned int i=0; i<series.size(); ++i)
+ {
+ g_element& g_ptr = image.get_g_element(detail::PLOT_LIMIT_POINTS);
+
+ for(std::multimap<double,double>::const_iterator j = series[i].series_limits.begin();
+ j!=series[i].series_limits.end(); ++j)
+ {
+ x = j->first;
+ y = j->second;
+
+ _transform_point(x, y);
+
+ _draw_plot_point(x, y, g_ptr, plot_point_style(blank, blank, 10, circle));
+ }
+ }
     }
 
 public:
@@ -693,6 +737,9 @@
     image.get_g_element(detail::PLOT_BACKGROUND)
         .style().fill_color(white);
 
+ image.get_g_element(detail::PLOT_LIMIT_POINTS)
+ .style().stroke_color(lightgray).fill_color(whitesmoke);
+
     image.get_g_element(detail::PLOT_Y_AXIS)
         .style().stroke_color(black);
 

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp 2007-08-08 13:31:18 EDT (Wed, 08 Aug 2007)
@@ -4,7 +4,6 @@
 #include <vector>
 #include <cmath>
 #include <map>
-#include <iostream>
 #include <limits>
 
 using std::multimap;
@@ -25,7 +24,6 @@
     return tan(x);
 }
 
-
 class dConvert
 {
 public:
@@ -37,8 +35,6 @@
     }
 };
 
-using namespace std;
-
 int main()
 {
     using namespace boost::svg;
@@ -50,13 +46,16 @@
     svg_1d_plot my_1d_plot;
 
     double pi = 3.1415926535;
-
+
+ data2[.5] = std::numeric_limits<double>::max();
+ data2[1.3] = std::numeric_limits<double>::infinity();
+ data2[2] = std::numeric_limits<double>::quiet_NaN();
+
     for(double i=0; i<10; i+=pi/8.)
     {
         data2[i] = g(i);
     }
 
- cout<<"Done with first part"<<endl;
     // size/scale settings
     my_2d_plot.image_size(500, 350);
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk