// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_sg_plotter #define tools_sg_plotter #include "../lina/vec2f" #include "../axis" #include "render_action" #include "plottable" #include "style" #include "rep" #include "colormap" #include "noderef" #include "line_set" #include "atb_vertices" #include "cube" //for lego #include "matrix" #include "normal" #include "holder" #include "axis" #include "infos_box" #include "legend" #include "text" namespace tools { namespace sg { class plotter : public node { TOOLS_NODE(plotter,tools::sg::plotter,node) private: static const std::string& s_infos_what_def() { static const std::string s_v ("name entries mean rms fit_quality fit_ndf fit_parameters fit_errors"); return s_v; } static float default_infos_margin() {return 0.005f;} //0.005 or Wt public: sf width; //PAW XSIZ sf height; //PAW YSIZ sf left_margin; //PAW XMGL sf right_margin; //PAW XMGR sf bottom_margin; //PAW YMGL sf top_margin; //PAW YMGU sf depth; sf down_margin; sf up_margin; sf title_up; sf title_to_axis; sf title_height; sf title_automated; sf_enum title_hjust; sf_string title; //output if title_automated. //sf superposeBins; sf colormap_visible; enum colormap_axis_labeling_type { cells = 0, min_max }; sf_enum colormap_axis_labeling; sf colormap_attached; sf colormap_axis_visible; /* sf wallEnforced; sf gridEnforced; sf primitivesEnforced; sf innerFrameEnforced; */ // Wanted axes parameters. // They are not necessary realized on the sg::axis nodes. sf x_axis_enforced; sf x_axis_automated; sf x_axis_min; sf x_axis_max; sf x_axis_is_log; sf y_axis_enforced; sf y_axis_automated; sf y_axis_min; sf y_axis_max; sf y_axis_is_log; sf z_axis_enforced; sf z_axis_automated; sf z_axis_min; sf z_axis_max; sf z_axis_is_log; sf value_top_margin; sf infos_width; //in percent of width. sf infos_x_margin; //in percent of width. From right. sf infos_y_margin; //in percent of height. From top. sf_string infos_what; //sf inner_frame_visible; //sf grid_visible; /* sf topAxisVisible; sf rightAxisVisible; // For contours : SoSFInt32 numberOfLevels; SoMFFloat levels; sf frozen; sf ttfScale; */ sf func2D_borders_visible; // used with shape xyz sf theta; //in degrees. sf phi; //in degrees. //legend related : sf legends_visible; sf legends_attached_to_infos; //if legends_attached_to_infos is false : // legends_origin is used to place the legends. It is then // the lower left corner of the box containing all legends. sf_vec legends_origin; //common origin of legend boxes. enum unit_type { unit_percent, unit_axis }; sf_enum legends_origin_unit; sf_vec legends_size; //overall legend boxes size. sf legends_automated; mf_string legends_string; mf_vec legends_color; //sf legends_font; //sf legends_encoding; sf shape_automated; enum shape_type { xy = 0, xyz }; sf_enum shape; /* SoSFEnum shape; //Output if shapeAutomated == true. SoMFString infos; //Output SoMFString legend; //Output SoSFInt32 numberOfPlottedObject; //Output SoSFInt32 numberOfPlottedBins1D; //Output SoSFInt32 numberOfPlottedBins2D; //Output SoSFInt32 numberOfPlottedPoints2D; //Output SoSFInt32 numberOfPlottedPoints3D; //Output SoSFInt32 numberOfPlottedFunction1D; //Output SoSFInt32 numberOfPlottedFunction2D; //Output SoMFString plottedObjectNames; //Output */ // used with xy shape : sf xy_depth; //all is in z [0,xy_depth] public: virtual const std::vector& node_fields() const { TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::plotter) static std::vector s_v; if(s_v.empty()) { s_v = parent::node_fields(); TOOLS_ADD_FIELD_DESC(width) TOOLS_ADD_FIELD_DESC(height) TOOLS_ADD_FIELD_DESC(left_margin) TOOLS_ADD_FIELD_DESC(right_margin) TOOLS_ADD_FIELD_DESC(bottom_margin) TOOLS_ADD_FIELD_DESC(top_margin) TOOLS_ADD_FIELD_DESC(depth) TOOLS_ADD_FIELD_DESC(down_margin) TOOLS_ADD_FIELD_DESC(up_margin) TOOLS_ADD_FIELD_DESC(title_up); TOOLS_ADD_FIELD_DESC(title_to_axis); TOOLS_ADD_FIELD_DESC(title_height); TOOLS_ADD_FIELD_DESC(title_automated); TOOLS_ADD_FIELD_DESC(title_hjust); TOOLS_ADD_FIELD_DESC(title) TOOLS_ADD_FIELD_DESC(x_axis_enforced) TOOLS_ADD_FIELD_DESC(x_axis_automated) TOOLS_ADD_FIELD_DESC(x_axis_min) TOOLS_ADD_FIELD_DESC(x_axis_max) TOOLS_ADD_FIELD_DESC(x_axis_is_log) TOOLS_ADD_FIELD_DESC(y_axis_enforced) TOOLS_ADD_FIELD_DESC(y_axis_automated) TOOLS_ADD_FIELD_DESC(y_axis_min) TOOLS_ADD_FIELD_DESC(y_axis_max) TOOLS_ADD_FIELD_DESC(y_axis_is_log) TOOLS_ADD_FIELD_DESC(z_axis_enforced) TOOLS_ADD_FIELD_DESC(z_axis_automated) TOOLS_ADD_FIELD_DESC(z_axis_min) TOOLS_ADD_FIELD_DESC(z_axis_max) TOOLS_ADD_FIELD_DESC(z_axis_is_log) TOOLS_ADD_FIELD_DESC(value_top_margin) TOOLS_ADD_FIELD_DESC(infos_width) TOOLS_ADD_FIELD_DESC(infos_x_margin) TOOLS_ADD_FIELD_DESC(infos_y_margin) TOOLS_ADD_FIELD_DESC(infos_what) TOOLS_ADD_FIELD_DESC(func2D_borders_visible) TOOLS_ADD_FIELD_DESC(theta) TOOLS_ADD_FIELD_DESC(phi) TOOLS_ADD_FIELD_DESC(legends_visible) TOOLS_ADD_FIELD_DESC(legends_attached_to_infos) TOOLS_ADD_FIELD_DESC(legends_origin) TOOLS_ADD_FIELD_DESC(legends_origin_unit) TOOLS_ADD_FIELD_DESC(legends_size) TOOLS_ADD_FIELD_DESC(legends_automated) TOOLS_ADD_FIELD_DESC(legends_string) TOOLS_ADD_FIELD_DESC(legends_color) TOOLS_ADD_FIELD_DESC(shape_automated) TOOLS_ADD_FIELD_DESC(shape) TOOLS_ADD_FIELD_DESC(xy_depth) } return s_v; } private: void add_fields(){ // if adding a field, look for reset_style() and set_from_style() add_field(&width); add_field(&height); add_field(&left_margin); add_field(&right_margin); add_field(&bottom_margin); add_field(&top_margin); add_field(&depth); add_field(&down_margin); add_field(&up_margin); add_field(&title_up); add_field(&title_to_axis); add_field(&title_height); add_field(&title_automated); add_field(&title_hjust); add_field(&title); add_field(&x_axis_enforced); add_field(&x_axis_automated); add_field(&x_axis_min); add_field(&x_axis_max); add_field(&x_axis_is_log); add_field(&y_axis_enforced); add_field(&y_axis_automated); add_field(&y_axis_min); add_field(&y_axis_max); add_field(&y_axis_is_log); add_field(&z_axis_enforced); add_field(&z_axis_automated); add_field(&z_axis_min); add_field(&z_axis_max); add_field(&z_axis_is_log); add_field(&value_top_margin); add_field(&infos_width); add_field(&infos_x_margin); add_field(&infos_y_margin); add_field(&infos_what); add_field(&func2D_borders_visible); add_field(&theta); add_field(&phi); add_field(&legends_visible); add_field(&legends_attached_to_infos); add_field(&legends_origin); add_field(&legends_origin_unit); add_field(&legends_size); add_field(&legends_automated); add_field(&legends_string); add_field(&legends_color); add_field(&shape_automated); add_field(&shape); add_field(&xy_depth); } public: //style void reset_style(bool a_geom = false) { //reset fields that are considered as part of the style. //////////////////////////////////////////// // we do not touch : //////////////////////////////////////////// // not part of the style ??? //legends_string //legends_color shape_automated = true; shape = xy; xy_depth = 0.01f; //////////////////////////////////////////// // CERN-PAW seems to have 0.1F and CERN-ROOT 0.05F. value_top_margin = 0.1f; //percent. infos_what = s_infos_what_def(); infos_width = 0.3f; //infos height is automatic. infos_x_margin = default_infos_margin(); //percent of width infos_y_margin = default_infos_margin(); //percent of height legends_visible = false; legends_attached_to_infos = true; // if legends_attached_to_infos is false and // unit_percent, legends_origin is the position // of the upper right corner of the legends // relative to the upper right corner of the plotter // with positive values going in reverse x,y axis. legends_origin.value().set_value(0.01f,0.01f); legends_origin_unit = unit_percent; legends_size.value().set_value(0.2f,0.16f); legends_automated = true; //////////////////////////////////////////// if(a_geom) { float xfac = 1.0F/20.0F; //0.05 float yfac = 1.0F/20.0F; //0.05 // Take PAW defaults : float XSIZ = 20 * xfac; //1 //page width float YSIZ = 20 * yfac; //1 //page height float XMGL = 2 * xfac; //0.1 //left x margin (to data frame). float XMGR = 2 * xfac; //0.1 //right y margin (to data frame). float YMGL = 2 * yfac; //0.1 //low y margin (to data frame). float YMGU = 2 * yfac; //0.1 //up y margin (to data frame). // Axes : float VSIZ = 0.28F * yfac; //0.014 //tick label character size. float XVAL = 0.4F * xfac; //0.02 //x distance of y tick label to data frame. float YVAL = 0.4F * yfac; //0.02 //y distance of x tick label to data frame. float XTIC = 0.3F * yfac; //0.015 //y length of X axis ticks. float YTIC = 0.3F * xfac; //0.015 //x length of Y axis ticks. float XLAB = 1.4F * xfac; //0.07 //x distance of y title to data frame. float YLAB = 0.8F * yfac; //0.04 //y distance of x title to data frame. float ASIZ = 0.28F * yfac; //0.014 // axis title (label) character size. float YHTI = 1.2F * yfac; //0.06 //y distance of title to x axis. float TSIZ = 0.28F * yfac; //0.014 //title character size float zfac = 1.0F/20.0F; //0.05 float ZSIZ = 20 * zfac; //1 //page depth float ZMGD = 2 * zfac; //0.1 //low y margin (to data frame). float ZMGU = 2 * zfac; //0.1 //up y margin (to data frame). // Data area : //float wData = XSIZ-XMGL-XMGR; //float hData = YSIZ-YMGL-YMGU; //float dData = ZSIZ-ZMGD-ZMGU; width = XSIZ; height = YSIZ; depth = ZSIZ; left_margin = XMGL; right_margin = XMGR; bottom_margin = YMGL; top_margin = YMGU; down_margin = ZMGD; up_margin = ZMGU; title_to_axis = YHTI; title_height = TSIZ; if(shape.value()==xy) { m_x_axis.tick_length.value(XTIC); m_x_axis.label_to_axis.value(YVAL); m_x_axis.label_height.value(VSIZ); m_x_axis.title_to_axis.value(YLAB); m_x_axis.title_height.value(ASIZ); m_y_axis.tick_length.value(YTIC); m_y_axis.label_to_axis.value(XVAL); m_y_axis.label_height.value(VSIZ); m_y_axis.title_to_axis.value(XLAB); m_y_axis.title_height.value(ASIZ); //set anyway z axis : //m_z_axis.tick_length.value(YTIC); //m_z_axis.label_to_axis.value(XVAL); //m_z_axis.label_height.value(VSIZ); //m_z_axis.title_to_axis.value(XLAB); //m_z_axis.title_height.value(ASIZ); m_cmap_axis.tick_length.value(YTIC); m_cmap_axis.label_to_axis.value(XVAL); m_cmap_axis.label_height.value(VSIZ); m_cmap_axis.title_to_axis.value(XLAB); m_cmap_axis.title_height.value(ASIZ); } else { //xyz m_x_axis.tick_length.value(XTIC); m_x_axis.label_to_axis.value(YVAL); m_x_axis.label_height.value(VSIZ); m_x_axis.title_to_axis.value(YLAB); m_x_axis.title_height.value(ASIZ); m_y_axis.tick_length.value(XTIC); m_y_axis.label_to_axis.value(YVAL); m_y_axis.label_height.value(VSIZ); m_y_axis.title_to_axis.value(YLAB); m_y_axis.title_height.value(ASIZ); m_z_axis.tick_length.value(YTIC); m_z_axis.label_to_axis.value(XVAL); m_z_axis.label_height.value(VSIZ); m_z_axis.title_to_axis.value(XLAB); m_z_axis.title_height.value(ASIZ); m_cmap_axis.tick_length.value(XTIC); m_cmap_axis.label_to_axis.value(YVAL); m_cmap_axis.label_height.value(VSIZ); m_cmap_axis.title_to_axis.value(YLAB); m_cmap_axis.title_height.value(ASIZ); } } title_automated = true; title.value().clear(); title_up = true; title_hjust = center; //////////////////////////////////////////// colormap_visible = true; colormap_axis_labeling = cells; colormap_attached = true; colormap_axis_visible = true; //////////////////////////////////////////// x_axis_enforced = false; x_axis_automated = true; x_axis_min = 0; x_axis_max = 1; x_axis_is_log = false; y_axis_enforced = false; y_axis_automated = true; y_axis_min = 0; y_axis_max = 1; y_axis_is_log = false; z_axis_enforced = false; z_axis_automated = true; z_axis_min = 0; z_axis_max = 1; z_axis_is_log = false; m_x_axis.reset_style(); m_y_axis.reset_style(); m_z_axis.reset_style(); //////////////////////////////////////////// // setup styles : //////////////////////////////////////////// m_title_style = text_style(); m_infos_style = text_style(); m_title_box_style = text_style(); m_background_style = style(); m_inner_frame_style = style(); m_grid_style = style(); m_title_style.color = colorf::black(); m_title_style.font = font_hershey(); m_title_style.encoding = encoding_PAW(); m_background_style.back_color = colorf::white(); m_background_style.line_width = 0; //no border m_background_style.color = colorf::black(); //border m_inner_frame_style.color = colorf::black(); m_inner_frame_style.line_pattern = line_solid; m_grid_style.color = colorf::black(); m_grid_style.line_pattern = line_dashed; m_infos_style.font = font_hershey(); m_infos_style.encoding = encoding_PAW(); m_title_box_style.visible = false; m_title_box_style.font = font_hershey(); m_title_box_style.encoding = encoding_PAW(); //m_legend_style = std::vector(); {std::vector