/src/tesseract/src/textord/workingpartset.h
Line | Count | Source (jump to first uncovered line) |
1 | | /////////////////////////////////////////////////////////////////////// |
2 | | // 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 | | // |
19 | | /////////////////////////////////////////////////////////////////////// |
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<WorkingPartSet>::LINK { |
33 | | public: |
34 | | explicit WorkingPartSet(ColPartition *column) |
35 | 0 | : column_(column), latest_part_(nullptr), part_it_(&part_set_) {} |
36 | | |
37 | | // Simple accessors. |
38 | 0 | ColPartition *column() const { |
39 | 0 | return column_; |
40 | 0 | } |
41 | 0 | void set_column(ColPartition *col) { |
42 | 0 | column_ = col; |
43 | 0 | } |
44 | | |
45 | | // Add the partition to this WorkingPartSet. Partitions are generally |
46 | | // stored in the order in which they are received, but if the partition |
47 | | // has a SingletonPartner, make sure that it stays with its partner. |
48 | | void AddPartition(ColPartition *part); |
49 | | |
50 | | // Make blocks out of any partitions in this WorkingPartSet, and append |
51 | | // them to the end of the blocks list. bleft, tright and resolution give |
52 | | // the bounds and resolution of the source image, so that blocks can be |
53 | | // made to fit in the bounds. |
54 | | // All ColPartitions go in the used_parts list, as they need to be kept |
55 | | // around, but are no longer needed. |
56 | | void ExtractCompletedBlocks(const ICOORD &bleft, const ICOORD &tright, int resolution, |
57 | | ColPartition_LIST *used_parts, BLOCK_LIST *blocks, |
58 | | TO_BLOCK_LIST *to_blocks); |
59 | | |
60 | | // Insert the given blocks at the front of the completed_blocks_ list so |
61 | | // they can be kept in the correct reading order. |
62 | | void InsertCompletedBlocks(BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks); |
63 | | |
64 | | private: |
65 | | // Convert the part_set_ into blocks, starting a new block at a break |
66 | | // in partnerships, or a change in linespacing (for text). |
67 | | void MakeBlocks(const ICOORD &bleft, const ICOORD &tright, int resolution, |
68 | | ColPartition_LIST *used_parts); |
69 | | |
70 | | // The column that this working set applies to. Used by the caller. |
71 | | ColPartition *column_; |
72 | | // The most recently added partition. |
73 | | ColPartition *latest_part_; |
74 | | // All the partitions in the block that is currently under construction. |
75 | | ColPartition_LIST part_set_; |
76 | | // Iteratorn on part_set_ pointing to the most recent addition. |
77 | | ColPartition_IT part_it_; |
78 | | // The blocks that have been made so far and belong before the current block. |
79 | | BLOCK_LIST completed_blocks_; |
80 | | TO_BLOCK_LIST to_blocks_; |
81 | | }; |
82 | | |
83 | | ELISTIZEH(WorkingPartSet) |
84 | | |
85 | | } // namespace tesseract. |
86 | | |
87 | | #endif // TESSERACT_TEXTORD_WORKINGPARSET_H_ |