69 vtkInformation *request,
70 vtkInformationVector **inputVector,
71 vtkInformationVector *outputVector)
73 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
74 vtkInformation *outInfo = outputVector->GetInformationObject(0);
76 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
77 inInfo->Get(vtkDataObject::DATA_OBJECT()));
78 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
79 outInfo->Get(vtkDataObject::DATA_OBJECT()));
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;
87 bool allDotPositive, allDotMinusOnePositive;
89 vtkCellArray* newTetras;
90 vtkIdList* newCellTypes;
91 vtkIntArray* keepCell;
92 vtkDataArray* outwardPointNormals;
97 vtkErrorMacro(<<
"No normals array name specified!");
103 if (!outwardPointNormals)
105 vtkErrorMacro(<<
"Array with name specified does not exist!");
109 if (outwardPointNormals->GetNumberOfComponents()!=3)
111 vtkErrorMacro(<<
"Normals have NumberOfComponents != 3!");
115 if (outwardPointNormals->GetNumberOfTuples()!=input->GetNumberOfPoints())
117 vtkErrorMacro(<<
"Number of normals does not match input number of points !");
123 vtkErrorMacro(<<
"UseCapsOn but no CapCenterIds specified !");
129 vtkErrorMacro(<<
"RemoveSubresolutionTetrahedraOn but no Surface specified !");
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 !");
140 newTetras = vtkCellArray::New();
141 newCellTypes = vtkIdList::New();
142 keepCell = vtkIntArray::New();
143 keepCell->SetNumberOfTuples(input->GetNumberOfCells());
152 for (i=0; i<input->GetNumberOfCells(); i++)
154 tetra = vtkTetra::SafeDownCast(input->GetCell(i));
161 boundaryTetra =
false;
164 for (j=0; j<tetra->GetNumberOfPoints(); j++)
168 boundaryTetra =
true;
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);
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];
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);
192 dot0 = vtkMath::Dot(v0,n0);
193 dot1 = vtkMath::Dot(v1,n1);
194 dot2 = vtkMath::Dot(v2,n2);
195 dot3 = vtkMath::Dot(v3,n3);
197 allDotPositive =
false;
198 allDotMinusOnePositive =
false;
200 if ((dot0>tolerance)&&(dot1>tolerance)&&(dot2>tolerance)&&(dot3>tolerance))
202 allDotPositive =
true;
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)))
209 allDotMinusOnePositive =
true;
212 keepCell->SetValue(i,0);
216 keepCell->SetValue(i,1);
218 else if (boundaryTetra)
220 if (allDotMinusOnePositive)
222 keepCell->SetValue(i,1);
229 double pt0[3], pt1[3], pt2[3];
232 vtkIdList* cellNeighbors = vtkIdList::New();
233 for (i=0; i<input->GetNumberOfCells(); i++)
235 if (keepCell->GetValue(i) == 0)
240 tetra = vtkTetra::SafeDownCast(input->GetCell(i));
245 bool onNewBoundary =
false;
246 for (j=0; j<tetra->GetNumberOfFaces(); j++)
248 cellNeighbors->Initialize();
249 input->GetCellNeighbors(i,tetra->GetFace(j)->GetPointIds(),cellNeighbors);
250 if (cellNeighbors->GetNumberOfIds() == 0 || keepCell->GetValue(cellNeighbors->GetId(0)) == 0)
252 onNewBoundary =
true;
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);
266 for (j=0; j<tetra->GetNumberOfPoints(); j++)
270 this->
Surface->GetPointCells(j,ncells,cells);
273 for (k=0; k<ncells; k++)
275 vtkTriangle* triangle = vtkTriangle::SafeDownCast(this->
Surface->GetCell(cells[k]));
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)
287 minEdgeLength = edgeLength;
293 keepCell->SetValue(i,0);
297 cellNeighbors->Delete();
300 for (i=0; i<input->GetNumberOfCells(); i++)
302 if (keepCell->GetValue(i))
304 newCellTypes->InsertNextId(VTK_TETRA);
305 newTetras->InsertNextCell(input->GetCell(i));
309 int* newCellTypesInt =
new int[newCellTypes->GetNumberOfIds()];
310 for (i=0; i<newCellTypes->GetNumberOfIds(); i++)
312 newCellTypesInt[i] = newCellTypes->GetId(i);
315 output->SetPoints(input->GetPoints());
316 output->GetPointData()->PassData(input->GetPointData());
317 output->SetCells(newCellTypesInt,newTetras);
321 newCellTypes->Delete();
324 delete[] newCellTypesInt;