tesseract v5.3.3.20231005
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 1271 of file paragraphs.cpp.

1271 {
1272 for (const auto &m : *models_) {
1273 if (m->Comparable(model)) {
1274 return m;
1275 }
1276 }
1277 auto *m = new ParagraphModel(model);
1278 models_->push_back(m);
1279 push_back_new(models_we_added_, m);
1280 return m;
1281}
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 1283 of file paragraphs.cpp.

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

◆ Fits()

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

Definition at line 1302 of file paragraphs.cpp.

1303 {
1304 for (const auto *model : *models_) {
1305 if (model->justification() != JUSTIFICATION_CENTER && RowsFitModel(rows, start, end, model)) {
1306 return model;
1307 }
1308 }
1309 return nullptr;
1310}
@ JUSTIFICATION_CENTER
Definition: publictypes.h:249
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 1320 of file paragraphs.cpp.

1320 {
1321 int i = 0;
1322 for (const auto *m : *models_) {
1323 if (m == model) {
1324 return i;
1325 }
1326 i++;
1327 }
1328 return -1;
1329}

◆ 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 1312 of file paragraphs.cpp.

1312 {
1313 for (const auto *model : *models_) {
1314 if (model->justification() != JUSTIFICATION_CENTER) {
1315 push_back_new(*models, model);
1316 }
1317 }
1318}

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