1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestTulipReaderProperties.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 "vtkDataSetAttributes.h"
#include "vtkDoubleArray.h"
#include "vtkGraph.h"
#include "vtkIntArray.h"
#include "vtkSmartPointer.h"
#include "vtkStdString.h"
#include "vtkStringArray.h"
#include "vtkTestUtilities.h"
#include "vtkTulipReader.h"
#include "vtkVariantArray.h"
template<typename value_t>
void TestValue(const value_t& Value, const value_t& ExpectedValue,
const vtkStdString& ValueDescription, int& ErrorCount)
{
if(Value == ExpectedValue)
{
return;
}
cerr << ValueDescription << " is [" << Value << "] - expected ["
<< ExpectedValue << "]" << endl;
++ErrorCount;
}
int TestTulipReaderProperties(int argc, char* argv[])
{
char* file = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/Infovis/clustered-graph.tlp");
cerr << "file: " << file << endl;
vtkSmartPointer<vtkTulipReader> reader =
vtkSmartPointer<vtkTulipReader>::New();
reader->SetFileName(file);
delete[] file;
reader->Update();
vtkGraph* const graph = reader->GetOutput();
int error_count = 0;
// Test a sample of the node pedigree id property
vtkVariantArray *nodePedigree= vtkVariantArray::SafeDownCast(
graph->GetVertexData()->GetPedigreeIds());
if (nodePedigree)
{
TestValue(nodePedigree->GetValue(0), vtkVariant(0),
"Node 0 pedigree id property", error_count);
TestValue(nodePedigree->GetValue(5), vtkVariant(5),
"Node 5 pedigree id property", error_count);
TestValue(nodePedigree->GetValue(11), vtkVariant(11),
"Node 11 pedigree id property", error_count);
}
else
{
cerr << "Node pedigree id property not found." << endl;
++error_count;
}
// Test a sample of the node string property
vtkStringArray *nodeProperty1 = vtkStringArray::SafeDownCast(
graph->GetVertexData()->GetAbstractArray("Node Name"));
if (nodeProperty1)
{
TestValue(nodeProperty1->GetValue(0), vtkStdString("Node A"),
"Node 0 string property", error_count);
TestValue(nodeProperty1->GetValue(5), vtkStdString("Node F"),
"Node 5 string property", error_count);
TestValue(nodeProperty1->GetValue(11), vtkStdString("Node L"),
"Node 11 string property", error_count);
}
else
{
cerr << "Node string property 'Node Name' not found." << endl;
++error_count;
}
// Test a sample of the node int property
vtkIntArray *nodeProperty2 = vtkIntArray::SafeDownCast(
graph->GetVertexData()->GetAbstractArray("Weight"));
if (nodeProperty2)
{
TestValue(nodeProperty2->GetValue(0), 100, "Node 0 int property",
error_count);
TestValue(nodeProperty2->GetValue(5), 105, "Node 5 int property",
error_count);
TestValue(nodeProperty2->GetValue(11), 111, "Node 11 int property",
error_count);
}
else
{
cerr << "Node int property 'Weight' not found." << endl;
++error_count;
}
// Test a sample of the node double property
vtkDoubleArray *nodeProperty3 = vtkDoubleArray::SafeDownCast(
graph->GetVertexData()->GetAbstractArray("Betweenness Centrality"));
if (nodeProperty3)
{
TestValue(nodeProperty3->GetValue(0), 0.0306061, "Node 0 double property",
error_count);
TestValue(nodeProperty3->GetValue(5), 0.309697, "Node 5 double property",
error_count);
TestValue(nodeProperty3->GetValue(11), 0.0306061, "Node 11 double property",
error_count);
}
else
{
cerr << "Node double property 'Betweenness Centrality' not found." << endl;
++error_count;
}
// Test a sample of the edge string property
vtkStringArray *edgeProperty1 = vtkStringArray::SafeDownCast(
graph->GetEdgeData()->GetAbstractArray("Edge Name"));
if (edgeProperty1)
{
TestValue(edgeProperty1->GetValue(0), vtkStdString("Edge A"),
"Edge 0 string property", error_count);
TestValue(edgeProperty1->GetValue(7), vtkStdString("Edge H"),
"Edge 7 string property", error_count);
TestValue(edgeProperty1->GetValue(16), vtkStdString("Edge Q"),
"Edge 16 string property", error_count);
}
else
{
cerr << "Edge string property 'Edge Name' not found." << endl;
++error_count;
}
// Test a sample of the edge int property
vtkIntArray *edgeProperty2 = vtkIntArray::SafeDownCast(
graph->GetEdgeData()->GetAbstractArray("Weight"));
if (edgeProperty2)
{
TestValue(edgeProperty2->GetValue(0), 100, "Edge 0 int property",
error_count);
TestValue(edgeProperty2->GetValue(7), 107, "Edge 7 int property",
error_count);
TestValue(edgeProperty2->GetValue(16), 116, "Edge 16 int property",
error_count);
}
else
{
cerr << "Edge int property 'Weight' not found." << endl;
++error_count;
}
// Test a sample of the edge pedigree id property
vtkVariantArray *edgePedigree= vtkVariantArray::SafeDownCast(
graph->GetEdgeData()->GetPedigreeIds());
if (edgePedigree)
{
TestValue(edgePedigree->GetValue(0), vtkVariant(0),
"Edge 0 pedigree id property", error_count);
TestValue(edgePedigree->GetValue(7), vtkVariant(7),
"Edge 7 pedigree id property", error_count);
TestValue(edgePedigree->GetValue(16), vtkVariant(16),
"Edge 16 pedigree id property", error_count);
}
else
{
cerr << "Edge pedigree id property not found." << endl;
++error_count;
}
cerr << error_count << " errors" << endl;
return error_count;
}
|