tesseract  5.0.0-alpha-619-ge9db
tesseract::DPPoint Class Reference

#include <dppoint.h>

Public Types

using CostFunc = int64_t(DPPoint::*)(const DPPoint *)
 

Public Member Functions

 DPPoint ()
 
int64_t 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 59 of file dppoint.h.

Member Typedef Documentation

◆ CostFunc

using tesseract::DPPoint::CostFunc = int64_t (DPPoint::*)(const DPPoint*)

Definition at line 80 of file dppoint.h.

Constructor & Destructor Documentation

◆ DPPoint()

tesseract::DPPoint::DPPoint ( )
inline

Definition at line 82 of file dppoint.h.

85  :
86  // Code common to different cost functions.
87 
88  // Update the other members if the cost is lower.
89  void UpdateIfBetter(int64_t cost, int32_t steps, const DPPoint* prev,

Member Function Documentation

◆ AddLocalCost()

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

Definition at line 112 of file dppoint.h.

◆ best_prev()

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

Definition at line 109 of file dppoint.h.

◆ CostWithVariance()

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

Definition at line 85 of file dppoint.cpp.

87  {
88  if (cost < total_cost_) {
89  total_cost_ = cost;
90  total_steps_ = steps;
91  best_prev_ = prev;
92  n_ = n;
93  sig_x_ = sig_x;
94  sig_xsq_ = sig_xsq;
95  }
96 }
97 
98 } // namespace tesseract.

◆ Pathlength()

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

Definition at line 106 of file dppoint.h.

◆ Solve()

DPPoint * tesseract::DPPoint::Solve ( int  min_step,
int  max_step,
bool  debug,
CostFunc  cost_func,
int  size,
DPPoint points 
)
static

Definition at line 47 of file dppoint.cpp.

49  {
50  tprintf("At point %d, local cost=%d, total_cost=%d, steps=%d\n",
51  i, points[i].local_cost_, points[i].total_cost_,
52  points[i].total_steps_);
53  }
54  }
55  // Now find the end of the best path and return it.
56  int best_cost = points[size - 1].total_cost_;
57  int best_end = size - 1;
58  for (int end = best_end - 1; end >= size - min_step; --end) {
59  int cost = points[end].total_cost_;
60  if (cost < best_cost) {
61  best_cost = cost;
62  best_end = end;
63  }
64  }
65  return points + best_end;
66 }
67 
68 // A CostFunc that takes the variance of step into account in the cost.
69 int64_t DPPoint::CostWithVariance(const DPPoint* prev) {
70  if (prev == nullptr || prev == this) {
71  UpdateIfBetter(0, 1, nullptr, 0, 0, 0);
72  return 0;
73  }
74 
75  int delta = this - prev;
76  int32_t n = prev->n_ + 1;
77  int32_t sig_x = prev->sig_x_ + delta;
78  int64_t sig_xsq = prev->sig_xsq_ + delta * delta;
79  int64_t cost = (sig_xsq - sig_x * sig_x / n) / n;
80  cost += prev->total_cost_;
81  UpdateIfBetter(cost, prev->total_steps_ + 1, prev, n, sig_x, sig_xsq);
82  return cost;

◆ total_cost()

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

Definition at line 103 of file dppoint.h.


The documentation for this class was generated from the following files:
tesseract::DPPoint::DPPoint
DPPoint()
Definition: dppoint.h:82
tesseract::DPPoint::CostWithVariance
int64_t CostWithVariance(const DPPoint *prev)
Definition: dppoint.cpp:85
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34