1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: TestDijkstraGraphGeodesicPath.cxx 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 16 #include "vtkAppendPolyData.h" 17 #include "vtkDijkstraGraphGeodesicPath.h" 18 #include "vtkNew.h" 19 #include "vtkSphereSource.h" 20 TestDijkstraGraphGeodesicPath(int vtkNotUsed (argc),char * vtkNotUsed (argv)[])21int TestDijkstraGraphGeodesicPath(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) 22 { 23 vtkNew<vtkSphereSource> sphere1; 24 sphere1->SetCenter(10, 10, 10); 25 sphere1->SetRadius(5.0); 26 27 vtkNew<vtkAppendPolyData> appendFilter; 28 appendFilter->AddInputConnection(sphere1->GetOutputPort()); 29 appendFilter->Update(); 30 31 vtkPolyData* polyData = appendFilter->GetOutput(); 32 33 vtkNew<vtkDijkstraGraphGeodesicPath> pathFilter; 34 pathFilter->SetInputData(polyData); 35 pathFilter->SetStartVertex(0); 36 pathFilter->SetEndVertex(polyData->GetNumberOfPoints() - 1); 37 pathFilter->Update(); 38 39 // Valid path from the first to last point on a single sphere 40 vtkPolyData* path1 = pathFilter->GetOutput(); 41 if (!path1 || !path1->GetPoints()) 42 { 43 std::cerr << "Invalid output!" << std::endl; 44 return EXIT_FAILURE; 45 } 46 if (path1->GetPoints()->GetNumberOfPoints() < 1) 47 { 48 std::cerr << "Could not find valid a path!" << std::endl; 49 return EXIT_FAILURE; 50 } 51 52 vtkNew<vtkSphereSource> sphere2; 53 sphere2->SetCenter(-10, -10, -10); 54 sphere2->SetRadius(2.0); 55 appendFilter->AddInputConnection(sphere2->GetOutputPort()); 56 appendFilter->Update(); 57 58 polyData = appendFilter->GetOutput(); 59 pathFilter->SetEndVertex(polyData->GetNumberOfPoints() - 1); 60 pathFilter->Update(); 61 62 // No path should exist between the two separate spheres 63 vtkPolyData* path2 = pathFilter->GetOutput(); 64 if (!path2 || !path2->GetPoints()) 65 { 66 std::cerr << "Invalid output!" << std::endl; 67 return EXIT_FAILURE; 68 } 69 if (path2->GetPoints()->GetNumberOfPoints() > 0) 70 { 71 std::cerr << "Invalid path was expected, however a valid path was found!" << std::endl; 72 return EXIT_FAILURE; 73 } 74 75 return EXIT_SUCCESS; 76 } 77