tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
workingpartset.h
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.
73  // The most recently added partition.
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_
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
Definition: workingpartset.h:32
BLOCK_LIST completed_blocks_
Definition: workingpartset.h:80
ColPartition_IT part_it_
Definition: workingpartset.h:78
Definition: baseapi.cpp:94
ColPartition_LIST part_set_
Definition: workingpartset.h:76
void AddPartition(ColPartition *part)
Definition: workingpartset.cpp:31
ColPartition * latest_part_
Definition: workingpartset.h:74
void set_column(ColPartition *col)
Definition: workingpartset.h:42
void MakeBlocks(const ICOORD &bleft, const ICOORD &tright, int resolution, ColPartition_LIST *used_parts)
Definition: workingpartset.cpp:83
integer coordinate
Definition: points.h:32
ColPartition * column() const
Definition: workingpartset.h:39
WorkingPartSet(ColPartition *column)
Definition: workingpartset.h:34
ColPartition * column_
Definition: workingpartset.h:72
TO_BLOCK_LIST to_blocks_
Definition: workingpartset.h:81
void InsertCompletedBlocks(BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks)
Definition: workingpartset.cpp:72
Definition: colpartition.h:68