ImFusion SDK 4.3
GlPlotView Class Reference

#include <ImFusion/GL/GlPlotView.h>

View for plotting data. More...

+ Inheritance diagram for GlPlotView:

Detailed Description

View for plotting data.

Code examples for using GlPlotView:

//reference and clear existing view
GlPlotView *pv = m_speedView->view();
pv->clear(); //clear all plots
//initialize plot view
//pv->setGrid(false, false, false); //completely hide grid
pv->setGrid(true, true, true); //show grid incl fine grid and scale
pv->setGridSize(6, 6, 6); //set size of the grid (number of subdivisions)
pv->setTitle("Speed"); //set title of the plot view
pv->setLabels("Sample", "Angulation"); //set labels of x- and y-axis
//pv->setAdjustBounds(false); //do not automatically adjust min/max and scale
pv->setAxisEqual(true); //makes both axes of equal scale (does not distort circles e.g.)
//create and plot a diagonal line
//only y-values are passed, x-values are computed automatically
//line is solid with cyan color
//other style examples: "r-+", "g.", "m-", "g-", "b-s"
const int data6size = 20;
int *data6y = new int[data6size];
for (int i = 0; i < data6size; ++i)
data6y[i] = i;
int h6 = pv->addPlot2d(data6size, data6y,"c-");
//create and plot a circle
const int data10size = 360;
double *data10x = new double[data10size];
double *data10y = new double[data10size];
double cx = 40.0; double cy = 20.0; double radius = 15.0;
for (int i = 0; i < data10size; ++i) {
float theta = 2.0f * 3.1415926f * double(i) / double(data10size);
double x = radius * cosf(theta);
double y = radius * sinf(theta);
data10x[i] = cx + x;
data10y[i] = cy + y;
}
int h10 = pv->addPlot2d(data10size, data10x, data10y, "r-", false, false);
//read 3d data from file and show 3d plot
//x- and y-axes are assumed to have the same size
//remark: 2d and 3d plots cannot be mixed in the same GlPlotView!
std::ifstream file("Plot.txt");
int steps = 5;
float* data7X = new float[steps*steps];
float* data7Y = new float[steps*steps];
float* data7Z = new float[steps*steps];
if (file.good()) {
for (int i = 0; i < steps; i++)
for (int j = 0; j < steps; j++)
file >> data7X[i*steps + j] >> data7Y[i*steps + j] >> data7Z[i*steps + j];
file.close();
}
int h7 = pv->addPlot3d(steps, data7X, data7Y, data7Z, "g");
int addPlot3d(int size, const T *x, const T *y, const T *z, const std::string &style="r")
Add a 3d plot to the plot view by passing x, y, z values, does not take ownership of data.
void setGridSize(const int gridSizeX=10, const int gridSizeY=10, const int gridSizeZ=10)
Set the grid size along each axis, i.e. the number of grid lines an axis is split up into.
void setAxisEqual(const bool axisEqual)
Makes x- and y-axis of equal scale (e.g. to avoid distorting circles)
Definition GlPlotView.h:191
int addPlot2d(int size, const T *x, const T *y, const std::string &style="r-", bool fit=false, bool sort=true)
Add a 2d plot to the plot view by passing x and y values, takes ownership of data.
void setGrid(const bool grid, const bool halfGrid=false, const bool showNumbers=true, const bool dataGrid=true)
Set the grid size along each axis, i.e. the number of grid lines an axis is split up into.
void setTitle(const std::string &title)
Set the title of the plot view.
Definition GlPlotView.h:146
void clear()
Clears all plots from the view.
void setLabels(const std::string &lx, const std::string &ly)
Sets the labels of x- and y-axis.
Definition GlPlotView.h:149

Classes

struct  PlotInfo
 Data for a single plot handle. More...
 

Public Types

enum  Coordinate { X , Y , Z }
 Convenience enum for classification of coordinates.
 
enum  SelectionFocusMarkerStyle {
  DEFAULT_STYLE = -1 , DISABLED = 0 , CROSSES , VERTICAL_LINE ,
  NR_STYLES
}
 Configure the appearance of the focus marker.
 
enum  LogarithmicAxes { None = 0 , LogX = 1 , LogY = 2 , LogXY = 3 }
 Options for logarithmic scaling of axes. More...
 
enum  Marker {
  Point , Square , Cross , Triangle ,
  NoMarker
}
 Marker types for 2d plotting.
 
enum  LineStyle { Solid , Dashed , Bar , NoLine }
 Line styles for 2d plotting.
 
- Public Types inherited from GlView
enum  Type { SLICE2D = 0 , SLICE3D = 1 , SPACE3D = 2 , OTHER = 3 }
 Type of the view. More...
 

Public Member Functions

template<typename T>
int addPlot2d (int size, const T *x, const T *y, const std::string &style="r-", bool fit=false, bool sort=true)
 Add a 2d plot to the plot view by passing x and y values, takes ownership of data.
 
template<typename T>
int addPlot2d (int size, const T *y, const std::string &style="r-", bool fit=false, bool sort=true)
 Add a 2d plot to the plot view by just passing y values (array of size size) The corresponding x values are set automatically as the sample indices from 0 to size-1.
 
template<typename T>
int addPlot2d (const std::vector< T > &y, const std::string &style="r-", bool fit=false, bool sort=true)
 Add a 2d plot using y vector, see above for details.
 
template<typename T>
int addPlot2d (const std::vector< T > &x, const std::vector< T > &y, const std::string &style="r-", bool fit=false, bool sort=true)
 Add a 2d plot using x and y vectors, see above for details.
 
int addPlot2d (const Tensor< 1 > *xPtr, const Tensor< 1 > &y, const std::string &style="r-", bool fit=false, bool sort=true)
 Add a 2d plot using x and y rank 1 tensors, see above for details.
 
template<typename T>
void updatePlot2d (int handle, const T *y)
 Updates the existing y values of a 2d plot with the passed y values. Passed y-array has to be of the same size as the existing plot.
 
void addValuePlot2d (int handle, double y)
 Add a single Y data point to an existing plot.
 
void addValuePlot2d (int handle, double x, double y, bool sort=true)
 Add a single X/Y data point to an existing plot.
 
void clearPlot (int handle)
 Clear the data for an existing plot but keep the handle and attributes.
 
int plotCount () const
 Return number of plots.
 
std::string getNextUnusedStyle (bool allowAutoColors=false) const
 Returns the next unused style string using solid line or dashes. If allowAutoColors is set, the "o" (other) color flag may be used.
 
template<typename T>
int addPlot3d (int size, const T *x, const T *y, const T *z, const std::string &style="r")
 Add a 3d plot to the plot view by passing x, y, z values, does not take ownership of data.
 
void removePlot (int handle)
 Removes the plot for the given handle from the view.
 
void clear ()
 Clears all plots from the view.
 
void setTitle (const std::string &title)
 Set the title of the plot view.
 
void setLabels (const std::string &lx, const std::string &ly)
 Sets the labels of x- and y-axis.
 
void setGrid (const bool grid, const bool halfGrid=false, const bool showNumbers=true, const bool dataGrid=true)
 Set the grid size along each axis, i.e. the number of grid lines an axis is split up into.
 
void setGridSize (const int gridSizeX=10, const int gridSizeY=10, const int gridSizeZ=10)
 Set the grid size along each axis, i.e. the number of grid lines an axis is split up into.
 
void setAdjustBounds (const bool rescale)
 Rescales min and max of the plot view to have a better scale at the axes.
 
void setBounds (Coordinate coord, double min, double max)
 Set bounds (min/max values) for selected axis.
 
void resetBounds ()
 Reset bounds.
 
vec4 bounds2D () const
 
vec2 extent2D () const
 
void setBounds2D (const vec4 &bounds)
 
const double * bounds () const
 
void setAxisEqual (const bool axisEqual)
 Makes x- and y-axis of equal scale (e.g. to avoid distorting circles)
 
void setHeatmap (const bool heatMapOn)
 Sets whether the colors are based on a heat map, only in 3d plotting.
 
void setFlatShaded (const bool optFlatShaded)
 Sets flat shading.
 
void setIsolines (const bool iso)
 Sets isolines.
 
void setBarWidth (const unsigned int width)
 Sets histogram bar width.
 
void setXAxisRefersToSelection (bool on)
 In some scenarios, x-data of a 2D plot directly corresponds to the image set data of an algorithm.
 
bool xAxisRefersToSelection () const
 
void updateSelectionFocusMarker (int focus)
 Update the selection focus marker.
 
void setFocusImage (const SharedImageSet &img)
 
void setSelectionFocusMarkerStyle (int style, const std::string &color="w")
 
int selectionFocusMarkerStyle () const
 
void setLogarithmicAxes (LogarithmicAxes logAxes, bool refresh=false)
 Sets options for logarithmic scaling of axes.
 
LogarithmicAxes logAxes () const
 
bool render () override
 Renders the plots on the view. If a LogAxes option is set, invalid coordinates will be skipped.
 
void reset ()
 Reset settings to their default values.
 
std::string title ()
 Get the title of the plot view.
 
Type type () const override
 Return the type of this view.
 
virtual std::string typeName () const
 
bool exportPlotsCsv (const std::string &filename)
 Export plots as CSV file.
 
std::string markerToString (Marker m) const
 Converts a Marker value to the corresponding string, e.g. Cross becomes "+".
 
std::string lineStyleToString (LineStyle l) const
 Convert a LineStyle value to the corresponding string, e.g. Solid becomes "-".
 
std::string colorToString (const vec3 &color) const
 
bool setLineStyle (int handle, LineStyle style)
 
bool setMarkerStyle (int handle, Marker style)
 
bool setColor (int handle, const vec3 &color)
 
std::string styleToString (const PlotInfo &pi) const
 
const std::vector< PlotInfo > & plotData () const
 Read access to all the plot data.
 
bool plotData (int handle, PlotInfo &plot) const
 Fetch copy of PlotInfo with specified handle.
 
bool is3D () const
 Fetch information if plots are 3D or not.
 
bool hasHistogramPlot () const
 Finds out if this GlPlotView contains one or more histograms (i.e. PlotInfos with LineStyle::Bar)
 
void setWhiteBackgroundOverride (bool toWhite)
 Toggle background color between white and global background color.
 
vec2 screenPixelToCoord (const vec2 &pixel) const
 
vec2 coordToScreenPixel (const vec2 &coord) const
 
void setMousePosition (const vec2i &val)
 
void setShowLabelAtCursor (bool v)
 
void setShowAllLabels (bool v)
 
void setPointLabels (int idx, const std::vector< std::string > &labels)
 
bool computeSpectrum (const PlotInfo &plot, std::vector< double > &ampOut, std::vector< double > &freqOut) const
 
- Public Member Functions inherited from GlView
virtual void setMatrix (const mat4 &mat)
 Sets the view matrix (view coordinates to world coordinates).
 
virtual const mat4 & matrix () const
 Returns the current view matrix (view coordinates to world coordinates).
 
virtual void resize (int width, int height)
 Set a new viewport size for this view.
 
virtual const GL::OrderIndependentTransparencyorderIndependentTransparency () const
 Returns the optional OIT manager instance of the view if the feature is supported and enabled.
 
int height () const
 Current viewport height of the view.
 
int width () const
 Current viewport width of the view.
 
void addObject (GlObject *object)
 Add a reference to a GlObject to be drawn by this view.
 
void removeObject (GlObject *object)
 Remove a reference to a GlObject drawn by this view.
 
const std::vector< GlObject * > & objects () const
 Return the set of GlObjects that are drawn by this view.
 
const GL::ViewStatestate () const
 Return the view state that was set during the last render() call.
 

Additional Inherited Members

- Protected Member Functions inherited from GlView
GL::OrderIndependentTransparencysharedOitInstance () const
 Offers support for GlViews sharing GL::OrderIndependentTransparency instances to reduce GPU memory consumption.
 
- Protected Attributes inherited from GlView
std::vector< GlObject * > m_objects
 Other objects to consider during rendering.
 
mat4 m_matrix = mat4::Identity()
 Matrix converting view coordinates to world coords (inverse of a traditional OpenGL view matrix)
 
GL::ViewState m_state
 OpenGL state describing viewport, projection and model-view matrix of last render call.
 
int m_width = 0
 
int m_height = 0
 

Member Enumeration Documentation

◆ LogarithmicAxes

Options for logarithmic scaling of axes.

Warning
Don't change the order since the corresponding QStrings are hardcoded in PlotView::createActions()

Member Function Documentation

◆ addPlot2d() [1/2]

template<typename T>
int addPlot2d ( int size,
const T * x,
const T * y,
const std::string & style = "r-",
bool fit = false,
bool sort = true )

Add a 2d plot to the plot view by passing x and y values, takes ownership of data.

The buffer of both arrays needs to be of size size and hence represents a size x 1 vector. Color, line style and marker of the plot can be defined by supplying the format string style, which is a combination of characters. (colors: r, g, b, c, m, y, k, w; line styles: -=solid, .=dashed, n=none, |=bar; markers: +=cross, *=point, s=square, t=triangle; marker sizes: 1 to 9, default=3) Returns a handle that can be used to remove or update the plot.

◆ addPlot2d() [2/2]

template<typename T>
int addPlot2d ( int size,
const T * y,
const std::string & style = "r-",
bool fit = false,
bool sort = true )

Add a 2d plot to the plot view by just passing y values (array of size size) The corresponding x values are set automatically as the sample indices from 0 to size-1.

Returns a handle that can be used to remove or update the plot.

◆ addPlot3d()

template<typename T>
int addPlot3d ( int size,
const T * x,
const T * y,
const T * z,
const std::string & style = "r" )

Add a 3d plot to the plot view by passing x, y, z values, does not take ownership of data.

The buffer of all three arrays needs to be of size size*size. The format string in style so far only supports colors. Returns a handle that can be used to remove or update the plot. Note that the data points do not have to fall onto an orthonormal grid, which is why the x and y positions for each point have to be given individually. Also note that nonetheless the points are assumed to be on a sorted grid by the rendering code.

◆ setXAxisRefersToSelection()

void setXAxisRefersToSelection ( bool on)
inline

In some scenarios, x-data of a 2D plot directly corresponds to the image set data of an algorithm.

The position of the currently focused image can be marked for better visualization. To this end, the controller that owns the plotview needs to derive from SelectionListener. The listener needs to be added to the image data of the corresponding algorithm (and removed in the destructor). Override the selectionChanged() method to glPlotView->updateSelectionFocusMarker(m_images->focus()); In the Controller::init(), set the flag setXAxisRefersToSelection and an optional marker style.

◆ updateSelectionFocusMarker()

void updateSelectionFocusMarker ( int focus)

Update the selection focus marker.

This should be called from the selectionChanged() method of the controller.

Parameters
focusIndex of the focus image.

◆ setLogarithmicAxes()

void setLogarithmicAxes ( LogarithmicAxes logAxes,
bool refresh = false )

Sets options for logarithmic scaling of axes.

Parameters
refreshPass false if computation of bounds is not necessary (e.g. right after construction of PlotView)

◆ render()

bool render ( )
overridevirtual

Renders the plots on the view. If a LogAxes option is set, invalid coordinates will be skipped.

Implements GlView.

◆ type()

Type type ( ) const
inlineoverridevirtual

Return the type of this view.

Implements GlView.

◆ plotData()

bool plotData ( int handle,
PlotInfo & plot ) const

Fetch copy of PlotInfo with specified handle.

Returns
True if plot with given handle is found. This plot is copied to the plot passed by reference.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close