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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
// .NAME
// .SECTION Description
// this program tests vtkPolyData
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDataSetAttributes.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkLogger.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkUnsignedCharArray.h"
namespace
{
//------------------------------------------------------------------------------
bool TestSupportsGhostArray()
{
vtkNew<vtkPolyData> pd;
if (!pd->SupportsGhostArray(vtkDataObject::POINT) || !pd->SupportsGhostArray(vtkDataObject::CELL))
{
vtkLog(ERROR, "Unexpected results on SupportsGhostArray");
return false;
}
return true;
}
//------------------------------------------------------------------------------
bool TestRemoveGhostCells()
{
vtkNew<vtkPolyData> pd;
pd->SetVerts(vtkNew<vtkCellArray>());
pd->SetLines(vtkNew<vtkCellArray>());
pd->SetPolys(vtkNew<vtkCellArray>());
pd->SetStrips(vtkNew<vtkCellArray>());
vtkNew<vtkPoints> points;
vtkNew<vtkIdList> pointIds;
vtkNew<vtkUnsignedCharArray> ghosts;
vtkNew<vtkIdTypeArray> ids;
ghosts->SetName(vtkDataSetAttributes::GhostArrayName());
ids->SetName("Ids");
double p[3] = { 0.0, 0.0, 0.0 };
points->SetNumberOfPoints(5);
points->SetPoint(0, p);
p[0] = -1.0;
points->SetPoint(1, p);
p[0] = 1.0;
points->SetPoint(2, p);
p[1] = 1.0;
points->SetPoint(3, p);
p[2] = 1.0;
points->SetPoint(4, p);
pd->SetPoints(points);
pointIds->SetNumberOfIds(1);
pointIds->SetId(0, 0);
ghosts->InsertNextValue(vtkDataSetAttributes::DUPLICATECELL);
pd->InsertNextCell(VTK_VERTEX, pointIds);
pointIds->SetId(0, 1);
ghosts->InsertNextValue(0);
pd->InsertNextCell(VTK_VERTEX, pointIds);
pointIds->SetNumberOfIds(2);
pointIds->SetId(0, 3);
pointIds->SetId(1, 1);
ghosts->InsertNextValue(0);
pd->InsertNextCell(VTK_LINE, pointIds);
pointIds->SetId(1, 2);
ghosts->InsertNextValue(vtkDataSetAttributes::DUPLICATECELL);
pd->InsertNextCell(VTK_LINE, pointIds);
pointIds->SetNumberOfIds(3);
pointIds->SetId(0, 4);
pointIds->SetId(1, 1);
pointIds->SetId(2, 2);
ghosts->InsertNextValue(vtkDataSetAttributes::DUPLICATECELL);
pd->InsertNextCell(VTK_TRIANGLE, pointIds);
pointIds->SetId(2, 3);
ghosts->InsertNextValue(0);
pd->InsertNextCell(VTK_TRIANGLE, pointIds);
pointIds->SetNumberOfIds(3);
pointIds->SetId(0, 1);
pointIds->SetId(1, 2);
pointIds->SetId(2, 3);
ghosts->InsertNextValue(0);
pd->InsertNextCell(VTK_TRIANGLE_STRIP, pointIds);
pointIds->SetId(2, 4);
ghosts->InsertNextValue(0);
pd->InsertNextCell(VTK_TRIANGLE_STRIP, pointIds);
pointIds->SetId(1, 3);
ghosts->InsertNextValue(vtkDataSetAttributes::DUPLICATECELL);
pd->InsertNextCell(VTK_TRIANGLE_STRIP, pointIds);
pd->GetCellData()->AddArray(ghosts);
ids->SetNumberOfValues(ghosts->GetNumberOfValues());
for (vtkIdType cellId = 0; cellId < ids->GetNumberOfValues(); ++cellId)
{
ids->SetValue(cellId, cellId);
}
pd->GetCellData()->AddArray(ids);
// ghosts: 1 0 0 1 1 0 0 0
// ids: 0 1 2 3 4 5 6 7
// Add dummy point data and field data
vtkNew<vtkIdTypeArray> pointDataIds;
pointDataIds->SetName("pointDataIds");
for (vtkIdType pointId = 0; pointId < pd->GetNumberOfPoints(); ++pointId)
{
pointDataIds->InsertNextValue(pointId);
}
pd->GetPointData()->AddArray(pointDataIds);
vtkNew<vtkIdTypeArray> field;
field->SetName("field");
field->InsertNextValue(17);
pd->GetFieldData()->AddArray(field);
pd->RemoveGhostCells();
const int nVerts = 1, nLines = 1, nPolys = 1, nStrips = 2;
if (pd->GetNumberOfVerts() != nVerts || pd->GetNumberOfLines() != nLines ||
pd->GetNumberOfPolys() != nPolys || pd->GetNumberOfStrips() != nStrips)
{
vtkLog(ERROR, "Removing ghosts failed... Wrong number of cells.");
vtkLog(INFO, << pd->GetNumberOfVerts() << ", " << pd->GetNumberOfLines() << ", "
<< pd->GetNumberOfPolys() << ", " << pd->GetNumberOfStrips());
return false;
}
vtkIdTypeArray* newIds =
vtkArrayDownCast<vtkIdTypeArray>(pd->GetCellData()->GetAbstractArray(ids->GetName()));
if (newIds->GetValue(0) != 1 || newIds->GetValue(1) != 2 || newIds->GetValue(2) != 5 ||
newIds->GetValue(3) != 6 || newIds->GetValue(4) != 7)
{
vtkLog(ERROR, "Removing ghosts failed... Wrong cell mapping.");
return false;
}
// The first point should have been removed.
if (pd->GetNumberOfPoints() != 4)
{
vtkLog(ERROR, "Removing ghosts fails... Wrong number of points.");
return false;
}
// Check point data is still present and of the expected size
vtkAbstractArray* ptArray = pd->GetPointData()->GetAbstractArray(pointDataIds->GetName());
if (!ptArray || ptArray->GetNumberOfValues() != 4)
{
vtkLog(ERROR, "Removing ghosts failed... Unexpected point data content.");
return false;
}
vtkIdTypeArray* fArray =
vtkArrayDownCast<vtkIdTypeArray>(pd->GetFieldData()->GetAbstractArray(field->GetName()));
if (!fArray || fArray->GetNumberOfValues() != 1 || fArray->GetValue(0) != 17)
{
vtkLog(ERROR, "Removing ghosts failed... Unexpected field data content.");
return false;
}
return true;
}
} // anonymous namespace
//------------------------------------------------------------------------------
int otherPolyData(int, char*[])
{
bool status = true;
status &= TestSupportsGhostArray();
status &= TestRemoveGhostCells();
return status ? EXIT_SUCCESS : EXIT_FAILURE;
}
|