|
#include <aced.h>
#include <adslib.h>
#include <geassign.h> // asDblArray
#include <gecone.h>
#include <gessint.h>
#include <dbxutil.h> // acdbWcs2Ucs
void dcgMdtDrawInfo(const AcGeCurve3d* crv,short color)
{
// ads_printf("\nCurve is a %d", crv->type() );
AcGeInterval iv; double lb,ub; double nominalRange = 10.0;
crv->getInterval(iv);
if( iv.isUnBounded() )
{
ads_printf("\nCurve is unbounded");
lb = -(nominalRange / 2.0);
ub = nominalRange / 2.0;
}
else
{
iv.getBounds(lb,ub);
if( iv.isBounded() )
{
ads_printf("\nCurve is bounded");
}
else if( iv.isBoundedBelow() )
{
ads_printf("\nCurve is unbounded above");
ub = lb + nominalRange;
}
else
{
ads_printf("\nCurve is unbounded below");
lb = ub - nominalRange;
}
}
ads_printf("\nBounds of curve [lower,upper] = [%.3lf,%.3lf]",lb,ub);
AcGePoint3dArray pts;
AcGeDoubleArray params;
crv->getSamplePoints( lb, ub, 0.01, pts, params );
int nPts = pts.length();
AcGePoint3d start = pts[0];
acdbWcs2Ucs(asDblArray(start),asDblArray(start),Adesk::kFalse);
ads_printf("\nGot %d sample points",nPts);
for( int i=1;i<nPts; i++ )
{
AcGePoint3d end = pts;
ads_printf("\nSamplePoint [%d] = (%.3lf,%.3lf,%.3lf)",i,pts.x,pts.y,pts.z);
acdbWcs2Ucs(asDblArray(end),asDblArray(end),Adesk::kFalse);
ads_grdraw(asDblArray(start),asDblArray(end),color,0);
start = end;
}
}
void dcgMdtDrawInfo(const AcGeSurface* srf,int color)
{
AcGeInterval vi,ui;
double vlb,vub,ulb,uub; srf->getEnvelope(ui,vi);
vi.getBounds(vlb,vub); ui.getBounds(ulb,uub);
double vstep = (vub-vlb) / 4;
AcGePoint3d p1,p2;
double ustep = (uub - ulb) / 100;
AcGePoint2d param(ulb,vlb);
p1 = srf->evalPoint(param);
while(param.y < vub)
{
param.x = ulb;
p1 = srf->evalPoint(param);
acdbWcs2Ucs(asDblArray(p1),asDblArray(p1),Adesk::kFalse);
while(param.x < uub)
{
param.x += ustep;
p2 = srf->evalPoint(param);
acdbWcs2Ucs(asDblArray(p2),asDblArray(p2),Adesk::kFalse);
ads_grdraw(asDblArray(p1),asDblArray(p2),color,0);
p1 = p2;
}
param.y += vstep;
}
param.y = vub;
param.x = ulb;
p1 = srf->evalPoint(param);
while(param.x < uub)
{
param.x += ustep;
p2 = srf->evalPoint(param);
acdbWcs2Ucs(asDblArray(p2),asDblArray(p2),Adesk::kFalse);
ads_grdraw(asDblArray(p1),asDblArray(p2),color,0);
p1 = p2;
}
param.y += vstep;
vstep = (vub-vlb) / 100;
ustep = (uub - ulb) / 4;
param.set(ulb,vlb);
while(param.x < uub)
{
param.y = vlb;
p1 = srf->evalPoint(param);
while(param.y < vub)
{
param.y += vstep;
p2 = srf->evalPoint(param);
acdbWcs2Ucs(asDblArray(p2),asDblArray(p2),Adesk::kFalse);
ads_grdraw(asDblArray(p1),asDblArray(p2),color,0);
p1 = p2;
}
param.x += ustep;
}
param.x = uub;
param.y = vlb;
p1 = srf->evalPoint(param);
while(param.y < vub)
{
param.y += vstep;
p2 = srf->evalPoint(param);
acdbWcs2Ucs(asDblArray(p2),asDblArray(p2),Adesk::kFalse);
ads_grdraw(asDblArray(p1),asDblArray(p2),color,0);
p1 = p2;
}
param.x += ustep;
}
void printInfo(AcGe::ssiConfig config)
{
switch(config)
{
case AcGe::kXOut :
ads_printf("\n kXOut : Curve neighborhood is outside the surface.");
break;
case AcGe::kXIn: ads_printf("\n kXIn : Curve neighborhood is inside the surface.");
break;
case AcGe::kXTanOut : ads_printf("\n kXTanOut : Curve neighborhood is outside the surface.");
break;
case AcGe::kXTanIn : ads_printf("\n kXTanIn : Curve neighborhood is inside the surface.");
break;
default :
ads_printf("\n unknown ssiConfig %d",config);
break;
}
}
void getIntConfigs(const AcGeSurfSurfInt& surfInt)
{
AcGeIntersectError err;
int numResult = surfInt.numResults(err);
int dim;
AcGe::ssiConfig surf1Left,surf1Right,surf2Left,surf2Right;
AcGe::ssiType intType;
ads_printf("\n Configs of intersection : ");
for(int i=0;i<numResult;i++)
{
surfInt.getIntConfigs(i,surf1Left,surf1Right,surf2Left,surf2Right,intType,dim,err);
ads_printf("\n Intersection %d",i);
ads_printf("\n surf1Left : "); printInfo(surf1Left);
ads_printf("\n dim = %d",dim);
}
}
int testfun()
{
double cosineAngle = 0.7071067811865;
double sineAngle = - 0.7071067811865;
AcGePoint3d origin(0,0,0);
double radius = 2;
AcGeVector3d axis(0,0,1);
AcGeIntersectError err;
Boolean isExternal = kTrue; // Draw the cone with ads_grdraw for visualization
AcGeCone geCone(cosineAngle,sineAngle,origin,radius,axis);
dcgMdtDrawInfo(&geCone,3);
ads_printf("\nFirst test case : "); // take the same cone and intersect it with a xz-plane
AcGeCone hCone(cosineAngle,sineAngle,origin,radius,axis);
AcGePlane hPlane(AcGePoint3d(0,0,0),AcGeVector3d(0,0,1));
AcGeSurfSurfInt surfSurfInt(hCone,hPlane);
getIntConfigs(surfSurfInt);
int numInters = surfSurfInt.numResults(err);
ads_printf("\nGot %d intersections : err = %d",numInters,err);
AcGeCurve3d* pIntersCurve;
for(int k=0;k<numInters;k++)
{
pIntersCurve = surfSurfInt.intCurve(k,isExternal,err);
ads_printf("\nsurfSurfInt: err = %d",numInters,err);
if(pIntersCurve)
dcgMdtDrawInfo(pIntersCurve,1);
} // intersect the cone with another plane
ads_printf("\n\nSecond test case : ");
AcGePlane hPlane2(AcGePoint3d(0,0,1.0),AcGeVector3d(0.1, 0, 1.0));
AcGeSurfSurfInt surfSurfInt2(hCone,hPlane2);
getIntConfigs(surfSurfInt2);
numInters = surfSurfInt2.numResults(err);
ads_printf("\nGot %d intersections : err = %d",numInters,err);
for(k=0;k<numInters;k++)
{
pIntersCurve = surfSurfInt2.intCurve(k,isExternal,err);
ads_printf("\nsurfSurfInt: err = %d",numInters,err);
if(pIntersCurve)
dcgMdtDrawInfo(pIntersCurve,1);
}
// intersect the cone with a plane on the cones tip
ads_printf("\n\nThird test case : ");
AcGePlane hPlane3(AcGePoint3d(0,0,2),AcGeVector3d(0,0,1));
AcGeSurfSurfInt surfSurfInt3(hCone,hPlane3);
getIntConfigs(surfSurfInt3);
numInters = surfSurfInt3.numResults(err);
ads_printf("\nGot %d intersections : err = %d",numInters,err);
AcGePoint3d isPoint;
for(k=0;k<numInters;k++)
{
isPoint = surfSurfInt3.intPoint(k,err);
ads_printf("\nIntersection point at (%.3lf,%.3lf,%.3lf)",isPoint.x,isPoint.y,isPoint.z);
}
return 1;
} |
|