//---------------------------------------------------------
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 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 );
}
예제 #3
0
//---------------------------------------------------------
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 );
}
예제 #4
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 );
}
예제 #6
0
//---------------------------------------------------------
bool CConvergence_Radius::On_Execute(void)
{
	CSG_Grid	*pDTM, *pConvergence_Radius;

	pDTM				= Parameters("ELEVATION")	->asGrid();
	pConvergence_Radius	= Parameters("RESULT")		->asGrid();

	if( Initialize(pDTM, Parameters("RADIUS")->asInt()) )
	{
		DataObject_Set_Colors(pConvergence_Radius, 100, SG_COLORS_RED_GREY_BLUE, true);

		pConvergence_Radius->Assign_NoData();

		Get_Convergence_Radius(
			pDTM,
			pConvergence_Radius,
			Parameters("SLOPE")	->asBool(),
			Parameters("DIFF")	->asInt() == 0 ? true : false,
			Parameters("METHOD")->asInt()
		);

		Finalize();

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
bool CPC_Drop_Attribute::On_After_Execution(void)
{
	CSG_PointCloud	*pOutput	= Parameters("OUTPUT")->asPointCloud();

	if( pOutput == NULL )
	{
		pOutput	= Parameters("INPUT")->asPointCloud();
	}

	DataObject_Set_Parameter(pOutput, "DISPLAY_VALUE_AGGREGATE",  3);	// highest z
	DataObject_Set_Parameter(pOutput, "METRIC_COLORS"          , 12);	// number of colors
	DataObject_Set_Parameter(pOutput, "COLORS_TYPE"            ,  3);	// graduated color
	DataObject_Set_Parameter(pOutput, "METRIC_ATTRIB"          ,  2);	// z attrib
	DataObject_Set_Parameter(pOutput, "METRIC_ZRANGE",
		pOutput->Get_Mean(2) - 2.0 * pOutput->Get_StdDev(2),
		pOutput->Get_Mean(2) + 2.0 * pOutput->Get_StdDev(2)
	);

	DataObject_Set_Colors(pOutput, 11, SG_COLORS_RAINBOW);

	if( pOutput == Parameters("INPUT")->asPointCloud() )
	{
		Parameters("OUTPUT")->Set_Value(DATAOBJECT_NOTSET);
	}

	return( true );
}
//---------------------------------------------------------
bool CHillslope_Evolution_FTCS::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Grid	DEM(Get_System());

	m_pDEM_Old	= &DEM;

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

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

	DataObject_Set_Colors(Parameters("DIFF")->asGrid(), 10, SG_COLORS_RED_GREY_BLUE, true);

	//-----------------------------------------------------
	double	k, dTime, nTime;

	k		= Parameters("KAPPA"   )->asDouble();
	nTime	= Parameters("DURATION")->asDouble();

	if( Parameters("TIMESTEP")->asInt() == 0 )
	{
		dTime	= Parameters("DTIME")->asDouble();
	}
	else
	{
		dTime	= 0.5 * Get_Cellarea() / (2.0 * k);

		if( Parameters("NEIGHBOURS")->asInt() == 1 )
		{
			dTime	/= sqrt(2.0);
		}
	}

	if( dTime > nTime )
	{
		Message_Fmt("\n%s: %s [%f]", _TL("Warning"), _TL("Time step exceeds duration"), dTime);

		dTime	= nTime;
	}

	Message_Fmt("\n%s: %f", _TL("Time Step"), dTime);
	Message_Fmt("\n%s: %d", _TL("Steps"), (int)(nTime / dTime));

	//-----------------------------------------------------
	for(double iTime=dTime; iTime<=nTime && Set_Progress(iTime, nTime); iTime+=dTime)
	{
		Process_Set_Text("%s: %.2f [%.2f]", _TL("Simulation Time"), iTime, nTime);

		SG_UI_Progress_Lock(true);

		Set_Diffusion(dTime * k / Get_Cellarea());

		Set_Difference();

		SG_UI_Progress_Lock(false);
	}

	//-----------------------------------------------------
	return( true );
}
예제 #9
0
//---------------------------------------------------------
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 );
}
예제 #10
0
void Cdodproperror::ApplyColors(CSG_Grid* from, CSG_Grid* to)
{
		CSG_Colors colors;
		DataObject_Get_Colors(from, colors);
		DataObject_Set_Colors(to, colors);
		DataObject_Update(to, false);	
}
예제 #11
0
//---------------------------------------------------------
bool CDVWK_SoilMoisture::On_Execute(void)
{
	int			Day, x, y, i, LandUseID;
	CSG_Grid	*pGrid;

	//-----------------------------------------------------
	if( pClimate->Get_Record_Count() > 0 )
	{
		pFK_mm		= Parameters("STA_FC")		->asGrid();
		FK_mm_Def	= Parameters("STA_FC_DEF")	->asDouble();

		pPWP_mm		= Parameters("STA_PWP")		->asGrid();
		PWP_mm_Def	= Parameters("STA_PWP_DEF")	->asDouble();

		pWi_mm		= Parameters("DYN_W")		->asGrid();
		DataObject_Set_Colors(pWi_mm, 100, SG_COLORS_YELLOW_BLUE);

		//-------------------------------------------------
		pLandUse	= SG_Create_Grid(pWi_mm, pCropCoeff->Get_Record_Count() < 127 ? SG_DATATYPE_Char : SG_DATATYPE_Int);
		pLandUse->Assign(Parameters("LANDUSE_DEF")->asInt());

		if( (pGrid = Parameters("LANDUSE")->asGrid()) != NULL )
		{
			for(y=0; y<Get_NY(); y++)
			{
				for(x=0; x<Get_NX(); x++)
				{
					LandUseID	= pGrid->asInt(x, y);

					for(i=0; i<pCropCoeff->Get_Record_Count(); i++)
					{
						if( LandUseID == pCropCoeff->Get_Record(i)->asInt(0) )
						{
							pLandUse->Set_Value(x, y, i);
							break;
						}
					}
				}
			}
		}

		//-------------------------------------------------
		DataObject_Update(pWi_mm, 0, pFK_mm ? pFK_mm->Get_ZMax() : FK_mm_Def, true);

		for(Day=0; Day<365 && Set_Progress(Day, 365); Day++)
		{
			Step_Day(Day);

			DataObject_Update(pWi_mm, true);
		}

		//-------------------------------------------------
		delete(pLandUse);

		return( true );
	}

	return( false );
}
예제 #12
0
//---------------------------------------------------------
bool CMine_Sweeper::MakeBoard(int level)
{
	int		i, x, y;
	CSG_Colors	Colors;

	switch( level )
	{
		case 0:	Mine_NX = 8;	Mine_NY = 8;	N_Mines=10;
			break;
		
		case 1: Mine_NX = 16;	Mine_NY = 16;	N_Mines=40;
			break;
		
		case 2: Mine_NX = 30;	Mine_NY = 16;	N_Mines=99;
			break;
	}

	pInput	= SG_Create_Grid(SG_DATATYPE_Int,SPRITE_SIZE*Mine_NX, SPRITE_SIZE*Mine_NY);
	pInput->Set_Name(_TL("Mine Sweeper"));
	Parameters("GRID")->Set_Value(pInput);

	//-----------------------------------------------------
	CSG_Parameter	*pLUT	= DataObject_Get_Parameter(pInput, "LUT");

	if( pLUT && pLUT->asTable() )
	{
		pLUT->asTable()->Del_Records();

		for(i=0; i<16; i++)
		{
			CSG_Table_Record	*pRecord	= pLUT->asTable()->Add_Record();
			
			pRecord->Set_Value(0, SG_GET_RGB(mine_res_color[i*3], mine_res_color[i*3+1], mine_res_color[i*3+2]));
			pRecord->Set_Value(3, i);
		}

		DataObject_Set_Parameter(pInput, pLUT);
		DataObject_Set_Parameter(pInput, "COLORS_TYPE", 1);	// Color Classification Type: Lookup Table
	}

	Colors.Set_Count(16);
	for ( i=0;i<16; i++)
	{
		Colors.Set_Color(i, SG_GET_RGB(mine_res_color[i*3],	mine_res_color[i*3+1],	mine_res_color[i*3+2]));
	}
	DataObject_Set_Colors(pInput, Colors);
	DataObject_Update(pInput, 0.0, 15.0, true);

	//-----------------------------------------------------
	for(  y = 0; y <  Mine_NY; y++)	
	for(  x = 0; x <  Mine_NX; x++)
	{
		SetSprite(x,y,SPRITE_CLOSE);
	}

	pInput->Set_Value(0, 0);

	return true;			
}
예제 #13
0
//---------------------------------------------------------
bool CErosion_LS_Fields::On_Execute(void)
{
	//-----------------------------------------------------
	m_Method		= Parameters("METHOD"        )->asInt();
	m_Method_Slope	= Parameters("METHOD_SLOPE"  )->asInt();
	m_Method_Area	= Parameters("METHOD_AREA"   )->asInt();

	m_bStopAtEdge	= Parameters("STOP_AT_EDGE"  )->asBool();

	m_Erosivity		= Parameters("EROSIVITY"     )->asDouble();
	m_Stability		= Parameters("STABILITY"     )->asInt();

	m_pDEM			= Parameters("DEM"           )->asGrid();
	m_pUp_Area		= Parameters("UPSLOPE_AREA"  )->asGrid();
	m_pUp_Length	= Parameters("UPSLOPE_LENGTH")->asGrid();
	m_pUp_Slope		= Parameters("UPSLOPE_SLOPE" )->asGrid();
	m_pLS			= Parameters("LS_FACTOR"     )->asGrid();

	DataObject_Set_Colors(m_pUp_Area  , 11, SG_COLORS_WHITE_BLUE    , false);
	DataObject_Set_Colors(m_pUp_Length, 11, SG_COLORS_YELLOW_RED    , false);
	DataObject_Set_Colors(m_pUp_Slope , 11, SG_COLORS_YELLOW_RED    , false);
	DataObject_Set_Colors(m_pLS       , 11, SG_COLORS_RED_GREY_GREEN, true );

	if( m_pUp_Area   == NULL )	m_pUp_Area   = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float);
	if( m_pUp_Length == NULL )	m_pUp_Length = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float);
	if( m_pUp_Slope  == NULL )	m_pUp_Slope  = SG_Create_Grid(*Get_System(), SG_DATATYPE_Float);

	//-----------------------------------------------------
	bool	bResult	= Set_Fields() && Get_Flow() && Get_LS();

	if( bResult )
	{
		Get_Statistics();

		Get_Balance();
	}

	//-----------------------------------------------------
	if( m_pUp_Area   && Parameters("UPSLOPE_AREA"  )->asGrid() == NULL ) delete(m_pUp_Area  );
	if( m_pUp_Length && Parameters("UPSLOPE_LENGTH")->asGrid() == NULL ) delete(m_pUp_Length);
	if( m_pUp_Slope  && Parameters("UPSLOPE_SLOPE" )->asGrid() == NULL ) delete(m_pUp_Slope );

	m_Fields.Destroy();

	return( bResult );
}
예제 #14
0
//---------------------------------------------------------
bool CFilter_LoG::On_Execute(void)
{
	CSG_Grid	*pResult;

	//-----------------------------------------------------
	m_pInput	= Parameters("INPUT")	->asGrid();
	pResult		= Parameters("RESULT")	->asGrid();

	//-----------------------------------------------------
	if( Initialise() )
	{
		if( !pResult || pResult == m_pInput )
		{
			pResult	= SG_Create_Grid(m_pInput);
		}
		else
		{
			pResult->Set_Name(CSG_String::Format(SG_T("%s [%s]"), m_pInput->Get_Name(), _TL("Laplace Filter")));

			pResult->Set_NoData_Value(m_pInput->Get_NoData_Value());
		}

		//-------------------------------------------------
		for(int y=0; y<Get_NY() && Set_Progress(y); y++)
		{
			for(int x=0; x<Get_NX(); x++)
			{
				if( m_pInput->is_InGrid(x, y) )
				{
					pResult->Set_Value(x, y, Get_Value(x, y));
				}
				else
				{
					pResult->Set_NoData(x, y);
				}
			}
		}

		//-------------------------------------------------
		if( !Parameters("RESULT")->asGrid() || Parameters("RESULT")->asGrid() == m_pInput )
		{
			m_pInput->Assign(pResult);

			delete(pResult);

			pResult	= m_pInput;
		}

		DataObject_Set_Colors(pResult, 100, SG_COLORS_BLACK_WHITE);

		m_Kernel.Destroy();

		return( true );
	}

	//-----------------------------------------------------
	return( false );
}
예제 #15
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 );
}
예제 #16
0
//---------------------------------------------------------
bool CGrid_Colors_Fit::On_Execute(void)
{
	int		iColor;
	long	aC, bC;
	double	aZ, bZ, dColor, zMin, zRange;
	CSG_Colors	Colors_Old, Colors_New;
	CSG_Grid	*pGrid;

	pGrid	= Parameters("GRID")->asGrid();

	Colors_New.Set_Count(Parameters("COUNT")->asInt());

	switch( Parameters("SCALE")->asInt() )
	{
	case 0:	default:
		zMin	= pGrid->Get_ZMin();
		zRange	= pGrid->Get_ZMax() - zMin;
		break;

	case 1:
		zMin	= Parameters("RANGE")->asRange()->Get_LoVal();
		zRange	= Parameters("RANGE")->asRange()->Get_HiVal() - zMin;
		break;
	}

	DataObject_Get_Colors(pGrid, Colors_Old);

	if( Colors_Old.Get_Count() > 1 && pGrid->Get_ZRange() > 0.0 && zRange != 0.0 )
	{
		dColor	= 100.0 / Colors_Old.Get_Count();

		aZ		= 0.0;
		aC		= Colors_Old.Get_Color(0);

		for(iColor=1; iColor<Colors_Old.Get_Count()-1; iColor++)
		{
			bZ	= aZ;
			bC	= aC;
			aZ	= (pGrid->Get_Percentile(iColor * dColor) - zMin) / zRange;
			aC	= Colors_Old.Get_Color(iColor);
			_Set_Colors(Colors_New, bZ, bC, aZ, aC);
		}

		bZ	= aZ;
		bC	= aC;
		aZ	= 1.0;
		aC	= Colors_Old.Get_Color(Colors_Old.Get_Count() - 1);
		_Set_Colors(Colors_New, bZ, bC, aZ, aC);

		DataObject_Set_Colors	(pGrid, Colors_New);
		DataObject_Update		(pGrid, zMin, zMin + zRange);

		return( true );
	}

	return( false );
}
예제 #17
0
//---------------------------------------------------------
bool CKernel_Density::On_Execute(void)
{
	int			Population;
	double		Radius;
	CSG_Shapes	*pPoints;

	//-----------------------------------------------------
	pPoints		= Parameters("POINTS"    )->asShapes();
	Population	= Parameters("POPULATION")->asInt();
	Radius		= Parameters("RADIUS"    )->asDouble();
	m_Kernel	= Parameters("KERNEL"    )->asInt();

	if( Population < 0 || Population >= pPoints->Get_Field_Count() || pPoints->Get_Field_Type(Population) == SG_DATATYPE_String )
	{
		Population	= -1;
	}

	//-----------------------------------------------------
	if( (m_pGrid = m_Grid_Target.Get_Grid()) == NULL )
	{
		return( false );
	}

	m_pGrid->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), _TL("Kernel Density")));
	m_pGrid->Set_NoData_Value(0.0);
	m_pGrid->Assign(0.0);

	DataObject_Set_Colors(m_pGrid, 100, SG_COLORS_BLACK_WHITE, true);

	m_dRadius	= Radius / m_pGrid->Get_Cellsize();
	m_iRadius	= 1 + (int)m_dRadius;

	//-----------------------------------------------------
	if( pPoints->Get_Selection_Count() > 0 )
	{
		for(int iPoint=0; iPoint<pPoints->Get_Selection_Count() && Set_Progress(iPoint, pPoints->Get_Selection_Count()); iPoint++)
		{
			CSG_Shape	*pPoint	= pPoints->Get_Selection(iPoint);

			Set_Kernel(pPoint->Get_Point(0), Population < 0 ? 1.0 : pPoint->asDouble(Population));
		}
	}
	else
	{
		for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++)
		{
			CSG_Shape	*pPoint	= pPoints->Get_Shape(iPoint);

			Set_Kernel(pPoint->Get_Point(0), Population < 0 ? 1.0 : pPoint->asDouble(Population));
		}
	}

	return( true );
}
예제 #18
0
//---------------------------------------------------------
bool CFlow_Distance::On_Execute(void)
{
	bool		bSeeds;
	int			x, y, Method;
	CSG_Grid	*pSeed;

	//-------------------------------------------------
	m_pDTM		= Parameters("ELEVATION")	->asGrid();
	pSeed		= Parameters("SEED")		->asGrid();
	m_pLength	= Parameters("LENGTH")		->asGrid();

	m_Converge	= Parameters("CONVERGENCE")	->asDouble();
	bSeeds		= Parameters("SEEDS_ONLY")	->asBool();
	Method		= Parameters("METHOD")		->asInt();

	m_pWeight	= SG_Create_Grid(m_pLength, SG_DATATYPE_Float);
	m_pWeight	->Assign(0.0);
	m_pLength	->Assign(0.0);

	//-------------------------------------------------
	for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
	{
		m_pDTM->Get_Sorted(n, x, y, true, false);

		if( pSeed && !pSeed->is_NoData(x, y) )
		{
			m_pLength->Set_Value(x, y, 0.0);
			m_pWeight->Set_Value(x, y, 0.0);
		}
		else if( m_pWeight->asDouble(x, y) > 0.0 )
		{
			m_pLength->Set_Value(x, y, m_pLength->asDouble(x, y) / m_pWeight->asDouble(x, y));
		}
		else if( bSeeds )
		{
			m_pLength->Set_NoData(x, y);

			continue;
		}

		switch( Method )
		{
		case 0:	Set_Length_D8	(x, y);	break;
		case 1:	Set_Length_MFD	(x, y);	break;
		}
	}

	//-------------------------------------------------
	delete(m_pWeight);

	DataObject_Set_Colors(m_pLength, 100, SG_COLORS_WHITE_BLUE);

	return( true );
}
예제 #19
0
//---------------------------------------------------------
bool CFlow_by_Slope::On_Execute(void)
{
	m_Slope_Min	= Parameters("SLOPE_MIN")->asDouble() * M_DEG_TO_RAD;
	m_Slope_Max = Parameters("SLOPE_MAX")->asDouble() * M_DEG_TO_RAD;

	if( m_Slope_Max <= 0.0 )
	{
		Error_Set(_TL("slope threshold must not be zero!"));

		return( false );
	}

	if( Parameters("B_FLOW")->asBool() )
	{
		m_Flow_Min	= Parameters("T_FLOW")->asRange()->Get_LoVal() * Get_Cellarea();
		m_Flow_Max	= Parameters("T_FLOW")->asRange()->Get_HiVal() * Get_Cellarea();
	}
	else
	{
		m_Flow_Min	= m_Flow_Max	= 0.0;
	}

	//-----------------------------------------------------
	m_pDEM		= Parameters("DEM"   )->asGrid();
	m_pFlow		= Parameters("FLOW"  )->asGrid();

	m_pFlow->Assign(Get_Cellarea());

	if( Parameters("WEIGHT")->asGrid() )
	{
		m_pFlow->Multiply(*Parameters("WEIGHT")->asGrid());
	}

	DataObject_Set_Colors(m_pFlow, 11, SG_COLORS_WHITE_BLUE, false);

	//-----------------------------------------------------
	for(sLong i=0; i<Get_NCells() && Set_Progress_NCells(i); i++)
	{
		int	x, y;

		if( !m_pDEM->Get_Sorted(i, x, y, true) || m_pDEM->is_NoData(x, y) )
		{
			m_pFlow->Set_NoData(x, y);
		}
		else
		{
			Set_Area(x, y);
		}
	}

	//-----------------------------------------------------
	return( true );
}
예제 #20
0
//---------------------------------------------------------
bool CLife::On_Execute(void)
{
	//-----------------------------------------------------
	m_pLife	= m_Grid_Target.Get_Grid("LIFE", SG_DATATYPE_Byte);

	if( !m_pLife )
	{
		Error_Set(_TL("could not create target grid"));

		return( false );
	}

	//-----------------------------------------------------
	m_nColors	= Parameters("FADECOLOR")->asInt();

	for(int y=0; y<m_pLife->Get_NY(); y++)
	{
		for(int x=0; x<m_pLife->Get_NX(); x++)
		{
			m_pLife->Set_Value(x, y, CSG_Random::Get_Uniform(0, 100) < 50 ? 0 : m_nColors);
		}
	}

	//-----------------------------------------------------
	m_pLife->Set_Name(_TL("Conway's Game of Life"));
	m_pLife->Set_NoData_Value(-1);

	DataObject_Add       (m_pLife);
	DataObject_Set_Colors(m_pLife, 11, SG_COLORS_WHITE_BLUE);
	DataObject_Update    (m_pLife, 0, m_nColors, SG_UI_DATAOBJECT_SHOW);

	//-----------------------------------------------------
	int		i;

	m_Count.Create(m_pLife->Get_System(), SG_DATATYPE_Byte);

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

		DataObject_Update(m_pLife, 0, m_nColors);
	}

	m_Count.Destroy();

	//-----------------------------------------------------
	if( is_Progress() )
	{
		Message_Add(CSG_String::Format("\n%s %d %s\n", _TL("Dead after"), i, _TL("Life Cycles")), false);
	}

	return( true );
}
예제 #21
0
//---------------------------------------------------------
bool CDiffuse_Pollution_Risk::On_Execute(void)
{	
	//-----------------------------------------------------
	m_pDEM			= Parameters("DEM"         )->asGrid();
	m_pDelivery		= Parameters("DELIVERY"    )->asGrid();
	m_pRisk_Point	= Parameters("RISK_POINT"  )->asGrid();
	m_pRisk_Diffuse	= Parameters("RISK_DIFFUSE")->asGrid();
	m_bSingle		= Parameters("METHOD"      )->asInt() == 0;

	DataObject_Set_Colors(m_pDelivery    , 11, SG_COLORS_RED_GREY_GREEN, true);
	DataObject_Set_Colors(m_pRisk_Point  , 11, SG_COLORS_RED_GREY_GREEN, true);
	DataObject_Set_Colors(m_pRisk_Diffuse, 11, SG_COLORS_RED_GREY_GREEN, true);

	//-----------------------------------------------------
	bool	bResult	= false;

	if( !Set_Flow() )
	{
		Error_Set(_TL("initialization failed"));
	}
	else if( !Set_Delivery_Index() )
	{
		Error_Set(_TL("delivery index calculation failed"));
	}
	else if( !Get_Risk_Diffuse() )
	{
		Error_Set(_TL("diffuse pollution risk calculation failed"));
	}
	else
	{
		bResult	= true;
	}

	//-----------------------------------------------------
	m_FlowDir.Destroy();
	m_RainAcc.Destroy();
	m_TWI    .Destroy();

	return( bResult );
}
예제 #22
0
//---------------------------------------------------------
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 CLandsat_Import::On_Execute(void)
{
	CSG_Strings	Files;

	if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) || Files.Get_Count() <= 0 )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Parameter_Grid_List	*pBands	= Parameters("BANDS")->asGridList();

	pBands->Del_Items();

	for(int i=0; i<Files.Get_Count(); i++)
	{
		Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("loading"), SG_File_Get_Name(Files[i], false).c_str()));

		CSG_Grid	*pBand	= Get_Band(Files[i]);

		if( pBand )
		{
			pBands->Add_Item(pBand);

			DataObject_Add(pBand);
			DataObject_Set_Colors(pBand, 11, SG_COLORS_BLACK_WHITE);
		}
	}

	//-----------------------------------------------------
	if( Parameters("SHOW_RGB")->is_Enabled() && Parameters("SHOW_RGB")->asBool() )
	{
		CSG_Grid	*pR	= pBands->asGrid(Parameters("SHOW_R")->asInt());
		CSG_Grid	*pG	= pBands->asGrid(Parameters("SHOW_G")->asInt());
		CSG_Grid	*pB	= pBands->asGrid(Parameters("SHOW_B")->asInt());

		if( pR && pG && pB )
		{
			DataObject_Set_Parameter(pR, "COLORS_TYPE" , 5);	// _TL("RGB Overlay")	// CLASSIFY_OVERLAY
			DataObject_Set_Parameter(pR, "OVERLAY_MODE", 0);	// _TL("red=this, green=1, blue=2")
			DataObject_Set_Parameter(pR, "OVERLAY_G"   , pG);
			DataObject_Set_Parameter(pR, "OVERLAY_B"   , pB);

			DataObject_Update(pR, true);
		}
	}

	//-----------------------------------------------------
	return( true );
}
예제 #24
0
//---------------------------------------------------------
bool CFlow_AreaUpslope_Interactive::On_Execute(void)
{
	if( m_Calculator.Initialise(
		Parameters("METHOD")	->asInt(),
		Parameters("ELEVATION")	->asGrid(),
		Parameters("SINKROUTE")	->asGrid(),
		Parameters("AREA")		->asGrid(),
		Parameters("CONVERGE")	->asDouble()	) )
	{
		DataObject_Set_Colors(Parameters("AREA")->asGrid(), 100, SG_COLORS_WHITE_BLUE);

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
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 );
}
예제 #26
0
//---------------------------------------------------------
bool CGrid_Color_Rotate::On_Execute(void)
{
	bool	bDown;
	int		i;
	long	c;
	CSG_Grid	*pGrid;
	CSG_Colors	*pColors;

	pGrid	= Parameters("GRID")->asGrid();
	pColors	= Parameters("COLORS")->asColors();
	bDown	= Parameters("DIR")->asBool();

	if( pColors->Get_Count() > 1 )
	{
		do
		{
			if( bDown )
			{
				for(i=0, c=pColors->Get_Color(0); i<pColors->Get_Count() - 1; i++)
				{
					pColors->Set_Color(i, pColors->Get_Color(i + 1));
				}

				pColors->Set_Color(pColors->Get_Count() - 1, c);
			}
			else
			{
				for(i=pColors->Get_Count()-1, c=pColors->Get_Color(pColors->Get_Count()-1); i>0; i--)
				{
					pColors->Set_Color(i, pColors->Get_Color(i - 1));
				}

				pColors->Set_Color(0, c);
			}

			DataObject_Set_Colors(pGrid, *pColors);
			DataObject_Update(pGrid, true);
		}
		while( Process_Get_Okay(true) );

		return( true );
	}

	return( false );
}
예제 #27
0
//---------------------------------------------------------
bool CFlow_AreaUpslope_Area::On_Execute(void)
{
	bool	bResult	= false;

	//-----------------------------------------------------
	if( m_Calculator.Initialise(
		Parameters("METHOD")	->asInt(),
		Parameters("ELEVATION")	->asGrid(),
		Parameters("SINKROUTE")	->asGrid(),
		Parameters("AREA")		->asGrid(),
		Parameters("CONVERGE")	->asDouble()	) )
	{
		if( m_Calculator.Clr_Target() )
		{
			int		x, y;
			CSG_Grid	*pTarget	= Parameters("TARGET")->asGrid();

			for(y=0; y<Get_NY() && Set_Progress(y); y++)
			{
				for(x=0; x<Get_NX(); x++)
				{
					if( !pTarget->is_NoData(x, y) && m_Calculator.Add_Target(x, y) )
					{
						bResult	= true;
					}
				}
			}

			if( bResult )
			{
				m_Calculator.Get_Area();

				DataObject_Set_Colors(Parameters("AREA")->asGrid(), 100, SG_COLORS_WHITE_BLUE);
			}
		}
	}

	//-----------------------------------------------------
	m_Calculator.Finalise();

	return( bResult );
}
예제 #28
0
//---------------------------------------------------------
bool CConvergence::On_Execute(void)
{
    pDTM			= Parameters("ELEVATION")	->asGrid();
    pConvergence	= Parameters("RESULT")		->asGrid();

    pConvergence->Assign_NoData();

    DataObject_Set_Colors(pConvergence, 100, SG_COLORS_RED_GREY_BLUE, true);

    switch( Parameters("METHOD")->asInt() )
    {
    case 0:
        Do_Aspect();
        break;
    case 1:
        Do_Gradient();
        break;
    }

    return( true );
}
예제 #29
0
//---------------------------------------------------------
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 CGrid_RGB_Composite::On_Execute(void)
{
	double		rMin, rRange, gMin, gRange, bMin, bRange, aMin, aRange;

	//-----------------------------------------------------
	CSG_Grid	*pR	= _Get_Grid(Parameters("R_GRID")->asGrid(), Parameters("R_METHOD")->asInt(), Parameters("R_RANGE")->asRange(), Parameters("R_PERCTL")->asRange(), Parameters("R_STDDEV")->asDouble(), rMin, rRange);
	CSG_Grid	*pG	= _Get_Grid(Parameters("G_GRID")->asGrid(), Parameters("G_METHOD")->asInt(), Parameters("G_RANGE")->asRange(), Parameters("G_PERCTL")->asRange(), Parameters("G_STDDEV")->asDouble(), gMin, gRange);
	CSG_Grid	*pB	= _Get_Grid(Parameters("B_GRID")->asGrid(), Parameters("B_METHOD")->asInt(), Parameters("B_RANGE")->asRange(), Parameters("B_PERCTL")->asRange(), Parameters("B_STDDEV")->asDouble(), bMin, bRange);
	CSG_Grid	*pA	= _Get_Grid(Parameters("A_GRID")->asGrid(), Parameters("A_METHOD")->asInt(), Parameters("A_RANGE")->asRange(), Parameters("A_PERCTL")->asRange(), Parameters("A_STDDEV")->asDouble(), aMin, aRange);

	//-----------------------------------------------------
	CSG_Grid	*pRGB	= Parameters("RGB")->asGrid();

	pRGB->Create(pRGB->Get_System(), SG_DATATYPE_Int);
	pRGB->Set_Name(_TL("Composite"));

	CSG_String	s;

	s	+= CSG_String(_TL("Red"  )) + ": " + pR->Get_Name() + "\n";
	s	+= CSG_String(_TL("Green")) + ": " + pG->Get_Name() + "\n";
	s	+= CSG_String(_TL("Blue" )) + ": " + pB->Get_Name() + "\n";

	if( pA )
	{
		s	+= CSG_String(_TL("Alpha")) + ": " + pA->Get_Name() + "\n";
	}

	pRGB->Set_Description(s);

	DataObject_Set_Colors   (pRGB, 100, SG_COLORS_BLACK_WHITE);
	DataObject_Set_Parameter(pRGB, "COLORS_TYPE", 5);	// Color Classification Type: RGB Coded Values

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		#pragma omp parallel for
		for(int x=0; x<Get_NX(); x++)
		{
			if( pR->is_NoData(x, y) || pG->is_NoData(x, y) || pB->is_NoData(x, y) || (pA && pA->is_NoData(x, y)) )
			{
				pRGB->Set_NoData(x, y);
			}
			else
			{
				int	r	= (int)(rRange * (pR->asDouble(x, y) - rMin)); if( r > 255 ) r = 255; else if( r < 0 ) r = 0;
				int	g	= (int)(gRange * (pG->asDouble(x, y) - gMin)); if( g > 255 ) g = 255; else if( g < 0 ) g = 0;
				int	b	= (int)(bRange * (pB->asDouble(x, y) - bMin)); if( b > 255 ) b = 255; else if( b < 0 ) b = 0;

				if( pA )
				{
					int	a	= (int)(aRange * (pA->asDouble(x, y) - aMin)); if( a > 255 ) a = 255; else if( a < 0 ) a = 0;

					pRGB->Set_Value(x, y, SG_GET_RGBA(r, g, b, a));
				}
				else
				{
					pRGB->Set_Value(x, y, SG_GET_RGB (r, g, b));
				}
			}
		}
	}

	return( true );
}