MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / NthPoint

Method NthPoint

annotation/psimpl.h:491–519  ·  view source on GitHub ↗

! \brief Performs the nth point routine (NP). NP is an O(n) algorithm for polyline simplification. It keeps only the first, last and each nth point. As an example, consider any random line of 8 points. Using n = 3 will always yield a simplification consisting of points: 1, 4, 7, 8 \image html psimpl_np.png NP is ap

Source from the content-addressed store, hash-verified

489 \return one beyond the last coordinate of the simplified polyline
490 */
491 OutputIterator NthPoint (
492 InputIterator first,
493 InputIterator last,
494 unsigned n,
495 OutputIterator result)
496 {
497 diff_type coordCount = std::distance (first, last);
498 diff_type pointCount = DIM // protect against zero DIM
499 ? coordCount / DIM
500 : 0;
501
502 // validate input and check if simplification required
503 if (coordCount % DIM || pointCount < 3 || n < 2) {
504 return std::copy (first, last, result);
505 }
506
507 unsigned remaining = pointCount - 1; // the number of points remaining after key
508 InputIterator key = first; // indicates the current key
509
510 // the first point is always part of the simplification
511 CopyKey (key, result);
512
513 // copy each nth point
514 while (Forward (key, n, remaining)) {
515 CopyKey (key, result);
516 }
517
518 return result;
519 }
520
521 /*!
522 \brief Performs the (radial) distance between points routine (RD).

Callers 1

simplify_nth_pointFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected