def splitEdge(edge, p): "splits an edge at the supplied parameter, returns the new edges" "separationDist is the distance of the break between the two edges" (handleCurve, pstart, pend) = BRep.BRep_Tool().Curve(edge) return (edgeFromTwoPointsOnCurve(handleCurve, pstart, p), edgeFromTwoPointsOnCurve(handleCurve, p, pend))
def TestShortenEdge(): #test trimming and such e1 = edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(1, 1, 0)) display.DisplayColoredShape(e1, 'BLUE') #just for testing, get the parameters of the new edge. (handleCurve, p1, p2) = BRep.BRep_Tool().Curve(e1) p = (p1 + p2) / 2 display.DisplayColoredShape(splitEdge(e1, p, 0.1), 'RED') #display.DisplayColoredShape( shortenEdge(e1,p1,0.1), 'WHITE'); display.DisplayColoredShape(shortenEdge(e1, p2, 0.1), 'WHITE')
def get2dCurveFrom3dEdge(edge): """ returns a curve given an edge. here, we want to get a curve from a 3dEdge, since with this approach we'll only be getting existing curves from a 3d source """ #first, convert the curve to a 2d curve btool = BRep.BRep_Tool() handleCurve = btool.Curve(edge)[0] return GeomAPI.GeomAPI().To2d(handleCurve, gp.gp_Pln(gp.gp_Pnt(0, 0, 0), gp.gp().DZ()))
def get_vertices(shape, length): bt = BRep.BRep_Tool() t = Topo(shape) vertices = t.vertices() vert = [] for vertex in vertices: vert.append([ correctLengt(bt.Pnt(vertex).Coord()[0], length, None), correctLengt(bt.Pnt(vertex).Coord()[1], length, None), correctLengt(bt.Pnt(vertex).Coord()[2], length, None) ]) return vert
def __init__(self, edge): self.edge = edge hc = BRep.BRep_Tool().Curve(edge) self.curve = GeomAdaptor.GeomAdaptor_Curve(hc[0]) self.handleCurve = hc[0] self.firstParameter = hc[1] self.lastParameter = hc[2] p1 = self.curve.Value(self.firstParameter) p2 = self.curve.Value(self.lastParameter) #compute the first and last points, which are very commonly used if edge.Orientation() == TopAbs.TopAbs_FORWARD: self.reversed = False self.firstPoint = p1 self.lastPoint = p2 else: self.reversed = True self.firstPoint = p2 self.lastPoint = p1
import time,os,sys,string; import itertools # OCC imports from OCC import BRep,gp,GeomAbs,GeomAPI,GCPnts,TopoDS,BRepTools,GeomAdaptor,TopAbs,TopTools,TopExp,Approx,BRepLib,Bnd,BRepBndLib from OCC import BRepGProp,BRepLProp, BRepBuilderAPI,BRepPrimAPI,GeomAdaptor,GeomAbs,BRepClass,GCPnts,BRepBuilderAPI,BRepOffsetAPI,BRepAdaptor from OCC import BRepExtrema,TColgp from OCC import ShapeAnalysis from OCC.Utils import Topo from OCC import ShapeFix,ShapeExtend # project files import TestObjects import OCCUtil brepTool = BRep.BRep_Tool(); """ Smart Wire Builder.. accepts edges, and then uses WireOrder to connect them together into the best possible edges """ class WireBuilder: def __init__(self): self.edges = []; self.fixer = ShapeFix.ShapeFix_Wire(); self.wireData = ShapeExtend.ShapeExtend_WireData(); def add(self,edge):
def trimmedEdge(edge, p1, p2): "returns a new edge that is a trimmed version of the underlying one" hc = BRep.BRep_Tool().Curve(edge) return edgeFromTwoPointsOnCurve(hc[0], p1, p2)
## X change naming of slice() to something else ## X recognize .stp in addition to .step ## X install guide ## X remove unneed dumpTopology and shapeDescription ## add 2d per-slice view on select of slice ## X add ability to easily select slice thickness ## add separate display for original object and slices ## X sew faces from crappy stl files into single faces somehow ## X remove reference to profile import ##### #utility class instances #available to all methods ##### brt = BRepTools.BRepTools() btool = BRep.BRep_Tool() ts = TopoDS.TopoDS() topexp = TopExp.TopExp() texp = TopExp.TopExp_Explorer() """ Utility class to provide timing information """ class Timer: def __init__(self): self.startTime = time.time() self.startAscTime = time.asctime() def start(self): return self.startTime
import TestWires import bresenham import hexagonlib2d from OCC.Display.SimpleGui import * display, start_display, add_menu, add_function_to_menu = init_display() import pixMapTileTest import breshamtest as bres #import bresenham as bres import numpy as np import networkx as nx import hexagonlib import hexagonlib2d brt = BRep.BRep_Tool() def tP(x, y): "convert x-y tuple to a gp pnt" return gp.gp_Pnt2d(x, y) def edgeFromTwoPoints(p1, p2): "make a linear edge from two 2d points. p1 and p2 are simple (x,y) tuples " builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(tP(p1[0], p1[1]), tP(p2[0], p2[1])) builder.Build() if builder.IsDone(): return builder.Edge() else: