Example #1
0
//---------------------------------------------------------
bool CTIN_From_Shapes::On_Execute(void)
{
	CSG_TIN	*pTIN;
	CSG_Shapes	*pShapes;

	pShapes	= Parameters("SHAPES")	->asShapes();
	pTIN	= Parameters("TIN")		->asTIN();


	return( pTIN->Create(pShapes) );
}
Example #2
0
//---------------------------------------------------------
bool CTIN_Gradient::On_Execute(void)
{
	bool			bDegree;
	int				iTriangle, zField;
	double			a, b;
	CSG_TIN_Triangle	*pTriangle;
	CSG_TIN			*pTIN;
	CSG_Shape			*pShape;
	CSG_Shapes			*pShapes;

	//-----------------------------------------------------
	pTIN		= Parameters("TIN")			->asTIN();
	zField		= Parameters("ZFIELD")		->asInt();
	pShapes		= Parameters("GRADIENT")	->asShapes();
	bDegree		= Parameters("DEGREE")		->asInt() == 1;

	//-----------------------------------------------------
	pShapes->Create(SHAPE_TYPE_Polygon, CSG_String::Format(SG_T("%s [%s], %s [%s]"), _TL("TIN_Gradient"), pTIN->Get_Field_Name(zField), _TL("TIN"), pTIN->Get_Name()));

	pShapes->Add_Field(_TL("ID")		, SG_DATATYPE_Int);
	pShapes->Add_Field(_TL("AREA")	, SG_DATATYPE_Double);
	pShapes->Add_Field(_TL("DECLINE"), SG_DATATYPE_Double);
	pShapes->Add_Field(_TL("AZIMUTH"), SG_DATATYPE_Double);

	//-----------------------------------------------------
	for(iTriangle=0; iTriangle<pTIN->Get_Triangle_Count() && Set_Progress(iTriangle, pTIN->Get_Triangle_Count()); iTriangle++)
	{
		pTriangle	= pTIN->Get_Triangle(iTriangle);

		if( pTriangle->Get_Gradient(zField, a, b) )
		{
			if( bDegree )
			{
				a	*= M_RAD_TO_DEG;
				b	*= M_RAD_TO_DEG;
			}

			pShape		= pShapes->Add_Shape();
			pShape->Add_Point(pTriangle->Get_Node(0)->Get_Point());
			pShape->Add_Point(pTriangle->Get_Node(1)->Get_Point());
			pShape->Add_Point(pTriangle->Get_Node(2)->Get_Point());

			pShape->Set_Value(0, iTriangle + 1);
			pShape->Set_Value(1, pTriangle->Get_Area());
			pShape->Set_Value(2, a);
			pShape->Set_Value(3, b);
		}
	}

	return( true );
}
Example #3
0
//---------------------------------------------------------
bool CTIN_View_Module::On_Execute(void)
{
	if( !SG_UI_Get_Window_Main() )
	{
		Message_Add(_TL("point cloud viewer can only be run from graphical user interface"));

		return( false );
	}

	CSG_TIN	*pTIN	= Parameters("TIN")->asTIN();

	if( pTIN->Get_Count() <= 0 )
	{
		Message_Add(_TL("point cloud viewer will not be started, because point cloud has no points"));

		return( false );
	}

	CTIN_View_Dialog	dlg(pTIN, Parameters("HEIGHT")->asInt(), Parameters("COLOR")->asInt(), Parameters("RGB")->asGrid());

	dlg.ShowModal();

	return( true );
}
Example #4
0
//---------------------------------------------------------
bool CSTL_Export::On_Execute(void)
{
	bool		bBinary;
	int			zField;
	float		v[3];
	CSG_String	File;
	CSG_File	Stream;
	CSG_TIN		*pTIN;

	pTIN	= Parameters("TIN")		->asTIN();
	File	= Parameters("FILE")	->asString();
	zField	= Parameters("ZFIELD")	->asInt(); 
	bBinary	= Parameters("BINARY")	->asInt() == 1; 

	if( !Stream.Open(File, SG_FILE_W, bBinary) )
	{
		return( false );
	}

	//-----------------------------------------------------
	if( bBinary )
	{
		char	*sHeader	= (char *)SG_Calloc(80, sizeof(char));
		DWORD	nFacets		= pTIN->Get_Triangle_Count();
		WORD	nBytes		= 0;

		Stream.Write(sHeader , sizeof(char), 80);
		Stream.Write(&nFacets, sizeof(DWORD));

		SG_Free(sHeader);

		//-------------------------------------------------
		for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++)
		{
			CSG_TIN_Triangle	*pTriangle	= pTIN->Get_Triangle(iTriangle);

			Get_Normal(pTriangle, zField, v);

			Stream.Write(v, sizeof(float), 3);	// facet normal

			for(int iNode=0; iNode<3; iNode++)
			{
				CSG_TIN_Node	*pNode	= pTriangle->Get_Node(iNode);

				v[0]	= (float)pNode->Get_X();
				v[1]	= (float)pNode->Get_Y();
				v[2]	= (float)pNode->asDouble(zField);

				Stream.Write(v, sizeof(float), 3);
			}

			Stream.Write(&nBytes, sizeof(WORD));
		}
	}

	//-----------------------------------------------------
	else	// ASCII
	{
		Stream.Printf(SG_T("solid %s\n"), SG_File_Get_Name(File, false).c_str());

		for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++)
		{
			CSG_TIN_Triangle	*pTriangle	= pTIN->Get_Triangle(iTriangle);

			Get_Normal(pTriangle, zField, v);

			Stream.Printf(SG_T(" facet normal %.4f %.4f %.4f\n"), v[0], v[1], v[2]);
			Stream.Printf(SG_T("  outer loop\n"));

			for(int iNode=0; iNode<3; iNode++)
			{
				CSG_TIN_Node	*pNode	= pTriangle->Get_Node(iNode);

				v[0]	= (float)pNode->Get_X();
				v[1]	= (float)pNode->Get_Y();
				v[2]	= (float)pNode->asDouble(zField);

				Stream.Printf(SG_T("   vertex %.4f %.4f %.4f\n"), v[0], v[1], v[2]);
			}

			Stream.Printf(SG_T("  endloop\n"));
			Stream.Printf(SG_T(" endfacet\n"));		
		}

		Stream.Printf(SG_T("endsolid %s\n"), SG_File_Get_Name(File, false).c_str());
	}

	return( true );
}
//---------------------------------------------------------
bool CTIN_From_Grid_Specific_Points::On_Execute(void)
{
	bool					bResult;
	int						x, y, i;
	CSG_TIN					*pTIN;
	CSG_Grid					*pGrid, Grid;
	CSG_Parameter_Grid_List	*pValues;
	CSG_Shape					*pPoint;
	CSG_Shapes					Points;

	//-----------------------------------------------------
	pGrid	= Parameters("GRID")->asGrid();
	Grid.Create(pGrid, SG_DATATYPE_Byte);

	//-----------------------------------------------------
	switch( Parameters("METHOD")->asInt() )
	{
	default:
		bResult	= false;
		break;

	case 0:
		bResult	= Get_MarkHighestNB	(&Grid, pGrid);
		break;

	case 1:
		bResult	= Get_OppositeNB	(&Grid, pGrid, Parameters("HIGH")->asInt());
		break;

	case 2:
		bResult	= Get_FlowDirection	(&Grid, pGrid,
			(int)Parameters("FLOW")->asRange()->Get_LoVal(),
			(int)Parameters("FLOW")->asRange()->Get_HiVal()
		);
		break;

	case 3:
		bResult	= Get_FlowDirection2(&Grid, pGrid,
			(int)Parameters("FLOW")->asRange()->Get_HiVal()
		);
		break;

	case 4:
		bResult	= Get_Peucker		(&Grid, pGrid, Parameters("PEUCKER")->asDouble());
		break;
	}

	//-----------------------------------------------------
	if( bResult )
	{
		pValues	= Parameters("VALUES")->asGridList();

		Points.Create(SHAPE_TYPE_Point);
		Points.Add_Field(_TL("VALUE"), SG_DATATYPE_Double);

		for(i=0; i<pValues->Get_Count(); i++)
		{
			Points.Add_Field(pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
		}

		for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++)
		{
			for(x=0; x<Get_NX(); x++)
			{
				if( Grid.asInt(x, y) != 0 )
				{
					pPoint	= Points.Add_Shape();

					pPoint->Add_Point(
						Get_XMin() + Get_Cellsize() * x,
						Get_YMin() + Get_Cellsize() * y
					);

					pPoint->Set_Value(0, pGrid->asDouble(x, y));

					for(i=0; i<pValues->Get_Count(); i++)
					{
						pPoint->Set_Value(1 + i, pValues->asGrid(i)->asDouble(x, y));
					}
				}
			}
		}

		//-------------------------------------------------
		if( Points.Get_Count() >= 3 )
		{
			pTIN	= Parameters("TIN")->asTIN();
			pTIN->Create(&Points);
			pTIN->Set_Name(pGrid->Get_Name());
		}
	}

	return( bResult );
}