Length of a cylinder

A simple, recurring problem which I am having trouble solving in OpenCascade: I have an existing STEP file, I load it into OpenCascade. It contains a cylindrical face, which I can interactively select. This face is finite, bounded by two planes. From the TopoDS_Shape representing this cylinder, I need to know its length. I've hunted through the documentation and this forum, and the best I can come up with is to use the TopoExp explorer, search through the shape and find all of its edges, and then try to recognize the two circular edges in that list, then find the distance between them. Haven't tried it, but it sounds like a terrible solution. Does anyone have a better approach??

-A.

Denis TEISSANDIER's picture

The following method gives a correct result in general.
This method is very easy to develop.

You can extract the axis of a surface, if this surface is identifed as a revolution surface. With the STEP translator of OCC, it works fine.

You will obtain easily a gp_Lin class.

You can compute two extremum points of the surface according extrema iso-value (i.e. a first point with Min U, Min V and the second point with max U, Max V.

You will obtain two "gp_Pnt". Then these two "gp_Pnt" can be projected on the axis (you must build a Geom_Line with you gp_Lin before).

You have just to calculate the distance between the two projected points.

DT

Aaron Turner's picture

I will try this; however, I would like to hear of other more direct solutions, if anyone knows of a cleaner approach.

Aaron Turner's picture

Well, I see how you are trying to proceed with this, but there's still a problem - how do I obtain Min U, Min V, Max U, Max V? Using Bounds just gives me +-Infinity in axis of symmetry (V). Also, if I could get Min V and Max V, apparently for a cylinder the depth is just their difference.

Denis TEISSANDIER's picture

The initial cylinder is identified by :

TopoDS_Shape aShapeElement;

Then :
TopoDS_Face aFaceElement= TopoDS::Face(aShapeElement);
BRepAdaptor_Surface aFaceElementAdaptor(aFaceElement, Standard_True);

GeomAbs_SurfaceType theTypeElement= aFaceElementAdaptor.GetType();
// You can verify if you shape is recognized as a cylinder ...

gp_Cylinder theCylinder= aFaceElementAdaptor.Cylinder();
gp_Ax1 theAxis= theCylinder.Axis();
gp_Dir aDirAxis= theAxis.Direction();

gp_Lin theAxisLine(theAxis);
gp_Pnt aPnt1= aFaceElementAdaptor.Value(aFaceElementAdaptor.FirstUParameter(), aFaceElementAdaptor.FirstVParameter());
gp_Pnt aPnt2= aFaceElementAdaptor.Value(aFaceElementAdaptor.LastUParameter(), aFaceElementAdaptor.LastVParameter());

Handle(Geom_Line) aGeomAxis= new Geom_Line(theAxis);
GeomAPI_ProjectPointOnCurve aProj1(aPnt1, aGeomAxis);
GeomAPI_ProjectPointOnCurve aProj2(aPnt2, aGeomAxis);

Standard_Real theRadius= aProj1.Distance(1);

Then you can compute the length of the cylinder by a calculation of the distance between aProj1.Point(1) and aProj2.Point(1).

DT

Aaron Turner's picture

You have been incredibly helpful, Denis! The missing link for me has been the BRepAdaptor_Surface class.

In general, I have found OpenCascade to be a rough library to comprehend, due to its immensity. Of course, that I have any understanding at all of such a huge library without any official training (which is cost-prohibitive for me), is a testament to OpenCascade's completeness and reasonable documentation.

I will work from your outline to accomplish my task. Be sure to check back, because I'll be posting my success.

Thanks again, Denis!

-A.

Aaron Turner's picture

I haven't yet tried out your approach (this is still a hobby, not an occupation), but I note that this seemingly key class, BRepAdaptor_Surface, is not documented in the OpenCascade help system, nor, I believe in the various manuals. Do you know of a written description for this class?

Aaron Turner's picture

Documentation or no documentation, it worked!!! Thanks again, my friend you have saved me a major headache.

-A.