72{
73 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
74 vtkInformation *outInfo = outputVector->GetInformationObject(0);
75
76 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
77 inInfo->Get(vtkDataObject::DATA_OBJECT()));
78 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
79 outInfo->Get(vtkDataObject::DATA_OBJECT()));
80
81
82 double circumcenter[3];
83 double p0[3], p1[3], p2[3], p3[3];
84 double v0[3], v1[3], v2[3], v3[3], n0[3], n1[3], n2[3], n3[3];
85 double dot0, dot1, dot2, dot3;
86 bool boundaryTetra;
87 bool allDotPositive, allDotMinusOnePositive;
88 vtkIdType i, j;
89 vtkCellArray* newTetras;
90 vtkIdList* newCellTypes;
91 vtkIntArray* keepCell;
92 vtkDataArray* outwardPointNormals;
93 vtkTetra* tetra;
94
96 {
97 vtkErrorMacro(<< "No normals array name specified!");
98 return 1;
99 }
100
102
103 if (!outwardPointNormals)
104 {
105 vtkErrorMacro(<< "Array with name specified does not exist!");
106 return 1;
107 }
108
109 if (outwardPointNormals->GetNumberOfComponents()!=3)
110 {
111 vtkErrorMacro(<< "Normals have NumberOfComponents != 3!");
112 return 1;
113 }
114
115 if (outwardPointNormals->GetNumberOfTuples()!=input->GetNumberOfPoints())
116 {
117 vtkErrorMacro(<< "Number of normals does not match input number of points !");
118 return 1;
119 }
120
122 {
123 vtkErrorMacro(<< "UseCapsOn but no CapCenterIds specified !");
124 return 1;
125 }
126
128 {
129 vtkErrorMacro(<< "RemoveSubresolutionTetrahedraOn but no Surface specified !");
130 return 1;
131 }
132
134 {
135 vtkErrorMacro(<< "NumberOfPoints of Surface is different than that of input Delaunay tessellation, the Delaunay tessellation doesn't look like it has been produced from the Surface !");
136 return 1;
137 }
138
139
140 newTetras = vtkCellArray::New();
141 newCellTypes = vtkIdList::New();
142 keepCell = vtkIntArray::New();
143 keepCell->SetNumberOfTuples(input->GetNumberOfCells());
144
145
146
147
148
149
151
152 for (i=0; i<input->GetNumberOfCells(); i++)
153 {
154 tetra = vtkTetra::SafeDownCast(input->GetCell(i));
155
156 if (!tetra)
157 {
158 continue;
159 }
160
161 boundaryTetra = false;
163 {
164 for (j=0; j<tetra->GetNumberOfPoints(); j++)
165 {
167 {
168 boundaryTetra = true;
169 }
170 }
171 }
172
173 tetra->GetPoints()->GetPoint(0,p0);
174 tetra->GetPoints()->GetPoint(1,p1);
175 tetra->GetPoints()->GetPoint(2,p2);
176 tetra->GetPoints()->GetPoint(3,p3);
177 vtkTetra::Circumsphere(p0,p1,p2,p3,circumcenter);
178
179 for (j=0; j<3; j++)
180 {
181 v0[j] = p0[j] - circumcenter[j];
182 v1[j] = p1[j] - circumcenter[j];
183 v2[j] = p2[j] - circumcenter[j];
184 v3[j] = p3[j] - circumcenter[j];
185 }
186
187 outwardPointNormals->GetTuple(tetra->GetPointId(0),n0);
188 outwardPointNormals->GetTuple(tetra->GetPointId(1),n1);
189 outwardPointNormals->GetTuple(tetra->GetPointId(2),n2);
190 outwardPointNormals->GetTuple(tetra->GetPointId(3),n3);
191
192 dot0 = vtkMath::Dot(v0,n0);
193 dot1 = vtkMath::Dot(v1,n1);
194 dot2 = vtkMath::Dot(v2,n2);
195 dot3 = vtkMath::Dot(v3,n3);
196
197 allDotPositive = false;
198 allDotMinusOnePositive = false;
199
200 if ((dot0>tolerance)&&(dot1>tolerance)&&(dot2>tolerance)&&(dot3>tolerance))
201 {
202 allDotPositive = true;
203 }
204 else if (((dot0>tolerance)&&(dot1>tolerance)&&(dot2>tolerance))||
205 ((dot0>tolerance)&&(dot1>tolerance)&&(dot3>tolerance))||
206 ((dot0>tolerance)&&(dot2>tolerance)&&(dot3>tolerance))||
207 ((dot1>tolerance)&&(dot2>tolerance)&&(dot3>tolerance)))
208 {
209 allDotMinusOnePositive = true;
210 }
211
212 keepCell->SetValue(i,0);
213
214 if (allDotPositive)
215 {
216 keepCell->SetValue(i,1);
217 }
218 else if (boundaryTetra)
219 {
220 if (allDotMinusOnePositive)
221 {
222 keepCell->SetValue(i,1);
223 }
224 }
225 }
226
228 {
229 double pt0[3], pt1[3], pt2[3];
231
232 vtkIdList* cellNeighbors = vtkIdList::New();
233 for (i=0; i<input->GetNumberOfCells(); i++)
234 {
235 if (keepCell->GetValue(i) == 0)
236 {
237 continue;
238 }
239
240 tetra = vtkTetra::SafeDownCast(input->GetCell(i));
241 if (!tetra)
242 {
243 continue;
244 }
245 bool onNewBoundary = false;
246 for (j=0; j<tetra->GetNumberOfFaces(); j++)
247 {
248 cellNeighbors->Initialize();
249 input->GetCellNeighbors(i,tetra->GetFace(j)->GetPointIds(),cellNeighbors);
250 if (cellNeighbors->GetNumberOfIds() == 0 || keepCell->GetValue(cellNeighbors->GetId(0)) == 0)
251 {
252 onNewBoundary = true;
253 }
254 }
255 if (!onNewBoundary)
256 {
257 continue;
258 }
259
260 tetra->GetPoints()->GetPoint(0,p0);
261 tetra->GetPoints()->GetPoint(1,p1);
262 tetra->GetPoints()->GetPoint(2,p2);
263 tetra->GetPoints()->GetPoint(3,p3);
264 double circumradius = vtkTetra::Circumsphere(p0,p1,p2,p3,circumcenter);
265
266 for (j=0; j<tetra->GetNumberOfPoints(); j++)
267 {
268 vtkIdType ncells;
269 vtkIdType* cells;
270 this->
Surface->GetPointCells(j,ncells,cells);
272 int k;
273 for (k=0; k<ncells; k++)
274 {
275 vtkTriangle* triangle = vtkTriangle::SafeDownCast(this->
Surface->GetCell(cells[k]));
276 if (!triangle)
277 {
278 continue;
279 }
280 triangle->GetPoints()->GetPoint(0,pt0);
281 triangle->GetPoints()->GetPoint(1,pt1);
282 triangle->GetPoints()->GetPoint(2,pt2);
283 double triangleArea = triangle->TriangleArea(pt0,pt1,pt2);
284 double edgeLength = sqrt(2.0 * triangleArea);
285 if (edgeLength < minEdgeLength)
286 {
287 minEdgeLength = edgeLength;
288 }
289 }
290
292 {
293 keepCell->SetValue(i,0);
294 }
295 }
296 }
297 cellNeighbors->Delete();
298 }
299
300 for (i=0; i<input->GetNumberOfCells(); i++)
301 {
302 if (keepCell->GetValue(i))
303 {
304 newCellTypes->InsertNextId(VTK_TETRA);
305 newTetras->InsertNextCell(input->GetCell(i));
306 }
307 }
308
309 int* newCellTypesInt = new int[newCellTypes->GetNumberOfIds()];
310 for (i=0; i<newCellTypes->GetNumberOfIds(); i++)
311 {
312 newCellTypesInt[i] = newCellTypes->GetId(i);
313 }
314
315 output->SetPoints(input->GetPoints());
316 output->GetPointData()->PassData(input->GetPointData());
317 output->SetCells(newCellTypesInt,newTetras);
318
319
320 newTetras->Delete();
321 newCellTypes->Delete();
322 keepCell->Delete();
323
324 delete[] newCellTypesInt;
325
326 return 1;
327}
#define VTK_VMTK_LARGE_DOUBLE