Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
tesseract::CharAltList Class Reference

`#include <char_altlist.h>`

Inheritance diagram for tesseract::CharAltList:

List of all members.

## 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.

: AltList(max_alt) {
char_set_ = char_set;
max_alt_ = max_alt;
class_id_alt_ = NULL;
class_id_cost_ = NULL;
}

tesseract::CharAltList::~CharAltList | ( |  | ) |

Definition at line 34 of file char_altlist.cpp.

{
if (class_id_alt_ != NULL) {
delete []class_id_alt_;
class_id_alt_ = NULL;
}
if (class_id_cost_ != NULL) {
delete []class_id_cost_;
class_id_cost_ = NULL;
}
}

## Member Function Documentation

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;
}
}
}
}

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

- /mnt/data/src/tesseract-ocr/cube/char_altlist.h
- /mnt/data/src/tesseract-ocr/cube/char_altlist.cpp