Verify if input face is close to Plane, Cylinder, Cone or Sphere

nicoloc

Looking around for some CAD
In the release notes of open cascade 7.7.0, it is written that:
New functionality is implemented, which could verify the input shape to be placed on a canonical geometry with the given tolerance. If the input shape is a face or a shell, it could be verified to be close enough to Plane, Cylinder, Cone or Sphere. If the input shape is an edge or a wire, it could be verified to be close to Line, Circle or Ellipse as well as lying on one of the analytical surfaces above.
under the modeling section.
I have tried to look around for some examples or even a simple reference to this functionality, but couldn't find anything relevant. Do you know where to look? In general, all release notes from open cascade seem quite cryptic.
 
Last edited:

nicoloc

Looking around for some CAD
Ah great! What's the difference compared to the occt function? I believe they also perform the conversion. I got something easy up and running:
C++:
void convertToCyl(const TopoDS_Shape &shapeIn) {
    TopExp_Explorer explorer;
    int i = 0;
    explorer.Init(shapeIn, TopAbs_FACE);
    for (; explorer.More(); explorer.Next())
    {
      TopoDS_Face face = TopoDS::Face(explorer.Current());
      ShapeAnalysis_CanonicalRecognition aCanonRec(face);
      gp_Cylinder aCyl;
      if (aCanonRec.IsCylinder(1e-1, aCyl)) {
        gp_Ax1 ax = aCyl.Axis();
        std::cout << "found cyl with radius=" << aCyl.Radius();
        std::cout << ", axis_pnt=(" << ax.Location().X() << "," << ax.Location().Y() << "," << ax.Location().Z()  << ")";
        std::cout << ", axis_dir=(" << ax.Direction().X() << "," << ax.Direction().Y() << "," << ax.Direction().Z()  << ")" << std::endl;
        ++i;
      }
    }
    std::cout << "Cylinders found:" << i << std::endl;
}
 

Quaoar

Administrator
Staff member
At first glance, this tool is read-only. You may want to try it out on the attached shape.

Before:
1714838599087.png

After conversion:
1714838638836.png

For the sake of feature recognition and defeaturing, we try not only to find canonical shapes in a model but also normalize the model that all splines are cleaned up from its representation.
 

Attachments

  • canrec_003.stp
    181.1 KB · Views: 2

nicoloc

Looking around for some CAD
that's nice! You're probably right, I don't think it's possible doing the conversion using ShapeAnalysis_CanonicalRecognition methods, maybe there's something else?
On your shape I get this output:
found cyl with radius=35.1, axis_pnt=(-1.06581e-14,-3.59042e-13,0), axis_dir=(0,0,1)
found cyl with radius=38.1, axis_pnt=(4.44089e-14,-2.48996e-13,0), axis_dir=(0,0,1)
found cyl with radius=35.1, axis_pnt=(-1.14575e-13,-2.0678e-13,2.06054e-31), axis_dir=(0,-3.36581e-31,1)
found cyl with radius=38.1, axis_pnt=(5.32907e-14,-2.28939e-13,0), axis_dir=(0,0,1)
Cylinders found:4
 

Quaoar

Administrator
Staff member
maybe there's something else?
I don't think so. But actually, shape conversion is often just not required. Another issue with conversion is that it essentially rebuilds the shape, i.e., all 3D curves will be reprojected to the new (converted) surfaces. And we all know that such computations (based on approximations) are never perfect. Just recently, I saw a problem with the infinite projection of a curve onto a highly complex surface of linear extrusion.
 

nicoloc

Looking around for some CAD
Thanks for your help! I think in the end just having the recognition is enough in my case.
Btw great job on Analysis Situs, it seems all the features I need are already implemented :D
 
Top