MCPcopy Create free account
hub / github.com/Kitware/VTK / TestSQLGraphReader

Function TestSQLGraphReader

IO/SQL/Testing/Cxx/TestSQLGraphReader.cxx:23–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
22
23int TestSQLGraphReader(int argc, char* argv[])
24{
25 vtkIdType vertices = 10;
26
27 // Create a SQLite in-memory database
28 VTK_CREATE(vtkSQLiteDatabase, database);
29 database->SetDatabaseFileName(":memory:");
30
31 bool ok = database->Open("");
32 if (!ok)
33 {
34 std::cerr << "Could not open database!" << std::endl;
35 std::cerr << database->GetLastErrorText() << std::endl;
36 return 1;
37 }
38
39 // Build a graph
40 vtkSmartPointer<vtkSQLQuery> q;
41 q.TakeReference(database->GetQueryInstance());
42 std::ostringstream oss;
43
44 q->SetQuery("DROP TABLE IF EXISTS vertices");
45 q->Execute();
46
47 q->SetQuery("CREATE TABLE vertices (id INTEGER, x FLOAT, y FLOAT)");
48 q->Execute();
49 for (int i = 0; i < vertices; i++)
50 {
51 oss.str("");
52 oss << "INSERT INTO vertices VALUES(" << i << ", "
53 << 0.5 * cos(i * 2.0 * vtkMath::Pi() / vertices) << ", "
54 << 0.5 * sin(i * 2.0 * vtkMath::Pi() / vertices) << ")" << std::endl;
55 q->SetQuery(oss.str().c_str());
56 q->Execute();
57 }
58
59 q->SetQuery("DROP TABLE IF EXISTS edges");
60 q->Execute();
61
62 q->SetQuery("CREATE TABLE edges (id INTEGER, source INTEGER, target INTEGER)");
63 q->Execute();
64 for (int i = 0; i < vertices; i++)
65 {
66 oss.str("");
67 oss << "INSERT INTO edges VALUES(" << 2 * i + 0 << ", " << i << ", " << (i + 1) % vertices
68 << ")" << std::endl;
69 q->SetQuery(oss.str().c_str());
70 q->Execute();
71 oss.str("");
72 oss << "INSERT INTO edges VALUES(" << 2 * i + 1 << ", " << (i + 3) % vertices << ", " << i
73 << ")" << std::endl;
74 q->SetQuery(oss.str().c_str());
75 q->Execute();
76 }
77
78 // Set up graph reader
79 VTK_CREATE(vtkSQLGraphReader, reader);
80 vtkSmartPointer<vtkSQLQuery> edgeQuery;

Callers

nothing calls this directly

Calls 15

PiFunction · 0.85
vtkRegressionTestImageFunction · 0.85
SetEdgeQueryMethod · 0.80
SetVertexQueryMethod · 0.80
ColorEdgesOnMethod · 0.80
ColorVerticesOnMethod · 0.80
cosFunction · 0.50
sinFunction · 0.50
OpenMethod · 0.45
GetLastErrorTextMethod · 0.45
TakeReferenceMethod · 0.45
GetQueryInstanceMethod · 0.45

Tested by

no test coverage detected