MCPcopy Create free account
hub / github.com/Kitware/VTK / TestGetNumNodesAndCells

Function TestGetNumNodesAndCells

Common/DataModel/Testing/Cxx/TestStructuredData.cxx:47–101  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

45
46//------------------------------------------------------------------------------
47int TestGetNumNodesAndCells()
48{
49
50#ifdef VTK_USE_64BIT_IDS
51 constexpr int maxDim = 2047;
52#else
53 constexpr int maxDim = 511;
54#endif
55
56 // Extent for 2048^3 grid
57 int ext[6] = { 0, maxDim, 0, maxDim, 0, maxDim };
58
59 int dims[3];
60 vtkStructuredData::GetDimensionsFromExtent(ext, dims);
61 if ((dims[0] != maxDim + 1) || (dims[1] != maxDim + 1) || (dims[2] != maxDim + 1))
62 {
63 std::cerr << "Wrong dims computed: ";
64 std::cerr << dims[0] << ", " << dims[1] << ", " << dims[2] << std::endl;
65 return EXIT_FAILURE;
66 }
67
68 // Compute expected number of nodes. Note, we cast dims to vtkIdType to
69 // ensure the compiler will generate a 32x32=64 multiply instruction.
70 vtkIdType nNodesExpected = static_cast<vtkIdType>(dims[0]) * static_cast<vtkIdType>(dims[1]) *
71 static_cast<vtkIdType>(dims[2]);
72
73 if (vtkStructuredData::GetNumberOfPoints(ext) != nNodesExpected)
74 {
75 std::cerr << "ERROR: GetNumberOfNodes(ext) failed!\n";
76 std::cerr << "val=" << vtkStructuredData::GetNumberOfPoints(ext) << "\n";
77 std::cerr << "expected=" << nNodesExpected << "\n";
78 return EXIT_FAILURE;
79 }
80
81 vtkStructuredData::GetCellDimensionsFromExtent(ext, dims);
82 if ((dims[0] != maxDim) || (dims[1] != maxDim) || (dims[2] != maxDim))
83 {
84 std::cerr << "Wrong dims computed: ";
85 std::cerr << dims[0] << ", " << dims[1] << ", " << dims[2] << std::endl;
86 return EXIT_FAILURE;
87 }
88 // Compute expected number of nodes. Note, we cast dims to vtkIdType to
89 // ensure the compiler will generate a 32x32=64 multiply instruction.
90 vtkIdType nCellsExpected = static_cast<vtkIdType>(dims[0]) * static_cast<vtkIdType>(dims[1]) *
91 static_cast<vtkIdType>(dims[2]);
92
93 if (vtkStructuredData::GetNumberOfCells(ext) != nCellsExpected)
94 {
95 std::cerr << "ERROR: GetNumberOfNodes(ext) failed!\n";
96 std::cerr << "val=" << vtkStructuredData::GetNumberOfCells(ext) << "\n";
97 std::cerr << "expected=" << nCellsExpected << "\n";
98 return EXIT_FAILURE;
99 }
100 return EXIT_SUCCESS;
101}
102
103//------------------------------------------------------------------------------
104int TestGridExtent(int ext[6])

Callers 1

TestStructuredDataFunction · 0.85

Calls 2

GetNumberOfPointsFunction · 0.50
GetNumberOfCellsFunction · 0.50

Tested by

no test coverage detected