bool IfcGeom::Kernel::convert(const IfcSchema::IfcPlane* l, TopoDS_Shape& face) { gp_Pln pln; convert(l, pln); Handle_Geom_Surface surf = new Geom_Plane(pln); #if OCC_VERSION_HEX < 0x60502 face = BRepBuilderAPI_MakeFace(surf); #else face = BRepBuilderAPI_MakeFace(surf, getValue(GV_PRECISION)); #endif return true; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCylindricalSurface* l, TopoDS_Shape& face) { gp_Trsf trsf; IfcGeom::Kernel::convert(l->Position(),trsf); // IfcElementarySurface.Position has unit scale factor #if OCC_VERSION_HEX < 0x60502 face = BRepBuilderAPI_MakeFace(new Geom_CylindricalSurface(gp::XOY(), l->Radius())).Face().Moved(trsf); #else face = BRepBuilderAPI_MakeFace(new Geom_CylindricalSurface(gp::XOY(), l->Radius()), getValue(GV_PRECISION)).Face().Moved(trsf); #endif return true; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcBSplineSurfaceWithKnots* l, TopoDS_Shape& face) { boost::shared_ptr< IfcTemplatedEntityListList<IfcSchema::IfcCartesianPoint> > cps = l->ControlPointsList(); std::vector<double> uknots = l->UKnots(); std::vector<double> vknots = l->VKnots(); std::vector<int> umults = l->UMultiplicities(); std::vector<int> vmults = l->VMultiplicities(); TColgp_Array2OfPnt Poles (0, (int)cps->size() - 1, 0, (int)(*cps->begin()).size() - 1); TColStd_Array1OfReal UKnots(0, (int)uknots.size() - 1); TColStd_Array1OfReal VKnots(0, (int)vknots.size() - 1); TColStd_Array1OfInteger UMults(0, (int)umults.size() - 1); TColStd_Array1OfInteger VMults(0, (int)vmults.size() - 1); Standard_Integer UDegree = l->UDegree(); Standard_Integer VDegree = l->VDegree(); int i = 0, j; for (IfcTemplatedEntityListList<IfcSchema::IfcCartesianPoint>::outer_it it = cps->begin(); it != cps->end(); ++it, ++i) { j = 0; for (IfcTemplatedEntityListList<IfcSchema::IfcCartesianPoint>::inner_it jt = (*it).begin(); jt != (*it).end(); ++jt, ++j) { IfcSchema::IfcCartesianPoint* p = *jt; gp_Pnt pnt; if (!convert(p, pnt)) return false; Poles(i, j) = pnt; } } i = 0; for (std::vector<double>::const_iterator it = uknots.begin(); it != uknots.end(); ++it, ++i) { UKnots(i) = *it; } i = 0; for (std::vector<double>::const_iterator it = vknots.begin(); it != vknots.end(); ++it, ++i) { VKnots(i) = *it; } i = 0; for (std::vector<int>::const_iterator it = umults.begin(); it != umults.end(); ++it, ++i) { UMults(i) = *it; } i = 0; for (std::vector<int>::const_iterator it = vmults.begin(); it != vmults.end(); ++it, ++i) { VMults(i) = *it; } Handle_Geom_Surface surf = new Geom_BSplineSurface(Poles, UKnots, VKnots, UMults, VMults, UDegree, VDegree); #if OCC_VERSION_HEX < 0x60502 face = BRepBuilderAPI_MakeFace(surf); #else face = BRepBuilderAPI_MakeFace(surf, getValue(GV_PRECISION)); #endif return true; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCenterLineProfileDef* l, TopoDS_Shape& face) { const double d = l->Thickness() * getValue(GV_LENGTH_UNIT) / 2.; TopoDS_Wire wire; if (!convert_wire(l->Curve(), wire)) return false; // BRepOffsetAPI_MakeOffset insists on creating circular arc // segments for joining the curves that constitute the center // line. This is probably not in accordance with the IFC spec. // Although it does not specify a method to join segments // explicitly, it does dictate 'a constant thickness along the // curve'. Therefore for simple singular wires a quick // alternative is provided that uses a straight join. TopExp_Explorer exp(wire, TopAbs_EDGE); TopoDS_Edge edge = TopoDS::Edge(exp.Current()); exp.Next(); if (!exp.More()) { double u1, u2; Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, u1, u2); Handle(Geom_TrimmedCurve) trim = new Geom_TrimmedCurve(curve, u1, u2); Handle(Geom_OffsetCurve) c1 = new Geom_OffsetCurve(trim, d, gp::DZ()); Handle(Geom_OffsetCurve) c2 = new Geom_OffsetCurve(trim, -d, gp::DZ()); gp_Pnt c1a, c1b, c2a, c2b; c1->D0(c1->FirstParameter(), c1a); c1->D0(c1->LastParameter(), c1b); c2->D0(c2->FirstParameter(), c2a); c2->D0(c2->LastParameter(), c2b); BRepBuilderAPI_MakeWire mw; mw.Add(BRepBuilderAPI_MakeEdge(c1)); mw.Add(BRepBuilderAPI_MakeEdge(c1a, c2a)); mw.Add(BRepBuilderAPI_MakeEdge(c2)); mw.Add(BRepBuilderAPI_MakeEdge(c2b, c1b)); face = BRepBuilderAPI_MakeFace(mw.Wire()); } else { BRepOffsetAPI_MakeOffset offset(BRepBuilderAPI_MakeFace(gp_Pln(gp::Origin(), gp::DZ()))); offset.AddWire(wire); offset.Perform(d); face = BRepBuilderAPI_MakeFace(TopoDS::Wire(offset)); } return true; }
//================================================================ // Function : DrawSurface // Purpose : displays a given geometric surface in 3d viewer // (creates a finite face and displays it) //================================================================ Handle_AIS_InteractiveObject OCCDemo_Presentation::drawSurface (const Handle_Geom_Surface& theSurface, const Quantity_Color& theColor, const Standard_Boolean toDisplay) { Standard_Real u1, u2, v1, v2; theSurface->Bounds(u1,u2,v1,v2); fixParam(u1); fixParam(u2); fixParam(v1); fixParam(v2); Handle_AIS_Shape aGraphicSurface = new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2)); getAISContext()->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay); getAISContext()->SetColor(aGraphicSurface, theColor, toDisplay); if (toDisplay) { if (FitMode){ getAISContext()->Display (aGraphicSurface, Standard_False); COCCDemoDoc::Fit(); } else getAISContext()->Display (aGraphicSurface); } return aGraphicSurface; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) { TopoDS_Shape halfspace; if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false; TopoDS_Wire wire; if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false; gp_Trsf trsf; if ( ! convert(l->Position(),trsf) ) return false; TColgp_SequenceOfPnt points; if (wire_to_sequence_of_point(wire, points)) { remove_duplicate_points_from_loop(points, wire.Closed()); // Note: wire always closed, as per if statement above remove_collinear_points_from_loop(points, wire.Closed()); sequence_of_point_to_wire(points, wire, wire.Closed()); } TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200)); gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0)); // `trsf` and `down` both have a unit scale factor prism.Move(trsf*down); shape = BRepAlgoAPI_Common(halfspace,prism); return true; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCylindricalSurface* l, TopoDS_Shape& face) { gp_Trsf trsf; IfcGeom::Kernel::convert(l->Position(),trsf); face = BRepBuilderAPI_MakeFace(new Geom_CylindricalSurface(gp::XOY(), l->Radius()), getValue(GV_PRECISION)).Face().Moved(trsf); return true; }
TopoDS_Shape OCCPartFactory::makeCube( const Standard_Real width, const Standard_Real height, const Standard_Real depth) { // define points gp_Pnt pt1( -width / 2.0, 0.0, 0.0 ); gp_Pnt pt2( -width / 2.0, -depth / 2.0, 0.0 ); gp_Pnt pt3( width / 2.0, -depth / 2.0, 0.0 ); gp_Pnt pt4( width /2.0, 0.0, 0.0 ); // define segments Handle_Geom_TrimmedCurve seg1 = GC_MakeSegment( pt1, pt2 ); Handle_Geom_TrimmedCurve seg2 = GC_MakeSegment( pt2, pt3 ); Handle_Geom_TrimmedCurve seg3 = GC_MakeSegment( pt3, pt4 ); // make edge TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge( seg1 ); TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge( seg2 ); TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge( seg3 ); // make wire TopoDS_Wire wire1 = BRepBuilderAPI_MakeWire( edge1, edge2, edge3 ); //Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf transfer; transfer.SetMirror( xAxis ); BRepBuilderAPI_Transform aBRepTrsf( wire1 , transfer ); TopoDS_Shape mirroredShape = aBRepTrsf.Shape(); TopoDS_Wire mirroredWire1 = TopoDS::Wire( mirroredShape ); BRepBuilderAPI_MakeWire mkWire; mkWire.Add( wire1 ); mkWire.Add( mirroredWire1 ); TopoDS_Wire wireProfile = mkWire.Wire(); //Body : Prism the Profile TopoDS_Face faceProfile = BRepBuilderAPI_MakeFace( wireProfile ); gp_Vec prismVec( 0.0 , 0.0 , height ); TopoDS_Shape cube = BRepPrimAPI_MakePrism( faceProfile, prismVec); // cube.setMaterial( Graphic3d_NOM_JADE ); // Handle_AIS_Shape shape = new AIS_Shape( cube ); // shape->SetColor( Quantity_NOC_RED ); // return shape; return cube; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcHalfSpaceSolid* l, TopoDS_Shape& shape) { IfcSchema::IfcSurface* surface = l->BaseSurface(); if ( ! surface->is(IfcSchema::Type::IfcPlane) ) { Logger::Message(Logger::LOG_ERROR, "Unsupported BaseSurface:", surface->entity); return false; } gp_Pln pln; IfcGeom::Kernel::convert((IfcSchema::IfcPlane*)surface,pln); const gp_Pnt pnt = pln.Location().Translated( l->AgreementFlag() ? -pln.Axis().Direction() : pln.Axis().Direction()); shape = BRepPrimAPI_MakeHalfSpace(BRepBuilderAPI_MakeFace(pln),pnt).Solid(); return true; }
TopoDS_Face buildEtaCutFace(const CTiglWingStructureReference& wsr, double eta) { // NOTE: we have to determine the cut plane by using the // GetMidplaneOrChordlinePoint methods for handling the case when the eta line // is extended because of an z-rotation of the outer or inner sections gp_Pnt startPnt = wsr.GetMidplaneOrChordlinePoint(eta, 0); gp_Pnt endPnt = wsr.GetMidplaneOrChordlinePoint(eta, 1); gp_Vec midplaneNormal = wsr.GetMidplaneNormal(eta); gp_Dir cutPlaneNormal = midplaneNormal.Crossed(gp_Vec(startPnt, endPnt)); gp_Pln etaCutPlane = gp_Pln(startPnt, cutPlaneNormal); return BRepBuilderAPI_MakeFace(etaCutPlane); }
void createGroundShape(TopoDS_Shape& shape) { TColgp_Array2OfPnt cv (0, 4, 0, 4); cv.SetValue(0, 0, gp_Pnt(-10000, -10000, -4130)); cv.SetValue(0, 1, gp_Pnt(-10000, -4330, -4130)); cv.SetValue(0, 2, gp_Pnt(-10000, 0, -5130)); cv.SetValue(0, 3, gp_Pnt(-10000, 4330, -7130)); cv.SetValue(0, 4, gp_Pnt(-10000, 10000, -7130)); cv.SetValue(1, 0, gp_Pnt( -3330, -10000, -5130)); cv.SetValue(1, 1, gp_Pnt( -7670, -3670, 5000)); cv.SetValue(1, 2, gp_Pnt( -9000, 0, 1000)); cv.SetValue(1, 3, gp_Pnt( -7670, 7670, 6000)); cv.SetValue(1, 4, gp_Pnt( -3330, 10000, -4130)); cv.SetValue(2, 0, gp_Pnt( 0, -10000, -5530)); cv.SetValue(2, 1, gp_Pnt( 0, -3670, 3000)); cv.SetValue(2, 2, gp_Pnt( 0, 0, -12000)); cv.SetValue(2, 3, gp_Pnt( 0, 7670, 1500)); cv.SetValue(2, 4, gp_Pnt( 0, 10000, -4130)); cv.SetValue(3, 0, gp_Pnt( 3330, -10000, -6130)); cv.SetValue(3, 1, gp_Pnt( 7670, -3670, 6000)); cv.SetValue(3, 2, gp_Pnt( 9000, 0, 5000)); cv.SetValue(3, 3, gp_Pnt( 7670, 9000, 7000)); cv.SetValue(3, 4, gp_Pnt( 3330, 10000, -4130)); cv.SetValue(4, 0, gp_Pnt( 10000, -10000, -6130)); cv.SetValue(4, 1, gp_Pnt( 10000, -4330, -5130)); cv.SetValue(4, 2, gp_Pnt( 10000, 0, -4130)); cv.SetValue(4, 3, gp_Pnt( 10000, 4330, -4130)); cv.SetValue(4, 4, gp_Pnt( 10000, 10000, -8130)); TColStd_Array1OfReal knots(0, 1); knots(0) = 0; knots(1) = 1; TColStd_Array1OfInteger mult(0, 1); mult(0) = 5; mult(1) = 5; Handle(Geom_BSplineSurface) surf = new Geom_BSplineSurface(cv, knots, knots, mult, mult, 4, 4); #if OCC_VERSION_HEX < 0x60502 shape = BRepBuilderAPI_MakeFace(surf); #else shape = BRepBuilderAPI_MakeFace(surf, Precision::Confusion()); #endif }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) { TopoDS_Shape halfspace; if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false; TopoDS_Wire wire; if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false; gp_Trsf trsf; convert(l->Position(),trsf); TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200)); gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0)); prism.Move(trsf*down); shape = BRepAlgoAPI_Common(halfspace,prism); return true; }
void occQt::makeRevol() { gp_Ax1 anAxis; // revol a vertex result is an edge. anAxis.SetLocation(gp_Pnt(0.0, 70.0, 0.0)); TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(2.0, 70.0, 0.0)); TopoDS_Shape aRevolVertex = BRepPrimAPI_MakeRevol(aVertex, anAxis); Handle_AIS_Shape anAisRevolVertex = new AIS_Shape(aRevolVertex); // revol an edge result is a face. anAxis.SetLocation(gp_Pnt(8.0, 70.0, 0.0)); TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(6.0, 70.0, 0.0), gp_Pnt(6.0, 70.0, 5.0)); TopoDS_Shape aRevolEdge = BRepPrimAPI_MakeRevol(anEdge, anAxis); Handle_AIS_Shape anAisRevolEdge = new AIS_Shape(aRevolEdge); // revol a wire result is a shell. anAxis.SetLocation(gp_Pnt(20.0, 70.0, 0.0)); anAxis.SetDirection(gp::DY()); TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(15.0, 70.0, 0.0), gp::DZ()), 1.5)); TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); TopoDS_Shape aRevolCircle = BRepPrimAPI_MakeRevol(aCircleWire, anAxis, M_PI_2); Handle_AIS_Shape anAisRevolCircle = new AIS_Shape(aRevolCircle); // revol a face result is a solid. anAxis.SetLocation(gp_Pnt(30.0, 70.0, 0.0)); anAxis.SetDirection(gp::DY()); TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(gp_Ax2(gp_Pnt(25.0, 70.0, 0.0), gp::DZ()), 3.0, 2.0)); TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge); TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire); TopoDS_Shape aRevolEllipse = BRepPrimAPI_MakeRevol(aEllipseFace, anAxis, M_PI_4); Handle_AIS_Shape anAisRevolEllipse = new AIS_Shape(aRevolEllipse); anAisRevolVertex->SetColor(Quantity_NOC_LIMEGREEN); anAisRevolEdge->SetColor(Quantity_NOC_LINEN); anAisRevolCircle->SetColor(Quantity_NOC_MAGENTA1); anAisRevolEllipse->SetColor(Quantity_NOC_MAROON); mContext->Display(anAisRevolVertex); mContext->Display(anAisRevolEdge); mContext->Display(anAisRevolCircle); mContext->Display(anAisRevolEllipse); }
void Werkstuck::BulkForm(float Xmin, float Ymin, float Zmin, float Xmax, float Ymax, float Zmax) { Xstart=Xmax+10; //начальное положение инструмента Ystart=Ymax+10; // за заготовкой Zstart=Zmax+10; Xwz=Xstart; Ywz=Ystart; Zwz=Zstart; H0=Zmax; Xfmin=Xmin; Xfmax=Xmax; Yfmin=Ymin; Yfmax=Ymax; gp_Pnt punkt1(Xmin, Ymin, Zmin); gp_Pnt punkt2(Xmin, Ymax, Zmin); gp_Pnt punkt3(Xmax, Ymax, Zmin); gp_Pnt punkt4(Xmax, Ymin, Zmin); Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2); Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3); Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeSegment(punkt3 , punkt4); Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt4 , punkt1); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2); TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3); TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4); TopoDS_Wire Basis = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4); TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis); gp_Vec PrismVec(0 , 0 , Zmax-Zmin); TopoDS_Shape sBulkForm = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec); WS = sBulkForm; //Erst_weg = true; }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { BRepBuilderAPI_MakeWire wireMaker; // Profile : Define Support Points { Handle(TColgp_HArray1OfPnt) gp_array = new TColgp_HArray1OfPnt(1, 4); gp_Pnt p0(-myWidth / 2., 0, 0); gp_Pnt p4(myWidth / 2., 0, 0); // gp_array->SetValue(0, p0); gp_array->SetValue(1, gp_Pnt(-myWidth / 2., -myThickness / 4., 0)); gp_array->SetValue(2, gp_Pnt(0, -myThickness / 2., 0)); gp_array->SetValue(3, gp_Pnt(myWidth / 2., -myThickness / 4., 0)); gp_array->SetValue(4, p4); GeomAPI_Interpolate sp(gp_array, true, 1.0e-3); sp.Perform(); wireMaker.Add(BRepBuilderAPI_MakeEdge(sp.Curve())); } // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(wireMaker.Wire()); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound(aRes); aBuilder.Add(aRes, myBody); // aBuilder.Add(aRes, myThreading); return aRes; }
void occQt::makeExtrude() { // prism a vertex result is an edge. TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 60.0, 0.0)); TopoDS_Shape aPrismVertex = BRepPrimAPI_MakePrism(aVertex, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismVertex = new AIS_Shape(aPrismVertex); // prism an edge result is a face. TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0)); TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismEdge = new AIS_Shape(aPrismEdge); // prism a wire result is a shell. gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(16.0, 60.0, 0.0)); TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, 3.0)); TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); TopoDS_Shape aPrismCircle = BRepPrimAPI_MakePrism(aCircleWire, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismCircle = new AIS_Shape(aPrismCircle); // prism a face or a shell result is a solid. anAxis.SetLocation(gp_Pnt(24.0, 60.0, 0.0)); TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(anAxis, 3.0, 2.0)); TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge); TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire); TopoDS_Shape aPrismEllipse = BRepPrimAPI_MakePrism(aEllipseFace, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismEllipse = new AIS_Shape(aPrismEllipse); anAisPrismVertex->SetColor(Quantity_NOC_PAPAYAWHIP); anAisPrismEdge->SetColor(Quantity_NOC_PEACHPUFF); anAisPrismCircle->SetColor(Quantity_NOC_PERU); anAisPrismEllipse->SetColor(Quantity_NOC_PINK); mContext->Display(anAisPrismVertex); mContext->Display(anAisPrismEdge); mContext->Display(anAisPrismCircle); mContext->Display(anAisPrismEllipse); }
// Returns the point where the distance between the selected fuselage and the ground is at minimum. // The Fuselage could be turned with a given angle at at given axis, specified by a point and a direction. gp_Pnt CCPACSFuselage::GetMinumumDistanceToGround(gp_Ax1 RAxis, double angle) { TopoDS_Shape fusedFuselage = GetLoft()->Shape(); // now rotate the fuselage gp_Trsf myTrsf; myTrsf.SetRotation(RAxis, angle * M_PI / 180.); BRepBuilderAPI_Transform xform(fusedFuselage, myTrsf); fusedFuselage = xform.Shape(); // build cutting plane for intersection // We move the "ground" to "-1000" to be sure it is _under_ the fuselage gp_Pnt p1(-1.0e7, -1.0e7, -1000); gp_Pnt p2( 1.0e7, -1.0e7, -1000); gp_Pnt p3( 1.0e7, 1.0e7, -1000); gp_Pnt p4(-1.0e7, 1.0e7, -1000); Handle(Geom_TrimmedCurve) shaft_line1 = GC_MakeSegment(p1,p2); Handle(Geom_TrimmedCurve) shaft_line2 = GC_MakeSegment(p2,p3); Handle(Geom_TrimmedCurve) shaft_line3 = GC_MakeSegment(p3,p4); Handle(Geom_TrimmedCurve) shaft_line4 = GC_MakeSegment(p4,p1); TopoDS_Edge shaft_edge1 = BRepBuilderAPI_MakeEdge(shaft_line1); TopoDS_Edge shaft_edge2 = BRepBuilderAPI_MakeEdge(shaft_line2); TopoDS_Edge shaft_edge3 = BRepBuilderAPI_MakeEdge(shaft_line3); TopoDS_Edge shaft_edge4 = BRepBuilderAPI_MakeEdge(shaft_line4); TopoDS_Wire shaft_wire = BRepBuilderAPI_MakeWire(shaft_edge1, shaft_edge2, shaft_edge3, shaft_edge4); TopoDS_Face shaft_face = BRepBuilderAPI_MakeFace(shaft_wire); // calculate extrema BRepExtrema_DistShapeShape extrema(fusedFuselage, shaft_face); extrema.Perform(); return extrema.PointOnShape1(1); }
TopoDS_Shape IfcGeom::halfspace_from_plane(const gp_Pln& pln,const gp_Pnt& cent) { TopoDS_Face face = BRepBuilderAPI_MakeFace(pln).Face(); return BRepPrimAPI_MakeHalfSpace(face,cent).Solid(); }
//////////////////////////////////////////////////////////////////////////////// // Construct TopoDS from BRL-CAD data //////////////////////////////////////////////////////////////////////////////// BRLTopo::BRLTopo(struct rt_arb_internal *arb) { TopoDS_Vertex v[8]; for(int i=0;i<8;i++) v[i]=BRepBuilderAPI_MakeVertex( gp_Pnt( scale*arb->pt[i][0], scale*arb->pt[i][1], scale*arb->pt[i][2] ) ); int arbn; if(!BRepTools::Compare(v[6],v[7])) arbn=8; else if(!BRepTools::Compare(v[4],v[5])) arbn=7; else if(!BRepTools::Compare(v[5],v[6])) arbn=6; else if(!BRepTools::Compare(v[0],v[3])) arbn=5; else arbn=4; switch(arbn) { case 8: { TopoDS_Edge e[12]; for(int i=0;i<4;i++) { e[i]=BRepBuilderAPI_MakeEdge(v[i],v[(i+1)%4]); e[i+4]=BRepBuilderAPI_MakeEdge(v[i+4],v[(i+1)%4+4]); e[i+8]=BRepBuilderAPI_MakeEdge(v[i],v[(i+4)%8]); } TopoDS_Wire w[6]; w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]); w[1]=BRepBuilderAPI_MakeWire(e[4],e[5],e[6],e[7]); w[2]=BRepBuilderAPI_MakeWire(e[0],e[9],e[4],e[8]); w[3]=BRepBuilderAPI_MakeWire(e[1],e[10],e[5],e[9]); w[4]=BRepBuilderAPI_MakeWire(e[2],e[11],e[6],e[10]); w[5]=BRepBuilderAPI_MakeWire(e[3],e[8],e[7],e[11]); BRep_Builder BB; TopoDS_Shell shell; BB.MakeShell(shell); for(int i=0;i<6;i++) { TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]); BB.Add(shell,i? f.Reversed():f); } TopoDS_Solid solid; BB.MakeSolid(solid); BB.Add(solid,shell); ShapeFix_Solid sf(solid); sf.Perform(); shape=sf.Solid(); } break; case 6: { TopoDS_Edge e[9]; e[0]=BRepBuilderAPI_MakeEdge(v[0],v[1]); e[1]=BRepBuilderAPI_MakeEdge(v[1],v[2]); e[2]=BRepBuilderAPI_MakeEdge(v[2],v[3]); e[3]=BRepBuilderAPI_MakeEdge(v[3],v[0]); e[4]=BRepBuilderAPI_MakeEdge(v[0],v[4]); e[5]=BRepBuilderAPI_MakeEdge(v[1],v[4]); e[6]=BRepBuilderAPI_MakeEdge(v[2],v[6]); e[7]=BRepBuilderAPI_MakeEdge(v[3],v[6]); e[8]=BRepBuilderAPI_MakeEdge(v[4],v[6]); TopoDS_Wire w[5]; w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]); w[1]=BRepBuilderAPI_MakeWire(e[0],e[4],e[5]); w[2]=BRepBuilderAPI_MakeWire(e[2],e[6],e[7]); w[3]=BRepBuilderAPI_MakeWire(e[3],e[4],e[8],e[7]); w[4]=BRepBuilderAPI_MakeWire(e[1],e[5],e[8],e[6]); BRep_Builder BB; #if 0 TopoDS_Compound result; BB.MakeCompound(result); for(int i=0;i<5;i++) { BB.Add(result,BRepBuilderAPI_MakeFace(w[i])); } shape=result; #else TopoDS_Shell shell; BB.MakeShell(shell); for(int i=0;i<5;i++) { TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]); BB.Add(shell,f); //i? f:f.Reversed()); } TopoDS_Solid solid; BB.MakeSolid(solid); BB.Add(solid,shell); ShapeFix_Solid sf(solid); sf.Perform(); shape=sf.Solid(); #endif } break; default: cerr << "Unhandled arb8 type n=" << arbn << '\n'; } }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_PlaneDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IPlane aPI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; double aSize = aPI.GetSize() / 2.0; if (aType == PLANE_PNT_VEC) { Handle(GEOM_Function) aRefPnt = aPI.GetPoint(); Handle(GEOM_Function) aRefVec = aPI.GetVector(); TopoDS_Shape aShape1 = aRefPnt->GetValue(); TopoDS_Shape aShape2 = aRefVec->GetValue(); if (aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_EDGE) return 0; gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShape1)); TopoDS_Edge anE = TopoDS::Edge(aShape2); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (!V1.IsNull() && !V2.IsNull()) { gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); gp_Pln aPln (aP, aV); aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape(); } } else if (aType == PLANE_THREE_PNT) { Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1(); Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2(); Handle(GEOM_Function) aRefPnt3 = aPI.GetPoint3(); TopoDS_Shape aShape1 = aRefPnt1->GetValue(); TopoDS_Shape aShape2 = aRefPnt2->GetValue(); TopoDS_Shape aShape3 = aRefPnt3->GetValue(); if (aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX || aShape3.ShapeType() != TopAbs_VERTEX) return 0; gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1)); gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2)); gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape3)); if (aP1.Distance(aP2) < gp::Resolution() || aP1.Distance(aP3) < gp::Resolution() || aP2.Distance(aP3) < gp::Resolution()) Standard_ConstructionError::Raise("Plane creation aborted: coincident points given"); if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) Standard_ConstructionError::Raise("Plane creation aborted: points lay on one line"); GC_MakePlane aMakePlane (aP1, aP2, aP3); aShape = BRepBuilderAPI_MakeFace(aMakePlane, -aSize, +aSize, -aSize, +aSize).Shape(); } else if (aType == PLANE_FACE) { Handle(GEOM_Function) aRef = aPI.GetFace(); TopoDS_Shape aRefShape = aRef->GetValue(); //if (aRefShape.ShapeType() != TopAbs_FACE) return 0; //Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aRefShape)); //if (!aGS->IsKind(STANDARD_TYPE(Geom_Plane))) { // Standard_TypeMismatch::Raise("Plane creation aborted: non-planar face given as argument"); //} //aShape = BRepBuilderAPI_MakeFace(aGS, -aSize, +aSize, -aSize, +aSize).Shape(); gp_Ax3 anAx3 = GEOMImpl_IMeasureOperations::GetPosition(aRefShape); gp_Pln aPln (anAx3); aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape(); } else if (aType == PLANE_TANGENT_FACE) { Handle(GEOM_Function) aRefFace = aPI.GetFace(); TopoDS_Shape aShape1 = aRefFace->GetValue(); if(aShape1.IsNull()) Standard_TypeMismatch::Raise("Plane was not created.Basis face was not specified"); TopoDS_Face aFace = TopoDS::Face(aShape1); Standard_Real aKoefU = aPI.GetParameterU(); Standard_Real aKoefV = aPI.GetParameterV(); Standard_Real aUmin,aUmax,aVmin,aVmax; ShapeAnalysis::GetFaceUVBounds(aFace,aUmin,aUmax,aVmin,aVmax); Standard_Real aDeltaU = aUmax - aUmin; Standard_Real aDeltaV = aVmax - aVmin; Standard_Real aParamU = aUmin + aDeltaU*aKoefU; Standard_Real aParamV = aVmin + aDeltaV*aKoefV; Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); if(aSurf.IsNull()) Standard_TypeMismatch::Raise("Plane was not created.Base surface is absent"); gp_Vec aVecU,aVecV; gp_Pnt aPLoc; aSurf->D1(aParamU,aParamV,aPLoc,aVecU,aVecV); BRepTopAdaptor_FClass2d clas(aFace,Precision::PConfusion()); TopAbs_State stOut= clas.PerformInfinitePoint(); gp_Pnt2d aP2d(aParamU,aParamV); TopAbs_State st= clas.Perform(aP2d); if(st == stOut) Standard_TypeMismatch::Raise("Plane was not created.Point lies outside the face"); gp_Vec aNorm = aVecU^aVecV; gp_Ax3 anAxis(aPLoc,gp_Dir(aNorm),gp_Dir(aVecU)); gp_Pln aPlane(anAxis); BRepBuilderAPI_MakeFace aTool(aPlane, -aSize, +aSize, -aSize, +aSize); if(aTool.IsDone()) aShape = aTool.Shape(); } else if (aType == PLANE_2_VEC) { Handle(GEOM_Function) aRefVec1 = aPI.GetVector1(); Handle(GEOM_Function) aRefVec2 = aPI.GetVector2(); TopoDS_Shape aShape1 = aRefVec1->GetValue(); TopoDS_Shape aShape2 = aRefVec2->GetValue(); if (aShape1.ShapeType() != TopAbs_EDGE || aShape2.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge aVectX = TopoDS::Edge(aShape1); TopoDS_Edge aVectZ = TopoDS::Edge(aShape2); TopoDS_Vertex VX1, VX2, VZ1, VZ2; TopExp::Vertices( aVectX, VX1, VX2, Standard_True ); TopExp::Vertices( aVectZ, VZ1, VZ2, Standard_True ); gp_Vec aVX = gp_Vec( BRep_Tool::Pnt( VX1 ), BRep_Tool::Pnt( VX2 ) ); gp_Vec aVZ = gp_Vec( BRep_Tool::Pnt( VZ1 ), BRep_Tool::Pnt( VZ2 ) ); if ( aVX.Magnitude() < Precision::Confusion() || aVZ.Magnitude() < Precision::Confusion()) Standard_TypeMismatch::Raise("Invalid vector selected"); gp_Dir aDirX = gp_Dir( aVX.X(), aVX.Y(), aVX.Z() ); gp_Dir aDirZ = gp_Dir( aVZ.X(), aVZ.Y(), aVZ.Z() ); if ( aDirX.IsParallel( aDirZ, Precision::Angular() ) ) Standard_TypeMismatch::Raise("Parallel vectors selected"); gp_Ax3 aPlane = gp_Ax3( BRep_Tool::Pnt( VX1 ), aDirZ, aDirX ); BRepBuilderAPI_MakeFace aTool(aPlane, -aSize, +aSize, -aSize, +aSize); if(aTool.IsDone()) aShape = aTool.Shape(); } else if (aType == PLANE_LCS) { Handle(GEOM_Function) aRef = aPI.GetLCS(); double anOrientation = aPI.GetOrientation(); gp_Ax3 anAx3; if (aRef.IsNull()) { gp_Ax2 anAx2 = gp::XOY(); anAx3 = gp_Ax3( anAx2 ); } else { TopoDS_Shape aRefShape = aRef->GetValue(); if (aRefShape.ShapeType() != TopAbs_FACE) return 0; anAx3 = GEOMImpl_IMeasureOperations::GetPosition(aRefShape); } if ( anOrientation == 2) anAx3 = gp_Ax3(anAx3.Location(), anAx3.XDirection(), anAx3.YDirection() ); else if ( anOrientation == 3 ) anAx3 = gp_Ax3(anAx3.Location(), anAx3.YDirection(), anAx3.XDirection() ); gp_Pln aPln(anAx3); aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcTriangulatedFaceSet* l, TopoDS_Shape& shape) { IfcSchema::IfcCartesianPointList3D* point_list = l->Coordinates(); const std::vector< std::vector<double> > coordinates = point_list->CoordList(); std::vector<gp_Pnt> points; points.reserve(coordinates.size()); for (std::vector< std::vector<double> >::const_iterator it = coordinates.begin(); it != coordinates.end(); ++it) { const std::vector<double>& coords = *it; if (coords.size() != 3) { Logger::Message(Logger::LOG_ERROR, "Invalid dimensions encountered on Coordinates", l->entity); return false; } points.push_back(gp_Pnt(coords[0] * getValue(GV_LENGTH_UNIT), coords[1] * getValue(GV_LENGTH_UNIT), coords[2] * getValue(GV_LENGTH_UNIT))); } std::vector< std::vector<int> > indices = l->CoordIndex(); std::vector<TopoDS_Face> faces; faces.reserve(indices.size()); for(std::vector< std::vector<int> >::const_iterator it = indices.begin(); it != indices.end(); ++ it) { const std::vector<int>& tri = *it; if (tri.size() != 3) { Logger::Message(Logger::LOG_ERROR, "Invalid dimensions encountered on CoordIndex", l->entity); return false; } const int min_index = *std::min_element(tri.begin(), tri.end()); const int max_index = *std::max_element(tri.begin(), tri.end()); if (min_index < 1 || max_index > points.size()) { Logger::Message(Logger::LOG_ERROR, "Contents of CoordIndex out of bounds", l->entity); return false; } const gp_Pnt& a = points[tri[0] - 1]; // account for zero- vs const gp_Pnt& b = points[tri[1] - 1]; // one-based indices in const gp_Pnt& c = points[tri[2] - 1]; // c++ and express TopoDS_Wire wire = BRepBuilderAPI_MakePolygon(a, b, c, true).Wire(); TopoDS_Face face = BRepBuilderAPI_MakeFace(wire).Face(); TopoDS_Iterator face_it(face, false); const TopoDS_Wire& w = TopoDS::Wire(face_it.Value()); const bool reversed = w.Orientation() == TopAbs_REVERSED; if (reversed) { face.Reverse(); } if (face_area(face) > getValue(GV_MINIMAL_FACE_AREA)) { faces.push_back(face); } } if (faces.empty()) return false; const unsigned int num_faces = indices.size(); bool valid_shell = false; if (faces.size() < getValue(GV_MAX_FACES_TO_SEW)) { BRepOffsetAPI_Sewing builder; builder.SetTolerance(getValue(GV_POINT_EQUALITY_TOLERANCE)); builder.SetMaxTolerance(getValue(GV_POINT_EQUALITY_TOLERANCE)); builder.SetMinTolerance(getValue(GV_POINT_EQUALITY_TOLERANCE)); for (std::vector<TopoDS_Face>::const_iterator it = faces.begin(); it != faces.end(); ++it) { builder.Add(*it); } try { builder.Perform(); shape = builder.SewedShape(); valid_shell = BRepCheck_Analyzer(shape).IsValid(); } catch(...) {} if (valid_shell) { try { ShapeFix_Solid solid; solid.LimitTolerance(getValue(GV_POINT_EQUALITY_TOLERANCE)); TopoDS_Solid solid_shape = solid.SolidFromShell(TopoDS::Shell(shape)); if (!solid_shape.IsNull()) { try { BRepClass3d_SolidClassifier classifier(solid_shape); shape = solid_shape; } catch (...) {} } } catch(...) {} } else { Logger::Message(Logger::LOG_WARNING, "Failed to sew faceset:", l->entity); } } if (!valid_shell) { TopoDS_Compound compound; BRep_Builder builder; builder.MakeCompound(compound); for (std::vector<TopoDS_Face>::const_iterator it = faces.begin(); it != faces.end(); ++it) { builder.Add(compound, *it); } shape = compound; } return true; }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { // Profile : Define Support Points gp_Pnt aPnt1(-myWidth / 2., 0, 0); gp_Pnt aPnt2(-myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt3(0, -myThickness / 2., 0); gp_Pnt aPnt4(myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt5(myWidth / 2., 0, 0); // Profile : Define the Geometry Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3,aPnt4); Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2); Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5); // Profile : Define the Topology TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1); TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle); TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3); // Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf aTrsf; aTrsf.SetMirror(xAxis); BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf); TopoDS_Shape aMirroredShape = aBRepTrsf.Shape(); TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape); BRepBuilderAPI_MakeWire mkWire; mkWire.Add(aWire); mkWire.Add(aMirroredWire); TopoDS_Wire myWireProfile = mkWire.Wire(); // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Body : Apply Fillets BRepFilletAPI_MakeFillet mkFillet(myBody); TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE); while(anEdgeExplorer.More()) { TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current()); //Add edge to fillet algorithm mkFillet.Add(myThickness / 12., anEdge); anEdgeExplorer.Next(); } myBody = mkFillet.Shape(); // Body : Add the Neck gp_Pnt neckLocation(0, 0, myHeight); gp_Dir neckAxis = gp::DZ(); gp_Ax2 neckAx2(neckLocation, neckAxis); Standard_Real myNeckRadius = myThickness / 4.; Standard_Real myNeckHeight = myHeight / 10.; BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight); TopoDS_Shape myNeck = MKCylinder.Shape(); myBody = BRepAlgoAPI_Fuse(myBody, myNeck); // Body : Create a Hollowed Solid TopoDS_Face faceToRemove; Standard_Real zMax = -1; for(TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) { TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); // Check if <aFace> is the top face of the bottle�s neck Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace); if(aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface); gp_Pnt aPnt = aPlane->Location(); Standard_Real aZ = aPnt.Z(); if(aZ > zMax) { zMax = aZ; faceToRemove = aFace; } } } TopTools_ListOfShape facesToRemove; facesToRemove.Append(faceToRemove); myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1.e-3); // Threading : Create Surfaces Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99); Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05); // Threading : Define 2D Curves gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.); gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.); gp_Ax2d anAx2d(aPnt, aDir); Standard_Real aMajor = 2. * M_PI; Standard_Real aMinor = myNeckHeight / 10; Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor); Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4); Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI); Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI); gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2); // Threading : Build Edges and Wires TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1); TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1); TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2); TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2); TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1); TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2); BRepLib::BuildCurves3d(threadingWire1); BRepLib::BuildCurves3d(threadingWire2); // Create Threading BRepOffsetAPI_ThruSections aTool(Standard_True); aTool.AddWire(threadingWire1); aTool.AddWire(threadingWire2); aTool.CheckCompatibility(Standard_False); TopoDS_Shape myThreading = aTool.Shape(); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound (aRes); aBuilder.Add (aRes, myBody); aBuilder.Add (aRes, myThreading); return aRes; }
int OCCWire::chamfer(std::vector<OCCVertex *> vertices, std::vector<double> distances) { int vertices_size = vertices.size(); int distances_size = distances.size(); BRepFilletAPI_MakeFillet2d MF; try { if (this->getShape().IsNull()) { StdFail_NotDone::Raise("Shapes is Null"); } MF.Init(BRepBuilderAPI_MakeFace(this->getWire())); // creat map of vertices TopTools_IndexedMapOfShape vertMap; for (unsigned i=0; i<vertices.size(); i++) vertMap.Add(vertices[i]->getShape()); bool first = true; TopoDS_Edge firstEdge, nextEdge; TopoDS_Vertex vertex; BRepTools_WireExplorer Ex1; for (Ex1.Init(this->getWire()); Ex1.More(); ) { if(first == true) { firstEdge = Ex1.Current(); first = false; } Ex1.Next(); //if the number of edges is odd don't proceed if(Ex1.More() == Standard_False) break; nextEdge = Ex1.Current(); //get the common vertex of the two edges if (!TopExp::CommonVertex(firstEdge, nextEdge, vertex)) { // disconnected wire first = true; continue; } if (vertMap.Contains(vertex)) { int i = vertMap.FindIndex(vertex) - 1; if (distances_size == 1) { // single distance MF.AddChamfer(firstEdge, nextEdge, distances[0], distances[0]); } else if (distances_size == vertices_size) { // distance given for each vertex MF.AddChamfer(firstEdge, nextEdge, distances[i], distances[i]); } else { StdFail_NotDone::Raise("distances argument has wrong size"); } } firstEdge = nextEdge; } // special case for closed wire if (isClosed()) { // find seam vertex TopoDS_Vertex aV1; TopExp::Vertices(this->getWire(), vertex, aV1); // check if seam vertex has chamfer value if (vertMap.Contains(vertex)) { int i = vertMap.FindIndex(vertex) - 1; // map vertices to edges to find edge pair TopTools_IndexedDataMapOfShapeListOfShape mapVertexEdge; TopExp::MapShapesAndAncestors(this->getWire(), TopAbs_VERTEX, TopAbs_EDGE, mapVertexEdge); const TopTools_ListOfShape& edges = mapVertexEdge.FindFromKey(vertex); firstEdge = TopoDS::Edge(edges.First()); nextEdge = TopoDS::Edge(edges.Last()); if (distances_size == 1) { // single distance MF.AddChamfer(firstEdge, nextEdge, distances[0], distances[0]); } else if (distances_size == vertices_size) { // distance given for each vertex MF.AddChamfer(firstEdge, nextEdge, distances[i], distances[i]); } else { StdFail_NotDone::Raise("distances argument has wrong size"); } } } if(MF.Status() != ChFi2d_IsDone) StdFail_NotDone::Raise("chamfer operation failed"); TopTools_IndexedMapOfShape aMap; TopExp::MapShapes(MF.Shape(), TopAbs_WIRE, aMap); if(aMap.Extent() != 1) StdFail_NotDone::Raise("chamfer result did not result in single wire");; //add edges to the wire BRepBuilderAPI_MakeWire wire; BRepTools_WireExplorer Ex2; for(Ex2.Init(TopoDS::Wire(aMap(1))); Ex2.More(); Ex2.Next()) { wire.Add(Ex2.Current()); } this->setShape(wire.Shape()); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to chamfer wire"); } return 0; } return 1; }
int OCCWire::fillet(std::vector<OCCVertex *> vertices, std::vector<double> radius) { int vertices_size = vertices.size(); int radius_size = radius.size(); BRepFilletAPI_MakeFillet2d MF; try { if (this->getShape().IsNull()) { StdFail_NotDone::Raise("Shapes is Null"); } MF.Init(BRepBuilderAPI_MakeFace(this->getWire())); for (unsigned i=0; i<vertices.size(); i++) { OCCVertex *vertex = vertices[i]; if (radius_size == 1) { // single radius MF.AddFillet(vertex->getVertex(), radius[0]); } else if (radius_size == vertices_size) { // radius given for each vertex MF.AddFillet(vertex->getVertex(), radius[i]); } else { StdFail_NotDone::Raise("radius argument has wrong size"); } } if(MF.Status() != ChFi2d_IsDone) StdFail_NotDone::Raise("fillet not completed"); BRepBuilderAPI_MakeWire wire; TopTools_IndexedMapOfShape aMap; BRepTools_WireExplorer Ex; TopExp::MapShapes(MF.Shape(), TopAbs_WIRE, aMap); if(aMap.Extent() != 1) StdFail_NotDone::Raise("Fillet operation did not result in single wire"); //add edges to the wire Ex.Clear(); for(Ex.Init(TopoDS::Wire(aMap(1))); Ex.More(); Ex.Next()) { wire.Add(Ex.Current()); } this->setShape(wire); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to fillet wire"); } return 0; } return 1; }
void Werkstuck::LY(float endPunkt, float Rwz, float Lwz, float Rwz2) // прямое фрезерование по оси Х // endPunkt - конечная точка { if (Zwz<H0) { gp_Pnt punkt1(Xwz-Rwz,Ywz,Zwz); gp_Pnt punkt2(Xwz+Rwz,Ywz,Zwz); gp_Pnt punkt3(Xwz+Rwz,endPunkt,Zwz); gp_Pnt punkt4(Xwz,endPunkt,Zwz); if (endPunkt>=Ywz) punkt4.SetY(endPunkt+Rwz); else punkt4.SetY(endPunkt-Rwz); gp_Pnt punkt5(Xwz-Rwz,endPunkt,Zwz); Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2); Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3); Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeArcOfCircle(punkt3,punkt4 ,punkt5); Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt5 , punkt1); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2); TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3); TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4); TopoDS_Wire Basis = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4); TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis); if (firstRun) { fBasis = FlacheBasis; firstRun = false; } else { fBasis = BRepAlgo_Fuse(fBasis, FlacheBasis); gp_Vec PrismVec(0 , 0 , Lwz); TopoDS_Shape sLY = BRepPrimAPI_MakePrism(fBasis , PrismVec); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLY); TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE); while(aEdgeExplorer.More()) { TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLY = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLY); firstRun = true; } /*gp_Vec PrismVec(0 , 0 , Lwz); TopoDS_Shape sLY = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLY); TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE); while(aEdgeExplorer.More()){ TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLY = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLY);*/ } Ywz=endPunkt; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_MarkerDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IMarker aPI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == MARKER_CS) { double OX, OY, OZ; double XDX, XDY, XDZ; double YDX, YDY, YDZ; aPI.GetOrigin(OX, OY, OZ); aPI.GetXDir(XDX, XDY, XDZ); aPI.GetYDir(YDX, YDY, YDZ); gp_Pnt aPO (OX, OY, OZ); gp_Vec aVX (XDX, XDY, XDZ); gp_Vec aVY (YDX, YDY, YDZ); Standard_Real aTol = Precision::Confusion(); if (aVX.Magnitude() < aTol || aVY.Magnitude() < aTol || aVX.IsParallel(aVY, Precision::Angular())) { Standard_ConstructionError::Raise("Degenerated or parallel directions given"); } gp_Vec aN = aVX ^ aVY; gp_Ax3 anA (aPO, aN, aVX); gp_Pln aPln (anA); double aTrimSize = 100.0; aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape(); } else if (aType == MARKER_SHAPE) { Handle(GEOM_Function) aRefShape = aPI.GetShape(); TopoDS_Shape aSh = aRefShape->GetValue(); gp_Ax3 anAx3 = GEOMImpl_IMeasureOperations::GetPosition(aSh); gp_Pln aPln (anAx3); double aTrimSize = 100.0; aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape(); } else if (aType == MARKER_PNT2VEC) { Handle(GEOM_Function) aRefOrigin = aPI.GetOrigin(); Handle(GEOM_Function) aRefXVec = aPI.GetXVec(); Handle(GEOM_Function) aRefYVec = aPI.GetYVec(); TopoDS_Shape aShapeOrigin = aRefOrigin->GetValue(); TopoDS_Shape aShapeXVec = aRefXVec->GetValue(); TopoDS_Shape aShapeYVec = aRefYVec->GetValue(); if (aShapeOrigin.ShapeType() != TopAbs_VERTEX || aShapeOrigin.IsNull()) return 0; if (aShapeXVec.ShapeType() != TopAbs_EDGE || aShapeXVec.IsNull()) return 0; if (aShapeYVec.ShapeType() != TopAbs_EDGE || aShapeYVec.IsNull()) return 0; gp_Pnt aPO = BRep_Tool::Pnt( TopoDS::Vertex( aShapeOrigin ) ); gp_Pnt aPX1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeXVec ) ) ); gp_Pnt aPX2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeXVec ) ) ); gp_Vec aVX( aPX1, aPX2 ); gp_Pnt aPY1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeYVec ) ) ); gp_Pnt aPY2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeYVec ) ) ); gp_Vec aVY( aPY1, aPY2 ); if (aVX.Magnitude() < gp::Resolution() || aVY.Magnitude() < gp::Resolution()) Standard_ConstructionError::Raise ("Local CS creation aborted: vector of zero length is given"); if ( aVX.IsParallel(aVY, Precision::Angular())) Standard_ConstructionError::Raise("Parallel Vectors given"); gp_Vec aN = aVX ^ aVY; gp_Ax3 anA (aPO, aN, aVX); gp_Pln aPln (anA); double aTrimSize = 100.0; aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
void CSkinUnitODL::DrawImage(Gdiplus::Graphics& gcDrawer, Gdiplus::GraphicsPath& gcPath, Gdiplus::PointF& ptOffset, Gdiplus::REAL fScale) { if (m_imgSkin) { if (m_nWrapMode>=4) { //居中模式 Gdiplus::RectF rtArea; gcPath.GetBounds(&rtArea); Gdiplus::GraphicsPath gcDrawPath; //图片中间X:(width-imagewidth )/2 + left; //Y: (height - imageheight)/2 +top; Gdiplus::REAL fX0 = (rtArea.Width - m_fSkinWidth-m_nGroutX) /2.0f + rtArea.X; Gdiplus::REAL fY0 = (rtArea.Height - m_fSkinHeight-m_nGroutY) /2.0f + rtArea.Y; Gdiplus::REAL fX1 = m_fSkinWidth + m_nGroutX+ fX0; Gdiplus::REAL fY1 = m_fSkinHeight +m_nGroutY+ fY0; std::vector<Gdiplus::PointF> arrPt; arrPt.emplace_back(fX0, fY0); arrPt.emplace_back(fX1, fY0); arrPt.emplace_back(fX1, fY1); arrPt.emplace_back(fX0, fY1); Gdiplus::Matrix mx; Gdiplus::PointF ptCenter=Gdiplus::PointF((fX1+fX0)/2.0f, (fY1+fY0)/2.0f); mx.RotateAt(m_fRotate, ptCenter); mx.TransformPoints(arrPt.data(), arrPt.size()); gcDrawPath.AddPolygon(arrPt.data(),arrPt.size()); //如果图片的path大于当前区域Path,则居中操作在区域内 { BRepBuilderAPI_MakePolygon ply1; for (auto& ptPos:arrPt) { ply1.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y)); } ply1.Close(); TopoDS_Face face1 = BRepBuilderAPI_MakeFace(ply1.Wire()).Face(); std::vector<Gdiplus::PointF> arrPic; arrPic.resize(gcDrawPath.GetPointCount()); gcPath.GetPathPoints(arrPic.data(), arrPic.size()); BRepBuilderAPI_MakePolygon ply2; for (auto& ptPos:arrPic) { ply2.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y)); } ply2.Close(); TopoDS_Face face2 = BRepBuilderAPI_MakeFace(ply2.Wire()).Face(); BRepAlgoAPI_Common bc(face1, face2); auto face = bc.Shape(); TopExp_Explorer expWire(face, TopAbs_WIRE); std::vector<Gdiplus::PointF> arrDraw; for ( BRepTools_WireExplorer expVertex(TopoDS::Wire(expWire.Current())); expVertex.More(); expVertex.Next() ) { auto pnt = BRep_Tool::Pnt(expVertex.CurrentVertex()); arrDraw.emplace_back(static_cast<Gdiplus::REAL>(pnt.X()), static_cast<Gdiplus::REAL>(pnt.Z())); } gcDrawPath.Reset(); gcDrawPath.AddPolygon(arrDraw.data(), arrDraw.size()); } Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode; if (std::fabs(m_fRotate)<0.001f) { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); mx.Translate(fX0, fY0); brush.SetTransform(&mx); gcDrawer.FillPath(&brush, &gcDrawPath); } else { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); mx.Translate(fX0, fY0); brush.SetTransform(&mx); gcDrawer.FillPath(&brush, &gcDrawPath); } } else { //铺满模式 Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode; if (std::fabs(m_fRotate)<0.001f) { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); brush.TranslateTransform(ptOffset.X, ptOffset.Y); gcDrawer.FillPath(&brush, &gcPath); } else { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); brush.TranslateTransform(ptOffset.X, ptOffset.Y); brush.RotateTransform(m_fRotate); gcDrawer.FillPath(&brush, &gcPath); } } } }