home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk21
/
dir01
/
f014270.re_
/
f014270.re
Wrap
Text File
|
1996-04-02
|
33KB
|
1,184 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1995) Bentley Systems, Inc., All rights reserved. |
| |
| "MicroStation" is a registered trademark and "MDL" and "MicroCSL" |
| are trademarks of Bentley Systems, Inc. |
| |
| Limited permission is hereby granted to reproduce and modify this |
| copyrighted material provided that the resulting code is used only |
| in conjunction with Bentley Systems products under the terms of the |
| license agreement provided therein, and that this notice is retained |
| in its entirety in any such reproduction or modification. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Logfile: J:/mdl/examples/doc/bspline.mcv $
| $Workfile: bspline.mc $
| $Revision: 5.3 $
| $Date: 20 Jun 1995 08:49:42 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| bspline.mc - examples for the mdlBspline_ functions. |
| |
| This file is intended as an adjunct to the MDL manual to |
| illustrate MDL built-in function calling conventions and parameter |
| values. While it can be compiled, it does NOT, on its own, |
| constitute a workable MDL example. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h> /* system include files */
#include <global.h>
#include <mselems.h>
#include <mdlbspln.h>
/*----------------------------------------------------------------------+
| |
| name defineACurve |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int defineACurve
(
MSBsplineCurve *curve
)
{
int status;
MSElementDescr *edP;
memset (curve, 0, sizeof (*curve));
curve->params.order = 3;
curve->params.numPoles = 5;
if ((status = mdlBspline_allocateCurve (&curve)) != SUCCESS)
return (status);
curve->poles[0].x = 0.0;
curve->poles[0].y = 10.0;
curve->poles[0].z = 5.0;
curve->poles[1].x = 1.0;
curve->poles[1].y = 10.0;
curve->poles[1].z = 10.0;
curve->poles[2].x = 2.0;
curve->poles[2].y = 10.0;
curve->poles[2].z = 15.0;
curve->poles[3].x = 3.0;
curve->poles[3].y = 10.0;
curve->poles[3].z = 20.0;
curve->poles[4].x = 4.0;
curve->poles[4].y = 10.0;
curve->poles[4].z = 25.0;
mdlBspline_computeKnotVector (curve->knots, &curve->params, NULL);
if ((status = mdlBspline_createCurve (&edP, NULL, curve)) == SUCCESS)
{
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_add (edP);
mdlElmdscr_freeAll (&edP);
}
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name defineASurface |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int defineASurface
(
MSBsplineSurface *surface
)
{
int status;
MSElementDescr *edP;
memset (surface, 0, sizeof (*surface));
surface->uParams.order = 3;
surface->uParams.numPoles = 4;
surface->vParams.order = 2;
surface->vParams.numPoles = 2;
if ((status = mdlBspline_allocateSurface (&surface)) != SUCCESS)
return (status);
surface->poles[0].x = 0.0;
surface->poles[0].y = 10.0;
surface->poles[0].z = 5.0;
surface->poles[1].x = 1.0;
surface->poles[1].y = 10.0;
surface->poles[1].z = 10.0;
surface->poles[2].x = 2.0;
surface->poles[2].y = 10.0;
surface->poles[2].z = 15.0;
surface->poles[3].x = 3.0;
surface->poles[3].y = 10.0;
surface->poles[3].z = 20.0;
surface->poles[4].x = 0.0;
surface->poles[4].y = 30.0;
surface->poles[4].z = 25.0;
surface->poles[5].x = 1.0;
surface->poles[5].y = 30.0;
surface->poles[5].z = 25.0;
surface->poles[6].x = 2.0;
surface->poles[6].y = 30.0;
surface->poles[6].z = 25.0;
surface->poles[7].x = 3.0;
surface->poles[7].y = 30.0;
surface->poles[7].z = 25.0;
mdlBspline_computeKnotVector (surface->uKnots, &surface->uParams, NULL);
mdlBspline_computeKnotVector (surface->vKnots, &surface->vParams, NULL);
if ((status = mdlBspline_createSurface (&edP, NULL, surface)) == SUCCESS)
{
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_add (edP);
mdlElmdscr_freeAll (&edP);
}
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name createASpiral |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Public void createASpiral
(
void
)
{
int status;
double initialRadius, finalRadius, sweepAngle;
Dpoint3d startPt, tangentPt, directionPt;
MSBsplineCurve curve;
MSElementDescr *edP;
memset (&curve, 0, sizeof(curve));
initialRadius = 1000.0;
finalRadius = 100.0;
sweepAngle = fc_pi;
startPt.x = 0.0;
startPt.y = 0.0;
startPt.z = 0.0;
tangentPt.x = 10.0;
tangentPt.y = 10.0;
tangentPt.z = 0.0;
directionPt.x = 10.0;
directionPt.y = 20.0;
directionPt.z = 0.0;
if (status = mdlBspline_spiral (&curve, initialRadius, finalRadius,
sweepAngle, &startPt, &tangentPt,
&directionPt))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
if (status = mdlBspline_createCurve (&edP, NULL, &curve))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
mdlBspline_freeCurve (&curve);
return;
}
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_add (edP);
mdlElmdscr_freeAll (&edP);
mdlBspline_freeCurve (&curve);
}
/*----------------------------------------------------------------------+
| |
| name createAHelix |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Public void createAHelix
(
void
)
{
int status;
double initialRadius, finalRadius, pitchHeight;
Dpoint3d startPt, axis1Pt, axis2Pt;
MSBsplineCurve curve;
MSElementDescr *edP;
memset (&curve, 0, sizeof(curve));
initialRadius = 1000.0;
finalRadius = 500.0;
pitchHeight = 10.0;
startPt.x = 1000.0;
startPt.y = 0.0;
startPt.z = 0.0;
axis1Pt.x = 0.0;
axis1Pt.y = 0.0;
axis1Pt.z = 0.0;
axis2Pt.x = 0.0;
axis2Pt.y = 10.0;
axis2Pt.z = 0.0;
if (status = mdlBspline_helix (&curve, initialRadius, finalRadius,
pitchHeight, &startPt,
&axis1Pt, &axis2Pt, TRUE))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
if (status = mdlBspline_createCurve (&edP, NULL, &curve))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
mdlBspline_freeCurve (&curve);
return;
}
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_add (edP);
mdlElmdscr_freeAll (&edP);
mdlBspline_freeCurve (&curve);
}
/*----------------------------------------------------------------------+
| |
| name displayKnotInfo |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Public void displayKnotInfo
(
MSBsplineCurve *curve,
double parameter
)
{
int i, status, index, totalKnots, numDistinct,
multiplicities[MAX_KNOTS], numInflects;
double knotTolerance, distinctKnots[MAX_KNOTS], greville[MAX_POLES];
knotTolerance = mdlBspline_knotTolerance (curve);
totalKnots = curve->params.closed ?
curve->params.numPoles + 2 * curve->params.order - 1 :
curve->params.numPoles + curve->params.order;
if (totalKnots > MAX_KNOTS)
return;
mdlBspline_getKnotMultiplicity (distinctKnots, multiplicities,
&numDistinct,
curve->knots, curve->params.numPoles,
curve->params.order, curve->params.closed,
knotTolerance);
for (i=0; i < numDistinct; i++)
printf ("Knot [#i] = %3.4f\n", i, distinctKnots[i]);
mdlBspline_computeGrevilleAbscissa (greville, curve->knots,
curve->params.numPoles,
curve->params.order,
curve->params.closed,
knotTolerance);
for (i=0; i < curve->params.numPoles; i++)
printf ("Greville Abscissa [#d] = %3.4f\n", i, greville[i]);
mdlBspline_findSpan (&index, curve->knots, curve->params.numPoles,
curve->params.order, curve->params.closed,
parameter);
printf ("Parameter value %3.4f is in span %d\n", parameter, index);
mdlBspline_inflectionPoints (NULL, NULL, &numInflects, curve, NULL);
printf ("The curve contains %d inflection points \n", numInflects);
}
/*----------------------------------------------------------------------+
| |
| name convertElementDescr |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int convertElementDescr
(
MSElementDescr **newEdP,
MSElementDescr *edP
)
{
int status;
MSBsplineCurve curve;
MSBsplineSurface surface;
MSElementDescr *endCaps;
if ((edP->el.ehdr.type == LINE_ELM) ||
(edP->el.ehdr.type == LINE_STRING_ELM) ||
(edP->el.ehdr.type == SHAPE_ELM) ||
(edP->el.ehdr.type == CURVE_ELM) ||
(edP->el.ehdr.type == CMPLX_STRING_ELM) ||
(edP->el.ehdr.type == CMPLX_SHAPE_ELM) ||
(edP->el.ehdr.type == ELLIPSE_ELM) ||
(edP->el.ehdr.type == ARC_ELM))
{
if ((status = mdlBspline_convertToCurve (&curve, edP)) ||
(status = mdlBspline_createCurve (newEdP, NULL, &curve)))
return (status);
mdlBspline_freeCurve (&curve);
}
else if ((edP->el.ehdr.type == SURFACE_ELM) ||
(edP->el.ehdr.type == CONE_ELM) ||
(edP->el.ehdr.type == SOLID_ELM))
{
if ((status = mdlBspline_convertToSurface (&surface, edP)) ||
(status = mdlBspline_createSurface (newEdP, NULL, &surface)))
return (status);
mdlBspline_freeSurface (&surface);
if (edP->el.ehdr.type == SOLID_ELM ||
(edP->el.ehdr.type == CONE_ELM && ! edP->el.cone_3d.b.surf))
{
if (status = mdlBspline_convertToEndcaps (&endCaps, edP))
return (status);
mdlElmdscr_addToChain (*newEdP, endCaps);
}
}
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name sampleCurvePoints |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void sampleCurvePoints
(
void
)
{
int i, status, numPoints;
Dpoint3d *points, line[2];
MSBsplineCurve curve;
MSElementUnion u;
if (status = defineACurve (&curve))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
numPoints = 50;
points = NULL;
if ((status = mdlBspline_evaluateCurve (&points, NULL, &numPoints, &curve))
!= SUCCESS)
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
for (i = 0; i < numPoints; i++)
{
line[0] = line[1] = points[i];
mdlLine_create (&u, NULL, line);
u.line_3d.dhdr.symb.b.weight = 5;
mdlElement_display (&u, NORMALDRAW);
}
/* Free the memory allocated by mdlBspline_evaluateCurve */
free (points);
mdlBspline_freeCurve (&curve);
}
/*----------------------------------------------------------------------+
| |
| name sampleSurfacePoints |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void sampleSurfacePoints
(
void
)
{
int i, status, numPoints[2];
Dpoint3d *points, line[2];
MSBsplineSurface surface;
MSElementUnion u;
if (status = defineASurface (&surface))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
numPoints[0] = 50;
numPoints[1] = 100;
points = NULL;
if ((status = mdlBspline_evaluateSurface (&points, NULL, numPoints,
&surface))
!= SUCCESS)
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
for (i = 0; i < numPoints[0]*numPoints[1]; i++)
{
line[0] = line[1] = points[i];
mdlLine_create (&u, NULL, line);
u.line_3d.dhdr.symb.b.weight = 5;
mdlElement_display (&u, NORMALDRAW);
}
/* Free the memory allocated by mdlBspline_evaluateSurface */
free (points);
mdlBspline_freeSurface (&surface);
}
/*----------------------------------------------------------------------+
| |
| name modifyBsplineCurve |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void modifyBsplineCurve
(
void
)
{
int i, status, action, intValue, numKnots;
double doubleValue, knotTolerance;
MSBsplineCurve curve, result;
MSElementDescr *edP=NULL;
memset (&result, 0, sizeof (result));
if (status = defineACurve (&curve))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
action = 0;
switch (action)
{
/* Reverse direction of curve */
case 0:
status = mdlBspline_reverseCurve (&result, &curve);
break;
/* Make into a multiple segment Bezier curve */
case 1:
status = mdlBspline_makeBezier (&result, &curve);
break;
/* Close curve */
case 2:
status = mdlBspline_closeCurve (&result, &curve);
break;
/* Open curve */
case 3:
doubleValue = fc_zero;
status = mdlBspline_openCurve (&result, &curve, doubleValue);
break;
/* Elevate the degree of the curve */
case 4:
intValue = 4;
status = mdlBspline_elevateDegree (&result, &curve, intValue);
break;
/* Add a knot to the knot vector of the curve */
case 5:
doubleValue = fc_onehalf;
status = mdlBspline_copyCurve (&result, &curve);
if (status == SUCCESS)
{
knotTolerance = mdlBspline_knotTolerance (&result);
status = mdlBspline_addKnot (&result, doubleValue,
knotTolerance,
intValue, TRUE);
}
break;
/* Change the weights of the curve */
case 6:
doubleValue = fc_onehalf;
status = mdlBspline_makeRational (&result, &curve);
if (status == SUCCESS)
{
mdlBspline_unWeightPoles (result.poles, result.poles,
result.weights, result.params.numPoles);
for (i=0; i < result.params.numPoles; i++)
result.weights[i] *= doubleValue;
mdlBspline_weightPoles (result.poles, result.poles,
result.weights, result.params.numPoles);
}
break;
/* Partially delete the curve */
case 7:
doubleValue = fc_onehalf;
status = mdlBspline_segmentCurve (&result, &curve,
fc_zero, doubleValue);
break;
/* Change the parameterization of the curve */
case 8:
status = mdlBspline_copyCurve (&result, &curve);
if (status == SUCCESS)
{
numKnots = result.params.closed ?
result.params.numPoles + 2 * result.params.order-1:
result.params.numPoles + result.params.order;
for (i=0; i < numKnots; i++)
result.knots[i] *= doubleValue;
mdlBspline_normalizeKnotVector (result.knots,
result.params.numPoles,
result.params.order,
result.params.closed);
}
break;
}
if (status)
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
else
{
mdlBspline_createCurve (&edP, NULL, &result);
mdlElmdscr_display (edP, 0, NORMALDRAW);
}
mdlBspline_freeCurve (&result);
mdlBspline_freeCurve (&curve);
mdlElmdscr_freeAll (&edP);
}
/*----------------------------------------------------------------------+
| |
| name modifyBsplineSurface |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void modifyBsplineSurface
(
void
)
{
int i, status, action, intValue;
double doubleValue;
Dpoint2d start, finish;
MSBsplineSurface surface, result;
MSElementDescr *edP=NULL;
memset (&result, 0, sizeof (result));
if (status = defineASurface (&surface))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
action = 0;
switch (action)
{
/* Make into a multiple patch Bezier surface */
case 0:
status = mdlBspline_makeBezierSurface (&result, &surface);
break;
/* Open surface in U direction */
case 1:
doubleValue = fc_zero;
status = mdlBspline_openSurface (&result, &surface,
doubleValue, BSSURF_U);
break;
/* Elevate the degree of the surface in V direction */
case 2:
intValue = 4;
status = mdlBspline_elevateDegreeSurface (&result, &surface,
intValue, BSSURF_V);
break;
/* Partially delete the surface */
case 3:
start.x = 0.2;
start.y = 0.0;
finish.x = 0.8;
finish.y = 0.8;
status = mdlBspline_segmentSurface (&result, &surface,
&start, &finish);
break;
}
if (status)
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
else
{
mdlBspline_createSurface (&edP, NULL, &result);
mdlElmdscr_display (edP, 0, NORMALDRAW);
}
mdlBspline_freeSurface (&result);
mdlBspline_freeSurface (&surface);
mdlElmdscr_freeAll (&edP);
}
/*----------------------------------------------------------------------+
| |
| name makeDerivedSurface |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void makeDerivedSurface
(
MSBsplineCurve *curve1,
MSBsplineCurve *curve2,
MSBsplineCurve *curve3,
MSBsplineCurve *curve4,
int surfaceType
)
{
int i, status;
double start, sweep;
Dpoint3d center, axis, delta;
Dvector3d orientation1, orientation2;
MSBsplineCurve curves[4];
MSBsplineSurface surface;
MSElementDescr *edP=NULL;
memset (&surface, 0, sizeof(surface));
memset (curves, 0, sizeof(curves));
switch (surfaceType)
{
case 0:
status = mdlBspline_ruledSurface (&surface, curve1, curve2);
break;
case 1:
if (!(status = mdlBspline_copyCurve (&curves[0], curve1)) ||
(status = mdlBspline_copyCurve (&curves[1], curve2)) ||
(status = mdlBspline_copyCurve (&curves[2], curve3)) ||
(status = mdlBspline_copyCurve (&curves[3], curve4)))
{
status = mdlBspline_coonsPatch (&surface, curves);
}
for (i=0; i < 4; i++)
mdlBspline_freeCurve (&curves[i]);
break;
case 2:
center.x = 0.0;
center.y = 0.0;
center.z = 0.0;
axis.x = 0.0;
axis.y = 0.0;
axis.z = 100.0;
start = fc_zero;
sweep = fc_pi;
status = mdlBspline_surfaceOfRevolution (&surface, curve1,
¢er, &axis, start, sweep);
break;
case 3:
delta.x = 0.0;
delta.y = 0.0;
delta.z = 100.0;
start = fc_zero;
sweep = fc_pi;
status = mdlBspline_surfaceOfProjection (&surface, curve1, &delta);
break;
case 4:
orientation1.org.x = 0.0; orientation1.org.x = 0.0;
orientation1.org.y = 0.0; orientation1.org.y = 1.0;
orientation1.org.z = 0.0; orientation1.org.z = 0.0;
orientation2.org.x = 0.0; orientation2.org.x = 1.0;
orientation2.org.y = 0.0; orientation2.org.y = 0.0;
orientation2.org.z = 0.0; orientation2.org.z = 0.0;
status = mdlBspline_skinPatch (&surface, curve1, curve2, curve3,
&orientation1, &orientation2,
TRUE);
break;
}
if (status)
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
else
{
mdlBspline_createSurface (&edP, NULL, &surface);
mdlElmdscr_display (edP, 0, NORMALDRAW);
}
mdlBspline_freeSurface (&surface);
mdlElmdscr_freeAll (&edP);
}
/*----------------------------------------------------------------------+
| |
| name makeCompatible |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int makeCompaible
(
MSBsplineCurve *curve1,
MSBsplineCurve *curve2,
MSBsplineCurve *curve3,
MSBsplineCurve *curve4,
int numberOfCurves
)
{
int i, status;
MSBsplineCurve *inputPtr[4], *compatiblePtr[4], compatibleCurves[4];
if (numberOfCurves > 4)
return (ERROR);
if (numberOfCurves == 1)
return (SUCCESS);
memset (compatibleCurves, 0, sizeof(compatibleCurves));
if (numberOfCurves == 2)
return mdlBspline_make2CurvesCompatible (curve1, curve2);
inputPtr[0] = curve1; inputPtr[1] = curve2;
inputPtr[2] = curve3; inputPtr[3] = curve4;
for (i=0; i < numberOfCurves; i++)
compatiblePtr[i] = &compatibleCurves[i];
if (status = mdlBspline_makeCurvesCompatible (compatiblePtr, inputPtr,
numberOfCurves))
return (status);
for (i=0; i < numberOfCurves; i++)
{
mdlBspline_freeCurve (inputPtr[i]);
*inputPtr[i] = *compatiblePtr[i];
}
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name imposeBoundary |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int imposeBoundary
(
MSBsplineSurface *surface,
MSBsplineCurve *boundary
)
{
int i, status, numPts;
double tolerance;
Dpoint3d *points=NULL, *pP;
Dvector3d direction;
MSElementUnion u;
MSElementDescr *edP=NULL;
tolerance = fc_10000;
if (status = mdlBspline_createCurve (&edP, NULL, boundary))
return (status);
else
{
mdlElmdscr_extractNormal (&direction.end, &direction.org, edP, NULL);
mdlElmdscr_freeAll (&edP);
}
if (status = mdlBspline_imposeBoundary (surface, boundary, tolerance,
&direction, &points, &numPts))
return (status);
for (i=0, pP=points; i < numPts; i++, pP++)
{
mdlLine_create (&u, NULL, pP);
u.line_3d.dhdr.symb.b.weight = 5;
mdlElement_display (&u, NORMALDRAW);
}
/* Free memory allocated in mdlBspline_imposeBoundary */
free (points);
if (status = mdlBspline_extractBoundary (&edP, surface, tolerance))
return (status);
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
}
/*----------------------------------------------------------------------+
| |
| name extractSurfaceCurves |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int extractSurfaceCurves
(
MSBsplineSurface *surface,
Dpoint3d *pt
)
{
int i, status;
double distance;
Dpoint2d parameter;
Dpoint3d closestPt;
MSBsplineCurve curve;
MSElementDescr *edP=NULL;
if (status = mdlBspline_minimumDistanceToSurface (&distance, &closestPt,
¶meter, pt, surface))
return (status);
if (status = mdlBspline_extractIsoCurve (&edP, surface,
parameter.x, BSSURF_U))
return (status);
else
{
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
}
if (status = mdlBspline_extractIsoCurve (&edP, surface,
parameter.y, BSSURF_V))
return (status);
else
{
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
}
memset (&curve, 0, sizeof (curve));
if (status = mdlBspline_extractProfile (&curve, surface))
return (status);
else
{
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
}
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name curveInfo |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int curveInfo
(
MSBsplineCurve *curve,
Dpoint3d *pt
)
{
int i, status;
double distance, parameter, wtDerv[3], curvature, torsion;
Dpoint3d closestPt, frame[3], line[2];
MSElementUnion u;
if (status = mdlBspline_minimumDistanceToCurve (&distance, &closestPt,
¶meter, pt, curve))
return (status);
if (status = mdlBspline_computeDerivatives (frame, wtDerv, curve, 2,
¶meter))
return (status);
if (status = mdlBspline_frenetFrame (frame, line, &curvature, &torsion,
curve, parameter))
return (status);
for (i=0; i < 3; i++)
{
mdlVec_projectPoint (line+1, line, frame+i, fc_10000);
mdlLine_create (&u, NULL, line);
mdlElement_display (&u, NORMALDRAW);
}
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name leastSquaresCurve |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void leastSquaresCurve
(
Dpoint3d *data,
int numDataPoints
)
{
int status;
MSBsplineCurve curve;
MSElementDescr *edP=NULL;
memset (&curve, 0, sizeof (curve));
curve.params.order = 3;
curve.params.numPoles = 5;
if (status = mdlBspline_leastSquaresToCurve (&curve, NULL, NULL, data,
NULL, numDataPoints))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
mdlBspline_createCurve (&edP, NULL, &curve);
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
mdlBspline_freeCurve (&curve);
}
/*----------------------------------------------------------------------+
| |
| name leastSquaresSurface |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void leastSquaresSurface
(
Dpoint3d *data,
int *numPointsInEachRow,
int numberOfRows
)
{
int status;
MSBsplineSurface surface;
MSElementDescr *edP=NULL;
memset (&surface, 0, sizeof (surface));
surface.uParams.order = 3;
surface.uParams.numPoles = 5;
surface.vParams.order = 2;
surface.vParams.numPoles = 4;
if (status = mdlBspline_leastSquaresToSurface (&surface, NULL, NULL,
data, NULL,
numPointsInEachRow,
numberOfRows))
{
mdlOutput_printf (MSG_ERROR, "ERROR : # %d", status);
return;
}
mdlBspline_createSurface (&edP, NULL, &surface);
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
mdlBspline_freeSurface (&surface);
}
/*----------------------------------------------------------------------+
| |
| name convertBackToNonBspline |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int convertBackToNonBspline
(
MSElementDescr **out,
MSElementDescr *in
)
{
int status;
MSBsplineCurve curve;
MSBsplineSurface surface;
if ((status = mdlBspline_convertToCurve (&curve, in)) == SUCCESS)
{
status = mdlBspline_extractFromCurve (out, &curve);
mdlBspline_freeCurve (&curve);
return (status);
}
else if ((status = mdlBspline_convertToSurface (&surface, in)) == SUCCESS)
{
status = mdlBspline_extractFromSurface (out, &surface);
mdlBspline_freeSurface (&surface);
return (status);
}
else
return (status);
}
/*----------------------------------------------------------------------+
| |
| name extractCurveInfo |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void extractCurveInfo
(
MSElementDescr *in
)
{
int type, rational;
double *weights, *knots;
Dpoint3d *poles;
BsplineParam params;
MSElementUnion header;
poles = (Dpoint3d *) 0;
knots = weights = (double *) 0;
mdlBspline_extractCurve (&header, &type, &rational, NULL, ¶ms,
&poles, &knots, &weights, in);
if (poles) free (poles);
if (knots) free (knots);
if (weights) free (weights);
}
/*----------------------------------------------------------------------+
| |
| name extractSurfaceInfo |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void extractSurfaceInfo
(
MSElementDescr *in
)
{
int type, rational, numBounds, holeOrigin;
double *weights, *uKnots, *vKnots;
Dpoint3d *poles;
BsplineParam uParams, vParams;
MSElementUnion header;
poles = (Dpoint3d *) 0;
uKnots = vKnots = weights = (double *) 0;
mdlBspline_extractSurface (&header, &type, &rational, NULL, &uParams,
&vParams, &poles, &uKnots, &vKnots, &weights,
&holeOrigin, &numBounds, NULL, in);
if (poles) free (poles);
if (uKnots) free (uKnots);
if (vKnots) free (vKnots);
if (weights) free (weights);
}
/*----------------------------------------------------------------------+
| |
| name appendCurves |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int appendCurve
(
MSBsplineCurve *curve1,
MSBsplineCurve *curve2
)
{
int status;
MSBsplineCurve result;
MSElementDescr *edP=NULL;
if (status = mdlBspline_appendCurves (&result, curve1, curve2))
return (status);
mdlBspline_createCurve (&edP, NULL, &result);
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
mdlBspline_freeCurve (&result);
return (SUCCESS);
}
/*----------------------------------------------------------------------+
| |
| name appendSurfaces |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private int appendSurface
(
MSBsplineSurface *surface1,
MSBsplineSurface *surface2
)
{
int status;
MSBsplineSurface result;
MSElementDescr *edP=NULL;
if (status = mdlBspline_appendSurfaces (&result, surface1, surface2,
BSSURF_U))
return (status);
mdlBspline_createSurface (&edP, NULL, &result);
mdlElmdscr_display (edP, 0, NORMALDRAW);
mdlElmdscr_freeAll (&edP);
mdlBspline_freeSurface (&result);
return (SUCCESS);
}