-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvtkCleanUnstructuredGrid.cxx
More file actions
135 lines (119 loc) · 3.98 KB
/
vtkCleanUnstructuredGrid.cxx
File metadata and controls
135 lines (119 loc) · 3.98 KB
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
#include "include/vtkCleanUnstructuredGrid.h"
#include "vtkCell.h"
#include "vtkCellData.h"
#include "vtkCollection.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIntArray.h"
#include "vtkMergePoints.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"
vtkStandardNewMacro(vtkCleanUnstructuredGrid);
//----------------------------------------------------------------------------
vtkCleanUnstructuredGrid::vtkCleanUnstructuredGrid()
{
this->Locator = vtkMergePoints::New();
}
//----------------------------------------------------------------------------
vtkCleanUnstructuredGrid::~vtkCleanUnstructuredGrid()
{
this->Locator->Delete();
this->Locator = NULL;
}
//----------------------------------------------------------------------------
void vtkCleanUnstructuredGrid::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
int vtkCleanUnstructuredGrid::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkDataSet* input = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkUnstructuredGrid* output =
vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
if (input->GetNumberOfCells() == 0)
{
// set up a ugrid with same data arrays as input, but
// no points, cells or data.
output->Allocate(1);
output->GetPointData()->CopyAllocate(input->GetPointData(), VTK_CELL_SIZE);
output->GetCellData()->CopyAllocate(input->GetCellData(), 1);
vtkPoints* pts = vtkPoints::New();
output->SetPoints(pts);
pts->Delete();
return 1;
}
output->GetPointData()->CopyAllocate(input->GetPointData());
output->GetCellData()->PassData(input->GetCellData());
// First, create a new points array that eliminate duplicate points.
// Also create a mapping from the old point id to the new.
vtkPoints* newPts = vtkPoints::New();
vtkIdType num = input->GetNumberOfPoints();
vtkIdType id;
vtkIdType newId;
vtkIdType* ptMap = new vtkIdType[num];
double pt[3];
this->Locator->InitPointInsertion(newPts, input->GetBounds(), num);
vtkIdType progressStep = num / 100;
if (progressStep == 0)
{
progressStep = 1;
}
for (id = 0; id < num; ++id)
{
if (id % progressStep == 0)
{
this->UpdateProgress(0.8 * ((float)id / num));
}
input->GetPoint(id, pt);
if (this->Locator->InsertUniquePoint(pt, newId))
{
output->GetPointData()->CopyData(input->GetPointData(), id, newId);
}
ptMap[id] = newId;
}
output->SetPoints(newPts);
newPts->Delete();
// Now copy the cells.
vtkIdList* cellPoints = vtkIdList::New();
num = input->GetNumberOfCells();
output->Allocate(num);
for (id = 0; id < num; ++id)
{
if (id % progressStep == 0)
{
this->UpdateProgress(0.8 + 0.2 * ((float)id / num));
}
// special handling for polyhedron cells
if (vtkUnstructuredGrid::SafeDownCast(input) && input->GetCellType(id) == VTK_POLYHEDRON)
{
vtkUnstructuredGrid::SafeDownCast(input)->GetFaceStream(id, cellPoints);
vtkUnstructuredGrid::ConvertFaceStreamPointIds(cellPoints, ptMap);
}
else
{
input->GetCellPoints(id, cellPoints);
for (int i = 0; i < cellPoints->GetNumberOfIds(); i++)
{
int cellPtId = cellPoints->GetId(i);
newId = ptMap[cellPtId];
cellPoints->SetId(i, newId);
}
}
output->InsertNextCell(input->GetCellType(id), cellPoints);
}
delete[] ptMap;
cellPoints->Delete();
output->Squeeze();
return 1;
}
int vtkCleanUnstructuredGrid::FillInputPortInformation(int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
return 1;
}