- 积分
- 36673
- 明经币
- 个
- 注册时间
- 2010-7-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-6-18 15:03:45
|
显示全部楼层
本帖最后由 highflybird 于 2011-6-18 21:20 编辑
回复 chpmould 的帖子
然后在程序中这样用:
#include <set>
#include <algorithm>
using namespace std;
以下为测试:
在你的函数中这样添加:
-
- //过滤选择CAD的点(PointArray)对象
- resbuf filter;
- filter.restype=0;
- filter.resval.rstring=_T("POINT");
- filter.rbnext = NULL;
- ads_name sel;
- int ret=acedSSGet(NULL,NULL,NULL,&filter,sel);
- if( ret!=RTNORM)
- {
- acedSSFree(sel);
- return;
- }
- long len;
- ads_name ent;
- AcDbObjectId ObjId;
- AcDbPoint *pEnt;
- acedSSLength(sel,&len);
- AcGePoint3dArray ptset;
- for (long i = 0;i<len;i++)
- {
- acedSSName(sel,i,ent);
- acdbGetObjectId(ObjId,ent);
- if (acdbOpenObject(pEnt,ObjId,AcDb::kForRead)!=Acad::eOk)
- continue;
- ptset.append(pEnt->position());
- pEnt->close();
- }
- acedSSFree(sel);
- len = ptset.length();
- //这样得到了AcGePoint3dArray,然后运用set,排除重复点:
- set<CPoint3d> pts;
- CPoint3d tempPt;
- tempPt.SetFuzz(1e-4);
- for (int i = 0; i < ptset.length();i++)
- {
- tempPt.copy(ptset[ i ]);
- pts.insert(tempPt);
- }
- //利用set迭代器,构建新的AcGePoint3dArray:
- size_t newlen = pts.size();
- acutPrintf(_T("New size is %d"),newlen);
- ptset.removeAll();
- ptset.setLogicalLength(newlen);
- AcGePoint3d Pt3d;
- set<CPoint3d>::iterator pItr;
- int i = 0;
- for (pItr = pts.begin();pItr!=pts.end();pItr++)
- {
- acutPrintf(_T("\nPoint [%d] is : %f,%f,%f"),i,(*pItr).x,(*pItr).y,(*pItr).z);
- Pt3d.x=(*pItr).x;
- Pt3d.y=(*pItr).y;
- Pt3d.z=(*pItr).z;
- ptset[ i ] = Pt3d;
- i++;
- }
|
|