Exemple #1
0
//---------------------------------------------------------
bool CSG_Grid::_Assign_Interpolated(CSG_Grid *pGrid, TSG_Grid_Interpolation Interpolation)
{
	int		x, y;
	double	xPosition, yPosition, z;

	Set_NoData_Value_Range(pGrid->Get_NoData_Value(), pGrid->Get_NoData_hiValue());

	for(y=0, yPosition=Get_YMin(); y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++, yPosition+=Get_Cellsize())
	{
		for(x=0, xPosition=Get_XMin(); x<Get_NX(); x++, xPosition+=Get_Cellsize())
		{
			if( pGrid->Get_Value(xPosition, yPosition, z, Interpolation) )
			{
				Set_Value (x, y, z);
			}
			else
			{
				Set_NoData(x, y);
			}
		}
	}

	Get_History()	= pGrid->Get_History();
	Get_History().Add_Child(SG_T("GRID_OPERATION"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()))->Add_Property(SG_T("NAME"), LNG("Resampling"));

	SG_UI_Process_Set_Ready();

	return( true );
}
Exemple #2
0
//---------------------------------------------------------
bool CWatershed_Segmentation::Get_Borders(void)
{
    Process_Set_Text(_TL("Borders"));

    CSG_Grid	*pBorders	= SG_Create_Grid(SG_DATATYPE_Byte, Get_NX() + 2, Get_NY() + 2, Get_Cellsize(), Get_XMin() - 0.5 * Get_Cellsize(), Get_YMin() - 0.5 * Get_Cellsize());

    pBorders->Set_NoData_Value(0);

    Parameters("BORDERS")->Set_Value(pBorders);

    for(int y=0, yy=1; yy<Get_NY() && Set_Progress(yy); y++, yy++)
    {
        for(int x=0, xx=1; xx<Get_NX(); x++, xx++)
        {
            int		id	= m_pSegments->asInt(x, y);

            if( id != m_pSegments->asInt(xx,  y) )
            {
                pBorders->Set_Value(xx,  y, 1);
            }

            if( id != m_pSegments->asInt( x, yy) )
            {
                pBorders->Set_Value( x, yy, 1);
            }

            if( id != m_pSegments->asInt(xx, yy) )
            {
                pBorders->Set_Value(xx, yy, 1);
            }
        }
    }

    return( true );
}
//---------------------------------------------------------
bool CViGrA_Watershed::On_Execute(void)
{
	CSG_Grid	*pInput  = Parameters("INPUT" )->asGrid();
	CSG_Grid	*pOutput = Parameters("OUTPUT")->asGrid();

	//-----------------------------------------------------
	if( !Parameters("RGB")->asBool() )
	{
		vigra::FImage	Input, Output(Get_NX(), Get_NY());

		Copy_Grid_SAGA_to_VIGRA(*pInput, Input, true);

		Segmentation(Input, Output, Parameters("SCALE")->asDouble(), Parameters("EDGES")->asBool());

		Copy_Grid_VIGRA_to_SAGA(*pOutput, Output, false);
	}

	//-----------------------------------------------------
	else	// perform watershed segmentation on color image
	{
		vigra::BRGBImage	Input, Output(Get_NX(), Get_NY());

		Copy_RGBGrid_SAGA_to_VIGRA(*pInput, Input, true);

		Segmentation(Input, Output, Parameters("SCALE")->asDouble(), Parameters("EDGES")->asBool());

		Copy_RGBGrid_VIGRA_to_SAGA(*pOutput, Output, false);
	}

	//-----------------------------------------------------
	pOutput->Fmt_Name("%s [%s]", pInput->Get_Name(), Get_Name().c_str());

	return( true );
}
//---------------------------------------------------------
double CGSGrid_Variance::Get_GSGrid_Variance(int x, int y, int iRadius, int &Count)
{
	int		i, ix, iy;

	double	d, z, Variance;

	Variance	= 0;
	z			= pInput->asDouble(x,y);

	for(i=rLength[iRadius-1], Count=0; i<rLength[iRadius]; i++, Count++)
	{
		ix	= x + x_diff[i];
		if( ix < 0 )
			ix	= 0;
		else if( ix >= Get_NX() )
			ix	= Get_NX() - 1;

		iy	= y + y_diff[i];
		if( iy < 0 )
			iy	= 0;
		else if( iy >= Get_NY() )
			iy	= Get_NY() - 1;

		d			= z - pInput->asDouble(ix,iy);
		Variance	+= d * d;
	}

	return( Variance );
}
Exemple #5
0
//---------------------------------------------------------
void CSG_Grid::Invert(void)
{
	int		x, y;
	double	zMin, zMax;

	if( is_Valid() && Get_ZRange() > 0.0 )
	{
		zMin	= Get_ZMin();
		zMax	= Get_ZMax();

		for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
		{
			for(x=0; x<Get_NX(); x++)
			{
				if( !is_NoData(x, y) )
				{
					Set_Value(x, y, zMax - (asDouble(x, y) - zMin));
				}
			}
		}

		SG_UI_Process_Set_Ready();

		Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Inversion"));
	}
}
Exemple #6
0
//---------------------------------------------------------
bool CExercise_09::On_Execute(void)
{
	int			x, y;
	CSG_Grid	*pDTM;

	//-----------------------------------------------------
	// Get parameter settings...

	pDTM		= Parameters("ELEVATION")->asGrid();
	m_pArea		= Parameters("AREA"     )->asGrid();


	//-----------------------------------------------------
	// Initialisations...

	m_pArea		->Assign(0.0);
	m_pArea		->Set_Unit(SG_T("m\xc2\xb2"));
	DataObject_Set_Colors(m_pArea, 100, SG_COLORS_WHITE_BLUE);


	//-----------------------------------------------------
	// Save flow directions to temporary grid...

	m_pDir		= new CSG_Grid(pDTM, SG_DATATYPE_Char);	// this object has to be deleted later...

	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			m_pDir->Set_Value(x, y, pDTM->Get_Gradient_NeighborDir(x, y) % 8);
		}
	}


	//-------------------------------------------------
	// Execute calculation...

	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			Get_Area(x, y);
		}
	}


	//-----------------------------------------------------
	// Finalisations...

	delete(m_pDir);


	//-----------------------------------------------------
	// Return 'true' if everything went okay...

	return( true );
}
Exemple #7
0
//---------------------------------------------------------
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 );
}
//---------------------------------------------------------
bool CGrid_Histogram_Surface::Get_Lines(bool bRows)
{
	int			i, j, n_i, n_j;
	CSG_Table	Values;
	CSG_Grid	*pHist;

	//-----------------------------------------------------
	Parameters("HIST")->Set_Value(pHist	= SG_Create_Grid(m_pGrid));

	pHist->Set_NoData_Value_Range(
		m_pGrid->Get_NoData_Value(),
		m_pGrid->Get_NoData_hiValue()
	);

	n_i	= bRows ? Get_NX() : Get_NY();
	n_j	= bRows ? Get_NY() : Get_NX();

	Values.Add_Field(SG_T("Z"), SG_DATATYPE_Double);

	for(i=0; i<n_i; i++)
	{
		Values.Add_Record();
	}

	//-----------------------------------------------------
	for(j=0; j<n_j && Set_Progress(j, n_j); j++)
	{
		for(i=0; i<n_i; i++)
		{
			Values.Get_Record(i)->Set_Value(0, bRows ? m_pGrid->asDouble(i, j) : m_pGrid->asDouble(j, i));
		}

		Values.Set_Index(0, TABLE_INDEX_Ascending);

		for(i=0; i<n_i; i++)
		{
			int		k	= i % 2 ? i / 2 : n_i - 1 - i / 2;

			if( bRows )
			{
				pHist->Set_Value(k, j, Values.Get_Record_byIndex(i)->asDouble(0));
			}
			else
			{
				pHist->Set_Value(j, k, Values.Get_Record_byIndex(i)->asDouble(0));
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
///////////////////////////////////////////////////////////
//---------------------------------------------------------
// This function modifies the incoming integer variables!!!
//---------------------------------------------------------
bool CGrid_Polygon_Clip::Get_Extent(int &xMin, int &xCount, int &yMin, int &yCount, CSG_Grid *pMask, CSG_Parameter_Grid_List *pGrids)
{
	bool	bFound;

	for(yMin=0, bFound=false; yMin<Get_NY() && !bFound && Process_Get_Okay(true); yMin++)
	{
		for(int x=0; x<Get_NX() && !bFound; x++)
		{
			bFound	= is_InGrid(x, yMin, pMask, pGrids);
		}
	}
	yMin--;
	

	//-----------------------------------------------------
	if( yMin < Get_NY() && Process_Get_Okay() )
	{
		int		xMax, yMax;

		for(yMax=Get_NY()-1, bFound=false; yMax>=yMin && !bFound && Process_Get_Okay(true); yMax--)
		{
			for(int x=0; x<Get_NX() && !bFound; x++)
			{
				bFound	= is_InGrid(x, yMax, pMask, pGrids);
			}
		}

		for(xMin=0, bFound=false; xMin<Get_NX() && !bFound && Process_Get_Okay(true); xMin++)
		{
			for(int y=yMin; y<yMax && !bFound; y++)
			{
				bFound	= is_InGrid(xMin, y, pMask, pGrids);
			}
		}
		xMin--;

		for(xMax=Get_NX()-1, bFound=false; xMax>=xMin && !bFound && Process_Get_Okay(true); xMax--)
		{
			for(int y=yMin; y<yMax && !bFound; y++)
			{
				bFound	= is_InGrid(xMax, y, pMask, pGrids);
			}
		}

		xCount	= 1 + xMax - xMin;
		yCount	= 1 + yMax - yMin;

		return( xCount > 0 && yCount > 0 );
	}

	return( false );
}
Exemple #10
0
//---------------------------------------------------------
bool CSG_Grid::_Assign_ExtremeValue(CSG_Grid *pGrid, bool bMaximum)
{
	if( Get_Cellsize() < pGrid->Get_Cellsize() || is_Intersecting(pGrid->Get_Extent()) == INTERSECTION_None )
	{
		return( false );
	}

	//-----------------------------------------------------
	int			x, y, ix, iy;
	double		px, py, ax, ay, d, z;
	CSG_Matrix	S(Get_NY(), Get_NX()), N(Get_NY(), Get_NX());

	d	= pGrid->Get_Cellsize() / Get_Cellsize();

	Set_NoData_Value(pGrid->Get_NoData_Value());

	Assign_NoData();

	//-----------------------------------------------------
	ax	= 0.5 + (pGrid->Get_XMin() - Get_XMin()) / Get_Cellsize();
	ay	= 0.5 + (pGrid->Get_YMin() - Get_YMin()) / Get_Cellsize();

	for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
	{
		if( (iy = (int)floor(py)) >= 0 && iy < Get_NY() )
		{
			for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
			{
				if( !pGrid->is_NoData(x, y) && (ix = (int)floor(px)) >= 0 && ix < Get_NX() )
				{
					z	= pGrid->asDouble(x, y);

					if( is_NoData(ix, iy)
					||	(bMaximum == true  && z > asDouble(ix, iy))
					||	(bMaximum == false && z < asDouble(ix, iy)) )
					{
						Set_Value(ix, iy, z);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	Get_History()	= pGrid->Get_History();
	Get_History().Add_Child(SG_T("GRID_OPERATION"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()))->Add_Property(SG_T("NAME"), LNG("Resampling"));

	SG_UI_Process_Set_Ready();

	return( true );
}
//---------------------------------------------------------
bool CGSGrid_Variance::On_Execute(void)
{
	int		x, y;

	//-----------------------------------------------------
	pInput		= Parameters("INPUT"	)->asGrid();
	pOutput		= Parameters("RESULT"	)->asGrid();

	maxRadius	= Parameters("RADIUS"	)->asInt();
	Exponent	= Parameters("EXPONENT"	)->asDouble();

	//-----------------------------------------------------
	Initialize();

	//-----------------------------------------------------
	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			pOutput->Set_Value(x,y, Get_Laenge(x,y) );
		}
	}

	//-----------------------------------------------------
	Finalize();

	//-----------------------------------------------------
	return( true );
}
Exemple #12
0
//---------------------------------------------------------
bool CMRVBF::Get_MRVBF(int Level, CSG_Grid *pMRVBF, CSG_Grid *pVF, CSG_Grid *pMRRTF, CSG_Grid *pRF)
{
	if( pMRVBF && pVF && pMRRTF && pRF )
	{
		double	d, w, t, p;

		t	= 0.4;
		p	= log((Level - 0.5) / 0.1) / log(1.5);

		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
		{
			for(int x=0; x<Get_NX(); x++)
			{
				if( !pMRVBF->is_NoData(x, y) && !pVF->is_NoData(x, y) )
				{
					d	= pVF->asDouble(x, y);
					w	= 1.0 - Get_Transformation(d, t, p);
					pMRVBF->Set_Value(x, y, w * (Level - 1 + d) + (1.0 - w) * pMRVBF->asDouble(x, y));
				}

				if( !pMRRTF->is_NoData(x, y) && !pRF->is_NoData(x, y) )
				{
					d	= pRF->asDouble(x, y);
					w	= 1.0 - Get_Transformation(d, t, p);
					pMRRTF->Set_Value(x, y, w * (Level - 1 + d) + (1.0 - w) * pMRRTF->asDouble(x, y));
				}
			}
		}

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
bool CGrid_Volume::On_Execute(void)
{
	int			x, y, Method;
	double		Level, Volume, z;
	CSG_Grid		*pGrid;
	CSG_String	s;

	//-----------------------------------------------------
	pGrid	= Parameters("GRID")	->asGrid();
	Level	= Parameters("LEVEL")	->asDouble();
	Method	= Parameters("METHOD")	->asInt();

	//-----------------------------------------------------
	for(y=0, Volume=0.0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( !pGrid->is_NoData(x, y) )
			{
				z	= pGrid->asDouble(x, y) - Level;

				switch( Method )
				{
				case 0:	// Count Only Above Base Level
					if( z > 0.0 )
					{
						Volume	+= z;
					}
					break;

				case 1:	// Count Only Below Base Level
					if( z < 0.0 )
					{
						Volume	-= z;
					}
					break;

				case 2:	// Subtract Volumes Below Base Level
					Volume	+= z;
					break;

				case 3:	// Add Volumes Below Base Level
					Volume	+= fabs(z);
					break;
				}
			}
		}
	}

	//-----------------------------------------------------
	Volume	*= pGrid->Get_Cellarea();

	s.Printf(_TL("Volume: %f"), Volume);

	Message_Add(s);
	Message_Dlg(s, _TL("Grid Volume"));

	//-----------------------------------------------------
	return( true );
}
//---------------------------------------------------------
bool CGradient_Polar_To_Cartes::On_Execute(void)
{
	bool		bDegree, bClockwise;
	int			Method;
	double		LEN, DIR, Zero;
	CSG_Grid	*pDX, *pDY, *pDIR, *pLEN;

	//-----------------------------------------------------
	pDX		= Parameters("DX")		->asGrid();
	pDY		= Parameters("DY")		->asGrid();
	pDIR	= Parameters("DIR")		->asGrid();
	pLEN	= Parameters("LEN")		->asGrid();

	bDegree	= Parameters("UNITS")	->asInt() == 1;
	Method	= Parameters("SYSTEM")	->asInt();

	if( Method == 0 )	// mathematic
	{
		Zero		= M_PI_090;
		bClockwise	= false;
	}
	else
	{
		Zero		= Parameters("SYSTEM_ZERO")->asDouble() * M_DEG_TO_RAD;
		bClockwise	= Parameters("SYSTEM_ORIENT")->asInt() == 0;
	}

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{		
		for(int x=0; x<Get_NX(); x++)
		{
			if( pLEN->is_NoData(x, y) || pDIR->is_NoData(x, y) )
			{
				pDX->Set_NoData(x, y);
				pDY->Set_NoData(x, y);
			}
			else
			{
				LEN	= pLEN->asDouble(x, y);
			    DIR	= pDIR->asDouble(x, y);

				if( bDegree )
				{
					DIR	*= M_DEG_TO_RAD;
				}

				if( Method != 1 )	// not geographic
				{
					DIR	= bClockwise ? DIR - Zero : Zero - DIR;
				}

				pDX->Set_Value(x, y, LEN * sin(DIR));
				pDY->Set_Value(x, y, LEN * cos(DIR));
			}
		}
	}

	return( true );
}
//---------------------------------------------------------
bool CCost_Accumulated::Get_Destinations(CPoints &Points)
{
	Points.Clear();

	m_pAccumulated->Set_NoData_Value(-1.0); m_pAccumulated->Assign(-1.0);
	m_pAllocation ->Set_NoData_Value(-1.0); m_pAllocation ->Assign( 0.0);

	if( Parameters("DEST_TYPE")->asInt() == 0 )	// Point
	{
		CSG_Shapes	*pDestinations	= Parameters("DEST_POINTS")->asShapes();

		for(int i=0, x, y; i<pDestinations->Get_Count(); i++)
		{
			if( Get_System().Get_World_to_Grid(x, y, pDestinations->Get_Shape(i)->Get_Point(0)) && !m_pCost->is_NoData(x, y) )
			{
				Points.Add(x, y); m_pAllocation->Set_Value(x, y, Points.Get_Count()); m_pAccumulated->Set_Value(x, y, 0.0);
			}
		}
	}
	else										// Grid
	{
		CSG_Grid	*pDestinations	= Parameters("DEST_GRID")->asGrid();

		for(int y=0; y<Get_NY(); y++)	for(int x=0; x<Get_NX(); x++)
		{
			if( !pDestinations->is_NoData(x, y) && !m_pCost->is_NoData(x, y) )
			{
				Points.Add(x, y); m_pAllocation->Set_Value(x, y, Points.Get_Count()); m_pAccumulated->Set_Value(x, y, 0.0);
			}
		}
	}

	return( Points.Get_Count() > 0 );
}
//---------------------------------------------------------
bool CFragmentation_Classify::On_Execute(void)
{
	CSG_Grid	*pDensity, *pConnectivity, *pFragmentation;

	pDensity			= Parameters("DENSITY")			->asGrid();
	pConnectivity		= Parameters("CONNECTIVITY")	->asGrid();
	pFragmentation		= Parameters("FRAGMENTATION")	->asGrid();

	m_Weight			= Parameters("WEIGHT")			->asDouble();
	m_Density_Min		= Parameters("DENSITY_MIN")		->asDouble() / 100.0;
	m_Density_Interior	= Parameters("DENSITY_INT")		->asDouble() / 100.0;

	//-----------------------------------------------------
	CSG_Parameters	Parms;

	DataObject_Set_Colors(pFragmentation, 100, SG_COLORS_WHITE_GREEN, true);

	if( DataObject_Get_Parameters(pFragmentation, Parms) && Parms("COLORS_TYPE") && Parms("LUT") )
	{
		Parms("LUT")->asTable()->Assign_Values(&m_LUT);	// Lookup Table
		Parms("COLORS_TYPE")->Set_Value(1);				// Color Classification Type: Lookup Table

		DataObject_Set_Parameters(pFragmentation, Parms);
	}

//	pFragmentation->Set_NoData_Value(CLASS_NONE);

	//-----------------------------------------------------
	if( 1 )
	{
		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
		{
			for(int x=0; x<Get_NX(); x++)
			{
				if( !pDensity->is_NoData(x, y) && !pConnectivity->is_NoData(x, y) )
				{
					double	Density			= pDensity		->asDouble(x, y) / 100.0;
					double	Connectivity	= pConnectivity	->asDouble(x, y) / 100.0;

				//	pFragmentation	->Set_Value (x, y, 100.0 * Density * Connectivity);
					pFragmentation	->Set_Value (x, y, Get_Classification(Density, Connectivity));
				}
				else
				{
					pFragmentation	->Set_NoData(x, y);
				}
			}
		}

		//-------------------------------------------------
		if( Parameters("BORDER")->asBool() )
		{
			Add_Border(pFragmentation);
		}

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
bool CGrid_Division::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Grid	*pA	= Parameters("A")->asGrid();
	CSG_Grid	*pB	= Parameters("B")->asGrid();
	CSG_Grid	*pC	= Parameters("C")->asGrid();

	DataObject_Set_Colors(pC, 11, SG_COLORS_RED_GREY_BLUE);

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		#pragma omp parallel for
		for(int x=0; x<Get_NX(); x++)
		{
			if( pA->is_NoData(x, y) || pB->is_NoData(x, y) || pB->asDouble(x, y) == 0.0 )
			{
				pC->Set_NoData(x, y);
			}
			else
			{
				pC->Set_Value(x, y, pA->asDouble(x, y) / pB->asDouble(x, y));
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
Exemple #18
0
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
Exemple #19
0
//---------------------------------------------------------
bool CSG_Grid::Assign(double Value)
{
	if( is_Valid() )
	{
		if( Value == 0.0 && m_Memory_Type == GRID_MEMORY_Normal )
		{
			for(int n=0, m=_Get_nLineBytes(); n<Get_NY(); n++)
			{
				memset(m_Values[n], 0, m);
			}
		}
		else
		{
			for(int n=0; n<Get_NCells(); n++)
			{
				Set_Value(n, Value);
			}
		}

		//-------------------------------------------------
		Get_History().Destroy();
		Get_History().Add_Child(SG_T("GRID_OPERATION"), Value)->Add_Property(SG_T("NAME"), LNG("Assign"));

		//-------------------------------------------------
		m_zStats.Invalidate();

		Set_Update_Flag(false);

		return( true );
	}

	return( false );
}
Exemple #20
0
//---------------------------------------------------------
bool CGrid_Plotter::On_Execute(void)
{
	pResult		= Parameters("RESULT")->asGrid();

	double xmin	= Parameters("XMIN")->asDouble();
	double ymin	= Parameters("YMIN")->asDouble();
	double xmax	= Parameters("XMAX")->asDouble();
	double ymax	= Parameters("YMAX")->asDouble();

	const SG_Char *formel  = Parameters("FORMUL")->asString();

	CSG_Formula Formel;

	Formel.Set_Formula(formel);

	CSG_String Msg;
	if (Formel.Get_Error(Msg))
	{
		Message_Add(Msg);
		
		return false;
	}

	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	for(int x=0; x<Get_NX(); x++)
	{
		pResult->Set_Value(x,y,Formel.Get_Value(SG_T("xy"),(xmax-xmin)*((double)x/Get_NX())+xmin,(ymax-ymin)*((double)y/Get_NY())+ymin)); 
	}
	return( true );
}
Exemple #21
0
//---------------------------------------------------------
bool CMRVBF::Get_Classified(CSG_Grid *pMRF)
{
	if( pMRF && pMRF->is_Valid() )
	{
		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
		{
			for(int x=0; x<Get_NX(); x++)
			{
				if( !pMRF->is_NoData(x, y) )
				{
					double	d	= pMRF->asDouble(x, y);

					if		( d < 0.5 )
						pMRF->Set_Value(x, y, 0.0);
					else if	( d < 1.5 )
						pMRF->Set_Value(x, y, 1.0);
					else if	( d < 2.5 )
						pMRF->Set_Value(x, y, 2.0);
					else if	( d < 3.5 )
						pMRF->Set_Value(x, y, 3.0);
					else if	( d < 4.5 )
						pMRF->Set_Value(x, y, 4.0);
					else if	( d < 5.5 )
						pMRF->Set_Value(x, y, 5.0);
					else
						pMRF->Set_Value(x, y, 6.0);
				}
			}
		}

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
bool CExercise_10::On_Execute(void)
{
	bool	bAlive;
	int		x, y, i;
	CSG_Colors	Colors;


	//-----------------------------------------------------
	// General initialisations...

	m_pLife		= Parameters("RESULT")->asGrid();

	m_nColors	= Parameters("COLORS")->asInt();

	Colors.Set_Count(m_nColors + 1);
	Colors.Set_Ramp(SG_GET_RGB(127, 127, 127), SG_GET_RGB(0, 0, 0));
	Colors.Set_Color(0, SG_GET_RGB(255, 255, 255));
	DataObject_Set_Colors(m_pLife, Colors);


	//-----------------------------------------------------
	// Initialise life's world...

	if( Parameters("REFRESH")->asBool() )
	{
		srand((unsigned)time(NULL));

		for(y=0; y<Get_NY(); y++)
		{
			for(x=0; x<Get_NX(); x++)
			{
				m_pLife->Set_Value(x, y, rand() > RAND_MAX / 2 ? 0 : 1);
			}
		}
	}


	//-----------------------------------------------------
	// Execution...

	m_pTemp		= SG_Create_Grid(m_pLife, SG_DATATYPE_Byte);

	for(i=1, bAlive=true; bAlive && Process_Get_Okay(true); i++)
	{
		Process_Set_Text(CSG_String::Format(SG_T("%d %s"), i, _TL("Life Cycle")));

		if( (bAlive = Next_Step()) == false )
		{
			Message_Add(CSG_String::Format(SG_T("%s %d %s\n"), _TL("Dead after"), i, _TL("Life Cycles")));
		}
	}

	delete(m_pTemp);


	//-----------------------------------------------------
	// Finish...

	return( true );
}
//---------------------------------------------------------
void CHillslope_Evolution_FTCS::Set_Diffusion(double dFactor)
{
	int	iStep	= Parameters("NEIGHBOURS")->asInt() == 1 ? 1 : 2;

	m_pDEM_Old->Assign(m_pDEM);

	#pragma omp parallel for
	for(int y=0; y<Get_NY(); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			if( !m_pDEM_Old->is_NoData(x, y) )
			{
				double	z	= m_pDEM_Old->asDouble(x, y);
				double	dz	= 0.0;

				for(int i=0; i<8; i+=iStep)
				{
					int	ix	= Get_xTo(i, x);
					int	iy	= Get_yTo(i, y);

					if( m_pDEM_Old->is_InGrid(ix, iy) )
					{
						dz	+= (m_pDEM_Old->asDouble(ix, iy) - z) / Get_UnitLength(i);
					}
				}

				m_pDEM->Add_Value(x, y, dFactor * dz);
			}
		}
	}
}
//---------------------------------------------------------
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 );
}
bool CGrid_Pattern::On_Execute(void){
	
	m_pInput = Parameters("INPUT")->asGrid(); 	
	CSG_Grid *pRelative = Parameters("RELATIVE")->asGrid();
	CSG_Grid *pDominance = Parameters("DOMINANCE")->asGrid();
	CSG_Grid *pDiversity = Parameters("DIVERSITY")->asGrid();
	CSG_Grid *pFragmentation = Parameters("FRAGMENTATION")->asGrid();
	CSG_Grid *pNDC = Parameters("NDC")->asGrid();
	CSG_Grid *pCVN = Parameters("CVN")->asGrid();
	m_iWinSize = Parameters("WINSIZE")->asInt()*2+3;
	m_iNumClasses = Parameters("MAXNUMCLASS")->asInt();
	
    for(int y=m_iWinSize-2; y<Get_NY()-m_iWinSize+2 && Set_Progress(y); y++){		
		for(int x=m_iWinSize-2; x<Get_NX()-m_iWinSize+2; x++){
			double dDiversity = getDiversity(x,y);
			int iNumClasses = getNumberOfClasses(x,y);
			pRelative->Set_Value(x,y,((double)iNumClasses)/((double)m_iNumClasses)*100.0);
			pDominance->Set_Value(x,y,log((double)iNumClasses)-dDiversity);
			pDiversity->Set_Value(x,y,dDiversity);
			pFragmentation->Set_Value(x,y,((double)(iNumClasses-1))/((double)(m_iWinSize*m_iWinSize-1)));
			pNDC->Set_Value(x,y,iNumClasses);
			pCVN->Set_Value(x,y,getCVN(x,y));
        }// for
    }// for

	return true;

}//method
//---------------------------------------------------------
bool CConvergence::On_Execute(void)
{
	bool		bGradient;
	int			Neighbours;
	CSG_Grid	*pConvergence;

	m_pDTM			= Parameters("ELEVATION")	->asGrid();
	pConvergence	= Parameters("RESULT")		->asGrid();
	Neighbours		= Parameters("NEIGHBOURS")	->asInt();
	bGradient		= Parameters("METHOD")		->asInt() == 1;

	DataObject_Set_Colors(pConvergence, 100, SG_COLORS_RED_GREY_BLUE, true);

	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			if( m_pDTM->is_InGrid(x, y) )
			{
				switch( Neighbours )
				{
				case 0: default:	pConvergence->Set_Value(x, y, Get_2x2(x, y, bGradient));	break;
				case 1:				pConvergence->Set_Value(x, y, Get_9x9(x, y, bGradient));	break;
				}
			}
			else
			{
				pConvergence->Set_NoData(x, y);
			}
		}
	}

	return( true );
}
Exemple #27
0
bool CIsochronesVar::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
{
	int iX, iY;

	if(	Mode != MODULE_INTERACTIVE_LDOWN || !Get_Grid_Pos(iX, iY) )
	{
		return( false );
	}
	
	m_pTime->Assign((double)0);

	writeTimeOut(iX, iY, iX, iY);

	for(int y=0; y<Get_NY() && Set_Progress(y); y++){
		for(int x=0; x<Get_NX(); x++){
			m_pTime->Set_Value(x,y,m_pTime->asDouble(x,y)/3600.);
        }// for
    }// for

	ZeroToNoData();

	DataObject_Update(m_pTime, true);

	return (true);

}//method
Exemple #28
0
//---------------------------------------------------------
bool CTC_Texture::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Grid	Noise(*Get_System(), SG_DATATYPE_Char);

	double	Epsilon	= Parameters("EPSILON")->asDouble();

	m_pDEM	= Parameters("DEM")->asGrid();

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		#pragma omp parallel for
		for(int x=0; x<Get_NX(); x++)
		{
			if( m_pDEM->is_NoData(x, y) )
			{
				Noise.Set_NoData(x, y);
			}
			else
			{
				Noise.Set_Value(x, y, Get_Noise(x, y, Epsilon));
			}
		}
	}

	//-----------------------------------------------------
	return( Get_Parameter(&Noise, Parameters("TEXTURE")->asGrid()) );
}
Exemple #29
0
bool CGrid_CVA::On_Execute(void){
	
	double a1,a2,b1,b2;
	double dDist, dAngle;
	
	CSG_Grid* pA1 = Parameters("A1")->asGrid(); 
	CSG_Grid* pA2 = Parameters("A2")->asGrid(); 
	CSG_Grid* pB1 = Parameters("B1")->asGrid(); 
	CSG_Grid* pB2 = Parameters("B2")->asGrid(); 
	CSG_Grid* pDist = Parameters("DIST")->asGrid(); 
	CSG_Grid* pAngle = Parameters("ANGLE")->asGrid();
	pDist->Assign(0.0);
	pAngle->Assign(0.0);

    for(int y=0; y<Get_NY() && Set_Progress(y); y++){		
		for(int x=0; x<Get_NX(); x++){
			a1 = pA1->asDouble(x,y);
			a2 = pA2->asDouble(x,y);
			b1 = pB1->asDouble(x,y);
			b2 = pB2->asDouble(x,y);
			dDist = sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
			dAngle = atan((a1-a2)/(b1-b2));			
			pDist->Set_Value(x,y,dDist);
			pAngle->Set_Value(x,y,dAngle);
        }// for
    }// for

	return true;

}//method
Exemple #30
0
//---------------------------------------------------------
bool CTC_Convexity::On_Execute(void)
{
	//-----------------------------------------------------
	const double	Kernels[3][2]	= { { 1, 0 }, { 1, 1 }, { 1, 1 / sqrt(2.0) } };

	int	Kernel	= Parameters("KERNEL")->asInt();

	//-----------------------------------------------------
	CSG_Grid	Laplace(*Get_System(), SG_DATATYPE_Char);

	double	Epsilon	= Parameters("EPSILON")->asDouble();
	int		Type	= Parameters("TYPE"   )->asInt   ();

	m_pDEM	= Parameters("DEM")->asGrid();

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		#pragma omp parallel for
		for(int x=0; x<Get_NX(); x++)
		{
			if( m_pDEM->is_NoData(x, y) )
			{
				Laplace.Set_NoData(x, y);
			}
			else
			{
				Laplace.Set_Value(x, y, Get_Laplace(x, y, Kernels[Kernel], Type, Epsilon));
			}
		}
	}

	//-----------------------------------------------------
	return( Get_Parameter(&Laplace, Parameters("CONVEXITY")->asGrid()) );
}