📄 flow_recursivedown.cpp
字号:
{
if( is_Locked(ix, iy) )
{
if( pLinear )
{
pLinear->Add_Value(x, y, qFlow);
}
}
else
{
Lock_Set( x, y, 1);
Add_Flow(ix, iy, qFlow);
Rho8_Start(ix, iy, qFlow);
Lock_Set( x, y, 0);
}
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_RecursiveDown::KRA_Start(int x, int y, double qFlow)
{
int dir;
double dif;
if( (dif = pDif->asDouble(x, y)) > M_PI_045 ) // to the right...
{
dir = pDir->asInt(x, y) + 2;
dif = 0.5 - tan(M_PI_090 - dif) / 2.0;
}
else // to the top...
{
dir = pDir->asInt(x, y) + 0;
dif = 0.5 + tan(dif) / 2.0;
}
KRA_Trace(x, y, qFlow, dir, dif);
}
//---------------------------------------------------------
void CFlow_RecursiveDown::KRA_Trace(int x, int y, double qFlow, int Direction, double from)
{
bool bLinear;
int dir;
double dif, to, weight;
Direction %= 8;
x = Get_xTo(Direction, x);
y = Get_yTo(Direction, y);
//-----------------------------------------------------
if( pDTM->is_InGrid(x, y) && !is_Locked(x, y) )
{
Lock_Set(x, y, 1);
bLinear = false;
weight = 1.0;
dir = pDir->asInt(x, y);
dif = pDif->asDouble(x, y);
//-------------------------------------------------
if( Direction == dir ) // entering from the bottom...
{
if( from > 1.0 - tan(dif) ) // 1. to the right...
{
to = GET_OUTLET_DIAG__1(from, dif);
KRA_Trace(x, y, qFlow, dir + 2, to);
if( bFlowPathWeight )
{
weight = GET_LENGTH(1.0 - from, 1.0 - to);
}
}
else // 2. to the top...
{
to = GET_OUTLET_CROSS_1(from, dif);
KRA_Trace(x, y, qFlow, dir + 0, to);
if( bFlowPathWeight )
{
weight = GET_LENGTH(1.0, to - from);
}
}
}
else if( (8 + Direction - dir) % 8 == 2 ) // entering from the left...
{
if( from < tan(M_PI_090 - dif) ) // 1. to the top...
{
to = GET_OUTLET_DIAG__2(from, dif);
KRA_Trace(x, y, qFlow, dir + 0, to);
if( bFlowPathWeight )
{
weight = GET_LENGTH(from, to);
}
}
else // 2. to the right...
{
to = GET_OUTLET_CROSS_2(from, dif);
KRA_Trace(x, y, qFlow, dir + 2, to);
if( bFlowPathWeight )
{
weight = GET_LENGTH(1.0, from - to);
}
}
}
else // go linear...
{
bLinear = true;
}
//-------------------------------------------------
if( bLinear && pLinear )
{
pLinear->Add_Value(x, y, qFlow);
}
else
{
Add_Flow(x, y, weight * qFlow);
}
Lock_Set(x, y, 0);
}
}
///////////////////////////////////////////////////////////
// //
// DEMON - Digital Elevation MOdel Network //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CFlow_RecursiveDown::DEMON_Start(int x, int y, double qFlow)
{
double dif, flow_A, flow_B;
if( (dif = pDif->asDouble(x, y)) < M_PI_045 ) // mostly to the top...
{
flow_B = tan(dif) / 2.0;
flow_A = 1.0 - flow_B;
}
else // mostly to the right...
{
flow_A = tan(M_PI_090 - dif) / 2.0;
flow_B = 1.0 - flow_A;
}
flow_A *= qFlow;
flow_B *= qFlow;
if( flow_A <= DEMON_minDQV )
{
DEMON_Trace(x, y, qFlow , pDir->asInt(x, y) + 2, 0.0, 1.0); // all to the right...
}
else if( flow_B <= DEMON_minDQV )
{
DEMON_Trace(x, y, qFlow , pDir->asInt(x, y) + 0, 0.0, 1.0); // all to the top...
}
else
{
DEMON_Trace(x, y, flow_A, pDir->asInt(x, y) + 0, 0.0, 1.0); // to the top...
DEMON_Trace(x, y, flow_B, pDir->asInt(x, y) + 2, 0.0, 1.0); // to the right...
}
}
//---------------------------------------------------------
void CFlow_RecursiveDown::DEMON_Trace(int x, int y, double qFlow, int Direction, double from_A, double from_B)
{
bool bLinear;
int dir;
double dif, to_A, to_B, flow_A, flow_B, weight;
Direction %= 8;
x = Get_xTo(Direction, x);
y = Get_yTo(Direction, y);
//-----------------------------------------------------
if( pDTM->is_InGrid(x, y) && !is_Locked(x, y) )
{
Lock_Set(x, y, 1);
bLinear = false;
weight = 1.0;
dir = pDir->asInt(x, y);
dif = pDif->asDouble(x, y);
//-------------------------------------------------
if( Direction == dir ) // entering from the bottom...
{
if( from_A >= 1.0 - tan(dif) ) // 1. completely to the right...
{
to_A = GET_OUTLET_DIAG__1(from_A, dif);
to_B = GET_OUTLET_DIAG__1(from_B, dif);
DEMON_Trace(x, y, qFlow, dir + 2, to_A, to_B);
if( bFlowPathWeight )
{
//weight = ((1.0 - from_A) * (1.0 - to_A) - (1.0 - from_B) * (1.0 - to_B)) / 2.0; // area...
weight = GET_LENGTH(1.0 - (from_B + from_A) / 2.0, 1.0 - (to_B + to_A) / 2.0);
}
}
else if( from_B < 1.0 - tan(dif) ) // 2. completely to the top...
{
to_A = GET_OUTLET_CROSS_1(from_A, dif);
to_B = GET_OUTLET_CROSS_1(from_B, dif);
DEMON_Trace(x, y, qFlow, dir + 0, to_A, to_B);
if( bFlowPathWeight )
{
//weight = from_B - from_A; // area...
weight = GET_LENGTH(1.0, to_A - from_A);
}
}
else // 3. partly to the right, partly to the top...
{
to_A = GET_OUTLET_CROSS_1(from_A, dif);
to_B = GET_OUTLET_DIAG__1(from_B, dif);
dif = 1.0 - tan(dif);
flow_A = dif - from_A;
flow_B = from_B - dif;
flow_A = qFlow * flow_A / (flow_A + flow_B);
flow_B = qFlow - flow_A;
if( bFlowPathWeight )
{
//weight = (dif - from_A) + ((1.0 - dif) - (1.0 - from_B) * (1.0 - to_B)) / 2.0; // area...
if( (weight = (from_A + from_B) / 2.0) < dif ) // to the top...
{
weight = GET_LENGTH(1.0, to_A - from_A);
}
else // to the right...
{
weight = (1.0 - weight) / (1.0 - dif) * GET_LENGTH(1.0, to_A - from_A);
}
}
if( flow_A <= DEMON_minDQV )
{
DEMON_Trace(x, y, qFlow, dir + 2, 0.0, to_B);
}
else if( flow_B <= DEMON_minDQV )
{
DEMON_Trace(x, y, qFlow, dir + 0, to_A, 1.0);
}
else
{
DEMON_Trace(x, y, flow_A, dir + 0, to_A, 1.0);
DEMON_Trace(x, y, flow_B, dir + 2, 0.0, to_B);
}
}
}
else if( (8 + Direction - dir) % 8 == 2 ) // entering from the left...
{
if( from_B <= tan(M_PI_090 - dif) ) // 1. completely to the top...
{
to_A = GET_OUTLET_DIAG__2(from_A, dif);
to_B = GET_OUTLET_DIAG__2(from_B, dif);
DEMON_Trace(x, y, qFlow, dir + 0, to_A, to_B);
if( bFlowPathWeight )
{
//weight = (from_B * to_B - from_A * to_A) / 2.0; // area...
weight = GET_LENGTH((from_A + from_B) / 2.0, (to_A + to_B) / 2.0);
}
}
else if( from_A > tan(M_PI_090 - dif) ) // 2. completely to the right...
{
to_A = GET_OUTLET_CROSS_2(from_A, dif);
to_B = GET_OUTLET_CROSS_2(from_B, dif);
DEMON_Trace(x, y, qFlow, dir + 2, to_A, to_B);
if( bFlowPathWeight )
{
//weight = from_B - from_A; // area...
weight = GET_LENGTH(1.0, from_A - to_A);
}
}
else // 3. partly to the top, partly to the right...
{
to_A = GET_OUTLET_DIAG__2(from_A, dif);
to_B = GET_OUTLET_CROSS_2(from_B, dif);
dif = tan(M_PI_090 - dif);
flow_A = dif - from_A;
flow_B = from_B - dif;
flow_A = qFlow * flow_A / (flow_A + flow_B);
flow_B = qFlow - flow_A;
if( bFlowPathWeight )
{
//weight = (from_B - dif) + (dif - (from_A * to_A)) / 2.0; // area...
if( (weight = (from_A + from_B) / 2.0) > dif )
{
weight = GET_LENGTH(1.0, from_B - to_B);
}
else
{
weight = weight / dif * GET_LENGTH(1.0, from_B - to_B);
}
}
if( flow_A <= DEMON_minDQV )
{
DEMON_Trace(x, y, qFlow, dir + 2, 0.0, to_B);
}
else if( flow_B <= DEMON_minDQV )
{
DEMON_Trace(x, y, qFlow, dir + 0, to_A, 1.0);
}
else
{
DEMON_Trace(x, y, flow_A, dir + 0, to_A, 1.0);
DEMON_Trace(x, y, flow_B, dir + 2, 0.0, to_B);
}
}
}
else
{
bLinear = true;
}
//-------------------------------------------------
if( bLinear && pLinear )
{
pLinear->Add_Value(x, y, qFlow);
}
else
{
if( bFlowPathWeight )
{
Add_Flow(x, y, weight * qFlow);
//Add_Flow(x, y, weight >= qFlow ? qFlow : weight * qFlow);
}
else
{
Add_Flow(x, y, qFlow);
}
}
Lock_Set(x, y, 0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -