Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CleanedBinaryImage.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------+
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2002  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 /**
00029  * @file   CleanedBinaryImage.C
00030  * @brief  Implementation of class qgar::CleanedBinaryImage.
00031  *
00032  * See file CleanedBinaryImage.H for the interface.
00033  *
00034  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00035  * @date   July 4, 2001  17:32
00036  * @since  Qgar 1.0
00037  */
00038 
00039 
00040 // QGAR
00041 #include <qgarlib/CleanedBinaryImage.H>
00042 
00043 
00044 
00045 namespace qgar
00046 {
00047 
00048 // -------------------------------------------------------------------
00049 // C O N S T R U C T O R
00050 // -------------------------------------------------------------------
00051 CleanedBinaryImage::CleanedBinaryImage(const BinaryImage& img)
00052 
00053   : BinaryImage(img)
00054 
00055 {
00056   // Allocate a table for three lines
00057   BinaryImage::value_type* rows = new BinaryImage::value_type[3 * _width];
00058   // Allocate a table for resulting line
00059   BinaryImage::value_type* resrow = new BinaryImage::value_type[_width];
00060   // Read two first lines
00061   img.row(0, rows);
00062   img.row(1, rows+_width);
00063   // Where the last line read is located in rows
00064   int nextLine = 1;
00065   // Where the current line is located
00066   int currLine = 0;
00067   // Where the previous line is located (fiction right here)
00068   int prevLine = 2;
00069 
00070   for (int i = 1 ; i < _height - 1 ; i++)
00071     {
00072       // Read the new line and set up all pointers to right place
00073       // We replace the previous line
00074       img.row(i+1, rows + prevLine*_width);
00075       // rotate the three positions
00076       int savprevLine = prevLine;
00077       // the previous line becomes last current line
00078       prevLine = currLine;
00079       // the current line becomes the last read
00080       currLine = nextLine;
00081       // the next line is the last read
00082       nextLine = savprevLine;
00083 
00084       // Pointers in the three rows
00085       BinaryImage::value_type* pprev = rows + prevLine*_width + 1;
00086       BinaryImage::value_type* pcurr = rows + currLine*_width + 1;
00087       BinaryImage::value_type* pnext = rows + nextLine*_width + 1;
00088 
00089       // and in result
00090       img.row(i, resrow);
00091       BinaryImage::value_type* q = resrow + 1;
00092 
00093       for (int j = 1 ; j < _width-1 ; j++, pprev++, pcurr++, pnext++, q++)
00094         {
00095         if(*pcurr == 0)
00096           {
00097             if((*(pcurr-1) && *(pcurr+1) &&
00098                 *(pnext-1) && *pnext && *(pnext+1) &&
00099                 ! *(pprev-1) && ! *pprev && ! *(pprev+1)) ||
00100                (*pprev && *(pprev+1) && *(pcurr+1) &&
00101                 *(pnext+1) && *pnext &&
00102                 ! *(pnext-1) && ! *(pcurr-1) && ! *(pprev-1)) ||
00103                (*(pcurr-1) && *(pcurr+1) &&
00104                 *(pprev-1) && *pprev && *(pprev+1) &&
00105                 ! *(pnext-1) && ! *pnext && ! *(pnext+1)) ||
00106                (*pprev && *(pprev-1) && *(pcurr-1) &&
00107                 *(pnext-1) && *pnext &&
00108                 ! *(pnext+1) && ! *(pcurr+1) && ! *(pprev+1)) ||
00109                (*(pcurr-1) && *pprev && *(pcurr+1) && *pnext))
00110               // ????????????????????????????????????????????
00111               // Maybe we should add the diagonal directions?
00112               // ????????????????????????????????????????????
00113               {
00114                 *q = 1;
00115               }
00116           }
00117         else
00118           {
00119           if((! *(pcurr-1) && ! *(pcurr+1) &&
00120               ! *(pnext-1) && ! *pnext && ! *(pnext+1) &&
00121               *(pprev-1) && *pprev && *(pprev+1)) ||
00122              (! *pprev && ! *(pprev+1) && ! *(pcurr+1) &&
00123               ! *(pnext+1) && ! *pnext &&
00124               *(pnext-1) && *(pcurr-1) && *(pprev-1)) ||
00125              (! *(pcurr-1) && ! *(pcurr+1) &&
00126               ! *(pprev-1) && ! *pprev && ! *(pprev+1) &&
00127               *(pnext-1) && *pnext && *(pnext+1)) ||
00128              (! *pprev && ! *(pprev-1) && ! *(pcurr-1) &&
00129               ! *(pnext-1) && ! *pnext &&
00130               *(pnext+1) && *(pcurr+1) && *(pprev+1)) ||
00131              (! *(pcurr-1) && ! *(pcurr+1) &&
00132               ! *(pnext-1) && ! *pnext && ! *(pnext+1) &&
00133               ! *(pprev-1) && ! *pprev && ! *(pprev+1)))
00134             // ????????????????????????????????????????????
00135             // Maybe we should add the diagonal directions?
00136             // ????????????????????????????????????????????
00137             {
00138               *q = 0;
00139             }
00140           }
00141         }
00142 
00143       setRow(i, resrow);
00144     }
00145 
00146   delete [] rows;
00147   delete [] resrow;
00148 
00149 }
00150 } // namespace qgar
00151 // -------------------------------------------------------------------