有关路径搜索的一个算法

由各个直线组成的路网,求一点到另一点的所有路径:

FindRateWay.h文件代码如下:

#include <list>
#include <vector>
#include <stack>
#include "GELNSG3D.h"

typedef std::vector<AcGeLineSeg3d> vecLineSeg;

//死胡同点记录
struct DeadList
{
 AcGePoint3d ptOri; //参照点
 AcGePoint3dArray ptDeadAry; //死胡同点(即从参照点出发的不能走的下一点)
};
typedef std::vector<DeadList> vecDeadPt;

class CFindRateWay 
{
public:
 CFindRateWay(std::list<AcGeLineSeg3d>& lstRate,AcGePoint3d ptStart,AcGePoint3d ptEnd);
 virtual ~CFindRateWay();

 //寻找所有路径(排除回路),没找到返回FALSE
 BOOL FindWay(std::vector<vecLineSeg>& vecWay);

private:
 //检查路径点是否可继续向下走,如果可走则返回TRUE并返回一个可走的邻接点ptNext
 BOOL IsValid(AcGePoint3d pt, std::stack<AcGePoint3d>& staRatePt,std::vector<vecLineSeg>& vecWay, IN vecDeadPt& vecDead, OUT AcGePoint3d& ptNext);

 //查找某点的所有邻接点
 void FindPtNear(AcGePoint3d pt,AcGePoint3dArray& PtAry);

 //从栈中寻找指定点,找到返回TRUE
 BOOL FindPtFromStack(AcGePoint3d pt, IN std::stack<AcGePoint3d>& staPt);

 //通过栈中轨迹记录到路径组中
 void SaveRate(std::stack<AcGePoint3d>& staPt,std::vector<vecLineSeg>& vecWay);

 //通过两点从m_lstRate中获得AcGeLineSeg3d
 BOOL FindLineSegFromList(AcGePoint3d pt1, AcGePoint3d pt2, AcGeLineSeg3d& Line);

 //将栈中点记录到点数组中
 void SaveStaPt2PtAry(std::stack<AcGePoint3d>& staPt,AcGePoint3dArray& ptAry);

 //判断从起点到pt整个路径是否已经属于成功路径结果的一部分,条件:pt不在栈中
 BOOL IsPartOfSuccRate(AcGePoint3d pt, std::stack<AcGePoint3d>& staRatePt, std::vector<vecLineSeg>& vecWay);

 //判断一个点pt1是否为另一个点pt2的死胡同点
 BOOL IsDeadPt(AcGePoint3d pt1, AcGePoint3d pt2,IN vecDeadPt& vecDead);

 std::list<AcGeLineSeg3d> m_lstRate;
 AcGePoint3d m_ptStart; //出发点
 AcGePoint3d m_ptEnd; //目的点

};

 

------------------------------------------------------------

FindRateWay.cpp文件代码如下:

 

// FindRateWay.cpp: implementation of the CFindRateWay class.
//
//

#include "stdafx.h"
#include "resource.h"
#include "FindRateWay.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//
// Construction/Destruction
//

CFindRateWay::CFindRateWay(std::list<AcGeLineSeg3d>& lstRate,AcGePoint3d ptStart,AcGePoint3d ptEnd)
{
 m_lstRate = lstRate;
 m_ptSta

  • 0
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 102
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 102
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值