Adding surface to Brep Primitives

Hello

Huge thanks firstly for responding to the earlier queries.

I have used BrepPrimAPI_MakeCone/BRepPrimAPI_MakeCylinder for creation of these primitives. To display the primitives in another application I iterate through the list of faces and create the face display data(for each face). I am using the following code : /*===============================*/ TopExp_Explorer ExpFace; TopLoc_Location l;

for (ExpFace.Init (myShape,TopAbs_FACE); ExpFace.More(); ExpFace.Next()) {

TopoDS_Face TopologicalFace = TopoDS::Face (ExpFace.Current());

TopologicalFace.Orientation (TopAbs_FORWARD) ;

AddFaceDisplay(TopologicalFace, displaydata); // create face display data } /*=================================*/

The AddFaceDisplay function adds the display of the face as line segments in the list displaydata. This list is written out and displayed by my display program.

The code that computes the display data is as follows

/*****************************************/ AddFaceDisplay(TopoDS_Face& TopologicalFace, Segments& cdd) { Standard_Real UFirst, VFirst, ULast, VLast;

BRepAdaptor_Surface bas(F,Standard_True); UFirst = bas.FirstUParameter(); ULast = bas.LastUParameter(); VFirst = bas.FirstVParameter(); VLast = bas.LastVParameter(); GeomAdaptor_Surface S = bas.Surface(); Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(S); Adaptor3d_IsoCurve C(HS);

Standard_Integer i, j;

Standard_Real Du = (ULast - UFirst) / (nbUIsos + 1); Standard_Real U = UFirst; for (i = 1; i

U += Du;

DrawIsoCurveOn(C,GeomAbs_IsoU,U,VFirst,VLast, cdd); }

Standard_Real Dv = (VLast - VFirst) / (nbVIsos + 1); Standard_Real V = VFirst; for (j = 1; j

V += Dv;

DrawIsoCurveOn(C,GeomAbs_IsoV,V,UFirst,ULast, cdd); }

// draw bounds DrawIsoCurveOn(C,GeomAbs_IsoU,UFirst,VFirst,VLast, cdd); DrawIsoCurveOn(C,GeomAbs_IsoU,ULast ,VFirst,VLast, cdd); DrawIsoCurveOn(C,GeomAbs_IsoV,VFirst,UFirst,ULast, cdd); DrawIsoCurveOn(C,GeomAbs_IsoV,VLast ,UFirst,ULast, cdd); }

/********************************************/

This code is the same as the code for displaying surfaces in the Draw package.

The PROBLEM I am facing with this is that the top and bottom faces of the cone/ cylinder are not trimmed to the circular boundaries. I get the top/bottom faces extending beyond the cone/cyl boundary. Kindly help me to solve this.

The same code displays a Box/Torus/sphere correctly.

regards Prasad

Igor Feoktistov's picture

Hi again,

probably your problem is that for top and bottom faces of cylinder and cone underliing geometry (surfaces) is infinite plane with UFirst, ULast, VFirst, VLast = +- infinite (really +-1.e100). You should use additional information about origins and radii to restrict parametric range for your isocurves.

For boxes each face is based on trimmed plane, that is why for box all is OK. For sphere and torus surfaces are restricted by default.

Igor

G. Prasad's picture

Hi Igor,

Thanks a lot for your reply.

The solution you suggested is useful only for cones and cylinders. But my interest is quite wide. ie: I am getting problem with faces of booleaned objects also. You know, such faces are highly irregular (with no centre and/or radius etc ...). Can you suggest how to overcome this problem (with faces of boolean objects).

Meantime, I changed the previous code slightly, as follows.

Step 1; Extract each face as follows--- =============================

for (ExpFace.Init (myShape,TopAbs_FACE); ExpFace.More(); ExpFace.Next()) {

TopoDS_Face TopologicalFace = TopoDS::Face (ExpFace.Current());

const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopologicalFace,l);

if (S.IsNull()) continue;

TopologicalFace.Orientation (TopAbs_FORWARD) ;

AddFaceDisplay(TopologicalFace, displaydata); }

Step 2:

The AddFaceDisplay function adds the display of the face as line segments in the list displaydata. The code that computes the display data is as follows ===============================================

AddFaceDisplay(TopoDS_Face& F, MyDispData displaydata) {

GeomAbs_IsoType type;

Standard_Real param, start, end;

BRepAdaptor_Surface bas(F,Standard_True);

GeomAdaptor_Surface S = bas.Surface();

Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(S);

Adaptor3d_IsoCurve C(HS);

DBRep_IsoBuilder IsoBuild(F, 1.0e100, 10) ;

DBRep_Face *DBFace = new DBRep_Face(F, IsoBuild.NbDomains());

Standard_Integer lastIso = IsoBuild.LoadIsos(DBFace) ; // modified to give number of Iso curves

for(int i=0; iGetIso(i+1, type, param, start, end);

if (type == GeomAbs_IsoU)

{

DrawIsoCurveOn(C,GeomAbs_IsoU,param,start,end, displaydata);

}

else // (type == GeomAbs_IsoV)

{

DrawIsoCurveOn(C,GeomAbs_IsoV,param,start,end, displaydata);

}

} }

The DBRep_IsoBuilder and DBRep_Face are taken from Draw pakacge.

This changes solves the problem with cone and cylinder top/bottom surfaces. But the faces of booleaned objects are still a problem.

However, when we displayed the triangular facets of the objects and primitives it came out fine. Problem is with generation and/or display of Iso curves only.

Kindly let me know, if we are following the right path, and what is lacking where .

Thanks in advance..

Prasad.

Igor Feoktistov's picture

Hi

try to change value 1.0e100 in

DBRep_IsoBuilder IsoBuild(F, 1.0e100, 10) ;

this parameter is used to restrict parametric range of surface when face has infinite range for any parameters (for example, plane or cylindrical face with natural restriction or half of space and so on...). Really in Draw this parameter is 100. If you have such kind of faces, you only replace its infinite boudaries by yours. I don't see other "criminal" places in your source, may be something wrong in DrawIsoCurveOn(...). Send source of this method.

Igor

G. Prasad's picture

Hi Igor,

Thanks again for the prompt response. I had tried lower values instead of 1.0e100 earlier too, but no use.

The code for DrawIsoCurveOn(...) is given below

DrawIsoCurveOn(Adaptor3d_IsoCurve& C,

const GeomAbs_IsoType T,

const Standard_Real P,

const Standard_Real F,

MyDispData dispData) { C.Load(T,P,F,L);

if ((C.GetType() == GeomAbs_BezierCurve) ||

(C.GetType() == GeomAbs_BSplineCurve)) {

GeomAdaptor_Curve GC;

if (C.GetType() == GeomAbs_BezierCurve)

GC.Load(C.Bezier(),F,L);

else

GC.Load(C.BSpline(),F,L);

DrawCurveOn(GC, dispData); } else

DrawCurveOn(C, dispData); }

And the DrawCurveOn( ) method is as follows ================================= DrawCurveOn (const Adaptor3d_Curve& C, MyDispData dispdata) {

gp_Pnt P;

Standard_Integer myDiscret = 50;

Standard_Real fp = C.FirstParameter();

Standard_Real lp = C.LastParameter();

C.D0(fp, P);

dispData.MoveTo(P.X(), P.Y(), P.Z());

if (C.GetType() != GeomAbs_Line)

{

Standard_Real step = (lp - fp) / (myDiscret + 1);

Standard_Real cp = fp;

for (int i=1; i

Igor Feoktistov's picture

Your code seems to be OK, so problem may be in bad shape. When there are a lot strange isolines, very often shape has inversed faces, edges and so on.... Sometimes IsoBuilder can wrongly define intersections between edges and isocurves in some places, try to change number of iso. Could you reproduce this situation in Draw and send me Draw script? If you do not work with Draw, could you send me C++ source for creation your shapes?

Igor