- UID
- 42
- 积分
- 2687
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-9
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- // includes from ObjectARX Wizard
- #include "acdb.h" // acdb definitions
- #include "adslib.h" // ads defs
- #include "aced.h" // aced stuff
- #include "dbsymtb.h" // symboltables
- #include "rxregsvc.h" // unlock application
- #include "dbcurve.h"
- #include "gevec3d.h"
- #include "dbray.h"
- #include "dbautil.h"
- #include "geassign.h"
- #include "dbents.h"
- // entry point for this application
- extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void* );
- // message handlers
- // helper functions
- static void initApp (void);
- static void unloadApp(void);
- void utilsisinside (void );
- // end of declaration
- /////////////////////////////////////////////////////////////////////
- // acrxEntryPoint(internal)
- // This function is the entry point for your application.
- /////////////////////////////////////////////////////////////////////
- AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)
- {
- switch (msg) {
- case AcRx::kInitAppMsg:
- acrxUnlockApplication(ptr);
- initApp();
- break;
- case AcRx::kUnloadAppMsg:
- unloadApp();
- break;
- default:
- break;
- }
- return AcRx::kRetOK;
- }
- static void initApp(void)
- {
- // register your autocad commands
- acedRegCmds->addCommand("UTILS", "ISINSIDE", "ISINSIDE", ACRX_CMD_MODAL,
- utilsisinside);
- } // END initApp()
- static void unloadApp(void)
- {
- // unregister your autocad commands
- acedRegCmds->removeGroup("UTILS");
- // END unloadApp()
- }
- enum IncidenceType {
- kIncidenceToLeft = 0,
- kIncidenceToRight = 1,
- kIncidenceToFront =2,
- kIncidenceUnknown };
- IncidenceType CurveIncidence(AcDbCurve*pCurve, double param, AcGeVector3d
- dir, AcGeVector3d normal )
- {
- AcGeVector3d deriv1;
- pCurve->getFirstDeriv( param, deriv1 );
- if( deriv1.isParallelTo( dir )) {
- // need second degree analysis
- AcGeVector3d deriv2;
- pCurve->getSecondDeriv( param, deriv2 );
- if( deriv2.isZeroLength() || deriv2.isParallelTo( dir ) ) {
- return kIncidenceToFront;
- } else if(deriv2.crossProduct( dir ).dotProduct( normal ) < 0 ) {
- return kIncidenceToRight;
- } else {
- return kIncidenceToLeft;
- }
- }
-
- if( deriv1.crossProduct( dir ).dotProduct( normal ) < 0 ) {
- return kIncidenceToLeft;
- } else {
- return kIncidenceToRight;
- }
- }
- Adesk::Boolean IsInsideCurve(AcDbCurve*pCurve, AcGePoint3d testPt )
- {
- if(!pCurve->isClosed() || !pCurve) {
- // cannot be inside
- return Adesk::kFalse;
- }
- Acad::ErrorStatus es;
- AcDb2dPolyline*p2dPoly = AcDb2dPolyline::cast(pCurve);
- if( p2dPoly != NULL && p2dPoly->polyType() != AcDb::k2dSimplePoly ) {
- // Not supported
- return Adesk::kFalse;
- }
- AcGePoint3d ptOnCurve;
- es = pCurve->getClosestPointTo(testPt, ptOnCurve );
- if( testPt == ptOnCurve ) {
- return Adesk::kTrue;
- }
- // check its planar
- AcGePlane plane;
- AcDb::Planarity planarity;
- es = pCurve->getPlane(plane, planarity );
- if( es != Acad::eOk || planarity != AcDb::kPlanar ) {
- return Adesk::kFalse;
- }
- // make the test ray from the plane
- AcGeVector3d normal = plane.normal();
- AcGeVector3d testVector = normal.perpVector();
- AcDbRay ray;
- ray.setBasePoint(testPt);
- ray.setUnitDir(testVector);
- AcGePoint3dArray IntersectionPoints;
- // fire the ray at the curve
- es = pCurve->intersectWith(&ray, AcDb::kOnBothOperands,
- IntersectionPoints);
- if(es != Acad::eOk) {
- return Adesk::kFalse;
- }
- int numberOfInters = IntersectionPoints.length();
- if(numberOfInters == 0) {
- // must be outside
- return Adesk::kFalse;
- }
- int nGlancingHits = 0;
- double epsilon = 2e-6; // ( trust me on this )
- for( int i=0;i < numberOfInters; i++ ) {
- // get the first point, and get its parameter
- AcGePoint3d hitPt = IntersectionPoints[i];
- double hitParam;
- es = pCurve->getParamAtPoint(hitPt, hitParam );
- if(es != Acad::eOk) {
- return Adesk::kFalse;
- }
- double inParam = hitParam - epsilon;
- double outParam = hitParam + epsilon;
- IncidenceType inIncidence = CurveIncidence(pCurve, inParam,
- testVector, normal );
- IncidenceType outIncidence = CurveIncidence(pCurve, outParam,
- testVector, normal );
- if( ( inIncidence == kIncidenceToRight && outIncidence ==
- kIncidenceToLeft ) ||
- ( inIncidence == kIncidenceToLeft && outIncidence ==
- kIncidenceToRight ) )
- {
- nGlancingHits ++;
- }
- }
- return (( numberOfInters + nGlancingHits) % 2 == 1);
- }
- void utilsisinside()
- {
- ads_name eName;
- ads_point pt;
- if( RTNORM != ads_entsel( "\nPlease pick a curve ", eName, pt ) ) {
- return;
- }
- AcDbObjectId curveId;
- acdbGetObjectId( curveId, eName );
- AcDbCurve*pCurve = NULL;
- acdbOpenObject(pCurve, curveId, AcDb::kForRead );
- if( pCurve == NULL ) {
- return;
- }
- while( RTNORM == ads_getpoint( NULL, "\nPlease pick a point ", pt ) ) {
- acdbUcs2Wcs( pt, pt, Adesk::kFalse );
-
- Adesk::Boolean isIn;
- isIn = IsInsideCurve( pCurve, asPnt3d( pt ) );
- ads_printf("\n%s", isIn ? "INSIDE OR ON" : "OUTSIDE" );
-
- }
- pCurve->close();
- }
复制代码 |
|