1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestPolyhedron3.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 "vtkPolyData.h"
17 #include "vtkUnstructuredGrid.h"
18 #include "vtkPolyhedron.h"
19 #include "vtkPlane.h"
20 
21 #include "vtkTestUtilities.h"
22 #include "vtkNew.h"
23 #include "vtkClipDataSet.h"
24 #include "vtkPlane.h"
25 
26 #include "vtkUnstructuredGridReader.h"
27 #include "vtkXMLUnstructuredGridWriter.h"
28 
29 const char inputDataStream[] =
30   "# vtk DataFile Version 3.0\n"
31   "vtk output\n"
32   "ASCII\n"
33   "DATASET UNSTRUCTURED_GRID\n"
34   "POINTS 8 float\n"
35   "1337.72 1586.34 914.4 1337.72 1586.34 1371.6 1261.68 1606.71 914.4 \n"
36   "1261.68 1606.71 1371.6 1337.72 1484.47 914.4 1337.72 1484.47 1371.6 \n"
37   "1261.68 1464.1 914.4 1261.68 1464.1 1371.6 \n"
38   "CELLS 1 32\n"
39   "31 6 4 4 6 2 0 4 1 3 7 5 4 0 2 3 1 4 2 6 7 3 4 6 4 5 7 4 4 0 1 5 \n"
40   "CELL_TYPES 1\n"
41   "42\n";
42 
43 // Test of contour/clip of vtkPolyhedron. uses input from https://gitlab.kitware.com/vtk/vtk/issues/15026
TestPolyhedron3(int argc,char * argv[])44 int TestPolyhedron3(int argc, char *argv[])
45 {
46   (void)argc;
47   (void)argv;
48 
49   vtkNew<vtkUnstructuredGridReader> reader;
50   reader->SetInputString(inputDataStream);
51   reader->ReadFromInputStringOn();
52 
53   vtkNew<vtkPlane> plane;
54   plane->SetNormal(0.847934330264784, 0.530022019598814, -0.00916680417631942);
55   plane->SetOrigin(1254.0760499239, 1489.93486006017, 1143.9780493697);
56 
57   vtkNew<vtkClipDataSet> clip;
58   clip->SetInputConnection(reader->GetOutputPort());
59   clip->SetClipFunction(plane);
60   clip->Update();
61 
62   vtkUnstructuredGrid* result = clip->GetOutput(0);
63   if (!result) return 1;
64   if (result->GetNumberOfCells() != 1)
65   {
66     std::cout << "Expected 1 but found " << result->GetNumberOfCells() << " cells in intersected polyhedron" << std::endl;
67     return EXIT_FAILURE;
68   }
69   vtkCell* clipped = result->GetCell(0);
70   if (!clipped) return 1;
71   if (clipped->GetNumberOfFaces() != 7 )
72   {
73     std::cout << "Expected 7 but found " << clipped->GetNumberOfFaces() << " faces on in intersected polyhedron" << std::endl;
74     return EXIT_FAILURE;
75   }
76 
77   return EXIT_SUCCESS;
78 }
79