Updates will be applied April 15th at 12pm EDT (UTC-0400). GitLab could be a little slow between 12 - 12:45pm EDT.

Commit 4f25c6a1 authored by Zack Galbreath's avatar Zack Galbreath Committed by Code Review

Merge topic 'tanglegram' into master

8bb5d5f8 various minor improvements to vtkTanglegram
2e85c7cd various minor improvements to tanglegrams
dda53180 update tests & baselines
bd266aab new class: vtkTanglegramItem
3ea80450 refactor vtkTreeHeatmapItem into three classes
ab999619 new function: ComputeFontSizeForBoundedString
8a4c60bb preserve FieldData when pruning a tree
parents f1532fe7 8bb5d5f8
......@@ -84,6 +84,9 @@ int vtkPruneTreeFilter::RequestData(
builderVertexData->CopyAllocate(inputVertexData);
builderEdgeData->CopyAllocate(inputEdgeData);
// Copy field data
builder->GetFieldData()->DeepCopy(inputTree->GetFieldData());
// Build a copy of the tree, skipping the parent vertex to remove.
vtksys_stl::vector< vtksys_stl::pair<vtkIdType, vtkIdType> > vertStack;
if (inputTree->GetRoot() != this->ParentVertex)
......
......@@ -654,6 +654,45 @@ void vtkContext2D::ComputeStringBounds(const char* string,
this->ComputeStringBounds(vtkStdString(string), bounds);
}
//-----------------------------------------------------------------------------
int vtkContext2D::ComputeFontSizeForBoundedString(const vtkStdString &string,
float width, float height)
{
int orientation = this->GetTextProp()->GetOrientation();
this->GetTextProp()->SetOrientation(0.0);
float stringBounds[4];
int currentFontSize = this->GetTextProp()->GetFontSize();
this->ComputeStringBounds(string, stringBounds);
// font size is too big
if (stringBounds[2] > width || stringBounds[3] > height)
{
while (stringBounds[2] > width || stringBounds[3] > height)
{
--currentFontSize;
this->GetTextProp()->SetFontSize(currentFontSize);
this->ComputeStringBounds(string, stringBounds);
}
}
// font size is too small
else
{
while (stringBounds[2] < width && stringBounds[3] < height)
{
++currentFontSize;
this->GetTextProp()->SetFontSize(currentFontSize);
this->ComputeStringBounds(string, stringBounds);
}
--currentFontSize;
this->GetTextProp()->SetFontSize(currentFontSize);
}
this->GetTextProp()->SetOrientation(orientation);
return currentFontSize;
}
//-----------------------------------------------------------------------------
void vtkContext2D::DrawMathTextString(vtkPoints2D *point,
const vtkStdString &string)
......
......@@ -299,7 +299,6 @@ public:
// supplied bounds variable, the first two elements are the bottom corner of
// the string, and the second two elements are the width and height of the
// bounding box.
// NOTE: This function does not take account of the text rotation.
void ComputeStringBounds(const vtkStdString &string, vtkPoints2D *bounds);
void ComputeStringBounds(const vtkStdString &string, float bounds[4]);
void ComputeStringBounds(const vtkUnicodeString &string, vtkPoints2D *bounds);
......@@ -307,6 +306,14 @@ public:
void ComputeStringBounds(const char* string, vtkPoints2D *bounds);
void ComputeStringBounds(const char* string, float bounds[4]);
// Description:
// Calculate the largest possible font size where the supplied string will fit
// within the specified bounds. In addition to being returned, this font size
// is also used to update the vtkTextProperty used by this object.
// NOTE: text rotation is ignored for the purposes of this function.
int ComputeFontSizeForBoundedString(const vtkStdString &string, float width,
float height);
// Description:
// Draw a MathText formatted equation to the screen. See
// http://matplotlib.sourceforge.net/users/mathtext.html for more information.
......
SET(Module_SRCS
vtkApplyColors.cxx
vtkApplyIcons.cxx
vtkDendrogramItem.cxx
vtkGraphItem.cxx
vtkGraphLayoutView.cxx
vtkHeatmapItem.cxx
vtkHierarchicalGraphPipeline.cxx
vtkHierarchicalGraphView.cxx
vtkIcicleView.cxx
......@@ -17,6 +19,7 @@ SET(Module_SRCS
vtkRenderedSurfaceRepresentation.cxx
vtkRenderedTreeAreaRepresentation.cxx
vtkRenderView.cxx
vtkTanglegramItem.cxx
vtkTreeAreaView.cxx
vtkTreeHeatmapItem.cxx
vtkTreeMapView.cxx
......
vtk_add_test_cxx(
TestCoincidentGraphLayoutView.cxx
TestConeLayoutStrategy.cxx
TestDendrogramOnly.cxx
TestDendrogramItem.cxx
TestGraphLayoutView.cxx
TestHeatmapOnly.cxx
TestHeatmapItem.cxx
TestHierarchicalGraphView.cxx
TestIcicleView.cxx
TestInteractorStyleTreeMapHover.cxx
TestNetworkViews.cxx
TestRenderView.cxx
TestSpanTreeLayoutStrategy.cxx
TestTanglegramItem.cxx
TestTreeHeatmapAutoCollapse.cxx
TestTreeHeatmapItem.cxx
TestTreeMapView.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestDendrogramOnly.cxx
Module: TestDendrogramItem.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -13,7 +13,7 @@
=========================================================================*/
#include "vtkTreeHeatmapItem.h"
#include "vtkDendrogramItem.h"
#include "vtkDataSetAttributes.h"
#include "vtkDoubleArray.h"
#include "vtkMutableDirectedGraph.h"
......@@ -33,7 +33,7 @@
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
int TestDendrogramOnly(int argc, char* argv[])
int TestDendrogramItem(int argc, char* argv[])
{
vtkNew<vtkMutableDirectedGraph> graph;
vtkIdType root = graph->AddVertex();
......@@ -79,12 +79,14 @@ int TestDendrogramOnly(int argc, char* argv[])
vtkNew<vtkTree> tree;
tree->ShallowCopy(graph.GetPointer());
vtkNew<vtkTreeHeatmapItem> treeItem;
treeItem->SetTree(tree.GetPointer());
vtkNew<vtkDendrogramItem> dendrogram;
dendrogram->SetTree(tree.GetPointer());
dendrogram->SetPosition(40, 15);
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(treeItem.GetPointer());
trans->AddItem(dendrogram.GetPointer());
trans->Scale(3, 3);
actor->GetScene()->AddItem(trans.GetPointer());
vtkNew<vtkRenderer> renderer;
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestHeatmapOnly.cxx
Module: TestHeatmapItem.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -13,7 +13,7 @@
=========================================================================*/
#include "vtkTreeHeatmapItem.h"
#include "vtkHeatmapItem.h"
#include "vtkDoubleArray.h"
#include "vtkNew.h"
#include "vtkStringArray.h"
......@@ -31,7 +31,7 @@
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
int TestHeatmapOnly(int argc, char* argv[])
int TestHeatmapItem(int argc, char* argv[])
{
vtkNew<vtkTable> table;
vtkNew<vtkStringArray> tableNames;
......@@ -80,12 +80,14 @@ int TestHeatmapOnly(int argc, char* argv[])
vtkNew<vtkContextActor> actor;
vtkNew<vtkTreeHeatmapItem> treeItem;
treeItem->SetTable(table.GetPointer());
vtkNew<vtkHeatmapItem> heatmap;
heatmap->SetTable(table.GetPointer());
heatmap->SetPosition(20, 5);
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(treeItem.GetPointer());
trans->AddItem(heatmap.GetPointer());
trans->Scale(2, 2);
actor->GetScene()->AddItem(trans.GetPointer());
vtkNew<vtkRenderer> renderer;
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestTanglegramItem.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 "vtkTanglegramItem.h"
#include "vtkDataSetAttributes.h"
#include "vtkDoubleArray.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkNew.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkTree.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContextInteractorStyle.h"
#include "vtkContextActor.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextScene.h"
#include "vtkContextTransform.h"
#include "vtkNew.h"
#include "vtkRegressionTestImage.h"
//----------------------------------------------------------------------------
int TestTanglegramItem(int argc, char* argv[])
{
//tree #1
vtkNew<vtkMutableDirectedGraph> graph1;
vtkIdType root = graph1->AddVertex();
vtkIdType internalOne = graph1->AddChild(root);
vtkIdType internalTwo = graph1->AddChild(internalOne);
vtkIdType a = graph1->AddChild(internalTwo);
vtkIdType b = graph1->AddChild(internalTwo);
vtkIdType c = graph1->AddChild(internalOne);
vtkNew<vtkDoubleArray> weights;
weights->SetNumberOfTuples(5);
weights->SetValue(graph1->GetEdgeId(root, internalOne), 1.0f);
weights->SetValue(graph1->GetEdgeId(internalOne, internalTwo), 2.0f);
weights->SetValue(graph1->GetEdgeId(internalTwo, a), 1.0f);
weights->SetValue(graph1->GetEdgeId(internalTwo, b), 1.0f);
weights->SetValue(graph1->GetEdgeId(internalOne, c), 3.0f);
weights->SetName("weight");
graph1->GetEdgeData()->AddArray(weights.GetPointer());
vtkNew<vtkStringArray> names1;
names1->SetNumberOfTuples(6);
names1->SetValue(a, "cat");
names1->SetValue(b, "dog");
names1->SetValue(c, "human");
names1->SetName("node name");
graph1->GetVertexData()->AddArray(names1.GetPointer());
vtkNew<vtkDoubleArray> nodeWeights;
nodeWeights->SetNumberOfTuples(6);
nodeWeights->SetValue(root, 0.0f);
nodeWeights->SetValue(internalOne, 1.0f);
nodeWeights->SetValue(internalTwo, 3.0f);
nodeWeights->SetValue(a, 4.0f);
nodeWeights->SetValue(b, 4.0f);
nodeWeights->SetValue(c, 4.0f);
nodeWeights->SetName("node weight");
graph1->GetVertexData()->AddArray(nodeWeights.GetPointer());
//tree #2
vtkNew<vtkMutableDirectedGraph> graph2;
root = graph2->AddVertex();
internalOne = graph2->AddChild(root);
internalTwo = graph2->AddChild(internalOne);
a = graph2->AddChild(internalTwo);
b = graph2->AddChild(internalTwo);
c = graph2->AddChild(internalOne);
weights->SetName("weight");
graph2->GetEdgeData()->AddArray(weights.GetPointer());
vtkNew<vtkStringArray> names2;
names2->SetNumberOfTuples(6);
names2->SetValue(a, "dog food");
names2->SetValue(b, "cat food");
names2->SetValue(c, "steak");
names2->SetName("node name");
graph2->GetVertexData()->AddArray(names2.GetPointer());
graph2->GetVertexData()->AddArray(nodeWeights.GetPointer());
// set up correspondence table: who eats what
vtkNew<vtkTable> table;
vtkNew<vtkStringArray> eaters;
vtkNew<vtkDoubleArray> hungerForSteak;
hungerForSteak->SetName("steak");
vtkNew<vtkDoubleArray> hungerForDogFood;
hungerForDogFood->SetName("dog food");
vtkNew<vtkDoubleArray> hungerForCatFood;
hungerForCatFood->SetName("cat food");
eaters->SetNumberOfTuples(3);
hungerForSteak->SetNumberOfTuples(3);
hungerForDogFood->SetNumberOfTuples(3);
hungerForCatFood->SetNumberOfTuples(3);
eaters->SetValue(0, "human");
eaters->SetValue(1, "dog");
eaters->SetValue(2, "cat");
hungerForSteak->SetValue(0, 2.0);
hungerForSteak->SetValue(1, 1.0);
hungerForSteak->SetValue(2, 1.0);
hungerForDogFood->SetValue(0, 0.0);
hungerForDogFood->SetValue(1, 2.0);
hungerForDogFood->SetValue(2, 0.0);
hungerForCatFood->SetValue(0, 0.0);
hungerForCatFood->SetValue(1, 1.0);
hungerForCatFood->SetValue(2, 2.0);
table->AddColumn(eaters.GetPointer());
table->AddColumn(hungerForSteak.GetPointer());
table->AddColumn(hungerForDogFood.GetPointer());
table->AddColumn(hungerForCatFood.GetPointer());
vtkNew<vtkContextActor> actor;
vtkNew<vtkTree> tree1;
tree1->ShallowCopy(graph1.GetPointer());
vtkNew<vtkTree> tree2;
tree2->ShallowCopy(graph2.GetPointer());
vtkNew<vtkTanglegramItem> tanglegram;
tanglegram->SetTree1(tree1.GetPointer());
tanglegram->SetTree2(tree2.GetPointer());
tanglegram->SetTable(table.GetPointer());
tanglegram->SetTree1Label("Diners");
tanglegram->SetTree2Label("Meals");
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(tanglegram.GetPointer());
// center the item within the render window
trans->Translate(10, 75);
trans->Scale(1.375, 1.375);
actor->GetScene()->AddItem(trans.GetPointer());
vtkNew<vtkRenderer> renderer;
renderer->SetBackground(1.0, 1.0, 1.0);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(400, 200);
renderWindow->AddRenderer(renderer.GetPointer());
renderer->AddActor(actor.GetPointer());
actor->GetScene()->SetRenderer(renderer.GetPointer());
vtkNew<vtkContextInteractorStyle> interactorStyle;
interactorStyle->SetScene(actor->GetScene());
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetInteractorStyle(interactorStyle.GetPointer());
interactor->SetRenderWindow(renderWindow.GetPointer());
renderWindow->SetMultiSamples(0);
renderWindow->Render();
int retVal = vtkRegressionTestImageThreshold(renderWindow.GetPointer(), 100);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
renderWindow->Render();
interactor->Start();
retVal = vtkRegressionTester::PASSED;
}
return !retVal;
}
......@@ -15,6 +15,7 @@
#include "vtkTreeHeatmapItem.h"
#include "vtkDataSetAttributes.h"
#include "vtkDendrogramItem.h"
#include "vtkDoubleArray.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkNew.h"
......@@ -123,6 +124,9 @@ int TestTreeHeatmapAutoCollapse(int argc, char* argv[])
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
// center the item within the render window
trans->Translate(20, 30);
trans->Scale(2.5, 2.5);
trans->AddItem(treeItem.GetPointer());
actor->GetScene()->AddItem(trans.GetPointer());
......
......@@ -126,6 +126,9 @@ int TestTreeHeatmapItem(int argc, char* argv[])
vtkNew<vtkContextTransform> trans;
trans->SetInteractive(true);
trans->AddItem(treeItem.GetPointer());
// center the item within the render window
trans->Translate(40, 30);
trans->Scale(2, 2);
actor->GetScene()->AddItem(trans.GetPointer());
vtkNew<vtkRenderer> renderer;
......
ca3b7a7d5728458c046390d055a87776
d1ffa41cd988a64cfccf48f4daa4cb0a
005ad73f6a5959a65a360a0acf696859
c7dd8c6992c367f078617aa914750897
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDendrogramItem.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 vtkDendrogramItem - A 2D graphics item for rendering a tree as
// a dendrogram
//
// .SECTION Description
// Draw a tree as a dendrogram
// The input tree's vertex data must contain at least two arrays.
// The first required array is a vtkStringArray called "node name".
// This array is used to label the leaf nodes of the tree.
// The second required array is a scalar array called "node weight".
// This array is used by vtkTreeLayoutStrategy to set any particular
// node's distance from the root of the tree.
//
// The vtkNewickTreeReader automatically initializes both of these
// required arrays in its output tree.
//
// .SEE ALSO
// vtkTree vtkNewickTreeReader
#ifndef __vtkDendrogramItem_h
#define __vtkDendrogramItem_h
#include "vtkViewsInfovisModule.h" // For export macro
#include "vtkContextItem.h"
#include "vtkNew.h" // For vtkNew ivars
#include "vtkSmartPointer.h" // For vtkSmartPointer ivars
#include "vtkVector.h" // For vtkVector2f ivar
class vtkDoubleArray;
class vtkGraphLayout;
class vtkLookupTable;
class vtkTree;
class vtkPruneTreeFilter;
class VTKVIEWSINFOVIS_EXPORT vtkDendrogramItem : public vtkContextItem
{
public:
static vtkDendrogramItem *New();
vtkTypeMacro(vtkDendrogramItem, vtkContextItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Set the tree that this item draws. Note that this tree's vertex data
// must contain a vtkStringArray called "node name". The vtkNewickTreeReader
// automatically creates this required array for you.
virtual void SetTree(vtkTree *tree);
// Description:
// Get the tree that this item draws.
vtkTree * GetTree();
// Description:
// Collapse subtrees until there are only n leaf nodes left in the tree.
// The leaf nodes that remain are those that are closest to the root.
// Any subtrees that were collapsed prior to this function being called
// may be re-expanded.
void CollapseToNumberOfLeafNodes(unsigned int n);
// Description:
// Get the collapsed tree
vtkTree * GetPrunedTree();
// Description:
// Indicate which array within the Tree's VertexData should be used to
// color the tree. The specified array must be a vtkDoubleArray.
// By default, the tree will be drawn in black.
void SetColorArray(const char *arrayName);
// Description:
// Get/set whether or not leaf nodes should be extended so that they all line
// up vertically. The default is to NOT extend leaf nodes. When extending
// leaf nodes, the extra length is drawn in grey so as to distinguish it from
// the actual length of the leaf node.
vtkSetMacro(ExtendLeafNodes, bool);
vtkGetMacro(ExtendLeafNodes, bool);
vtkBooleanMacro(ExtendLeafNodes, bool);
// Description:
// Set which way the tree should face within the visualization. The default
// is for the tree to be drawn left to right.
void SetOrientation(int orientation);
// Description:
// Get the current tree orientation.
int GetOrientation();
// Description:
// Get the rotation angle (in degrees) that corresponds to the given
// tree orientation. For the default orientation (LEFT_TO_RIGHT), this
// is 90 degrees.
double GetAngleForOrientation(int orientation);
// Description:
// Get the angle that vertex labels should be rotated for the correponding
// tree orientation. For the default orientation (LEFT_TO_RIGHT), this
// is 0 degrees.
double GetTextAngleForOrientation(int orientation);
// Description:
// Get/Set whether or not leaf nodes should be labeled by this class.
// Default is true.
vtkSetMacro(DrawLabels, bool);
vtkGetMacro(DrawLabels, bool);
vtkBooleanMacro(DrawLabels, bool);
// Description:
// Set the position of the dendrogram.
vtkSetVector2Macro(Position, float);
void SetPosition(const vtkVector2f &pos);
// Description:
// Get position of the dendrogram.
vtkGetVector2Macro(Position, float);
vtkVector2f GetPositionVector();
// Description:
// Get/Set the spacing between the leaf nodes in our dendrogram.
// Default is 18 pixels.
vtkGetMacro(LeafSpacing, double);
vtkSetMacro(LeafSpacing, double);
// Description:
// This function calls RebuildBuffers() if necessary.
// Once PrepareToPaint() has been called, GetBounds() is guaranteed
// to provide useful information.
void PrepareToPaint();
// Description:
// Get the bounds for this item as (Xmin,Xmax,Ymin,Ymax).
// These bounds are only guaranteed to be accurate after Paint() or
// PrepareToPaint() has been called.
virtual void GetBounds(double bounds[4]);
// Description:
// Get the width of the longest leaf node label.
float GetLabelWidth(vtkContext2D *painter);
// Description:
// Find the position of the vertex with the specified name. Store
// this information in the passed array. Returns true if the vertex
// was found, false otherwise.
bool GetPositionOfVertex(std::string vertexName, double position[2]);
// this struct & class allow us to generate a priority queue of vertices.