| 364 | } |
| 365 | |
| 366 | void vtkBundlingMetadata::SimulateEdgeStep() |
| 367 | { |
| 368 | vtkIdType numEdges = this->Graph->GetNumberOfEdges(); |
| 369 | |
| 370 | for (vtkIdType e1 = 0; e1 < numEdges; ++e1) |
| 371 | { |
| 372 | float weight1 = 1.0f; |
| 373 | for (int m1 = 0; m1 < this->MeshCount; ++m1) |
| 374 | { |
| 375 | // Immovable |
| 376 | if (m1 <= 0 || m1 >= this->MeshCount - 1) |
| 377 | { |
| 378 | continue; |
| 379 | } |
| 380 | |
| 381 | // Move the point according to dynamics |
| 382 | vtkVector3f position = this->EdgeMesh[e1][m1]; |
| 383 | vtkVector3f velocity = this->EdgeMeshVelocities[e1][m1]; |
| 384 | vtkVector3f acceleration = this->EdgeMeshAccelerations[e1][m1]; |
| 385 | velocity = velocity + acceleration * this->SimulationStep * 0.5f; |
| 386 | velocity = velocity * this->VelocityDamping; |
| 387 | position = position + velocity * this->SimulationStep; |
| 388 | this->EdgeMesh[e1][m1] = position; |
| 389 | |
| 390 | acceleration = vtkVector3f(0.0f, 0.0f, 0.0f); |
| 391 | |
| 392 | // Spring force |
| 393 | vtkVector3f prevPosition = this->EdgeMesh[e1][m1 - 1]; |
| 394 | vtkVector3f prevDirection = prevPosition - position; |
| 395 | float prevDist = prevDirection.Norm(); |
| 396 | float prevForce = |
| 397 | this->EdgeSpringConstant / 1000.0f * (this->MeshCount - 1) * prevDist * weight1; |
| 398 | prevDirection.Normalize(); |
| 399 | acceleration = acceleration + prevForce * prevDirection; |
| 400 | |
| 401 | vtkVector3f nextPosition = this->EdgeMesh[e1][m1 + 1]; |
| 402 | vtkVector3f nextDirection = nextPosition - position; |
| 403 | float nextDist = nextDirection.Norm(); |
| 404 | float nextForce = |
| 405 | this->EdgeSpringConstant / 1000.0f * (this->MeshCount - 1) * nextDist * weight1; |
| 406 | nextDirection.Normalize(); |
| 407 | acceleration = acceleration + nextForce * nextDirection; |
| 408 | |
| 409 | // Coulomb force |
| 410 | float normalizedEdgeCoulombConstant = |
| 411 | this->EdgeCoulombConstant / sqrt(static_cast<float>(numEdges)); |
| 412 | |
| 413 | for (vtkIdType e2 = 0; e2 < numEdges; ++e2) |
| 414 | { |
| 415 | if (e1 == e2) |
| 416 | { |
| 417 | continue; |
| 418 | } |
| 419 | |
| 420 | float compatibility = this->EdgeCompatibilities[e1][e2]; |
| 421 | if (compatibility <= 0.05) |
| 422 | { |
| 423 | continue; |
no test coverage detected