Plotting with exlib

The best is to start with an example of how to plot an inlib histogram with exlib. For that reconstruct the plotter_X11 example with :

    cd <path to exlib>
    cd examples/cpp
    ./build plotter_X11.cpp
    cp ../../data/arialbd.ttf .
    Linux> ./bin_gnu/plotter_X11
 and on Windows :
    <install VisualC++>
    <install a minimum of cygwin to have a bash shell>
    DOS> <setup VisualC++>
    DOS> cygwin
 and then proceed as if on a UNIX :
    cd <path to exlib>
    cd examples/cpp
    ./build plotter_Windows.cpp
    cp ../../data/arialbd.ttf .
    ./bin_visual/plotter_Windows.exe

you should see :

exlib_exa_plotter_X11.png

Contrary to an inlib example, here the build script is rather mendatory since you have to pass all the "-I" and "-L" flags in order to use some external packages. The build script uses the bush package where access to the externals is done with the "bush/use/&lt;external&gt;" scripts. For plotter_X11, the build script uses :

    bush/use/freetype
    bush/use/GL
    bush/use/GLX
    bush/use/X11
    bush/use/gl2ps

If having problem to compile one of the example because of "something not found" for a given external package, check/change the flags found in the related use script.

You can have a look to plotter_X11.cpp and see that the code is rather simple and easy to customize...

// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file exlib.license for terms.

//exlib_build_use exlib inlib freetype inlib_glutess gl2ps GL GLX X11

#define EXLIB_SCREEN_MGR X11

#include <exlib/X11/plotter>

#include "plotter_common.icc"

#ifndef __CLING__
int main(int argc,char** argv) {return plotter_X11(argc,argv);}
//int main(int argc,char** argv) {return plotter_EXLIB_SCREEN_MGR(argc,argv);}
#endif
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file exlib.license for terms.

#include <inlib/mem>
#include <inlib/random>

#include <inlib/sg/zb_action>
#include <inlib/wps>

#include <exlib/sg/gl2ps_action>

#include <iostream>
#include <cstdlib>

#define CONC_1(a__a,a__b) a__a##_##a__b
#define CONC_2(x,y)  CONC_1(x,y)
#define MAIN_COMMON CONC_2(plotter,EXLIB_SCREEN_MGR)

int MAIN_COMMON(int,char**) {

#ifdef INLIB_MEM
  inlib::mem::set_check_by_class(true);{
#endif

  //////////////////////////////////////////////////////////
  /// create and fill histogram : //////////////////////////
  //////////////////////////////////////////////////////////
  inlib::histo::h1d h("Random Gauss",100,-5,5);
  inlib::random::gauss rg(0,1);
  for(unsigned int index=0;index<10000;index++) h.fill(rg.shoot(),1);

  //////////////////////////////////////////////////////////
  /// managers related to scene graphs : ///////////////////
  //////////////////////////////////////////////////////////
  inlib::sg::zb_manager zb_mgr;
  exlib::sg::gl2ps_manager gl2ps_mgr;
  
  //////////////////////////////////////////////////////////
  /// plotting : ///////////////////////////////////////////
  //////////////////////////////////////////////////////////
  exlib::EXLIB_SCREEN_MGR::session smgr(std::cout);
  if(!smgr.is_valid()) return EXIT_FAILURE;

  exlib::EXLIB_SCREEN_MGR::plotter plotter(smgr,1,1,0,0,700,500);
  if(!plotter.window()) return EXIT_FAILURE;

  inlib::env_append_path("EXLIB_FONT_PATH",".");    

  inlib::sg::plotter& sgp = plotter.plots().current_plotter();
  sgp.bins_style(0).color = inlib::colorf_blue();
//sgp.bins_style(0).line_width = 3;

  sgp.infos_style().font = inlib::sg::font_arialbd_ttf();
  sgp.infos_style().front_face = inlib::sg::winding_cw;
  sgp.infos_x_margin = 0.01f; //percent of plotter width.
  sgp.infos_y_margin = 0.01f; //percent of plotter height.

  plotter.plot(h);

  plotter.plots().view_border = false;

 {inlib::sg::zb_action action(zb_mgr,std::cout,plotter.width(),plotter.height());
  inlib::colorf clear_color = inlib::colorf_white();
  action.zbuffer().clear_color_buffer(0);
  action.add_color(clear_color.r(),clear_color.g(),clear_color.b());
  action.zbuffer().clear_depth_buffer();
  plotter.sg().render(action);
  inlib::wps wps(std::cout);
  if(!wps.open_file("out_zb.ps")) {
    std::cout << "can't open out_zb.ps." << std::endl;
    return EXIT_FAILURE;
  }
  wps.PS_BEGIN_PAGE();
  wps.PS_PAGE_SCALE(float(plotter.width()),float(plotter.height()));
  wps.PS_IMAGE(plotter.width(),plotter.height(),inlib::wps::rgb_4,inlib::sg::zb_action::get_rgb,&action);
  wps.PS_END_PAGE();
  wps.close_file();}

 {exlib::sg::gl2ps_action action(gl2ps_mgr,std::cout,plotter.width(),plotter.height());
  action.open("out_gl2ps.ps");
  plotter.sg().render(action);
  action.close();}

  plotter.show();

  smgr.steer();

#ifdef INLIB_MEM
  }inlib::mem::balance(std::cout);
#endif

  return EXIT_SUCCESS;
}

Moods

Note that in order to build this program, it had not been needed to build and install some rather (complicated) "graphics / plotting / analysis / interpreter" package. All the externals are some quite standards ones (X11, OpenGL) that are probably already installed on your machine and, if not, can be easily installed by using some installer tool coming with your machine (apt-get or yum on a Linux, MacPorts on a Mac, etc...)