------------------------------------------------------------------------------
| 286 | |
| 287 | //------------------------------------------------------------------------------ |
| 288 | int vtkCell::Inflate(double dist) |
| 289 | { |
| 290 | if (this->GetNumberOfFaces() != 0) |
| 291 | { |
| 292 | vtkWarningMacro(<< "Base version of vtkCell::Inflate only implements cell inflation" |
| 293 | << " for linear non 3D cells. Class " << this->GetClassName() |
| 294 | << " needs to overload this method. Ignoring this cell."); |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | // Strategy: |
| 299 | // For each point, store in a buffer its inflated position by moving each |
| 300 | // incident edge their normal direction by a distance of dist. This new |
| 301 | // position is done by solving a linear system of equation (intersection of 2 |
| 302 | // lines). |
| 303 | |
| 304 | auto pointRange = vtk::DataArrayTupleRange<3>(this->Points->GetData()); |
| 305 | using ConstTupleRef = typename decltype(pointRange)::ConstTupleReferenceType; |
| 306 | using TupleRef = typename decltype(pointRange)::TupleReferenceType; |
| 307 | using ConstScalar = typename ConstTupleRef::value_type; |
| 308 | using Scalar = typename TupleRef::value_type; |
| 309 | |
| 310 | std::vector<Scalar> buf(3 * pointRange.size()); |
| 311 | |
| 312 | Scalar normal[3]; |
| 313 | vtkPolygon::ComputeNormal(this->Points, normal); |
| 314 | |
| 315 | // Matrix transforming the 3D world into a 2D space |
| 316 | // used for solving line intersection. |
| 317 | // 2x3 matrix |
| 318 | Scalar basis[6]; |
| 319 | |
| 320 | // This will be used to store consecutive edge line equations |
| 321 | // 2x2 matrix |
| 322 | Scalar normals2D[4]; |
| 323 | |
| 324 | Scalar edgeNormal3D[3]; |
| 325 | |
| 326 | // Offset of the corresponding edge line equations in normals2D, shifted by |
| 327 | // dist |
| 328 | Scalar y[2]; |
| 329 | |
| 330 | // Intersection coordinates in 2D basis normals2D of the intersection between |
| 331 | // edges |
| 332 | Scalar x[2]; |
| 333 | |
| 334 | // Current index in normals2D and y. At each iteration, it binary swaps |
| 335 | int baseId = 1; |
| 336 | |
| 337 | { |
| 338 | ConstTupleRef p1 = pointRange[this->Points->GetNumberOfPoints() - 1], p2 = pointRange[0]; |
| 339 | |
| 340 | // We do not support the case of collapsed edges |
| 341 | if (vtkMathUtilities::NearlyEqual<ConstScalar>(p1[0], p2[0]) && |
| 342 | vtkMathUtilities::NearlyEqual<ConstScalar>(p1[1], p2[1]) && |
| 343 | vtkMathUtilities::NearlyEqual<ConstScalar>(p1[2], p2[2])) |
| 344 | { |
| 345 | return 0; |