找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 771|回复: 1

[教学] 【AcBr库应用(二)】判断点和封闭曲线的位置关系

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2018-5-24 21:21:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 newer 于 2018-5-25 00:49 编辑

ARX可以通过AcBr API ,判断点和AcBrFace的位置关系

AcBrFace::getPointRelationToFace Function
AcBr::ErrorStatus
getPointRelationToFace(
const AcGePoint3d& point,
AcBr::Relation& relation) const;
pointAcGe point object
relationAcBr relation enum
Point containment query. Returns the relation of an external point to the face (inside, outside, and so on). Deprecated in favor of AcBrEntity::getPointContainment().


AcBr::Relation Enum
These are the ErrorStatus enumerated values used by getPointRelationToXXX() and getCurveRelationToXXX() functions. These enumerated types and the functions that use them are deprecated in favor of the newer getPointContainment() and getLineContainment() functions, along with the new AcGe::PointContainment enumerated type.
Relation
NameDeclared ValueDescription
kUnknown0Unable to determine containment. Due to an internal modeler error, it is not possible to determine whether the point is inside, outside, or on the boundary of the selected topology. This return code should be reported when it occurs. If a curve, this code is returned when the curve is partially inside and partially outside the selected topology bounds.
kOutside1The point or curve is outside the topology bounds. The point is outside the bounds of the selected topology, or the curve is fully outside the bounds.
kInside2The point or curve is inside the topology bounds. The point is inside the bounds of the selected topology, or the curve is fully inside the bounds.
kBoundary3The point is on the topology bounds. The point is outside the bounds of the selected topology, or the curve lies entirely on the curve or surface associated with the selected topology. (Note: it is not possible to receive this return code from AcBrVertex::getCurveRelationToVertex().)
kCoincident4The point or curve is coincident with the topology. This return code is currently unused, due to ambiguity. This condition now returns kInside instead.
kTangent5The curve is tangent to the topology bounds. This return code is currently unused, due to ambiguity. This condition now returns kUnknown.
kIntersect6The curve intersects the topology bounds. This return code is currently unused, due to ambiguity. This condition now returns kUnknown.


下面是ARX实现代码:

[C++] 纯文本查看 复制代码
static void BrepPointCheckPoint(void)
{
  Acad::ErrorStatus es;
  AcBr::ErrorStatus ebr;
  ads_name en;
  ads_point pt;
  if (acedEntSel(_T("\nSelect contour: "), en, pt) != RTNORM)
    return;
  AcDbObjectId eId; acdbGetObjectId(eId,en);
  AcDbObjectPointer<AcDbCurve> pline(eId,AcDb::kForRead) ;
  if ((es = pline.openStatus()) != Acad::eOk) {
    acutPrintf(_T("\npline.openStatus()=%s"),acadErrorStatusText(es));
    return;
  }
  if (acedGetPoint(pt,_T("\nPick point: "), pt) != RTNORM)
    return;

  AcDbVoidPtrArray ar, regions;
  ar.append(pline.object());
  if ((es = AcDbRegion::createFromCurves(ar,regions)) != Acad::eOk)  {
    acutPrintf(_T("\nAcDbRegion::createFromCurves(ar,regions)=%s"),acadErrorStatusText(es));
    return;
  }
  AcDbRegion reg; reg.copyFrom((AcDbRegion *)regions[0]);
  for (int i=0; i<regions.length();i++) delete regions[i];
  AcBrBrep brEnt;  ebr = brEnt.set(reg);
  if (ebr != AcBr::eOk) {
    acutPrintf(_T("\nbrEnt.set(sol)=%s"),acadErrorStatusText((Acad::ErrorStatus)(Adesk::UInt32)ebr));
    return;
  }
  AcGe::PointContainment pDesc;
  AcBrEntity *pCont = NULL;
  AcBrBrepFaceTraverser brepFaceTrav; brepFaceTrav.setBrep(brEnt);
  AcBr::ErrorStatus err = AcBr::eInvalidInput;
  while (!brepFaceTrav.done()) {
   AcBrFace brFace; brepFaceTrav.getFace(brFace);
   err = brFace.getPointContainment(asPnt3d(pt),pDesc,pCont);
   if (err == Acad::eOk && pDesc == AcGe::kInside) {
     acedAlert(_T("In")); return;
   } else if (err == Acad::eOk && pDesc == AcGe::kOnBoundary) {
     acedAlert(_T("On")); return;
   }
   brepFaceTrav.next();
  }
  if (err == Acad::eOk) {
    acedAlert(_T("Out"));
  } else {
    acedAlert(_T("Unknown error"));
  }
  return;
}


下面我们用XDRX API 封装的AcBr 库函数来把上述的ARX代码翻译到LISP:

定义个函数 _isPtInPoly
参数:pl ----封闭的曲线
pnt ---- 测试点

返回值:1:外部、2:内部、3、边界上

  1. (defun _isPtInPoly (pl pnt / ss brep tr face region relation)
  2.   (if (setq ss (xdrx_region_make pl t)) ;PL生成REGION
  3.     (progn (setq brep (xdbr::constructor (setq region (entlast))));;构建AcBrBrep对象
  4.            (setq tr (xdbr::constructor "brepfacetraverser" brep));;构建Brep到Face遍历器

  5.            ;;FACE遍历
  6.            (while (not (xdbr::traverser:done tr)) ;;遍历器没到最后,循环
  7.              (setq face (xdbr::getpropertyvalue tr "face"));;获得当前遍历位置的AcBrFace对象
  8.              (setq relation (xdbr::getpropertyvalue face "PointRelationToFace" pnt));;用PointRelationToFace方法判断点和面的位置关系
  9.              (xdrx_object_release face);;释放face对象
  10.              (xdbr::traverser:next tr);;遍历器指向下个面
  11.            )

  12.            (xdrx_entity_delete region);;删除临时的REGION
  13.            (xdrx_object_release tr brep);;释放AcBrBrep对象和遍历器对象
  14.     )
  15.   )
  16.   relation
  17. )



下面是用点监视器实现测试鼠标点和封闭曲线的位置关系,打印到屏幕。

  1. (defun c:tt ()
  2.   (defun _callback (dynpt / str)
  3.     (if (not (setq testpnt (osnap dynpt "nea")))
  4.       (setq testpnt dynpt)
  5.     )
  6.     (setq relation (_isPtInPoly crv testpnt))
  7.     (cond ((= relation XD:kInside)
  8.            (setq str "当前鼠标在多段线内部!")
  9.           )
  10.           ((= relation XD:kBoundary)
  11.            (setq str "当前鼠标在多段线上!")
  12.           )
  13.           (t (setq str "当前鼠标在多段线外部!"))
  14.     )
  15.     str
  16.   )
  17.   (if (setq crv (car (xdrx_entsel
  18.                        "\n拾取封闭的多段线<退出>:"
  19.                        '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))
  20.                      )
  21.                 )
  22.       )
  23.     (progn (xdrx_begin)
  24.            (xdrx_sysvar_push '("osmode" 0))
  25.            (xdrx_pointmonitor "_callback")
  26.            (getpoint
  27.              "\n移动鼠标,判断当前鼠标点和多段线位置关系<退出>:"
  28.            )
  29.            (xdrx_pointmonitor)
  30.            (xdrx_end)
  31.     )
  32.   )
  33.   (princ)
  34. )


acbr-点和面关系.gif

评分

参与人数 1D豆 +5 收起 理由
sh_h + 5 很给力!经验;技术要点;资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 769个

财富等级: 财运亨通

发表于 2018-5-25 09:22:30 | 显示全部楼层
谢谢楼主分享!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-27 06:54 , Processed in 0.528824 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表