File: TestTreeBFSIterator.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 118,532 kB
  • ctags: 138,251
  • sloc: cpp: 1,443,749; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,127; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 471; makefile: 95; objc: 17
file content (74 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download | duplicates (10)
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
#include <vtkMutableDirectedGraph.h>
#include <vtkTree.h>
#include <vtkNew.h>

#include <vector>

#include "vtkTreeBFSIterator.h"

int TestTreeBFSIterator(int, char *[])
{
  vtkNew<vtkMutableDirectedGraph> g;

  // Create vertices:
  // Level 0
  vtkIdType v0 = g->AddVertex();
  // Level 1
  vtkIdType v1 = g->AddVertex();
  vtkIdType v2 = g->AddVertex();
  // Level 2
  vtkIdType v3 = g->AddVertex();
  vtkIdType v4 = g->AddVertex();
  vtkIdType v5 = g->AddVertex();
  // Level 3
  vtkIdType v6 = g->AddVertex();
  vtkIdType v7 = g->AddVertex();
  vtkIdType v8 = g->AddVertex();

  //create a fully connected graph
  g->AddEdge(v0, v1);
  g->AddEdge(v0, v2);
  g->AddEdge(v1, v3);
  g->AddEdge(v2, v4);
  g->AddEdge(v2, v5);
  g->AddEdge(v4, v6);
  g->AddEdge(v4, v7);
  g->AddEdge(v5, v8);

  vtkNew<vtkTree> tree;
  tree->CheckedShallowCopy(g.GetPointer());

  std::vector<int> correctSequence;
  for(int i = 0; i <= 8; i++)
    {
    correctSequence.push_back(i);
    }

  vtkNew<vtkTreeBFSIterator> bfsIterator;
  bfsIterator->SetTree(tree.GetPointer());

  if(bfsIterator->GetStartVertex() != tree->GetRoot())
    {
    cout << "StartVertex is not defaulting to root" << endl;
    return EXIT_FAILURE;
    }

  //traverse the tree in a depth first fashion
  for(size_t i = 0; i < correctSequence.size(); i++)
    {
    if(!bfsIterator->HasNext())
      {
      cout << "HasNext() returned false before the end of the tree" << endl;
      return EXIT_FAILURE;
      }

    vtkIdType nextVertex = bfsIterator->Next();
    if(nextVertex != correctSequence[i])
      {
      cout << "Next vertex should be " << correctSequence[i] << " but it is " << nextVertex << endl;
      return EXIT_FAILURE;
      }
    }

  return EXIT_SUCCESS;
}