For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

How to Correct TopoDS_Face?

George Stavrou's picture
Forums: 

Hi

I have a problem with wires, BRep_Builder and  TopoDS_Face. Everything goes as i want but the BRepPrimAPI_MakePrism gives me a surface shape instead of a solid. I known there is a problem in my code with the face and the wires orientation but i cannot fix it. Below is the code it self and also i have include an attached photo of the result.   

double outerDiameter = 50;
		double outerRadius = outerDiameter/2;
		double offsetInnerCircle = 5;
		double X = 5;
		double slotHeight = 10;
		double slotDiameter = 10;
		double holeDiameter = 3;
		double circularPattern = 10;
		double phi = M_PI / 2 - acos(X / outerRadius);
		double Y = outerRadius * sin(M_PI / 2 - phi);
		
		gp_Pnt pnt1(X, Y, 0.);
		gp_Pnt pnt2(X, Y + slotHeight, 0.);
		gp_Pnt pnt3(-X, Y + slotHeight, 0.);
		gp_Pnt pnt4(-X, Y, 0.);

		double phiX = 2 * M_PI / circularPattern- phi;
		gp_Pnt pntX(-outerRadius * cos(M_PI/2 - phiX), outerRadius * sin(M_PI/2 - phiX), 0.);

		//slot edge 1
		TopoDS_Edge edgeSlot1 = BRepBuilderAPI_MakeEdge(pnt1, pnt2);
		TopoDS_Wire wireSlot1 = BRepBuilderAPI_MakeWire(edgeSlot1);
		//axis for all circulars, i use circAxis.SetLocation(gp_Pnt(0., 0., 0.)); to change the location of center
		gp_Ax2 circAxis(gp_Pnt(0., 0, 0.), gp_Dir(0., 0., 1));
		//slot half circle
		circAxis.SetLocation(gp_Pnt(0., Y + slotHeight, 0.));
		gp_Circ aCirc(circAxis, slotDiameter /2);
		TopoDS_Edge aCircSlot = BRepBuilderAPI_MakeEdge(aCirc,pnt2,pnt3);
		TopoDS_Wire aCircSlotWire = BRepBuilderAPI_MakeWire(aCircSlot);      
		//slot holes
		gp_Circ holeCirc(circAxis, holeDiameter / 2);
		TopoDS_Edge aCircSlotHole = BRepBuilderAPI_MakeEdge(holeCirc);
		TopoDS_Wire holesCircWire = BRepBuilderAPI_MakeWire(aCircSlotHole);
		//slot edge 2
		TopoDS_Edge edgeSlot2 = BRepBuilderAPI_MakeEdge(pnt3, pnt4);
		TopoDS_Wire wireSlot2 = BRepBuilderAPI_MakeWire(edgeSlot2);
		//outer circle		
		circAxis.SetLocation(gp_Pnt(0., 0., 0.));
		gp_Circ outerCirc(circAxis, outerRadius);
		TopoDS_Edge outerCircEdge = BRepBuilderAPI_MakeEdge(outerCirc, pnt4, pntX);
		TopoDS_Wire outerCircWire = BRepBuilderAPI_MakeWire(outerCircEdge);
		//inner circle
		gp_Circ innerCirc(circAxis, outerRadius- offsetInnerCircle);
		TopoDS_Edge innerCircEdge = BRepBuilderAPI_MakeEdge(innerCirc);
		innerCircEdge.Orientation();
		TopoDS_Wire innerCircWire = BRepBuilderAPI_MakeWire(innerCircEdge);
		

		BRepBuilderAPI_MakeWire slotWire;
		slotWire.Add(wireSlot1);
		slotWire.Add(aCircSlotWire);
		slotWire.Add(wireSlot2);
		TopoDS_Wire aSlot = slotWire.Wire();


		//create a circular pattern
		BRep_Builder aBuilder;
		gp_Pln planeXY(gp_Pnt(0.,0.,0.),gp_Dir(0.,0.,1));
		TopoDS_Face faceProfile = BRepBuilderAPI_MakeFace(planeXY);
		faceProfile.Infinite();

		for (int i = 0; i < circularPattern; i++)
		{
			TopoDS_Wire aSlotWire = BRepBuilderAPI_MakeWire(aSlot);
			TopoDS_Wire aCircWire = BRepBuilderAPI_MakeWire(outerCircWire);
			TopoDS_Wire aHoleWire = BRepBuilderAPI_MakeWire(holesCircWire);
			gp_Trsf rot;
			rot.SetRotation(gp_Ax1(gp_Pnt(0., 0., 0.), gp_Dir(0, 0, 1)), 2.*M_PI*i / circularPattern);
			aSlotWire.Move(rot);
			aHoleWire.Move(rot);
			aCircWire.Move(rot);
			aBuilder.Add(faceProfile, aSlotWire);
			aBuilder.Add(faceProfile, aCircWire);
			aBuilder.Add(faceProfile, aHoleWire.Reversed());
		}
		
		aBuilder.Add(faceProfile,innerCircWire.Reversed());
			
		TopoDS_Shape ok = BRepPrimAPI_MakePrism(faceProfile,gp_Vec(0.,0.,10), Standard_True, Standard_False);
					
		return ok;

Attachments: