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