⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grid_3d_image.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

///////////////////////////////////////////////////////////
//                                                       //
//                         SAGA                          //
//                                                       //
//      System for Automated Geoscientific Analyses      //
//                                                       //
//                    Module Library:                    //
//                  Grid_Visualisation                   //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//                   Grid_3D_Image.cpp                   //
//                                                       //
//                 Copyright (C) 2005 by                 //
//                      Olaf Conrad                      //
//                                                       //
//-------------------------------------------------------//
//                                                       //
// This file is part of 'SAGA - System for Automated     //
// Geoscientific Analyses'. SAGA is free software; you   //
// can redistribute it and/or modify it under the terms  //
// of the GNU General Public License as published by the //
// Free Software Foundation; version 2 of the License.   //
//                                                       //
// SAGA is distributed in the hope that it will be       //
// useful, but WITHOUT ANY WARRANTY; without even the    //
// implied warranty of MERCHANTABILITY or FITNESS FOR A  //
// PARTICULAR PURPOSE. See the GNU General Public        //
// License for more details.                             //
//                                                       //
// You should have received a copy of the GNU General    //
// Public License along with this program; if not,       //
// write to the Free Software Foundation, Inc.,          //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307,   //
// USA.                                                  //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//    e-mail:     oconrad@saga-gis.org                   //
//                                                       //
//    contact:    Olaf Conrad                            //
//                Institute of Geography                 //
//                University of Goettingen               //
//                Goldschmidtstr. 5                      //
//                37077 Goettingen                       //
//                Germany                                //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#include "Grid_3D_Image.h"


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CGrid_3D_Image::CGrid_3D_Image(void)
{
	Set_Name(_TL("Create 3D Image"));

	Set_Author(_TL("Copyrights (c) 2005 by Olaf Conrad"));

	Set_Description(
		_TL("")
	);

	//-----------------------------------------------------
	Parameters.Add_Grid(
		NULL	, "DEM"				, _TL("Elevation"),
		_TL(""),
		PARAMETER_INPUT
	);

	Parameters.Add_Grid(
		NULL	, "IMAGE"			, _TL("Overlay Image"),
		_TL(""),
		PARAMETER_INPUT
	);

	Parameters.Add_Shapes_List(
		NULL	, "SHAPES"			, _TL("Shapes to project"),
		_TL(""),
		PARAMETER_INPUT_OPTIONAL
	);


	//-----------------------------------------------------
	Parameters.Add_Value(
		NULL	, "ZEXAGG"			, _TL("Exaggeration"),
		_TL(""),
		PARAMETER_TYPE_Double, 1.0
	);

	Parameters.Add_Value(
		NULL	, "ZEXAGG_MIN"		, _TL("Minimum Exaggeration [%]"),
		_TL(""),
		PARAMETER_TYPE_Double, 10.0, 0.0, true, 100.0, true
	);

	Parameters.Add_Value(
		NULL	, "Z_ROTATE"		, _TL("Image Rotation [Degree]"),
		_TL(""),
		PARAMETER_TYPE_Double, 0.0
	);

	Parameters.Add_Value(
		NULL	, "X_ROTATE"		, _TL("Local Rotation [Degree]"),
		_TL(""),
		PARAMETER_TYPE_Double, 1.0
	);

	Parameters.Add_Choice(
		NULL	, "X_ROTATE_LEVEL"	, _TL("Local Rotation Base Level"),
		_TL(""),

		CSG_String::Format(SG_T("%s|%s|"),
			_TL("Zero"),
			_TL("Mean Elevation")
		), 1
	);

	Parameters.Add_Value(
		NULL	, "PANBREAK"		, _TL("Panorama Break [%]"),
		_TL(""),
		PARAMETER_TYPE_Double, 70.0, 0.0, true, 100.0, true
	);

	Parameters.Add_Value(
		NULL	, "BKCOLOR"			, _TL("Background Color"),
		_TL(""),
		PARAMETER_TYPE_Color, SG_COLOR_BLACK
	);


	//-----------------------------------------------------
	Parameters.Add_Choice(
		NULL	, "PROJECTION"		, _TL("Projection"),
		_TL(""),

		CSG_String::Format(SG_T("%s|%s|"),
			_TL("Panorama"),
			_TL("Circular")
		), 0
	);


	//-----------------------------------------------------
	Parameters.Add_Value(
		NULL	, "NX"				, _TL("3D Image Width"),
		_TL(""),
		PARAMETER_TYPE_Int, 100, 1, true
	);

	Parameters.Add_Value(
		NULL	, "NY"				, _TL("3D Image Height"),
		_TL(""),
		PARAMETER_TYPE_Int, 100, 1, true
	);

	Parameters.Add_Grid(
		NULL	, "RGB"				, _TL("3D Image"),
		_TL(""),
//		PARAMETER_OUTPUT_OPTIONAL, false, GRID_TYPE_Int
		PARAMETER_OUTPUT_OPTIONAL, true, GRID_TYPE_Int
	);

	Parameters.Add_Grid(
		NULL	, "RGB_Z"			, _TL("Projected Height"),
		_TL(""),
//		PARAMETER_OUTPUT_OPTIONAL, false, GRID_TYPE_Float
		PARAMETER_OUTPUT_OPTIONAL, true, GRID_TYPE_Float
	);
}

//---------------------------------------------------------
CGrid_3D_Image::~CGrid_3D_Image(void)
{}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
bool CGrid_3D_Image::On_Execute(void)
{
	//-----------------------------------------------------
	m_pDEM			= Parameters("DEM")				->asGrid();
	m_pImage		= Parameters("IMAGE")			->asGrid();

	m_Projection	= Parameters("PROJECTION")		->asInt();

	m_ZExagg		= Parameters("ZEXAGG")			->asDouble();
	m_ZExagg_Min	= Parameters("ZEXAGG_MIN")		->asDouble() / 100.0;
	m_ZMean			= Parameters("X_ROTATE_LEVEL")	->asInt() == 0 ? 0.0 : m_pDEM->Get_ZMin() + m_pDEM->Get_ZRange() / 2.0;
	m_XRotate		= Parameters("X_ROTATE")		->asDouble() * M_DEG_TO_RAD;
	m_ZRotate		= Parameters("Z_ROTATE")		->asDouble() * M_DEG_TO_RAD;

	m_PanoramaBreak	= Parameters("PANBREAK")		->asDouble() / 100.0;

	//-----------------------------------------------------
	m_pRGB			= Parameters("RGB")				->asGrid();
	m_pRGB_Z		= Parameters("RGB_Z")			->asGrid();

	if( !m_pRGB )
	{
		int		nx, ny;

		nx			= Parameters("NX")->asInt();
		ny			= Parameters("NY")->asInt();

		m_pRGB		= SG_Create_Grid(GRID_TYPE_Int		, nx, ny, 1.0);
	}

	if( !m_pRGB_Z || !m_pRGB_Z->is_Compatible(m_pRGB->Get_System()) )
	{
		m_pRGB_Z	= SG_Create_Grid(m_pRGB, GRID_TYPE_Float);
	}

	m_pRGB			->Set_Name(_TL("3D Image"));
	m_pRGB			->Assign(Parameters("BKCOLOR")->asDouble());

	m_pRGB_Z		->Set_Name(_TL("3D Image Height"));
	m_pRGB_Z		->Set_NoData_Value_Range(-999999, -999999);
	m_pRGB_Z		->Assign_NoData();

	//-----------------------------------------------------
	m_XScale		= (double)m_pRGB->Get_NX() / (double)Get_NX();
	m_YScale		= (double)m_pRGB->Get_NY() / (double)Get_NY();

	//-----------------------------------------------------
	_Set_Grid();

	CSG_Parameter_Shapes_List	*pShapes	= Parameters("SHAPES")->asShapesList();

	for(int i=0; i<pShapes->Get_Count(); i++)
	{
		_Set_Shapes(pShapes->asShapes(i));
	}

	//-----------------------------------------------------
	return( true );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#define DRAW_TRIANGLE(pa, pb, pc)	p[0] = pa; p[1] = pb; p[2] = pc; _Draw_Triangle(p);

//---------------------------------------------------------
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);
}

//---------------------------------------------------------
void CGrid_3D_Image::_Set_Shapes(CSG_Shapes *pInput)
{
	int			iShape, iPart, iPoint;
	double		x, y, z, dx, dy;
	T3DPoint	p;
	TSG_Point	Point;
	CSG_Shape		*pShape;
	CSG_Shapes		*pOutput;

	if( pInput && pInput->is_Valid() )
	{
		Process_Set_Text(CSG_String::Format(_TL("Project \'%s\'"), pInput->Get_Name()));

		pOutput	= SG_Create_Shapes(*pInput);
		dx		= (double)Get_NX() / Get_System()->Get_XRange();
		dy		= (double)Get_NY() / Get_System()->Get_YRange();

		for(iShape=0; iShape<pOutput->Get_Count() && Set_Progress(iShape, pOutput->Get_Count()); iShape++)
		{
			pShape	= pOutput->Get_Shape(iShape);

			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
			{
				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
				{
					Point	= pShape->Get_Point(iPoint, iPart);

					x		= dx * (Point.x - Get_XMin());
					y		= dy * (Point.y - Get_YMin());
					z		= m_pDEM->is_InGrid((int)x, (int)y, true) ? m_pDEM->asDouble((int)x, (int)y) : 0.0;

					_Get_Position(x, y, z, p);

					pShape->Set_Point(p.x, p.y, iPoint, iPart);
				}
			}
		}

		DataObject_Add(pOutput);
	}
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CGrid_3D_Image::_Get_Line(int y, T3DPoint *p)
{
	for(int x=0; x<Get_NX(); x++)
	{
		if( m_pDEM->is_NoData(x, y) || m_pImage->is_NoData(x, y) )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -