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

Mask1dGaussD1.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   Mask1dGaussD1.C
00030  * @brief  Implementation of class qgar::Mask1dGaussD1.
00031  *
00032  * See file Mask1dGaussD1.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 3, 2001  10:30
00036  * @since  qgar 1.0
00037  */
00038 
00039 
00040 // The following code is an adaptation of code written by Carsten Steger
00041 // at TU Muenchen, Germany. Here is the copyright notice from his code:
00042 //+----------------------------------------------------------------------+
00043 //| Copyright (C) 1996 Carsten Steger                                    |
00044 //|                                                                      |
00045 //| This program is free software; you can redistribute it and/or modify |
00046 //| it under the terms of the GNU General Public License as published by |
00047 //| the Free Software Foundation; either version 2, or (at your option)  |
00048 //| any later version.                                                   |
00049 //|                                                                      |
00050 //| This program is distributed in the hope that it will be useful, but  |
00051 //| WITHOUT ANY WARRANTY; without even the implied warranty of           |
00052 //| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
00053 //| General Public License for more details.                             |
00054 //|                                                                      |
00055 //| You should have received a copy of the GNU General Public License    |
00056 //| along with this program; if not, write to the Free Software          |
00057 //| Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            |
00058 //+----------------------------------------------------------------------+
00059 
00060 
00061 
00062 // STL
00063 #include <cmath>
00064 // QGAR
00065 #include <qgarlib/Mask1dGaussD1.H>
00066 #include <qgarlib/math.H>
00067 
00068 
00069 
00070 namespace qgar
00071 {
00072 
00073 
00074 // LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
00075 //
00076 // L O C A L   A U X I L I A R I E S
00077 //
00078 // LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
00079 
00080 namespace
00081 {
00082 
00083 
00084 double MASK1DGAUSSD1_phi1(double aX, double aSigma)
00085 {
00086   double r = aX / aSigma;
00087   return Math::QG_1_SQRT_2PI / aSigma * exp(-0.5 * r * r);
00088 }
00089 
00090 
00091 } // unnamed namespace
00092 
00093 // LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
00094 
00095 
00096 
00097 
00098 // -------------------------------------------------------------------
00099 // C O N S T R U C T O R S 
00100 // -------------------------------------------------------------------
00101 
00102 // COPY CONSTRUCTOR
00103 Mask1dGaussD1::Mask1dGaussD1(const Mask1dGaussD1& aMask)
00104 
00105   : DMask1d(aMask)
00106 
00107 {
00108   // VOID
00109 }
00110 
00111 
00112 // INITIALIZE FROM GIVEN SIGMA
00113 Mask1dGaussD1::Mask1dGaussD1(double aSigma)
00114 {
00115   // Error < 0.001 on each side
00116   double limit = ceil(3.46087178201605 * aSigma);
00117   int    n     = (int) ceil(limit);
00118 
00119   _width     = (2 * n) + 1;        // Width of mask [-n..n]
00120   _pCoeffMap = new double[_width]; // Allocate space for mask
00121 
00122   // Fill [-(n-1)..(n-1)]
00123   double* pm = _pCoeffMap + 1;
00124   for (int idx = -n + 1 ; idx <= (n - 1) ; ++idx)
00125     {
00126       *pm++ =   MASK1DGAUSSD1_phi1( 0.5 - idx, aSigma)
00127               - MASK1DGAUSSD1_phi1(-0.5 - idx, aSigma);
00128     }
00129 
00130   // Fill extremities
00131   *_pCoeffMap = -MASK1DGAUSSD1_phi1(n - 0.5, aSigma);  // -n
00132   *pm         =  MASK1DGAUSSD1_phi1(0.5 - n, aSigma);  // +n
00133 }
00134 
00135 // -------------------------------------------------------------------
00136 // D E S T R U C T O R 
00137 // -------------------------------------------------------------------
00138 
00139 Mask1dGaussD1::~Mask1dGaussD1()
00140 {
00141   // VOID
00142 }
00143 
00144 
00145 // -------------------------------------------------------------------
00146 // O P E R A T O R S 
00147 // -------------------------------------------------------------------
00148 
00149 // ASSIGNMENT.
00150 // PERFORM A DEEP COPY
00151 Mask1dGaussD1& Mask1dGaussD1::operator=(const Mask1dGaussD1& aMask)
00152 {
00153   DMask1d::operator=(aMask);
00154   return *this;
00155 }
00156 
00157 // -------------------------------------------------------------------
00158 
00159 
00160 } // namespace qgar