/* 
* 
* Copyright (C) 2013 UMPC
* 
* This file is part of CLaRiNet.
*  
* CLaRiNet is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* CLaRiNet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with CLaRiNet.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RASTERCALC_H
#define RASTERCALC_H

#include "GeoMorph.h"

#ifdef __cplusplus
extern "C" {
#endif
    int GetRasterValue ( const int HandleRaster , int * CELLS , const int ncells , float ** _VALUES );
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
    int RasterFind ( const int HandleRaster , const float a, const float b, int ** CELLS );
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
    int RasterFindTransition (  const int HandleRaster ,
                            const int HandleFlowDir ,
                            const float * _a,
                            const float * _b,
                            int * _root,
                            int * _nitmax,
                            int * _nfound,
                            int ** _CELLS );
#ifdef __cplusplus
}
#endif

/*int RasterFindTransition_ ( FloatRaster * R ,
                            FlowDirGrid * F ,
                            const float * _a ,
                            const float * _b ,
                            int * _root ,
                            float * _evalexpr ,
                            int * _nit ,
                            int * _nfound ,
                            int ** _CELLS );
*/

#ifdef __cplusplus
extern "C" {
#endif
    int MakeDistanceMap ( const int HandleFlowDir, const int HandleRaster, int outlet );
#ifdef __cplusplus
}
#endif

int MakeDistanceMap_ ( FlowDirGrid * F , FloatRaster * Dst , int * _outlet , int * _n1 , int * _nsqrt2 );

#ifdef __cplusplus
extern "C" {
#endif
	int MakeDistanceMap_iter ( int HandleFlowDir, int HandleRaster, int outlet );
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
    int PutRasterValue ( const int HandleRaster , const int ncells , int * CELLS , const float * VALUES );
#ifdef __cplusplus
}
#endif

void PutRasterValue1 ( FloatRaster * R , int * _rec , float * _f );

#ifdef __cplusplus
extern "C" {
#endif
    int MakeAccumulationMap ( const int HandleFlowDir, const int HandleRaster );
#ifdef __cplusplus
}
#endif

int MakeAccumulationMap_ ( FlowDirGrid * F , FloatRaster * Acc, int * _outlet , int * _nup , int * _nr_tmp , int * _nc_tmp );

#ifdef __cplusplus
extern "C" {
#endif
    int RasterCDF ( const int HandleRaster , const int HandleMask , const int nf , const float * FREQ , float ** _FVALUES , int * _N );
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
    int RasterMSE ( const int HandleRaster1 , const int HandleRaster2 , const int HandleMask , float * _MSE );
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
    int GetRasterRowAddr ( const int HandleRaster , const int row , int * _ncols , float ** _ptrRow );
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
    int PutRasterRow ( const int HandleRaster , const int row , const int nv , const float * VALUES );
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
    int FlagCatchmentCells ( const int HandleRaster , const int HandleFlowDir , int root , float flag , int nnodes, int * NODES , int ** _BB , int * _nup , int ** _IXUPNODES , int * _nixupnodes );
#ifdef __cplusplus
}
#endif

#endif
