Tesseract  3.02
tesseract::CharAltList Class Reference

#include <char_altlist.h>

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

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)

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: