File: TestDijkstraGraphGeodesicPath.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,992 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 185; javascript: 165; objc: 153; tcl: 59
file content (64 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (3)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

#include "vtkAppendPolyData.h"
#include "vtkDijkstraGraphGeodesicPath.h"
#include "vtkNew.h"
#include "vtkSphereSource.h"

int TestDijkstraGraphGeodesicPath(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
  vtkNew<vtkSphereSource> sphere1;
  sphere1->SetCenter(10, 10, 10);
  sphere1->SetRadius(5.0);

  vtkNew<vtkAppendPolyData> appendFilter;
  appendFilter->AddInputConnection(sphere1->GetOutputPort());
  appendFilter->Update();

  vtkPolyData* polyData = appendFilter->GetOutput();

  vtkNew<vtkDijkstraGraphGeodesicPath> pathFilter;
  pathFilter->SetInputData(polyData);
  pathFilter->SetStartVertex(0);
  pathFilter->SetEndVertex(polyData->GetNumberOfPoints() - 1);
  pathFilter->Update();

  // Valid path from the first to last point on a single sphere
  vtkPolyData* path1 = pathFilter->GetOutput();
  if (!path1 || !path1->GetPoints())
  {
    std::cerr << "Invalid output!" << std::endl;
    return EXIT_FAILURE;
  }
  if (path1->GetPoints()->GetNumberOfPoints() < 1)
  {
    std::cerr << "Could not find valid a path!" << std::endl;
    return EXIT_FAILURE;
  }

  vtkNew<vtkSphereSource> sphere2;
  sphere2->SetCenter(-10, -10, -10);
  sphere2->SetRadius(2.0);
  appendFilter->AddInputConnection(sphere2->GetOutputPort());
  appendFilter->Update();

  polyData = appendFilter->GetOutput();
  pathFilter->SetEndVertex(polyData->GetNumberOfPoints() - 1);
  pathFilter->Update();

  // No path should exist between the two separate spheres
  vtkPolyData* path2 = pathFilter->GetOutput();
  if (!path2 || !path2->GetPoints())
  {
    std::cerr << "Invalid output!" << std::endl;
    return EXIT_FAILURE;
  }
  if (path2->GetPoints()->GetNumberOfPoints() > 0)
  {
    std::cerr << "Invalid path was expected, however a valid path was found!" << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}