马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
曲面:AcDbSurface
实体:3DSOLID
ARX提供了AcGeCurveSurfInt,它可以让你获得3D曲线和曲面的交点。 AcGeCurveSurfInt构造方法或AcGeCurveSurfInt :: Set可输入曲线和曲面。 它需要AcGeSurface, 所以我们需要从AcDbSurface转换到AcGeSurface。 这需要AcBrBrep作为中间对象。
ARX实现代码如下:
[C++] 纯文本查看 复制代码
static AcGePoint3dArray Intersect(AcDbSurface* pSurface, AcGeLine3d line)
{
AcGePoint3dArray returnPtArray;
AcDbBody* pBody = new AcDbBody();
// 2013
// Acad::ErrorStatus es = pBody->setASMBody(pSurface->ASMBodyCopy());
//before 20123
Acad::ErrorStatus es = pBody->setBody(pSurface->body());
//build AcBrBrep
AcBrBrep* pBrep = new AcBrBrep();
//
if (AcBr::eOk == pBrep->set(*pBody))
{
AcBrBrepFaceTraverser* pFaceTrav = new AcBrBrepFaceTraverser;
if (AcBr::eOk == pFaceTrav->setBrep(*pBrep))
{
for (pFaceTrav->restart(); !pFaceTrav->done(); pFaceTrav->next())
{
AcBrFace face;
if (AcBr::eOk == pFaceTrav->getFace(face))
{
double area = 0.0f;
face.getSurfaceArea(area);
acutPrintf(L"\nSurface Area: %f", area);
//*****whole surface of the Brep face******
//AcGeNurbSurface nurbSurface;
//face.getSurfaceAsNurb(nurbSurface);
//AcGeCurveSurfInt curveSI;
////input the curve and line
//curveSI.set(line,nurbSurface);
////get the count of intersect points
//int count = curveSI.numIntPoints(err_1);
// if(err_1 == AcGe::kXXOk && count >0 )
// {
// AcGeIntersectError err_2;
// for(int index = 0 ;index < count; index ++)
// {
// AcGePoint3d pt =
// curveSI.intPoint(index,err_2);
// returnPtArray.append(pt);
// }
//
// }
//**********
//****real surface of the orignal AcDbSurface
AcGeExternalBoundedSurface** nurbs = NULL;
Adesk::UInt32 numNurbs = 0;
face.getSurfaceAsTrimmedNurbs(numNurbs, nurbs);
//*****
for (Adesk::UInt32 i = 0; i < numNurbs; i++)
{
AcGeCurveSurfInt curveSI;
AcGeIntersectError err_1 = AcGe::kXXOk;
//input the curve and line
curveSI.set(line, *nurbs[i]);
//get the count of intersect points
int count = curveSI.numIntPoints(err_1);
if (err_1 == AcGe::kXXOk && count >0)
{
AcGeIntersectError err_2;
for (int index = 0; index < count; index++)
{
AcGePoint3d pt =
curveSI.intPoint(index, err_2);
returnPtArray.append(pt);
}
}
delete nurbs[i];
}
// your responsibility to delete the
// array of surfaces
delete[] nurbs;
}
}
}
delete pFaceTrav;
}
delete pBrep;
return returnPtArray;
}
static void getIntersectPts(void)
{
ads_name ename;
ads_point pickpt;
AcDbObjectId objId;
AcDbObject *pObj;
int rc;
// select a surface
rc = acedEntSel(L"\nSelect Surface: ", ename, pickpt);
if (rc != RTNORM)
{
if (rc != RTCAN)
acutPrintf(L"\nError selecting entity ");
return;
}
acdbGetObjectId(objId, ename);
acdbOpenObject(pObj, objId, AcDb::kForRead);
AcDbSurface* pEntity1 = AcDbSurface::cast(pObj);
if (!pEntity1)
{
acutPrintf(L"\nSelection Invalid...");
pObj->close();
return;
}
// call Intersect
AcGePoint3dArray points =
Intersect(pEntity1, AcGeLine3d(AcGePoint3d(0, 0, 0),
AcGePoint3d(0, 0, 1)));
if (points.length() >0)
{
// iterate the points
}
pObj->close();
}
下面是XDRX API 的ACBR库函数的LISP实现上面ARX功能的代码:
 - (defun c:tt ()
- (defun _traversface (e ln)
- (setq gln (xdge::constructor ln))
- ;;构建直线几何对象AcGeLineSeg3d
- (setq body (xdrx_body_make))
- ;;创建一个内存AcDbBody对象
- (xdrx_set_body body e)
- ;;将选取的曲面或3DSOLID对象的模型数据设置到BODY对象
- (setq br (xdbr::constructor body))
- ;;从BODY创建AcBrBrep
- (setq tr (xdbr::constructor "brepfacetraverser" br))
- ;;构建Brep->Face遍历器
- ;;FACE遍历
- (setq i 0
- ints nil
- )
- (while (not (xdbr::traverser:done tr))
- (if (setq face (xdbr::getpropertyvalue tr "face"))
- ;;当前遍历位置获得AcBrFace
- (progn
- (setq gface (xdbr::getpropertyvalue face "SurfaceAsTrimmedNurbs"))
- ;;AcBrFace->SurfaceAsTrimmedNurbs几何对象
- (setq j -1)
- (repeat (length gface)
- (setq gface1 (nth (setq j (1+ j)) gface))
- (setq mInt (xdge::constructor "kCurveSurfaceInt" gln gface1))
- ;;构建曲线和曲面求交kCurveSurfaceInt对象
- (if (> (xdge::getpropertyvalue mint "numintpoints") 0)
- ;;交点数大于0
- (progn
- (setq ar (xdbr::getpropertyvalue face "area"))
- (xdrx_prompt (xdrx_string_format "\n发现交点,Surface[%d] Area: %f"
- (setq i (1+ i))
- ar
- )
- )
- (setq ints (cons (xdge::getpropertyvalue mint "intpoints") ints))
- ;;交点保存到全局变量
- )
- )
- )
- (xdrx_object_release face)
- )
- )
- (xdbr::traverser:next tr)
- )
- (xdrx_setvar "pdmode" 35)
- (xdrx_entity_setcolor (xdrx_point_make ints) 2)
- (xdrx_object_release tr br body)
- )
- (if
- (and
- (setq e (car (xdrx_entsel "\n选取曲面、3DSOLID<退出>:" '((0 . "SURFACE,3DSOLID")))))
- (setq ln (car (xdrx_entsel "\n选择直线<退出>:" '((0 . "LINE")))))
- )
- (progn (xdrx_begin) (_traversface e ln) (xdrx_end))
- )
- (princ)
- )
|