def _analyze(self): faces = [] points = [] ex = TopExp_Explorer(self.shape,TopAbs_FACE) nb = 0 while ex.More(): F = TopoDS().Face(ex.Current()) L = TopLoc_Location() facing = (BRep_Tool().Triangulation(F,L)).GetObject() tri = facing.Triangles() tab = facing.Nodes() for i in range(1,facing.NbTriangles()+1): trian = tri.Value(i) index1, index2, index3 = trian.Get() p1 = tab.Value(index1).XYZ().Coord() p2 = tab.Value(index2).XYZ().Coord() p3 = tab.Value(index3).XYZ().Coord() if not p1 in points: points.append(p1) if not p2 in points: points.append(p2) if not p3 in points: points.append(p3) faces.append((p1,p2,p3)) ex.Next() for i,face in enumerate(faces): faces[i] = (points.index(face[0]),points.index(face[1]),points.index(face[2])) self.vertices_list = points self.triangles_list = faces
def readSTLShape(fileName): ts = TopoDS.TopoDS() log.info("Reading STL:'" + fileName + "'...") #read stl file shape = TopoDS.TopoDS_Shape() stl_reader = StlAPI.StlAPI_Reader() stl_reader.Read(shape, fileName) return fixShape(shape)
def process_wire(wire): '''takes a wire and extracts points returns a list of points''' vertices = [] explorer = BRepTools_WireExplorer(wire) while explorer.More(): vertex = TopoDS().Vertex(explorer.CurrentVertex()) xyz = Point(BRep_Tool().Pnt(vertex)) vertices.append(xyz) explorer.Next() return vertices
def process_face(face): '''traverses a face for wires returns a list of wires''' wires = [] explorer = TopExp_Explorer(face, TopAbs_EDGE) while explorer.More(): edge = TopoDS().Edge(explorer.Current()) wire = BRepBuilderAPI_MakeWire(edge).Wire() wires.append(wire) explorer.Next() return wires
def process_shape(shape): '''extracts faces from a shape note: if this doesnt work you should try process_face(shape) returns a list of faces''' faces = [] explorer = TopExp_Explorer(shape, TopAbs_FACE) while explorer.More(): face = TopoDS().Face(explorer.Current()) faces.append(face) explorer.Next() return faces
def __init__(self): self.tds = TopoDS() self.topoTypes = { TopAbs_VERTEX: self.tds.vertex, TopAbs_EDGE: self.tds.edge, TopAbs_FACE: self.tds.face, TopAbs_WIRE: self.tds.wire, TopAbs_SHELL: self.tds.shell, TopAbs_SOLID: self.tds.solid, TopAbs_COMPOUND: self.tds.compound, TopAbs_COMPSOLID: self.tds.compsolid, }
def build(self): self.update_name() args = self.args if isinstance(args[0], str): if args[0] == "cut": self.data = BRepAlgo_Cut(args[1].topology, args[2].topology) ex = TopExp_Explorer() ex.Init(self.data.Shape(), TopAbs_FACE) self.topology = TopoDS().Face(ex.Current()) else: self.value = args self.data = BRepBuilderAPI_MakeWire() for i in args: self.data.Add(i.topology) self.topology = BRepBuilderAPI_MakeFace(self.data.Wire()).Face()
def readSTLShape(fileName): ts = TopoDS.TopoDS() logging.info("Reading STL:'" + fileName + "'...") #read stl file shape = TopoDS.TopoDS_Shape() stl_reader = StlAPI.StlAPI_Reader() stl_reader.Read(shape, fileName) logging.info("Fixing holes and degenerated Meshes...") sf = ShapeFix.ShapeFix_Shape(shape) sf.Perform() fixedShape = sf.Shape() logging.info("Making Solid from the Shell...") #bb = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(ts.Shell(fixedShape)); #bb.Build(); bb = ShapeFix.ShapeFix_Solid() return bb.SolidFromShell(ts.Shell(fixedShape)) logging.info("Done.") return bb.Solid()
def execute(self): input_shape = self.input.shape topo = Topo(input_shape) self._n_edges = topo.number_of_edges() builder = BRepFilletAPI.BRepFilletAPI_MakeChamfer(input_shape) Map = TDF.TDF_LabelMap() itr = TDF.TDF_ChildIterator(self.parent_label, True) while itr.More(): sub_label = itr.Value() Map.Add(sub_label) itr.Next() selector = self.selector ret = selector.Solve(Map) if not ret: raise Exception("Failed to solve for edge") #print "Failed to solve for edge" nt = TNaming.TNaming_Tool() selected_shape = nt.CurrentShape(selector.NamedShape()) selected_edge = TopoDS.TopoDS().Edge(selected_shape) try: face = Topo(input_shape).faces_from_edge(selected_edge).next() except RuntimeError: raise #not sure how to handle this size = self.size builder.Add(size, size, selected_edge, face) self.update_naming(builder) return builder.Shape()
DEFAULT_FEEDRATE = 1.0; DEFAULT_DEFLECTION=0.001; OMIT_UNCHANGED_AXES=False; TOLERANCE=0.00001; ##### #utility class instances #available to all methods ##### #Brep_Tools = BRepTools.BRepTools(); Brep_Tool = BRep.BRep_Tool(); BRepLProp_CurveTool = BRepLProp.BRepLProp_CurveTool(); #TopoDS = TopoDS.TopoDS(); #TopExp = TopExp.TopExp() #TopExp_Explorer = TopExp.TopExp_Explorer(); ts = TopoDS.TopoDS(); def close(x,y): if x == None or y == None: return False; return abs(x - y ) < TOLERANCE; def printPoint(point): return "x=%0.4f,y=%0.4f,z=%0.4f" % (point.X(), point.Y(), point.Z()); """ State machine for creating gcode. This class will track the current position, which makes it easier to move along a particular path.
""" EdgeGraphs Utilties for representing wires and lists of edges in a graph. """ from OCC import BRep, gp, GeomAbs, GeomAPI, GCPnts, TopoDS, BRepTools, GeomAdaptor, TopAbs, TopTools, TopExp from OCC import BRepGProp, BRepLProp, BRepBuilderAPI, BRepPrimAPI, GeomAdaptor, GeomAbs, BRepClass, GCPnts, BRepBuilderAPI, BRepOffsetAPI, BRepAdaptor import time, os, sys, string, logging from OCC.Geom import * brepTool = BRep.BRep_Tool() topoDS = TopoDS.TopoDS() import TestDisplay import itertools import Wrappers import time def hashE(edge): return edge.HashCode(1000000) "an edge in a connected set of edges." class EdgeNode: "an edge node from an edge wrapper" def __init__(self, edgeWrapper, type):
from OCC import TopExp, BRepPrimAPI, TopAbs, TopoDS box = BRepPrimAPI.BRepPrimAPI_MakeBox(10., 20., 30.) ex = TopExp.TopExp_Explorer(box.Shape(), TopAbs.TopAbs_EDGE) results = [] while ex.More(): shape = TopoDS.TopoDS().Edge(ex.Current()) print "is null?", bool(shape.IsNull()) results.append(shape) ex.Next() ex.ReInit() for edge in results: print "null now?", bool(edge.IsNull())
def _readSTL(self, inputFileName): ts = TopoDS.TopoDS() shape = TopoDS.TopoDS_Shape() stl_reader = StlAPI.StlAPI_Reader() stl_reader.Read(shape, inputFileName) return shape