tesseract  3.05.02
tesseract::CharAltList Class Reference

#include <char_altlist.h>

Inheritance diagram for tesseract::CharAltList:
tesseract::AltList

Public Member Functions

 CharAltList (const CharSet *char_set, int max_alt=kMaxCharAlt)
 
 ~CharAltList ()
 
void Sort ()
 
bool Insert (int class_id, int cost, void *tag=NULL)
 
int ClassCost (int class_id) const
 
int Alt (int alt_idx) const
 
void SetAltCost (int alt_idx, int cost)
 
- Public Member Functions inherited from tesseract::AltList
 AltList (int max_alt)
 
virtual ~AltList ()
 
int BestCost (int *best_alt) const
 
int AltCount () const
 
int AltCost (int alt_idx) const
 
double AltProb (int alt_idx) const
 
void * AltTag (int alt_idx) const
 

Additional Inherited Members

- Protected Attributes inherited from tesseract::AltList
int max_alt_
 
int alt_cnt_
 
int * alt_cost_
 
void ** alt_tag_
 

Detailed Description

Definition at line 32 of file char_altlist.h.

Constructor & Destructor Documentation

◆ CharAltList()

tesseract::CharAltList::CharAltList ( const CharSet char_set,
int  max_alt = kMaxCharAlt 
)

Definition at line 26 of file char_altlist.cpp.

27  : AltList(max_alt) {
28  char_set_ = char_set;
29  max_alt_ = max_alt;
30  class_id_alt_ = NULL;
31  class_id_cost_ = NULL;
32 }
AltList(int max_alt)
Definition: altlist.cpp:25

◆ ~CharAltList()

tesseract::CharAltList::~CharAltList ( )

Definition at line 34 of file char_altlist.cpp.

34  {
35  if (class_id_alt_ != NULL) {
36  delete []class_id_alt_;
37  class_id_alt_ = NULL;
38  }
39 
40  if (class_id_cost_ != NULL) {
41  delete []class_id_cost_;
42  class_id_cost_ = NULL;
43  }
44 }

Member Function Documentation

◆ Alt()

int tesseract::CharAltList::Alt ( int  alt_idx) const
inline

Definition at line 51 of file char_altlist.h.

51 { return class_id_alt_[alt_idx]; }

◆ ClassCost()

int tesseract::CharAltList::ClassCost ( int  class_id) const
inline

Definition at line 42 of file char_altlist.h.

42  {
43  if (class_id_cost_ == NULL ||
44  class_id < 0 ||
45  class_id >= char_set_->ClassCount()) {
46  return WORST_COST;
47  }
48  return class_id_cost_[class_id];
49  }
#define WORST_COST
Definition: cube_const.h:30
int ClassCount() const
Definition: char_set.h:111

◆ Insert()

bool tesseract::CharAltList::Insert ( int  class_id,
int  cost,
void *  tag = NULL 
)

Definition at line 47 of file char_altlist.cpp.

47  {
48  // validate class ID
49  if (class_id < 0 || class_id >= char_set_->ClassCount()) {
50  return false;
51  }
52 
53  // allocate buffers if nedded
54  if (class_id_alt_ == NULL || alt_cost_ == NULL) {
55  class_id_alt_ = new int[max_alt_];
56  alt_cost_ = new int[max_alt_];
57  alt_tag_ = new void *[max_alt_];
58 
59  memset(alt_tag_, 0, max_alt_ * sizeof(*alt_tag_));
60  }
61 
62  if (class_id_cost_ == NULL) {
63  int class_cnt = char_set_->ClassCount();
64 
65  class_id_cost_ = new int[class_cnt];
66 
67  for (int ich = 0; ich < class_cnt; ich++) {
68  class_id_cost_[ich] = WORST_COST;
69  }
70  }
71 
72  if (class_id < 0 || class_id >= char_set_->ClassCount()) {
73  return false;
74  }
75 
76  // insert the alternate
77  class_id_alt_[alt_cnt_] = class_id;
78  alt_cost_[alt_cnt_] = cost;
79  alt_tag_[alt_cnt_] = tag;
80 
81  alt_cnt_++;
82 
83  class_id_cost_[class_id] = cost;
84 
85  return true;
86 }
void ** alt_tag_
Definition: altlist.h:57
#define WORST_COST
Definition: cube_const.h:30
int ClassCount() const
Definition: char_set.h:111

◆ SetAltCost()

void tesseract::CharAltList::SetAltCost ( int  alt_idx,
int  cost 
)
inline

Definition at line 53 of file char_altlist.h.

53  {
54  alt_cost_[alt_idx] = cost;
55  class_id_cost_[class_id_alt_[alt_idx]] = cost;
56  }

◆ Sort()

void tesseract::CharAltList::Sort ( )
virtual

Implements tesseract::AltList.

Definition at line 89 of file char_altlist.cpp.

89  {
90  for (int alt_idx = 0; alt_idx < alt_cnt_; alt_idx++) {
91  for (int alt = alt_idx + 1; alt < alt_cnt_; alt++) {
92  if (alt_cost_[alt_idx] > alt_cost_[alt]) {
93  int temp = class_id_alt_[alt_idx];
94  class_id_alt_[alt_idx] = class_id_alt_[alt];
95  class_id_alt_[alt] = temp;
96 
97  temp = alt_cost_[alt_idx];
98  alt_cost_[alt_idx] = alt_cost_[alt];
99  alt_cost_[alt] = temp;
100 
101  void *tag = alt_tag_[alt_idx];
102  alt_tag_[alt_idx] = alt_tag_[alt];
103  alt_tag_[alt] = tag;
104  }
105  }
106  }
107 }
void ** alt_tag_
Definition: altlist.h:57

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