127 lines
2.8 KiB
C++
127 lines
2.8 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeFitGraph3D Àà
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TPGeFitGraph3D ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeFitGraph3D.h"
|
|
|
|
|
|
TPGeFitGraph3D::TPGeFitGraph3D()
|
|
{
|
|
|
|
}
|
|
|
|
TPGeFitGraph3D::~TPGeFitGraph3D()
|
|
{
|
|
|
|
}
|
|
|
|
long TPGeFitGraph3D::GetPointNum() const
|
|
{
|
|
return allPoint.GetLength();
|
|
}
|
|
|
|
TPGeDscPoint3D& TPGeFitGraph3D::operator [](long i)
|
|
{
|
|
return allPoint(i);
|
|
}
|
|
|
|
void TPGeFitGraph3D::Reset()
|
|
{
|
|
newPoint.Clear();
|
|
newEdge.Clear();
|
|
for(allEdge.MoveToFirst();!allEdge.IsOut();allEdge.MoveToNext())
|
|
{
|
|
allEdge.GetCurData()->pPtFit = NULL;
|
|
}
|
|
}
|
|
|
|
TPGeDscPoint3D* TPGeFitGraph3D::FindOrAddPoint(TPGeDscPoint3D pt)
|
|
{
|
|
if(!allPoint.BFindDataTo(pt))
|
|
{
|
|
allPoint.InsertCur(new TPGeDscPoint3D(pt));
|
|
}
|
|
else
|
|
{
|
|
allPoint.GetCurData()->AppendValue(pt.GetValue());
|
|
}
|
|
return allPoint.GetCurData();
|
|
}
|
|
|
|
TPGeDscEdge3D* TPGeFitGraph3D::FindOrAddEdge(TPGeDscPoint3D pt0,TPGeDscPoint3D pt1)
|
|
{
|
|
TPGeDscPoint3D *pPPt0 = FindOrAddPoint(pt0);
|
|
TPGeDscPoint3D *pPPt1 = FindOrAddPoint(pt1);
|
|
TPGeDscEdge3D *pEdge = pPPt0->FindEdge(pPPt1);
|
|
if(pEdge != NULL)
|
|
{
|
|
return pEdge;
|
|
}
|
|
|
|
pEdge = new TPGeDscEdge3D(pPPt0,pPPt1);
|
|
allEdge.AddTail(pEdge);
|
|
return pEdge;
|
|
}
|
|
|
|
TPGeFitTriangle3D* TPGeFitGraph3D::AppendTriangle(TPGeDscPoint3D pt0,TPGeDscPoint3D pt1,TPGeDscPoint3D pt2)
|
|
{
|
|
TPGeDscEdge3D *pDE0 = FindOrAddEdge(pt0,pt1);
|
|
TPGeDscEdge3D *pDE1 = FindOrAddEdge(pt1,pt2);
|
|
TPGeDscEdge3D *pDE2 = FindOrAddEdge(pt2,pt0);
|
|
allTrg.AddTail(new TPGeFitTriangle3D(pDE0,pDE1,pDE2));
|
|
return allTrg.GetCurData();
|
|
}
|
|
|
|
void TPGeFitGraph3D::Fit(double value,double vSnap)
|
|
{
|
|
Reset();
|
|
|
|
for(allPoint.MoveToFirst();!allPoint.IsOut();allPoint.MoveToNext())
|
|
{
|
|
TPGeDscPoint3D *pNewPt = allPoint.GetCurData()->GetFitPoint(value,vSnap);
|
|
if(pNewPt != NULL)
|
|
{
|
|
newPoint.AddTail(pNewPt);
|
|
}
|
|
}
|
|
|
|
for(allEdge.MoveToFirst();!allEdge.IsOut();allEdge.MoveToNext())
|
|
{
|
|
TPGeDscPoint3D*pNewPt = allEdge.GetCurPData().GetFitPoint(value);
|
|
if(pNewPt != NULL)
|
|
{
|
|
newPoint.AddTail(pNewPt);
|
|
}
|
|
}
|
|
|
|
for(allTrg.MoveToFirst();!allTrg.IsOut();allTrg.MoveToNext())
|
|
{
|
|
allTrg.GetCurPData().GetFitEdge(value,newEdge);
|
|
}
|
|
|
|
for(newEdge.MoveToFirst();!newEdge.IsOut();newEdge.MoveToNext())
|
|
{
|
|
TPGeDscEdge3D* pNewEdge = newEdge.GetCurData();
|
|
if(pNewEdge->IsNot(VISITED))
|
|
{
|
|
TPGeFitPath3D*pNewPath = new TPGeFitPath3D(value);
|
|
pNewEdge->ConnectPath(*pNewPath);
|
|
if(pNewPath->GetLength() > 1)
|
|
{
|
|
newPath.AddTail(pNewPath);
|
|
}
|
|
else
|
|
{
|
|
delete pNewPath;
|
|
}
|
|
}
|
|
}
|
|
}
|