/** * Given a track, fill the track with valid section * @param ut :: Initial track * @return Number of segments added */ int MeshObject2D::interceptSurface(Geometry::Track &ut) const { int originalCount = ut.count(); // Number of intersections original track const auto &norm = m_planeParameters.normal; auto t = -(ut.startPoint().scalar_prod(norm) + m_planeParameters.p0.scalar_prod(norm)) / ut.direction().scalar_prod(norm); // Intersects infinite plane. No point evaluating individual segements if this // fails if (t >= 0) { Kernel::V3D intersection; int entryExit; for (size_t i = 0; i < m_vertices.size(); i += 3) { if (MeshObjectCommon::rayIntersectsTriangle( ut.startPoint(), ut.direction(), m_vertices[i], m_vertices[i + 1], m_vertices[i + 2], intersection, entryExit)) { ut.addPoint(entryExit, intersection, *this); ut.buildLink(); // All vertices on plane. So only one triangle intersection possible break; } } } return ut.count() - originalCount; }
/** * Given a track, fill the track with valid section * @param UT :: Initial track * @return Number of segments added */ int MeshObject::interceptSurface(Geometry::Track &UT) const { int originalCount = UT.count(); // Number of intersections original track BoundingBox bb = getBoundingBox(); if (!bb.doesLineIntersect(UT)) { return 0; } std::vector<Kernel::V3D> intersectionPoints; std::vector<TrackDirection> entryExit; getIntersections(UT.startPoint(), UT.direction(), intersectionPoints, entryExit); if (intersectionPoints.empty()) return 0; // Quit if no intersections found // For a 3D mesh, a ray may intersect several segments for (size_t i = 0; i < intersectionPoints.size(); ++i) { UT.addPoint(entryExit[i], intersectionPoints[i], *this); } UT.buildLink(); return UT.count() - originalCount; }