//--------------------------------------------------------- void CFlow_RecursiveUp::Get_Flow(int x, int y) { int i, ix, iy, j; double jFlow; if( !is_Locked(x,y) ) { Lock_Set(x,y); Init_Cell(x,y); for(i=0, j=4; i<8; i++, j=(j+1)%8) { ix = Get_xTo(i,x); iy = Get_yTo(i,y); if( is_InGrid(ix,iy) ) { jFlow = Flow[iy][ix][j]; if( jFlow > 0 ) { Get_Flow(ix,iy); Add_Fraction(ix,iy,j,jFlow); } } } } }
//--------------------------------------------------------- void CChannelNetwork::Set_Channel_Order(int x, int y) { int i, ix, iy, j, n; //----------------------------------------------------- if( pChannelRoute->asChar(x,y) > 0 ) { for(i=n=0, j=4; i<8; i++, j=(j+1)%8) { ix = Get_xTo(i,x); iy = Get_yTo(i,y); if( pDTM->is_InGrid(ix,iy) && pChannelRoute->asChar(ix,iy) && j == pChannelRoute->asChar(ix,iy) % 8 ) { n++; } } //----------------------------------------------------- if( n == 0 ) { Lock_Create(); do { Lock_Set(x,y); pChannels->Add_Value(x,y, 1 ); i = pChannelRoute->asChar(x,y); if( i > 0 ) { x = Get_xTo(i,x); y = Get_yTo(i,y); } } while( pDTM->is_InGrid(x,y) && i > 0 && !is_Locked(x,y) ); } } }
//--------------------------------------------------------- void CPit_Eliminator::Fill_Sink(int x, int y, int j, double z) { int i, ix, iy; if( is_InGrid(x, y) && !is_Locked(x, y) && goRoute->asChar(x, y) == j ) { Lock_Set(x, y); z += M_ALMOST_ZERO * Get_UnitLength(j); if( pDTM->asDouble(x, y) < z ) { pDTM->Set_Value(x, y, z); for(i=0, j=4; i<8; i++, j=(j+1)%8) { ix = Get_xTo(i, x); iy = Get_yTo(i, y); Fill_Sink(ix, iy, j, z); } } } }
//--------------------------------------------------------- void CChannelNetwork::Set_Vector(int x, int y, int ID) { bool bContinue; int i, ix, iy, j, Order; double xMin, yMin, Length; CSG_Shape *pShape; //----------------------------------------------------- if( (Order = pChannels->asInt(x,y)) > 0 ) { bContinue = true; for(i=0, j=4; i<8 && bContinue; i++, j=(j+1)%8) { ix = Get_xTo(i,x); iy = Get_yTo(i,y); if( pDTM->is_InGrid(ix,iy) && pChannels->asInt(ix,iy) == Order && pChannelRoute->asChar(ix,iy) && j == pChannelRoute->asChar(ix,iy) % 8 ) { bContinue = false; } } //------------------------------------------------- if( bContinue ) // Startpunkt gefunden... { xMin = pDTM->Get_XMin(), yMin = pDTM->Get_YMin(); ID = 1; pShape = pShapes->Add_Shape(); do { bContinue = false; Length = 0; Lock_Set(x,y); pShape->Add_Point(xMin + x * Get_Cellsize(), yMin + y * Get_Cellsize()); i = pChannelRoute->asChar(x,y); if( i > 0 ) { ix = Get_xTo(i,x); iy = Get_yTo(i,y); Length += Get_Length(i); if( pDTM->is_InGrid(ix,iy) ) { if( !is_Locked(ix,iy) && ( pChannels->asInt(ix,iy) == Order || pChannels->asInt(ix,iy) < 0) ) { x = ix; y = iy; bContinue = true; } else { pShape->Add_Point(xMin + ix * Get_Cellsize(), yMin + iy * Get_Cellsize()); } } } } while( bContinue ); pShape->Set_Value(0, ID ); pShape->Set_Value(1, Order ); pShape->Set_Value(2, Length ); } } }
//--------------------------------------------------------- void CChannelNetwork::Set_Channel_Route(int x, int y) { const int BUFFER_GROWSIZE = 256; int xStart, yStart, i, ix, iy, goDir, m, n, nDiv; double z, dz, dzMin, Length; //----------------------------------------------------- if( pStart->asChar(x,y) && !pChannelRoute->asChar(x,y) ) { Lock_Create(); n = 0; nDiv = 0; Length = 0; xStart = x; yStart = y; do { //--------------------------------------------- // 1. Divergence ?!... if( pConvergence ) { if( pConvergence->asDouble(x,y) > -1.0 ) { nDiv++; } else { nDiv = 0; } } if( pConvergence && nDiv > maxDivCells ) { goDir = -1; } else { //----------------------------------------- // 2. Is there any channel around ?!... goDir = 0; z = pDTM->asDouble(x,y); for(i=1; i<=8; i++) { ix = Get_xTo(i,x); iy = Get_yTo(i,y); if( pDTM->is_InGrid(ix,iy) && !is_Locked(ix,iy) && pChannelRoute->asChar(ix,iy) ) { dz = (z - pDTM->asDouble(ix,iy)) / Get_Length(i); if( goDir <= 0 || dzMin < dz ) { goDir = i; dzMin = dz; } } } if( goDir <= 0 ) // ...if not then go as usual... { goDir = pChannels->asInt(x,y); } //----------------------------------------- // 3. Go to Drainage Direction !... if( goDir > 0 ) { Lock_Set(x,y); x = Get_xTo(goDir,x); y = Get_yTo(goDir,y); Length += Get_UnitLength(goDir); if( n >= Direction_Buffer ) { Direction_Buffer += BUFFER_GROWSIZE; Direction = (int *)SG_Realloc(Direction, Direction_Buffer * sizeof(int)); } Direction[n++] = goDir; } } } while( goDir > 0 && pDTM->is_InGrid(x,y) && !is_Locked(x,y) && !pChannelRoute->asChar(x,y) ); //------------------------------------------------- if( Length >= minLength ) { x = xStart; y = yStart; if( goDir < 0 ) { n -= nDiv; } for(m=0; m<n; m++) { goDir = Direction[m]; pChannelRoute->Set_Value(x,y,goDir); for(i=0; i<8; i++) // Don't start new channels beside existing ones... { ix = Get_xTo(i,x); iy = Get_yTo(i,y); if( pDTM->is_InGrid(ix,iy) ) { pStart->Set_Value(ix,iy,0); } } x = Get_xTo(goDir,x); y = Get_yTo(goDir,y); } } } }