00001 /*************************************************************************** 00002 normalize.cpp - description 00003 ------------------- 00004 begin : july 2nd, 2006 00005 copyright : (C) 2006 by Frédéric RODRIGO 00006 email : f.rodrigo free.fr 00007 00008 $Id: normalize.cpp 83 2006-11-05 20:46:42Z neoneurone $ 00009 ***************************************************************************/ 00010 00011 /*************************************************************************** 00012 * * 00013 * This program is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU General Public License as published by * 00015 * the Free Software Foundation; either version 2 of the License, or * 00016 * any later version. * 00017 * * 00018 ***************************************************************************/ 00019 00020 #include "normalize.h" 00021 00022 //#include <math.h> 00023 00024 namespace MapGen 00025 { 00026 00027 /*=====================================================================*/ 00028 Normalize::Normalize( 00029 const float min, 00030 const float max ): 00031 _min(min), 00032 _max(max) 00033 { 00034 MAP_DEBUG( "ctor" ); 00035 } 00036 00037 00038 /*=====================================================================*/ 00039 Normalize::~Normalize() 00040 { 00041 MAP_DEBUG( "ctor" ); 00042 } 00043 00044 00045 /*=====================================================================*/ 00046 void Normalize::apply( Map* map ) 00047 { 00048 float min, max; 00049 _getMinMax( map, &min, &max ); 00050 00051 float a = (_max-_min) / (max-min); 00052 float b = -min * a + _min; 00053 00054 for( uint x=0 ; x<map->getW() ; ++x ) 00055 for( uint y=0 ; y<map->getH() ; ++y ) 00056 map->setAt( x, y, a*map->getAt(x,y)+b ); 00057 } 00058 00059 }
1.4.2