File: TestCountFaces.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (154 lines) | stat: -rw-r--r-- 4,154 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*=========================================================================

  Program:   Visualization Toolkit

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkCountFaces.h"

#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkNew.h"
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"

int TestCountFaces(int, char*[])
{
  vtkNew<vtkUnstructuredGrid> data;
  vtkNew<vtkPoints> points;
  vtkNew<vtkIdList> cell;
  vtkNew<vtkCountFaces> filter;

  // Need 12 points to test all cell types:
  for (int i = 0; i < 12; ++i)
  {
    points->InsertNextPoint(0., 0., 0.);
  }
  data->SetPoints(points.Get());

  // Insert the following cell types and verify the number of faces computed
  // by the filter:
  // VTK_VERTEX = 0
  // VTK_LINE = 0
  // VTK_TRIANGLE = 0
  // VTK_TETRA = 4
  // VTK_PYRAMID = 5
  // VTK_WEDGE = 5
  // VTK_VOXEL = 6
  // VTK_HEXAHEDRON = 6
  // VTK_PENTAGONAL_PRISM = 7
  // VTK_HEXAGONAL_PRISM = 8

  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_VERTEX, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_LINE, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_TRIANGLE, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_TETRA, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_PYRAMID, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_WEDGE, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_VOXEL, cell.Get());
  data->InsertNextCell(VTK_HEXAHEDRON, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_PENTAGONAL_PRISM, cell.Get());

  cell->InsertNextId(cell->GetNumberOfIds());
  cell->InsertNextId(cell->GetNumberOfIds());
  data->InsertNextCell(VTK_HEXAGONAL_PRISM, cell.Get());

  filter->SetInputData(data.Get());
  filter->Update();

  vtkUnstructuredGrid *output =
      vtkUnstructuredGrid::SafeDownCast(filter->GetOutput());
  if (!output)
  {
    std::cerr << "No output data!\n";
    return EXIT_FAILURE;
  }

  vtkIdTypeArray *faces =
      vtkIdTypeArray::SafeDownCast(
        output->GetCellData()->GetArray(
          filter->GetOutputArrayName()));
  if (!faces)
  {
    std::cerr << "No output array!\n";
    return EXIT_FAILURE;
  }

  if (faces->GetNumberOfComponents() != 1)
  {
    std::cerr << "Invalid number of components in output array: "
              << faces->GetNumberOfComponents() << "\n";
    return EXIT_FAILURE;
  }

  if (faces->GetNumberOfTuples() != 10)
  {
    std::cerr << "Invalid number of components in output array: "
              << faces->GetNumberOfTuples() << "\n";
    return EXIT_FAILURE;
  }

#define TEST_FACES(idx, expected) \
  { \
  vtkIdType numFaces = faces->GetTypedComponent(idx, 0); \
  if (numFaces != expected) \
  { \
    std::cerr << "Expected cell @idx=" << idx << " to have " << expected \
              << " faces, but found " << numFaces << "\n"; \
    return EXIT_FAILURE; \
  } \
  }

  int idx = 0;
  // VTK_VERTEX = 0
  TEST_FACES(idx++, 0);
  // VTK_LINE = 0
  TEST_FACES(idx++, 0);
  // VTK_TRIANGLE = 0
  TEST_FACES(idx++, 0);
  // VTK_TETRA = 4
  TEST_FACES(idx++, 4);
  // VTK_PYRAMID = 5
  TEST_FACES(idx++, 5);
  // VTK_WEDGE = 5
  TEST_FACES(idx++, 5);
  // VTK_VOXEL = 6
  TEST_FACES(idx++, 6);
  // VTK_HEXAHEDRON = 6
  TEST_FACES(idx++, 6);
  // VTK_PENTAGONAL_PRISM = 7
  TEST_FACES(idx++, 7);
  // VTK_HEXAGONAL_PRISM = 8
  TEST_FACES(idx++, 8);

#undef TEST_FACES

  return EXIT_SUCCESS;
}