📄 telinearfilter.cpp
字号:
/*****************************************************************************\ * * TeLinearFilter.cpp * * TeLinearFilter generator implementation * * Author: Martin Havl龛ek (xhavli15 AT stud.fit.vutbr.cz) * Contributors: * * ---------------------------------------------------------------------------- * * THIS SOFTWARE IS NOT COPYRIGHTED * * This source code is offered for use in the public domain. * You may use, modify or distribute it freely. * * This source code is distributed in the hope that it will be useful but * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY * DISCLAIMED. This includes but is not limited to warranties of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * If you find the source code useful, authors will kindly welcome * if you give them credit and keep their names with their source code. *\*****************************************************************************/#include "generators/TeLinearFilter.h"//-----------------------------------------------------------------------------/** * Constructor. * * Sets default generator parameters and resets the step counter. */TeLinearFilter::TeLinearFilter(){ this->setDefaults(); this->reset();}//-----------------------------------------------------------------------------/** * Sets default generator parameters. */void TeLinearFilter::setDefaults(){ hmap = NULL; stepNum = 0; // not used by this generator _times = times = 5; _coef = coef = 0.90f;}//-----------------------------------------------------------------------------/** * Updates private parameters to fit theirs public images. * * I call this "delayed setting". It ensures, that correct attributes * are used for the current task (the private ones). When the task is done, * private attributes are updated to match the public ones and then will be * used for the next task. * * User doesn't need to worry about this, because this method is called * internally from generate() and genStep() functions. * * \sa times, coef */void TeLinearFilter::updateParams(){ _times = times; _coef = coef;}//-----------------------------------------------------------------------------/** * In-One-Step generation. * * The whole generation will be done in one function call. * * Calling updateParams() should be the first thing done here. It calls * original TeHeightMap::filter_Linear() method. */void TeLinearFilter::generate(){ this->updateParams(); hmap->filter_Linear(_coef, _times);}//-----------------------------------------------------------------------------/** * One step of the generation algorithm. * * Calling updateParams() should be the first thing done in the first run. * reset() and TeHeightMap::resetFlags() should be called before returning * TRUE. * * \return TRUE if generation finished and object is ready, FALSE otherwise. * * \todo Generation should be controlled by stepNum attribute. This one * should be dynamically updated according to system performance. */SbBool TeLinearFilter::genStep(){ static int resx, resy; switch (step) { case 0: // init this->updateParams(); hmap->getResolution(resx, resy); step++; break; default: // loop if (step<_times) { int x = 0; int y = 0; // rows for (y=0; y<resy; y++) { // from left to right x = 1; while (x < resx-1) { hmap->values[(y*resx)+x] = hmap->values[(y*resx)+x-1]*(1-coef)+hmap->values[(y*resx)+x]*coef; x++; } // from right to left x = resx-2; while (x > -1) { hmap->values[(y*resx)+x] = hmap->values[(y*resx)+x+1]*(1-coef)+hmap->values[(y*resx)+x]*coef; x--; } } // columns for(x=0; x<resx; x++) { // columns top to bottom y = 1; while (y < resy) { hmap->values[(y*resx)+x] = hmap->values[((y-1)*resx)+x]*(1-coef)+hmap->values[(y*resx)+x]*coef; y++; } // columns bottom to top y = resy-2; while (y > -1) { hmap->values[(y*resx)+x] = hmap->values[((y+1)*resx)+x]*(1-coef)+hmap->values[(y*resx)+x]*coef; y--; } } step++; } else { hmap->resetFlags(); this->reset(); return TRUE; } break; } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -