tesseract  4.0.0-1-g2a2b
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 234 of file shapetable.cpp.

234  : unicharset_(nullptr), num_fonts_(0) {
235 }

◆ ShapeTable() [2/2]

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

Definition at line 236 of file shapetable.cpp.

237  : unicharset_(&unicharset), num_fonts_(0) {
238 }
const UNICHARSET & unicharset() const
Definition: shapetable.h:278

Member Function Documentation

◆ AddShape() [1/2]

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

Definition at line 336 of file shapetable.cpp.

336  {
337  int index = shape_table_.size();
338  Shape* shape = new Shape;
339  shape->AddToShape(unichar_id, font_id);
340  shape_table_.push_back(shape);
341  num_fonts_ = std::max(num_fonts_, font_id + 1);
342  return index;
343 }

◆ AddShape() [2/2]

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

Definition at line 347 of file shapetable.cpp.

347  {
348  int index;
349  for (index = 0; index < shape_table_.size() &&
350  !(other == *shape_table_[index]); ++index)
351  continue;
352  if (index == shape_table_.size()) {
353  Shape* shape = new Shape(other);
354  shape_table_.push_back(shape);
355  }
356  num_fonts_ = 0;
357  return index;
358 }

◆ AddShapeToResults()

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

Definition at line 687 of file shapetable.cpp.

689  {
690  if (shape_rating.joined) {
691  AddUnicharToResults(UNICHAR_JOINED, shape_rating.rating, unichar_map,
692  results);
693  }
694  if (shape_rating.broken) {
695  AddUnicharToResults(UNICHAR_BROKEN, shape_rating.rating, unichar_map,
696  results);
697  }
698  const Shape& shape = GetShape(shape_rating.shape_id);
699  for (int u = 0; u < shape.size(); ++u) {
700  int result_index = AddUnicharToResults(shape[u].unichar_id,
701  shape_rating.rating,
702  unichar_map, results);
703  for (int f = 0; f < shape[u].font_ids.size(); ++f) {
704  (*results)[result_index].fonts.push_back(
705  ScoredFont(shape[u].font_ids[f],
706  IntCastRounded(shape_rating.rating * INT16_MAX)));
707  }
708  }
709 }
int IntCastRounded(double x)
Definition: helpers.h:168
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 376 of file shapetable.cpp.

376  {
377  Shape& shape = *shape_table_[shape_id];
378  shape.AddShape(other);
379  num_fonts_ = 0;
380 }

◆ AddToShape()

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

Definition at line 369 of file shapetable.cpp.

369  {
370  Shape& shape = *shape_table_[shape_id];
371  shape.AddToShape(unichar_id, font_id);
372  num_fonts_ = std::max(num_fonts_, font_id + 1);
373 }

◆ AlreadyMerged()

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

Definition at line 439 of file shapetable.cpp.

439  {
440  return MasterDestinationIndex(shape_id1) == MasterDestinationIndex(shape_id2);
441 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531

◆ AnyMultipleUnichars()

bool tesseract::ShapeTable::AnyMultipleUnichars ( ) const

Definition at line 444 of file shapetable.cpp.

444  {
445  int num_shapes = NumShapes();
446  for (int s1 = 0; s1 < num_shapes; ++s1) {
447  if (MasterDestinationIndex(s1) != s1) continue;
448  if (GetShape(s1).size() > 1)
449  return true;
450  }
451  return false;
452 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
int NumShapes() const
Definition: shapetable.h:275

◆ AppendMasterShapes()

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

Definition at line 656 of file shapetable.cpp.

657  {
658  if (shape_map != nullptr)
659  shape_map->init_to_size(other.NumShapes(), -1);
660  for (int s = 0; s < other.shape_table_.size(); ++s) {
661  if (other.shape_table_[s]->destination_index() < 0) {
662  int index = AddShape(*other.shape_table_[s]);
663  if (shape_map != nullptr)
664  (*shape_map)[s] = index;
665  }
666  }
667 }
void init_to_size(int size, const T &t)
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:336

◆ BuildFromShape()

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

Definition at line 413 of file shapetable.cpp.

414  {
415  BitVector shape_map(master_shapes.NumShapes());
416  for (int u_ind = 0; u_ind < shape.size(); ++u_ind) {
417  for (int f_ind = 0; f_ind < shape[u_ind].font_ids.size(); ++f_ind) {
418  int c = shape[u_ind].unichar_id;
419  int f = shape[u_ind].font_ids[f_ind];
420  int master_id = master_shapes.FindShape(c, f);
421  if (master_id >= 0) {
422  shape_map.SetBit(master_id);
423  } else if (FindShape(c, f) < 0) {
424  AddShape(c, f);
425  }
426  }
427  }
428  int num_masters = 0;
429  for (int s = 0; s < master_shapes.NumShapes(); ++s) {
430  if (shape_map[s]) {
431  AddShape(master_shapes.GetShape(s));
432  ++num_masters;
433  }
434  }
435  return num_masters;
436 }
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:386
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:336

◆ CommonFont()

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

Definition at line 641 of file shapetable.cpp.

641  {
642  const Shape& shape1 = GetShape(shape_id1);
643  const Shape& shape2 = GetShape(shape_id2);
644  for (int c1 = 0; c1 < shape1.size(); ++c1) {
645  const GenericVector<int>& font_list1 = shape1[c1].font_ids;
646  for (int f = 0; f < font_list1.size(); ++f) {
647  if (shape2.ContainsFont(font_list1[f]))
648  return true;
649  }
650  }
651  return false;
652 }
int size() const
Definition: genericvector.h:71
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 629 of file shapetable.cpp.

629  {
630  const Shape& shape1 = GetShape(shape_id1);
631  const Shape& shape2 = GetShape(shape_id2);
632  for (int c1 = 0; c1 < shape1.size(); ++c1) {
633  int unichar_id1 = shape1[c1].unichar_id;
634  if (shape2.ContainsUnichar(unichar_id1))
635  return true;
636  }
637  return false;
638 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ DebugStr()

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

Definition at line 281 of file shapetable.cpp.

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

◆ DeleteShape()

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

Definition at line 361 of file shapetable.cpp.

361  {
362  delete shape_table_[shape_id];
363  shape_table_[shape_id] = nullptr;
364  shape_table_.remove(shape_id);
365 }

◆ DeSerialize()

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

Definition at line 246 of file shapetable.cpp.

246  {
247  if (!shape_table_.DeSerialize(fp)) return false;
248  num_fonts_ = 0;
249  return true;
250 }

◆ EqualUnichars()

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

Definition at line 587 of file shapetable.cpp.

587  {
588  const Shape& shape1 = GetShape(shape_id1);
589  const Shape& shape2 = GetShape(shape_id2);
590  for (int c1 = 0; c1 < shape1.size(); ++c1) {
591  int unichar_id1 = shape1[c1].unichar_id;
592  if (!shape2.ContainsUnichar(unichar_id1))
593  return false;
594  }
595  for (int c2 = 0; c2 < shape2.size(); ++c2) {
596  int unichar_id2 = shape2[c2].unichar_id;
597  if (!shape1.ContainsUnichar(unichar_id2))
598  return false;
599  }
600  return true;
601 }
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 386 of file shapetable.cpp.

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

◆ ForceFontMerges()

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

Definition at line 468 of file shapetable.cpp.

468  {
469  for (int s1 = start; s1 < end; ++s1) {
470  if (MasterDestinationIndex(s1) == s1 && GetShape(s1).size() == 1) {
471  int unichar_id = GetShape(s1)[0].unichar_id;
472  for (int s2 = s1 + 1; s2 < end; ++s2) {
473  if (MasterDestinationIndex(s2) == s2 && GetShape(s2).size() == 1 &&
474  unichar_id == GetShape(s2)[0].unichar_id) {
475  MergeShapes(s1, s2);
476  }
477  }
478  }
479  }
480  ShapeTable compacted(*unicharset_);
481  compacted.AppendMasterShapes(*this, nullptr);
482  *this = compacted;
483 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
void MergeShapes(int shape_id1, int shape_id2)
Definition: shapetable.cpp:513

◆ GetFirstUnicharAndFont()

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

Definition at line 404 of file shapetable.cpp.

405  {
406  const UnicharAndFonts& unichar_and_fonts = (*shape_table_[shape_id])[0];
407  *unichar_id = unichar_and_fonts.unichar_id;
408  *font_id = unichar_and_fonts.font_ids[0];
409 }

◆ 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 531 of file shapetable.cpp.

531  {
532  int dest_id = shape_table_[shape_id]->destination_index();
533  if (dest_id == shape_id || dest_id < 0)
534  return shape_id; // Is master already.
535  int master_id = shape_table_[dest_id]->destination_index();
536  if (master_id == dest_id || master_id < 0)
537  return dest_id; // Dest is the master and shape_id points to it.
538  master_id = MasterDestinationIndex(master_id);
539  return master_id;
540 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531

◆ MasterFontCount()

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

Definition at line 492 of file shapetable.cpp.

492  {
493  int master_id = MasterDestinationIndex(shape_id);
494  const Shape& shape = GetShape(master_id);
495  int font_count = 0;
496  for (int c = 0; c < shape.size(); ++c) {
497  font_count += shape[c].font_ids.size();
498  }
499  return font_count;
500 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ MasterUnicharCount()

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

Definition at line 486 of file shapetable.cpp.

486  {
487  int master_id = MasterDestinationIndex(shape_id);
488  return GetShape(master_id).size();
489 }
int size() const
Definition: shapetable.h:200
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320

◆ MaxNumUnichars()

int tesseract::ShapeTable::MaxNumUnichars ( ) const

Definition at line 455 of file shapetable.cpp.

455  {
456  int max_num_unichars = 0;
457  int num_shapes = NumShapes();
458  for (int s = 0; s < num_shapes; ++s) {
459  if (GetShape(s).size() > max_num_unichars)
460  max_num_unichars = GetShape(s).size();
461  }
462  return max_num_unichars;
463 }
int size() const
Definition: shapetable.h:200
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:320
int NumShapes() const
Definition: shapetable.h:275

◆ MergedUnicharCount()

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

Definition at line 503 of file shapetable.cpp.

503  {
504  // Do it the easy way for now.
505  int master_id1 = MasterDestinationIndex(shape_id1);
506  int master_id2 = MasterDestinationIndex(shape_id2);
507  Shape combined_shape(*shape_table_[master_id1]);
508  combined_shape.AddShape(*shape_table_[master_id2]);
509  return combined_shape.size();
510 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531

◆ MergeEqualUnichars()

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

Definition at line 604 of file shapetable.cpp.

605  {
606  const Shape& merge1 = GetShape(merge_id1);
607  const Shape& merge2 = GetShape(merge_id2);
608  const Shape& shape = GetShape(shape_id);
609  for (int cs = 0; cs < shape.size(); ++cs) {
610  int unichar_id = shape[cs].unichar_id;
611  if (!merge1.ContainsUnichar(unichar_id) &&
612  !merge2.ContainsUnichar(unichar_id))
613  return false; // Shape has a unichar that appears in neither merge.
614  }
615  for (int cm1 = 0; cm1 < merge1.size(); ++cm1) {
616  int unichar_id1 = merge1[cm1].unichar_id;
617  if (!shape.ContainsUnichar(unichar_id1))
618  return false; // Merge has a unichar that is not in shape.
619  }
620  for (int cm2 = 0; cm2 < merge2.size(); ++cm2) {
621  int unichar_id2 = merge2[cm2].unichar_id;
622  if (!shape.ContainsUnichar(unichar_id2))
623  return false; // Merge has a unichar that is not in shape.
624  }
625  return true;
626 }
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 513 of file shapetable.cpp.

513  {
514  int master_id1 = MasterDestinationIndex(shape_id1);
515  int master_id2 = MasterDestinationIndex(shape_id2);
516  // Point master_id2 (and all merged shapes) to master_id1.
517  shape_table_[master_id2]->set_destination_index(master_id1);
518  // Add all the shapes of master_id2 to master_id1.
519  shape_table_[master_id1]->AddShape(*shape_table_[master_id2]);
520 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:531

◆ MergeSubsetUnichar()

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

Definition at line 561 of file shapetable.cpp.

562  {
563  const Shape& merge1 = GetShape(merge_id1);
564  const Shape& merge2 = GetShape(merge_id2);
565  const Shape& shape = GetShape(shape_id);
566  int cm1, cm2, cs;
567  for (cs = 0; cs < shape.size(); ++cs) {
568  int unichar_id = shape[cs].unichar_id;
569  if (!merge1.ContainsUnichar(unichar_id) &&
570  !merge2.ContainsUnichar(unichar_id))
571  break; // Shape is not a subset of the merge.
572  }
573  for (cm1 = 0; cm1 < merge1.size(); ++cm1) {
574  int unichar_id1 = merge1[cm1].unichar_id;
575  if (!shape.ContainsUnichar(unichar_id1))
576  break; // Merge is not a subset of shape
577  }
578  for (cm2 = 0; cm2 < merge2.size(); ++cm2) {
579  int unichar_id2 = merge2[cm2].unichar_id;
580  if (!shape.ContainsUnichar(unichar_id2))
581  break; // Merge is not a subset of shape
582  }
583  return cs == shape.size() || (cm1 == merge1.size() && cm2 == merge2.size());
584 }
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 254 of file shapetable.cpp.

254  {
255  if (num_fonts_ <= 0) {
256  for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
257  const Shape& shape = *shape_table_[shape_id];
258  for (int c = 0; c < shape.size(); ++c) {
259  for (int f = 0; f < shape[c].font_ids.size(); ++f) {
260  if (shape[c].font_ids[f] >= num_fonts_)
261  num_fonts_ = shape[c].font_ids[f] + 1;
262  }
263  }
264  }
265  }
266  return num_fonts_;
267 }

◆ NumMasterShapes()

int tesseract::ShapeTable::NumMasterShapes ( ) const

Definition at line 670 of file shapetable.cpp.

670  {
671  int num_shapes = 0;
672  for (int s = 0; s < shape_table_.size(); ++s) {
673  if (shape_table_[s]->destination_index() < 0)
674  ++num_shapes;
675  }
676  return num_shapes;
677 }

◆ 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 271 of file shapetable.cpp.

271  {
272  for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
273  Shape* shape = shape_table_[shape_id];
274  for (int c = 0; c < shape->size(); ++c) {
275  shape->SetUnicharId(c, unicharset_map[(*shape)[c].unichar_id]);
276  }
277  }
278 }

◆ Serialize()

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

Definition at line 241 of file shapetable.cpp.

241  {
242  return shape_table_.Serialize(fp);
243 }

◆ 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 543 of file shapetable.cpp.

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

◆ SummaryStr()

STRING tesseract::ShapeTable::SummaryStr ( ) const

Definition at line 313 of file shapetable.cpp.

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

◆ SwapShapes()

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

Definition at line 523 of file shapetable.cpp.

523  {
524  Shape* tmp = shape_table_[shape_id1];
525  shape_table_[shape_id1] = shape_table_[shape_id2];
526  shape_table_[shape_id2] = tmp;
527 }

◆ 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: