Files
envi-code/SourceCode/Code2026/tg_shs/shs_subgeLib/TPGeFitGraph.cpp
T
2026-09-28 15:28:50 +08:00

233 lines
5.2 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TPGeFitGraph Àà
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TPGeFitGraph ¶¨Òå
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TPGeFitGraph.h"
TPGeFitGraph::~TPGeFitGraph()
{
}
void TPGeFitGraph::AppendPoint(TPGeDscPoint*pPt)
{
allPoint.AddTail(pPt);
}
void TPGeFitGraph::AppendEdge(TPGeDscEdge*pEdge)
{
allEdge.AddTail(pEdge);
}
void TPGeFitGraph::AppendTriangle(TPGeFitTriangle*pTrg)
{
allTrg.AddTail(pTrg);
}
void TPGeFitGraph::AppendEdge(TPGeDscPoint*p0,TPGeDscPoint*p1)
{
AppendEdge(new TPGeDscEdge(p0,p1));
}
void TPGeFitGraph::AppendTriangle(TPGeDscEdge*p0,TPGeDscEdge*p1,TPGeDscEdge*p2)
{
AppendTriangle(new TPGeFitTriangle(p0,p1,p2));
}
TPGeDscPoint* TPGeFitGraph::FindOrAddPoint(TPGeDscPoint pt)
{
if(!allPoint.BFindDataTo(pt))
allPoint.InsertCur(new TPGeDscPoint(pt));
else
allPoint.GetCurData()->AppendValue(pt.GetValue());
return allPoint.GetCurData();
}
void TPGeFitGraph::MakeEdge(double maxDist)
{
allEdge.Clear();
TPDList<TPGeDscPoint> allPoint1;
allPoint1.Conbine(allPoint);
TPDList<TPGeDscPoint> ptBuf;
TPDListEx<TPGeDscEdge> eBuf;
while(!allPoint1.IsEmpty())
{
allPoint1.MoveToFirst();
TPGeDscPoint *pCurPt=allPoint1.FetchCur();
TPGeExtend2D ext(pCurPt->x - maxDist, pCurPt->x + maxDist, pCurPt->y - maxDist, pCurPt->y + maxDist);
ptBuf.AddTail(pCurPt);
for(allPoint1.MoveToFirst(); !allPoint1.IsOut(); allPoint1.MoveToNext())
{
TPGeDscPoint* pPt = allPoint1.GetCurData();
if(DOWNEQUAL_ZEROD(maxDist) || ext.IsInclude(pPt->x, pPt->y))
{
TPGeDscEdge*pNewEdge=new TPGeDscEdge(pCurPt,pPt,Distance2D(*pCurPt,*pPt));
eBuf.SortIn(pNewEdge,true);
}
}
}
allPoint.Conbine(ptBuf);
eBuf.Reverse();
for(eBuf.MoveToLast(); !eBuf.IsOut(); )
{
TPGeDscEdge* pCurEdge = eBuf.FetchCur();
TPGeExtend2D ext;
pCurEdge->GetExtend2D(ext);
for(allEdge.MoveToFirst(); !allEdge.IsOut(); allEdge.MoveToNext())
{
TPGeDscEdge* pEdge = allEdge.GetCurData();
TPGeExtend2D ext1;
pEdge->GetExtend2D(ext1);
if(ext.IsIntersect(ext1) && pCurEdge->IsCrossWith(pEdge))
{
pCurEdge->pPt0->RemoveEdge(pCurEdge);
pCurEdge->pPt1->RemoveEdge(pCurEdge);
delete pCurEdge;
break;
}
}
if(allEdge.IsOut())
{
allEdge.AddTail(pCurEdge);
}
}
}
void TPGeFitGraph::Reset()
{
newPoint.Clear();
newEdge.Clear();
for(allEdge.MoveToFirst();!allEdge.IsOut();allEdge.MoveToNext())
{
allEdge.GetCurData()->pPtFit = NULL;
}
}
void TPGeFitGraph::Fit(double z,double zSnap)
{
Reset();
for(allPoint.MoveToFirst();!allPoint.IsOut();allPoint.MoveToNext())
{
TPGeDscPoint *pNewPt = allPoint.GetCurData()->GetFitPoint(z,zSnap);
if(pNewPt!=NULL)
{
newPoint.AddTail(pNewPt);
}
}
for(allEdge.MoveToFirst();!allEdge.IsOut();allEdge.MoveToNext())
{
TPGeDscPoint*pNewPt = allEdge.GetCurPData().GetFitPoint(z);
if(pNewPt!=NULL)
{
newPoint.AddTail(pNewPt);
}
}
for(allTrg.MoveToFirst();!allTrg.IsOut();allTrg.MoveToNext())
{
allTrg.GetCurPData().GetFitEdge(z,newEdge);
}
for(newPoint.MoveToFirst();!newPoint.IsOut();newPoint.MoveToNext())
{
newPoint.GetCurPData().Arrange();
}
for(newEdge.MoveToFirst();!newEdge.IsOut();newEdge.MoveToNext())
{
TPGeDscEdge* pNewEdge = newEdge.GetCurData();
if(pNewEdge->IsNot(VISITED))
{
TPGeFitPath*pNewPath = new TPGeFitPath(z);
pNewEdge->ConnectPath(*pNewPath);
if(pNewPath->GetLength() > 1)
{
newPath.AddTail(pNewPath);
}
else
{
delete pNewPath;
}
}
}
}
void TPGeFitGraph::MakeTriangle()
{
allTrg.Clear();
for(allPoint.MoveToFirst();!allPoint.IsOut();allPoint.MoveToNext())
{
TPGeDscPoint *pPt = allPoint.GetCurData();
pPt->MakeTriangle(allTrg);
pPt->RemoveAllEdge();
}
for(allEdge.MoveToFirst();!allEdge.IsOut();allEdge.MoveToNext())
{
TPGeDscEdge*pEdge = allEdge.GetCurData();
pEdge->pPt0->AppendEdge(pEdge);
pEdge->pPt1->AppendEdge(pEdge);
}
for(allTrg.MoveToFirst();!allTrg.IsOut();allTrg.MoveToNext())
{
TPGeFitTriangle *pTrg = allTrg.GetCurData();
if(pTrg->IsParentTriangle())
{
allTrg.DelCur();
}
}
}
void TPGeFitGraph::CreatePoint(TGObjectList&res)
{
for(allPoint.MoveToFirst();!allPoint.IsOut();allPoint.MoveToNext())
{
res << (TGObject*)allPoint.GetCurData()->CreatePoint();
}
}
void TPGeFitGraph::CreateCurve(TGObjectList&res)
{
for(newPath.MoveToFirst();!newPath.IsOut();newPath.MoveToNext())
{
res << newPath.GetCurData()->CreateCurve();
}
}
void TPGeFitGraph::CreateTriangle(TGObjectList&res)
{
for(allTrg.MoveToFirst();!allTrg.IsOut();allTrg.MoveToNext())
{
res << (TGObject*)allTrg.GetCurData()->CreateTriangle();
}
}
void TPGeFitGraph::CreateEdge(TGObjectList&res)
{
for(allEdge.MoveToFirst();!allEdge.IsOut();allEdge.MoveToNext())
{
res << allEdge.GetCurData()->CreateEdge();
}
}
void TPGeFitGraph::CreateFitEdge(TGObjectList&res)
{
for(newEdge.MoveToFirst();!newEdge.IsOut();newEdge.MoveToNext())
{
res << newEdge.GetCurData()->CreateEdge();
}
}