112 lines
2.1 KiB
C++
112 lines
2.1 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeGraph.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: ÀàµÄ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeGraph.h"
|
|
|
|
|
|
TPGeGraph::~TPGeGraph()
|
|
{
|
|
|
|
}
|
|
|
|
void TPGeGraph::AppendEdge(TPGeCurve2D*pSeg)
|
|
{
|
|
TGNode *pNode0 = NULL,*pNode1 = NULL;
|
|
if (pSeg->IsFinite(true))
|
|
{
|
|
TGPoint pt;
|
|
pSeg->GetStartPoint(pt);
|
|
pNode0 = FindOrAddNode(pt);
|
|
}
|
|
if (pSeg->IsFinite(false))
|
|
{
|
|
TGPoint pt;
|
|
pSeg->GetEndPoint(pt);
|
|
pNode1 = FindOrAddNode(pt);
|
|
}
|
|
|
|
if (pNode0 == pNode1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
TPGeEdge *pNewEdge = new TPGeEdge(pSeg);
|
|
pNode0->AddTail(pNewEdge);
|
|
pNewEdge->SetNode(pNode0,pNode1);
|
|
if (pNode0 == NULL)
|
|
{
|
|
edgeTable.InsertHead(pNewEdge);
|
|
}
|
|
else
|
|
{
|
|
edgeTable.AddTail(pNewEdge);
|
|
}
|
|
}
|
|
|
|
void TPGeGraph::AppendEdge(TGObjectList&curves)
|
|
{
|
|
while(!curves.IsEmpty())
|
|
{
|
|
AppendEdge((TPGeCurve2D*)(curves.Fetch(0)));
|
|
}
|
|
}
|
|
|
|
TGNode* TPGeGraph::FindOrAddNode(const TGPoint &pt)
|
|
{
|
|
for (nodeTable.MoveToFirst();!nodeTable.IsOut();nodeTable.MoveToNext())
|
|
{
|
|
if (nodeTable.GetCurPData() == pt)
|
|
{
|
|
return nodeTable.GetCurData();
|
|
}
|
|
}
|
|
nodeTable<<new TGNode(pt);
|
|
return nodeTable.GetCurData();
|
|
}
|
|
|
|
void TPGeGraph::FindCurve(TGObjectList&closed,TGObjectList&infinite)
|
|
{
|
|
TPDList<TPGeEdgePath> paths;
|
|
FindLoop(paths);
|
|
for (paths.MoveToFirst();!paths.IsOut();paths.MoveToNext())
|
|
{
|
|
TPGeCurve2D* pCurve = paths.GetCurData()->CreateCurve();
|
|
if (pCurve->IsClosed())
|
|
{
|
|
closed<<pCurve;
|
|
}
|
|
else
|
|
{
|
|
infinite<<pCurve;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TPGeGraph::FindLoop(TPDList<TPGeEdgePath>&res)
|
|
{
|
|
for (edgeTable.MoveToFirst();!edgeTable.IsOut();edgeTable.MoveToNext())
|
|
{
|
|
TPGeEdge*pEdge = edgeTable.GetCurData();
|
|
if (pEdge->IsNot(LOCKED))
|
|
{
|
|
TPGeEdgePath *pNewPath = new TPGeEdgePath;
|
|
pEdge->AddFlag(LOCKED);
|
|
if (pEdge->FindLoop(*pNewPath))
|
|
{
|
|
res << pNewPath;
|
|
}
|
|
else
|
|
{
|
|
delete pNewPath;
|
|
}
|
|
}
|
|
}
|
|
} |