1 /*  GNU Ocrad - Optical Character Recognition program
2     Copyright (C) 2003-2019 Antonio Diaz Diaz.
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 class Profile
19   {
20 public:
21   enum Type { left, top, right, bottom, height, width };
22 
23 private:
24   const Bitmap & bm;		// Bitmap to witch this profile belongs
25 				// can be a Blob or a hole
26   Type type;
27   int limit_, max_, min_, mean_;
28   signed char isconcave_, isconvex_, isflat_, isflats_,
29               ispit_, istpit_, isupit_, isvpit_, istip_;
30   std::vector< int > data;
31 
32   void initialize();
33   int mean();
34 
35 public:
36   Profile( const Bitmap & bm_, const Type t );
37 
38 //  const Bitmap & bitmap() const { return bm; }
39 
limit()40   int limit() { if( limit_ < 0 ) initialize(); return limit_; }
41   int max();
42   int max( const int l, int r = -1 );
43   int min();
44   int min( const int l, int r = -1 );
45   int operator[]( int i );
pos(const int p)46   int pos( const int p ) { return ( ( samples() - 1 ) * p ) / 100; }
range()47   int range() { return max() - min(); }
samples()48   int samples() { if( limit_ < 0 ) initialize(); return data.size(); }
49 
50   int  area( const int l = 0, int r = -1 );
51   bool increasing( int i = 1, const int min_delta = 2 );
52   bool decreasing( int i = 1, int end = -1 );
53   bool isconcave();
54   bool isconvex();
55   bool isflat();
56   bool isflats();
57   bool ispit();
58   bool iscpit( const int cpos = 50 );
59   bool istpit();
60   bool isupit();
61   bool isvpit();
62   bool istip();
63   bool isctip( const int cpos = 50 );
64   bool isltip();
65   bool isrtip();
66   int  imaximum();
67   int  iminimum( const int m = 0, int th = -1 );
68   int  minima( int th = -1 );
69   bool straight( int * const dyp );
70   };
71