1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestNetworkViews.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16 Copyright 2008 Sandia Corporation.
17 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18 the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20
21 #include "vtkNetworkHierarchy.h"
22 #include "vtkRegressionTestImage.h"
23 #include "vtkRenderWindow.h"
24 #include "vtkRenderWindowInteractor.h"
25 #include "vtkRenderer.h"
26 #include "vtkSQLDatabaseTableSource.h"
27 #include "vtkTableToGraph.h"
28 #include "vtkTextProperty.h"
29 #include "vtkTreeRingView.h"
30 #include "vtkVertexDegree.h"
31 #include "vtkViewTheme.h"
32
33 #include "vtkSmartPointer.h"
34 #define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
35
36 using std::string;
37
TestNetworkViews(int argc,char * argv[])38 int TestNetworkViews(int argc, char* argv[])
39 {
40 VTK_CREATE(vtkTesting, testHelper);
41 testHelper->AddArguments(argc, const_cast<const char**>(argv));
42 string dataRoot = testHelper->GetDataRoot();
43 string file = dataRoot + "/Data/Infovis/SQLite/ports_protocols.db";
44
45 // Pull the table (that represents relationships/edges) from the database
46 VTK_CREATE(vtkSQLDatabaseTableSource, databaseToEdgeTable);
47 databaseToEdgeTable->SetURL("sqlite://" + file);
48 databaseToEdgeTable->SetQuery("select src, dst, dport, protocol, port_protocol from tcp");
49
50 // Pull the table (that represents entities/vertices) from the database
51 VTK_CREATE(vtkSQLDatabaseTableSource, databaseToVertexTable);
52 databaseToVertexTable->SetURL("sqlite://" + file);
53 databaseToVertexTable->SetQuery("select ip, hostname from dnsnames");
54
55 // Make a graph
56 VTK_CREATE(vtkTableToGraph, graph);
57 graph->AddInputConnection(0, databaseToEdgeTable->GetOutputPort());
58 graph->AddInputConnection(1, databaseToVertexTable->GetOutputPort());
59 graph->AddLinkVertex("src", "ip", false);
60 graph->AddLinkVertex("dst", "ip", false);
61 graph->AddLinkEdge("src", "dst");
62
63 // Make a tree out of ip addresses
64 VTK_CREATE(vtkNetworkHierarchy, ip_tree);
65 ip_tree->AddInputConnection(graph->GetOutputPort());
66
67 VTK_CREATE(vtkTreeRingView, dummy);
68
69 // Create a view on city/region/country
70 VTK_CREATE(vtkTreeRingView, view1);
71 view1->DisplayHoverTextOff();
72 view1->SetTreeFromInputConnection(ip_tree->GetOutputPort());
73 view1->SetGraphFromInputConnection(graph->GetOutputPort());
74 view1->Update();
75 view1->SetLabelPriorityArrayName("VertexDegree");
76 view1->SetAreaColorArrayName("VertexDegree");
77 view1->SetColorAreas(true);
78 view1->SetAreaLabelArrayName("ip");
79 view1->SetAreaHoverArrayName("ip");
80 view1->SetAreaLabelVisibility(true);
81 view1->SetEdgeColorArrayName("dport");
82 view1->SetColorEdges(true);
83 view1->SetInteriorLogSpacingValue(5.);
84 view1->SetBundlingStrength(.5);
85
86 // Apply a theme to the views
87 vtkViewTheme* const theme = vtkViewTheme::CreateMellowTheme();
88 theme->GetPointTextProperty()->ShadowOn();
89 view1->ApplyViewTheme(theme);
90 theme->Delete();
91
92 view1->GetRenderWindow()->SetMultiSamples(0);
93 view1->GetRenderWindow()->SetSize(600, 600);
94
95 view1->ResetCamera();
96 view1->Render();
97
98 int retVal = vtkRegressionTestImage(view1->GetRenderWindow());
99 if (retVal == vtkRegressionTester::DO_INTERACTOR)
100 {
101 view1->GetInteractor()->Initialize();
102 view1->GetInteractor()->Start();
103
104 retVal = vtkRegressionTester::PASSED;
105 }
106
107 return !retVal;
108 }
109