All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

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
#define NULL
Definition: host.h:144
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 }
#define NULL
Definition: host.h:144

Member Function Documentation

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]; }
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
#define NULL
Definition: host.h:144
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  if (class_id_alt_ == NULL || alt_cost_ == NULL || alt_tag_ == NULL) {
60  return false;
61  }
62 
63  memset(alt_tag_, 0, max_alt_ * sizeof(*alt_tag_));
64  }
65 
66  if (class_id_cost_ == NULL) {
67  int class_cnt = char_set_->ClassCount();
68 
69  class_id_cost_ = new int[class_cnt];
70  if (class_id_cost_ == NULL) {
71  return false;
72  }
73 
74  for (int ich = 0; ich < class_cnt; ich++) {
75  class_id_cost_[ich] = WORST_COST;
76  }
77  }
78 
79  if (class_id < 0 || class_id >= char_set_->ClassCount()) {
80  return false;
81  }
82 
83  // insert the alternate
84  class_id_alt_[alt_cnt_] = class_id;
85  alt_cost_[alt_cnt_] = cost;
86  alt_tag_[alt_cnt_] = tag;
87 
88  alt_cnt_++;
89 
90  class_id_cost_[class_id] = cost;
91 
92  return true;
93 }
#define WORST_COST
Definition: cube_const.h:30
void ** alt_tag_
Definition: altlist.h:57
int ClassCount() const
Definition: char_set.h:111
#define NULL
Definition: host.h:144
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  }
void tesseract::CharAltList::Sort ( )
virtual

Implements tesseract::AltList.

Definition at line 96 of file char_altlist.cpp.

96  {
97  for (int alt_idx = 0; alt_idx < alt_cnt_; alt_idx++) {
98  for (int alt = alt_idx + 1; alt < alt_cnt_; alt++) {
99  if (alt_cost_[alt_idx] > alt_cost_[alt]) {
100  int temp = class_id_alt_[alt_idx];
101  class_id_alt_[alt_idx] = class_id_alt_[alt];
102  class_id_alt_[alt] = temp;
103 
104  temp = alt_cost_[alt_idx];
105  alt_cost_[alt_idx] = alt_cost_[alt];
106  alt_cost_[alt] = temp;
107 
108  void *tag = alt_tag_[alt_idx];
109  alt_tag_[alt_idx] = alt_tag_[alt];
110  alt_tag_[alt] = tag;
111  }
112  }
113  }
114 }
void ** alt_tag_
Definition: altlist.h:57

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