All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::ShapeTable Class Reference

#include <shapetable.h>

Public Member Functions

 ShapeTable ()
 
 ShapeTable (const UNICHARSET &unicharset)
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (bool swap, FILE *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 264 of file shapetable.h.

Constructor & Destructor Documentation

tesseract::ShapeTable::ShapeTable ( )

Definition at line 243 of file shapetable.cpp.

243  : unicharset_(NULL), num_fonts_(0) {
244 }
#define NULL
Definition: host.h:144
tesseract::ShapeTable::ShapeTable ( const UNICHARSET unicharset)
explicit

Definition at line 245 of file shapetable.cpp.

246  : unicharset_(&unicharset), num_fonts_(0) {
247 }

Member Function Documentation

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

Definition at line 346 of file shapetable.cpp.

346  {
347  int index = shape_table_.size();
348  Shape* shape = new Shape;
349  shape->AddToShape(unichar_id, font_id);
350  shape_table_.push_back(shape);
351  num_fonts_ = MAX(num_fonts_, font_id + 1);
352  return index;
353 }
#define MAX(x, y)
Definition: ndminx.h:24
int tesseract::ShapeTable::AddShape ( const Shape other)

Definition at line 357 of file shapetable.cpp.

357  {
358  int index;
359  for (index = 0; index < shape_table_.size() &&
360  !(other == *shape_table_[index]); ++index)
361  continue;
362  if (index == shape_table_.size()) {
363  Shape* shape = new Shape(other);
364  shape_table_.push_back(shape);
365  }
366  num_fonts_ = 0;
367  return index;
368 }
void tesseract::ShapeTable::AddShapeToResults ( const ShapeRating shape_rating,
GenericVector< int > *  unichar_map,
GenericVector< UnicharRating > *  results 
) const

Definition at line 697 of file shapetable.cpp.

699  {
700  if (shape_rating.joined) {
701  AddUnicharToResults(UNICHAR_JOINED, shape_rating.rating, unichar_map,
702  results);
703  }
704  if (shape_rating.broken) {
705  AddUnicharToResults(UNICHAR_BROKEN, shape_rating.rating, unichar_map,
706  results);
707  }
708  const Shape& shape = GetShape(shape_rating.shape_id);
709  for (int u = 0; u < shape.size(); ++u) {
710  int result_index = AddUnicharToResults(shape[u].unichar_id,
711  shape_rating.rating,
712  unichar_map, results);
713  for (int f = 0; f < shape[u].font_ids.size(); ++f) {
714  (*results)[result_index].fonts.push_back(
715  ScoredFont(shape[u].font_ids[f],
716  IntCastRounded(shape_rating.rating * MAX_INT16)));
717  }
718  }
719 }
int IntCastRounded(double x)
Definition: helpers.h:172
#define MAX_INT16
Definition: host.h:119
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
void tesseract::ShapeTable::AddShapeToShape ( int  shape_id,
const Shape other 
)

Definition at line 386 of file shapetable.cpp.

386  {
387  Shape& shape = *shape_table_[shape_id];
388  shape.AddShape(other);
389  num_fonts_ = 0;
390 }
void tesseract::ShapeTable::AddToShape ( int  shape_id,
int  unichar_id,
int  font_id 
)

Definition at line 379 of file shapetable.cpp.

379  {
380  Shape& shape = *shape_table_[shape_id];
381  shape.AddToShape(unichar_id, font_id);
382  num_fonts_ = MAX(num_fonts_, font_id + 1);
383 }
#define MAX(x, y)
Definition: ndminx.h:24
bool tesseract::ShapeTable::AlreadyMerged ( int  shape_id1,
int  shape_id2 
) const

Definition at line 449 of file shapetable.cpp.

449  {
450  return MasterDestinationIndex(shape_id1) == MasterDestinationIndex(shape_id2);
451 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
bool tesseract::ShapeTable::AnyMultipleUnichars ( ) const

Definition at line 454 of file shapetable.cpp.

454  {
455  int num_shapes = NumShapes();
456  for (int s1 = 0; s1 < num_shapes; ++s1) {
457  if (MasterDestinationIndex(s1) != s1) continue;
458  if (GetShape(s1).size() > 1)
459  return true;
460  }
461  return false;
462 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
int NumShapes() const
Definition: shapetable.h:278
void tesseract::ShapeTable::AppendMasterShapes ( const ShapeTable other,
GenericVector< int > *  shape_map 
)

Definition at line 666 of file shapetable.cpp.

667  {
668  if (shape_map != NULL)
669  shape_map->init_to_size(other.NumShapes(), -1);
670  for (int s = 0; s < other.shape_table_.size(); ++s) {
671  if (other.shape_table_[s]->destination_index() < 0) {
672  int index = AddShape(*other.shape_table_[s]);
673  if (shape_map != NULL)
674  (*shape_map)[s] = index;
675  }
676  }
677 }
void init_to_size(int size, T t)
#define NULL
Definition: host.h:144
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:346
int tesseract::ShapeTable::BuildFromShape ( const Shape shape,
const ShapeTable master_shapes 
)

Definition at line 423 of file shapetable.cpp.

424  {
425  BitVector shape_map(master_shapes.NumShapes());
426  for (int u_ind = 0; u_ind < shape.size(); ++u_ind) {
427  for (int f_ind = 0; f_ind < shape[u_ind].font_ids.size(); ++f_ind) {
428  int c = shape[u_ind].unichar_id;
429  int f = shape[u_ind].font_ids[f_ind];
430  int master_id = master_shapes.FindShape(c, f);
431  if (master_id >= 0) {
432  shape_map.SetBit(master_id);
433  } else if (FindShape(c, f) < 0) {
434  AddShape(c, f);
435  }
436  }
437  }
438  int num_masters = 0;
439  for (int s = 0; s < master_shapes.NumShapes(); ++s) {
440  if (shape_map[s]) {
441  AddShape(master_shapes.GetShape(s));
442  ++num_masters;
443  }
444  }
445  return num_masters;
446 }
int FindShape(int unichar_id, int font_id) const
Definition: shapetable.cpp:396
int AddShape(int unichar_id, int font_id)
Definition: shapetable.cpp:346
bool tesseract::ShapeTable::CommonFont ( int  shape_id1,
int  shape_id2 
) const

Definition at line 651 of file shapetable.cpp.

651  {
652  const Shape& shape1 = GetShape(shape_id1);
653  const Shape& shape2 = GetShape(shape_id2);
654  for (int c1 = 0; c1 < shape1.size(); ++c1) {
655  const GenericVector<int>& font_list1 = shape1[c1].font_ids;
656  for (int f = 0; f < font_list1.size(); ++f) {
657  if (shape2.ContainsFont(font_list1[f]))
658  return true;
659  }
660  }
661  return false;
662 }
int size() const
Definition: genericvector.h:72
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
bool tesseract::ShapeTable::CommonUnichars ( int  shape_id1,
int  shape_id2 
) const

Definition at line 639 of file shapetable.cpp.

639  {
640  const Shape& shape1 = GetShape(shape_id1);
641  const Shape& shape2 = GetShape(shape_id2);
642  for (int c1 = 0; c1 < shape1.size(); ++c1) {
643  int unichar_id1 = shape1[c1].unichar_id;
644  if (shape2.ContainsUnichar(unichar_id1))
645  return true;
646  }
647  return false;
648 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
STRING tesseract::ShapeTable::DebugStr ( int  shape_id) const

Definition at line 291 of file shapetable.cpp.

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

Definition at line 371 of file shapetable.cpp.

371  {
372  delete shape_table_[shape_id];
373  shape_table_[shape_id] = NULL;
374  shape_table_.remove(shape_id);
375 }
#define NULL
Definition: host.h:144
bool tesseract::ShapeTable::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 256 of file shapetable.cpp.

256  {
257  if (!shape_table_.DeSerialize(swap, fp)) return false;
258  num_fonts_ = 0;
259  return true;
260 }
bool tesseract::ShapeTable::EqualUnichars ( int  shape_id1,
int  shape_id2 
) const

Definition at line 597 of file shapetable.cpp.

597  {
598  const Shape& shape1 = GetShape(shape_id1);
599  const Shape& shape2 = GetShape(shape_id2);
600  for (int c1 = 0; c1 < shape1.size(); ++c1) {
601  int unichar_id1 = shape1[c1].unichar_id;
602  if (!shape2.ContainsUnichar(unichar_id1))
603  return false;
604  }
605  for (int c2 = 0; c2 < shape2.size(); ++c2) {
606  int unichar_id2 = shape2[c2].unichar_id;
607  if (!shape1.ContainsUnichar(unichar_id2))
608  return false;
609  }
610  return true;
611 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
int tesseract::ShapeTable::FindShape ( int  unichar_id,
int  font_id 
) const

Definition at line 396 of file shapetable.cpp.

396  {
397  for (int s = 0; s < shape_table_.size(); ++s) {
398  const Shape& shape = GetShape(s);
399  for (int c = 0; c < shape.size(); ++c) {
400  if (shape[c].unichar_id == unichar_id) {
401  if (font_id < 0)
402  return s; // We don't care about the font.
403  for (int f = 0; f < shape[c].font_ids.size(); ++f) {
404  if (shape[c].font_ids[f] == font_id)
405  return s;
406  }
407  }
408  }
409  }
410  return -1;
411 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
void tesseract::ShapeTable::ForceFontMerges ( int  start,
int  end 
)

Definition at line 478 of file shapetable.cpp.

478  {
479  for (int s1 = start; s1 < end; ++s1) {
480  if (MasterDestinationIndex(s1) == s1 && GetShape(s1).size() == 1) {
481  int unichar_id = GetShape(s1)[0].unichar_id;
482  for (int s2 = s1 + 1; s2 < end; ++s2) {
483  if (MasterDestinationIndex(s2) == s2 && GetShape(s2).size() == 1 &&
484  unichar_id == GetShape(s2)[0].unichar_id) {
485  MergeShapes(s1, s2);
486  }
487  }
488  }
489  }
490  ShapeTable compacted(*unicharset_);
491  compacted.AppendMasterShapes(*this, NULL);
492  *this = compacted;
493 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
void MergeShapes(int shape_id1, int shape_id2)
Definition: shapetable.cpp:523
#define NULL
Definition: host.h:144
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
void tesseract::ShapeTable::GetFirstUnicharAndFont ( int  shape_id,
int *  unichar_id,
int *  font_id 
) const

Definition at line 414 of file shapetable.cpp.

415  {
416  const UnicharAndFonts& unichar_and_fonts = (*shape_table_[shape_id])[0];
417  *unichar_id = unichar_and_fonts.unichar_id;
418  *font_id = unichar_and_fonts.font_ids[0];
419 }
const Shape& tesseract::ShapeTable::GetShape ( int  shape_id) const
inline

Definition at line 323 of file shapetable.h.

323  {
324  return *shape_table_[shape_id];
325  }
int tesseract::ShapeTable::MasterDestinationIndex ( int  shape_id) const

Definition at line 541 of file shapetable.cpp.

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

Definition at line 502 of file shapetable.cpp.

502  {
503  int master_id = MasterDestinationIndex(shape_id);
504  const Shape& shape = GetShape(master_id);
505  int font_count = 0;
506  for (int c = 0; c < shape.size(); ++c) {
507  font_count += shape[c].font_ids.size();
508  }
509  return font_count;
510 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
int tesseract::ShapeTable::MasterUnicharCount ( int  shape_id) const

Definition at line 496 of file shapetable.cpp.

496  {
497  int master_id = MasterDestinationIndex(shape_id);
498  return GetShape(master_id).size();
499 }
int size() const
Definition: shapetable.h:202
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
int tesseract::ShapeTable::MaxNumUnichars ( ) const

Definition at line 465 of file shapetable.cpp.

465  {
466  int max_num_unichars = 0;
467  int num_shapes = NumShapes();
468  for (int s = 0; s < num_shapes; ++s) {
469  if (GetShape(s).size() > max_num_unichars)
470  max_num_unichars = GetShape(s).size();
471  }
472  return max_num_unichars;
473 }
int size() const
Definition: shapetable.h:202
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
int NumShapes() const
Definition: shapetable.h:278
int tesseract::ShapeTable::MergedUnicharCount ( int  shape_id1,
int  shape_id2 
) const

Definition at line 513 of file shapetable.cpp.

513  {
514  // Do it the easy way for now.
515  int master_id1 = MasterDestinationIndex(shape_id1);
516  int master_id2 = MasterDestinationIndex(shape_id2);
517  Shape combined_shape(*shape_table_[master_id1]);
518  combined_shape.AddShape(*shape_table_[master_id2]);
519  return combined_shape.size();
520 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
bool tesseract::ShapeTable::MergeEqualUnichars ( int  merge_id1,
int  merge_id2,
int  shape_id 
) const

Definition at line 614 of file shapetable.cpp.

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

Definition at line 523 of file shapetable.cpp.

523  {
524  int master_id1 = MasterDestinationIndex(shape_id1);
525  int master_id2 = MasterDestinationIndex(shape_id2);
526  // Point master_id2 (and all merged shapes) to master_id1.
527  shape_table_[master_id2]->set_destination_index(master_id1);
528  // Add all the shapes of master_id2 to master_id1.
529  shape_table_[master_id1]->AddShape(*shape_table_[master_id2]);
530 }
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
bool tesseract::ShapeTable::MergeSubsetUnichar ( int  merge_id1,
int  merge_id2,
int  shape_id 
) const

Definition at line 571 of file shapetable.cpp.

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

Definition at line 326 of file shapetable.h.

326  {
327  return shape_table_[shape_id];
328  }
int tesseract::ShapeTable::NumFonts ( ) const

Definition at line 264 of file shapetable.cpp.

264  {
265  if (num_fonts_ <= 0) {
266  for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
267  const Shape& shape = *shape_table_[shape_id];
268  for (int c = 0; c < shape.size(); ++c) {
269  for (int f = 0; f < shape[c].font_ids.size(); ++f) {
270  if (shape[c].font_ids[f] >= num_fonts_)
271  num_fonts_ = shape[c].font_ids[f] + 1;
272  }
273  }
274  }
275  }
276  return num_fonts_;
277 }
int tesseract::ShapeTable::NumMasterShapes ( ) const

Definition at line 680 of file shapetable.cpp.

680  {
681  int num_shapes = 0;
682  for (int s = 0; s < shape_table_.size(); ++s) {
683  if (shape_table_[s]->destination_index() < 0)
684  ++num_shapes;
685  }
686  return num_shapes;
687 }
int tesseract::ShapeTable::NumShapes ( ) const
inline

Definition at line 278 of file shapetable.h.

278  {
279  return shape_table_.size();
280  }
void tesseract::ShapeTable::ReMapClassIds ( const GenericVector< int > &  unicharset_map)

Definition at line 281 of file shapetable.cpp.

281  {
282  for (int shape_id = 0; shape_id < shape_table_.size(); ++shape_id) {
283  Shape* shape = shape_table_[shape_id];
284  for (int c = 0; c < shape->size(); ++c) {
285  shape->SetUnicharId(c, unicharset_map[(*shape)[c].unichar_id]);
286  }
287  }
288 }
bool tesseract::ShapeTable::Serialize ( FILE *  fp) const

Definition at line 250 of file shapetable.cpp.

250  {
251  if (!shape_table_.Serialize(fp)) return false;
252  return true;
253 }
void tesseract::ShapeTable::set_unicharset ( const UNICHARSET unicharset)
inline

Definition at line 289 of file shapetable.h.

289  {
290  unicharset_ = &unicharset;
291  }
const UNICHARSET & unicharset() const
Definition: shapetable.h:281
bool tesseract::ShapeTable::SubsetUnichar ( int  shape_id1,
int  shape_id2 
) const

Definition at line 553 of file shapetable.cpp.

553  {
554  const Shape& shape1 = GetShape(shape_id1);
555  const Shape& shape2 = GetShape(shape_id2);
556  int c1, c2;
557  for (c1 = 0; c1 < shape1.size(); ++c1) {
558  int unichar_id1 = shape1[c1].unichar_id;
559  if (!shape2.ContainsUnichar(unichar_id1))
560  break;
561  }
562  for (c2 = 0; c2 < shape2.size(); ++c2) {
563  int unichar_id2 = shape2[c2].unichar_id;
564  if (!shape1.ContainsUnichar(unichar_id2))
565  break;
566  }
567  return c1 == shape1.size() || c2 == shape2.size();
568 }
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
STRING tesseract::ShapeTable::SummaryStr ( ) const

Definition at line 323 of file shapetable.cpp.

323  {
324  int max_unichars = 0;
325  int num_multi_shapes = 0;
326  int num_master_shapes = 0;
327  for (int s = 0; s < shape_table_.size(); ++s) {
328  if (MasterDestinationIndex(s) != s) continue;
329  ++num_master_shapes;
330  int shape_size = GetShape(s).size();
331  if (shape_size > 1)
332  ++num_multi_shapes;
333  if (shape_size > max_unichars)
334  max_unichars = shape_size;
335  }
336  STRING result;
337  result.add_str_int("Number of shapes = ", num_master_shapes);
338  result.add_str_int(" max unichars = ", max_unichars);
339  result.add_str_int(" number with multiple unichars = ", num_multi_shapes);
340  return result;
341 }
int size() const
Definition: shapetable.h:202
int MasterDestinationIndex(int shape_id) const
Definition: shapetable.cpp:541
void add_str_int(const char *str, int number)
Definition: strngs.cpp:376
Definition: strngs.h:44
const Shape & GetShape(int shape_id) const
Definition: shapetable.h:323
void tesseract::ShapeTable::SwapShapes ( int  shape_id1,
int  shape_id2 
)

Definition at line 533 of file shapetable.cpp.

533  {
534  Shape* tmp = shape_table_[shape_id1];
535  shape_table_[shape_id1] = shape_table_[shape_id2];
536  shape_table_[shape_id2] = tmp;
537 }
const UNICHARSET& tesseract::ShapeTable::unicharset ( ) const
inline

Definition at line 281 of file shapetable.h.

281  {
282  return *unicharset_;
283  }

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