205{
206 vtkDataArray* radiusArray;
207 vtkDataArray* groupIdsArray;
208 vtkDataArray* blankingArray;
209
213
214 vtkIdType point0Id, point1Id;
215
216 double point0[3];
217 double point1[3];
218
219 double radius0;
220 double radius1;
221
222 vtkPoints* bifurcationPoints = vtkPoints::New();
223 vtkDoubleArray* bifurcationRadii = vtkDoubleArray::New();
224
225 vtkIdList* groupCellIds = vtkIdList::New();
226
228 int i;
229 for (i=0; i<groupCellIds->GetNumberOfIds(); i++)
230 {
231 vtkIdType cellId = groupCellIds->GetId(i);
232 vtkCell* polyLine = input->GetCell(cellId);
233
234 if (polyLine->GetCellType() != VTK_LINE && polyLine->GetCellType() != VTK_POLY_LINE)
235 {
236 continue;
237 }
238
239 point0Id = polyLine->GetPointId(0);
240 input->GetPoint(point0Id,point0);
241 point1Id = polyLine->GetPointId(polyLine->GetNumberOfPoints()-1);
242 input->GetPoint(point1Id,point1);
243
244 bool skip = false;
245
246 for (int j=0; j<bifurcationPoints->GetNumberOfPoints(); j+=2)
247 {
248 if (vtkMath::Distance2BetweenPoints(point0,bifurcationPoints->GetPoint(j)) <
VTK_VMTK_DOUBLE_TOL &&
249 vtkMath::Distance2BetweenPoints(point1,bifurcationPoints->GetPoint(j+1)) <
VTK_VMTK_DOUBLE_TOL)
250 {
251 skip = true;
252 break;
253 }
254 }
255
256 if (skip)
257 {
258 continue;
259 }
260
261 radius0 = radiusArray->GetComponent(point0Id,0);
262 bifurcationPoints->InsertNextPoint(point0);
263 bifurcationRadii->InsertNextTuple1(radius0);
264
265 radius1 = radiusArray->GetComponent(point1Id,0);
266 bifurcationPoints->InsertNextPoint(point1);
267 bifurcationRadii->InsertNextTuple1(radius1);
268 }
269 groupCellIds->Delete();
270
271 int numberOfBifurcationPoints = bifurcationPoints->GetNumberOfPoints();
272
273 double bifurcationOrigin[3];
274 double bifurcationNormal[3];
275 double bifurcationUpNormal[3];
276
277 double point[3];
278 double radius;
279 double weight;
280 double weightSum;
281
282 bifurcationOrigin[0] = bifurcationOrigin[1] = bifurcationOrigin[2] = 0.0;
283 weightSum = 0.0;
284
285 for (i=0; i<numberOfBifurcationPoints; i++)
286 {
287 bifurcationPoints->GetPoint(i,point);
288 radius = bifurcationRadii->GetComponent(i,0);
289
290 weight = radius*radius;
291
292 bifurcationOrigin[0] += weight * point[0];
293 bifurcationOrigin[1] += weight * point[1];
294 bifurcationOrigin[2] += weight * point[2];
295
296 weightSum += weight;
297 }
298
299 bifurcationOrigin[0] /= weightSum;
300 bifurcationOrigin[1] /= weightSum;
301 bifurcationOrigin[2] /= weightSum;
302
303 vtkDoubleArray* bifurcationNormals = vtkDoubleArray::New();
304 bifurcationNormals->SetNumberOfComponents(3);
305
306 vtkPoints* vertexPoints = vtkPoints::New();
307
308 for (i=0; i<numberOfBifurcationPoints; i+=2)
309 {
310 for (int j=i+2; j<numberOfBifurcationPoints; j+=2)
311 {
312 if (j==i)
313 {
314 continue;
315 }
316
317 vertexPoints->Initialize();
318
319 bifurcationPoints->GetPoint(i,point0);
320 bifurcationPoints->GetPoint(j,point1);
322 {
323 vertexPoints->InsertPoint(0,bifurcationPoints->GetPoint(i));
324 vertexPoints->InsertPoint(1,bifurcationPoints->GetPoint(i+1));
325 vertexPoints->InsertPoint(2,bifurcationPoints->GetPoint(j+1));
326 }
327 else
328 {
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));
333 }
334
335 int numberOfPolygonPoints = vertexPoints->GetNumberOfPoints();
336 double vertexPoint0[3], vertexPoint1[3], vertexPoint2[3];
337 double vertexNormal[3];
338 double cotangent0, cotangent1;
339
340 double polygonNormal[3];
341 polygonNormal[0] = polygonNormal[1] = polygonNormal[2] = 0.0;
342
343 for (int n=0; n<numberOfPolygonPoints; n++)
344 {
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);
351
352 vtkTriangle::ComputeNormal(vertexPoint0,vertexPoint1,vertexPoint2,vertexNormal);
353
356
357 weight = (cotangent0 + cotangent1) / vtkMath::Distance2BetweenPoints(bifurcationOrigin,vertexPoint1);
358
359 for (int k=0; k<3; k++)
360 {
361 polygonNormal[k] += weight * vertexNormal[k];
362 }
363 }
364
365 vtkMath::Normalize(polygonNormal);
366
367 bifurcationNormals->InsertNextTuple(polygonNormal);
368 }
369 }
370
371 if (bifurcationNormals->GetNumberOfTuples() == 0)
372 {
373 if (bifurcationPoints->GetNumberOfPoints() > 1)
374 {
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);
382
383 double lineNormal[3], dummy[3];
384 vtkMath::Perpendiculars(lineUpNormal,lineNormal,dummy,0.0);
385
386 outputPoints->InsertNextPoint(bifurcationOrigin);
387 normalArray->InsertNextTuple(lineNormal);
388 upNormalArray->InsertNextTuple(lineUpNormal);
389 referenceGroupIdsArray->InsertNextTuple1(referenceGroupId);
390 }
391
392 vertexPoints->Delete();
393 bifurcationPoints->Delete();
394 bifurcationRadii->Delete();
395 bifurcationNormals->Delete();
396
397 return;
398 }
399
400 int numberOfNormals = bifurcationNormals->GetNumberOfTuples();
401
402 double positiveNormal[3], orientedNormal[3];
403 bifurcationNormals->GetTuple(0,positiveNormal);
404
405 for (i=1; i<numberOfNormals; i++)
406 {
407 bifurcationNormals->GetTuple(i,orientedNormal);
408
409 if (vtkMath::Dot(positiveNormal,orientedNormal) < 0.0)
410 {
411 orientedNormal[0] *= -1.0;
412 orientedNormal[1] *= -1.0;
413 orientedNormal[2] *= -1.0;
414 bifurcationNormals->SetTuple(i,orientedNormal);
415 }
416 }
417
418 bifurcationNormal[0] = bifurcationNormal[1] = bifurcationNormal[2] = 0.0;
419
420 for (i=0; i<numberOfNormals; i++)
421 {
422 bifurcationNormals->GetTuple(i,orientedNormal);
423 for (int k=0; k<3; k++)
424 {
425 bifurcationNormal[k] += orientedNormal[k];
426 }
427 }
428
429 vtkMath::Normalize(bifurcationNormal);
430
431 bifurcationUpNormal[0] = bifurcationUpNormal[1] = bifurcationUpNormal[2] = 0.0;
432 double upVector[3], projectedUpVector[3];
433
434 weightSum = 0.0;
435 for (i=0; i<numberOfBifurcationPoints; i+=2)
436 {
437 bifurcationPoints->GetPoint(i+1,point1);
438 bifurcationPoints->GetPoint(i,point0);
439 radius0 = bifurcationRadii->GetTuple1(i);
440 radius1 = bifurcationRadii->GetTuple1(i+1);
441
442
443
444 weight = radius1 * radius1;
445 int k;
446 for (k=0; k<3; k++)
447 {
448 upVector[k] = point1[k] - point0[k];
449 }
450 double dot = vtkMath::Dot(upVector,bifurcationNormal);
451 for (k=0; k<3; k++)
452 {
453 projectedUpVector[k] = upVector[k] - dot * bifurcationNormal[k];
454 }
455 vtkMath::Normalize(projectedUpVector);
456 for (k=0; k<3; k++)
457 {
458 bifurcationUpNormal[k] += projectedUpVector[k] * weight;
459 }
460 weightSum += weight;
461 }
462
463 vtkMath::Normalize(bifurcationUpNormal);
464
465 outputPoints->InsertNextPoint(bifurcationOrigin);
466 normalArray->InsertNextTuple(bifurcationNormal);
467 upNormalArray->InsertNextTuple(bifurcationUpNormal);
468 referenceGroupIdsArray->InsertNextTuple1(referenceGroupId);
469
470 vertexPoints->Delete();
471 bifurcationPoints->Delete();
472 bifurcationRadii->Delete();
473 bifurcationNormals->Delete();
474}
static void GetGroupUniqueCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static double Cotangent(double point0[3], double point1[3], double point2[3])
#define VTK_VMTK_DOUBLE_TOL