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