Commit 3eba81ad authored by Zack Galbreath's avatar Zack Galbreath

tests to cover new legends functionality

* New test in Charts/Core to color the new class vtkCategoryLegend

* New tests to cover the continuous & categorical heatmaps now
  available from vtkHeatmapItem

Change-Id: I06fa49c65e85ad421d5a360920a679379e77be89
parent 352f55b5
......@@ -13,6 +13,7 @@ vtk_add_test_cxx(
TestAxes.cxx
TestBarGraph.cxx
TestBarGraphHorizontal.cxx
TestCategoryLegend.cxx
TestColorTransferFunction.cxx,-E80
TestChartDouble.cxx
TestChartMatrix.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestCategoryLegend.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 "vtkCategoryLegend.h"
#include "vtkColorSeries.h"
#include "vtkLookupTable.h"
#include "vtkNew.h"
#include "vtkVariantArray.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContextScene.h"
#include "vtkContextTransform.h"
#include "vtkContextView.h"
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
int TestCategoryLegend(int argc, char* argv[])
{
vtkNew<vtkVariantArray> values;
values->InsertNextValue(vtkVariant("a"));
values->InsertNextValue(vtkVariant("b"));
values->InsertNextValue(vtkVariant("c"));
vtkNew<vtkLookupTable> lut;
for (int i = 0; i < values->GetNumberOfTuples(); ++i)
{
lut->SetAnnotation(values->GetValue(i), values->GetValue(i).ToString());
}
vtkNew<vtkColorSeries> colorSeries;
colorSeries->SetColorScheme(vtkColorSeries::BREWER_QUALITATIVE_SET3);
colorSeries->BuildLookupTable(lut.GetPointer());
vtkNew<vtkCategoryLegend> legend;
legend->SetScalarsToColors(lut.GetPointer());
legend->SetValues(values.GetPointer());
legend->SetTitle("legend");
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(legend.GetPointer());
trans->Translate(180, 70);
vtkNew<vtkContextView> contextView;
contextView->GetScene()->AddItem(trans.GetPointer());
contextView->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
contextView->GetRenderWindow()->SetSize(300,200);
contextView->GetRenderWindow()->SetMultiSamples(0);
contextView->GetRenderWindow()->Render();
int retVal = vtkRegressionTestImage(contextView->GetRenderWindow());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
contextView->GetRenderWindow()->Render();
contextView->GetInteractor()->Start();
retVal = vtkRegressionTester::PASSED;
}
return !retVal;
}
......@@ -4,7 +4,9 @@ vtk_add_test_cxx(
TestConeLayoutStrategy.cxx
TestDendrogramItem.cxx
TestGraphLayoutView.cxx
TestHeatmapCategoryLegend.cxx
TestHeatmapItem.cxx
TestHeatmapScalarLegend.cxx
TestHierarchicalGraphView.cxx
TestIcicleView.cxx
TestInteractorStyleTreeMapHover.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestHeatmapCategoryLegend.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 "vtkHeatmapItem.h"
#include "vtkNew.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkContextTransform.h"
#include "vtkContextView.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
int TestHeatmapCategoryLegend(int argc, char* argv[])
{
vtkNew<vtkTable> table;
vtkNew<vtkStringArray> tableNames;
vtkNew<vtkStringArray> column;
tableNames->SetNumberOfTuples(4);
tableNames->SetValue(0, "c");
tableNames->SetValue(1, "b");
tableNames->SetValue(2, "a");
tableNames->SetValue(3, "a");
tableNames->SetName("names");
column->SetNumberOfTuples(4);
column->SetName("values");
column->SetValue(0, "c");
column->SetValue(1, "b");
column->SetValue(2, "a");
column->SetValue(3, "a");
table->AddColumn(tableNames.GetPointer());
table->AddColumn(column.GetPointer());
vtkNew<vtkHeatmapItem> heatmap;
heatmap->SetTable(table.GetPointer());
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(heatmap.GetPointer());
trans->Translate(125, 125);
vtkNew<vtkContextView> contextView;
contextView->GetScene()->AddItem(trans.GetPointer());
contextView->GetRenderWindow()->SetMultiSamples(0);
contextView->GetRenderWindow()->Render();
// double click to display the category legend
vtkContextMouseEvent mouseEvent;
mouseEvent.SetInteractor(contextView->GetInteractor());
vtkVector2f pos;
mouseEvent.SetButton(vtkContextMouseEvent::LEFT_BUTTON);
pos.Set(16, 38);
mouseEvent.SetPos(pos);
heatmap->MouseDoubleClickEvent(mouseEvent);
contextView->GetRenderWindow()->Render();
int retVal = vtkRegressionTestImage(contextView->GetRenderWindow());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
contextView->GetRenderWindow()->Render();
contextView->GetInteractor()->Start();
retVal = vtkRegressionTester::PASSED;
}
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestHeatmapScalarLegend.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 "vtkHeatmapItem.h"
#include "vtkNew.h"
#include "vtkIntArray.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkContextTransform.h"
#include "vtkContextView.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
int TestHeatmapScalarLegend(int argc, char* argv[])
{
vtkNew<vtkTable> table;
vtkNew<vtkStringArray> tableNames;
vtkNew<vtkIntArray> column;
tableNames->SetNumberOfTuples(3);
tableNames->SetValue(0, "3");
tableNames->SetValue(1, "2");
tableNames->SetValue(2, "1");
tableNames->SetName("names");
column->SetNumberOfTuples(3);
column->SetName("values");
column->SetValue(0, 3);
column->SetValue(1, 2);
column->SetValue(2, 1);
table->AddColumn(tableNames.GetPointer());
table->AddColumn(column.GetPointer());
vtkNew<vtkHeatmapItem> heatmap;
heatmap->SetTable(table.GetPointer());
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(heatmap.GetPointer());
trans->Translate(125, 125);
vtkNew<vtkContextView> contextView;
contextView->GetScene()->AddItem(trans.GetPointer());
contextView->GetRenderWindow()->SetMultiSamples(0);
contextView->GetRenderWindow()->Render();
// double click to display the color legend
vtkContextMouseEvent mouseEvent;
mouseEvent.SetInteractor(contextView->GetInteractor());
vtkVector2f pos;
mouseEvent.SetButton(vtkContextMouseEvent::LEFT_BUTTON);
pos.Set(16, 38);
mouseEvent.SetPos(pos);
heatmap->MouseDoubleClickEvent(mouseEvent);
contextView->GetRenderWindow()->Render();
int retVal = vtkRegressionTestImage(contextView->GetRenderWindow());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
contextView->GetRenderWindow()->Render();
contextView->GetInteractor()->Start();
retVal = vtkRegressionTester::PASSED;
}
return !retVal;
}
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