//--------------------------------------------------------- bool CFilter_Resample::On_Execute(void) { double Cellsize; CSG_Grid *pGrid, *pLoPass, *pHiPass; //----------------------------------------------------- pGrid = Parameters("GRID" )->asGrid(); pLoPass = Parameters("LOPASS")->asGrid(); pHiPass = Parameters("HIPASS")->asGrid(); Cellsize = Parameters("SCALE" )->asDouble() * Get_Cellsize(); //----------------------------------------------------- if( Cellsize > 0.5 * SG_Get_Length(Get_System()->Get_XRange(), Get_System()->Get_YRange()) ) { Error_Set(_TL("resampling cell size is too large")); return( false ); } //----------------------------------------------------- CSG_Grid Grid(CSG_Grid_System(Cellsize, Get_XMin(), Get_YMin(), Get_XMax(), Get_YMax()), SG_DATATYPE_Float); Grid.Assign(pGrid, GRID_RESAMPLING_Mean_Cells); //----------------------------------------------------- pLoPass->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("Low Pass"))); pHiPass->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("High Pass"))); CSG_Colors Colors; DataObject_Get_Colors(pGrid , Colors); DataObject_Set_Colors(pLoPass, Colors); DataObject_Set_Colors(pHiPass, 11, SG_COLORS_RED_GREY_BLUE); //----------------------------------------------------- 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++) { double z, px = Get_XMin() + x * Get_Cellsize(); if( !pGrid->is_NoData(x, y) && Grid.Get_Value(px, py, z) ) { pLoPass->Set_Value(x, y, z); pHiPass->Set_Value(x, y, pGrid->asDouble(x, y) - z); } else { pLoPass->Set_NoData(x, y); pHiPass->Set_NoData(x, y); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- TSG_Intersection CSG_Rect::Intersects(const CSG_Rect &Rect) const { if( m_rect.xMax < Rect.Get_XMin() || Rect.Get_XMax() < m_rect.xMin || m_rect.yMax < Rect.Get_YMin() || Rect.Get_YMax() < m_rect.yMin ) { return( INTERSECTION_None ); } if( is_Equal(Rect) ) { return( INTERSECTION_Identical ); } if( Contains(Rect.Get_XMin(), Rect.Get_YMin()) && Contains(Rect.Get_XMax(), Rect.Get_YMax()) ) { return( INTERSECTION_Contains ); } if( Rect.Contains(Get_XMin(), Get_YMin()) && Rect.Contains(Get_XMax(), Get_YMax()) ) { return( INTERSECTION_Contained ); } return( INTERSECTION_Overlaps ); }
//--------------------------------------------------------- bool CTC_Parameter_Base::Get_Parameter(CSG_Grid *pValues, CSG_Grid *pParameter) { DataObject_Set_Colors(pParameter, 10, SG_COLORS_RED_GREY_BLUE, true); //----------------------------------------------------- if( Parameters("METHOD")->asInt() == 0 ) { m_Kernel.Get_Weighting().Set_Parameters(&Parameters); m_Kernel.Get_Weighting().Set_BandWidth(Parameters("SCALE")->asDouble() * m_Kernel.Get_Weighting().Get_BandWidth()); m_Kernel.Set_Radius(Parameters("SCALE")->asDouble()); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pValues->is_NoData(x, y) ) { pParameter->Set_NoData(x, y); } else { double d, w, nTotal = 0.0, nValid = 0.0; for(int i=0, ix, iy; i<m_Kernel.Get_Count(); i++) { if( m_Kernel.Get_Values(i, ix = x, iy = y, d, w, true) && pValues->is_InGrid(ix, iy) ) { nTotal += w; if( pValues->asInt(ix, iy) != 0 ) { nValid += w; } } } pParameter->Set_Value(x, y, nTotal > 0.0 ? 100.0 * nValid / nTotal : 0.0); // make percentage } } } m_Kernel.Destroy(); } //----------------------------------------------------- else { double Cellsize = Parameters("SCALE")->asInt() * Get_Cellsize(); if( Cellsize > 0.5 * SG_Get_Length(Get_System()->Get_XRange(), Get_System()->Get_YRange()) ) { Error_Set(_TL("resampling cell size is too large")); return( false ); } CSG_Grid Values(CSG_Grid_System(Cellsize, Get_XMin(), Get_YMin(), Get_XMax(), Get_YMax()), SG_DATATYPE_Float); Values.Assign(pValues, GRID_RESAMPLING_Mean_Cells); 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++) { double z, px = Get_XMin() + x * Get_Cellsize(); if( pValues->is_NoData(x, y) || !Values.Get_Value(px, py, z, GRID_RESAMPLING_BSpline) ) { pParameter->Set_NoData(x, y); } else { pParameter->Set_Value(x, y, 100.0 * z); // make percentage } } } } //----------------------------------------------------- return( true ); }