tesseract  4.00.00dev
tesseract::ShapeTable Class Reference

#include <shapetable.h>

Public Member Functions

 ShapeTable ()
 
 ShapeTable (const UNICHARSET &unicharset)
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (TFile *fp)
 
int NumShapes () const
 
const UNICHARSETunicharset () const
 
int NumFonts () const
 
void set_unicharset (const UNICHARSET &unicharset)
 
void ReMapClassIds (const GenericVector< int > &unicharset_map)
 
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 ShapeGetShape (int shape_id) const
 
ShapeMutableShape (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 SwapShapes (int shape_id1, int shape_id2)
 
void AppendMasterShapes (const ShapeTable &other, GenericVector< int > *shape_map)
 
int NumMasterShapes () const
 
int MasterDestinationIndex (int shape_id) const
 
bool SubsetUnichar (int shape_id1, int shape_id2) const
 
bool MergeSubsetUnichar (int merge_id1, int merge_id2, int shape_id) const
 
bool EqualUnichars (int shape_id1, int shape_id2) const
 
bool MergeEqualUnichars (int merge_id1, int merge_id2, int shape_id) const
 
bool CommonUnichars (int shape_id1, int shape_id2) const
 
bool CommonFont (int shape_id1, int shape_id2) const
 
void AddShapeToResults (const ShapeRating &shape_rating, GenericVector< int > *unichar_map, GenericVector< UnicharRating > *results) const
 

Detailed Description

Definition at line 262 of file shapetable.h.

Constructor & Destructor Documentation

◆ ShapeTable() [1/2]

tesseract::ShapeTable::ShapeTable ( )

Definition at line 239 of file shapetable.cpp.

239  : unicharset_(NULL), num_fonts_(0) {
240 }

◆ ShapeTable() [2/2]

tesseract::ShapeTable::ShapeTable ( const UNICHARSET unicharset)
explicit

Definition at line 241 of file shapetable.cpp.

242  : unicharset_(&unicharset), num_fonts_(0) {
243 }

Member Function Documentation

◆ AddShape() [1/2]

int tesseract::ShapeTable::AddShape ( int  unichar_id,
int  font_id 
)

Definition at line 342 of file shapetable.cpp.

342  {
343  int index = shape_table_.size();
344  Shape* shape = new Shape;
345  shape->AddToShape(unichar_id, font_id);
346  shape_table_.push_back(shape);
347  num_fonts_ = MAX(num_fonts_, font_id + 1);
348  return index;
349 }
#define MAX(x, y)
Definition: ndminx.h:24

◆ AddShape() [2/2]

int tesseract::ShapeTable::AddShape ( const Shape other)

Definition at line 353 of file shapetable.cpp.

353  {
354  int index;
355  for (index = 0; index < shape_table_.size() &&
356  !(other == *shape_table_[index]); ++index)
357  continue;
358  if (index == shape_table_.size()) {
359  Shape* shape = new Shape(other);
360  shape_table_.push_back(shape);
361  }
362  num_fonts_ = 0;
363  return index;
364 }

◆ AddShapeToResults()

void tesseract::ShapeTable::AddShapeToResults ( const ShapeRating shape_rating,
GenericVector< int > *  unichar_map,
GenericVector< UnicharRating > *  results 
) const

Definition at line 693 of file shapetable.cpp.

695  {
696  if (shape_rating.joined) {
697  AddUnicharToResults(UNICHAR_JOINED, shape_rating.rating, unichar_map,
698  results);
699  }
700  if (shape_rating.broken) {
701  AddUnicharToResults(UNICHAR_BROKEN, shape_rating.rating, unichar_map,
702  results);
703  }
704  const Shape& shape = GetShape(shape_rating.shape_id);
705  for (int u = 0; u < shape.size(); ++u) {
706  int result_index = AddUnicharToResults(shape[u].unichar_id,
707  shape_rating.rating,
708  unichar_map, results);
709  for (int f = 0; f < shape[u].font_ids.size(); ++f) {
710  (*results)[result_index].fonts.push_back(
711  ScoredFont(shape[u].font_ids[f],
712  IntCastRounded(shape_rating.rating * MAX_INT16)));
713  }
714  }
715 }
double u[max]
#define MAX_INT16
Definition: host.h:61
int IntCastRounded(double x)
Definition: helpers.h:179
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ AddShapeToShape()

void tesseract::ShapeTable::AddShapeToShape ( int  shape_id,
const Shape other 
)

Definition at line 382 of file shapetable.cpp.

382  {
383  Shape& shape = *shape_table_[shape_id];
384  shape.AddShape(other);
385  num_fonts_ = 0;
386 }

◆ AddToShape()

void tesseract::ShapeTable::AddToShape ( int  shape_id,
int  unichar_id,
int  font_id 
)

Definition at line 375 of file shapetable.cpp.

375  {
376  Shape& shape = *shape_table_[shape_id];
377  shape.AddToShape(unichar_id, font_id);
378  num_fonts_ = MAX(num_fonts_, font_id + 1);
379 }
#define MAX(x, y)
Definition: ndminx.h:24

◆ AlreadyMerged()

bool tesseract::ShapeTable::AlreadyMerged ( int  shape_id1,
int  shape_id2 
) const

Definition at line 445 of file shapetable.cpp.

445  {
446  return MasterDestinationIndex(shape_id1) == MasterDestinationIndex(shape_id2);
447 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537

◆ AnyMultipleUnichars()

bool tesseract::ShapeTable::AnyMultipleUnichars ( ) const

Definition at line 450 of file shapetable.cpp.

450  {
451  int num_shapes = NumShapes();
452  for (int s1 = 0; s1 < num_shapes; ++s1) {
453  if (MasterDestinationIndex(s1) != s1) continue;
454  if (GetShape(s1).size() > 1)
455  return true;
456  }
457  return false;
458 }
voidpf void uLong size
Definition: ioapi.h:39
int NumShapes() const
Definition: shapetable.h:275
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ AppendMasterShapes()

void tesseract::ShapeTable::AppendMasterShapes ( const ShapeTable other,
GenericVector< int > *  shape_map 
)

Definition at line 662 of file shapetable.cpp.

663  {
664  if (shape_map != NULL)
665  shape_map->init_to_size(other.NumShapes(), -1);
666  for (int s = 0; s < other.shape_table_.size(); ++s) {
667  if (other.shape_table_[s]->destination_index() < 0) {
668  int index = AddShape(*other.shape_table_[s]);
669  if (shape_map != NULL)
670  (*shape_map)[s] = index;
671  }
672  }
673 }
void init_to_size(int size, T t)
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:342

◆ BuildFromShape()

int tesseract::ShapeTable::BuildFromShape ( const Shape shape,
const ShapeTable master_shapes 
)

Definition at line 419 of file shapetable.cpp.

420  {
421  BitVector shape_map(master_shapes.NumShapes());
422  for (int u_ind = 0; u_ind < shape.size(); ++u_ind) {
423  for (int f_ind = 0; f_ind < shape[u_ind].font_ids.size(); ++f_ind) {
424  int c = shape[u_ind].unichar_id;
425  int f = shape[u_ind].font_ids[f_ind];
426  int master_id = master_shapes.FindShape(c, f);
427  if (master_id >= 0) {
428  shape_map.SetBit(master_id);
429  } else if (FindShape(c, f) < 0) {
430  AddShape(c, f);
431  }
432  }
433  }
434  int num_masters = 0;
435  for (int s = 0; s < master_shapes.NumShapes(); ++s) {
436  if (shape_map[s]) {
437  AddShape(master_shapes.GetShape(s));
438  ++num_masters;
439  }
440  }
441  return num_masters;
442 }
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:342
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:392

◆ CommonFont()

bool tesseract::ShapeTable::CommonFont ( int  shape_id1,
int  shape_id2 
) const

Definition at line 647 of file shapetable.cpp.

647  {
648  const Shape& shape1 = GetShape(shape_id1);
649  const Shape& shape2 = GetShape(shape_id2);
650  for (int c1 = 0; c1 < shape1.size(); ++c1) {
651  const GenericVector<int>& font_list1 = shape1[c1].font_ids;
652  for (int f = 0; f < font_list1.size(); ++f) {
653  if (shape2.ContainsFont(font_list1[f]))
654  return true;
655  }
656  }
657  return false;
658 }
int size() const
Definition: genericvector.h:72
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ CommonUnichars()

bool tesseract::ShapeTable::CommonUnichars ( int  shape_id1,
int  shape_id2 
) const

Definition at line 635 of file shapetable.cpp.

635  {
636  const Shape& shape1 = GetShape(shape_id1);
637  const Shape& shape2 = GetShape(shape_id2);
638  for (int c1 = 0; c1 < shape1.size(); ++c1) {
639  int unichar_id1 = shape1[c1].unichar_id;
640  if (shape2.ContainsUnichar(unichar_id1))
641  return true;
642  }
643  return false;
644 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ DebugStr()

STRING tesseract::ShapeTable::DebugStr ( int  shape_id) const

Definition at line 287 of file shapetable.cpp.

287  {
288  if (shape_id < 0 || shape_id >= shape_table_.size())
289  return STRING("INVALID_UNICHAR_ID");
290  const Shape& shape = GetShape(shape_id);
291  STRING result;
292  result.add_str_int("Shape", shape_id);
293  if (shape.size() > 100) {
294  result.add_str_int(" Num unichars=", shape.size());
295  return result;
296  }
297  for (int c = 0; c < shape.size(); ++c) {
298  result.add_str_int(" c_id=", shape[c].unichar_id);
299  result += "=";
300  result += unicharset_->id_to_unichar(shape[c].unichar_id);
301  if (shape.size() < 10) {
302  result.add_str_int(", ", shape[c].font_ids.size());
303  result += " fonts =";
304  int num_fonts = shape[c].font_ids.size();
305  if (num_fonts > 10) {
306  result.add_str_int(" ", shape[c].font_ids[0]);
307  result.add_str_int(" ... ", shape[c].font_ids[num_fonts - 1]);
308  } else {
309  for (int f = 0; f < num_fonts; ++f) {
310  result.add_str_int(" ", shape[c].font_ids[f]);
311  }
312  }
313  }
314  }
315  return result;
316 }
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266
inT32 size() const
Definition: strngs.h:69
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
Definition: strngs.h:45

◆ DeleteShape()

void tesseract::ShapeTable::DeleteShape ( int  shape_id)

Definition at line 367 of file shapetable.cpp.

367  {
368  delete shape_table_[shape_id];
369  shape_table_[shape_id] = NULL;
370  shape_table_.remove(shape_id);
371 }

◆ DeSerialize()

bool tesseract::ShapeTable::DeSerialize ( TFile fp)

Definition at line 252 of file shapetable.cpp.

252  {
253  if (!shape_table_.DeSerialize(fp)) return false;
254  num_fonts_ = 0;
255  return true;
256 }

◆ EqualUnichars()

bool tesseract::ShapeTable::EqualUnichars ( int  shape_id1,
int  shape_id2 
) const

Definition at line 593 of file shapetable.cpp.

593  {
594  const Shape& shape1 = GetShape(shape_id1);
595  const Shape& shape2 = GetShape(shape_id2);
596  for (int c1 = 0; c1 < shape1.size(); ++c1) {
597  int unichar_id1 = shape1[c1].unichar_id;
598  if (!shape2.ContainsUnichar(unichar_id1))
599  return false;
600  }
601  for (int c2 = 0; c2 < shape2.size(); ++c2) {
602  int unichar_id2 = shape2[c2].unichar_id;
603  if (!shape1.ContainsUnichar(unichar_id2))
604  return false;
605  }
606  return true;
607 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ FindShape()

int tesseract::ShapeTable::FindShape ( int  unichar_id,
int  font_id 
) const

Definition at line 392 of file shapetable.cpp.

392  {
393  for (int s = 0; s < shape_table_.size(); ++s) {
394  const Shape& shape = GetShape(s);
395  for (int c = 0; c < shape.size(); ++c) {
396  if (shape[c].unichar_id == unichar_id) {
397  if (font_id < 0)
398  return s; // We don't care about the font.
399  for (int f = 0; f < shape[c].font_ids.size(); ++f) {
400  if (shape[c].font_ids[f] == font_id)
401  return s;
402  }
403  }
404  }
405  }
406  return -1;
407 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ ForceFontMerges()

void tesseract::ShapeTable::ForceFontMerges ( int  start,
int  end 
)

Definition at line 474 of file shapetable.cpp.

474  {
475  for (int s1 = start; s1 < end; ++s1) {
476  if (MasterDestinationIndex(s1) == s1 && GetShape(s1).size() == 1) {
477  int unichar_id = GetShape(s1)[0].unichar_id;
478  for (int s2 = s1 + 1; s2 < end; ++s2) {
479  if (MasterDestinationIndex(s2) == s2 && GetShape(s2).size() == 1 &&
480  unichar_id == GetShape(s2)[0].unichar_id) {
481  MergeShapes(s1, s2);
482  }
483  }
484  }
485  }
486  ShapeTable compacted(*unicharset_);
487  compacted.AppendMasterShapes(*this, NULL);
488  *this = compacted;
489 }
voidpf void uLong size
Definition: ioapi.h:39
void MergeShapes(int shape_id1, int shape_id2)
Definition: shapetable.cpp:519
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ GetFirstUnicharAndFont()

void tesseract::ShapeTable::GetFirstUnicharAndFont ( int  shape_id,
int unichar_id,
int font_id 
) const

Definition at line 410 of file shapetable.cpp.

411  {
412  const UnicharAndFonts& unichar_and_fonts = (*shape_table_[shape_id])[0];
413  *unichar_id = unichar_and_fonts.unichar_id;
414  *font_id = unichar_and_fonts.font_ids[0];
415 }

◆ GetShape()

const Shape& tesseract::ShapeTable::GetShape ( int  shape_id) const
inline

Definition at line 320 of file shapetable.h.

320  {
321  return *shape_table_[shape_id];
322  }

◆ MasterDestinationIndex()

int tesseract::ShapeTable::MasterDestinationIndex ( int  shape_id) const

Definition at line 537 of file shapetable.cpp.

537  {
538  int dest_id = shape_table_[shape_id]->destination_index();
539  if (dest_id == shape_id || dest_id < 0)
540  return shape_id; // Is master already.
541  int master_id = shape_table_[dest_id]->destination_index();
542  if (master_id == dest_id || master_id < 0)
543  return dest_id; // Dest is the master and shape_id points to it.
544  master_id = MasterDestinationIndex(master_id);
545  return master_id;
546 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537

◆ MasterFontCount()

int tesseract::ShapeTable::MasterFontCount ( int  shape_id) const

Definition at line 498 of file shapetable.cpp.

498  {
499  int master_id = MasterDestinationIndex(shape_id);
500  const Shape& shape = GetShape(master_id);
501  int font_count = 0;
502  for (int c = 0; c < shape.size(); ++c) {
503  font_count += shape[c].font_ids.size();
504  }
505  return font_count;
506 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ MasterUnicharCount()

int tesseract::ShapeTable::MasterUnicharCount ( int  shape_id) const

Definition at line 492 of file shapetable.cpp.

492  {
493  int master_id = MasterDestinationIndex(shape_id);
494  return GetShape(master_id).size();
495 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
int size() const
Definition: shapetable.h:200

◆ MaxNumUnichars()

int tesseract::ShapeTable::MaxNumUnichars ( ) const

Definition at line 461 of file shapetable.cpp.

461  {
462  int max_num_unichars = 0;
463  int num_shapes = NumShapes();
464  for (int s = 0; s < num_shapes; ++s) {
465  if (GetShape(s).size() > max_num_unichars)
466  max_num_unichars = GetShape(s).size();
467  }
468  return max_num_unichars;
469 }
voidpf void uLong size
Definition: ioapi.h:39
int NumShapes() const
Definition: shapetable.h:275
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
int size() const
Definition: shapetable.h:200

◆ MergedUnicharCount()

int tesseract::ShapeTable::MergedUnicharCount ( int  shape_id1,
int  shape_id2 
) const

Definition at line 509 of file shapetable.cpp.

509  {
510  // Do it the easy way for now.
511  int master_id1 = MasterDestinationIndex(shape_id1);
512  int master_id2 = MasterDestinationIndex(shape_id2);
513  Shape combined_shape(*shape_table_[master_id1]);
514  combined_shape.AddShape(*shape_table_[master_id2]);
515  return combined_shape.size();
516 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537

◆ MergeEqualUnichars()

bool tesseract::ShapeTable::MergeEqualUnichars ( int  merge_id1,
int  merge_id2,
int  shape_id 
) const

Definition at line 610 of file shapetable.cpp.

611  {
612  const Shape& merge1 = GetShape(merge_id1);
613  const Shape& merge2 = GetShape(merge_id2);
614  const Shape& shape = GetShape(shape_id);
615  for (int cs = 0; cs < shape.size(); ++cs) {
616  int unichar_id = shape[cs].unichar_id;
617  if (!merge1.ContainsUnichar(unichar_id) &&
618  !merge2.ContainsUnichar(unichar_id))
619  return false; // Shape has a unichar that appears in neither merge.
620  }
621  for (int cm1 = 0; cm1 < merge1.size(); ++cm1) {
622  int unichar_id1 = merge1[cm1].unichar_id;
623  if (!shape.ContainsUnichar(unichar_id1))
624  return false; // Merge has a unichar that is not in shape.
625  }
626  for (int cm2 = 0; cm2 < merge2.size(); ++cm2) {
627  int unichar_id2 = merge2[cm2].unichar_id;
628  if (!shape.ContainsUnichar(unichar_id2))
629  return false; // Merge has a unichar that is not in shape.
630  }
631  return true;
632 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ MergeShapes()

void tesseract::ShapeTable::MergeShapes ( int  shape_id1,
int  shape_id2 
)

Definition at line 519 of file shapetable.cpp.

519  {
520  int master_id1 = MasterDestinationIndex(shape_id1);
521  int master_id2 = MasterDestinationIndex(shape_id2);
522  // Point master_id2 (and all merged shapes) to master_id1.
523  shape_table_[master_id2]->set_destination_index(master_id1);
524  // Add all the shapes of master_id2 to master_id1.
525  shape_table_[master_id1]->AddShape(*shape_table_[master_id2]);
526 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537

◆ MergeSubsetUnichar()

bool tesseract::ShapeTable::MergeSubsetUnichar ( int  merge_id1,
int  merge_id2,
int  shape_id 
) const

Definition at line 567 of file shapetable.cpp.

568  {
569  const Shape& merge1 = GetShape(merge_id1);
570  const Shape& merge2 = GetShape(merge_id2);
571  const Shape& shape = GetShape(shape_id);
572  int cm1, cm2, cs;
573  for (cs = 0; cs < shape.size(); ++cs) {
574  int unichar_id = shape[cs].unichar_id;
575  if (!merge1.ContainsUnichar(unichar_id) &&
576  !merge2.ContainsUnichar(unichar_id))
577  break; // Shape is not a subset of the merge.
578  }
579  for (cm1 = 0; cm1 < merge1.size(); ++cm1) {
580  int unichar_id1 = merge1[cm1].unichar_id;
581  if (!shape.ContainsUnichar(unichar_id1))
582  break; // Merge is not a subset of shape
583  }
584  for (cm2 = 0; cm2 < merge2.size(); ++cm2) {
585  int unichar_id2 = merge2[cm2].unichar_id;
586  if (!shape.ContainsUnichar(unichar_id2))
587  break; // Merge is not a subset of shape
588  }
589  return cs == shape.size() || (cm1 == merge1.size() && cm2 == merge2.size());
590 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ MutableShape()

Shape* tesseract::ShapeTable::MutableShape ( int  shape_id)
inline

Definition at line 323 of file shapetable.h.

323  {
324  return shape_table_[shape_id];
325  }

◆ NumFonts()

int tesseract::ShapeTable::NumFonts ( ) const

Definition at line 260 of file shapetable.cpp.

260  {
261  if (num_fonts_ <= 0) {
262  for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
263  const Shape& shape = *shape_table_[shape_id];
264  for (int c = 0; c < shape.size(); ++c) {
265  for (int f = 0; f < shape[c].font_ids.size(); ++f) {
266  if (shape[c].font_ids[f] >= num_fonts_)
267  num_fonts_ = shape[c].font_ids[f] + 1;
268  }
269  }
270  }
271  }
272  return num_fonts_;
273 }

◆ NumMasterShapes()

int tesseract::ShapeTable::NumMasterShapes ( ) const

Definition at line 676 of file shapetable.cpp.

676  {
677  int num_shapes = 0;
678  for (int s = 0; s < shape_table_.size(); ++s) {
679  if (shape_table_[s]->destination_index() < 0)
680  ++num_shapes;
681  }
682  return num_shapes;
683 }

◆ NumShapes()

int tesseract::ShapeTable::NumShapes ( ) const
inline

Definition at line 275 of file shapetable.h.

275  {
276  return shape_table_.size();
277  }

◆ ReMapClassIds()

void tesseract::ShapeTable::ReMapClassIds ( const GenericVector< int > &  unicharset_map)

Definition at line 277 of file shapetable.cpp.

277  {
278  for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
279  Shape* shape = shape_table_[shape_id];
280  for (int c = 0; c < shape->size(); ++c) {
281  shape->SetUnicharId(c, unicharset_map[(*shape)[c].unichar_id]);
282  }
283  }
284 }

◆ Serialize()

bool tesseract::ShapeTable::Serialize ( FILE *  fp) const

Definition at line 246 of file shapetable.cpp.

246  {
247  if (!shape_table_.Serialize(fp)) return false;
248  return true;
249 }

◆ set_unicharset()

void tesseract::ShapeTable::set_unicharset ( const UNICHARSET unicharset)
inline

Definition at line 286 of file shapetable.h.

286  {
287  unicharset_ = &unicharset;
288  }
const UNICHARSET & unicharset() const
Definition: shapetable.h:278

◆ SubsetUnichar()

bool tesseract::ShapeTable::SubsetUnichar ( int  shape_id1,
int  shape_id2 
) const

Definition at line 549 of file shapetable.cpp.

549  {
550  const Shape& shape1 = GetShape(shape_id1);
551  const Shape& shape2 = GetShape(shape_id2);
552  int c1, c2;
553  for (c1 = 0; c1 < shape1.size(); ++c1) {
554  int unichar_id1 = shape1[c1].unichar_id;
555  if (!shape2.ContainsUnichar(unichar_id1))
556  break;
557  }
558  for (c2 = 0; c2 < shape2.size(); ++c2) {
559  int unichar_id2 = shape2[c2].unichar_id;
560  if (!shape1.ContainsUnichar(unichar_id2))
561  break;
562  }
563  return c1 == shape1.size() || c2 == shape2.size();
564 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ SummaryStr()

STRING tesseract::ShapeTable::SummaryStr ( ) const

Definition at line 319 of file shapetable.cpp.

319  {
320  int max_unichars = 0;
321  int num_multi_shapes = 0;
322  int num_master_shapes = 0;
323  for (int s = 0; s < shape_table_.size(); ++s) {
324  if (MasterDestinationIndex(s) != s) continue;
325  ++num_master_shapes;
326  int shape_size = GetShape(s).size();
327  if (shape_size > 1)
328  ++num_multi_shapes;
329  if (shape_size > max_unichars)
330  max_unichars = shape_size;
331  }
332  STRING result;
333  result.add_str_int("Number of shapes = ", num_master_shapes);
334  result.add_str_int(" max unichars = ", max_unichars);
335  result.add_str_int(" number with multiple unichars = ", num_multi_shapes);
336  return result;
337 }
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:537
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
Definition: strngs.h:45
int size() const
Definition: shapetable.h:200

◆ SwapShapes()

void tesseract::ShapeTable::SwapShapes ( int  shape_id1,
int  shape_id2 
)

Definition at line 529 of file shapetable.cpp.

529  {
530  Shape* tmp = shape_table_[shape_id1];
531  shape_table_[shape_id1] = shape_table_[shape_id2];
532  shape_table_[shape_id2] = tmp;
533 }

◆ unicharset()

const UNICHARSET& tesseract::ShapeTable::unicharset ( ) const
inline

Definition at line 278 of file shapetable.h.

278  {
279  return *unicharset_;
280  }

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