# Surface modeling. Part4

*(continued...)***Constructing arbitrary sweep surfaces**

GeomFill algorithms considered in the previous posts internally use Approx_SweepFunction subclasses that define particular techniques to calculate cross-sections.

You can create your own subclass to model a particular sweep surface. Approx_SweepFunction has a few pure virtual methods which your subclass must redefine. For instance, in ACIS-SAT import for CAD Exchanger I use it to generate variable-radius surfaces. In ACIS, such surfaces are defined with the help of so called support surfaces (left and right), path curve, left and right radius functions, cross-section forms (circular, elliptical, chamfer, etc). Below is an example of such surface (in dark yellow) with elliptical section; support surfaces are in green and bright yellow, and path is red.

Here is an exceprt of the method that calculates a cross section at parameter along the path:

Standard_Boolean ACISAlgo_VarBlendSweepFunction::D0 (const Standard_Real theParam,

const Standard_Real,

const Standard_Real,

TColgp_Array1OfPnt& thePoles,

TColgp_Array1OfPnt2d&,

TColStd_Array1OfReal& theWeights)

{

gp_Pnt2d aLRad, aRRad;

// left radius

aLRad = myLRad->Value(theParam);

// right radius

if (myRRad == myLRad) {

aRRad = aLRad;

} else {

aRRad = myRRad->Value(R2Param);

}

gp_Pnt aPathPnt;

gp_Vec aNormal;

myPath->D1 (theParam, aPathPnt, aNormal);

const gp_Ax2 Axis (aPathPnt, aNormal);

const gp_Pln aSecPln (Axis);

Handle(Geom_Plane) aGSecPln = new Geom_Plane(Axis);

//intersection of a section plan with support surfaces

Handle(TColGeom2d_HArray1OfCurve) aLCArr, aRCArr;

if (!::Intersect (aGSecPln, aSecPln, myLSurf, aLCArr) || !::Intersect (aGSecPln, aSecPln, myRSurf, aRCArr))

return Standard_False;

//compute a section in 2D and restore it into 3D

const Standard_Integer n = thePoles.Upper();

TColgp_Array1OfPnt2d aPArr (1, n);

if (!mySec->ComputeSection (Axis, aLCArr, aLRad, aRCArr, aRRad, aPArr, theWeights))

return Standard_False;

for (Standard_Integer i = 1; i <= n; i++) {

thePoles.SetValue (i, ElCLib::To3d (Axis, aPArr (i)));

}

return Standard_True;

}

The above redefined virtual method D0() populates poles and weights arrays of the B-Spline curve which defines a cross-section.

Here is how to construct your surface using Approx_SweepFunction subclass:

...

Handle(ACISAlgo_VarBlendSweepFunction) aSweep = new ACISAlgo_VarBlendSweepFunction (...);

Approx_SweepApproximation anApprox (aSweep);

const Standard_Real aTol = 1e-4;

anApprox.Perform (aHPath->FirstParameter(), aHPath->LastParameter(), aTol, aTol,

Precision::Parametric (aTol), 1-3,

(GeomAbs_Shape)Min (GeomAbs_C1, aHPath->Continuity()), BSplCLib::MaxDegree(), aMaxSeg);

Handle(Geom_Surface) aRes;

if (anApprox.IsDone()) {

aRes = new Geom_BSplineSurface(anApprox.SurfPoles(),

anApprox.SurfWeights(), anApprox.SurfUKnots(), anApprox.SurfVKnots(),

anApprox.SurfUMults(), anApprox.SurfVMults(),

anApprox.UDegree(), anApprox.VDegree());

I guess using the above technique you can create arbitrary sweep surfaces, e.g. like the one below:

**Topological algorithms**

As mentioned in the first post of this series, as a rule Open CASCADE offers algorithms both at geometrical and topological level. Until now I was mainly focused on the geometrical level (just because I myself used it :-)). Let me try to give a brief mapping with a topo one:

1. Sweep of 1 curve along the other (including pipe with constant section)

a. GeomFill_Pipe (path, profile)

b. BRepOffsetAPI_Pipe (path, profile)

2. Pipe with constant radius (tube-like):

a. GeomFill_Pipe (path, radius):

b. BRepOffsetAPI_Pipe (path, profile) where profile must be pre-created

3. Pipe with constant radius with rail curves

a. GeomFill_Pipe (path, radius, rail1, rail2)

b. Unsupported ?

4. Pipe with variable radius

a. GeomFill_Sweep (path, radius_function)

b. Unsupported ?

Note that topo algorithms can use elements of diffent dimensions for profile object. This defines a type of a result. For instance, a pipe of vertex will generate an edge, edge – face, wire – shell, face-solid, etc.

Brief note on BRepOffsetAPI_MakePipeShell. As it works with wire spines, it must be able to deal with discontinuties between the edges (when edges intersect with sharp edges). It offers 3 modes:

- intersection and rounding

- extension and intersection

- modifying trihedron mode used when sweeping a profile along the following edge in a spine.

The following picture shows these modes respectively in red, green and blue:*To be continued...*

## 0 comments