tesseract  4.00.00dev
tesseract::DPPoint Class Reference

#include <dppoint.h>

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

◆ CostFunc

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

Definition at line 49 of file dppoint.h.

Constructor & Destructor Documentation

◆ DPPoint()

tesseract::DPPoint::DPPoint ( )
inline

Definition at line 51 of file dppoint.h.

52  : local_cost_(0), total_cost_(MAX_INT32), total_steps_(1), best_prev_(NULL),
53  n_(0), sig_x_(0), sig_xsq_(0) {
54  }
#define MAX_INT32
Definition: host.h:62

Member Function Documentation

◆ AddLocalCost()

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

Definition at line 77 of file dppoint.h.

77  {
78  local_cost_ += new_cost;
79  }

◆ best_prev()

const DPPoint* tesseract::DPPoint::best_prev ( ) const
inline

Definition at line 74 of file dppoint.h.

74  {
75  return best_prev_;
76  }

◆ CostWithVariance()

inT64 tesseract::DPPoint::CostWithVariance ( const DPPoint prev)

Definition at line 68 of file dppoint.cpp.

68  {
69  if (prev == NULL || prev == this) {
70  UpdateIfBetter(0, 1, NULL, 0, 0, 0);
71  return 0;
72  }
73 
74  int delta = this - prev;
75  inT32 n = prev->n_ + 1;
76  inT32 sig_x = prev->sig_x_ + delta;
77  inT64 sig_xsq = prev->sig_xsq_ + delta * delta;
78  inT64 cost = (sig_xsq - sig_x * sig_x / n) / n;
79  cost += prev->total_cost_;
80  UpdateIfBetter(cost, prev->total_steps_ + 1, prev, n, sig_x, sig_xsq);
81  return cost;
82 }
int64_t inT64
Definition: host.h:40
int32_t inT32
Definition: host.h:38

◆ Pathlength()

int tesseract::DPPoint::Pathlength ( ) const
inline

Definition at line 71 of file dppoint.h.

71  {
72  return total_steps_;
73  }

◆ Solve()

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.

31  {
32  if (size <= 0 || max_step < min_step || min_step >= size)
33  return NULL; // Degenerate, but not necessarily an error.
34  ASSERT_HOST(min_step > 0); // Infinite loop possible if this is not true.
35  if (debug)
36  tprintf("min = %d, max=%d\n",
37  min_step, max_step);
38  // Evaluate the total cost at each point.
39  for (int i = 0; i < size; ++i) {
40  for (int offset = min_step; offset <= max_step; ++offset) {
41  DPPoint* prev = offset <= i ? points + i - offset : NULL;
42  inT64 new_cost = (points[i].*cost_func)(prev);
43  if (points[i].best_prev_ != NULL && offset > min_step * 2 &&
44  new_cost > points[i].total_cost_)
45  break; // Find only the first minimum if going over twice the min.
46  }
47  points[i].total_cost_ += points[i].local_cost_;
48  if (debug) {
49  tprintf("At point %d, local cost=%d, total_cost=%d, steps=%d\n",
50  i, points[i].local_cost_, points[i].total_cost_,
51  points[i].total_steps_);
52  }
53  }
54  // Now find the end of the best path and return it.
55  int best_cost = points[size - 1].total_cost_;
56  int best_end = size - 1;
57  for (int end = best_end - 1; end >= size - min_step; --end) {
58  int cost = points[end].total_cost_;
59  if (cost < best_cost) {
60  best_cost = cost;
61  best_end = end;
62  }
63  }
64  return points + best_end;
65 }
int64_t inT64
Definition: host.h:40
voidpf void uLong size
Definition: ioapi.h:39
#define tprintf(...)
Definition: tprintf.h:31
voidpf uLong offset
Definition: ioapi.h:42
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ total_cost()

int tesseract::DPPoint::total_cost ( ) const
inline

Definition at line 68 of file dppoint.h.

68  {
69  return total_cost_;
70  }

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