Пример #1
0
//---------------------------------------------------------
bool CFilter_Multi_Dir_Lee::Get_Filter_Ringeler(void)
{
	int			x, y, ix, iy, k, kx, ky, Count, Best_Direction;
	double		Mean, StdDev, Variance, Best_Mean, Best_StdDev, Noise, Noise2;

	Noise	= Parameters("NOISE_ABS")->asDouble();
	Noise2	= Noise*Noise;

	//-----------------------------------------------------
	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( m_pInput->is_NoData(x, y) )
			{
				m_pFiltered->Set_NoData(x, y);

				if( m_pDirection )	m_pDirection	->Set_NoData(x, y);
				if( m_pStdDev )		m_pStdDev		->Set_NoData(x, y);
			}
			else
			{
				//-----------------------------------------
				for(k=0; k<16; k++)
				{
					Variance	= Mean	= Count	= 0;

					for(ky=0, iy=y-4; ky<9; iy++, ky++)
					{
						for(kx=0, ix=x-4; kx<9; ix++, kx++)
						{
							if( m_pInput->is_InGrid(ix, iy) && Filter_Directions[k][ky][kx] > 0.0 )
							{
								Mean		+= m_pInput->asDouble(ix, iy);
								Count		++;
							}
						}
					}

					Mean		= Mean     / Count;

					for(ky=0, iy=y-4; ky<9; iy++, ky++)
					{
						for(kx=0, ix=x-4; kx<9; ix++, kx++)
						{
							if( m_pInput->is_InGrid(ix, iy) && Filter_Directions[k][ky][kx] > 0.0 )
							{
								Variance	+= M_SQR(Mean - m_pInput->asDouble(ix, iy));
							}
						}
					}

					StdDev		= corr_norm * sqrt(Variance) / (corr[k] * Count);

					if( k == 0 || StdDev < Best_StdDev )
					{
						Best_StdDev		= StdDev;
						Best_Mean		= Mean;
						Best_Direction	= k;
					}
				}

				//-----------------------------------------
				if( Best_StdDev > Noise )
				{
					double	b	= Best_StdDev*Best_StdDev;

					b	= (b - Noise2) / b;

					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y) * b + (1.0 - b) * Best_Mean);
				}
				else if( Best_StdDev > 0.0 )
				{
					m_pFiltered->Set_Value(x, y, Best_Mean);
				}
				else
				{
					m_pFiltered->Set_Value(x, y, m_pInput->asDouble(x, y));
				}

				if( m_pDirection )	m_pDirection	->Set_Value(x, y, Best_Direction);
				if( m_pStdDev )		m_pStdDev		->Set_Value(x, y, Best_StdDev);
			}
		}
	}

	return( true );
}
Пример #2
0
/**
* WGS-84 gravity model
*
* @param  {struct} geodetic location
* @return {struct} gravity vector at location
**/
void F_GRAVITY_MODEL(struct grav_inputs_def *pIn, struct grav_outputs_def *pOut) {
	// locals
	double _Recef,				// distance to ECEF
		   _geoLat,				// geocentric latitude
		   _geoLatSin,			// sine of geocentric latitude
		   N,					// parameter in gravity model
		   sinLat, cosLat,		// latitude trigonometric functions
	       _ECEF[3],			// position in ECEF
		   _LLH[3];				// position in geodetic coordinates

	// housekeeping
	sinLat = sin(pIn->latitude);
	cosLat = cos(pIn->latitude);

	// geodesic coordinate system [rad, m], longitude is of no importance
	_LLH[_LAT] = pIn->latitude;
	_LLH[_LON] = 0.0;
	_LLH[_ALT] = pIn->altitude * C_FOOT_TO_METER;

	// calculate the position in ECEF coordinates
	F_GEODETIC_TO_ECEF(_LLH, _ECEF);

	// calculate distance from earth center [m]
	_Recef = sqrt(_ECEF[_X] * _ECEF[_X] + _ECEF[_Y] * _ECEF[_Y] + _ECEF[_Z] * _ECEF[_Z]);

	// calculate the geocentric latitude [rad]
	_geoLat    = asin(_ECEF[_Z] / _Recef);
	_geoLatSin = sin(_geoLat);

	// gravity model parameters
	N = C_WGS84_MAJOR / sqrt(1.0 - C_WGS84_ECENT_SQR * sinLat * sinLat);

	// calculate Gravitation vector in earth coordinate system
	pOut->G[_X]  = C_WGS84_MAJOR;
	pOut->G[_X] /= _Recef;
	pOut->G[_X] *= -pOut->G[_X];
	pOut->G[_X] *= 3.0;
	pOut->G[_X] *= C_J2;
	pOut->G[_X] *= _geoLatSin;
	pOut->G[_X] *= cos(_geoLat);
	pOut->G[_X] *= C_GM / M_SQR(_Recef);

	pOut->G[_Y] = 0.0;

	pOut->G[_Y]  = C_WGS84_MAJOR;
	pOut->G[_Y] /= _Recef;
	pOut->G[_Y] *= -pOut->G[_Y];
	pOut->G[_Y] *= C_J2;
	pOut->G[_Y] *= 3.0 * M_SQR(_geoLatSin) - 1.0;
	pOut->G[_Y] *= -1.5;
	pOut->G[_Y] += 1.0;
	pOut->G[_Y] *= C_GM / M_SQR(_Recef);

	// calculate gravity vector in earth coordinate system (g[_Y] used as a temporary holder at the beginning)
	pOut->g[_Y]  = pIn->altitude;
	pOut->g[_Y] *= C_FOOT_TO_METER;
	pOut->g[_Y] += N;
	pOut->g[_Y] *= cosLat;
	pOut->g[_Y] *= C_EARTH_SPIN;
	pOut->g[_Y] *= -C_EARTH_SPIN;

	pOut->g[_X]  = pOut->g[_Y];
	pOut->g[_X] *= sinLat;
	pOut->g[_X] += pOut->G[_X];

	pOut->g[_Z]  = pOut->g[_Y];
	pOut->g[_Z] *= cosLat;
	pOut->g[_Z] += pOut->G[_Z];

	pOut->g[_Y] = 0.0;

	// [m / sec / sec] to [ft / sec / sec]
	pOut->G[_X] *= C_METER_TO_FOOT;
	pOut->G[_Y] *= C_METER_TO_FOOT;
	pOut->G[_Z] *= C_METER_TO_FOOT;
	pOut->g[_X] *= C_METER_TO_FOOT;
	pOut->g[_Y] *= C_METER_TO_FOOT;
	pOut->g[_Z] *= C_METER_TO_FOOT;
}
Пример #3
0
//---------------------------------------------------------
bool CChange_Detection::On_Execute(void)
{
	bool		bNoChange;
	int			iInitial, iFinal;
	CSG_Matrix	Identity;
	CSG_Table	Initial, Final, *pChanges;
	CSG_Grid	*pInitial, *pFinal, *pChange;

	//-----------------------------------------------------
	pInitial	= Parameters("INITIAL")	->asGrid();
	pFinal		= Parameters("FINAL")	->asGrid();
	pChange		= Parameters("CHANGE")	->asGrid();
	pChanges	= Parameters("CHANGES")	->asTable();
	bNoChange	= Parameters("NOCHANGE")->asBool();

	if( !Get_Classes(Initial, pInitial, true) )
	{
		Error_Set(_TL("no class definitions for initial state"));

		return( false );
	}

	if( !Get_Classes(Final, pFinal, false) )
	{
		Error_Set(_TL("no class definitions for final state"));

		return( false );
	}

	if( !Get_Changes(Initial, Final, pChanges, Identity) )
	{
		return( false );
	}

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			iInitial	= Get_Class(Initial, pInitial->asDouble(x, y));
			iFinal		= Get_Class(Final  , pFinal  ->asDouble(x, y));

			if( bNoChange || !Identity[iInitial][iFinal] )
			{
				pChanges->Get_Record(iInitial)->Add_Value(1 + iFinal, 1);

				pChange->Set_Value(x, y, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal);
			}
			else
			{
				pChange->Set_Value(x, y, -1);
			}
		}
	}

	//-----------------------------------------------------
	CSG_Parameters	P;

	if( DataObject_Get_Parameters(pChange, P) && P("COLORS_TYPE") && P("LUT") )
	{
		CSG_Table	*pLUT	= P("LUT")->asTable();

		CSG_Colors	cRandom(pChanges->Get_Count());

		cRandom.Random();

		pLUT->Del_Records();

		for(iInitial=0; iInitial<pChanges->Get_Count(); iInitial++)
		{
			CSG_Colors	cRamp(pChanges->Get_Field_Count() - 1);

			cRamp.Set_Ramp(cRandom[iInitial], cRandom[iInitial]);
			cRamp.Set_Ramp_Brighness(225, 50);

			for(iFinal=0; iFinal<pChanges->Get_Field_Count()-1; iFinal++)
			{
				if( pChanges->Get_Record(iInitial)->asInt(1 + iFinal) > 0 )
				{
					CSG_Table_Record	*pClass	= pLUT->Add_Record();

					pClass->Set_Value(0, cRamp.Get_Color(iFinal));
					pClass->Set_Value(1, CSG_String::Format(SG_T("%s >> %s"), pChanges->Get_Record(iInitial)->asString(0), pChanges->Get_Field_Name(1 + iFinal)));
					pClass->Set_Value(3, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal);
					pClass->Set_Value(4, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal);
				}
			}
		}

		P("COLORS_TYPE")->Set_Value(1);	// Color Classification Type: Lookup Table

		DataObject_Set_Parameters(pChange, P);
	}

	//-----------------------------------------------------
	double	Factor;

	switch( Parameters("OUTPUT")->asInt() )
	{
	default:	Factor	= 1.0;						break;	// cells
	case 1:		Factor	= 100.0 / Get_NCells();		break;	// percent
	case 2:		Factor	= M_SQR(Get_Cellsize());	break;	// area
	}

	if( Factor != 1.0 )
	{
		for(iInitial=0; iInitial<pChanges->Get_Count(); iInitial++)
		{
			for(iFinal=0; iFinal<pChanges->Get_Field_Count()-1; iFinal++)
			{
				pChanges->Get_Record(iInitial)->Mul_Value(1 + iFinal, Factor);
			}
		}
	}

	//-----------------------------------------------------
	pChanges	->Set_Name(CSG_String::Format(SG_T("%s [%s >> %s]"), _TL("Changes"), pInitial->Get_Name(), pFinal->Get_Name()));

	pChange		->Set_Name(CSG_String::Format(SG_T("%s [%s >> %s]"), _TL("Changes"), pInitial->Get_Name(), pFinal->Get_Name()));
	pChange		->Set_NoData_Value(-1);

	return( true );
}