void CSinuosity::ZeroToNoData(void){ for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ if (m_pSinuosity->asDouble(x,y) == 0){ m_pSinuosity->Set_Value(x,y,m_pSinuosity->Get_NoData_Value()); }//if }// for }// for }//method
//--------------------------------------------------------- CSG_Grid & CSG_Grid::_Operation_Arithmetic(double Value, TSG_Grid_Operation Operation) { //----------------------------------------------------- switch( Operation ) { case GRID_OPERATION_Addition: Get_History().Add_Child(SG_T("GRID_OPERATION"), Value)->Add_Property(SG_T("NAME"), LNG("Addition")); break; case GRID_OPERATION_Subtraction: Get_History().Add_Child(SG_T("GRID_OPERATION"), Value)->Add_Property(SG_T("NAME"), LNG("Subtraction")); Value = -Value; break; case GRID_OPERATION_Multiplication: Get_History().Add_Child(SG_T("GRID_OPERATION"), Value)->Add_Property(SG_T("NAME"), LNG("Multiplication")); break; case GRID_OPERATION_Division: if( Value == 0.0 ) return( *this ); Get_History().Add_Child(SG_T("GRID_OPERATION"), Value)->Add_Property(SG_T("NAME"), LNG("Division")); Value = 1.0 / Value; break; } //----------------------------------------------------- for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { for(int x=0; x<Get_NX(); x++) { if( !is_NoData(x, y) ) { switch( Operation ) { case GRID_OPERATION_Addition: case GRID_OPERATION_Subtraction: Add_Value(x, y, Value); break; case GRID_OPERATION_Multiplication: case GRID_OPERATION_Division: Mul_Value(x, y, Value); break; } } } } SG_UI_Process_Set_Ready(); return( *this ); }
//--------------------------------------------------------- double CGrid_Gaps::Tension_Step(int iStep) { int x, y; double d, dMax; dMax = 0.0; for(y=0; y<Get_NY(); y+=iStep) { for(x=0; x<Get_NX(); x+=iStep) { if( pTension_Keep->asByte(x, y) == false ) { d = Tension_Change(x, y, iStep); pTension_Temp->Set_Value(x, y, d); d = fabs(d - pResult->asDouble(x, y)); if( d > dMax ) { dMax = d; } } } } for(y=0; y<Get_NY(); y+=iStep) { for(x=0; x<Get_NX(); x+=iStep) { if( pTension_Keep->asByte(x, y) == false ) { pResult->Set_Value(x, y, pTension_Temp->asDouble(x, y)); } } } return( dMax ); }
//--------------------------------------------------------- bool CCost_Accumulated::Get_Allocation(void) { for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { Get_Allocation(x, y); } } return( true ); }
//--------------------------------------------------------- void CGrid_3D_Image::_Set_Grid(void) { T3DPoint *a, *b, *c, *d, p[3]; //----------------------------------------------------- a = (T3DPoint *)SG_Malloc(sizeof(T3DPoint) * Get_NX()); b = (T3DPoint *)SG_Malloc(sizeof(T3DPoint) * Get_NX()); c = (T3DPoint *)SG_Malloc(sizeof(T3DPoint) * (Get_NX() - 1)); //----------------------------------------------------- _Get_Line(0, b); for(int y=1; y<Get_NY() && Set_Progress(y); y++) { d = a; a = b; b = d; _Get_Line(y, b); _Get_Line(a, b, c); for(int ax=0, bx=1; bx<Get_NX(); ax++, bx++) { DRAW_TRIANGLE(a[ax], a[bx], c[ax]); DRAW_TRIANGLE(b[ax], b[bx], c[ax]); DRAW_TRIANGLE(a[ax], b[ax], c[ax]); DRAW_TRIANGLE(a[bx], b[bx], c[ax]); } } //----------------------------------------------------- SG_Free(a); SG_Free(b); SG_Free(c); //----------------------------------------------------- DataObject_Add(m_pRGB_Z); DataObject_Add(m_pRGB); DataObject_Set_Colors(m_pRGB, 100, SG_COLORS_BLACK_WHITE); }
//--------------------------------------------------------- bool CSlopeLength::On_Execute(void) { int x, y; //----------------------------------------------------- m_pDEM = Parameters("DEM" )->asGrid(); m_pLength = Parameters("LENGTH")->asGrid(); if( !m_pDEM->Set_Index() ) { Error_Set(_TL("index creation failed")); return( false ); } //----------------------------------------------------- m_Slope.Create(*Get_System()); for(y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for private(x) for(x=0; x<Get_NX(); x++) { double Slope, Aspect; if( m_pDEM->Get_Gradient(x, y, Slope, Aspect) ) { m_Slope .Set_Value(x, y, Slope); m_pLength->Set_Value(x, y, 0.0); } else { m_Slope .Set_NoData(x, y); m_pLength->Set_NoData(x, y); } } } //----------------------------------------------------- for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { if( m_pDEM->Get_Sorted(n, x, y) ) { Get_Length(x, y); } } //----------------------------------------------------- m_Slope.Destroy(); return( true ); }
//--------------------------------------------------------- bool CKinWav_D8::Initialize(double Roughness) { m_Flow_Last .Create(*Get_System(), SG_DATATYPE_Float); m_Alpha .Create(*Get_System(), SG_DATATYPE_Float); m_Direction .Create(*Get_System(), SG_DATATYPE_Char); m_Direction .Set_NoData_Value(-1); m_pFlow->Assign(0.0); DataObject_Set_Colors(m_pFlow, 100, SG_COLORS_WHITE_BLUE); DataObject_Update(m_pFlow, 0.0, 100.0, SG_UI_DATAOBJECT_SHOW); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( !m_pDEM->is_NoData(x, y) ) { int i, ix, iy, iMax; double z, d, dMax; for(i=0, iMax=-1, dMax=0.0, z=m_pDEM->asDouble(x, y); i<8; i++) { ix = Get_xTo(i, x); iy = Get_yTo(i, y); if( is_InGrid(ix, iy) && (d = (z - m_pDEM->asDouble(ix, iy)) / Get_Length(i)) > dMax ) { dMax = d; iMax = i; } } if( iMax < 0 ) { m_Direction .Set_NoData(x, y); } else { m_Direction .Set_Value(x, y, iMax); m_Alpha .Set_Value(x, y, pow(Roughness / sqrt(dMax), Beta_0)); if( m_Alpha.asDouble(x, y) > 10 ) m_Alpha.Set_Value(x, y, 10); } } } } return( true ); }
//--------------------------------------------------------- bool CFlow_Parallel::Calculate(void) { for(int y=0; y<Get_NY() && Set_Progress(y); y+=m_Step) { #pragma omp parallel for for(int x=0; x<Get_NX(); x+=m_Step) { Init_Cell(x, y); } } return( Set_Flow() ); }
//--------------------------------------------------------- bool CXYZ_Export::On_Execute(void) { bool bExNoData; int x, y, i; TSG_Point p; CSG_File Stream; CSG_String FileName; CSG_Parameter_Grid_List *pGrids; pGrids = Parameters("GRIDS") ->asGridList(); FileName = Parameters("FILENAME")->asString(); bExNoData = Parameters("EX_NODATA")->asBool(); if( pGrids->Get_Count() > 0 && Stream.Open(FileName, SG_FILE_W, false) ) { if( Parameters("CAPTION")->asBool() ) { Stream.Printf(SG_T("\"X\"\t\"Y\"")); for(i=0; i<pGrids->Get_Count(); i++) { Stream.Printf(SG_T("\t\"%s\""), pGrids->asGrid(i)->Get_Name()); } Stream.Printf(SG_T("\n")); } for(y=0, p.y=Get_YMin(); y<Get_NY() && Set_Progress(y); y++, p.y+=Get_Cellsize()) { for(x=0, p.x=Get_XMin(); x<Get_NX(); x++, p.x+=Get_Cellsize()) { if( !bExNoData || (bExNoData && !pGrids->asGrid(0)->is_NoData(x, y)) ) { Stream.Printf(SG_T("%f\t%f"), p.x, p.y); for(i=0; i<pGrids->Get_Count(); i++) { Stream.Printf(SG_T("\t%f"), pGrids->asGrid(i)->asDouble(x, y)); } Stream.Printf(SG_T("\n")); } } } return( true ); } return( false ); }
//--------------------------------------------------------- bool CLand_Surface_Temperature::On_Execute(void) { double Z_reference, T_reference, T_gradient, C_Factor, LAI_max, Z, SWR, LAI, LST; CSG_Grid *pDEM, *pSWR, *pLAI, *pLST; //----------------------------------------------------- pDEM = Parameters("DEM") ->asGrid(); pSWR = Parameters("SWR") ->asGrid(); pLAI = Parameters("LAI") ->asGrid(); pLST = Parameters("LST") ->asGrid(); Z_reference = Parameters("Z_REFERENCE") ->asDouble(); T_reference = Parameters("T_REFERENCE") ->asDouble(); T_gradient = Parameters("T_GRADIENT") ->asDouble(); C_Factor = Parameters("C_FACTOR") ->asDouble(); LAI_max = pLAI->Get_ZMax(); //----------------------------------------------------- if( LAI_max > 0.0 ) { for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( pDEM->is_NoData(x, y) || pSWR->is_NoData(x, y) || pLAI->is_NoData(x, y) || (SWR = pSWR->asDouble(x, y)) <= 0.0 ) { pLST->Set_NoData(x, y); } else { Z = pDEM->asDouble(x, y); SWR = pSWR->asDouble(x, y); LAI = pLAI->asDouble(x, y); LST = T_reference - (T_gradient * (Z - Z_reference)) / 1000.0 + C_Factor * (SWR - 1.0 / SWR) * (1.0 - LAI / LAI_max); pLST->Set_Value(x, y, LST); } } } return( true ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CPit_Eliminator::Fill_Sinks(void) { int x, y; for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Fill_Check(x, y); } } return( is_Progress() ); }
//--------------------------------------------------------- CvMat* COpenCV_NNet::GetEvalMatrix(CSG_Parameter_Grid_List *gl_grids, int type) { bool b_NoData; int x,y,i_Grid; CSG_Table *t_data; CSG_Table_Record *tr_rec; TSG_Point p; CvMat *mat; // We will use this table as a temporary data store, // since we cannot dynamically resize the CvMat t_data = new CSG_Table(); // We need a column for each grid and the output lable for (int i = 0; i < gl_grids->Get_Count(); i++) { t_data->Add_Field(CSG_String::Format(SG_T("GRID_%d"), i), SG_DATATYPE_Float, i); } // Traverse all grids, every point for(y=0, p.y=Get_YMin(); y<Get_NY() && Set_Progress(y); y++, p.y+=Get_Cellsize()) { for(x=0, p.x=Get_XMin(); x<Get_NX(); x++, p.x+=Get_Cellsize()) { for(i_Grid=0, b_NoData=false; i_Grid<gl_grids->Get_Count() && !b_NoData; i_Grid++) { // If there is one grid that has no data in this point p, then set the no data flag if( gl_grids->asGrid(i_Grid)->is_NoData(x, y) ) { b_NoData = true; } } if (!b_NoData) { // We have data in all grids, so lets add them to the eval data table tr_rec = t_data->Add_Record(); for(i_Grid=0; i_Grid<gl_grids->Get_Count(); i_Grid++) { tr_rec->Set_Value(i_Grid, (float) gl_grids->asGrid(i_Grid)->asFloat(x, y)); } } } } // Now create the matrix and add all data from the table to the matrix mat = GetEvalMatrix(t_data, type); return mat; }
//--------------------------------------------------------- bool CExercise_03::Method_02(void) { int x, y, ix; double a, b, c; //----------------------------------------------------- for(y=0; y<Get_NY() && Set_Progress(y); y++) { x = 0; // initialize x... while( x < Get_NX() - 1 ) // condition for x... { ix = x + 1; if( m_pInput->is_NoData(x, y) || m_pInput->is_NoData(ix, y) ) // don't work with 'no data'... { m_pOutput->Set_NoData(x, y); } else { a = m_pInput->asDouble( x, y); b = m_pInput->asDouble(ix, y); c = a - b; m_pOutput->Set_Value(x, y, c); } x++; // increment x... } m_pOutput->Set_NoData(Get_NX() - 1, y); // what shall we do with the last cell in a row ??!! } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CSADO_SolarRadiation::Set_Insolation(double Decline, double Azimuth) { int x, y; double a, e, Direct, Diffus; Get_Shade(Decline, Azimuth); e = Get_Vapour_Exponent (m_VP); a = Get_Vapour_A (m_VP); for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( m_pDEM->is_NoData(x, y) ) { if( m_pSumDirect ) m_pSumDirect->Set_NoData(x, y); if( m_pSumDiffus ) m_pSumDiffus->Set_NoData(x, y); if( m_pSumTotal ) m_pSumTotal ->Set_NoData(x, y); } else { if( m_pVP != NULL ) { e = Get_Vapour_Exponent (m_pVP->asDouble(x, y)); a = Get_Vapour_A (m_pVP->asDouble(x, y)); } if( m_bBending ) { Azimuth = m_Azimuth.asDouble(x, y); Decline = m_Decline.asDouble(x, y); } if( Decline > 0.0 ) { Direct = Get_Solar_Direct(x, y, Decline, Azimuth, e); Diffus = Get_Solar_Diffus(x, y, Decline, a , e); if( m_pSumDirect ) m_pSumDirect->Add_Value(x, y, Direct); if( m_pSumDiffus ) m_pSumDiffus->Add_Value(x, y, Diffus); if( m_pSumTotal ) m_pSumTotal ->Add_Value(x, y, Direct + Diffus); } } } } return( true ); }
//--------------------------------------------------------- bool CGrids_Sum::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS" )->asGridList(); if( pGrids->Get_Count() < 1 ) { Error_Set(_TL("no grid in list")); return( false ); } //----------------------------------------------------- CSG_Grid *pResult = Parameters("RESULT")->asGrid(); bool bNoData = Parameters("NODATA")->asBool(); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { int n = 0; double d = 0.0; for(int i=0; i<pGrids->Get_Count(); i++) { if( pGrids->asGrid(i)->is_InGrid(x, y) ) { n ++; d += pGrids->asGrid(i)->asDouble(x, y); } } if( bNoData ? n > 0 : n == pGrids->Get_Count() ) { pResult->Set_Value(x, y, d); } else { pResult->Set_NoData(x, y); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- void CSG_Grid::Flip(void) { int x, yA, yB; double *Line, d; if( is_Valid() ) { Line = (double *)SG_Malloc(Get_NX() * sizeof(double)); for(yA=0, yB=Get_NY()-1; yA<yB && SG_UI_Process_Set_Progress(2 * yA, Get_NY()); yA++, yB--) { for(x=0; x<Get_NX(); x++) { Line[x] = asDouble(x, yA); } for(x=0; x<Get_NX(); x++) { d = Line[x]; Line[x] = asDouble(x, yB); Set_Value(x, yB, d); } for(x=0; x<Get_NX(); x++) { Set_Value(x, yA, Line[x]); } } SG_UI_Process_Set_Ready(); SG_Free(Line); Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Vertically mirrored")); } }
//--------------------------------------------------------- void CGrid_Gaps::Tension_Main(void) { int iStep, iStart, n; double max, Threshold; Threshold = Parameters("THRESHOLD")->asDouble(); n = Get_NX() > Get_NY() ? Get_NX() : Get_NY(); iStep = 0; do { iStep++; } while( pow(2.0, iStep + 1) < n ); iStart = (int)pow(2.0, iStep); pTension_Keep = new CSG_Grid(pResult, SG_DATATYPE_Byte); pTension_Temp = new CSG_Grid(pResult); pResult->Assign_NoData(); for(iStep=iStart; iStep>=1; iStep/=2) { Tension_Init(iStep); do { max = Tension_Step(iStep); Process_Set_Text(CSG_String::Format(SG_T("[%d] %s: %f"), iStep, _TL("max. change"), max)); } while( max > Threshold && Process_Get_Okay(true) ); DataObject_Update(pResult, pInput->Get_ZMin(), pInput->Get_ZMax(), true); } delete(pTension_Keep); delete(pTension_Temp); }
void CIsochronesVar::ZeroToNoData(void){ for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ if (m_pTime->asDouble(x,y) == 0){ m_pTime->Set_Value(x,y,m_pTime->Get_NoData_Value()); }//if if (m_pSpeed->asDouble(x,y) == 0){ m_pSpeed->Set_Value(x,y,m_pSpeed->Get_NoData_Value()); }//if }// for }// for }//method
//--------------------------------------------------------- bool CGrid_Mask::On_Execute(void) { CSG_Grid *pGrid = Parameters("GRID")->asGrid(); CSG_Grid *pMask = Parameters("MASK")->asGrid(); if( !pGrid->is_Intersecting(pMask->Get_Extent()) ) { Message_Add(_TL("no intersection with mask grid.")); return( false ); } //----------------------------------------------------- CSG_Grid *pMasked = Parameters("MASKED")->asGrid(); if( pMasked && pMasked != pGrid ) { pMasked->Create(*pGrid); pMasked->Fmt_Name("%s [%s]", pGrid->Get_Name(), _TL("masked")); pGrid = pMasked; } //----------------------------------------------------- Process_Set_Text(_TL("masking...")); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { double py = Get_YMin() + y * Get_Cellsize(); #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { double px = Get_XMin() + x * Get_Cellsize(); if( !pMask->is_InGrid_byPos(px, py) ) { pGrid->Set_NoData(x, y); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CDiversity_Analysis::On_Execute(void) { //----------------------------------------------------- m_pClasses = Parameters("CATEGORIES" )->asGrid(); m_pCount = Parameters("COUNT" )->asGrid(); m_pDiversity = Parameters("DIVERSITY" )->asGrid(); m_pConnectivity = Parameters("CONNECTIVITY")->asGrid(); m_pConnectedAvg = Parameters("CONNECTEDAVG")->asGrid(); m_pCount ->Set_Name(CSG_String::Format("%s [%s]", m_pClasses->Get_Name(), _TL("Count" ))); m_pDiversity ->Set_Name(CSG_String::Format("%s [%s]", m_pClasses->Get_Name(), _TL("Diversity" ))); m_pConnectivity ->Set_Name(CSG_String::Format("%s [%s]", m_pClasses->Get_Name(), _TL("Connectivity" ))); m_pConnectedAvg ->Set_Name(CSG_String::Format("%s [%s]", m_pClasses->Get_Name(), _TL("Averaged Connectivity"))); DataObject_Set_Colors(m_pCount , 11, SG_COLORS_RAINBOW, false); DataObject_Set_Colors(m_pDiversity , 11, SG_COLORS_RAINBOW, false); DataObject_Set_Colors(m_pConnectivity, 11, SG_COLORS_RAINBOW, true); DataObject_Set_Colors(m_pConnectedAvg, 11, SG_COLORS_RAINBOW, true); //----------------------------------------------------- m_Search.Get_Weighting().Set_Parameters(&Parameters); m_Search.Get_Weighting().Set_BandWidth(Parameters("SEARCH_RADIUS")->asDouble() * m_Search.Get_Weighting().Get_BandWidth()); m_Search.Set_Radius(m_Radius = Parameters("SEARCH_RADIUS")->asInt(), Parameters("SEARCH_MODE")->asInt() == 0); m_NB_Step = Parameters("NB_CASE" )->asInt() == 0 ? 2 : 1; m_Normalize = Parameters("NORMALIZE")->asInt(); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( !Get_Diversity(x, y) ) { m_pCount ->Set_NoData(x, y); m_pDiversity ->Set_NoData(x, y); m_pConnectivity->Set_NoData(x, y); m_pConnectedAvg->Set_NoData(x, y); } } } //----------------------------------------------------- m_Search.Destroy(); return( true ); }
//--------------------------------------------------------- bool CGSGrid_Residuals::On_Execute(void) { m_pGrid = Parameters("GRID") ->asGrid(); m_pMean = Parameters("MEAN") ->asGrid(); m_pDiff = Parameters("DIFF") ->asGrid(); m_pStdDev = Parameters("STDDEV") ->asGrid(); m_pRange = Parameters("RANGE") ->asGrid(); m_pMin = Parameters("MIN") ->asGrid(); m_pMax = Parameters("MAX") ->asGrid(); m_pDevMean = Parameters("DEVMEAN") ->asGrid(); m_pPercent = Parameters("PERCENT") ->asGrid(); DataObject_Set_Colors(m_pDiff , 100, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(m_pStdDev , 100, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(m_pRange , 100, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(m_pMin , 100, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(m_pMax , 100, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(m_pDevMean, 100, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(m_pPercent, 100, SG_COLORS_RED_GREY_BLUE, true); //----------------------------------------------------- bool bSquare = Parameters("MODE")->asBool() ? false : true; m_Cells.Get_Weighting().Set_Parameters(Parameters("WEIGHTING")->asParameters()); if( !m_Cells.Set_Radius(Parameters("RADIUS")->asInt(), bSquare) ) { return( false ); } bool bCenter = Parameters("BCENTER")->asBool(); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { Get_Statistics(x, y, bCenter); } } //----------------------------------------------------- m_Cells.Destroy(); return( true ); }
//--------------------------------------------------------- void CConvergence::Do_Gradient(void) { int x, y, i, ix, iy, n; double z, Slope, Aspect, iSlope, iAspect, d, dSum; for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( pDTM->is_InGrid(x, y) ) { z = pDTM->asDouble(x, y); for(i=0, n=0, dSum=0.0, iAspect=-M_PI_180; i<8; i++, iAspect+=M_PI_045) { ix = Get_xTo(i, x); iy = Get_yTo(i, y); if( pDTM->is_InGrid(ix, iy) && pDTM->Get_Gradient(ix, iy, Slope, Aspect) && Aspect >= 0.0 ) { iSlope = atan((pDTM->asDouble(ix, iy) - z) / Get_Length(i)); // Nach dem Seiten-Kosinus-Satz... d = acos(sin(Slope) * sin(iSlope) + cos(Slope) * cos(iSlope) * cos(iAspect - Aspect)); //--------------------------------- d = fmod(d, M_PI_360); if( d < -M_PI_180 ) { d += M_PI_360; } else if( d > M_PI_180 ) { d -= M_PI_360; } //--------------------------------- dSum += fabs(d); n++; } } pConvergence->Set_Value(x, y, n > 0 ? (dSum / (double)n - M_PI_090) * 100.0 / M_PI_090 : 0.0); } } } }
void CSinuosity::calculateSinuosity(void){ double dDist; for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ if (m_pSinuosity->asDouble(x,y) != m_pSinuosity->Get_NoData_Value()){ dDist = sqrt(pow((double)x-m_iX,2)+pow((double)y-m_iY,2))*m_pSinuosity->Get_Cellsize(); if (dDist!=0){ m_pSinuosity->Set_Value(x,y,m_pSinuosity->asDouble(x,y)/dDist); }//if }//if }// for }// for }//method
bool CEdgeContamination::On_Execute(void){ m_pEdgeContamination = Parameters("CONTAMINATION")->asGrid();; m_pDEM = Parameters("DEM")->asGrid(); m_pEdgeContamination->Assign(NOT_VISITED); for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ m_pEdgeContamination->Set_Value(x,y,getEdgeContamination(x,y)); }// for }// for return( true ); }//method
//--------------------------------------------------------- void CGrid_3D_Image::_Get_Line(T3DPoint *a, T3DPoint *b, T3DPoint *c) { for(int ax=0, bx=1; bx<Get_NX(); ax++, bx++) { if( (c[ax].bOk = a[ax].bOk && a[bx].bOk && b[ax].bOk && b[bx].bOk) == true ) { c[ax].x = (int)(0.5 + (a[ax].x + a[bx].x + b[ax].x + b[bx].x) / 4.0); c[ax].y = (int)(0.5 + (a[ax].y + a[bx].y + b[ax].y + b[bx].y) / 4.0); c[ax].z = (a[ax].z + a[bx].z + b[ax].z + b[bx].z) / 4.0; c[ax].r = (a[ax].r + a[bx].r + b[ax].r + b[bx].r) / 4; c[ax].g = (a[ax].g + a[bx].g + b[ax].g + b[bx].g) / 4; c[ax].b = (a[ax].b + a[bx].b + b[ax].b + b[bx].b) / 4; } } }
//--------------------------------------------------------- inline void CGrid_3D_Image::_Get_Position(double x, double y, double z, T3DPoint &p) { bool bResult; //----------------------------------------------------- if( m_ZRotate != 0.0 ) { _Get_Rotated(0.5 * Get_NX(), x, 0.5 * Get_NY(), y, m_ZRotate); } x = m_XScale * x; y = m_YScale * y; z = m_ZExagg * ((z - m_ZMean) / Get_Cellsize()); //----------------------------------------------------- switch( m_Projection ) { case 0: default: bResult = _Get_Panorama (y, z); break; case 1: bResult = _Get_Circle (y, z); break; case 2: bResult = _Get_Sinus (y, z); break; case 3: bResult = _Get_Hyperbel (y, z); break; } //----------------------------------------------------- if( bResult ) { p.bOk = true; p.x = (int)x; p.y = (int)y; p.z = z; } else { p.bOk = false; } }
//--------------------------------------------------------- bool CTopographic_Correction::On_Execute(void) { //----------------------------------------------------- if( !Get_Illumination() ) { m_Slope .Destroy(); m_Illumination .Destroy(); return( false ); } if( !Get_Model() ) { m_Slope .Destroy(); m_Illumination .Destroy(); return( false ); } //----------------------------------------------------- Process_Set_Text(_TL("Topographic Correction")); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( m_pOriginal->is_NoData(x, y) ) { m_pCorrected->Set_NoData(x, y); } else { m_pCorrected->Set_Value(x, y, Get_Correction( m_Slope .asDouble(x, y), m_Illumination.asDouble(x, y), m_pOriginal ->asDouble(x, y) )); } } } //----------------------------------------------------- m_Slope .Destroy(); m_Illumination .Destroy(); return( true ); }
//--------------------------------------------------------- bool CTopographic_Correction::Get_Illumination(void) { Process_Set_Text(_TL("Illumination calculation")); //----------------------------------------------------- CSG_Grid DEM, *pDEM = Parameters("DEM")->asGrid(); if( !pDEM->Get_System().is_Equal(*Get_System()) ) { DEM.Create(*Get_System()); DEM.Assign(pDEM, pDEM->Get_Cellsize() > Get_Cellsize() ? GRID_INTERPOLATION_BSpline : GRID_INTERPOLATION_Mean_Cells); pDEM = &DEM; } //----------------------------------------------------- double Azi = Parameters("AZI")->asDouble() * M_DEG_TO_RAD; double Hgt = Parameters("HGT")->asDouble() * M_DEG_TO_RAD; m_cosTz = cos(M_PI_090 - Hgt); m_sinTz = sin(M_PI_090 - Hgt); m_Slope .Create(*Get_System()); m_Illumination .Create(*Get_System()); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { double Slope, Aspect; if( pDEM->Get_Gradient(x, y, Slope, Aspect) ) { m_Slope .Set_Value(x, y, Slope); m_Illumination .Set_Value(x, y, cos(Slope) * m_cosTz + sin(Slope) * m_sinTz * cos(Azi - Aspect)); } else { m_Slope .Set_Value(x, y, 0.0); m_Illumination .Set_Value(x, y, m_cosTz); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Completion::On_Execute(void) { int x, y; double xPos, yPos, Value; TSG_Grid_Interpolation Interpolation; CSG_Grid *pGrid, *pAdditional; pAdditional = Parameters("ADDITIONAL") ->asGrid(); pGrid = Parameters("COMPLETED") ->asGrid(); if( pGrid->is_Intersecting(pAdditional->Get_Extent()) ) { if( pGrid != Parameters("ORIGINAL")->asGrid() ) { Process_Set_Text(_TL("Copying original data...")); pGrid->Assign(Parameters("ORIGINAL")->asGrid()); } Interpolation = (TSG_Grid_Interpolation)Parameters("INTERPOLATION")->asInt(); Process_Set_Text(_TL("Data completion...")); for(y=0, yPos=Get_YMin(); y<Get_NY() && Set_Progress(y, Get_NY()); y++, yPos+=Get_Cellsize()) { if( yPos >= pAdditional->Get_YMin() ) { for(x=0, xPos=Get_XMin(); x<Get_NX() && xPos<=pAdditional->Get_XMax(); x++, xPos+=Get_Cellsize()) { if( pGrid->is_NoData(x, y) && xPos >= pAdditional->Get_XMin() ) { if( !pAdditional->is_NoData_Value(Value = pAdditional->Get_Value(xPos, yPos, Interpolation)) ) { pGrid->Set_Value(x, y, Value); } } } } } return( true ); } Error_Set(_TL("Nothing to do: there is no intersection with additonal grid.")); return( false ); }
bool CImage_VI_Slope::On_Execute(void){ double dRed, dNIR; CSG_Grid* pNIR = Parameters("NIR")->asGrid(); CSG_Grid* pRed = Parameters("RED")->asGrid(); CSG_Grid* pNDVI = Parameters("NDVI")->asGrid(); CSG_Grid* pRatio = Parameters("RATIO")->asGrid(); CSG_Grid* pTVI = Parameters("TVI")->asGrid(); CSG_Grid* pTTVI = Parameters("TTVI")->asGrid(); CSG_Grid* pCTVI = Parameters("CTVI")->asGrid(); CSG_Grid* pNRatio = Parameters("NRATIO")->asGrid(); for(int y=0; y<Get_NY() && Set_Progress(y); y++){ for(int x=0; x<Get_NX(); x++){ dNIR = pNIR->asDouble(x,y); dRed = pRed->asDouble(x,y); pNDVI->Set_Value(x,y,getNDVI(dRed, dNIR)); if (pRatio){ if (dRed!=0){ pRatio->Set_Value(x,y,getRatio(dRed,dNIR)); }//if else{ pRatio->Set_Value(x,y,pRatio->Get_NoData_Value()); }//else }//if if (pTVI){ pTVI->Set_Value(x,y,getTVI(dRed,dNIR,pTVI)); }//if if (pCTVI){ pCTVI->Set_Value(x,y,getCTVI(dRed,dNIR)); }//if if (pTTVI){ pTTVI->Set_Value(x,y,getTTVI(dRed,dNIR)); }//if if (pNRatio){ pNRatio->Set_Value(x,y,getNRatio(dRed,dNIR)); }//if }// for }// for return true; }//method