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

Mask1dGaussD2.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   Mask1dGaussD2.C
00030  * @brief  Implementation of class qgar::Mask1dGaussD2.
00031  *
00032  * See file Mask1dGaussD2.H for the interface.
00033  *
00034  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00035  * @date   Jul 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/Mask1dGaussD2.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 MASK1DGAUSSD2_phi2(double aX, double aSigma)
00085 {
00086   double r = aX / aSigma;
00087   return -aX * Math::QG_1_SQRT_2PI / pow(aSigma, 3.0) * 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 Mask1dGaussD2::Mask1dGaussD2(const Mask1dGaussD2& aMask)
00104   : DMask1d(aMask)
00105 {
00106   // VOID
00107 }
00108 
00109 // INITIALIZE FROM GIVEN SIGMA
00110 Mask1dGaussD2::Mask1dGaussD2(double aSigma)
00111 {
00112   // Error < 0.001 on each side
00113   double limit = ceil(3.82922419517181 * aSigma);
00114   int    n     = (int) ceil(limit);
00115 
00116   _width     = (2 * n) + 1;         // Width of mask [-n..n]
00117   _pCoeffMap = new double[_width];  // Allocate space for mask
00118 
00119   // Fill [-(n-1)..(n-1)]
00120   double* pm = _pCoeffMap + 1;
00121   for (int idx = -n + 1 ; idx <= (n - 1) ; ++idx)
00122     {
00123       *pm++ =   MASK1DGAUSSD2_phi2( 0.5 - idx, aSigma)
00124               - MASK1DGAUSSD2_phi2(-0.5 - idx, aSigma);
00125     }
00126 
00127   // Fill extremities
00128   *_pCoeffMap = -MASK1DGAUSSD2_phi2(n - 0.5, aSigma);  // -n
00129   *pm         =  MASK1DGAUSSD2_phi2(0.5 - n, aSigma);  // +n
00130 }
00131 
00132 // -------------------------------------------------------------------
00133 // D E S T R U C T O R 
00134 // -------------------------------------------------------------------
00135 
00136 Mask1dGaussD2::~Mask1dGaussD2()
00137 {
00138   // VOID
00139 }
00140 
00141 // -------------------------------------------------------------------
00142 // O P E R A T O R S 
00143 // -------------------------------------------------------------------
00144 
00145 // ASSIGNMENT.
00146 // PERFORM A DEEP COPY
00147 Mask1dGaussD2& Mask1dGaussD2::operator=(const Mask1dGaussD2& aMask)
00148 {
00149   DMask1d::operator=(aMask);
00150   return *this;
00151 }
00152 
00153 // -------------------------------------------------------------------
00154 
00155 
00156 } // namespace qgar