Quantum GIS API Documentation  1.8
src/analysis/raster/qgsruggednessfilter.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsruggednessfilter.cpp  -  description
00003                           -----------------------
00004     begin                : August 7th, 2009
00005     copyright            : (C) 2009 by Marco Hugentobler
00006     email                : marco dot hugentobler at karto dot baug dot ethz dot ch
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qgsruggednessfilter.h"
00019 
00020 QgsRuggednessFilter::QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): QgsNineCellFilter( inputFile, outputFile, outputFormat )
00021 {
00022 
00023 }
00024 
00025 QgsRuggednessFilter::QgsRuggednessFilter(): QgsNineCellFilter( "", "", "" )
00026 {
00027 
00028 }
00029 
00030 
00031 QgsRuggednessFilter::~QgsRuggednessFilter()
00032 {
00033 
00034 }
00035 
00036 float QgsRuggednessFilter::processNineCellWindow( float* x11, float* x21, float* x31,
00037     float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
00038 {
00039   //the formula would be that easy without nodata values...
00040   /*
00041     //return *x22; //test: write the raster value of the middle cell
00042     float diff1 = *x11 - *x22;
00043     float diff2 = *x21 - *x22;
00044     float diff3 = *x31 - *x22;
00045     float diff4 = *x12 - *x22;
00046     float diff5 = *x32 - *x22;
00047     float diff6 = *x13 - *x22;
00048     float diff7 = *x23 - *x22;
00049     float diff8 = *x33 - *x22;
00050     return sqrt(diff1 * diff1 + diff2 * diff2 + diff3 * diff3 + diff4 * diff4 + diff5 * diff5 + diff6 * diff6 + diff7 * diff7 + diff8 * diff8);
00051    */
00052 
00053   if ( *x22 == mInputNodataValue )
00054   {
00055     return mOutputNodataValue;
00056   }
00057 
00058   double sum = 0;
00059   if ( *x11 != mInputNodataValue )
00060   {
00061     sum += ( *x11 - *x22 ) * ( *x11 - *x22 );
00062   }
00063   if ( *x21 != mInputNodataValue )
00064   {
00065     sum += ( *x21 - *x22 ) * ( *x21 - *x22 );
00066   }
00067   if ( *x31 != mInputNodataValue )
00068   {
00069     sum += ( *x31 - *x22 ) * ( *x31 - *x22 );
00070   }
00071   if ( *x12 != mInputNodataValue )
00072   {
00073     sum += ( *x12 - *x22 ) * ( *x12 - *x22 );
00074   }
00075   if ( *x32 != mInputNodataValue )
00076   {
00077     sum += ( *x32 - *x22 ) * ( *x32 - *x22 );
00078   }
00079   if ( *x13 != mInputNodataValue )
00080   {
00081     sum += ( *x13 - *x22 ) * ( *x13 - *x22 );
00082   }
00083   if ( *x23 != mInputNodataValue )
00084   {
00085     sum += ( *x23 - *x22 ) * ( *x23 - *x22 );
00086   }
00087   if ( *x33 != mInputNodataValue )
00088   {
00089     sum += ( *x33 - *x22 ) * ( *x33 - *x22 );
00090   }
00091 
00092   return sqrt( sum );
00093 }
00094 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines