1
/***************************************************************************
2
qgsruggednessfilter.cpp - description
3
-----------------------
4
begin : August 7th, 2009
5
copyright : (C) 2009 by Marco Hugentobler
6
email : marco dot hugentobler at karto dot baug dot ethz dot ch
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#include "qgsruggednessfilter.h"
20
QgsRuggednessFilter::QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): QgsNineCellFilter( inputFile, outputFile, outputFormat )
25
QgsRuggednessFilter::QgsRuggednessFilter(): QgsNineCellFilter( "", "", "" )
31
QgsRuggednessFilter::~QgsRuggednessFilter()
36
float QgsRuggednessFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
37
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
39
//the formula would be that easy without nodata values...
41
//return *x22; //test: write the raster value of the middle cell
42
float diff1 = *x11 - *x22;
43
float diff2 = *x21 - *x22;
44
float diff3 = *x31 - *x22;
45
float diff4 = *x12 - *x22;
46
float diff5 = *x32 - *x22;
47
float diff6 = *x13 - *x22;
48
float diff7 = *x23 - *x22;
49
float diff8 = *x33 - *x22;
50
return sqrt(diff1 * diff1 + diff2 * diff2 + diff3 * diff3 + diff4 * diff4 + diff5 * diff5 + diff6 * diff6 + diff7 * diff7 + diff8 * diff8);
53
if ( *x22 == mInputNodataValue )
55
return mOutputNodataValue;
59
if ( *x11 != mInputNodataValue )
61
sum += ( *x11 - *x22 ) * ( *x11 - *x22 );
63
if ( *x21 != mInputNodataValue )
65
sum += ( *x21 - *x22 ) * ( *x21 - *x22 );
67
if ( *x31 != mInputNodataValue )
69
sum += ( *x31 - *x22 ) * ( *x31 - *x22 );
71
if ( *x12 != mInputNodataValue )
73
sum += ( *x12 - *x22 ) * ( *x12 - *x22 );
75
if ( *x32 != mInputNodataValue )
77
sum += ( *x32 - *x22 ) * ( *x32 - *x22 );
79
if ( *x13 != mInputNodataValue )
81
sum += ( *x13 - *x22 ) * ( *x13 - *x22 );
83
if ( *x23 != mInputNodataValue )
85
sum += ( *x23 - *x22 ) * ( *x23 - *x22 );
87
if ( *x33 != mInputNodataValue )
89
sum += ( *x33 - *x22 ) * ( *x33 - *x22 );