#include <shapetable.h>
List of all members.
Public Member Functions |
| ShapeTable () |
| ShapeTable (const UNICHARSET &unicharset) |
bool | Serialize (FILE *fp) const |
bool | DeSerialize (bool swap, FILE *fp) |
int | NumShapes () const |
const UNICHARSET & | unicharset () const |
void | set_unicharset (const UNICHARSET &unicharset) |
STRING | DebugStr (int shape_id) const |
STRING | SummaryStr () const |
int | AddShape (int unichar_id, int font_id) |
int | AddShape (const Shape &other) |
void | DeleteShape (int shape_id) |
void | AddToShape (int shape_id, int unichar_id, int font_id) |
void | AddShapeToShape (int shape_id, const Shape &other) |
int | FindShape (int unichar_id, int font_id) const |
void | GetFirstUnicharAndFont (int shape_id, int *unichar_id, int *font_id) const |
const Shape & | GetShape (int shape_id) const |
Shape * | MutableShape (int shape_id) |
int | BuildFromShape (const Shape &shape, const ShapeTable &master_shapes) |
bool | AlreadyMerged (int shape_id1, int shape_id2) const |
bool | AnyMultipleUnichars () const |
int | MaxNumUnichars () const |
void | ForceFontMerges (int start, int end) |
int | MasterUnicharCount (int shape_id) const |
int | MasterFontCount (int shape_id) const |
int | MergedUnicharCount (int shape_id1, int shape_id2) const |
void | MergeShapes (int shape_id1, int shape_id2) |
void | AppendMasterShapes (const ShapeTable &other) |
int | NumMasterShapes () const |
int | MasterDestinationIndex (int shape_id) const |
Detailed Description
Definition at line 126 of file shapetable.h.
Constructor & Destructor Documentation
tesseract::ShapeTable::ShapeTable |
( |
| ) |
|
tesseract::ShapeTable::ShapeTable |
( |
const UNICHARSET & |
unicharset | ) |
|
|
explicit |
Member Function Documentation
int tesseract::ShapeTable::AddShape |
( |
int |
unichar_id, |
|
|
int |
font_id |
|
) |
| |
Definition at line 249 of file shapetable.cpp.
{
int index = shape_table_.
size();
Shape* shape = new Shape;
shape->AddToShape(unichar_id, font_id);
return index;
}
int tesseract::ShapeTable::AddShape |
( |
const Shape & |
other | ) |
|
Definition at line 259 of file shapetable.cpp.
{
int index = shape_table_.
size();
Shape* shape = new Shape(other);
return index;
}
void tesseract::ShapeTable::AddShapeToShape |
( |
int |
shape_id, |
|
|
const Shape & |
other |
|
) |
| |
Definition at line 281 of file shapetable.cpp.
{
Shape& shape = *shape_table_[shape_id];
shape.AddShape(other);
}
void tesseract::ShapeTable::AddToShape |
( |
int |
shape_id, |
|
|
int |
unichar_id, |
|
|
int |
font_id |
|
) |
| |
Definition at line 275 of file shapetable.cpp.
{
Shape& shape = *shape_table_[shape_id];
shape.AddToShape(unichar_id, font_id);
}
bool tesseract::ShapeTable::AlreadyMerged |
( |
int |
shape_id1, |
|
|
int |
shape_id2 |
|
) |
| const |
bool tesseract::ShapeTable::AnyMultipleUnichars |
( |
| ) |
const |
Definition at line 347 of file shapetable.cpp.
{
for (int s1 = 0; s1 < num_shapes; ++s1) {
return true;
}
return false;
}
void tesseract::ShapeTable::AppendMasterShapes |
( |
const ShapeTable & |
other | ) |
|
Definition at line 439 of file shapetable.cpp.
{
for (int s = 0; s < other.shape_table_.size(); ++s) {
if (other.shape_table_[s]->destination_index() < 0) {
}
}
}
int tesseract::ShapeTable::BuildFromShape |
( |
const Shape & |
shape, |
|
|
const ShapeTable & |
master_shapes |
|
) |
| |
Definition at line 317 of file shapetable.cpp.
{
int num_masters = 0;
for (int u_ind = 0; u_ind < shape.size(); ++u_ind) {
for (int f_ind = 0; f_ind < shape[u_ind].font_ids.size(); ++f_ind) {
int c = shape[u_ind].unichar_id;
int f = shape[u_ind].font_ids[f_ind];
int master_id = master_shapes.FindShape(c, f);
if (master_id >= 0 && shape.size() > 1) {
const Shape& master = master_shapes.GetShape(master_id);
if (master.IsSubsetOf(shape) && !shape.IsSubsetOf(master)) {
shape_table_[shape_id]->AddShape(master);
++num_masters;
}
}
}
}
}
return num_masters;
}
STRING tesseract::ShapeTable::DebugStr |
( |
int |
shape_id | ) |
const |
Definition at line 194 of file shapetable.cpp.
{
if (shape_id < 0 || shape_id >= shape_table_.
size())
return STRING(
"INVALID_UNICHAR_ID");
const Shape& shape =
GetShape(shape_id);
if (shape.size() > 100) {
return result;
}
for (int c = 0; c < shape.size(); ++c) {
result += "=";
if (shape.size() < 10) {
result += " fonts =";
int num_fonts = shape[c].font_ids.
size();
if (num_fonts > 10) {
result.
add_str_int(
" ... ", shape[c].font_ids[num_fonts - 1]);
} else {
for (
int f = 0;
f < num_fonts; ++
f) {
}
}
}
}
return result;
}
void tesseract::ShapeTable::DeleteShape |
( |
int |
shape_id | ) |
|
Definition at line 267 of file shapetable.cpp.
{
delete shape_table_[shape_id];
shape_table_[shape_id] =
NULL;
shape_table_.
remove(shape_id);
}
bool tesseract::ShapeTable::DeSerialize |
( |
bool |
swap, |
|
|
FILE * |
fp |
|
) |
| |
int tesseract::ShapeTable::FindShape |
( |
int |
unichar_id, |
|
|
int |
font_id |
|
) |
| const |
Definition at line 290 of file shapetable.cpp.
{
for (
int s = 0; s < shape_table_.
size(); ++s) {
for (int c = 0; c < shape.size(); ++c) {
if (shape[c].unichar_id == unichar_id) {
if (font_id < 0)
return s;
for (
int f = 0;
f < shape[c].font_ids.size(); ++
f) {
if (shape[c].font_ids[
f] == font_id)
return s;
}
}
}
}
return -1;
}
void tesseract::ShapeTable::ForceFontMerges |
( |
int |
start, |
|
|
int |
end |
|
) |
| |
Definition at line 371 of file shapetable.cpp.
{
for (int s1 = start; s1 < end; ++s1) {
int unichar_id =
GetShape(s1)[0].unichar_id;
for (int s2 = s1 + 1; s2 < end; ++s2) {
unichar_id ==
GetShape(s2)[0].unichar_id) {
}
}
}
}
compacted.AppendMasterShapes(*this);
*this = compacted;
}
void tesseract::ShapeTable::GetFirstUnicharAndFont |
( |
int |
shape_id, |
|
|
int * |
unichar_id, |
|
|
int * |
font_id |
|
) |
| const |
Definition at line 308 of file shapetable.cpp.
{
const UnicharAndFonts& unichar_and_fonts = (*shape_table_[shape_id])[0];
*unichar_id = unichar_and_fonts.unichar_id;
*font_id = unichar_and_fonts.font_ids[0];
}
const Shape& tesseract::ShapeTable::GetShape |
( |
int |
shape_id | ) |
const |
|
inline |
Definition at line 179 of file shapetable.h.
{
return *shape_table_[shape_id];
}
int tesseract::ShapeTable::MasterDestinationIndex |
( |
int |
shape_id | ) |
const |
Definition at line 427 of file shapetable.cpp.
{
int dest_id = shape_table_[shape_id]->destination_index();
if (dest_id == shape_id || dest_id < 0)
return shape_id;
int master_id = shape_table_[dest_id]->destination_index();
if (master_id == dest_id || master_id < 0)
return dest_id;
return master_id;
}
int tesseract::ShapeTable::MasterFontCount |
( |
int |
shape_id | ) |
const |
Definition at line 395 of file shapetable.cpp.
{
const Shape& shape =
GetShape(master_id);
int font_count = 0;
for (int c = 0; c < shape.size(); ++c) {
font_count += shape[c].font_ids.size();
}
return font_count;
}
int tesseract::ShapeTable::MasterUnicharCount |
( |
int |
shape_id | ) |
const |
int tesseract::ShapeTable::MaxNumUnichars |
( |
| ) |
const |
Definition at line 358 of file shapetable.cpp.
{
int max_num_unichars = 0;
for (int s = 0; s < num_shapes; ++s) {
if (
GetShape(s).size() > max_num_unichars)
}
return max_num_unichars;
}
int tesseract::ShapeTable::MergedUnicharCount |
( |
int |
shape_id1, |
|
|
int |
shape_id2 |
|
) |
| const |
Definition at line 406 of file shapetable.cpp.
{
Shape combined_shape(*shape_table_[master_id1]);
combined_shape.AddShape(*shape_table_[master_id2]);
return combined_shape.size();
}
void tesseract::ShapeTable::MergeShapes |
( |
int |
shape_id1, |
|
|
int |
shape_id2 |
|
) |
| |
Definition at line 416 of file shapetable.cpp.
{
shape_table_[master_id2]->set_destination_index(master_id1);
shape_table_[master_id1]->AddShape(*shape_table_[master_id2]);
}
Shape* tesseract::ShapeTable::MutableShape |
( |
int |
shape_id | ) |
|
|
inline |
Definition at line 182 of file shapetable.h.
{
return shape_table_[shape_id];
}
int tesseract::ShapeTable::NumMasterShapes |
( |
| ) |
const |
Definition at line 448 of file shapetable.cpp.
{
int num_shapes = 0;
for (
int s = 0; s < shape_table_.
size(); ++s) {
if (shape_table_[s]->destination_index() < 0)
++num_shapes;
}
return num_shapes;
}
int tesseract::ShapeTable::NumShapes |
( |
| ) |
const |
|
inline |
bool tesseract::ShapeTable::Serialize |
( |
FILE * |
fp | ) |
const |
void tesseract::ShapeTable::set_unicharset |
( |
const UNICHARSET & |
unicharset | ) |
|
|
inline |
STRING tesseract::ShapeTable::SummaryStr |
( |
| ) |
const |
Definition at line 226 of file shapetable.cpp.
{
int max_unichars = 0;
int num_multi_shapes = 0;
int num_master_shapes = 0;
for (
int s = 0; s < shape_table_.
size(); ++s) {
++num_master_shapes;
if (shape_size > 1)
++num_multi_shapes;
if (shape_size > max_unichars)
max_unichars = shape_size;
}
result.
add_str_int(
"Number of shapes = ", num_master_shapes);
result.
add_str_int(
" number with multiple unichars = ", num_multi_shapes);
return result;
}
const UNICHARSET& tesseract::ShapeTable::unicharset |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files: