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

#include "GeoMorph.h"

/* LinkTree : arbre de liens filaires */

typedef struct LinkTree {

    // Attributs statiques :

    int id ;
    int startnode ;
//    int endnode ;
    
    double xstart;
    double ystart;

    double xend;
    double yend;

    int npoints ;
    double Length ;
    double PKend ;
    int flip ;             // 0 : orientation amont-> aval ; 1 :  orientation aval-> amont

    int nchildren ;             // Nombre de fils directs dans l'arbre

    // Attributs dynamiques :

    double * Points[2] ; // ( Points[0][0] , Points[0][1] )
                         //            ..         ,          ..
                         // ( Points[npoints-1][0] , Points[npoints-1][1] )
    // Topologie :

    struct LinkTree ** Child ;       // Child[i] pointe vers le i-eme element fils
    struct LinkTree * Parent;        // Pointer towards parent (downstream) link

} LinkTree ;


int MakeLinkTree ( LinkTree *** _ptrLTree , char strFichGeom[120], char strFichLinks[120], char strFichNodes[120] , double * bb , int * _nlinks );

int UpdatePK ( LinkTree ** _LTree , int nlinks );

int UpdatePK_ ( LinkTree * LTree );

int RaiseLinkTree ( LinkTree ** _LTree , int nlinks , double slope , FloatRaster * R );

int PolyLineLength ( double * (*_PolyLine)[2] , int n , double * _length );

int RasterizePolyline ( double * (*_PolyLine)[2] , int npoints , esriheader * Header, int ** _CELLS , int * _ncells );

#ifdef __cplusplus
extern "C" {
#endif
        int RaiseStreamNetwork ( char strFichGeom[120] , char strFichLinks[120] , char strFichNodes[120] , int HandleRaster , double slope );
#ifdef __cplusplus
}
#endif

int DestroyLinkTree ( LinkTree *** _ptrLTree , int nlinks );

#endif
