LTL  2.0.x
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ltl::Gnuplot Class Reference

Inherits fdostream.

Public Member Functions

 Gnuplot (const std::string cmd="")
 
 ~Gnuplot ()
 
void getMouse (double &mx, double &my, int &mb)
 
template<class T >
Gnuplotsend_iter (T p, const T &last)
 
template<class T >
Gnuplotsend (const ltl::MArray< T, 1 > &A)
 
template<class T1 , class T2 >
Gnuplotsend (const ltl::MArray< T1, 1 > &X, const ltl::MArray< T2, 1 > &Y)
 
template<class T >
Gnuplotsend (const ltl::MArray< T, 2 > &A)
 
template<class T >
GnuplotsendAsImage (const ltl::MArray< T, 2 > &A)
 
void interactive (const string &pname)
 

Protected Member Functions

template<class T >
Gnuplotsend (const T &x)
 
template<class T , int N>
void sendEntry (const ltl::FVector< T, N > &v)
 
template<class T , int N>
void sendEntry (const ltl::FixedVector< T, N > &v)
 
template<class T >
void sendEntry (const T v)
 
template<class T , class U >
void sendEntry (const std::pair< T, U > &v)
 
void allocReader ()
 

Protected Attributes

FILE * pout
 
std::string pty_fn
 
FILE * pty_fh
 
int master_fd
 
int slave_fd
 
bool debug_messages
 

Detailed Description

Gnuplot interface for MArrays and FVectors

Simple interface to call gnuplot and send MArray and FVector objects. An instance of a Gnuplot class encapsulates a pipe into gnuplot's stdin. It exports a stream interface to the user, so that any gnuplot command can be sent via operator<<. For convenience, functions handling the loops over elements and the necessary formatting to plot elements of 1-D MArray against index number, two 1-D MArray against each other, 2-D MArray surfaces, and elements of any stl-iterator compatible container are provided.

The follwing example code should be self-explanatory:

* MArray<float,1> A;
*
* Gnuplot gp; // start a gnuplot session and open pipe
* Gnuplot gp ("gnuplot-cmd"); // alternative command string
*
* // plot elements of A against index number:
* gp << "plot '-' with lines\n";
* gp.send (A);
*
* MArray<float,1> X, Y;
* // add a plot of Y vs. X to previous plot
* gp << "replot '-' with points\n";
* gp.send (X,Y);
*
* MArray<float,2> S;
* // a surface plot of 2-D MArray S
* gp << "splot '-' with lines\n";
* gp.send (S);
*
* std::vector<float> v;
* float *f;
* // plot an iterator range
* gp << "plot '-' with points\n";
* gp.send_iter (v.begin(), v.end());
* gp << "replot '-' with points\n";
* gp.send_iter (f, f+10);
*
* double mx, my;
* int mb;
* gp.getMouse(mx, my, mb);
*

Gnuplot::send() works with MArrays up to dimension 2, FVectors. For stdlib containers use send with any valid iterator range, i.e. send(v.begin(),v.end())

Gnuplot inherits from std::ostream, so any gnuplot commands and data can be sent to Gnuplot via standard streamio operations, operator<<, setprecision(), etc.

Constructor & Destructor Documentation

ltl::Gnuplot::Gnuplot ( const std::string  cmd = "")

Construct with command to launch gnuplot. This will call gnuplot and open a pipe.

ltl::Gnuplot::~Gnuplot ( )

Member Function Documentation

void ltl::Gnuplot::getMouse ( double mx,
double my,
int mb 
)

Wait for mouse event in gnuplot window and return corrdinates and button

template<class T >
Gnuplot & ltl::Gnuplot::send_iter ( p,
const T &  last 
)

Any iterator range

References send().

template<class T >
Gnuplot & ltl::Gnuplot::send ( const ltl::MArray< T, 1 > &  A)

1-Dimensional MArray

1-Dimensional MArray Will be plotted against index number.

References ltl::indexPosInt(), and ltl::MArray< T, N >::shape().

Referenced by send(), and send_iter().

template<class T1 , class T2 >
Gnuplot & ltl::Gnuplot::send ( const ltl::MArray< T1, 1 > &  X,
const ltl::MArray< T2, 1 > &  Y 
)

Plot 2 MArrays against each other

References ltl::MArray< T, N >::maxIndex(), ltl::MArray< T, N >::minIndex(), and send().

template<class T >
Gnuplot & ltl::Gnuplot::send ( const ltl::MArray< T, 2 > &  A)
template<class T >
Gnuplot & ltl::Gnuplot::sendAsImage ( const ltl::MArray< T, 2 > &  A)

2-Dimensional MArray to be used with "plot '-' matrix with image" Note: T could be either a scalar or a blitz::TinyVector.

References ltl::MArray< T, N >::maxIndex(), and ltl::MArray< T, N >::minIndex().

void ltl::Gnuplot::interactive ( const string &  pname)
template<class T >
Gnuplot& ltl::Gnuplot::send ( const T &  x)
inlineprotected

Handles container elements

References sendEntry().

template<class T , int N>
void ltl::Gnuplot::sendEntry ( const ltl::FVector< T, N > &  v)
inlineprotected

Referenced by send(), and sendEntry().

template<class T , int N>
void ltl::Gnuplot::sendEntry ( const ltl::FixedVector< T, N > &  v)
inlineprotected

References sendEntry().

template<class T >
void ltl::Gnuplot::sendEntry ( const T  v)
inlineprotected
template<class T , class U >
void ltl::Gnuplot::sendEntry ( const std::pair< T, U > &  v)
inlineprotected

References sendEntry().

void ltl::Gnuplot::allocReader ( )
protected

Member Data Documentation

FILE* ltl::Gnuplot::pout
protected
std::string ltl::Gnuplot::pty_fn
protected
FILE* ltl::Gnuplot::pty_fh
protected
int ltl::Gnuplot::master_fd
protected
int ltl::Gnuplot::slave_fd
protected
bool ltl::Gnuplot::debug_messages
protected