//---------------------------------------------------------
bool CView_Map_3DPanel::On_Draw(void)
{
	if( !m_DEM.is_Valid() )
	{
		return( false );
	}

	//-----------------------------------------------------
	#pragma omp parallel for
	for(int y=1; y<m_DEM.Get_NY(); y++)
	{
		for(int x=1; x<m_DEM.Get_NX(); x++)
		{
			TSG_Triangle_Node	p[3];

			if( Get_Node(x - 1, y - 1, p[0])
			&&  Get_Node(x    , y    , p[1]) )
			{
				if( Get_Node(x, y - 1, p[2]) )
				{
					Draw_Triangle(p, true);
				}

				if( Get_Node(x - 1, y, p[2]) )
				{
					Draw_Triangle(p, true);
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
Beispiel #2
0
//---------------------------------------------------------
int CSG_Network::_Add_Node(CSG_PRQuadTree &Search, int Edge_ID, const TSG_Point &Node_Point, const TSG_Point &Dir_Point)
{
	int					Node_ID;
	double				Distance;
	CSG_PRQuadTree_Leaf	*pLeaf	= Search.Get_Nearest_Leaf(Node_Point, Distance);

	if( !pLeaf || Distance > 0.0 )//00001 )
	{
		Node_ID	= Get_Node_Count();

		m_Nodes.Inc_Array();

		((CSG_Network_Node **)m_Nodes.Get_Array())[Node_ID]	= new CSG_Network_Node(Node_ID, Node_Point);

		Search.Add_Point(Node_Point.x, Node_Point.y, Node_ID);
	}
	else
	{
		Node_ID	= (int)pLeaf->Get_Z();
	}

	Get_Node(Node_ID).Add_Edge(Edge_ID, SG_Get_Angle_Of_Direction(Node_Point, Dir_Point));

	return( Node_ID );
}
Beispiel #3
0
	bool CFSModule::Create_Directory( const std::string& Dir ) {
		// Enforce leading /
		if( Dir.empty() || (Dir.substr(0,1) != "/") || (Dir.substr(Dir.length() - 1) == "/") ) {
			return NULL;
		}
		
		string Node;
		string BaseDir;

		// Split path into Node and Basedir
		Split_Full_Path( Dir, BaseDir, Node );
		
		CFSNode* pNode = Get_Node( BaseDir );
		
		if( pNode->Get_Node_Type() != NODE_DIR ) {
			return NULL;
		}
		
		CDirectory* pBaseDir = (CDirectory*)pNode;
		
		// Create the directory
		if( pBaseDir->Create_Directory( Node ) ) {
			return true;
		} else {
			return false;
		}
	}
Beispiel #4
0
	bool CFSModule::Create_File( const std::string& Name ) {
		// Enforce leading /
		if( Name.empty() || (Name.substr(0,1) != "/") || (Name.substr(Name.length() - 1) == "/") ) {
			return NULL;
		}
		
		string Node;
		string BaseDir;

		// Split path into Node and Basedir
		Split_Full_Path( Name, BaseDir, Node );
		
		CDirectory* pDir = (CDirectory*)Get_Node( BaseDir );
		
		if( !pDir ) {
			return NULL;
		}
		
		if( pDir->Get_Node_Type() != NODE_DIR ) {
			return NULL;
		}
		
		if( pDir->Create_File( Node ) ) {
			return true;
		} else {
			return false;
		}
	}
Beispiel #5
0
bool CSG_Network::Destroy(void)
{
	for(int i=0; i<Get_Node_Count(); i++)
	{
		delete(&Get_Node(i));
	}

	m_Nodes.Set_Array(0);

	m_Edges.Del_Records();

	return( true );
}
Beispiel #6
0
//---------------------------------------------------------
bool CSG_Network::Update(void)
{
	int		iEdge;

	//-----------------------------------------------------
	for(iEdge=m_Edges.Get_Count()-1; iEdge>=0; iEdge--)
	{
		CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

		if( !(((CSG_Shape_Line *)pEdge)->Get_Length() > 0.0) )
		{
			m_Edges.Del_Shape(iEdge);
		}
	}

	//-----------------------------------------------------
	for(int i=0; i<Get_Node_Count(); i++)
	{
		delete(&Get_Node(i));
	}

	m_Nodes.Set_Array(0);

	//-----------------------------------------------------
	CSG_PRQuadTree	Search(m_Edges.Get_Extent());

	for(iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++)
	{
		CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

		pEdge->Set_Value(0, iEdge);

		pEdge->Set_Value(1, _Add_Node(Search, iEdge,
			pEdge->Get_Point(0),
			pEdge->Get_Point(1)
		));

		pEdge->Set_Value(2, _Add_Node(Search, iEdge,
			pEdge->Get_Point(pEdge->Get_Point_Count(0) - 1),
			pEdge->Get_Point(pEdge->Get_Point_Count(0) - 2)
		));
	}

	//-----------------------------------------------------
	return( true );
}
Beispiel #7
0
	// Read a bytestream from a file
	bool CFSModule::Read_ByteStream(const std::string Filename, CByteStream& Stream) {
		CFile* pFile = (CFile*)Get_Node( Filename );
		
		if( !pFile ) {
			return false;
		}
		
		if( pFile->Get_Node_Type() != NODE_FILE ) {
			DLog(LOG_FS, "Invalid node type in CFSModule::Read_ByteStream()\n");
			return false;
		}
		
		// Read file into bytestream
		if( !pFile->Read( Stream ) ) {
			return false;
		}
		
		return true;
	}
//---------------------------------------------------------
bool CSG_TIN::_Triangulate(void)
{
	bool			bResult;
	int				i, j, n, nTriangles;
	CSG_TIN_Node	**Nodes;
	TTIN_Triangle	*Triangles;

	//-----------------------------------------------------
	_Destroy_Edges();
	_Destroy_Triangles();

	//-----------------------------------------------------
	Nodes	= (CSG_TIN_Node **)SG_Malloc((Get_Node_Count() + 3) * sizeof(CSG_TIN_Node *));

	for(i=0; i<Get_Node_Count(); i++)
	{
		Nodes[i]	= Get_Node(i);
		Nodes[i]	->_Del_Relations();
	}

	//-----------------------------------------------------
	qsort(Nodes, Get_Node_Count(), sizeof(CSG_TIN_Node *), SG_TIN_Compare);

	for(i=0, j=0, n=Get_Node_Count(); j<n; i++)	// remove duplicates
	{
		Nodes[i]	= Nodes[j++];

		while(	j < n
			&&	Nodes[i]->Get_X() == Nodes[j]->Get_X()
			&&	Nodes[i]->Get_Y() == Nodes[j]->Get_Y() )
		{
			Del_Node(Nodes[j++]->Get_Index(), false);
		}
	}

	//-----------------------------------------------------
	for(i=Get_Node_Count(); i<Get_Node_Count()+3; i++)
	{
		Nodes[i]	= new CSG_TIN_Node(this, 0);
	}

	//-----------------------------------------------------
	Triangles	= (TTIN_Triangle *)SG_Malloc(3 * Get_Node_Count() * sizeof(TTIN_Triangle));

	if( (bResult = _Triangulate(Nodes, Get_Node_Count(), Triangles, nTriangles)) == true )
	{
		for(i=0; i<nTriangles && SG_UI_Process_Set_Progress(i, nTriangles); i++)
		{
			_Add_Triangle(Nodes[Triangles[i].p1], Nodes[Triangles[i].p2], Nodes[Triangles[i].p3]);
		}
	}

	SG_Free(Triangles);

	//-----------------------------------------------------
	for(i=Get_Node_Count(); i<Get_Node_Count()+3; i++)
	{
		delete(Nodes[i]);
	}

	SG_Free(Nodes);

	SG_UI_Process_Set_Ready();

	return( bResult );
}
Beispiel #9
0
//---------------------------------------------------------
bool CSG_Network::Remove_End_Nodes(void)
{
	int		iEdge, n;

	//-----------------------------------------------------
	for(iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++)
	{
		CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

		if( pEdge->asInt(3) == SHAPE_TYPE_Line )
		{
			bool	bRemove	= false;

			for(int iNode=1; iNode<=2 && !bRemove; iNode++)
			{
				CSG_Network_Node	&Node	= Get_Node(pEdge->asInt(iNode));
				CSG_Point			Point	= Node.Get_Point();
				CSG_Shape			*pNext;

				if(	(	(pNext = m_Edges.Get_Shape(Node.Get_Edge_Next(pEdge->asInt(0),  true))) != NULL
						&&	pNext->asInt(3) == SHAPE_TYPE_Polygon
						&&	!Point.is_Equal(pNext->Get_Point(0, 0, false)) )
				||	(	(pNext = m_Edges.Get_Shape(Node.Get_Edge_Next(pEdge->asInt(0), false))) != NULL
						&&	pNext->asInt(3) == SHAPE_TYPE_Polygon
						&&	!Point.is_Equal(pNext->Get_Point(0, 0,  true)) ) )
				{
					bRemove	= true;
				}
			}

			if( bRemove )
			{
				Get_Node(pEdge->asInt(1)).Del_Edge(pEdge->asInt(0));
				Get_Node(pEdge->asInt(2)).Del_Edge(pEdge->asInt(0));

				pEdge->Set_Value(4, 1);
			}
		}
	}

	//-----------------------------------------------------
	do
	{
		for(n=0, iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++)
		{
			CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

			if( pEdge->asInt(3) == SHAPE_TYPE_Line && pEdge->asInt(4) == 0 )
			{
				if(	Get_Node(pEdge->asInt(1)).Get_Edge_Count() <= 1
				||	Get_Node(pEdge->asInt(2)).Get_Edge_Count() <= 1 )
				{
					Get_Node(pEdge->asInt(1)).Del_Edge(pEdge->asInt(0));
					Get_Node(pEdge->asInt(2)).Del_Edge(pEdge->asInt(0));

					pEdge->Set_Value(4, 1);

					n++;
				}
			}
		}
	}
	while( n > 0 );

	//-----------------------------------------------------
	for(iEdge=m_Edges.Get_Count()-1; iEdge>=0; iEdge--)
	{
		if( m_Edges[iEdge][4] )
		{
			m_Edges.Del_Shape(iEdge);
		}
	}

	//-----------------------------------------------------
	return( Update() );
}