OpenCasCade BrepFeat_MakeCylindricalHole();功能

时间:2017-08-14 10:46:07

标签: c++ opencascade

目前我正在开展一个项目,在给定形状上钻一些圆柱孔。

为此,我确实使用了BRepFeat_MakeCylindricalHole();函数并使用了Standard_EXPORT void PerformThruNext (const Standard_Real Radius, const Standard_Boolean WithControl = Standard_True);

因为在这种情况下我没有圆柱体的深度。使用performThruNext,它将钻孔,顶面到底面。 用户将获得开始和结束点,然后使用它将钻孔。

  1. ** 1.当起点和终点具有小数部分(gp_pnt StartPnt (328.547,-4.325,97.412); gp_pnt EndPnt (291.841,-7.586,101.651);)时,它不会正确钻孔。
  2. 2.当直径达到更高值时,发生相同的事情, ,

    **以下是我的代码,任何帮助将非常感谢。谢谢!

    enter image description here

    enter image description here

    void COCCAPPDoc::OnBox2()
    {
    
    ofstream out;
    out.open("C:/Users/Dell/Desktop/Blade/areaInit.txt");
    CString str;
    
    TopoDS_Shape bladeWithCore,DrilledShape,DrilledShape2;
    
    /* IMPORT bladeWithCore.brep FILE */
    Standard_CString strFile = "C:/Users/Dell/Desktop/Blade/bladeWithCore.brep";
    BRep_Builder brepS;
    BRepTools::Read(bladeWithCore,strFile,brepS);
    
    TopoDS_Face Face_52;
    Standard_CString strFace = "C:/Users/Dell/Desktop/Blade/Face_52.brep";
    BRep_Builder brepF;
    BRepTools::Read(Face_52,strFace,brepF);
    
    BRepClass3d_SolidClassifier classify;
    classify.Load(bladeWithCore);
    classify.PerformInfinitePoint(1.0e-6);
    TopAbs_State state = classify.State();
    if(state==TopAbs_IN) bladeWithCore.Reverse();
    
    DrilledShape = bladeWithCore;
    
    gp_Vec v1(gp_Pnt( 330,11,108),gp_Pnt(291,4,109)); //FINDING VECTOR FROM START TO THE END POINT
    gp_Pnt point(330,11,108);
    
    gp_Pnt startpoint (330,11,108);
    TopoDS_Vertex aV1 = BRepBuilderAPI_MakeVertex (startpoint);
    BRepTools::Write(aV1,"C:/Users/Dell/Desktop/Blade/startpoint.brep");
    
    /* gp_Vec v1(gp_Pnt( 330.208114,11.203318,108.480255),gp_Pnt(291.103558,4.265285,109.432663));
    gp_Pnt point(330.208114,11.203318,108.480255);*/
    
    gp_Dir d1(v1); //GETTING DIRECTION USING FOUND VECTOR
    gp_Vec UnitVector(d1); //FINDING UNITVECTOR
    
    gp_Dir dir_line(0,0,1);
    gp_Vec UnitVector_line(dir_line);
    
    gp_Pnt minPoint;
    Standard_Real diameter = 0.1;
    
    int noOfInstances =3;
    int gap = -10;
    
    for(int i=0; i {
    
    point.Translate(UnitVector);
    
    gp_Pnt newPoint = point;
    newPoint.Translate(UnitVector_line*10);
    BRepBuilderAPI_MakeEdge LINE(newPoint, point);
    BRepBuilderAPI_MakeWire lineWire(LINE);
    
    TopoDS_Wire wire = TopoDS::Wire(lineWire);
    TopoDS_Shape lineShape = TopoDS_Shape(wire);
    BRepTools::Write(lineShape,"C:/Users/Dell/Desktop/Blade/linlineShapee.brep");
    
    intersection( bladeWithCore,lineShape, point, minPoint);
    
    TopoDS_Vertex checkPoint = BRepBuilderAPI_MakeVertex (minPoint);
    BRepTools::Write(checkPoint,"C:/Users/Dell/Desktop/Blade/checkPoint.brep");
    
    gp_Ax1 location =gp_Ax1(minPoint,gp_Dir(0,0,1));
    BRepFeat_MakeCylindricalHole drilled;
    drilled.Init(DrilledShape,location);
    drilled.PerformThruNext(diameter/2.0);
    
    BRepFeat_Status status = drilled.Status();
    
    if(status==BRepFeat_NoError)
    {
    DrilledShape = drilled.Shape();
    BRepTools::Write(DrilledShape,"C:/Users/Dell/Desktop/Blade/bladeWithCoreDrilled.brep");
    }
    
    }
    Handle(AIS_InteractiveObject) obj3 = (new AIS_Shape(DrilledShape));
    myAISContext->Display(obj3);
    COCCAPPDoc:: Fit();
    }
    
    void COCCAPPDoc::intersection(TopoDS_Shape bladeWithCore,TopoDS_Shape lineShape,gp_Pnt point,gp_Pnt& minPoint)
    {
    
    BRepExtrema_DistShapeShape  interSection( bladeWithCore, lineShape, Extrema_ExtFlag_MIN, Extrema_ExtAlgo_Grad);
    interSection.Perform();
    Standard_Integer Solutions = interSection.NbSolution();
    
    CArray disArray;
    int minindex = 1;
    
    for(int i = 1; i {
    
    double distance = point.Distance((interSection.PointOnShape1(i)));
    disArray.Add(distance);
    
    }
    
    for(int i = 1; i {
    
    if(disArray[0] > disArray[i])
    {
    disArray[0] = disArray[i];
    minindex = i;
    
    }
    }
    minPoint = interSection.PointOnShape1(minindex);
    TopoDS_Vertex aV = BRepBuilderAPI_MakeVertex (minPoint);
    BRepTools::Write(aV,"C:/Users/Dell/Desktop/Blade/minPoint.brep");
    }
    

0 个答案:

没有答案