int CEdgeContamination::getEdgeContamination(int x, int y){ int iNextX, iNextY; int iEdgeContamination; if (x <= 1 || y <= 1 || x >= Get_NX() - 2 || y >= Get_NY() - 2){ iEdgeContamination = 1; }//if else{ iEdgeContamination = 0; }//else for (int i = -1; i<2; i++){ for (int j = -1; j<2; j++){ if (!(i == 0) || !(j == 0)) { getNextCell(m_pDEM, x + i, y + j, iNextX, iNextY); if (iNextY == y && iNextX == x) { if (m_pEdgeContamination->asInt(x+i,y+j)!=NOT_VISITED){ iEdgeContamination += m_pEdgeContamination->asInt(x+i,y+j); }//if else{ iEdgeContamination += getEdgeContamination(x+i,y+j); }//else }// if }//if }//for }//for m_pEdgeContamination->Set_Value(x, y, iEdgeContamination); return iEdgeContamination; }//method
void CSinuosity::writeDistOut( int iX1, int iY1, int iX2, int iY2) { int iNextX, iNextY; double dDist = 1; if (iX1 < 0 || iX1 >= m_pDEM->Get_NX() || iY1 < 0 || iY1 >= m_pDEM->Get_NY() || m_pDEM->asFloat(iX1,iY1) == m_pDEM->Get_NoData_Value()) { }// if else { dDist = sqrt(pow((double)iX1-iX2,2)+pow((double)iY1-iY2,2))*m_pSinuosity->Get_Cellsize(); m_pSinuosity->Set_Value(iX1,iY1,m_pSinuosity->asDouble(iX2,iY2) + dDist); for (int i = -1; i<2; i++){ for (int j = -1; j<2; j++){ if (!(i == 0) || !(j == 0)) { getNextCell(m_pDEM, iX1 + i, iY1 + j, iNextX, iNextY); if (iNextY == iY1 && iNextX == iX1) { writeDistOut(iX1 + i, iY1 + j, iX1, iY1); }// if }//if }//for }//for }// else }// method
// Solves function for the sudoku class. // Basic algorithm is implemented here. Doesn't need to be overloaded. bool Sudoku::solve() { // If there is no empty cells, a solution is found. // (Note that there can be more than one solutions.) // Also get the next cell to explore and increase the depth by 1. short r, c; vector<unsigned char> values; if (!getNextCell(r, c, values)) // r, c & values are returned here. return true; // No more empty cell. depth++; // For all possible values for the given cell. for (short i = 0; i < values.size(); i++) { // If there is no conflict with the given value. if (!board.ifAnyConflict(r, c, values[i])) { // Set the cell's value temporarily. board.set(r, c, values[i]); // Keep going to the next cell recursively // until the given value doesn't work out. if (solve()) return true; // Comes here if the value didn't work, // so reset the cell as empty and try another value. board.makeEmpty(r, c); depth--; // decrease the depth by 1. }; }; // If there is no possible value, or all possible values didn't // work out, triggers the backtracking. return false; };
spAspCell_t AspCellList::getCell(int id) { AspCellMap::iterator ci; spAspCell_t cell; int i; for (cell= getFirstCell(ci), i=0; cell != nullAspCell; cell= getNextCell(ci), i++) { if(i == id) return cell; } return nullAspCell; }
//--------------------------------------------------------- void CLeastCostPathProfile_Points::Set_Profile(int iX, int iY, CSG_Shapes *pPoints, CSG_Shapes *pLine) { int iNextX, iNextY; iNextX = iX; iNextY = iY; do { iX = iNextX; iY = iNextY; getNextCell(m_pDEM, iX, iY, iNextX, iNextY); } while( Add_Point(iX, iY, pPoints, pLine) && (iX != iNextX || iY != iNextY) ); }
double FlowDistance(CSG_Grid *pDEM, CSG_Grid *pBasinGrid, int iBasin, int iX, int iY, int iX2, int iY2){// result in m, coords in grid coords. Returns 0 if no distance is calculated. bool bIsInBasin; double dDist = 1; int iNextX = iX; int iNextY = iY; if (iX2 <= 0 || iX2 >= pDEM->Get_NX() || iY2 <= 0 || iY2 >= pDEM->Get_NY() || iX <= 0 || iX >= pDEM->Get_NX() || iY <= 0 || iY >= pDEM->Get_NY() ) { return 0; }// if do { iX = iNextX; iY = iNextY; getNextCell(pDEM,iX,iY,iNextX,iNextY); if (fabs((double)(iX - iNextX + iY - iNextY)) == 1.0) { dDist = dDist + pDEM->Get_Cellsize(); }// if else { dDist = dDist + 1.414 * pDEM->Get_Cellsize(); }// else if (iX == iX2 && iY == iY2) { return dDist; }// if if (iBasin == GLOBAL_BASIN){ bIsInBasin = !pBasinGrid->is_NoData(iX,iY); }//if else{ bIsInBasin = (pBasinGrid->asInt(iX,iY) == iBasin); }//else }while (bIsInBasin &&(iX!=iNextX || iY!=iNextY)); return 0; }// method
bool CFlowDepth::isHeader(int iX, int iY){ int iNextX, iNextY; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (m_pCatchArea->is_InGrid(iX+i,iY+j)){ if (m_pCatchArea->asFloat(iX+i,iY+j) > m_dThreshold && (i!=0 || j!=0)){ getNextCell(m_pDEM, iX + i, iY + j, iNextX, iNextY); if (iNextX == iX && iNextY == iY) { return false; }//if }// if }//if }// for }// for return true; }// method
void CIsochronesVar::writeTimeOut( int iX1, int iY1, int iX2, int iY2) { double dDist = 1; double dD = 0; double dSlope; double dSpeed; double dQ = 0; double dH; double dSup; double dInf; double dAcc; double dArea = 0; double dPerim; double dDif; double dManning; double dCN; double dI = 0; int iIter; int iNextX, iNextY; if (iX1 < 0 || iX1 >= m_pDEM->Get_NX() || iY1 < 0 || iY1 >= m_pDEM->Get_NY() || m_pDEM->asFloat(iX1,iY1) == m_pDEM->Get_NoData_Value()) { }// if else { if (m_pCN!=NULL){ dCN = m_pCN->asDouble(iX1, iY1); if (dCN == m_pCN->Get_NoData_Value()) { dCN = m_dCN; }// if }//if else{ dCN = m_dCN; }//else dI = Runoff(m_dRainfall, dCN); dI /= 3600.0;// in mm/s dI /= 1000.0;// m/s of runoff; if (abs(iX1 - iX2 + iY1 - iY2) == 1) { dDist = m_pDEM->Get_Cellsize(); }// if else { dDist = 1.44 * m_pDEM->Get_Cellsize(); }// else dSlope = m_pSlope->asDouble(iX1,iY1); dSlope = fabs(tan(dSlope)); dSlope = max(0.001, dSlope); dAcc = m_pCatchArea->asDouble(iX1,iY1); if (dAcc < m_dMixedThresh) { dD = sqrt(2.0 * dAcc / 3.14159); if (m_pManning!=NULL){ dManning = m_pManning->asDouble(iX1, iY1); if (dManning == m_pManning->Get_NoData_Value()) { dManning = m_dManning; }// if }//id else{ dManning = m_dManning; }//else dSpeed = max(m_dMinSpeed, pow(dI * dD, 0.4) * pow(dSlope, 0.3) / pow(dManning, 0.6)); }// if else{ if (dAcc < m_dChannelThresh) { dManning = 0.06; }//if else{ dManning= 0.05; }//if dQ = dI * dAcc; // Q m3/s dSup = 60; dInf = 0; dH = 2; dArea = dH * dH / m_dChannelSlope; dPerim = 2.0 * (dH / m_dChannelSlope + sqrt(dH * dH + pow(dH / m_dChannelSlope, 2.0))); dDif = (sqrt(dSlope) * pow(dArea, 5.0 / 3.0) / pow(dPerim, 2.0 / 3.0) / dManning) - dQ; iIter = 0; do { if (dDif > 0) { dSup = dH; dH = (dInf + dH) / 2.0; }// if else if (dDif < 0) { dInf = dH; dH = (dSup + dH) / 2.0; }// else if dArea = dH * dH / m_dChannelSlope; dPerim = 2.0 * (dH / m_dChannelSlope + sqrt(dH * dH + pow(dH / m_dChannelSlope, 2.0))); dDif = (sqrt(dSlope) * pow(dArea, 5.0 / 3.0) / pow(dPerim, 2.0 / 3.0) / dManning) - dQ; iIter++; }while (fabs(dDif) > 0.1); dSpeed = max(m_dMinSpeed, dQ / dArea); }// else m_pTime->Set_Value(iX1,iY1,m_pTime->asDouble(iX2,iY2) + dDist / dSpeed); m_pSpeed->Set_Value(iX1,iY1, dSpeed); for (int i = -1; i<2; i++){ for (int j = -1; j<2; j++){ if (!(i == 0) || !(j == 0)) { getNextCell(m_pDEM, iX1 + i, iY1 + j, iNextX, iNextY); if (iNextY == iY1 && iNextX == iX1) { writeTimeOut(iX1 + i, iY1 + j, iX1, iY1); }// if }//if }//for }//for }// else }// method
bool CFlowDepth::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode){ int iX, iY; int iNextX, iNextY; int x,y; int iOutletX, iOutletY; double fArea; double fDepth, fPreviousDepth = 0; if( Mode != MODULE_INTERACTIVE_LDOWN || !Get_Grid_Pos(iOutletX, iOutletY) ) { return( false ); } m_pFlowDepth->Assign((double)0); fArea = m_pCatchArea->asFloat(iOutletX, iOutletY); if (fArea < m_dThreshold * 2.){ //check outlet point iNextX = iOutletX; iNextY = iOutletY; do{ iOutletX = iNextX; iOutletY = iNextY; getNextCell(m_pDEM, iOutletX, iOutletY, iNextX, iNextY); }while (m_pCatchArea->asFloat(iOutletX, iOutletY) < m_dThreshold * 2. && (iOutletX != iNextX || iOutletY != iNextY)); if (m_pCatchArea->asFloat(iOutletX, iOutletY) < m_dThreshold * 2.){ Message_Add(_TL("** Error : Wrong outlet point selected **")); return false; }//if Message_Add(_TL("** Warning : Outlet point was modified **")); }//if CalculateBasinGrid(m_pBasinGrid, m_pDEM, iOutletX, iOutletY); m_fMaxFlowAcc = m_pCatchArea->asFloat(iOutletX, iOutletY); for(y=0; y<Get_NY() && Set_Progress(y); y++){ for(x=0; x<Get_NX(); x++){ if (m_pCatchArea->asFloat(x,y) > m_dThreshold){ if (isHeader(x,y)){ iNextX = x; iNextY = y; do { iX = iNextX; iY = iNextY; if (m_pFlowDepth->asFloat(iX,iY) == 0. && m_pBasinGrid->asInt(iX, iY) != 0){ getNextCell(m_pDEM, iX, iY, iNextX, iNextY); fDepth = CalculateFlowDepth(iX,iY); if (fDepth == NO_DEPTH){ m_pFlowDepth->Set_Value(iX,iY, fPreviousDepth); }//if else{ fPreviousDepth = fDepth; }//else }//if }while ((iX != iOutletX || iY != iOutletY) && (iX != iNextX || iY != iNextY)); }//if }//if }//for }// for DataObject_Update(m_pFlowDepth); return true; }//method