马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 newer 于 2018-5-25 00:49 编辑
ARX可以通过AcBr API ,判断点和AcBrFace的位置关系
AcBrFace::getPointRelationToFace Function
AcBr::ErrorStatus getPointRelationToFace( const AcGePoint3d& point, AcBr::Relation& relation) const; point | AcGe point object | relation | AcBr 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.
RelationName | Declared Value | Description | kUnknown | 0 | Unable 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. | kOutside | 1 | The 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. | kInside | 2 | The 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. | kBoundary | 3 | The 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().) | kCoincident | 4 | The point or curve is coincident with the topology. This return code is currently unused, due to ambiguity. This condition now returns kInside instead. | kTangent | 5 | The curve is tangent to the topology bounds. This return code is currently unused, due to ambiguity. This condition now returns kUnknown. | kIntersect | 6 | The 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、边界上
- (defun _isPtInPoly (pl pnt / ss brep tr face region relation)
- (if (setq ss (xdrx_region_make pl t)) ;PL生成REGION
- (progn (setq brep (xdbr::constructor (setq region (entlast))));;构建AcBrBrep对象
- (setq tr (xdbr::constructor "brepfacetraverser" brep));;构建Brep到Face遍历器
- ;;FACE遍历
- (while (not (xdbr::traverser:done tr)) ;;遍历器没到最后,循环
- (setq face (xdbr::getpropertyvalue tr "face"));;获得当前遍历位置的AcBrFace对象
- (setq relation (xdbr::getpropertyvalue face "PointRelationToFace" pnt));;用PointRelationToFace方法判断点和面的位置关系
- (xdrx_object_release face);;释放face对象
- (xdbr::traverser:next tr);;遍历器指向下个面
- )
- (xdrx_entity_delete region);;删除临时的REGION
- (xdrx_object_release tr brep);;释放AcBrBrep对象和遍历器对象
- )
- )
- relation
- )
下面是用点监视器实现测试鼠标点和封闭曲线的位置关系,打印到屏幕。
- (defun c:tt ()
- (defun _callback (dynpt / str)
- (if (not (setq testpnt (osnap dynpt "nea")))
- (setq testpnt dynpt)
- )
- (setq relation (_isPtInPoly crv testpnt))
- (cond ((= relation XD:kInside)
- (setq str "当前鼠标在多段线内部!")
- )
- ((= relation XD:kBoundary)
- (setq str "当前鼠标在多段线上!")
- )
- (t (setq str "当前鼠标在多段线外部!"))
- )
- str
- )
- (if (setq crv (car (xdrx_entsel
- "\n拾取封闭的多段线<退出>:"
- '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))
- )
- )
- )
- (progn (xdrx_begin)
- (xdrx_sysvar_push '("osmode" 0))
- (xdrx_pointmonitor "_callback")
- (getpoint
- "\n移动鼠标,判断当前鼠标点和多段线位置关系<退出>:"
- )
- (xdrx_pointmonitor)
- (xdrx_end)
- )
- )
- (princ)
- )
|