tesseract  5.0.0
tesseract::ParagraphTheory Class Reference

#include <paragraphs_internal.h>

Public Member Functions

 ParagraphTheory (std::vector< ParagraphModel * > *models)
 
std::vector< ParagraphModel * > & models ()
 
const std::vector< ParagraphModel * > & models () const
 
const ParagraphModelAddModel (const ParagraphModel &model)
 
void DiscardUnusedModels (const SetOfModels &used_models)
 
void NonCenteredModels (SetOfModels *models)
 
const ParagraphModelFits (const std::vector< RowScratchRegisters > *rows, int start, int end) const
 
int IndexOf (const ParagraphModel *model) const
 

Detailed Description

Definition at line 191 of file paragraphs_internal.h.

Constructor & Destructor Documentation

◆ ParagraphTheory()

tesseract::ParagraphTheory::ParagraphTheory ( std::vector< ParagraphModel * > *  models)
inlineexplicit

Definition at line 195 of file paragraphs_internal.h.

195 : models_(models) {}
std::vector< ParagraphModel * > & models()

Member Function Documentation

◆ AddModel()

const ParagraphModel * tesseract::ParagraphTheory::AddModel ( const ParagraphModel model)

Definition at line 1267 of file paragraphs.cpp.

1267  {
1268  for (const auto &m : *models_) {
1269  if (m->Comparable(model)) {
1270  return m;
1271  }
1272  }
1273  auto *m = new ParagraphModel(model);
1274  models_->push_back(m);
1275  push_back_new(models_we_added_, m);
1276  return m;
1277 }
void push_back_new(std::vector< T > &vector, const T &data)
Definition: paragraphs.cpp:418

◆ DiscardUnusedModels()

void tesseract::ParagraphTheory::DiscardUnusedModels ( const SetOfModels used_models)

Definition at line 1279 of file paragraphs.cpp.

1279  {
1280  size_t w = 0;
1281  for (size_t r = 0; r < models_->size(); r++) {
1282  ParagraphModel *m = (*models_)[r];
1283  if (!contains(used_models, static_cast<const ParagraphModel *>(m)) && contains(models_we_added_, m)) {
1284  delete m;
1285  } else {
1286  if (r > w) {
1287  (*models_)[w] = m;
1288  }
1289  w++;
1290  }
1291  }
1292  models_->resize(w);
1293 }
bool contains(const std::vector< T > &data, const T &value)
Definition: helpers.h:37

◆ Fits()

const ParagraphModel * tesseract::ParagraphTheory::Fits ( const std::vector< RowScratchRegisters > *  rows,
int  start,
int  end 
) const

Definition at line 1298 of file paragraphs.cpp.

1299  {
1300  for (const auto *model : *models_) {
1301  if (model->justification() != JUSTIFICATION_CENTER && RowsFitModel(rows, start, end, model)) {
1302  return model;
1303  }
1304  }
1305  return nullptr;
1306 }
@ JUSTIFICATION_CENTER
Definition: publictypes.h:251
bool RowsFitModel(const std::vector< RowScratchRegisters > *rows, int start, int end, const ParagraphModel *model)

◆ IndexOf()

int tesseract::ParagraphTheory::IndexOf ( const ParagraphModel model) const

Definition at line 1316 of file paragraphs.cpp.

1316  {
1317  int i = 0;
1318  for (const auto *m : *models_) {
1319  if (m == model) {
1320  return i;
1321  }
1322  i++;
1323  }
1324  return -1;
1325 }

◆ models() [1/2]

std::vector<ParagraphModel *>& tesseract::ParagraphTheory::models ( )
inline

Definition at line 196 of file paragraphs_internal.h.

196  {
197  return *models_;
198  }

◆ models() [2/2]

const std::vector<ParagraphModel *>& tesseract::ParagraphTheory::models ( ) const
inline

Definition at line 199 of file paragraphs_internal.h.

199  {
200  return *models_;
201  }

◆ NonCenteredModels()

void tesseract::ParagraphTheory::NonCenteredModels ( SetOfModels models)

Definition at line 1308 of file paragraphs.cpp.

1308  {
1309  for (const auto *model : *models_) {
1310  if (model->justification() != JUSTIFICATION_CENTER) {
1311  push_back_new(*models, model);
1312  }
1313  }
1314 }

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