Extract into groupSurface the subset of cells of surface belonging to groupId (as identified by the groupIdsArrayName cell data array). If cleanGroupSurface is true, unused points are removed (vtkCleanPolyData) from the extracted group.
80{
81 vtkDataArray* groupIdsArray = surface->GetPointData()->GetArray(groupIdsArrayName);
82
83 surface->BuildCells();
84
85 int numberOfCells = surface->GetPolys()->GetNumberOfCells();
86
87 vtkCellArray* groupPolys = vtkCellArray::New();
88 vtkIdType npts;
89 const vtkIdType *pts;
90 for (int j=0; j<numberOfCells; j++)
91 {
92 surface->GetCellPoints(j,npts,pts);
93 bool insertCell = true;
94 for (int k=0; k<npts; k++)
95 {
96 if (static_cast<int>(groupIdsArray->GetComponent(pts[k],0) != groupId))
97 {
98 insertCell = false;
99 break;
100 }
101 }
102 if (!insertCell)
103 {
104 continue;
105 }
106 groupPolys->InsertNextCell(npts,pts);
107 }
108 groupPolys->Squeeze();
109
110
111
112
113
114
115
116
117
118 groupSurface->Initialize();
119 vtkPoints* groupPoints = vtkPoints::New();
120 groupPoints->DeepCopy(surface->GetPoints());
121 groupSurface->SetPoints(groupPoints);
122 groupPoints->Delete();
123 groupSurface->GetPointData()->DeepCopy(surface->GetPointData());
124 groupSurface->SetPolys(groupPolys);
125 groupPolys->Delete();
126
127 if (cleanGroupSurface)
128 {
129 vtkCleanPolyData* cleaner = vtkCleanPolyData::New();
130 cleaner->SetInputData(groupSurface);
131 cleaner->Update();
132
133 groupSurface->DeepCopy(cleaner->GetOutput());
134
135 cleaner->Delete();
136 }
137}