Exemplo n.º 1
0
// **************************************************************************
// Member function: Set_Hr_Matrix()
// COMMENT: Set Hr Rotation Matrix(3 by 3)
//          X-Y-Z fixed angle, R_XYZ
//          All rotation occur about axes of reference(WORLD) frame
// INPUT: rotation anlge about WORLD coordinates axes
// **************************************************************************
void MatrixMy::Set_Hr_Matrix(double roll, double elevation, double azimuth)

{
  if ( (row == 3) &&
       (column == 3) ) {

    double cz = cos(azimuth);
    double sz = sin(azimuth);
    double cy = cos(elevation);
    double sy = sin(elevation);
    double cx = cos(roll);
    double sx = sin(roll);

    Set_Value(0, 0) = (cz*cy);
    Set_Value(1, 0) = (sz*cy);
    Set_Value(2, 0) = (-sy);
    
    Set_Value(0, 1) = (cz*sy*sx - sz*cx);
    Set_Value(1, 1) = (sz*sy*sx + cz*cx);
    Set_Value(2, 1) = (cy * sx);
    
    Set_Value(0, 2) = (cz*sy*cx + sz*sx);
    Set_Value(1, 2) = (sz*sy*cx - cz*sx);
    Set_Value(2, 2) = (cy*cx);
  }
  else {
    printf("ERROR: Matrix Dimension Not Match(set Hr matrix)\n");
  }
} // End of Set_Hr_Matrix()
Exemplo n.º 2
0
// **************************************************************************
// Member function
// COMMENT: Set Jacobian Matrix(3 by 3)
// **************************************************************************
void MatrixMy::Set_J_Matrix(double theta0,
                            double theta1,
                            double theta2,
                            double theta3)
{
  if ( (row == 3) &&
       (column == 3) ) {

    double c2, s2;
    double c01, s01, c23, s23;

    c2 = cos(theta2);  s2 = sin(theta2);
    c01 = cos(theta0 + theta1);  s01 = sin(theta0 + theta1);
    c23 = cos(theta2 + theta3);  s23 = sin(theta2 + theta3);
    
    Set_Value(0, 0) = -s01*(LINK1 + LINK2*c2 + LINK3*c23);
    Set_Value(1, 0) =  c01*(LINK1 + LINK2*c2 + LINK3*c23);
    Set_Value(2, 0) =  0.0;

    Set_Value(0, 1) = -c01*(LINK2*s2 + LINK3*s23);
    Set_Value(1, 1) = -s01*(LINK2*s2 + LINK3*s23); 
    Set_Value(2, 1) = -    (LINK2*c2 + LINK3*c23);
    
    Set_Value(0, 2) = -LINK3*c01*s23;
    Set_Value(1, 2) = -LINK3*s01*s23;
    Set_Value(2, 2) = -LINK3*c23;
  }
  else {
    printf("ERROR: Matrix Dimension Not Match(set J matrix)\n");
  }
}
Exemplo n.º 3
0
// **************************************************************************
// Member function: Set_Vector3x1()
// COMMENT: Set 3 by 1 vector
// **************************************************************************
void MatrixMy::Set_Vector3x1(double x, double y, double z)
{
  if ( (row == 3) &&
       (column == 1) ) {
    Set_Value(0, 0) = x;
    Set_Value(1, 0) = y;
    Set_Value(2, 0) = z;
  }
  else {
    printf("ERROR: Matrix Dimension Not Match(set vector)\n");
    exit(1);
  }
}
Exemplo n.º 4
0
//---------------------------------------------------------
void CGaussian_Landscapes::Set_Values(int x_0, int y_0, int x_1, int y_1, double z_00, double z_10, double z_11, double z_01, double s, double r)
{
	int		x_n, y_n;
	double	z_n, z_n1, z_n2, z_n3, z_n4;

	//-----------------------------------------------------
	x_n		= (x_0 + x_1) / 2;
	y_n		= (y_0 + y_1) / 2;
	z_n		= (z_00 + z_10 + z_11 + z_01) / 4.0 + s * (double)(RANDOM(17) - 8) / 8.0;

	Set_Value(x_n, y_n, z_n);

	//-----------------------------------------------------
	if( x_0 != x_n && x_n != x_1 )
	{
		z_n1	= (z_00 + z_10) / 2.0;
		z_n2	= (z_10 + z_11) / 2.0;
		z_n3	= (z_11 + z_01) / 2.0;
		z_n4	= (z_01 + z_00) / 2.0;

		s		*= r;

		Set_Values(x_n, y_0, x_1, y_n, z_n1, z_10, z_n2, z_n , s, r);
		Set_Values(x_0, y_0, x_n, y_n, z_00, z_n1, z_n , z_n4, s, r);
		Set_Values(x_n, y_n, x_1, y_1, z_n , z_n2, z_11, z_n3, s, r);
		Set_Values(x_0, y_n, x_n, y_1, z_n4, z_n , z_n3, z_01, s, r);
	}
}
Exemplo n.º 5
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 );
}
Exemplo n.º 6
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 );
}
Exemplo n.º 7
0
//---------------------------------------------------------
void CShapes2Grid::Set_Polygon_Cell(CSG_Shape_Polygon *pPolygon)
{
	//-----------------------------------------------------
	CSG_Grid_System	s(m_pGrid->Get_System());

	int	xA	= s.Get_xWorld_to_Grid(pPolygon->Get_Extent().Get_XMin());	if( xA <  0          )	xA	= 0;
	int	xB	= s.Get_xWorld_to_Grid(pPolygon->Get_Extent().Get_XMax());	if( xB >= s.Get_NX() )	xB	= s.Get_NX() - 1;
	int	yA	= s.Get_yWorld_to_Grid(pPolygon->Get_Extent().Get_YMin());	if( yA <  0          )	yA	= 0;
	int	yB	= s.Get_yWorld_to_Grid(pPolygon->Get_Extent().Get_YMax());	if( yB >= s.Get_NY() )	yB	= s.Get_NY() - 1;

	//-----------------------------------------------------
	TSG_Rect	r;

	r.yMax	= s.Get_yGrid_to_World(yA) - 0.5 * s.Get_Cellsize();

	for(int y=yA; y<=yB; y++)
	{
		r.yMin	= r.yMax;	r.yMax	+= s.Get_Cellsize();

		r.xMax	= s.Get_xGrid_to_World(xA) - 0.5 * s.Get_Cellsize();

		for(int x=xA; x<=xB; x++)
		{
			r.xMin	= r.xMax;	r.xMax	+= s.Get_Cellsize();

			if( pPolygon->Intersects(r) )
			{
				Set_Value(x, y);
			}
		}
	}
}
Exemplo n.º 8
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"));
	}
}
Exemplo n.º 9
0
//---------------------------------------------------------
bool CFlow_AreaUpslope::Get_Area(void)
{
	int		i, x, y;

	if( m_pDTM && m_pFlow )
	{
		for(i=0; i<m_pDTM->Get_NCells() && SG_UI_Process_Set_Progress(i, m_pDTM->Get_NCells()); i++)
		{
			m_pDTM->Get_Sorted(i, x, y, false, false);

			if( m_pFlow->asDouble(x, y) > 0.0 )
			{
				break;
			}
		}

		for(i++; i<m_pDTM->Get_NCells() && SG_UI_Process_Set_Progress(i, m_pDTM->Get_NCells()); i++)
		{
			m_pDTM->Get_Sorted(i, x, y, false, false);

			Set_Value(x, y);
		}

		return( true );
	}

	return( false );
}
Exemplo n.º 10
0
//---------------------------------------------------------
void CShapes2Grid::Set_Line_A(TSG_Point a, TSG_Point b)
{
	double			ix, iy, sig;
	double			dx, dy;
	TSG_Point_Int	A, B;

	A.x	= (int)(a.x	+= 0.5);
	A.y	= (int)(a.y	+= 0.5);
	B.x	= (int)(b.x	+= 0.5);
	B.y	= (int)(b.y	+= 0.5);

	//-----------------------------------------------------
	if( A.x != B.x || A.y != B.y )
	{
		dx	= b.x - a.x;
		dy	= b.y - a.y;

		if( fabs(dx) > fabs(dy) )
		{
			sig	= dx < 0 ? -1 : 1;
			dx	= fabs(dx);
			dy	/= dx;

			for(ix=0; ix<=dx; ix++, a.x+=sig, a.y+=dy)
			{
				Set_Value((int)a.x, (int)a.y);
			}
		}
		else if( fabs(dy) >= fabs(dx) && dy != 0 )
		{
			sig	= dy < 0 ? -1 : 1;
			dy	= fabs(dy);
			dx	/= dy;

			for(iy=0; iy<=dy; iy++, a.x+=dx, a.y+=sig)
			{
				Set_Value((int)a.x, (int)a.y);
			}
		}
	}
	else
	{
		Set_Value(A.x, A.y);
	}
}
Exemplo n.º 11
0
//---------------------------------------------------------
void CSG_Grid::Normalise(void)
{
	if( is_Valid() )
	{
		Update();

		if( m_zStats.Get_StdDev() > 0.0 )
		{
			int		x, y;

			if(	(Get_NoData_hiValue() > -NORMALISED_NODATA && Get_NoData_hiValue() < NORMALISED_NODATA)
			||	(Get_NoData_Value  () > -NORMALISED_NODATA && Get_NoData_Value  () < NORMALISED_NODATA) )
			{
				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, -NORMALISED_NODATA);
						}
					}
				}

				Set_NoData_Value(-NORMALISED_NODATA);
			}

			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, (asDouble(x, y) - m_zStats.Get_Mean()) / m_zStats.Get_StdDev() );
					}
				}
			}

			SG_UI_Process_Set_Ready();

			Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Normalisation"));
		}
	}
}
Exemplo n.º 12
0
//---------------------------------------------------------
inline void CGrid_Merge::Set_Value(int x, int y, CSG_Grid *pGrid, double px, double py)
{
	double	z;

	if( pGrid->Get_Value(px, py, z, m_Resampling) )
	{
		if( m_Weight.is_Valid() )
		{
			double	w;

			if( m_Weight.Get_Value(px, py, w, GRID_RESAMPLING_BSpline, true) )
			{
				Set_Value(x, y, z, w);
			}
		}
		else
		{
			Set_Value(x, y, z, 1.0);
		}
	}
}
Exemplo n.º 13
0
//---------------------------------------------------------
inline void CGrid_Merge::Set_Value(int x, int y, CSG_Grid *pGrid, double px, double py)
{
	double	z;

	if( pGrid->Get_Value(px, py, z, m_Interpolation) )
	{
		if( m_Weight.is_Valid() )
		{
			double	w;

			if( m_Weight.Get_Value(px, py, w, GRID_INTERPOLATION_BSpline, true) )
			{
				Set_Value(x, y, z, w);
			}
		}
		else
		{
			Set_Value(x, y, z, 1.0);
		}
	}
}
Exemplo n.º 14
0
//---------------------------------------------------------
void CSG_Grid::Mirror(void)
{
	int		xA, xB, y;
	double	d;

	if( is_Valid() )
	{
		for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
		{
			for(xA=0, xB=Get_NX()-1; xA<xB; xA++, xB--)
			{
				d			=    asDouble(xA, y);
				Set_Value(xA, y, asDouble(xB, y));
				Set_Value(xB, y, d);
			}
		}

		SG_UI_Process_Set_Ready();

		Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Horizontally mirrored"));
	}
}
Exemplo n.º 15
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 );
}
Exemplo n.º 16
0
//---------------------------------------------------------
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"));
	}
}
Exemplo n.º 17
0
//---------------------------------------------------------
void CShapes2Grid::Set_Points(CSG_Shape *pShape)
{
	for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
	{
		for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
		{
			TSG_Point	p	= pShape->Get_Point(iPoint, iPart);

			Set_Value(
				(int)(0.5 + X_WORLD_TO_GRID(p.x)),
				(int)(0.5 + Y_WORLD_TO_GRID(p.y))
			);
		}
	}
}
//---------------------------------------------------------
bool CGridding_Spline_TPS_Local::On_Execute(void)
{
	int			x, y;
	TSG_Point	p;

	m_Regularisation	= Parameters("REGULARISATION")->asDouble();

	//-----------------------------------------------------
	if( m_Search.Do_Use_All(true) )	// global
	{
		if( !Initialise(m_Spline.Get_Points()) || !m_Spline.Create(m_Regularisation, false) )
		{
			return(false);
		}

		for(y=0, p.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, p.y+=m_pGrid->Get_Cellsize())
		{
			for(x=0, p.x=m_pGrid->Get_XMin(); x<m_pGrid->Get_NX(); x++, p.x+=m_pGrid->Get_Cellsize())
			{
				m_pGrid->Set_Value(x, y, m_Spline.Get_Value(p.x, p.y));
			}
		}
	}

	//-----------------------------------------------------
	else
	{
		if( !Initialise() || !m_Search.Initialize(Parameters("SHAPES")->asShapes(), Parameters("FIELD")->asInt()) )
		{
			return(false);
		}

		for(y=0, p.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++, p.y+=m_pGrid->Get_Cellsize())
		{
			for(x=0, p.x=m_pGrid->Get_XMin(); x<m_pGrid->Get_NX(); x++, p.x+=m_pGrid->Get_Cellsize())
			{
				Set_Value(x, y, p);
			}
		}

		m_Search.Finalize();
	}

	//-----------------------------------------------------
	m_Spline.Destroy();

	return( true );
}
Exemplo n.º 19
0
//---------------------------------------------------------
CSG_Shape * CSG_PointCloud::Add_Shape(CSG_Table_Record *pCopy, TSG_ADD_Shape_Copy_Mode mCopy)
{
    Add_Point(0.0, 0.0, 0.0);

    if( pCopy && (mCopy == SHAPE_COPY_ATTR || mCopy == SHAPE_COPY) )
    {
        for(int iField=0; iField<Get_Field_Count() && iField<pCopy->Get_Table()->Get_Field_Count(); iField++)
        {
            if( Get_Field_Type(iField) == pCopy->Get_Table()->Get_Field_Type(iField) )
            {
                Set_Value(iField, pCopy->asDouble(iField));
            }
        }
    }

    return( _Set_Shape(Get_Count() - 1) );
}
Exemplo n.º 20
0
Symbol * New_Symbol(char const * name)
{
	Symbol * symbol = (Symbol *)malloc(sizeof(Symbol));
	symbol->type = VOID;
	Set_Value(&symbol->value, symbol->type, NULL);
	symbol->params = -1;
	symbol->param_types = NULL;
	symbol->decl_line_num = 0;
	symbol->is_global = FALSE;
	symbol->stack_index = -1;

	symbol->next = NULL;

	if (name != NULL)
		symbol->name = strdup(name);
	else
		symbol->name = NULL;

	return symbol;
}
Exemplo n.º 21
0
//---------------------------------------------------------
bool CSG_Grid::_Load_ASCII(CSG_File &Stream, TSG_Grid_Memory_Type Memory_Type, bool bFlip)
{
	int		x, y, iy, dy;
	double	Value;

	if( Stream.is_Open() && m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined && _Memory_Create(Memory_Type) )
	{
		Set_File_Type(GRID_FILE_FORMAT_ASCII);

		if( bFlip )
		{
			y	= Get_NY() - 1;
			dy	= -1;
		}
		else
		{
			y	= 0;
			dy	= 1;
		}

		//-------------------------------------------------
		for(iy=0; iy<Get_NY() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy)
		{
			for(x=0; x<Get_NX(); x++)
			{
				SG_FILE_SCANF(Stream.Get_Stream(), SG_T("%lf"), &Value);

				Set_Value(x, y, Value);
			}
		}

		SG_UI_Process_Set_Ready();

		return( true );
	}

	return( false );
}
Exemplo n.º 22
0
//---------------------------------------------------------
void CSG_Grid::DeNormalise(double ArithMean, double Variance)
{
	int		x, y;

	if( is_Valid() )
	{
		Variance	= sqrt(Variance);

		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, Variance * asDouble(x, y) + ArithMean);
				}
			}
		}

		SG_UI_Process_Set_Ready();

		Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Denormalisation"));
	}
}
Exemplo n.º 23
0
void Set_Real(Value *value, double val)
{
	Set_Value(value, REAL, VOID(val));
}
Exemplo n.º 24
0
void Set_Char(Value *value, char val)
{
    Set_Value(value, CHAR, VOID(val));
}
Exemplo n.º 25
0
void Set_Bool(Value *value, bool val)
{
    Set_Value(value, BOOLEAN, VOID(val));
}
Exemplo n.º 26
0
void Set_Int(Value *value, int val)
{
    Set_Value(value, INTEGER, VOID(val));
}
Exemplo n.º 27
0
//---------------------------------------------------------
bool CSG_Grid::_Assign_MeanValue(CSG_Grid *pGrid, bool bAreaProportional)
{
	if( Get_Cellsize() < pGrid->Get_Cellsize() || is_Intersecting(pGrid->Get_Extent()) == INTERSECTION_None )
	{
		return( false );
	}

	//-----------------------------------------------------
	int			x, y, ix, iy, jx, jy;
	double		px, py, ax, ay, d, w, wx, wy, 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();

	//-----------------------------------------------------
	if( bAreaProportional == false )
	{
		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() )
					{
						S[ix][iy]	+= pGrid->asDouble(x, y);
						N[ix][iy]	++;
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	else // if( bAreaProportional == true )
	{
		ax	= ((pGrid->Get_XMin() - 0.5 * pGrid->Get_Cellsize()) - (Get_XMin() - 0.5 * Get_Cellsize())) / Get_Cellsize();
		ay	= ((pGrid->Get_YMin() - 0.5 * pGrid->Get_Cellsize()) - (Get_YMin() - 0.5 * Get_Cellsize())) / Get_Cellsize();

		for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
		{
			if( py > -d || py < Get_NY() )
			{
				iy	= (int)floor(py);
				wy	= (py + d) - iy;
				wy	= wy < 1.0 ? 1.0 : wy - 1.0; 

				for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
				{
					if( !pGrid->is_NoData(x, y) && (px > -d && px < Get_NX()) )
					{
						ix	= (int)floor(px);
						wx	= (px + d) - ix;
						wx	= wx < 1.0 ? 1.0 : wx - 1.0; 

						z	= pGrid->asDouble(x, y);

						if( iy >= 0 && iy < Get_NY() )		// wy > 0.0 is always true
						{
							if( ix >= 0 && ix < Get_NX() )	// wx > 0.0 is always true
							{
								w	= wx * wy;
								S[ix][iy]	+= w * z;
								N[ix][iy]	+= w;
							}

							if( wx < 1.0 && (jx = ix + 1) >= 0 && jx < Get_NX() )
							{
								w	= (1.0 - wx) * wy;
								S[jx][iy]	+= w * z;
								N[jx][iy]	+= w;
							}
						}

						if( wy < 1.0 && (jy = iy + 1) >= 0 && jy < Get_NY() )
						{
							if( ix >= 0 && ix < Get_NX() )
							{
								w	= wx * (1.0 - wy);
								S[ix][jy]	+= w * z;
								N[ix][jy]	+= w;
							}

							if( wx < 1.0 && (jx = ix + 1) >= 0 && jx < Get_NX() )
							{
								w	= (1.0 - wx) * (1.0 - wy);
								S[jx][jy]	+= w * z;
								N[jx][jy]	+= w;
							}
						}
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( N[x][y] )
			{
				Set_Value(x, y, S[x][y] / N[x][y]);
			}
			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 );
}
Exemplo n.º 28
0
//---------------------------------------------------------
bool CGrid_Merge::On_Execute(void)
{
	//-----------------------------------------------------
	if( !Initialize() )
	{
		return( false );
	}

	//-----------------------------------------------------
	for(int i=0; i<m_pGrids->Get_Count(); i++)
	{
		CSG_Grid	*pGrid	= m_pGrids->asGrid(i);

		Set_Weight(pGrid);

		Get_Match(i > 0 ? pGrid : NULL);

		int	ax	= (int)((pGrid->Get_XMin() - m_pMosaic->Get_XMin()) / m_pMosaic->Get_Cellsize());
		int	ay	= (int)((pGrid->Get_YMin() - m_pMosaic->Get_YMin()) / m_pMosaic->Get_Cellsize());

		//-------------------------------------------------
		if(	is_Aligned(pGrid) )
		{
			Process_Set_Text(CSG_String::Format("[%d/%d] %s: %s", i + 1, m_pGrids->Get_Count(), _TL("copying"), pGrid->Get_Name()));

			int	nx	= pGrid->Get_NX(); if( nx > m_pMosaic->Get_NX() - ax )	nx	= m_pMosaic->Get_NX() - ax;
			int	ny	= pGrid->Get_NY(); if( ny > m_pMosaic->Get_NY() - ay )	ny	= m_pMosaic->Get_NY() - ay;

			for(int y=0; y<ny && Set_Progress(y, ny); y++)
			{
				if( ay + y >= 0 )
				{
					#pragma omp parallel for
					for(int x=0; x<nx; x++)
					{
						if( ax + x >= 0 && !pGrid->is_NoData(x, y) )
						{
							Set_Value(ax + x, ay + y, pGrid->asDouble(x, y), Get_Weight(x, y));
						}
					}
				}
			}
		}

		//-------------------------------------------------
		else
		{
			Process_Set_Text(CSG_String::Format("[%d/%d] %s: %s", i + 1, m_pGrids->Get_Count(), _TL("resampling"), pGrid->Get_Name()));

			if( ax < 0 )	ax	= 0;
			if( ay < 0 )	ay	= 0;

			int	nx	= 1 + m_pMosaic->Get_System().Get_xWorld_to_Grid(pGrid->Get_XMax()); if( nx > m_pMosaic->Get_NX() )	nx	= m_pMosaic->Get_NX();
			int	ny	= 1 + m_pMosaic->Get_System().Get_yWorld_to_Grid(pGrid->Get_YMax()); if( ny > m_pMosaic->Get_NY() )	ny	= m_pMosaic->Get_NY();

			for(int y=ay; y<ny && Set_Progress(y-ay, ny-ay); y++)
			{
				double	py	= m_pMosaic->Get_YMin() + y * m_pMosaic->Get_Cellsize();

				#pragma omp parallel for
				for(int x=ax; x<nx; x++)
				{
					double	px	= m_pMosaic->Get_XMin() + x * m_pMosaic->Get_Cellsize();

					Set_Value(x, y, pGrid, px, py);
				}
			}
		}
	}

	//-----------------------------------------------------
	if( m_Overlap == 4 )	// mean
	{
		for(int y=0; y<m_pMosaic->Get_NY() && Set_Progress(y, m_pMosaic->Get_NY()); y++)
		{
			#pragma omp parallel for
			for(int x=0; x<m_pMosaic->Get_NX(); x++)
			{
				double	w	= m_Weights.asDouble(x, y);

				if( w > 0.0 )
				{
					m_pMosaic->Mul_Value(x, y, 1.0 / w);
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Weight .Destroy();
	m_Weights.Destroy();

	return( true );
}
Exemplo n.º 29
0
//---------------------------------------------------------
void CShapes2Grid::Set_Line_B(TSG_Point a, TSG_Point b)
{
	int				ix, iy;
	double			e, d, dx, dy;
	TSG_Point_Int	A, B;

	A.x	= (int)(a.x	+= 0.5);
	A.y	= (int)(a.y	+= 0.5);
	B.x	= (int)(b.x	+= 0.5);
	B.y	= (int)(b.y	+= 0.5);

	Set_Value(A.x, A.y);

	//-----------------------------------------------------
	if( A.x != B.x || A.y != B.y )
	{
		dx	= b.x - a.x;
		dy	= b.y - a.y;

		a.x	= a.x > 0.0 ? a.x - (int)a.x : 1.0 + (a.x - (int)a.x);
		a.y	= a.y > 0.0 ? a.y - (int)a.y : 1.0 + (a.y - (int)a.y);

		//-------------------------------------------------
		if( fabs(dx) > fabs(dy) )
		{
			ix	= dx > 0.0 ? 1 : -1;
			iy	= dy > 0.0 ? 1 : -1;
			d	= fabs(dy / dx);
			dx	= ix < 0 ? a.x : 1.0 - a.x;
			e	= iy > 0 ? a.y : 1.0 - a.y;
			e	+= d * dx;

			while( e > 1.0 )
			{
				e	-= 1.0;
				A.y	+= iy;
				Set_Value(A.x, A.y);
			}

			while( A.x != B.x )
			{
				A.x	+= ix;
				e	+= d;
				Set_Value(A.x, A.y);

				if( A.x != B.x )
				{
					while( e > 1.0 )
					{
						e	-= 1.0;
						A.y	+= iy;
						Set_Value(A.x, A.y);
					}
				}
			}

			if( A.y != B.y )
			{
				iy	= A.y < B.y ? 1 : -1;

				while( A.y != B.y )
				{
					A.y	+= iy;
					Set_Value(A.x, A.y);
				}
			}
		}

		//-------------------------------------------------
		else // if( fabs(dy) > fabs(dx) )
		{
			ix	= dx > 0.0 ? 1 : -1;
			iy	= dy > 0.0 ? 1 : -1;
			d	= fabs(dx / dy);
			dy	= iy < 0 ? a.y : 1.0 - a.y;
			e	= ix > 0 ? a.x : 1.0 - a.x;
			e	+= d * dy;

			while( e > 1.0 )
			{
				e	-= 1.0;
				A.x	+= ix;
				Set_Value(A.x, A.y);
			}

			while( A.y != B.y )
			{
				A.y	+= iy;
				e	+= d;
				Set_Value(A.x, A.y);

				if( A.y != B.y )
				{
					while( e > 1.0 )
					{
						e	-= 1.0;
						A.x	+= ix;
						Set_Value(A.x, A.y);
					}
				}
			}

			if( A.x != B.x )
			{
				ix	= A.x < B.x ? 1 : -1;

				while( A.x != B.x )
				{
					A.x	+= ix;
					Set_Value(A.x, A.y);
				}
			}
		}
	}
}
Exemplo n.º 30
0
//---------------------------------------------------------
void CShapes2Grid::Set_Polygon(CSG_Shape *pShape)
{
	bool		bFill, *bCrossing;
	int			x, y, xStart, xStop;
	TSG_Point	A, B, a, b, c;
	CSG_Rect	Extent;

	//-----------------------------------------------------
	bCrossing	= (bool *)SG_Malloc(m_pGrid->Get_NX() * sizeof(bool));

	Extent		= pShape->Get_Extent();

	xStart		= (int)((Extent.m_rect.xMin - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize()) - 1;
	if( xStart < 0 )
		xStart	= 0;

	xStop		= (int)((Extent.m_rect.xMax - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize()) + 1;
	if( xStop >= m_pGrid->Get_NX() )
		xStop	= m_pGrid->Get_NX() - 1;

	A.x			= m_pGrid->Get_XMin() - 1.0;
	B.x			= m_pGrid->Get_XMax() + 1.0;

	//-----------------------------------------------------
	for(y=0, A.y=m_pGrid->Get_YMin(); y<m_pGrid->Get_NY(); y++, A.y+=m_pGrid->Get_Cellsize())
	{
		if( A.y >= Extent.m_rect.yMin && A.y <= Extent.m_rect.yMax )
		{
			B.y	= A.y;

			memset(bCrossing, 0, m_pGrid->Get_NX() * sizeof(bool));

			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
			{
				b	= pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart);

				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
				{
					a	= b;
					b	= pShape->Get_Point(iPoint, iPart);

					if(	((a.y <= A.y && A.y  < b.y)
					||	 (a.y  > A.y && A.y >= b.y)) )
					{
						SG_Get_Crossing(c, a, b, A, B, false);

						x	= (int)(1.0 + X_WORLD_TO_GRID(c.x));

						if( x < 0 )
						{
							x	= 0;
						}
						else if( x >= m_pGrid->Get_NX() )
						{
							x	= m_pGrid->Get_NX() - 1;
						}

						bCrossing[x]	= !bCrossing[x];
					}
				}
			}

			//---------------------------------------------
			for(x=xStart, bFill=false; x<=xStop; x++)
			{
				if( bCrossing[x] )
				{
					bFill	= !bFill;
				}

				if( bFill )
				{
					Set_Value(x, y);
				}
			}
		}
	}

	//-----------------------------------------------------
	SG_Free(bCrossing);
}