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

Dist8cBlackCCImage.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  Dist8cBlackCCImage.C
00030  * @brief Implementation of class qgar::Dist8cBlackCCImage.
00031  *
00032  *        See file Dist8cBlackCCImage.H for the interface.
00033  * 
00034  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Mathieu Baeumler">Mathieu Baeumler</a>
00035  * @date   August 14, 2002  15:04
00036  * @since  Qgar 2.0
00037  */
00038 
00039 
00040 // STL
00041 #include <algorithm>
00042 // QGAR
00043 #include <qgarlib/Dist8cBlackCCImage.H>
00044 #include <qgarlib/GenImage.H>
00045 
00046 
00047 
00048 namespace qgar
00049 {
00050 
00051 // ---------------------------------------------------------------------
00052 // C O N S T R U C T O R S
00053 // ---------------------------------------------------------------------
00054 
00055 Dist8cBlackCCImage::Dist8cBlackCCImage(const BinaryImage& anImg)
00056 
00057   : GreyLevelImage(anImg)
00058 
00059 {
00060   // Current image size
00061   int pixsize = _width * _height;
00062   // Pointer to current pixel map
00063   BinaryImage::value_type* pMapCurr = _pPixMap;
00064   
00065   // First line to 0
00066   for (int iCnt = 0 ; iCnt < _width ; ++iCnt)
00067     {
00068       *pMapCurr = 0;
00069       ++pMapCurr;
00070     }
00071 
00072   // First and last columns to 0
00073   for (int iCnt = 1 ; iCnt < (_height - 1) ; ++iCnt, pMapCurr += _width)
00074     {
00075       *pMapCurr = 0;
00076       *(pMapCurr + _width - 1) = 0;
00077     }
00078 
00079   // Last line to 0
00080   for (int iCnt = 0 ; iCnt < _width ; ++iCnt)
00081     {
00082       *pMapCurr = 0;
00083       ++pMapCurr;
00084     }
00085 
00086 
00087   pMapCurr = _pPixMap + _width + 1;
00088 
00089   for (int iCnt = 1 ; iCnt < _height ; ++iCnt)
00090     {
00091       for (int jCnt = 1 ; jCnt < _width; ++jCnt, ++pMapCurr)
00092         {
00093           if (*pMapCurr != 0)
00094             {
00095               *pMapCurr = 1 + std::min(std::min(*(pMapCurr - 1),
00096                                                 *(pMapCurr - _width - 1)), 
00097                                        std::min(*(pMapCurr - _width),
00098                                                 *(pMapCurr - _width + 1)));
00099             }
00100         }
00101 
00102       ++pMapCurr;
00103     }
00104 
00105 
00106   pMapCurr = _pPixMap + pixsize - _width - 2;
00107  
00108   for (int iCnt = _height - 2 ; iCnt >= 0 ; --iCnt)
00109     {
00110       for (int jCnt = _width - 2; jCnt >= 0 ; --jCnt, --pMapCurr)
00111         {
00112           if (*pMapCurr != 0)
00113             {
00114               BinaryImage::value_type m =
00115                 1 + std::min(std::min(*(pMapCurr + 1),
00116                                       *(pMapCurr + _width + 1)),
00117                              std::min(*(pMapCurr + _width),
00118                                       *(pMapCurr + _width - 1)));
00119 
00120               *pMapCurr = std::min(m, *pMapCurr);
00121             }
00122         }
00123 
00124       --pMapCurr;
00125     }
00126 
00127 }
00128 
00129 // ----------------------------------------------------------------------
00130 
00131 } // namespace qgar