Commit eef78de8 authored by Berk Geveci's avatar Berk Geveci
Browse files

Merge remote-tracking branch 'pvvtk/pv-master' into VTK-6

Conflicts:
	Hybrid/vtkAxisActor.cxx
	Widgets/vtkPolygonalSurfaceContourLineInterpolator.cxx
parents 1056f5e1 040029c6
......@@ -27,6 +27,7 @@ IF(VTK_USE_RENDERING AND VTK_USE_VIEWS)
TestHistogram2D.cxx
TestLegendHiddenPlots.cxx
TestLinePlot.cxx
TestLinePlotAxisFonts.cxx
TestLinePlot2.cxx
TestLinePlotInteraction.cxx
TestMultipleChartRenderers.cxx
......
......@@ -49,5 +49,7 @@ int TestContextImage(int argc, char * argv [])
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
delete []logo;
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestLinePlotAxisFonts.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 "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkChartXY.h"
#include "vtkPlot.h"
#include "vtkAxis.h"
#include "vtkTextProperty.h"
#include "vtkTable.h"
#include "vtkFloatArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"
//----------------------------------------------------------------------------
int TestLinePlotAxisFonts(int, char * [])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart.GetPointer());
// Create a table with some points in it...
vtkNew<vtkTable> table;
vtkNew<vtkFloatArray> arrX;
arrX->SetName("X Axis");
table->AddColumn(arrX.GetPointer());
vtkNew<vtkFloatArray> arrC;
arrC->SetName("Cosine");
table->AddColumn(arrC.GetPointer());
vtkNew<vtkFloatArray> arrS;
arrS->SetName("Sine");
table->AddColumn(arrS.GetPointer());
vtkNew<vtkFloatArray> arrS2;
arrS2->SetName("Sine2");
table->AddColumn(arrS2.GetPointer());
// Test charting with a few more points...
int numPoints = 69;
float inc = 7.5 / (numPoints-1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
table->SetValue(i, 0, i * inc);
table->SetValue(i, 1, cos(i * inc));
}
// Add multiple line plots, setting the colors etc
vtkPlot *line = chart->AddPlot(vtkChart::LINE);
line->SetInput(table.GetPointer(), 0, 1);
line->SetColor(0, 255, 0, 255);
line->SetWidth(1.0);
vtkAxis *left = chart->GetAxis(vtkAxis::LEFT);
vtkAxis *bottom = chart->GetAxis(vtkAxis::BOTTOM);
left->SetTitle("Test Title");
bottom->SetTitle("Bottom axis");
// Load up the string image cache.
view->Render();
// Now change the size and color.
left->GetTitleProperties()->SetFontSize(20);
left->GetTitleProperties()->SetColor(1.0, 0.0, 0.0);
bottom->GetTitleProperties()->SetColor(0.0, 0.0, 1.0);
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
......@@ -27,6 +27,13 @@ vtkStandardNewMacro(vtkAxisExtended);
vtkAxisExtended::vtkAxisExtended()
{
this->FontSize = 0;
this->DesiredFontSize = 10;
this->Precision = 3;
this->LabelFormat = 0;
this->Orientation = 0;
this->LabelLegibilityChanged = true;
this->IsAxisVertical = false;
}
vtkAxisExtended::~vtkAxisExtended()
......@@ -268,8 +275,9 @@ int vtkAxisExtended::FormatStringLength(int format, double n, int precision)
// This methods determines the optimum notation, font size and orientation of
// labels from an exhaustive search
vtkVector<double, 4> vtkAxisExtended::Legibility(double lmin, double lmax,
double lstep, double scaling)
double vtkAxisExtended::Legibility(double lmin, double lmax, double lstep,
double scaling,
vtkVector<int, 3>& parameters)
{
int numTicks = static_cast<int>((lmax - lmin) / lstep);
double* tickPositions = new double[numTicks];
......@@ -341,7 +349,7 @@ vtkVector<double, 4> vtkAxisExtended::Legibility(double lmin, double lmax,
double overlapLegSum = 1.0;
double legScore = (formatLegSum + fontLegSum + orientLegSum
+ overlapLegSum)/4;
+ overlapLegSum) / 4;
if(legScore > bestLegScore )
{
if(numTicks>1)
......@@ -393,13 +401,11 @@ vtkVector<double, 4> vtkAxisExtended::Legibility(double lmin, double lmax,
}
}
vtkVector<double, 4> LegParameters;
LegParameters[0] = bestLegScore;
LegParameters[1] = bestFormat;
LegParameters[2] = bestFontSize;
LegParameters[3] = bestOrientation;
parameters[0] = bestFormat;
parameters[1] = bestFontSize;
parameters[2] = bestOrientation;
delete [] tickPositions;
return LegParameters;
return bestLegScore;
}
// This method implements the algorithm given in the paper
......@@ -413,7 +419,6 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin,
vtkVector3d ans;
this->LabelLegibilityChanged = false;
//vtkVector3d ans
if(dmin > dmax)
{
double temp = dmin;
......@@ -460,7 +465,7 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin,
double z = ceil(log10(delta));
while(z < INF)
{
double step = j*Q[qIndex]*pow(10,z);
double step = j*Q[qIndex]*pow(10.0,z);
//double cm = CoverageMax(dmin, dmax, step*(k-1));
if((w[0]*sm + w[1] + w[2]*dm + w[3]) < bestScore)
{
......@@ -491,9 +496,13 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin,
if(score < bestScore)
continue;
vtkVector<double,4> l = Legibility(lmin,lmax,lstep,scaling);
//vtkVector<double,4> l = this->Legibility(lmin, lmax, lstep, scaling);
score = w[0]*s + w[1]*c + w[2]*g + w[3]*l[0];
vtkVector<int, 3> legibilityIndex;
double newScore = this->Legibility(lmin, lmax, lstep, scaling,
legibilityIndex);
score = w[0] * s + w[1] * c + w[2] * g + w[3] * newScore;
if(score > bestScore)
{
......@@ -501,9 +510,9 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin,
bestLmin = lmin;
bestLmax = lmax;
bestLstep = lstep;
this->LabelFormat = l[1]; // label format
this->FontSize = l[2]; // label font size
this->Orientation = l[3]; // label orientation
this->LabelFormat = legibilityIndex[0]; // label format
this->FontSize = legibilityIndex[1]; // label font size
this->Orientation = legibilityIndex[2]; // label orientation
}
}
++z;
......@@ -520,3 +529,13 @@ vtkVector3d vtkAxisExtended::GenerateExtendedTickLabels(double dmin,
// return Sequence(bestLmin, bestLmax, bestLstep);
return ans;
}
void vtkAxisExtended::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Orientation: " << this->Orientation << endl;
os << indent << "FontSize: " << this->FontSize << endl;
os << indent << "DesiredFontSize: " << this->DesiredFontSize << endl;
os << indent << "Precision: " << this->Precision << endl;
os << indent << "LabelFormat: " << this->LabelFormat << endl;
}
......@@ -40,6 +40,7 @@ class VTK_CHARTS_EXPORT vtkAxisExtended : public vtkObject
public:
vtkTypeMacro(vtkAxisExtended, vtkObject);
static vtkAxisExtended *New();
virtual void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// This method return a value to make step sizes corresponding to low q
......@@ -72,11 +73,6 @@ public:
// m (user given)
static double DensityMax(int k, double m);
// Description:
// This method implements an exhaustive search for the legibilty parametes
vtkVector<double, 4> Legibility(double lmin, double lmax, double lstep,
double scaling);
// Description:
// This methods return the legibility score of differnt formats
static double FormatLegibilityScore(double n, int format);
......@@ -108,13 +104,18 @@ public:
vtkGetMacro(Orientation, int);
vtkSetMacro(Orientation, int);
//vtkGetMacro(FontSize, int);
vtkGetMacro(IsAxisVertical, bool);
vtkSetMacro(IsAxisVertical, bool);
protected:
vtkAxisExtended();
~vtkAxisExtended();
// Description:
// This method implements an exhaustive search of the legibilty parameters.
double Legibility(double lmin, double lmax, double lstep, double scaling,
vtkVector<int, 3>& parameters);
int Orientation;
int FontSize;
int DesiredFontSize;
......
......@@ -15,6 +15,7 @@
#include "vtkChart.h"
#include "vtkAxis.h"
#include "vtkBrush.h"
#include "vtkTransform2D.h"
#include "vtkContextMouseEvent.h"
......@@ -59,6 +60,8 @@ vtkChart::vtkChart()
this->AnnotationLink = NULL;
this->LayoutStrategy = vtkChart::FILL_SCENE;
this->RenderEmpty = false;
this->BackgroundBrush = vtkSmartPointer<vtkBrush>::New();
this->BackgroundBrush->SetColorF(1, 1, 1, 0);
}
//-----------------------------------------------------------------------------
......@@ -309,6 +312,28 @@ int vtkChart::GetClickActionToButton(int action)
return this->Actions[action - 2];
}
//-----------------------------------------------------------------------------
void vtkChart::SetBackgroundBrush(vtkBrush *brush)
{
if(brush == NULL)
{
// set to transparent white if brush is null
this->BackgroundBrush->SetColorF(1, 1, 1, 0);
}
else
{
this->BackgroundBrush = brush;
}
this->Modified();
}
//-----------------------------------------------------------------------------
vtkBrush* vtkChart::GetBackgroundBrush()
{
return this->BackgroundBrush.GetPointer();
}
//-----------------------------------------------------------------------------
void vtkChart::PrintSelf(ostream &os, vtkIndent indent)
{
......
......@@ -22,13 +22,15 @@
#define __vtkChart_h
#include "vtkContextItem.h"
#include "vtkRect.h" // For vtkRectf
#include "vtkStdString.h" // For vtkStdString ivars
#include "vtkRect.h" // For vtkRectf
#include "vtkStdString.h" // For vtkStdString ivars
#include "vtkSmartPointer.h" // For SP ivars
class vtkTransform2D;
class vtkContextScene;
class vtkPlot;
class vtkAxis;
class vtkBrush;
class vtkTextProperty;
class vtkChartLegend;
......@@ -244,6 +246,11 @@ public:
// vtkChart.
virtual int GetClickActionToButton(int action);
// Description:
// Set/Get the brush to use for the background color.
void SetBackgroundBrush(vtkBrush *brush);
vtkBrush* GetBackgroundBrush();
protected:
vtkChart();
~vtkChart();
......@@ -295,6 +302,10 @@ protected:
int LayoutStrategy;
bool RenderEmpty;
// Description:
// Brush to use for drawing the background.
vtkSmartPointer<vtkBrush> BackgroundBrush;
// Description:
// Hold mouse action mappings.
class MouseActions
......
......@@ -309,6 +309,15 @@ bool vtkChartXY::Paint(vtkContext2D *painter)
this->Point2[0]-this->Point1[0],
this->Point2[1]-this->Point1[1]);
// draw background
if(this->BackgroundBrush)
{
painter->GetPen()->SetLineType(vtkPen::NO_PEN);
painter->ApplyBrush(this->BackgroundBrush);
painter->DrawRect(this->Point1[0], this->Point1[1],
this->Geometry[0], this->Geometry[1]);
}
// Use the scene to render most of the chart.
this->PaintChildren(painter);
......
......@@ -32,21 +32,20 @@ vtkContextInteractorStyle::vtkContextInteractorStyle()
{
this->Scene = NULL;
this->ProcessingEvents = 0;
this->SceneCallbackCommand = vtkCallbackCommand::New();
this->SceneCallbackCommand->SetClientData(this);
this->SceneCallbackCommand->SetCallback(
vtkContextInteractorStyle::ProcessSceneEvents);
this->InteractorCallbackCommand->SetClientData(this);
this->InteractorCallbackCommand->SetCallback(
vtkContextInteractorStyle::ProcessInteractorEvents);
this->LastSceneRepaintMTime = 0;
this->TimerId = 0;
this->TimerCallbackInitialized = false;
}
//--------------------------------------------------------------------------
vtkContextInteractorStyle::~vtkContextInteractorStyle()
{
if (this->SceneCallbackCommand)
{
this->SceneCallbackCommand->Delete();
this->SceneCallbackCommand = 0;
}
}
//--------------------------------------------------------------------------
......@@ -69,7 +68,7 @@ void vtkContextInteractorStyle::SetScene(vtkContextScene* scene)
}
if (this->Scene)
{
this->Scene->RemoveObserver(this->SceneCallbackCommand);
this->Scene->RemoveObserver(this->SceneCallbackCommand.GetPointer());
}
this->Scene = scene;
......@@ -77,14 +76,14 @@ void vtkContextInteractorStyle::SetScene(vtkContextScene* scene)
if (this->Scene)
{
this->Scene->AddObserver(vtkCommand::ModifiedEvent,
this->SceneCallbackCommand,
this->SceneCallbackCommand.GetPointer(),
this->Priority);
}
this->Modified();
}
//----------------------------------------------------------------------------
void vtkContextInteractorStyle::ProcessSceneEvents(vtkObject* vtkNotUsed(object),
void vtkContextInteractorStyle::ProcessSceneEvents(vtkObject*,
unsigned long event,
void* clientdata,
void* vtkNotUsed(calldata))
......@@ -101,6 +100,28 @@ void vtkContextInteractorStyle::ProcessSceneEvents(vtkObject* vtkNotUsed(object)
}
}
//----------------------------------------------------------------------------
void vtkContextInteractorStyle::ProcessInteractorEvents(vtkObject*,
unsigned long,
void* clientdata,
void* vtkNotUsed(calldata))
{
vtkContextInteractorStyle* self =
reinterpret_cast<vtkContextInteractorStyle *>(clientdata);
self->RenderNow();
}
//----------------------------------------------------------------------------
void vtkContextInteractorStyle::RenderNow()
{
this->TimerId = 0;
if (this->Scene && !this->ProcessingEvents &&
this->Interactor->GetInitialized())
{
this->Interactor->GetRenderWindow()->Render();
}
}
//----------------------------------------------------------------------------
void vtkContextInteractorStyle::OnSceneModified()
{
......@@ -113,8 +134,19 @@ void vtkContextInteractorStyle::OnSceneModified()
return;
}
this->BeginProcessingEvent();
if (!this->TimerCallbackInitialized && this->Interactor)
{
this->Interactor->AddObserver(vtkCommand::TimerEvent,
this->InteractorCallbackCommand.GetPointer(),
0.0);
this->TimerCallbackInitialized = true;
}
this->LastSceneRepaintMTime = this->Scene->GetMTime();
this->Interactor->GetRenderWindow()->Render();
// If there is no timer, create a one shot timer to render an updated scene
if (this->TimerId == 0)
{
this->Interactor->CreateOneShotTimer(40);
}
this->EndProcessingEvent();
}
......
......@@ -23,6 +23,7 @@
#define __vtkContextInteractorStyle_h
#include "vtkInteractorStyle.h"
#include "vtkNew.h" // For ivars
class vtkContextScene;
......@@ -40,6 +41,7 @@ public:
// view is called appropriately: scene is dirty and no event is being
// processed.
void SetScene(vtkContextScene* scene);
// Description:
// Return the observed scene.
vtkGetObjectMacro(Scene, vtkContextScene);
......@@ -113,9 +115,15 @@ public:
protected:
vtkContextInteractorStyle();
~vtkContextInteractorStyle();
static void ProcessSceneEvents(vtkObject* object, unsigned long event,
void* clientdata, void* calldata);
static void ProcessInteractorEvents(vtkObject* object, unsigned long event,
void* clientdata, void* calldata);
void RenderNow();
// Description:
// Inform the interactor style that an event is being processed.
// That way is knows to not refresh the view (the view will eventually be
......@@ -129,10 +137,14 @@ protected:
void EndProcessingEvent();
vtkContextScene* Scene;
vtkCallbackCommand* SceneCallbackCommand;
vtkNew<vtkCallbackCommand> SceneCallbackCommand;
vtkNew<vtkCallbackCommand> InteractorCallbackCommand;
int ProcessingEvents;
unsigned long int LastSceneRepaintMTime;
unsigned long int TimerId;
bool TimerCallbackInitialized;
private:
vtkContextInteractorStyle(const vtkContextInteractorStyle&); // Not implemented
void operator=(const vtkContextInteractorStyle&); // Not implemented
......
......@@ -551,13 +551,13 @@ void vtkOpenGLContextDevice2D::DrawEllipticArc(float x, float y, float rX,
}
this->SetLineType(this->Pen->GetLineType());
glColor4ubv(this->Pen->GetColor());
glLineWidth(this->Pen->GetWidth());
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, p);
glDrawArrays(GL_LINE_STRIP, 0, iterations+1);
glColor4ubv(this->Brush->GetColor());
glDrawArrays(GL_TRIANGLE_FAN, 0, iterations+1);
glColor4ubv(this->Pen->GetColor());
glDrawArrays(GL_LINE_STRIP, 0, iterations+1);
glDisableClientState(GL_VERTEX_ARRAY);
delete[] p;
......
......@@ -32,6 +32,8 @@
#include "vtkOpenGLContextDevice2D.h"
#include "vtkColor.h"
#include "vtkTextProperty.h"
#include "vtkFreeTypeTools.h"
#include <algorithm>
#include <list>
......@@ -113,7 +115,7 @@ public:
protected:
// Description:
// Add a new cache entree into the cache list. Enforce the MaxSize size of the
// Add a new cache entry into the cache list. Enforce the MaxSize size of the
// list by removing the least used cache if needed.
CacheData& AddCacheData(const Key& key, const CacheData& cacheData)
{
......@@ -158,11 +160,11 @@ struct TextPropertyKey
{
// Description:
// Transform a text property into an unsigned long
static unsigned long GetIdFromTextProperty(vtkTextProperty* textProperty)
static unsigned int GetIdFromTextProperty(vtkTextProperty* textProperty)
{
unsigned long id;
vtkFreeTypeTools::GetInstance()->MapTextPropertyToId(textProperty, &id);
return id;
return static_cast<unsigned int>(id);
}
// Description:
......@@ -170,6 +172,13 @@ struct TextPropertyKey
TextPropertyKey(vtkTextProperty* textProperty, const vtkStdString& text)
{
this->TextPropertyId = GetIdFromTextProperty(textProperty);
this->FontSize = textProperty->GetFontSize();
double color[3];
textProperty->GetColor(color);
this->Color.Set(static_cast<unsigned char>(color[0] * 255),
static_cast<unsigned char>(color[1] * 255),
static_cast<unsigned char>(color[2] * 255),
static_cast<unsigned char>(textProperty->GetOpacity() * 255));
this->Text = text;
}
......@@ -179,9 +188,18 @@ struct TextPropertyKey
bool operator==(const TextPropertyKey& other)const
{
return this->TextPropertyId == other.TextPropertyId &&
this->Text == other.Text;
this->FontSize == other.FontSize &&
this->Text == other.Text &&
this->Color[0] == other.Color[0] &&
this->Color[1] == other.Color[1] &&
this->Color[2] == other.Color[2] &&
this->Color[3] == other.Color[3];
}
unsigned long TextPropertyId;
unsigned short FontSize;
vtkColor4ub Color;
// States in the function not to use more than 32 bits - int works fine here.
unsigned int TextPropertyId;
vtkStdString Text;
};
......
......@@ -136,5 +136,6 @@ void vtkPiecewiseFunctionItem::ComputeTexture()
ptr+=4;
}
}
delete[] values;
return;
}
......@@ -147,7 +147,7 @@ vtkIdType vtkPlotHistogram2D::GetNearestPoint(const vtkVector2f& point,
// rendered as the bottom left corner of a histogram cell, not the center
int locX = vtkMath::Floor( (point.GetX() - bounds[0]) / spacing[0] );
int locY = vtkMath::Floor( (point.GetY() - bounds[2]) / spacing[1] );
int width = vtkMath::Ceil( (bounds[1] - bounds[0]) / spacing[0] ) + 1.0;
int width = vtkMath::Ceil( (bounds[1] - bounds[0]) / spacing[0] ) + 1;
// Discretize to ImageData point values
location->SetX(locX * spacing[0] + bounds[0]);
......@@ -170,7 +170,7 @@ vtkStdString vtkPlotHistogram2D::GetTooltipLabel(const vtkVector2f &plotPos,
double bounds[4];
this->GetBounds(bounds);
int width = vtkMath::Ceil( (bounds[1] - bounds[0]) /
this->Input->GetSpacing()[0] ) + 1.0;
this->Input->GetSpacing()[0] ) + 1;
int pointX = seriesIndex % width;
int pointY = seriesIndex / width;
......
......@@ -682,6 +682,10 @@ bool vtkPlotPoints::UpdateTableCache(vtkTable *table)
{