|
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //Description: fKeepExtremes
- //1) Function to check for the minimum/maximum X and Y.
- //2) mPtMin and mPtMax will have minimum/maximum X and Y
- ///////////////////////////////////////////////////////////////////////////////////////////////
- void fKeepExtremes(AcGePoint3d& mPtSample,AcGePoint3d& mPtMin,AcGePoint3d& mPtMax)
- {
- //test for max
- if(mPtSample.x > mPtMax.x) mPtMax.x = mPtSample.x;
- if(mPtSample.y > mPtMax.y) mPtMax.y = mPtSample.y;
- if(mPtSample.z > mPtMax.z) mPtMax.z = mPtSample.z;
- //test for min
- if(mPtSample.x < mPtMin.x) mPtMin.x = mPtSample.x;
- if(mPtSample.y < mPtMin.y) mPtMin.y = mPtSample.y;
- if(mPtSample.z > mPtMax.z) mPtMax.z = mPtSample.z;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //Description: fGetBoundingBoxBySampling
- //1) Function to divide the AcDbSpline 1e6 times and check for points at each division
- ///////////////////////////////////////////////////////////////////////////////////////////////
- void fGetBoundingBoxBySampling(AcDbSpline *pSpline,AcGePoint3d& mPtMin, AcGePoint3d& mPtMax)
- {
- double mParam;
- double mIncr;
- double mStartParam;
- double mEndParam;
- AcGePoint3d mPtTemp;
- pSpline->getStartPoint(mPtTemp);
- pSpline->getParamAtPoint(mPtTemp,mStartParam);
- pSpline->getEndPoint(mPtTemp);
- pSpline->getParamAtPoint(mPtTemp,mEndParam);
- //calculate the division
- mIncr = (mEndParam - mStartParam)/1e6; //1e6 is the sampling tolerance
- //set the seed point for max and min. It is set to the start point
- mPtMax = mPtTemp;
- mPtMin = mPtTemp;
- for(mParam = mStartParam;mParam <= mEndParam;mParam +=mIncr)
- {
- if(Acad::eOk == pSpline->getPointAtParam(mParam,mPtTemp))
- {
- fKeepExtremes(mPtTemp,mPtMin,mPtMax);
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //Description: fDrawRect
- //1) Draws a LwPolyline rectangle given lower left and upper right corners
- ///////////////////////////////////////////////////////////////////////////////////////////////
- void fDrawRect(AcGePoint3d& mPtMin,AcGePoint3d& mPtMax,int mColor)
- {
- AcDbPolyline *pPline = new AcDbPolyline(4);
- pPline->addVertexAt(0, AcGePoint2d(mPtMin.x,mPtMin.y));
- pPline->addVertexAt(1,AcGePoint2d(mPtMax.x,mPtMin.y));
- pPline->addVertexAt(2,AcGePoint2d(mPtMax.x,mPtMax.y));
- pPline->addVertexAt(3,AcGePoint2d(mPtMin.x,mPtMax.y));
- pPline->setClosed(Adesk::kTrue);
- fAddEntToDwg(acdbHostApplicationServices()->workingDatabase(),pPline);
- pPline->setColorIndex(mColor);
- pPline->close();
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //Description: SplineBB
- //1) command 'SplineBB'
- ///////////////////////////////////////////////////////////////////////////////////////////////
- void SplineBB()
- {
- AcDbEntity *pEnt = NULL;
- AcDbObjectId mId;
- ads采用point mPt;
- ads采用name mEname;
- //select the entity
- if ( RTNORM == acedEntSel(L"Select a Spline", mEname, mPt))
- {
- if ( Acad::eOk == acdbGetObjectId(mId, mEname ))
- {
- acdbOpenAcDbEntity(pEnt, mId, AcDb::kForRead);
- }
- }
- else
- {
- return;
- }
- //see if it is a spline
- AcDbSpline *pSpline = NULL;
- if (NULL != pEnt)
- {
- pSpline = AcDbSpline::cast(pEnt);
- if(NULL != pSpline)
- {
- AcGePoint3d mPtMin,mPtMax;
- //draw the bounding box returned by spline's getGeomExtents
- AcDbExtents mExts;
- pSpline->getGeomExtents(mExts);
- //draw bounding box returned by the spline in red
- fDrawRect(mExts.minPoint(),mExts.maxPoint(),1);
- //calculate the time taken
- struct 采用timeb t1,t2;
- 采用ftime(&t1);
- //calculate the bounding box
- fGetBoundingBoxBySampling(pSpline,mPtMin,mPtMax);
- 采用ftime(&t2);
- acutPrintf(L"\nMethod Time %6.2f seconds.\n", (t2.time + (double)(t2.millitm)/1000) - (t1.time + (double)(t1.millitm)/1000) );
- //draw calculated bounding box in yellow
- fDrawRect(mPtMin,mPtMax,2);
- pSpline->close();
- }
- else
- {
- acutPrintf(L"\nEntity is not an Spline");
- pEnt->close();
- }
- }
- return;
- }
复制代码 |
|