def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] point1 = inp # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == point1: raise InvalidInputException dirvec = vec(0, 0, 0) dirvec[direction] = 1 axis = gp.gp_Ax2(point0, dirvec.to_gp_Dir()) d = point0 - inp d[direction] = 0 dist = d.length() a = Geom.Geom_Circle(axis, dist).GetHandle() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() c = BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire() d = BRepBuilderAPI.BRepBuilderAPI_MakeFace(c).Face() self._final = [d] return self._final
def make_interp_parabola(FL, rmin, rmax, segments=50): A = 1./(4*FL) x = numpy.linspace(rmin, rmax, segments) y = (A * x**2) - FL points = [(X,0,Z) for X,Z in zip(x,y)] points.append((x[0],0,y[-1])) def pairs(itr): a,b = itertools.tee(itr) next(b) return zip(a,b) edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge( gp.gp_Pnt(*p1), gp.gp_Pnt(*p2)) for p1, p2 in pairs(points)) last_edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge( gp.gp_Pnt(*points[-1]), gp.gp_Pnt(*points[0])) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) wire.Add(last_edge.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)) revol = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax) return revol.Shape()
def make_rays_wires(listOfRays, scale=None): raysItr = iter(listOfRays) first = next(raysItr) def MakeVertex(pt): vt = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*pt)) #print "make vertex", pt, vt return vt def MakeEdge(v1, v2): e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex()) #print "make edge", v1, v2, e return e wires = [BRepBuilderAPI.BRepBuilderAPI_MakeWire() for i in range(first.origin.shape[0])] v_start = [MakeVertex(pt) for pt in first.origin] v_end = [MakeVertex(pt) for pt in first.termination] first_edges = [MakeEdge(v1,v2) for v1, v2 in zip(v_start, v_end)] for edge, wire in zip(first_edges, wires): wire.Add(edge.Edge()) id_map = list(range(len(wires))) for rays in raysItr: id_map = [id_map[pid] for pid in rays.parent_idx] v_start = [v_end[pid] for pid in rays.parent_idx] v_end = [MakeVertex(pt) for pt in rays.termination] edges = [MakeEdge(v1,v2) for v1, v2 in zip(v_start, v_end)] for edge, w_id in zip(edges, id_map): wires[w_id].Add(edge.Edge()) return make_compound([w.Shape() for w in wires])
def makeKeyHoleWire(): circle2 = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(40, 40, 2), gp.gp_Dir(0, 0, 1)), 10) Edge4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle2, gp.gp_Pnt(40, 50, 2), gp.gp_Pnt(50, 40, 2)).Edge() ExistingWire2 = BRepBuilderAPI.BRepBuilderAPI_MakeWire(Edge4).Wire() P1 = gp.gp_Pnt(50, 40, 2) P2 = gp.gp_Pnt(80, 40, 2) #5,204,0 Edge5 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(P1, P2).Edge() MW = BRepBuilderAPI.BRepBuilderAPI_MakeWire() MW.Add(Edge5) MW.Add(ExistingWire2) if MW.IsDone(): WhiteWire = MW.Wire() return [WhiteWire, Edge5, ExistingWire2]
def makeCircleWire(): "designed to be include inside the square to simulate an island" circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 2, 0), gp.gp().DZ()), 1) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) return mw.Wire()
def wireFromEdges(edgeList): "TODO: might need to use sortwires to make sure it is i nthe right order" mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edgeList: mw.Add(e) if mw.IsDone(): return mw.Wire() else: raise ValueError, "Error %d Building Wire" % mw.Error()
def make_wire(listOfPoints, close=False): vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in listOfPoints] edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) for v1,v2 in pairs(vertices)] if close: edges.append(BRepBuilderAPI.BRepBuilderAPI_MakeEdge(vertices[-1].Vertex(), vertices[0].Vertex())) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) return toshape(wire)
def makeHexArray(self, bottomLeftCenter, countX, countY): """ makes an array of hexagons bottomLeftCenter is the center of the top left hex, as a three-element tuple countX is the number of hexes in the x direction countY is the number of hexes in the y direction returns a list of wires representing a hexagon fill pattern """ pattern = self.makePeriodic(bottomLeftCenter) wireBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeWire(pattern) #make horizontal array tsf = gp.gp_Trsf() pDist = 2.0 * self.cartesianSpacing()[0] tsf.SetTranslation(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(pDist, 0, 0)) tx = BRepBuilderAPI.BRepBuilderAPI_Transform(tsf) currentShape = pattern for i in range(1, int((countX / 2) + 1)): tx.Perform(currentShape, False) currentShape = tx.Shape() #display.DisplayShape(currentShape); wireBuilder.Add(Wrappers.cast(currentShape)) #create an array by alternately offsetting one cell right and #moving down topHalf = wireBuilder.Wire() #topHalf= approximatedWire(topHalf); wires = [] wires.append(topHalf) dY = self.cartesianSpacing()[1] / 2.0 dX = self.cartesianSpacing()[0] ####TODO// performance note. This method takes about 31ms to compute 1000x1000 hex. # pretty good, except that nearly 50% of the time is spent in makeTransform!!! # a much better method would be to use the same transform object somehow for i in range(1, int(countY * 2)): if i % 2 == 0: t = makeTransform(0, dY * i, 0) else: t = makeTransform(dX, dY * i, 0) t.Perform(topHalf, False) w = Wrappers.cast(t.Shape()) #approximate the wire #wires.append ( approximatedWire(w)); wires.append(w) #display.DisplayShape(wires); return wires
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == inp: raise InvalidInputException a = GC.GC_MakeSegment(inp, point0).Value() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()] return self._final
def makeReversedWire(): "this is a square" p1 = gp.gp_Pnt(.5, .5, 0) p2 = gp.gp_Pnt(1, 4, 0) p3 = gp.gp_Pnt(2, 4, 0) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2).Edge() e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p2).Edge() e2.Reverse() e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p1).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) mw.Add(e2) mw.Add(e3) return mw.Wire()
def makeSquareWithRoundHole(): points = [(0, 0), (0.05, -1.0), (1.0, 0), (2.0, 0), (2.0, 6.0), (0.0, 6.0)] ow = makeWireFromPointList(points) circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(1.0, 2, 0), gp.gp().DZ()), 0.75) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) circle = mw.Wire() builder = BRepBuilderAPI.BRepBuilderAPI_MakeFace(ow, True) builder.Add(circle) return builder.Face()
def makeSquareWire(): "this is a square" p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(5, 0, 0) p3 = gp.gp_Pnt(5, 5, 0) p4 = gp.gp_Pnt(0, 5, 0) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2).Edge() e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2, p3).Edge() e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p4).Edge() e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4, p1).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) mw.Add(e2) mw.Add(e3) mw.Add(e4) return mw.Wire()
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == inp: raise InvalidInputException point1 = inp dir_ = point1 - point0 len = dir_.length() p0 = point0 + 1000/len * dir_ p1 = point0 - 1000/len * dir_ a = GC.GC_MakeSegment(p0.to_gp_Pnt(), p1.to_gp_Pnt()).Value() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()] return self._final
def make_spherical_lens2(CT1, CT2, diameter, curvature1, curvature2, centre, direction, x_axis): cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT1-curvature1), gp.gp_Dir(0,sign(curvature1),0), gp.gp_Dir(1,0,0)) circ = Geom.Geom_Circle(cax, abs(curvature1)) h_circ = Geom.Handle_Geom_Circle(circ) cax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,CT2-curvature2), gp.gp_Dir(0,-sign(curvature2),0), gp.gp_Dir(1,0,0)) circ2 = Geom.Geom_Circle(cax2, abs(curvature2)) h_circ2 = Geom.Handle_Geom_Circle(circ2) r = diameter/2. h2 = CT1 - curvature1 + numpy.sqrt(curvature1**2 - r**2)*sign(curvature1) h3 = CT2 - curvature2 + numpy.sqrt(curvature2**2 - r**2)*sign(curvature2) p1 = gp.gp_Pnt(0,0,CT1) p2 = gp.gp_Pnt(r,0,h2) p3 = gp.gp_Pnt(r,0,h3) p4 = gp.gp_Pnt(0,0,CT2) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ2, p3,p4) e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in (e1,e2,e3,e4): print(e) wire.Add(e.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)) solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax) return position_shape(toshape(solid), centre, direction, x_axis)
def make_ellipsoid_2(focus1, focus2, major_axis): f1 = numpy.asarray(focus1) f2 = numpy.asarray(focus2) direction = -(f1 - f2) centre = (f1 + f2)/2. sep = numpy.sqrt((direction**2).sum()) minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 ) el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), major_axis, minor_axis) edge1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(el, gp.gp_Pnt(0,0,major_axis), gp.gp_Pnt(0,0,-major_axis)) edge2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0,0,-major_axis), gp.gp_Pnt(0,0,major_axis)) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() wire.Add(edge1.Edge()) wire.Add(edge2.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) el = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)), numpy.pi*2) loc = gp.gp_Ax3() loc.SetLocation(gp.gp_Pnt(*centre)) loc.SetDirection(gp.gp_Dir(*direction)) tr = gp.gp_Trsf() tr.SetTransformation(loc, gp.gp_Ax3()) trans = BRepBuilderAPI.BRepBuilderAPI_Transform(el.Shape(), tr) shape = toshape(trans) return shape
def make_spherical_lens(CT, diameter, curvature, centre, direction, x_axis): cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT-curvature), gp.gp_Dir(0,1,0), gp.gp_Dir(1,0,0)) circ = Geom.Geom_Circle(cax, curvature) h_circ = Geom.Handle_Geom_Circle(circ) r = diameter/2. h2 = CT - curvature + numpy.sqrt(curvature**2 - r**2) p1 = gp.gp_Pnt(0,0,CT) p2 = gp.gp_Pnt(r,0,h2) p3 = gp.gp_Pnt(r,0,0) p4 = gp.gp_Pnt(0,0,0) #ps = p1,p2,p3,p4 #vs = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(p) for p in ps] e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3,p4) e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in (e1,e2,e3,e4): print(e) wire.Add(e.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)) solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax) return position_shape(toshape(solid), centre, direction, x_axis)
radius = 25.0 sph = Geom.Geom_SphericalSurface(gp.gp_Ax3(), radius) h_sph = Geom.Handle_Geom_SphericalSurface(sph) c_rad = 12.0 #cylinder radius cyl = Geom.Geom_CylindricalSurface(gp.gp_Ax3(), c_rad) h_cyl = Geom.Handle_Geom_CylindricalSurface(cyl) intersect = GeomAPI.GeomAPI_IntSS(h_sph, h_cyl, 1e-7) edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge(intersect.Line(i)) for i in xrange(1, intersect.NbLines() + 1)) wires = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(e.Edge()) for e in edges] g_sph = gp.gp_Sphere(gp.gp_Ax3(), radius) faces = [BRepBuilderAPI.BRepBuilderAPI_MakeFace(w.Wire()) for w in wires] cyl_face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(h_cyl) #cyl_face.Add(wires[0].Wire()) #cyl_face.Add(wires[1].Wire()) #shell = TopoDS.TopoDS_Shell() shell_builder = BRep.BRep_Builder() #shell_builder.MakeShell(shell) #shell_builder.Add(shell, cyl_face.Shape()) #for f in faces: # shell_builder.Add(shell, f.Shape()) #sewing = BRepBuilderAPI.BRepBuilderAPI_Sewing()
def pairs(itr): a,b = tee(itr) b.next() return izip(a,b) points = [(0,0,0), (1,1,1), (0,0,-2), (0,2,0)] vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in points] #print "verts", vertices #edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) # for v1,v2 in pairs(vertices)] v=vertices edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v[i].Vertex(),v[j].Vertex()) for i,j, in [(0,1),(0,2),(0,3)] ] #print "edges", edges wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) print wire step_export = STEPControl.STEPControl_Writer() step_export.Transfer(wire.Shape(), STEPControl.STEPControl_AsIs) step_export.Write("/home/bryan/test_wire.stp")
def MakeWire(edgeList): bd = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edgeList: bd.Add(e.Edge()) return bd