88 vtkInformation *vtkNotUsed(request),
89 vtkInformationVector **inputVector,
90 vtkInformationVector *outputVector)
92 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
93 vtkInformation *outInfo = outputVector->GetInformationObject(0);
95 vtkPolyData *input = vtkPolyData::SafeDownCast(
96 inInfo->Get(vtkDataObject::DATA_OBJECT()));
97 vtkPolyData *output = vtkPolyData::SafeDownCast(
98 outInfo->Get(vtkDataObject::DATA_OBJECT()));
100 vtkDataArray* radiusArray;
101 vtkDataArray* groupIdsArray;
102 vtkDataArray* blankingArray;
106 vtkErrorMacro(<<
"RadiusArrayName not specified");
114 vtkErrorMacro(<<
"RadiusArray with name specified does not exist");
120 vtkErrorMacro(<<
"GroupIdsArrayName not specified");
126 if (!input->GetCellData()->GetArray(this->GroupIdsArrayName))
128 vtkErrorMacro(<<
"GroupIdsArray with name specified does not exist");
134 vtkErrorMacro(<<
"BlankingArrayName not specified");
140 if (!input->GetCellData()->GetArray(this->BlankingArrayName))
142 vtkErrorMacro(<<
"BlankingArray with name specified does not exist");
148 vtkErrorMacro(<<
"NormalArrayName not specified");
154 vtkErrorMacro(<<
"UpNormalArrayName not specified");
158 vtkPoints* outputPoints = vtkPoints::New();
160 vtkDoubleArray* normalArray = vtkDoubleArray::New();
162 normalArray->SetNumberOfComponents(3);
164 vtkDoubleArray* upNormalArray = vtkDoubleArray::New();
166 upNormalArray->SetNumberOfComponents(3);
168 vtkIntArray* referenceGroupIdsArray = vtkIntArray::New();
170 vtkIdList* blankedGroupIds = vtkIdList::New();
173 for (i=0; i<blankedGroupIds->GetNumberOfIds(); i++)
175 vtkIdType groupId = blankedGroupIds->GetId(i);
178 blankedGroupIds->Delete();
180 vtkCellArray* outputVertices = vtkCellArray::New();
182 int numberOfOutputPoints = outputPoints->GetNumberOfPoints();
183 for (i=0; i<numberOfOutputPoints; i++)
185 outputVertices->InsertNextCell(1);
186 outputVertices->InsertCellPoint(i);
189 output->SetPoints(outputPoints);
190 output->SetVerts(outputVertices);
191 output->GetPointData()->AddArray(normalArray);
192 output->GetPointData()->AddArray(upNormalArray);
193 output->GetPointData()->AddArray(referenceGroupIdsArray);
195 outputPoints->Delete();
196 outputVertices->Delete();
197 normalArray->Delete();
198 upNormalArray->Delete();
199 referenceGroupIdsArray->Delete();
206 vtkDataArray* radiusArray;
207 vtkDataArray* groupIdsArray;
208 vtkDataArray* blankingArray;
214 vtkIdType point0Id, point1Id;
222 vtkPoints* bifurcationPoints = vtkPoints::New();
223 vtkDoubleArray* bifurcationRadii = vtkDoubleArray::New();
225 vtkIdList* groupCellIds = vtkIdList::New();
229 for (i=0; i<groupCellIds->GetNumberOfIds(); i++)
231 vtkIdType cellId = groupCellIds->GetId(i);
232 vtkCell* polyLine = input->GetCell(cellId);
234 if (polyLine->GetCellType() != VTK_LINE && polyLine->GetCellType() != VTK_POLY_LINE)
239 point0Id = polyLine->GetPointId(0);
240 input->GetPoint(point0Id,point0);
241 point1Id = polyLine->GetPointId(polyLine->GetNumberOfPoints()-1);
242 input->GetPoint(point1Id,point1);
246 for (
int j=0; j<bifurcationPoints->GetNumberOfPoints(); j+=2)
248 if (vtkMath::Distance2BetweenPoints(point0,bifurcationPoints->GetPoint(j)) <
VTK_VMTK_DOUBLE_TOL &&
249 vtkMath::Distance2BetweenPoints(point1,bifurcationPoints->GetPoint(j+1)) <
VTK_VMTK_DOUBLE_TOL)
261 radius0 = radiusArray->GetComponent(point0Id,0);
262 bifurcationPoints->InsertNextPoint(point0);
263 bifurcationRadii->InsertNextTuple1(radius0);
265 radius1 = radiusArray->GetComponent(point1Id,0);
266 bifurcationPoints->InsertNextPoint(point1);
267 bifurcationRadii->InsertNextTuple1(radius1);
269 groupCellIds->Delete();
271 int numberOfBifurcationPoints = bifurcationPoints->GetNumberOfPoints();
273 double bifurcationOrigin[3];
274 double bifurcationNormal[3];
275 double bifurcationUpNormal[3];
282 bifurcationOrigin[0] = bifurcationOrigin[1] = bifurcationOrigin[2] = 0.0;
285 for (i=0; i<numberOfBifurcationPoints; i++)
287 bifurcationPoints->GetPoint(i,point);
288 radius = bifurcationRadii->GetComponent(i,0);
290 weight = radius*radius;
292 bifurcationOrigin[0] += weight * point[0];
293 bifurcationOrigin[1] += weight * point[1];
294 bifurcationOrigin[2] += weight * point[2];
299 bifurcationOrigin[0] /= weightSum;
300 bifurcationOrigin[1] /= weightSum;
301 bifurcationOrigin[2] /= weightSum;
303 vtkDoubleArray* bifurcationNormals = vtkDoubleArray::New();
304 bifurcationNormals->SetNumberOfComponents(3);
306 vtkPoints* vertexPoints = vtkPoints::New();
308 for (i=0; i<numberOfBifurcationPoints; i+=2)
310 for (
int j=i+2; j<numberOfBifurcationPoints; j+=2)
317 vertexPoints->Initialize();
319 bifurcationPoints->GetPoint(i,point0);
320 bifurcationPoints->GetPoint(j,point1);
323 vertexPoints->InsertPoint(0,bifurcationPoints->GetPoint(i));
324 vertexPoints->InsertPoint(1,bifurcationPoints->GetPoint(i+1));
325 vertexPoints->InsertPoint(2,bifurcationPoints->GetPoint(j+1));
329 vertexPoints->InsertPoint(0,bifurcationPoints->GetPoint(i));
330 vertexPoints->InsertPoint(1,bifurcationPoints->GetPoint(i+1));
331 vertexPoints->InsertPoint(2,bifurcationPoints->GetPoint(j+1));
332 vertexPoints->InsertPoint(3,bifurcationPoints->GetPoint(j));
335 int numberOfPolygonPoints = vertexPoints->GetNumberOfPoints();
336 double vertexPoint0[3], vertexPoint1[3], vertexPoint2[3];
337 double vertexNormal[3];
338 double cotangent0, cotangent1;
340 double polygonNormal[3];
341 polygonNormal[0] = polygonNormal[1] = polygonNormal[2] = 0.0;
343 for (
int n=0; n<numberOfPolygonPoints; n++)
345 vtkIdType vertexId0 = (n-1+numberOfPolygonPoints) % numberOfPolygonPoints;
346 vtkIdType vertexId1 = n;
347 vtkIdType vertexId2 = (n+1) % numberOfPolygonPoints;
348 vertexPoints->GetPoint(vertexId0,vertexPoint0);
349 vertexPoints->GetPoint(vertexId1,vertexPoint1);
350 vertexPoints->GetPoint(vertexId2,vertexPoint2);
352 vtkTriangle::ComputeNormal(vertexPoint0,vertexPoint1,vertexPoint2,vertexNormal);
357 weight = (cotangent0 + cotangent1) / vtkMath::Distance2BetweenPoints(bifurcationOrigin,vertexPoint1);
359 for (
int k=0; k<3; k++)
361 polygonNormal[k] += weight * vertexNormal[k];
365 vtkMath::Normalize(polygonNormal);
367 bifurcationNormals->InsertNextTuple(polygonNormal);
371 if (bifurcationNormals->GetNumberOfTuples() == 0)
373 if (bifurcationPoints->GetNumberOfPoints() > 1)
375 bifurcationPoints->GetPoint(1,point1);
376 bifurcationPoints->GetPoint(0,point0);
377 double lineUpNormal[3];
378 lineUpNormal[0] = point1[0] - point0[0];
379 lineUpNormal[1] = point1[1] - point0[1];
380 lineUpNormal[2] = point1[2] - point0[2];
381 vtkMath::Normalize(lineUpNormal);
383 double lineNormal[3], dummy[3];
384 vtkMath::Perpendiculars(lineUpNormal,lineNormal,dummy,0.0);
386 outputPoints->InsertNextPoint(bifurcationOrigin);
387 normalArray->InsertNextTuple(lineNormal);
388 upNormalArray->InsertNextTuple(lineUpNormal);
389 referenceGroupIdsArray->InsertNextTuple1(referenceGroupId);
392 vertexPoints->Delete();
393 bifurcationPoints->Delete();
394 bifurcationRadii->Delete();
395 bifurcationNormals->Delete();
400 int numberOfNormals = bifurcationNormals->GetNumberOfTuples();
402 double positiveNormal[3], orientedNormal[3];
403 bifurcationNormals->GetTuple(0,positiveNormal);
405 for (i=1; i<numberOfNormals; i++)
407 bifurcationNormals->GetTuple(i,orientedNormal);
409 if (vtkMath::Dot(positiveNormal,orientedNormal) < 0.0)
411 orientedNormal[0] *= -1.0;
412 orientedNormal[1] *= -1.0;
413 orientedNormal[2] *= -1.0;
414 bifurcationNormals->SetTuple(i,orientedNormal);
418 bifurcationNormal[0] = bifurcationNormal[1] = bifurcationNormal[2] = 0.0;
420 for (i=0; i<numberOfNormals; i++)
422 bifurcationNormals->GetTuple(i,orientedNormal);
423 for (
int k=0; k<3; k++)
425 bifurcationNormal[k] += orientedNormal[k];
429 vtkMath::Normalize(bifurcationNormal);
431 bifurcationUpNormal[0] = bifurcationUpNormal[1] = bifurcationUpNormal[2] = 0.0;
432 double upVector[3], projectedUpVector[3];
435 for (i=0; i<numberOfBifurcationPoints; i+=2)
437 bifurcationPoints->GetPoint(i+1,point1);
438 bifurcationPoints->GetPoint(i,point0);
439 radius0 = bifurcationRadii->GetTuple1(i);
440 radius1 = bifurcationRadii->GetTuple1(i+1);
444 weight = radius1 * radius1;
448 upVector[k] = point1[k] - point0[k];
450 double dot = vtkMath::Dot(upVector,bifurcationNormal);
453 projectedUpVector[k] = upVector[k] - dot * bifurcationNormal[k];
455 vtkMath::Normalize(projectedUpVector);
458 bifurcationUpNormal[k] += projectedUpVector[k] * weight;
463 vtkMath::Normalize(bifurcationUpNormal);
465 outputPoints->InsertNextPoint(bifurcationOrigin);
466 normalArray->InsertNextTuple(bifurcationNormal);
467 upNormalArray->InsertNextTuple(bifurcationUpNormal);
468 referenceGroupIdsArray->InsertNextTuple1(referenceGroupId);
470 vertexPoints->Delete();
471 bifurcationPoints->Delete();
472 bifurcationRadii->Delete();
473 bifurcationNormals->Delete();