Tesseract  3.02
tesseract::DPPoint Class Reference

#include <dppoint.h>

List of all members.

Public Types

typedef inT64(DPPoint::* CostFunc )(const DPPoint *prev)

Public Member Functions

 DPPoint ()
inT64 CostWithVariance (const DPPoint *prev)
int total_cost () const
int Pathlength () const
const DPPointbest_prev () const
void AddLocalCost (int new_cost)

Static Public Member Functions

static DPPointSolve (int min_step, int max_step, bool debug, CostFunc cost_func, int size, DPPoint *points)

Detailed Description

Definition at line 44 of file dppoint.h.


Member Typedef Documentation

typedef inT64(DPPoint::* tesseract::DPPoint::CostFunc)(const DPPoint *prev)

Definition at line 49 of file dppoint.h.


Constructor & Destructor Documentation

tesseract::DPPoint::DPPoint ( ) [inline]

Definition at line 51 of file dppoint.h.

    : local_cost_(0), total_cost_(MAX_INT32), total_steps_(1), best_prev_(NULL),
      n_(0), sig_x_(0), sig_xsq_(0) {
  }

Member Function Documentation

void tesseract::DPPoint::AddLocalCost ( int  new_cost) [inline]

Definition at line 77 of file dppoint.h.

                                  {
    local_cost_ += new_cost;
  }
const DPPoint* tesseract::DPPoint::best_prev ( ) const [inline]

Definition at line 74 of file dppoint.h.

                                   {
    return best_prev_;
  }
inT64 tesseract::DPPoint::CostWithVariance ( const DPPoint prev)

Definition at line 68 of file dppoint.cpp.

                                                   {
  if (prev == NULL || prev == this) {
    UpdateIfBetter(0, 1, NULL, 0, 0, 0);
    return 0;
  }

  int delta = this - prev;
  inT32 n = prev->n_ + 1;
  inT32 sig_x = prev->sig_x_ + delta;
  inT64 sig_xsq = prev->sig_xsq_ + delta * delta;
  inT64 cost = (sig_xsq - sig_x * sig_x / n) / n;
  cost += prev->total_cost_;
  UpdateIfBetter(cost, prev->total_steps_ + 1, prev, n, sig_x, sig_xsq);
  return cost;
}
int tesseract::DPPoint::Pathlength ( ) const [inline]

Definition at line 71 of file dppoint.h.

                         {
    return total_steps_;
  }
DPPoint * tesseract::DPPoint::Solve ( int  min_step,
int  max_step,
bool  debug,
CostFunc  cost_func,
int  size,
DPPoint points 
) [static]

Definition at line 30 of file dppoint.cpp.

                                                                       {
  if (size <= 0 || max_step < min_step || min_step >= size)
    return NULL;  // Degenerate, but not necessarily an error.
  ASSERT_HOST(min_step > 0);  // Infinite loop possible if this is not true.
  if (debug)
    tprintf("min = %d, max=%d\n",
            min_step, max_step);
  // Evaluate the total cost at each point.
  for (int i = 0; i < size; ++i) {
    for (int offset = min_step; offset <= max_step; ++offset) {
      DPPoint* prev = offset <= i ? points + i - offset : NULL;
      inT64 new_cost = (points[i].*cost_func)(prev);
      if (points[i].best_prev_ != NULL && offset > min_step * 2 &&
          new_cost > points[i].total_cost_)
        break;  // Find only the first minimum if going over twice the min.
    }
    points[i].total_cost_ += points[i].local_cost_;
    if (debug) {
      tprintf("At point %d, local cost=%d, total_cost=%d, steps=%d\n",
              i, points[i].local_cost_, points[i].total_cost_,
              points[i].total_steps_);
    }
  }
  // Now find the end of the best path and return it.
  int best_cost = points[size - 1].total_cost_;
  int best_end = size - 1;
  for (int end = best_end - 1; end >= size - min_step; --end) {
    int cost = points[end].total_cost_;
    if (cost < best_cost) {
      best_cost = cost;
      best_end = end;
    }
  }
  return points + best_end;
}
int tesseract::DPPoint::total_cost ( ) const [inline]

Definition at line 68 of file dppoint.h.

                         {
    return total_cost_;
  }

The documentation for this class was generated from the following files: