Foam::point Foam::polyLine::position ( const label segment, const scalar mu ) const { // out-of-bounds if (segment < 0) { return points_[0]; } else if (segment > nSegments()) { return points_[points_.size()-1]; } const point& p0 = points()[segment]; const point& p1 = points()[segment+1]; // special cases - no calculation needed if (mu <= 0.0) { return p0; } else if (mu >= 1.0) { return p1; } else { // linear interpolation return points_[segment] + mu * (p1 - p0); } }
Foam::label Foam::polyLine::localParameter(scalar& lambda) const { // check endpoints if (lambda < SMALL) { lambda = 0; return 0; } else if (lambda > 1 - SMALL) { lambda = 1; return nSegments(); } // search table of cumulative distances to find which line-segment // we are on. Check the upper bound. label segmentI = 1; while (param_[segmentI] < lambda) { segmentI++; } segmentI--; // we want the corresponding lower bound // the local parameter [0-1] on this line segment lambda = ( ( lambda - param_[segmentI] ) / ( param_[segmentI+1] - param_[segmentI] ) ); return segmentI; }
/** * Returns list of segments that are not empty. */ std::vector<UInt> getNonEmptySegList() const { std::vector<UInt> non_empties; for (UInt i = 0; i != _segments.size(); ++i) if (!_segments[i].empty()) non_empties.push_back(i); NTA_ASSERT(non_empties.size() == nSegments()); return non_empties; }
Foam::point Foam::CatmullRomSpline::position ( const label segment, const scalar mu ) const { // out-of-bounds if (segment < 0) { return points()[0]; } else if (segment > nSegments()) { return points()[points().size()-1]; } const point& p0 = points()[segment]; const point& p1 = points()[segment+1]; // special cases - no calculation needed if (mu <= 0.0) { return p0; } else if (mu >= 1.0) { return p1; } // determine the end points point e0; point e1; if (segment == 0) { // end: simple reflection e0 = 2*p0 - p1; } else { e0 = points()[segment-1]; } if (segment+1 == nSegments()) { // end: simple reflection e1 = 2*p1 - p0; } else { e1 = points()[segment+2]; } return 0.5 * ( ( 2*p0 ) + mu * ( ( -e0 + p1 ) + mu * ( ( 2*e0 - 5*p0 + 4*p1 - e1 ) + mu * ( -e0 + 3*p0 - 3*p1 + e1 ) ) ) ); }