Esempio n. 1
0
//---------------------------------------------------------
void CWKSP_TIN::_Draw_Triangles(CWKSP_Map_DC &dc_Map)
{
	if(	m_Parameters("DISPLAY_TRIANGES")->asBool() && dc_Map.IMG_Draw_Begin(m_Parameters("DISPLAY_TRANSPARENCY")->asDouble() / 100.0) )
	{
		for(int iTriangle=0; iTriangle<asTIN()->Get_Triangle_Count(); iTriangle++)
		{
			CSG_TIN_Triangle	*pTriangle	= asTIN()->Get_Triangle(iTriangle);

			if( dc_Map.m_rWorld.Intersects(pTriangle->Get_Extent()) != INTERSECTION_None )
			{
				TPoint	p[3];

				for(int iNode=0; iNode<3; iNode++)
				{
					CSG_TIN_Node	*pNode	= pTriangle->Get_Node(iNode);
					TSG_Point_Int	Point	= dc_Map.World2DC(pNode->Get_Point());

					p[iNode].x	= Point.x;
					p[iNode].y	= Point.y;
					p[iNode].z	= pNode->asDouble(m_fValue);
				}

				_Draw_Triangle(dc_Map, p);
			}
		}

		dc_Map.IMG_Draw_End();
	}
}
Esempio n. 2
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 );
}