1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestHierarchicalGraphView.cxx
5 
6 -------------------------------------------------------------------------
7   Copyright 2008 Sandia Corporation.
8   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9   the U.S. Government retains certain rights in this software.
10 -------------------------------------------------------------------------
11 
12   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13   All rights reserved.
14   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 
16      This software is distributed WITHOUT ANY WARRANTY; without even
17      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18      PURPOSE.  See the above copyright notice for more information.
19 
20 =========================================================================*/
21 
22 #include "vtkCosmicTreeLayoutStrategy.h"
23 #include "vtkDataRepresentation.h"
24 #include "vtkHierarchicalGraphView.h"
25 #include "vtkRegressionTestImage.h"
26 #include "vtkRenderWindow.h"
27 #include "vtkRenderWindowInteractor.h"
28 #include "vtkRenderedHierarchyRepresentation.h"
29 #include "vtkRenderer.h"
30 #include "vtkSelection.h"
31 #include "vtkSplineGraphEdges.h"
32 #include "vtkTestUtilities.h"
33 #include "vtkViewTheme.h"
34 #include "vtkXMLTreeReader.h"
35 
36 #include "vtkSmartPointer.h"
37 #define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
38 
39 using std::string;
40 
TestHierarchicalGraphView(int argc,char * argv[])41 int TestHierarchicalGraphView(int argc, char* argv[])
42 {
43   VTK_CREATE(vtkTesting, testHelper);
44   testHelper->AddArguments(argc, const_cast<const char**>(argv));
45   string dataRoot = testHelper->GetDataRoot();
46   string treeFileName = dataRoot + "/Data/Infovis/XML/vtklibrary.xml";
47   string graphFileName = dataRoot + "/Data/Infovis/XML/vtkclasses.xml";
48 
49   // We need to put the graph and tree edges in different domains.
50   VTK_CREATE(vtkXMLTreeReader, reader1);
51   reader1->SetFileName(treeFileName.c_str());
52   reader1->SetEdgePedigreeIdArrayName("tree edge");
53   reader1->GenerateVertexPedigreeIdsOff();
54   reader1->SetVertexPedigreeIdArrayName("id");
55 
56   VTK_CREATE(vtkXMLTreeReader, reader2);
57   reader2->SetFileName(graphFileName.c_str());
58   reader2->SetEdgePedigreeIdArrayName("graph edge");
59   reader2->GenerateVertexPedigreeIdsOff();
60   reader2->SetVertexPedigreeIdArrayName("id");
61 
62   reader1->Update();
63   reader2->Update();
64 
65   VTK_CREATE(vtkHierarchicalGraphView, view);
66   view->DisplayHoverTextOff();
67   view->GetRenderWindow()->SetMultiSamples(0);
68   view->SetHierarchyFromInputConnection(reader1->GetOutputPort());
69   view->SetGraphFromInputConnection(reader2->GetOutputPort());
70   view->SetVertexColorArrayName("VertexDegree");
71   view->SetColorVertices(true);
72   view->SetVertexLabelArrayName("id");
73   view->SetVertexLabelVisibility(true);
74   view->SetScalingArrayName("TreeRadius");
75 
76   view->Update(); // Needed for now
77   view->SetGraphEdgeColorArrayName("graph edge");
78   view->SetColorGraphEdgesByArray(true);
79   vtkRenderedHierarchyRepresentation::SafeDownCast(view->GetRepresentation())
80     ->SetGraphSplineType(vtkSplineGraphEdges::CUSTOM, 0);
81 
82   VTK_CREATE(vtkCosmicTreeLayoutStrategy, ct);
83   ct->SetNodeSizeArrayName("VertexDegree");
84   ct->SetSizeLeafNodesOnly(true);
85   view->SetLayoutStrategy(ct);
86 
87   // Apply a theme to the views
88   vtkViewTheme* const theme = vtkViewTheme::CreateMellowTheme();
89   theme->SetLineWidth(1);
90   view->ApplyViewTheme(theme);
91   theme->Delete();
92 
93   view->ResetCamera();
94 
95   int retVal = vtkRegressionTestImage(view->GetRenderWindow());
96   if (retVal == vtkRegressionTester::DO_INTERACTOR)
97   {
98     view->GetInteractor()->Initialize();
99     view->GetInteractor()->Start();
100 
101     retVal = vtkRegressionTester::PASSED;
102   }
103 
104   return !retVal;
105 }
106