/* 
* 
* 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 CELLTREE_H
#define CELLTREE_H

#include "GeoMorph.h"

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

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


#ifdef __cplusplus
extern "C" {
#endif
	int CreateWeightedCellTree ( const int HandleFlowDir , int RootCell , int HandleWeight );
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
	int DestroyCellTree ( const int HandleCellTree );
#ifdef __cplusplus
}
#endif

int FreeCellTree_ ( CellTree * T );

CellTree * GetCellTree ( const int HandleCellTree );

int MakeStreamLines_ ( CellTree * T , float * _threshold , int * _todivide , CellTree * Ancestor , int * _nstreams , int ** _StreamLength ,  int *** _StreamConnect , int *** _StreamCells );

#ifdef __cplusplus
extern "C" {
#endif
    int MakeStreamLines ( const int HandleTree , float * _threshold , int * _todivide , int * _nstreams , int ** _StreamLength , int *** _StreamConnect , int *** _StreamCells );
#ifdef __cplusplus
}
#endif

int SampleMainStream_ ( CellTree * T , int * _ntribut , int ** _TributOutlet , int ** _TributSize );

#ifdef __cplusplus
extern "C" {
#endif
    int SampleMainStream ( const int HandleTree , int * _ntribut , int ** _TributOutlet , int ** _TributSize );
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
    int MainBifurcationNode ( int HandleTree , 
                              int * _A , int * _B , int * _C , int * _D );
#ifdef __cplusplus
}
#endif

int MainBifurcationNode_ ( CellTree * T , 
                           int * _A , int * _B , int * _C , int * _D , float * _SB );


int UpstreamAverage_ ( CellTree * T , FloatRaster * R , FloatRaster * Rm, float * _sum );

#ifdef __cplusplus
extern "C" {
#endif
    int UpstreamAverage ( int HandleTree , int HandleRasterLocal , int HandleRasterAveraged );
#ifdef __cplusplus
}
#endif

#endif
