Tesseract
3.02
|
#include <char_altlist.h>
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) |
Definition at line 32 of file char_altlist.h.
tesseract::CharAltList::CharAltList | ( | const CharSet * | char_set, |
int | max_alt = kMaxCharAlt |
||
) |
tesseract::CharAltList::~CharAltList | ( | ) |
int tesseract::CharAltList::Alt | ( | int | alt_idx | ) | const [inline] |
Definition at line 51 of file char_altlist.h.
{ return class_id_alt_[alt_idx]; }
int tesseract::CharAltList::ClassCost | ( | int | class_id | ) | const [inline] |
Definition at line 42 of file char_altlist.h.
{ if (class_id_cost_ == NULL || class_id < 0 || class_id >= char_set_->ClassCount()) { return WORST_COST; } return class_id_cost_[class_id]; }
bool tesseract::CharAltList::Insert | ( | int | class_id, |
int | cost, | ||
void * | tag = NULL |
||
) |
Definition at line 47 of file char_altlist.cpp.
{ // validate class ID if (class_id < 0 || class_id >= char_set_->ClassCount()) { return false; } // allocate buffers if nedded if (class_id_alt_ == NULL || alt_cost_ == NULL) { class_id_alt_ = new int[max_alt_]; alt_cost_ = new int[max_alt_]; alt_tag_ = new void *[max_alt_]; if (class_id_alt_ == NULL || alt_cost_ == NULL || alt_tag_ == NULL) { return false; } memset(alt_tag_, 0, max_alt_ * sizeof(*alt_tag_)); } if (class_id_cost_ == NULL) { int class_cnt = char_set_->ClassCount(); class_id_cost_ = new int[class_cnt]; if (class_id_cost_ == NULL) { return false; } for (int ich = 0; ich < class_cnt; ich++) { class_id_cost_[ich] = WORST_COST; } } if (class_id < 0 || class_id >= char_set_->ClassCount()) { return false; } // insert the alternate class_id_alt_[alt_cnt_] = class_id; alt_cost_[alt_cnt_] = cost; alt_tag_[alt_cnt_] = tag; alt_cnt_++; class_id_cost_[class_id] = cost; return true; }
void tesseract::CharAltList::SetAltCost | ( | int | alt_idx, |
int | cost | ||
) | [inline] |
Definition at line 53 of file char_altlist.h.
{ alt_cost_[alt_idx] = cost; class_id_cost_[class_id_alt_[alt_idx]] = cost; }
void tesseract::CharAltList::Sort | ( | ) | [virtual] |
Implements tesseract::AltList.
Definition at line 96 of file char_altlist.cpp.
{ for (int alt_idx = 0; alt_idx < alt_cnt_; alt_idx++) { for (int alt = alt_idx + 1; alt < alt_cnt_; alt++) { if (alt_cost_[alt_idx] > alt_cost_[alt]) { int temp = class_id_alt_[alt_idx]; class_id_alt_[alt_idx] = class_id_alt_[alt]; class_id_alt_[alt] = temp; temp = alt_cost_[alt_idx]; alt_cost_[alt_idx] = alt_cost_[alt]; alt_cost_[alt] = temp; void *tag = alt_tag_[alt_idx]; alt_tag_[alt_idx] = alt_tag_[alt]; alt_tag_[alt] = tag; } } } }