Commit d031b0ea authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

ENH: Initial import of the work 2D API, 2D scene and charts code.

This is an initial import of the surviving parts of the 2D drawing API I
have been working on, along with a prototype for a 2D scene and some chart
elements. This work is experimental, and parts of the API will be moved into
Rendering.

The API is subject to change and/or removal.
parent 74b9175a
......@@ -269,6 +269,9 @@ VTK_DEPENDENT_OPTION(VTK_USE_CG_SHADERS "Build pixel and vertex shader support f
VTK_DEPENDENT_OPTION(VTK_USE_GLSL_SHADERS "Build pixel and vertex shader support for GLSL." ON
"VTK_USE_RENDERING" OFF)
VTK_DEPENDENT_OPTION(VTK_USE_CHARTS "Build VTK chart support (OpenGL based)" ON
"VTK_USE_RENDERING;VTK_USE_VIEWS" OFF)
SET(VTK_DEFAULT_SHADERS_DIR
"${VTK_BINARY_DIR}/Utilities/MaterialLibrary/Repository"
CACHE INTERNAL
......@@ -366,6 +369,9 @@ IF(VTK_USE_MFC)
SET(VTK_KITS ${VTK_KITS} MFC)
ENDIF(VTK_USE_MFC)
IF(VTK_USE_CHARTS)
SET(VTK_KITS ${VTK_KITS} CHARTS)
ENDIF(VTK_USE_CHARTS)
#-----------------------------------------------------------------------------
# Determine GUI.
......@@ -1150,6 +1156,9 @@ ENDIF(VTK_USE_VIEWS)
IF(VTK_USE_GUISUPPORT)
ADD_SUBDIRECTORY(GUISupport)
ENDIF(VTK_USE_GUISUPPORT)
IF(VTK_USE_CHARTS)
ADD_SUBDIRECTORY(Charts)
ENDIF(VTK_USE_CHARTS)
# Wrapping.
IF(VTK_WRAP_TCL)
......
SET(KIT Charts)
SET(UKIT CHARTS)
SET(KIT_TCL_LIBS vtkHybridTCL vtkViewsTCL ${VTK_TK_LIBRARIES})
SET(KIT_PYTHON_LIBS vtkHybridPythonD vtkViewsPythonD)
SET(KIT_JAVA_LIBS vtkHybridJava vtkViewsJava)
IF (JAVA_AWT_LIBRARY)
SET(KIT_JAVA_LIBS ${KIT_JAVA_LIBS} ${JAVA_AWT_LIBRARY})
ENDIF (JAVA_AWT_LIBRARY)
SET(KIT_INTERFACE_LIBRARIES vtkHybrid vtkViews)
SET(KIT_LIBS vtkIO vtkftgl
${VTK_FREETYPE_LIBRARIES}
)
SET(Kit_SRCS
vtkAxis.cxx
vtkBlockItem.cxx
vtkBrush.cxx
vtkChart.cxx
vtkChartXY.cxx
vtkContext2D.cxx
vtkContextActor.cxx
vtkContextDevice2D.cxx
vtkContextItem.cxx
vtkContextMapper2D.cxx
vtkContextScene.cxx
vtkContextView.cxx
vtkImageItem.cxx
vtkOpenGLContextDevice2D.cxx
vtkPen.cxx
vtkPlot.cxx
vtkPlotGrid.cxx
vtkPlotLine.cxx
vtkPlotPoints.cxx
)
SET_SOURCE_FILES_PROPERTIES(
vtkChart
vtkContextDevice2D
vtkContextItem
vtkContextMapper2D
vtkPlot
ABSTRACT
)
#-----------------------------------------------------------------------------
# Include CMake code common to all kits.
INCLUDE(${VTK_CMAKE_DIR}/KitCommonBlock.cmake)
#-----------------------------------------------------------------------------
#TARGET_LINK_LIBRARIES(vtkCharts ${QT_LIBRARIES})
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAxis.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 "vtkAxis.h"
#include "vtkContext2D.h"
#include "vtkPen.h"
#include "vtkTextProperty.h"
#include "vtkObjectFactory.h"
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkAxis, "1.1");
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkAxis);
//-----------------------------------------------------------------------------
vtkAxis::vtkAxis()
{
this->Point1[0] = 10.0;
this->Point1[1] = 10.0;
this->Point2[0] = 10.0;
this->Point2[1] = 10.0;
this->NumberOfTicks = 6;
this->Minimum = 0.0;
this->Maximum = 6.66;
this->Label = NULL;
}
//-----------------------------------------------------------------------------
vtkAxis::~vtkAxis()
{
this->SetLabel(NULL);
}
//-----------------------------------------------------------------------------
bool vtkAxis::Paint(vtkContext2D *painter)
{
// This is where everything should be drawn, or dispatched to other methods.
vtkDebugMacro(<< "Paint event called in vtkAxis.");
painter->GetPen()->SetWidth(1.0);
// Draw this axis
painter->DrawLine(this->Point1[0], this->Point1[1],
this->Point2[0], this->Point2[1]);
// Draw the axis label
if (this->Point1[0] == this->Point2[0]) // x1 == x2, therefore vertical
{
// Draw the axis label
int x = this->Point1[0] - 45;
int y = (this->Point1[1] + this->Point2[1]) / 2;
vtkTextProperty *prop = painter->GetTextProp();
prop->SetFontSize(15);
prop->SetFontFamilyAsString("Arial");
prop->SetColor(0.0, 0.0, 0.0);
prop->SetOrientation(90.0);
prop->SetJustificationToCentered();
prop->SetVerticalJustificationToBottom();
painter->DrawText(x, y, this->Label);
// Now draw the tick marks
float spacing = (this->Point2[1] - this->Point1[1]) /
float(this->NumberOfTicks - 1);
prop->SetOrientation(0.0);
prop->SetJustificationToRight();
prop->SetVerticalJustificationToCentered();
float labelSpacing = (this->Maximum - this->Minimum) /
float(this->NumberOfTicks -1);
for (int i = 0; i < this->NumberOfTicks; ++i)
{
int yTick = this->Point1[1] + float(i)*spacing;
painter->DrawLine(this->Point1[0] - 5, yTick, this->Point1[0], yTick);
// Draw the tick label
char string[20];
sprintf(string, "%-#6.3g", this->Minimum + i*labelSpacing);
painter->DrawText(this->Point1[0] - 5, yTick, string);
}
}
else // Default to horizontal orientation
{
int x = (this->Point1[0] + this->Point2[0]) / 2;
int y = this->Point1[1] - 30;
vtkTextProperty *prop = painter->GetTextProp();
prop->SetFontSize(15);
prop->SetFontFamilyAsString("Arial");
prop->SetColor(0.0, 0.0, 0.0);
prop->SetJustificationToCentered();
prop->SetVerticalJustificationToTop();
painter->DrawText(x, y, "X Axis");
// Now draw the tick marks
float spacing = (this->Point2[0] - this->Point1[0]) /
float(this->NumberOfTicks - 1);
prop->SetJustificationToCentered();
prop->SetVerticalJustificationToTop();
float labelSpacing = (this->Maximum - this->Minimum) /
float(this->NumberOfTicks -1);
for (int i = 0; i < this->NumberOfTicks; ++i)
{
int xTick = this->Point1[1] + float(i)*spacing;
painter->DrawLine(xTick, this->Point1[1] - 5, xTick, this->Point1[1]);
char string[20];
sprintf(string, "%-#6.3g", this->Minimum + i*labelSpacing);
painter->DrawText(xTick, this->Point1[1] - 5, string);
}
}
}
//-----------------------------------------------------------------------------
void vtkAxis::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Axis label: \"" << *this->Label << "\"" << endl;
os << indent << "Minimum point: " << this->Point1[0] << ", "
<< this->Point1[1] << endl;
os << indent << "Maximum point: " << this->Point2[0] << ", "
<< this->Point2[1] << endl;
os << indent << "Range: " << this->Minimum << " - " << this->Maximum << endl;
os << indent << "Number of tick marks: " << this->NumberOfTicks << endl;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAxis.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 vtkAxis - takes care of drawing 2D axes
//
// .SECTION Description
// The vtkAxis is drawn in screen coordinates. It is usually one of the last
// elements of a chart to be drawn. It renders the axis label, tick marks and
// tick labels.
#ifndef __vtkAxis_h
#define __vtkAxis_h
#include "vtkContextItem.h"
class vtkContext2D;
class VTK_CHARTS_EXPORT vtkAxis : public vtkContextItem
{
public:
vtkTypeRevisionMacro(vtkAxis, vtkContextItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Creates a 2D Chart object.
static vtkAxis *New();
// Description:
// Set point 1 of the axis (in pixels), this is usually the origin.
vtkSetVector2Macro(Point1, float);
// Description:
// Get point 1 of the axis (in pixels), this is usually the origin.
vtkGetVector2Macro(Point1, float);
// Description:
// Set point 2 of the axis (in pixels), this is usually the terminus.
vtkSetVector2Macro(Point2, float);
// Description:
// Get point 2 of the axis (in pixels), this is usually the terminus.
vtkGetVector2Macro(Point2, float);
// Description:
// Set the number of tick marks for this axis.
vtkSetMacro(NumberOfTicks, int);
// Description:
// Get the number of tick marks for this axis.
vtkGetMacro(NumberOfTicks, int);
// Description:
// Set the logical minimum value of the axis, in plot coordinates.
vtkSetMacro(Minimum, float);
// Description:
// Get the logical minimum value of the axis, in plot coordinates.
vtkGetMacro(Minimum, float);
// Description:
// Set the logical maximum value of the axis, in plot coordinates.
vtkSetMacro(Maximum, float);
vtkGetMacro(Maximum, float);
// Description:
// Get/set the label text for the axis, in plot coordinates.
vtkSetStringMacro(Label);
// Description:
// Get/set the label text for the axis, in plot coordinates.
vtkGetStringMacro(Label);
// Description:
// Paint event for the axis, called whenever the axis needs to be drawn.
virtual bool Paint(vtkContext2D *painter);
//BTX
protected:
vtkAxis();
~vtkAxis();
float Point1[2]; // The position of point 1 (usually the origin)
float Point2[2]; // The position of point 2 (usually the terminus)
int NumberOfTicks; // The number of tick marks to draw
float Minimum; // Minimum value of the axis
float Maximum; // Maximum values of the axis
char *Label; // The text label drawn on the axis
private:
vtkAxis(const vtkAxis &); // Not implemented.
void operator=(const vtkAxis &); // Not implemented.
//ETX
};
#endif //__vtkAxis_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBlockItem.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 "vtkBlockItem.h"
// Get my new commands
#include "vtkCommand.h"
#include "vtkContext2D.h"
#include "vtkContextScene.h"
#include "vtkPen.h"
#include "vtkBrush.h"
#include "vtkTextProperty.h"
#include "vtkObjectFactory.h"
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkBlockItem, "1.1");
vtkStandardNewMacro(vtkBlockItem);
//-----------------------------------------------------------------------------
vtkBlockItem::vtkBlockItem()
{
this->Label = NULL;
this->MouseOver = false;
this->MouseButtonPressed = -1;
this->scalarFunction = NULL;
}
//-----------------------------------------------------------------------------
vtkBlockItem::~vtkBlockItem()
{
this->SetLabel(NULL);
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::Paint(vtkContext2D *painter)
{
painter->GetTextProp()->SetVerticalJustificationToCentered();
painter->GetTextProp()->SetJustificationToCentered();
painter->GetTextProp()->SetColor(0.0, 0.0, 0.0);
painter->GetTextProp()->SetFontSize(24);
painter->GetPen()->SetColor(0, 0, 0);
if (this->MouseOver)
{
painter->GetBrush()->SetColor(255, 0, 0);
}
else
{
painter->GetBrush()->SetColor(0, 255, 0);
}
painter->DrawRect(this->Dimensions[0], this->Dimensions[1],
this->Dimensions[2], this->Dimensions[3]);
int x = this->Dimensions[0] + 0.5 * this->Dimensions[2];
int y = this->Dimensions[1] + 0.5 * this->Dimensions[3];
painter->DrawText(x, y, this->Label);
if (this->scalarFunction)
{
// We have a function pointer - do something...
;
}
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::Hit(const vtkContextMouseEvent &mouse)
{
if (mouse.Pos[0] > this->Dimensions[0] &&
mouse.Pos[0] < this->Dimensions[0]+this->Dimensions[2] &&
mouse.Pos[1] > this->Dimensions[1] &&
mouse.Pos[1] < this->Dimensions[1]+this->Dimensions[3])
{
return true;
}
else
{
return false;
}
return false;
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::MouseEnterEvent(const vtkContextMouseEvent &mouse)
{
this->MouseOver = true;
return true;
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::MouseMoveEvent(const vtkContextMouseEvent &mouse)
{
int deltaX = mouse.Pos[0] - this->LastPosition[0];
int deltaY = mouse.Pos[1] - this->LastPosition[1];
this->LastPosition[0] = mouse.Pos[0];
this->LastPosition[1] = mouse.Pos[1];
if (this->MouseButtonPressed == 0)
{
// Move the block by this amount
this->Dimensions[0] += deltaX;
this->Dimensions[1] += deltaY;
return true;
}
else if (this->MouseButtonPressed == 1)
{
// Resize the block by this amount
this->Dimensions[0] += deltaX;
this->Dimensions[1] += deltaY;
this->Dimensions[2] -= deltaX;
this->Dimensions[3] -= deltaY;
return true;
}
else if (this->MouseButtonPressed == 2)
{
// Resize the block by this amount
this->Dimensions[2] += deltaX;
this->Dimensions[3] += deltaY;
return true;
}
return false;
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::MouseLeaveEvent(const vtkContextMouseEvent &mouse)
{
this->MouseOver = false;
return true;
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::MouseButtonPressEvent(const vtkContextMouseEvent &mouse)
{
this->MouseButtonPressed = mouse.Button;
this->LastPosition[0] = mouse.Pos[0];
this->LastPosition[1] = mouse.Pos[1];
return true;
}
//-----------------------------------------------------------------------------
bool vtkBlockItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
{
this->MouseButtonPressed = -1;
return true;
}
void vtkBlockItem::SetScalarFunctor(double (*scalarFunction)(double, double))
{
this->scalarFunction = scalarFunction;
}
//-----------------------------------------------------------------------------
void vtkBlockItem::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBlockItem.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 vtkBlockItem - a vtkContextItem that draws a block (optional label).
//
// .SECTION Description
// This is a vtkContextItem that can be placed into a vtkContextScene. It draws
// a block of the given dimensions, and reacts to mouse events.
#ifndef __vtkBlockItem_h
#define __vtkBlockItem_h
#include "vtkContextItem.h"
class vtkContext2D;
class VTK_CHARTS_EXPORT vtkBlockItem : public vtkContextItem
{
public:
vtkTypeRevisionMacro(vtkBlockItem, vtkObject);
virtual void PrintSelf(ostream &os, vtkIndent indent);
static vtkBlockItem *New();
// Description:
// Paint event for the item.
virtual bool Paint(vtkContext2D *painter);
//BTX
// Description:
// Returns true if the supplied x, y coordinate is inside the item.
virtual bool Hit(const vtkContextMouseEvent &mouse);
// Description:
// Mouse enter event.
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse move event.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse leave event.
virtual bool MouseLeaveEvent(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 block label.
vtkSetStringMacro(Label);
// Description:
// Get the block label.
vtkGetStringMacro(Label);
// Description:
// Set the dimensions of the block, elements 0 and 1 are the x and y coordinate
// of the bottom corner. Elements 2 and 3 are the width and height.
vtkSetVector4Macro(Dimensions, int);
// Description:
// Get the dimensions of the block, elements 0 and 1 are the x and y coordinate
// of the bottom corner. Elements 2 and 3 are the width and height.
vtkGetVector4Macro(Dimensions, int);
//BTX
void SetScalarFunctor(double (*scalarFunction)(double, double));
//ETX
//BTX
protected:
vtkBlockItem();
~vtkBlockItem();
int Dimensions[4];
int LastPosition[2];
char *Label;
bool MouseOver;
int MouseButtonPressed;
// Some function pointers to optionally do funky things...
double (*scalarFunction)(double, double);
private:
vtkBlockItem(const vtkBlockItem &); // Not implemented.
void operator=(const vtkBlockItem &); // Not implemented.
//ETX
};
#endif //__vtkBlockItem_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBrush.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 "vtkBrush.h"
#include "vtkObjectFactory.h"
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkBrush, "1.1");
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkBrush);
//-----------------------------------------------------------------------------
vtkBrush::vtkBrush()
{
this->Color[0] = 0;
this->Color[1] = 0;
this->Color[2] = 0;
this->Color[3] = 255;
}
//-----------------------------------------------------------------------------
vtkBrush::~vtkBrush()
{
}
//-----------------------------------------------------------------------------
void vtkBrush::SetColorF(double color[3])
{
this->Color[0] = color[0] * 255.0;
this->Color[1] = color[1] * 255.0;
this->Color[2] = color[2] * 255.0;
}
//-----------------------------------------------------------------------------
void vtkBrush::SetColorF(double r, double g, double b)
{
this->Color[0] = r * 255.0;
this->Color[1] = g * 255.0;
this->Color[2] = b * 255.0;
}
//-----------------------------------------------------------------------------
void vtkBrush::SetColorF(double r, double g, double b, double a)
{
this->Color[0] = r * 255.0;
this->Color[1] = g * 255.0;
this->Color[2] = b * 255.0;
this->Color[3] = a * 255.0;
}
//-----------------------------------------------------------------------------
void vtkBrush::SetOpacityF(double a)
{
this->Color[3] = a * 255.0;
}
//-----------------------------------------------------------------------------
void vtkBrush::SetColor(unsigned char color[3])
{
this->Color[0] = color[0];
this->Color[1] = color[1];
this->Color[2] = color[2];
}
//-----------------------------------------------------------------------------
void vtkBrush::SetColor(unsigned char r, unsigned char g, unsigned char b)
{
this->Color[0] = r;
this->Color[1] = g;
this->Color[2] = b;
}
//-----------------------------------------------------------------------------
void vtkBrush::SetColor(unsigned char r, unsigned char g, unsigned char b,
unsigned char a)
{
this->Color[0] = r;
this->Color[1] = g;
this->Color[2] = b;
this->Color[3] = a;
}
//-----------------------------------------------------------------------------
void vtkBrush::SetOpacity(unsigned char a)
{
this->Color[3] = a;
}
//-----------------------------------------------------------------------------
void vtkBrush::GetColorF(double color[4])
{
for (int i = 0; i < 4; ++i)
{
color[i] = this->Color[i] / 255.0;
}
}
//-----------------------------------------------------------------------------
void vtkBrush::GetColor(unsigned char color[4])
{
for (int i = 0; i < 4