File: TestTreeDFSIterator.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (70 lines) | stat: -rw-r--r-- 1,787 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
#include <vtkMutableDirectedGraph.h>
#include <vtkTree.h>
#include <vtkNew.h>

#include <vector>

#include "vtkTreeDFSIterator.h"

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

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

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

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

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

  vtkNew<vtkTreeDFSIterator> dfsIterator;
  dfsIterator->SetTree(tree.GetPointer());

  if(dfsIterator->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(!dfsIterator->HasNext())
      {
      cout << "HasNext() returned false before the end of the tree" << endl;
      return EXIT_FAILURE;
      }

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

  return EXIT_SUCCESS;
}