tesseract  5.0.0-alpha-619-ge9db
workingpartset.h
Go to the documentation of this file.
1 // File: workingpartset.h
3 // Description: Class to hold a working set of partitions of the page
4 // during construction of text/image regions.
5 // Author: Ray Smith
6 // Created: Tue Ocr 28 17:21:01 PDT 2008
7 //
8 // (C) Copyright 2008, Google Inc.
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
20 
21 #ifndef TESSERACT_TEXTORD_WORKINGPARSET_H_
22 #define TESSERACT_TEXTORD_WORKINGPARSET_H_
23 
24 #include "blobbox.h" // For TO_BLOCK_LIST and BLOCK_LIST.
25 #include "colpartition.h" // For ColPartition_LIST.
26 
27 namespace tesseract {
28 
29 // WorkingPartSet holds a working set of ColPartitions during transformation
30 // from the grid-based storage to regions in logical reading order, and is
31 // therefore only used during construction of the regions.
32 class WorkingPartSet : public ELIST_LINK {
33  public:
35  : column_(column), latest_part_(nullptr), part_it_(&part_set_) {
36  }
37 
38  // Simple accessors.
39  ColPartition* column() const {
40  return column_;
41  }
42  void set_column(ColPartition* col) {
43  column_ = col;
44  }
45 
46  // Add the partition to this WorkingPartSet. Partitions are generally
47  // stored in the order in which they are received, but if the partition
48  // has a SingletonPartner, make sure that it stays with its partner.
49  void AddPartition(ColPartition* part);
50 
51  // Make blocks out of any partitions in this WorkingPartSet, and append
52  // them to the end of the blocks list. bleft, tright and resolution give
53  // the bounds and resolution of the source image, so that blocks can be
54  // made to fit in the bounds.
55  // All ColPartitions go in the used_parts list, as they need to be kept
56  // around, but are no longer needed.
57  void ExtractCompletedBlocks(const ICOORD& bleft, const ICOORD& tright,
58  int resolution, ColPartition_LIST* used_parts,
59  BLOCK_LIST* blocks, TO_BLOCK_LIST* to_blocks);
60 
61  // Insert the given blocks at the front of the completed_blocks_ list so
62  // they can be kept in the correct reading order.
63  void InsertCompletedBlocks(BLOCK_LIST* blocks, TO_BLOCK_LIST* to_blocks);
64 
65  private:
66  // Convert the part_set_ into blocks, starting a new block at a break
67  // in partnerships, or a change in linespacing (for text).
68  void MakeBlocks(const ICOORD& bleft, const ICOORD& tright, int resolution,
69  ColPartition_LIST* used_parts);
70 
71  // The column that this working set applies to. Used by the caller.
72  ColPartition* column_;
73  // The most recently added partition.
74  ColPartition* latest_part_;
75  // All the partitions in the block that is currently under construction.
76  ColPartition_LIST part_set_;
77  // Iteratorn on part_set_ pointing to the most recent addition.
78  ColPartition_IT part_it_;
79  // The blocks that have been made so far and belong before the current block.
80  BLOCK_LIST completed_blocks_;
81  TO_BLOCK_LIST to_blocks_;
82 };
83 
84 ELISTIZEH(WorkingPartSet)
85 
86 } // namespace tesseract.
87 
88 #endif // TESSERACT_TEXTORD_WORKINGPARSET_H_
tesseract::WorkingPartSet::AddPartition
void AddPartition(ColPartition *part)
Definition: workingpartset.cpp:31
blobbox.h
ICOORD
integer coordinate
Definition: points.h:30
tesseract::WorkingPartSet::ExtractCompletedBlocks
void ExtractCompletedBlocks(const ICOORD &bleft, const ICOORD &tright, int resolution, ColPartition_LIST *used_parts, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: workingpartset.cpp:55
colpartition.h
ELISTIZEH
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:907
tesseract::ColPartition
Definition: colpartition.h:67
tesseract::WorkingPartSet::WorkingPartSet
WorkingPartSet(ColPartition *column)
Definition: workingpartset.h:34
tesseract
Definition: baseapi.h:65
tesseract::WorkingPartSet
Definition: workingpartset.h:32
tesseract::WorkingPartSet::column
ColPartition * column() const
Definition: workingpartset.h:39
tesseract::WorkingPartSet::set_column
void set_column(ColPartition *col)
Definition: workingpartset.h:42
ELIST_LINK
Definition: elst.h:74
tesseract::WorkingPartSet::InsertCompletedBlocks
void InsertCompletedBlocks(BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: workingpartset.cpp:72