• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**********************************************************************
2  * File:        genblob.cpp  (Formerly gblob.c)
3  * Description: Generic Blob processing routines
4  * Author:      Phil Cheatle
5  * Created:     Mon Nov 25 10:53:26 GMT 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include "mfcpch.h"
21 #include          "stepblob.h"
22 #include          "polyblob.h"
23 #include          "genblob.h"
24 
25 /**********************************************************************
26  *  blob_comparator()
27  *
28  *  Blob comparator used to sort a blob list so that blobs are in increasing
29  *  order of left edge.
30  **********************************************************************/
31 
blob_comparator(const void * blob1p,const void * blob2p)32 int blob_comparator(                     //sort blobs
33                     const void *blob1p,  //ptr to ptr to blob1
34                     const void *blob2p   //ptr to ptr to blob2
35                    ) {
36   PBLOB *blob1 = *(PBLOB **) blob1p;
37   PBLOB *blob2 = *(PBLOB **) blob2p;
38 
39   return blob1->bounding_box ().left () - blob2->bounding_box ().left ();
40 }
41 
42 
43 /**********************************************************************
44  *  c_blob_comparator()
45  *
46  *  Blob comparator used to sort a blob list so that blobs are in increasing
47  *  order of left edge.
48  **********************************************************************/
49 
c_blob_comparator(const void * blob1p,const void * blob2p)50 int c_blob_comparator(                     //sort blobs
51                       const void *blob1p,  //ptr to ptr to blob1
52                       const void *blob2p   //ptr to ptr to blob2
53                      ) {
54   C_BLOB *blob1 = *(C_BLOB **) blob1p;
55   C_BLOB *blob2 = *(C_BLOB **) blob2p;
56 
57   return blob1->bounding_box ().left () - blob2->bounding_box ().left ();
58 }
59 
60 
61 /**********************************************************************
62  *  gblob_bounding_box()
63  *
64  *  Return the bounding box of a generic blob.
65  **********************************************************************/
66 
gblob_bounding_box(PBLOB * blob,BOOL8 polygonal)67 TBOX gblob_bounding_box(                 //Get bounding box
68                        PBLOB *blob,     //generic blob
69                        BOOL8 polygonal  //is blob polygonal?
70                       ) {
71   if (polygonal)
72     return blob->bounding_box ();
73   else
74     return ((C_BLOB *) blob)->bounding_box ();
75 }
76 
77 
78 /**********************************************************************
79  *  gblob_sort_list()
80  *
81  *  Sort a generic blob list into order of bounding box left edge
82  **********************************************************************/
83 
gblob_sort_list(PBLOB_LIST * blob_list,BOOL8 polygonal)84 void gblob_sort_list(                        //Sort a gblob list
85                      PBLOB_LIST *blob_list,  //generic blob list
86                      BOOL8 polygonal         //is list polygonal?
87                     ) {
88   PBLOB_IT b_it;
89   C_BLOB_IT c_it;
90 
91   if (polygonal) {
92     b_it.set_to_list (blob_list);
93     b_it.sort (blob_comparator);
94   }
95   else {
96     c_it.set_to_list ((C_BLOB_LIST *) blob_list);
97     c_it.sort (c_blob_comparator);
98   }
99 }
100 
101 
102 /**********************************************************************
103  *  gblob_out_list()
104  *
105  *  Return the generic outline list of a generic blob.
106  **********************************************************************/
107 
gblob_out_list(PBLOB * blob,BOOL8 polygonal)108 OUTLINE_LIST *gblob_out_list(                 //Get outline list
109                              PBLOB *blob,     //generic blob
110                              BOOL8 polygonal  //is blob polygonal?
111                             ) {
112   if (polygonal)
113     return blob->out_list ();
114   else
115     return (OUTLINE_LIST *) ((C_BLOB *) blob)->out_list ();
116 }
117 
118 
119 /**********************************************************************
120  *  goutline_bounding_box()
121  *
122  *  Return the bounding box of a generic outline.
123  **********************************************************************/
124 
goutline_bounding_box(OUTLINE * outline,BOOL8 polygonal)125 TBOX goutline_bounding_box(                   //Get bounding box
126                           OUTLINE *outline,  //generic outline
127                           BOOL8 polygonal    //is outline polygonal?
128                          ) {
129   if (polygonal)
130     return outline->bounding_box ();
131   else
132     return ((C_OUTLINE *) outline)->bounding_box ();
133 }
134