Commit 999ed2a6 authored by Joachim Pouderoux's avatar Joachim Pouderoux

Introduce box plot and the corresponding chart.

Change-Id: Ic5c728d45d447fac2678401394717d261dd91d48
parent cb83ede3
......@@ -3,6 +3,7 @@ set(Module_SRCS
vtkAxisExtended.cxx
vtkCategoryLegend.cxx
vtkChart.cxx
vtkChartBox.cxx
vtkChartHistogram2D.cxx
vtkChartLegend.cxx
vtkChartMatrix.cxx
......@@ -25,6 +26,7 @@ set(Module_SRCS
vtkPlot3D.cxx
vtkPlotBag.cxx
vtkPlotBar.cxx
vtkPlotBox.cxx
vtkPlotFunctionalBag.cxx
vtkPlotGrid.cxx
vtkPlotHistogram2D.cxx
......
......@@ -14,6 +14,7 @@ vtk_add_test_cxx(
TestBagPlot.cxx
TestBarGraph.cxx
TestBarGraphHorizontal.cxx
TestBoxPlot.cxx
TestCategoryLegend.cxx
TestColorTransferFunction.cxx,-E80
TestChartDouble.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestBoxPlot.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkChartBox.h"
#include "vtkPlotBox.h"
#include "vtkTable.h"
#include "vtkLookupTable.h"
#include "vtkIntArray.h"
#include "vtkFloatArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"
//----------------------------------------------------------------------------
int TestBoxPlot(int , char* [])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 400);
view->GetRenderWindow()->SetMultiSamples(0);
vtkNew<vtkChartBox> chart;
view->GetScene()->AddItem(chart.GetPointer());
// Creates a vtkPlotBox input table
// The vtkPlotBox object will display 4 (arbitrary) box plots
int numParam = 4;
vtkNew<vtkTable> inputBoxPlotTable;
for (int i = 0; i < numParam; i++)
{
char num[3];
sprintf(num, "%d", i);
char name[10];
strcpy(name,"Param ");
strcat(name,num);
vtkNew<vtkIntArray> arrIndex;
arrIndex->SetName(name);
inputBoxPlotTable->AddColumn(arrIndex.GetPointer());
}
inputBoxPlotTable->SetNumberOfRows(5);
for (int i = 0; i < numParam; i++)
{
inputBoxPlotTable->SetValue(0, i, i/2); //Q0
inputBoxPlotTable->SetValue(1, i, 2*i + 2 - i); //Q1
inputBoxPlotTable->SetValue(2, i, 2*i + 4); //Q2
inputBoxPlotTable->SetValue(3, i, 2*i + 7); //Q3
inputBoxPlotTable->SetValue(4, i, 2*i + 8); //Q4
}
vtkNew<vtkLookupTable> lookup;
lookup->SetNumberOfColors(5);
lookup->SetRange(0, 4);
lookup->Build();
chart->GetPlot(0)->SetInputData(inputBoxPlotTable.GetPointer());
chart->SetColumnVisibilityAll(true);
chart->SetShowLegend(true);
double rgb[3] = { 1., 1., 0. };
vtkPlotBox::SafeDownCast(chart->GetPlot(0))->SetColumnColor("Param 1", rgb);
// Render the scene
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->Render();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
......@@ -76,6 +76,7 @@ vtkAxis::vtkAxis()
this->GridVisible = true;
this->LabelsVisible = true;
this->TicksVisible = true;
this->AxisVisible = true;
this->Precision = 2;
this->Notation = vtkAxis::STANDARD_NOTATION;
this->Behavior = vtkAxis::AUTO;
......@@ -295,8 +296,11 @@ bool vtkAxis::Paint(vtkContext2D *painter)
painter->ApplyPen(this->Pen);
// Draw this axis
painter->DrawLine(this->Point1[0], this->Point1[1],
this->Point2[0], this->Point2[1]);
if (this->AxisVisible)
{
painter->DrawLine(this->Point1[0], this->Point1[1],
this->Point2[0], this->Point2[1]);
}
// Draw the axis title if there is one
if (!this->Title.empty())
......
......@@ -277,6 +277,11 @@ public:
vtkSetMacro(TicksVisible, bool);
vtkGetMacro(TicksVisible, bool);
// Description:
// Get/set whether the axis line should be visible.
vtkSetMacro(AxisVisible, bool);
vtkGetMacro(AxisVisible, bool);
// Description:
// Get/set the numerical precision to use, default is 2.
virtual void SetPrecision(int precision);
......@@ -506,6 +511,7 @@ protected:
bool GridVisible; // Whether the grid for the axis should be drawn
bool LabelsVisible; // Should the axis labels be visible
bool TicksVisible; // Should the tick marks be visible.
bool AxisVisible; // Should the axis line be visible.
int Precision; // Numerical precision to use, defaults to 2.
int Notation; // The notation to use (standard, scientific, mixed)
int Behavior; // The behaviour of the axis (auto, fixed, custom).
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkChartBox.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkChartBox - Factory class for drawing box plot charts
//
// .SECTION Description
// This defines the interface for a box plot chart.
#ifndef __vtkChartBox_h
#define __vtkChartBox_h
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkChart.h"
class vtkIdTypeArray;
class vtkPlotBox;
class vtkStdString;
class vtkStringArray;
class vtkTooltipItem;
class VTKCHARTSCORE_EXPORT vtkChartBox : public vtkChart
{
public:
vtkTypeMacro(vtkChartBox, vtkChart);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Creates a parallel coordinates chart
static vtkChartBox* New();
// Description:
// Perform any updates to the item that may be necessary before rendering.
// The scene should take care of calling this on all items before their
// Paint function is invoked.
virtual void Update();
// Description:
// Paint event for the chart, called whenever the chart needs to be drawn
virtual bool Paint(vtkContext2D *painter);
// Description:
// Set the visibility of the specified column.
void SetColumnVisibility(const vtkStdString& name, bool visible);
// Description:
// Set the visibility of all columns (true will make them all visible, false
// will remove all visible columns).
void SetColumnVisibilityAll(bool visible);
// Description:
// Get the visibility of the specified column.
bool GetColumnVisibility(const vtkStdString& name);
// Description:
// Get a list of the columns, and the order in which they are displayed.
vtkGetObjectMacro(VisibleColumns, vtkStringArray);
// Index of the selected column in the visible columns list.
vtkGetMacro(SelectedColumn, int);
vtkSetMacro(SelectedColumn, int);
// Description:
// Get the plot at the specified index, returns null if the index is invalid.
virtual vtkPlot* GetPlot(vtkIdType index);
// Description:
// Get the number of plots the chart contains.
virtual vtkIdType GetNumberOfPlots();
// Description:
// Get the chart Y axis
virtual vtkAxis* GetYAxis();
// Description:
// Get the column X position by index in the visible set.
virtual float GetXPosition(int index);
// Description:
// Get the number of visible box plots in the current chart.
virtual vtkIdType GetNumberOfVisibleColumns();
// Description
// Set plot to use for the chart. Since this type of chart can
// only contain one plot, this will replace the previous plot.
virtual void SetPlot(vtkPlotBox *plot);
//BTX
// Description:
// Return true if the supplied x, y coordinate is inside the item.
virtual bool Hit(const vtkContextMouseEvent &mouse);
// Description:
// Mouse move event.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button down event
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button release event.
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
//ETX
// Description:
// Set the vtkTooltipItem object that will be displayed by the chart.
virtual void SetTooltip(vtkTooltipItem *tooltip);
// Description:
// Get the vtkTooltipItem object that will be displayed by the chart.
virtual vtkTooltipItem* GetTooltip();
// Description:
// Set the information passed to the tooltip.
virtual void SetTooltipInfo(const vtkContextMouseEvent &,
const vtkVector2d &,
vtkIdType, vtkPlot*,
vtkIdType segmentIndex = -1);
//BTX
protected:
vtkChartBox();
~vtkChartBox();
// Description:
// Private storage object - where we hide all of our STL objects...
class Private;
Private *Storage;
bool GeometryValid;
// Description:
// Selected indices for the table the plot is rendering
vtkIdTypeArray *Selection;
// Description:
// A list of the visible columns in the chart.
vtkStringArray *VisibleColumns;
// Description:
// Index of the selected column in the visible columns list.
int SelectedColumn;
// Description:
// The point cache is marked dirty until it has been initialized.
vtkTimeStamp BuildTime;
// Description:
// The tooltip item for the chart - can be used to display extra information.
vtkSmartPointer<vtkTooltipItem> Tooltip;
void ResetSelection();
void UpdateGeometry();
void CalculatePlotTransform();
void SwapAxes(int a1, int a2);
// Description:
// Try to locate a point within the plots to display in a tooltip.
// If invokeEvent is greater than 0, then an event will be invoked if a point
// is at that mouse position.
bool LocatePointInPlots(const vtkContextMouseEvent &mouse,
int invokeEvent = -1);
int LocatePointInPlot(const vtkVector2f &position,
const vtkVector2f &tolerance, vtkVector2f &plotPos,
vtkPlot *plot, vtkIdType &segmentIndex);
private:
vtkChartBox(const vtkChartBox &); // Not implemented.
void operator=(const vtkChartBox &); // Not implemented.
//ETX
};
// Description:
// Small struct used by InvokeEvent to send some information about the point
// that was clicked on. This is an experimental part of the API, subject to
// change.
struct vtkChartBoxData
{
vtkStdString SeriesName;
vtkVector2f Position;
vtkVector2i ScreenPosition;
int Index;
};
#endif //__vtkChartBox_h
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlotBox.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPlotBox - Class for drawing box plots.
//
// .SECTION Description
// Plots to draw box plots given columns from a vtkTable that may contains
// 5 lines with quartiles and median.
#ifndef __vtkPlotBox_h
#define __vtkPlotBox_h
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkPlot.h"
#include "vtkStdString.h" // For vtkStdString ivars
class vtkBrush;
class vtkTextProperty;
class vtkTable;
class vtkStdString;
class vtkScalarsToColors;
class VTKCHARTSCORE_EXPORT vtkPlotBox : public vtkPlot
{
public:
vtkTypeMacro(vtkPlotBox, vtkPlot);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Creates a box plot.
static vtkPlotBox* New();
// Description:
// Perform any updates to the item that may be necessary before rendering.
// The scene should take care of calling this on all items before their
// Paint function is invoked.
virtual void Update();
// Description:
// Paint event for the plot, called whenever the chart needs to be drawn
virtual bool Paint(vtkContext2D *painter);
// Description:
// Paint legend event for the plot, called whenever the legend needs the
// plot items symbol/mark/line drawn. A rect is supplied with the lower left
// corner of the rect (elements 0 and 1) and with width x height (elements 2
// and 3). The plot can choose how to fill the space supplied.
virtual bool PaintLegend(vtkContext2D *painter, const vtkRectf& rect,
int legendIndex);
// Description:
// This is a convenience function to set the input table.
virtual void SetInputData(vtkTable *table);
virtual void SetInputData(vtkTable *table, const vtkStdString&,
const vtkStdString&)
{
this->SetInputData(table);
}
// Description:
// Function to query a plot for the nearest point to the specified coordinate.
// Returns the index of the data series with which the point is associated
// or -1.
virtual vtkIdType GetNearestPoint(const vtkVector2f& point,
const vtkVector2f& tolerance,
vtkVector2f* location);
// Description:
// Specify a lookup table for the mapper to use.
void SetLookupTable(vtkScalarsToColors *lut);
vtkScalarsToColors *GetLookupTable();
// Description:
// Helper function to set the color of a given column.
void SetColumnColor(const vtkStdString& colName, double *rgb);
// Description:
// Create default lookup table. Generally used to create one when none
// is available with the scalar data.
virtual void CreateDefaultLookupTable();
// Description:
// Get/Set the width of boxes.
vtkGetMacro(BoxWidth, float);
vtkSetMacro(BoxWidth, float);
// Description:
// Get the vtkTextProperty that governs how the plot title is displayed.
vtkGetObjectMacro(TitleProperties, vtkTextProperty);
//BTX
protected:
vtkPlotBox();
~vtkPlotBox();
void DrawBoxPlot(int, unsigned char*, double, vtkContext2D*);
// Description:
// Update the table cache.
bool UpdateTableCache(vtkTable *table);
// Description:
// Store a well packed set of XY coordinates for this data series.
class Private;
Private* Storage;
// Description:
// The point cache is marked dirty until it has been initialized.
vtkTimeStamp BuildTime;
// Description:
// Width of boxes.
float BoxWidth;
// Description:
// Lookup Table for coloring points by scalar value
vtkScalarsToColors *LookupTable;
// Description:
// Text properties for the plot title
vtkTextProperty* TitleProperties;
private:
vtkPlotBox(const vtkPlotBox &); // Not implemented.
void operator=(const vtkPlotBox &); // Not implemented.
//ETX
};
#endif //__vtkPlotBox_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment