77 double weightSum, weight;
82 numberOfPoints = points->GetNumberOfPoints();
90 double point0[3], point1[3];
92 for (i=0; i<numberOfPoints; i++)
94 points->GetPoint(i,point0);
95 points->GetPoint((i+1)%numberOfPoints,point1);
96 weight = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
103 barycenter[0] += (point0[0] + point1[0])/2.0 * weight;
104 barycenter[1] += (point0[1] + point1[1])/2.0 * weight;
105 barycenter[2] += (point0[2] + point1[2])/2.0 * weight;
108 barycenter[0] /= weightSum;
109 barycenter[1] /= weightSum;
110 barycenter[2] /= weightSum;
134 double point[3], vector1[3], vector0[3], cross[3], sumCross[3] = {0.0f,0.0f,0.0f};
139 numberOfPoints = points->GetNumberOfPoints();
141 points->GetPoint(numberOfPoints-1,point);
142 vector0[0] = point[0] - barycenter[0];
143 vector0[1] = point[1] - barycenter[1];
144 vector0[2] = point[2] - barycenter[2];
146 for (i=0; i<numberOfPoints; i++)
148 points->GetPoint(i,point);
149 vector1[0] = point[0] - barycenter[0];
150 vector1[1] = point[1] - barycenter[1];
151 vector1[2] = point[2] - barycenter[2];
153 vtkMath::Cross(vector1,vector0,cross);
157 vector0[j] = vector1[j];
158 sumCross[j] += cross[j];
162 vtkMath::Normalize(sumCross);
166 normal[j] = sumCross[j];
172 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(boundaryCellId));
179 outwardNormal[k] = normal[k];
184 surface->BuildCells();
185 surface->BuildLinks();
189 const vtkIdType *pts;
192 double boundaryPoint[3], neighborPoint[3];
194 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
197 vtkIdList* boundaryIds = vtkIdList::New();
198 for (j=0; j<numberOfBoundaryPoints; j++)
200 boundaryIds->InsertNextId(
static_cast<vtkIdType
>(vtkMath::Round(boundaries->GetPointData()->GetScalars()->GetComponent(boundary->GetPointId(j),0))));
203 double neighborsToBoundaryNormal[3];
204 neighborsToBoundaryNormal[0] = neighborsToBoundaryNormal[1] = neighborsToBoundaryNormal[2] = 0.0;
205 for (j=0; j<numberOfBoundaryPoints; j++)
207 surface->GetPointCells(boundaryIds->GetId(j),ncells,cells);
208 for (
int c=0; c<ncells; c++)
210 surface->GetCellPoints(cells[c],npts,pts);
211 for (
int p=0; p<npts; p++)
213 if (boundaryIds->IsId(pts[p]) == -1)
215 surface->GetPoint(boundaryIds->GetId(j),boundaryPoint);
216 surface->GetPoint(pts[p],neighborPoint);
219 neighborsToBoundaryNormal[k] += boundaryPoint[k] - neighborPoint[k];
228 outwardNormal[k] = normal[k];
231 vtkMath::Normalize(neighborsToBoundaryNormal);
233 if (vtkMath::Dot(normal,neighborsToBoundaryNormal) < 0.0)
237 outwardNormal[k] *= -1.0;
241 boundaryIds->Delete();
269 vtkInformation *vtkNotUsed(request),
270 vtkInformationVector **inputVector,
271 vtkInformationVector *outputVector)
274 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
275 vtkInformation *outInfo = outputVector->GetInformationObject(0);
278 vtkPolyData *input = vtkPolyData::SafeDownCast(
279 inInfo->Get(vtkDataObject::DATA_OBJECT()));
280 vtkPolyData *output = vtkPolyData::SafeDownCast(
281 outInfo->Get(vtkDataObject::DATA_OBJECT()));
285 vtkErrorMacro(<<
"BoundaryRadiusArrayName not specified.");
291 vtkErrorMacro(<<
"BoundaryNormalsArrayName not specified.");
297 vtkErrorMacro(<<
"Point1ArrayName not specified.");
303 vtkErrorMacro(<<
"Point2ArrayName not specified.");
307 vtkPoints* outputPoints = vtkPoints::New();
308 vtkCellArray* outputVerts = vtkCellArray::New();
309 vtkDoubleArray* outputRadius = vtkDoubleArray::New();
311 vtkDoubleArray* outputNormals = vtkDoubleArray::New();
313 outputNormals->SetNumberOfComponents(3);
314 vtkDoubleArray* point1Array = vtkDoubleArray::New();
316 point1Array->SetNumberOfComponents(3);
317 vtkDoubleArray* point2Array = vtkDoubleArray::New();
319 point2Array->SetNumberOfComponents(3);
322 boundaryExtractor->SetInputData(input);
324 boundaryExtractor->Update();
326 vtkPolyData* boundaries = boundaryExtractor->GetOutput();
328 double barycenter[3], normal[3], outwardNormal[3], meanRadius;
330 for (
int i=0; i<boundaries->GetNumberOfCells(); i++)
332 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(i));
336 vtkErrorMacro(<<
"Boundary not a vtkPolyLine");
344 double point1[3], point2[3];
347 vtkIdType pointId = outputPoints->InsertNextPoint(barycenter);
348 outputVerts->InsertNextCell(1);
349 outputVerts->InsertCellPoint(pointId);
350 outputNormals->InsertNextTuple(outwardNormal);
351 outputRadius->InsertNextValue(meanRadius);
352 point1Array->InsertNextTuple(point1);
353 point2Array->InsertNextTuple(point2);
356 output->SetPoints(outputPoints);
357 output->SetVerts(outputVerts);
358 output->GetPointData()->AddArray(outputNormals);
360 output->GetPointData()->AddArray(outputRadius);
362 output->GetPointData()->AddArray(point1Array);
363 output->GetPointData()->AddArray(point2Array);
365 outputPoints->Delete();
366 outputVerts->Delete();
367 outputNormals->Delete();
368 outputRadius->Delete();
369 point1Array->Delete();
370 point2Array->Delete();
371 boundaryExtractor->Delete();