src/ccstruct/detlinefit.cpp
double DetLineFit::ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist,
                                  bool debug, ICOORD *line_pt) {
  ComputeConstrainedDistances(direction, min_dist, max_dist);
  // Do something sensible with no points or computed distances.
  if (pts_.empty() || distances_.empty()) {
    line_pt->set_x(0);
    line_pt->set_y(0);
    return 0.0;
  }
  auto median_index = distances_.size() / 2;
  std::nth_element(distances_.begin(), distances_.begin() + median_index, distances_.end());
  *line_pt = distances_[median_index].data();
  if (debug) {
    tprintf("Constrained fit to dir %g, %g = %d, %d :%zu distances:\n", direction.x(), direction.y(),
            line_pt->x(), line_pt->y(), distances_.size());
    for (unsigned i = 0; i < distances_.size(); ++i) {
      tprintf("%d: %d, %d -> %g\n", i, distances_[i].data().x(), distances_[i].data().y(),
              distances_[i].key());
    }
    tprintf("Result = %zu\n", median_index);
  }
  // Center distances on the fitted point.
  double dist_origin = direction * *line_pt;
  for (auto &distance : distances_) {
    distance.key() -= dist_origin;
  }
  return sqrt(EvaluateLineFit());
}
// Constrained fit with a supplied direction vector. Finds the best line_pt,
// that is one of the supplied points having the median cross product with
// direction, ignoring points that have a cross product outside of the range
// [min_dist, max_dist]. Returns the resulting error metric using the same
// reduced set of points.
// *Makes use of floating point arithmetic*
Constrained fit with a supplied direction vector. Finds the best line_pt,
that is one of the supplied points having the median cross product with
direction, ignoring points that have a cross product outside of the range
[min_dist, max_dist]. Returns the resulting error metric using the same
reduced set of points.
Makes use of floating point arithmetic
Constrained fit with a supplied direction vector . Finds the best line_pt that is one of the supplied points having the median cross product with direction ignoring points that have a cross product outside of the range [ min_dist max_dist ] . Returns the resulting error metric using the same reduced set of points . Makes use of floating point arithmetic
double DetLineFit::ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist,
                                  bool debug, ICOORD *line_pt) {
  ComputeConstrainedDistances(direction, min_dist, max_dist);
  if (pts_.empty() || distances_.empty()) {
    line_pt->set_x(0);
    line_pt->set_y(0);
    return 0.0;
  }
  auto median_index = distances_.size() / 2;
  std::nth_element(distances_.begin(), distances_.begin() + median_index, distances_.end());
  *line_pt = distances_[median_index].data();
  if (debug) {
    tprintf("Constrained fit to dir %g, %g = %d, %d :%zu distances:\n", direction.x(), direction.y(),
            line_pt->x(), line_pt->y(), distances_.size());
    for (unsigned i = 0; i < distances_.size(); ++i) {
      tprintf("%d: %d, %d -> %g\n", i, distances_[i].data().x(), distances_[i].data().y(),
              distances_[i].key());
    }
    tprintf("Result = %zu\n", median_index);
  }
  double dist_origin = direction * *line_pt;
  for (auto &distance : distances_) {
    distance.key() -= dist_origin;
  }
  return sqrt(EvaluateLineFit());
}
double DetLineFit :: ConstrainedFit ( const FCOORD & direction , double min_dist , double max_dist , bool debug , ICOORD * line_pt ) { ComputeConstrainedDistances ( direction , min_dist , max_dist ) ; if ( pts_ . empty ( ) || distances_ . empty ( ) ) { line_pt -> set_x ( 0 ) ; line_pt -> set_y ( 0 ) ; return 0.0 ; } auto median_index = distances_ . size ( ) / 2 ; std :: nth_element ( distances_ . begin ( ) , distances_ . begin ( ) + median_index , distances_ . end ( ) ) ; * line_pt = distances_ [ median_index ] . data ( ) ; if ( debug ) { tprintf ( " \n " , direction . x ( ) , direction . y ( ) , line_pt -> x ( ) , line_pt -> y ( ) , distances_ . size ( ) ) ; for ( unsigned i = 0 ; i < distances_ . size ( ) ; ++ i ) { tprintf ( " \n " , i , distances_ [ i ] . data ( ) . x ( ) , distances_ [ i ] . data ( ) . y ( ) , distances_ [ i ] . key ( ) ) ; } tprintf ( " \n " , median_index ) ; } double dist_origin = direction * * line_pt ; for ( auto & distance : distances_ ) { distance . key ( ) -= dist_origin ; } return sqrt ( EvaluateLineFit ( ) ) ; }
Constrained fit with a supplied direction vector.
Constrained fit with a supplied direction vector .
// Do something sensible with no points or computed distances. // Center distances on the fitted point.