Open CASCADE学习|刚体( TopoDS_Shape)按某种轨迹运动,停在指定位置上

news2024/11/20 11:27:10

今天实现如下功能:刚体做做螺旋运动,轨迹已知,求刚体在每个位置上的所占据的空间,就是把刚体从初始位置变换到该位置。

这里的刚体是一个砂轮截面,螺旋运动轨迹由B样条曲线拟合,通过Frenet标架确定运动轨迹上的局部坐标系,据此计算变换矩阵,将砂轮截面变换到指定位置。

目前可以实现平面刚体的运动,还无法实现三维刚体的运动。

1、起始位置空间的确定

#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>

#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>

#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>

#include"Viewer.h"

#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <GC_MakeSegment.hxx>
#include <IntAna2d_AnaIntersection.hxx>
#include <ShapeUpgrade_UnifySameDomain.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <GeomFill_TrihedronLaw.hxx>
#include <GeomFill_Frenet.hxx>
#include <GeomFill_CurveAndTrihedron.hxx>
#include <BRepFill_Edge3DLaw.hxx>
#include <BRepFill_SectionPlacement.hxx>
#include <ShapeUpgrade_RemoveLocations.hxx>

TopoDS_Edge createHelix(const Standard_Real HelixRadius, const Standard_Real HelixAngle, const Standard_Real HelixLength)
{
    Standard_Real u0 = 0.0;
    Standard_Real u1 = 2 * M_PI;
    Standard_Real v0 = 0.0;
    Standard_Real v1 = HelixLength;
    double uInter = (u1 - u0) / 1000;
    double vInter = (v1 - v0) / 1000;
    TColgp_HArray1OfPnt Points(1, 1001);
    Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), HelixRadius);
    double u;
    double v;
    //生成点
    for (int i = 0; i < 1001; i++) {
        u = i * vInter * tan(HelixAngle) / HelixRadius;
        v = i * vInter;
        Points[i + 1] = aCylinder->Value(u, v);
    }
    GeomAPI_PointsToBSpline Approx(Points);
    Handle_Geom_BSplineCurve K = Approx.Curve();
    TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(K);
    return aHelixEdge;

}
TopoDS_Shape createGrindingwheel()
{
    Standard_Real Line1_angle = 280 * M_PI / 180;
    Standard_Real Line1_length = 0.5031;
    Standard_Real Line2_angle = 236 * M_PI / 180;
    Standard_Real Line2_length = 0.5925;
    Standard_Real Arc1_r = 0.112;
    Standard_Real Arc1_angle = (180 + 10 + 50) * M_PI / 180;
    gp_Pnt Line1_p1(-0.6822 / 2, 0, 0);
    gp_Pnt Line2_p1(0.6822 / 2, 0, 0);
    gp_Lin Line1(Line1_p1, gp_Dir(cos(Line1_angle), sin(Line1_angle), 0.));
    gp_Lin Line2(Line2_p1, gp_Dir(cos(Line2_angle), sin(Line2_angle), 0.));
    Handle(Geom_TrimmedCurve) L1 = GC_MakeSegment(Line1, 0., Line1_length);
    TopoDS_Edge L1e = BRepBuilderAPI_MakeEdge(L1);
    Handle(Geom_TrimmedCurve) L2 = GC_MakeSegment(Line2, 0., Line2_length);
    TopoDS_Edge L2e = BRepBuilderAPI_MakeEdge(L2);
    gp_Pnt l1end = L1->EndPoint();
    gp_Pnt l2end = L2->EndPoint();
    gp_Lin Line1v(l1end, gp_Dir(cos(Line1_angle + M_PI_2), sin(Line1_angle + M_PI_2), 0.));
    gp_Lin2d Line2v(gp_Pnt2d(l2end.X(), l2end.Y()), gp_Dir2d(cos(Line2_angle - M_PI_2), sin(Line2_angle - M_PI_2)));
    gp_Lin Line2v3d(l2end, gp_Dir(cos(Line2_angle - M_PI_2), sin(Line2_angle - M_PI_2), 0.));
    Handle(Geom_TrimmedCurve) L1v = GC_MakeSegment(Line1v, 0., Arc1_r);
    gp_Pnt l1vend = L1v->EndPoint();
    gp_Circ c1(gp_Ax2(l1vend, gp_Dir(0, 0, 1)), Arc1_r);
    Handle(Geom_TrimmedCurve) c1c = GC_MakeArcOfCircle(c1, l1end, Arc1_angle, 1);
    gp_Pnt c1end = c1c->EndPoint();
    gp_Lin2d Line3(gp_Pnt2d(c1end.X(), c1end.Y()), gp_Dir2d(l2end.X() - c1end.X(), l2end.Y() - c1end.Y()));
    gp_Lin2d Line3v = Line3.Normal(gp_Pnt2d((l2end.X() + c1end.X()) / 2, (l2end.Y() + c1end.Y()) / 2));
    IntAna2d_AnaIntersection aIntAna;
    aIntAna.Perform(Line2v, Line3v);
    IntAna2d_IntPoint aIntPoint = aIntAna.Point(1);
    gp_Pnt o2(aIntPoint.Value().X(), aIntPoint.Value().Y(), 0.);
    Handle(Geom_TrimmedCurve) L2v = GC_MakeSegment(Line2v3d, l2end, o2);
    Standard_Real r2 = L2v->LastParameter();
    gp_Circ c2(gp_Ax2(o2, gp_Dir(0, 0, 1)), r2);
    Handle(Geom_TrimmedCurve) c2c = GC_MakeArcOfCircle(c2, c1end, l2end, 0);
    gp_Pnt c2low = c2c->Value(M_PI_2);

    TopoDS_Edge c1ce = BRepBuilderAPI_MakeEdge(c1c);
    TopoDS_Edge L1ev = BRepBuilderAPI_MakeEdge(L1v);
    TopoDS_Edge c2ce = BRepBuilderAPI_MakeEdge(c2c);


    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(Line1_p1, Line2_p1);

    TopTools_ListOfShape listEdge;
    listEdge.Append(anEdge);
    listEdge.Append(L1e);
    listEdge.Append(c1ce);
    listEdge.Append(c2ce);
    listEdge.Append(L2e);
    BRepBuilderAPI_MakeWire mw;
    mw.Add(listEdge);
    mw.Build();


    TopoDS_Face out = BRepBuilderAPI_MakeFace(mw);
    gp_Circ  cutcircle(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 0.406 / 2);
    TopoDS_Edge cute = BRepBuilderAPI_MakeEdge(cutcircle);
    TopoDS_Wire cutw = BRepBuilderAPI_MakeWire(cute);
    TopoDS_Face cutf = BRepBuilderAPI_MakeFace(cutw);
    //平移:
    gp_Trsf theTransformation1;
    gp_Vec theVectorOfTranslation1(-c2low.X(), -c2low.Y(), 0.);
    theTransformation1.SetTranslation(theVectorOfTranslation1);

    BRepBuilderAPI_Transform myBRepTransformation1(out, theTransformation1);
    TopoDS_Shape outzero = myBRepTransformation1.Shape();
    TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(outzero, cutf);

    gp_Trsf theTransformation2;
    gp_Vec theVectorOfTranslation2(0., 0.125 / 2, 0.);
    theTransformation2.SetTranslation(theVectorOfTranslation2);
    //绕一个轴旋转:
    gp_Trsf theTransformation3;
    gp_Ax1 axez = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0., 0., 1.));
    theTransformation3.SetRotation(axez, -90 * M_PI / 180);

    gp_Trsf theTransformation4;
    gp_Ax1 axex = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1., 0., 0.));
    theTransformation4.SetRotation(axex, -50 * M_PI / 180);

    BRepBuilderAPI_Transform myBRepTransformation(theCommonSurface, theTransformation4 * theTransformation3 * theTransformation2);
    TopoDS_Shape TransformedShape = myBRepTransformation.Shape();

    return TransformedShape;
}
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
    //creat a profile of gringing wheel
    TopoDS_Shape gw = createGrindingwheel();
    //creat a cylinder surface
    Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), 0.306 / 2);
    TopoDS_Shape cF = BRepBuilderAPI_MakeFace(aCylinder->Cylinder(), 0, 2 * M_PI, 0, 3.);

    TopoDS_Solid cys = BRepPrimAPI_MakeCylinder(gp::XOY(), 0.306 / 2, 7);
  
    TopoDS_Edge aE = createHelix(0.306 / 2, M_PI / 4, 6.);
    TopoDS_Wire spine = BRepBuilderAPI_MakeWire(aE);
    
    //crate a sweep surface
    TopoDS_Shape pipe = BRepOffsetAPI_MakePipe(spine, gw, GeomFill_IsFrenet, 1);


    TopoDS_Wire mySpine;
    TopoDS_Shape myProfile;
    TopoDS_Shape myShape;
    gp_Trsf myTrsf;
    Handle(BRepFill_LocationLaw) myLoc;
    Handle(TopTools_HArray2OfShape) mySections;
    Handle(TopTools_HArray2OfShape) myFaces;
    Handle(TopTools_HArray2OfShape) myEdges;
    TopTools_MapOfShape myReversedEdges;
    BRepFill_DataMapOfShapeHArray2OfShape myTapes;
    BRepFill_DataMapOfShapeHArray2OfShape myRails;
    Standard_Integer myCurIndexOfSectionEdge;
    TopoDS_Shape myFirst;
    TopoDS_Shape myLast;
    TopTools_DataMapOfShapeListOfShape myGenMap;
    Standard_Integer myDegmax;
    Standard_Integer mySegmax;
    GeomAbs_Shape myContinuity;
    GeomFill_Trihedron myMode;
    Standard_Boolean myForceApproxC1;
    Standard_Real myErrorOnSurf;

    mySections.Nullify();
    myFaces.Nullify();
    myEdges.Nullify();

    mySpine = spine;
    myProfile = gw;

    TopoDS_Shape TheProf;

    Handle(GeomFill_TrihedronLaw) TLaw;
    TLaw = new GeomFill_Frenet();
    Handle(GeomFill_CurveAndTrihedron) Loc = new (GeomFill_CurveAndTrihedron) (TLaw);
    myLoc = new (BRepFill_Edge3DLaw) (mySpine, Loc);
    if (myLoc->NbLaw() == 0) {
        return 0; // Degenerated case
    }
    myLoc->TransformInG0Law(); // Set into continuity

    BRepFill_SectionPlacement Place(myLoc, gw);
    myTrsf = Place.Transformation();

    TopLoc_Location Loc2(myTrsf), Loc1;
    Loc1 = gw.Location();
    TopoDS_Shape aux;
    TheProf = myProfile;
    TheProf.Location(Loc2.Multiplied(Loc1));

    // Construct First && Last Shape
    Handle(GeomFill_LocationLaw) law;

    gp_Mat M;
    gp_Vec V;
    gp_Trsf fila;
    Standard_Real first,last;
    myLoc->Law(1)->GetDomain(first, last);
    std::cout << "first=" <<first<< std::endl;
    std::cout << "last=" << last << std::endl;
    myLoc->Law(1)->D0(first, M, V);
    fila.SetValues(M(1, 1), M(1, 2), M(1, 3), V.X(),
        M(2, 1), M(2, 2), M(2, 3), V.Y(),
        M(3, 1), M(3, 2), M(3, 3), V.Z());

    fila.Multiply(myTrsf);
    TopLoc_Location LocFirst(fila);
    myFirst = myProfile;
    if (!LocFirst.IsIdentity()) {
        //myFirst.Location( LocFirst.Multiplied(myProfile.Location()) );
        myFirst = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
    }

    ShapeUpgrade_RemoveLocations RemLoc;
    RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
    RemLoc.Remove(myFirst);
    myFirst = RemLoc.GetResult();

    myLoc->Law(myLoc->NbLaw())->GetDomain(first, last);
    myLoc->Law(myLoc->NbLaw())->D0(last, M, V);
    //    try { // Not good, but there are no other means to test SetValues
    fila.SetValues(M(1, 1), M(1, 2), M(1, 3), V.X(),
        M(2, 1), M(2, 2), M(2, 3), V.Y(),
        M(3, 1), M(3, 2), M(3, 3), V.Z());
    fila.Multiply(myTrsf);
    TopLoc_Location LocLast(fila);
    if (!myLoc->IsClosed() || LocFirst != LocLast) {
        myLast = myProfile;
        if (!LocLast.IsIdentity()) {
            //myLast.Location(LocLast.Multiplied(myProfile.Location()) );
            myLast = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
        }
    }
    else {
        myLast = myFirst;
    }
    RemLoc.Remove(myLast);
    myLast = RemLoc.GetResult();
   
    Viewer vout(50, 50, 500, 500);
    vout << wbe;
    vout << xline;
    vout << yline;
    vout << zline;
    vout << myProfile;
    vout << myLast;
    vout << spine;
    vout.StartMessageLoop();
    return 0;
}

2、中间任一位置空间的确定

#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>

#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>

#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>

#include"Viewer.h"

#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <GC_MakeSegment.hxx>
#include <IntAna2d_AnaIntersection.hxx>
#include <ShapeUpgrade_UnifySameDomain.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <GeomFill_TrihedronLaw.hxx>
#include <GeomFill_Frenet.hxx>
#include <GeomFill_CurveAndTrihedron.hxx>
#include <BRepFill_Edge3DLaw.hxx>
#include <BRepFill_SectionPlacement.hxx>
#include <ShapeUpgrade_RemoveLocations.hxx>

TopoDS_Edge createHelix(const Standard_Real HelixRadius, const Standard_Real HelixAngle, const Standard_Real HelixLength)
{
    Standard_Real u0 = 0.0;
    Standard_Real u1 = 2 * M_PI;
    Standard_Real v0 = 0.0;
    Standard_Real v1 = HelixLength;
    double uInter = (u1 - u0) / 1000;
    double vInter = (v1 - v0) / 1000;
    TColgp_HArray1OfPnt Points(1, 1001);
    Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), HelixRadius);
    double u;
    double v;
    //生成点
    for (int i = 0; i < 1001; i++) {
        u = i * vInter * tan(HelixAngle) / HelixRadius;
        v = i * vInter;
        Points[i + 1] = aCylinder->Value(u, v);
    }
    GeomAPI_PointsToBSpline Approx(Points);
    Handle_Geom_BSplineCurve K = Approx.Curve();
    TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(K);
    return aHelixEdge;

}
TopoDS_Shape createGrindingwheel()
{
    Standard_Real Line1_angle = 280 * M_PI / 180;
    Standard_Real Line1_length = 0.5031;
    Standard_Real Line2_angle = 236 * M_PI / 180;
    Standard_Real Line2_length = 0.5925;
    Standard_Real Arc1_r = 0.112;
    Standard_Real Arc1_angle = (180 + 10 + 50) * M_PI / 180;
    gp_Pnt Line1_p1(-0.6822 / 2, 0, 0);
    gp_Pnt Line2_p1(0.6822 / 2, 0, 0);
    gp_Lin Line1(Line1_p1, gp_Dir(cos(Line1_angle), sin(Line1_angle), 0.));
    gp_Lin Line2(Line2_p1, gp_Dir(cos(Line2_angle), sin(Line2_angle), 0.));
    Handle(Geom_TrimmedCurve) L1 = GC_MakeSegment(Line1, 0., Line1_length);
    TopoDS_Edge L1e = BRepBuilderAPI_MakeEdge(L1);
    Handle(Geom_TrimmedCurve) L2 = GC_MakeSegment(Line2, 0., Line2_length);
    TopoDS_Edge L2e = BRepBuilderAPI_MakeEdge(L2);
    gp_Pnt l1end = L1->EndPoint();
    gp_Pnt l2end = L2->EndPoint();
    gp_Lin Line1v(l1end, gp_Dir(cos(Line1_angle + M_PI_2), sin(Line1_angle + M_PI_2), 0.));
    gp_Lin2d Line2v(gp_Pnt2d(l2end.X(), l2end.Y()), gp_Dir2d(cos(Line2_angle - M_PI_2), sin(Line2_angle - M_PI_2)));
    gp_Lin Line2v3d(l2end, gp_Dir(cos(Line2_angle - M_PI_2), sin(Line2_angle - M_PI_2), 0.));
    Handle(Geom_TrimmedCurve) L1v = GC_MakeSegment(Line1v, 0., Arc1_r);
    gp_Pnt l1vend = L1v->EndPoint();
    gp_Circ c1(gp_Ax2(l1vend, gp_Dir(0, 0, 1)), Arc1_r);
    Handle(Geom_TrimmedCurve) c1c = GC_MakeArcOfCircle(c1, l1end, Arc1_angle, 1);
    gp_Pnt c1end = c1c->EndPoint();
    gp_Lin2d Line3(gp_Pnt2d(c1end.X(), c1end.Y()), gp_Dir2d(l2end.X() - c1end.X(), l2end.Y() - c1end.Y()));
    gp_Lin2d Line3v = Line3.Normal(gp_Pnt2d((l2end.X() + c1end.X()) / 2, (l2end.Y() + c1end.Y()) / 2));
    IntAna2d_AnaIntersection aIntAna;
    aIntAna.Perform(Line2v, Line3v);
    IntAna2d_IntPoint aIntPoint = aIntAna.Point(1);
    gp_Pnt o2(aIntPoint.Value().X(), aIntPoint.Value().Y(), 0.);
    Handle(Geom_TrimmedCurve) L2v = GC_MakeSegment(Line2v3d, l2end, o2);
    Standard_Real r2 = L2v->LastParameter();
    gp_Circ c2(gp_Ax2(o2, gp_Dir(0, 0, 1)), r2);
    Handle(Geom_TrimmedCurve) c2c = GC_MakeArcOfCircle(c2, c1end, l2end, 0);
    gp_Pnt c2low = c2c->Value(M_PI_2);

    TopoDS_Edge c1ce = BRepBuilderAPI_MakeEdge(c1c);
    TopoDS_Edge L1ev = BRepBuilderAPI_MakeEdge(L1v);
    TopoDS_Edge c2ce = BRepBuilderAPI_MakeEdge(c2c);


    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(Line1_p1, Line2_p1);

    TopTools_ListOfShape listEdge;
    listEdge.Append(anEdge);
    listEdge.Append(L1e);
    listEdge.Append(c1ce);
    listEdge.Append(c2ce);
    listEdge.Append(L2e);
    BRepBuilderAPI_MakeWire mw;
    mw.Add(listEdge);
    mw.Build();


    TopoDS_Face out = BRepBuilderAPI_MakeFace(mw);
    gp_Circ  cutcircle(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 0.406 / 2);
    TopoDS_Edge cute = BRepBuilderAPI_MakeEdge(cutcircle);
    TopoDS_Wire cutw = BRepBuilderAPI_MakeWire(cute);
    TopoDS_Face cutf = BRepBuilderAPI_MakeFace(cutw);
    //平移:
    gp_Trsf theTransformation1;
    gp_Vec theVectorOfTranslation1(-c2low.X(), -c2low.Y(), 0.);
    theTransformation1.SetTranslation(theVectorOfTranslation1);

    BRepBuilderAPI_Transform myBRepTransformation1(out, theTransformation1);
    TopoDS_Shape outzero = myBRepTransformation1.Shape();
    TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(outzero, cutf);

    gp_Trsf theTransformation2;
    gp_Vec theVectorOfTranslation2(0., 0.125 / 2, 0.);
    theTransformation2.SetTranslation(theVectorOfTranslation2);
    //绕一个轴旋转:
    gp_Trsf theTransformation3;
    gp_Ax1 axez = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0., 0., 1.));
    theTransformation3.SetRotation(axez, -90 * M_PI / 180);

    gp_Trsf theTransformation4;
    gp_Ax1 axex = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1., 0., 0.));
    theTransformation4.SetRotation(axex, -50 * M_PI / 180);

    BRepBuilderAPI_Transform myBRepTransformation(theCommonSurface, theTransformation4 * theTransformation3 * theTransformation2);
    TopoDS_Shape TransformedShape = myBRepTransformation.Shape();

    return TransformedShape;
}
TopoDS_Shape getShapeOnPosition(TopoDS_Shape myProfile,Handle(BRepFill_LocationLaw) myLoc,Standard_Real pos, Standard_Real a, Standard_Real b, gp_Trsf myTrsf)
{
    TopoDS_Shape myPos;
    Handle(GeomFill_LocationLaw) law;
    gp_Mat M;
    gp_Vec V;
    gp_Trsf fila;
    Standard_Real first, last;
    myLoc->Law(1)->GetDomain(first, last);
    Standard_Real px = (pos - a) / (b - a);
    myLoc->Law(1)->D0(px, M, V);
    fila.SetValues(M(1, 1), M(1, 2), M(1, 3), V.X(),
        M(2, 1), M(2, 2), M(2, 3), V.Y(),
        M(3, 1), M(3, 2), M(3, 3), V.Z());

    fila.Multiply(myTrsf);
    myPos = myProfile;
    TopLoc_Location LocPos(fila);
    if (!LocPos.IsIdentity()) {
        //myFirst.Location( LocFirst.Multiplied(myProfile.Location()) );
        myPos = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
    }

    ShapeUpgrade_RemoveLocations RemLoc;
    RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
    RemLoc.Remove(myPos);
    myPos = RemLoc.GetResult();
    return myPos;
}
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
    //creat a profile of gringing wheel
    TopoDS_Shape gw = createGrindingwheel();
    //creat a cylinder surface
    Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), 0.306 / 2);
    TopoDS_Shape cF = BRepBuilderAPI_MakeFace(aCylinder->Cylinder(), 0, 2 * M_PI, 0, 3.);

    TopoDS_Solid cys = BRepPrimAPI_MakeCylinder(gp::XOY(), 0.306 / 2, 7);
  
    TopoDS_Edge aE = createHelix(0.306 / 2, M_PI / 4, 6.);
    TopoDS_Wire spine = BRepBuilderAPI_MakeWire(aE);
    
    //crate a sweep surface
    TopoDS_Shape pipe = BRepOffsetAPI_MakePipe(spine, gw, GeomFill_IsFrenet, 1);


    TopoDS_Wire mySpine;
    TopoDS_Shape myProfile;
    TopoDS_Shape myShape;
    gp_Trsf myTrsf;
    Handle(BRepFill_LocationLaw) myLoc;
    Handle(TopTools_HArray2OfShape) mySections;
    Handle(TopTools_HArray2OfShape) myFaces;
    Handle(TopTools_HArray2OfShape) myEdges;
    TopTools_MapOfShape myReversedEdges;
    BRepFill_DataMapOfShapeHArray2OfShape myTapes;
    BRepFill_DataMapOfShapeHArray2OfShape myRails;
    Standard_Integer myCurIndexOfSectionEdge;
    TopoDS_Shape myFirst;
    TopoDS_Shape myLast;
    TopTools_DataMapOfShapeListOfShape myGenMap;
    Standard_Integer myDegmax;
    Standard_Integer mySegmax;
    GeomAbs_Shape myContinuity;
    GeomFill_Trihedron myMode;
    Standard_Boolean myForceApproxC1;
    Standard_Real myErrorOnSurf;

    mySections.Nullify();
    myFaces.Nullify();
    myEdges.Nullify();

    mySpine = spine;
    myProfile = gw;

    TopoDS_Shape TheProf;

    Handle(GeomFill_TrihedronLaw) TLaw;
    TLaw = new GeomFill_Frenet();
    Handle(GeomFill_CurveAndTrihedron) Loc = new (GeomFill_CurveAndTrihedron) (TLaw);
    myLoc = new (BRepFill_Edge3DLaw) (mySpine, Loc);
    if (myLoc->NbLaw() == 0) {
        return 0; // Degenerated case
    }
    myLoc->TransformInG0Law(); // Set into continuity

    BRepFill_SectionPlacement Place(myLoc, gw);
    myTrsf = Place.Transformation();

    TopLoc_Location Loc2(myTrsf), Loc1;
    Loc1 = gw.Location();
    TopoDS_Shape aux;
    TheProf = myProfile;
    TheProf.Location(Loc2.Multiplied(Loc1));

    // Construct First && Last Shape
    Handle(GeomFill_LocationLaw) law;

    gp_Mat M;
    gp_Vec V;
    gp_Trsf fila;
    Standard_Real first,last;
    myLoc->Law(1)->GetDomain(first, last);
    std::cout << "first=" <<first<< std::endl;
    std::cout << "last=" << last << std::endl;
    std::cout << "myLoc->NbLaw()=" << myLoc->NbLaw() << std::endl;
    myLoc->Law(1)->D0(first, M, V);
    fila.SetValues(M(1, 1), M(1, 2), M(1, 3), V.X(),
        M(2, 1), M(2, 2), M(2, 3), V.Y(),
        M(3, 1), M(3, 2), M(3, 3), V.Z());

    fila.Multiply(myTrsf);
    TopLoc_Location LocFirst(fila);
    myFirst = myProfile;
    if (!LocFirst.IsIdentity()) {
        //myFirst.Location( LocFirst.Multiplied(myProfile.Location()) );
        myFirst = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
    }

    ShapeUpgrade_RemoveLocations RemLoc;
    RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
    RemLoc.Remove(myFirst);
    myFirst = RemLoc.GetResult();

    myLoc->Law(myLoc->NbLaw())->GetDomain(first, last);
    myLoc->Law(myLoc->NbLaw())->D0(last, M, V);
    //    try { // Not good, but there are no other means to test SetValues
    fila.SetValues(M(1, 1), M(1, 2), M(1, 3), V.X(),
        M(2, 1), M(2, 2), M(2, 3), V.Y(),
        M(3, 1), M(3, 2), M(3, 3), V.Z());
    fila.Multiply(myTrsf);
    TopLoc_Location LocLast(fila);
    if (!myLoc->IsClosed() || LocFirst != LocLast) {
        myLast = myProfile;
        if (!LocLast.IsIdentity()) {
            //myLast.Location(LocLast.Multiplied(myProfile.Location()) );
            myLast = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
        }
    }
    else {
        myLast = myFirst;
    }
    RemLoc.Remove(myLast);
    myLast = RemLoc.GetResult();

    TopoDS_Shape md1 = getShapeOnPosition(myProfile, myLoc, 0.2, 0., 6., myTrsf);
    TopoDS_Shape md2 = getShapeOnPosition(myProfile, myLoc, 0.4, 0., 6., myTrsf);
    TopoDS_Shape md3 = getShapeOnPosition(myProfile, myLoc, 0.6, 0., 6., myTrsf);
    TopoDS_Shape md4 = getShapeOnPosition(myProfile, myLoc, 0.8, 0., 6., myTrsf);
    TopoDS_Shape md5 = getShapeOnPosition(myProfile, myLoc, 1.0, 0., 6., myTrsf);
   
    Viewer vout(50, 50, 500, 500);
    vout << wbe;
    vout << xline;
    vout << yline;
    vout << zline;
    vout << myProfile;
    vout << myLast;
    vout << spine;
    vout << md1;
    vout << md2;
    vout << md3;
    vout << md4;
    vout << md5;
    vout.StartMessageLoop();
    return 0;
}

3、使用的dll

TKernel.lib

TKMath.lib

TKTopAlgo.lib

TKBRep.lib

TKPrim.lib

TKOpenGl.lib

TKService.lib

TKV3d.lib

kernel32.lib

user32.lib

gdi32.lib

TKBinXCAF.lib

TKSTEP.lib

TKSTEP209.lib

TKSTEPAttr.lib

TKSTEPBase.lib

TKXSBase.lib

TKGeomBase.lib

TKG3d.lib

TKG2d.lib

TKShHealing.lib

TKGeomAlgo.lib

TKOffset.lib

TKBO.lib

TKFeat.lib

TKFillet.lib

TKBool.lib

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1566826.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Spring Boot集成AJ-Captcha实现滑动验证码功能

1.AJ-Captcha介绍 行为验证码 采用嵌入式集成方式&#xff0c;接入方便&#xff0c;安全&#xff0c;高效。抛弃了传统字符型验证码展示-填写字符-比对答案的流程&#xff0c;采用验证码展示-采集用户行为-分析用户行为流程&#xff0c;用户只需要产生指定的行为轨迹&#xff0…

WPS二次开发系列:如何获取应用签名SHA256值

在申请WPS SDK授权版时候需要开发者提供应用包名和签名&#xff0c;应用包名好说&#xff0c;那如何生成符合WPS要求的应用签名&#xff08;SHA256)呢&#xff0c;经笔者亲测&#xff0c;有如下两种方式可以实现获取第三方应用签名值&#xff08;SHA256&#xff09; 1. 方法一&…

springboot对接minio的webhook全过程

前言 近日需要将minio的apache2.0版本给用起来&#xff0c;顺便要完善一下原有的文件上传管理系统&#xff0c;其中很重要的一点是&#xff0c;在原有客户端直传的基础上&#xff0c;再添加 minio 的上传回调给服务端做后续处理。 本文重点在于&#xff0c;介绍整个minio与spr…

SpringCloud学习(1)-consul

consul下载安装及使用 1.consul简介 Consul是一种开源的、分布式的服务发现和配置管理工具&#xff0c;能够帮助开发人员构建和管理现代化的分布式系统。它提供了一套完整的功能&#xff0c;包括服务注册与发现、健康检查、KV存储、多数据中心支持等&#xff0c;可以帮助开发人…

Jenkins--任务详解

一、任务类型 Jenkins的主要功能的实现是由执行任务去完成的&#xff0c;常用的任务类型主要有以下三种&#xff1a; 自由风格任务(Free Style Project): 这是Jenkins中最常用的任务类型&#xff0c;允许你自定义各种构建步骤和配置选项&#xff0c;如源码管理、构建触发器、…

vue3+echarts:echarts地图打点显示的样式

colorStops是打点的颜色和呼吸灯、label为show是打点是否显示数据、rich里cnNum是自定义的过滤模板用来改写显示数据的样式 series: [{type: "effectScatter",coordinateSystem: "geo",rippleEffect: {brushType: "stroke",},showEffectOn: &quo…

Redis的值有5种数据结构,不同数据结构的使用场景是什么?

文章目录 字符串缓存计数共享Session限速 哈希缓存 列表消息队列文章列表栈队列有限集合 集合标签抽奖社交需求 有序集合排行榜系统 字符串 缓存 &#xff08;1&#xff09;使用原生字符类型缓存 优点&#xff1a;简单直观&#xff0c;每个属性都支持更新操作 缺点&#xff1…

大话设计模式之状态模式

状态模式是一种行为设计模式&#xff0c;它允许对象在其内部状态发生变化时改变其行为。在状态模式中&#xff0c;对象将其行为委托给当前状态对象&#xff0c;从而在不同的状态下执行不同的行为&#xff0c;而不必在对象自身的代码中包含大量的条件语句。 通常&#xff0c;状…

WE博客代码系统

WE博客代码系统 说明文档 运行前附加数据库.mdf&#xff08;或sql生成数据库&#xff09; 主要技术&#xff1a; 基于asp.net mvc架构和sql server数据库&#xff0c;并采用EF实体模型开发。 三层架构并采用EF实体模型开发 功能模块&#xff1a; WE博客代码系统 WE博客代码系…

使用SpringBoot实现的登录注册后端功能

1、系统演示视频&#xff08;演示视频&#xff09; 2、需要交流和学习请联系

java网络编程——网络编程概述及UDP/TCP通信编程的实现

前言&#xff1a; 学习到通信了&#xff0c;整理下相关知识点。打好基础&#xff0c;daydayup!!! 网络编程 网络编程指可以让设备中的程序与网络上其他设备中的程序进行数据交互。 基本的通信架构 基本的通信架构有两种形式&#xff1a;CS架构&#xff08;Client客户端/Server服…

2024年购买阿里云服务器多少钱?100元-5000元预算

2024年阿里云服务器租用费用&#xff0c;云服务器ECS经济型e实例2核2G、3M固定带宽99元一年&#xff0c;轻量应用服务器2核2G3M带宽轻量服务器一年61元&#xff0c;ECS u1服务器2核4G5M固定带宽199元一年&#xff0c;2核4G4M带宽轻量服务器一年165元12个月&#xff0c;2核4G服务…

KV260 BOOT.BIN更新 ubuntu22.04 netplan修改IP

KV260 2022.2设置 BOOT.BIN升级 KV260开发板需要先更新BOOT.BIN到2022.2版本&#xff0c;命令如下&#xff1a; sudo xmutil bootfw_update -i “BOOT-k26-starter-kit-202305_2022.2.bin” 注意BOOT.BIN应包含全目录。下面是更新到2022.1 FW的示例&#xff0c;非更新到2022.…

数据质量决定大模型能力,景联文科技提供高质量大模型数据

随着大模型的深入发展&#xff0c;各类资源要素的配置状态已悄然变化。其中&#xff0c;数据的价值已被提升到一个新高度。 大模型往往拥有庞大的参数和复杂的网络结构&#xff0c;需要大量的数据来学习和优化。数据的质量和数量直接决定了模型的训练效果。若数据不足或质量不佳…

【Flutter】windows环境配置

windows 11 环境 官方教程 配置了flutter 环境变量在系统的path里 bin 路径。 死活没反应 关闭了git关闭了dart.exe关闭了vs还是不行卸载重新来 新版git flutter doctor 还需要android 环境

WPF动画教程(PointAnimationUsingPath的使用)

PointAnimationUsingPath的介绍 PointAnimationUsingPath 是 WPF 中的一个类&#xff0c;它用于创建一个动画&#xff0c;该动画会沿着指定的路径移动一个点。 关于 PointAnimationUsingPath这些属性比较重要&#xff1a; 属性类型说明PathGeometryPathGeometry这个属性定义了…

【Django学习笔记(四)】JavaScript 语言介绍

JavaScript 语言介绍 前言正文1、JavaScript 小案例2、代码位置2.1 在当前 HTML 文件中2.2 在其他 js 文件中 3、代码注释3.1 HTML的注释3.2 CSS的注释3.3 Javascript的注释 4、变量 & 输出4.1 字符串4.2 数组4.3 对象(python里的字典) 5、条件语句6、函数7、DOM7.1 根据 I…

【动态规划】【背包问题】基础背包

【动态规划】【01背包问题】 解法 二维dp数组01背包解法 一维dp数组&#xff08;滚动数组&#xff09;01背包 ---------------&#x1f388;&#x1f388;题目链接&#x1f388;&#x1f388;------------------- 解法 二维dp数组01背包 &#x1f612;: 我的代码实现> …

RedCap轻量化5G提升生产效率,多领域应用

在工业数字化时代&#xff0c;工业智能化已经成为了各行各业的发展趋势。而在这个过程中&#xff0c;5G作为新一代网络通信技术正逐渐成为工业领域的核心力量。而在5G技术的应用中&#xff0c;RedCap轻量化5G工业网关路由器便是低成本畅享5G的最佳选择。 RedCap轻量化5G工业网…

可视化大屏的应用(18):网络安全和信息安全领域

可视化大屏在物联网领域具有以下价值&#xff1a; 实时监控和可视化&#xff1a; 可视化大屏可以将物联网设备和传感器的数据以图表、图形和动画等形式实时展示&#xff0c;帮助用户直观地了解物联网系统的运行状态和数据趋势。通过可视化大屏&#xff0c;用户可以快速发现异…