def collect_dumpable_shapes(self, shape): if shape.ShapeType() == TopAbs_EDGE: points = [] try: points = discretize_edge(shape, 0.25) except: points = [] else: debug("Discretize done !") return points debug("edge: %s/%s"%(str(shape), self.describe_edge(shape))) it = TopoDS_Iterator(shape) points = [] while it.More(): shp = it.Value() brt = BRep_Tool() debug("vertex: %s"%(str(shp),)) pnt = brt.Pnt(topods_Vertex(shp)) points.append((pnt.X(), pnt.Y(), pnt.Z())) it.Next() return points else: lines = [] it = TopoDS_Iterator(shape) while it.More(): shp = it.Value() lines.append(self.collect_dumpable_shapes(shp)) it.Next() return lines
def shape_iter(self): """ :return: Yield the underlying sub-shape(s). :rtype: collections.Iterable(afem.topology.entities.Shape) """ it = TopoDS_Iterator(self.object) while it.More(): yield Shape.wrap(it.Value()) it.Next()
def dumpTopology0(shape): brt = BRep_Tool() s = shape.ShapeType() #if s == TopAbs_VERTEX: # pnt = brt.Pnt(topods_Vertex(shape)) # print(".." * level + "<Vertex %i: %s %s %s>" % (hash(shape), pnt.X(), pnt.Y(), pnt.Z())) #else: # print(".." * level, shapeTypeString(shape)) st += get_dicostring(s, iface, brt, shape) it = TopoDS_Iterator(shape) while it.More(): shp = it.Value() it.Next() dumpTopology(shp)
def dumpTopology(shape, level=0): """ Print the details of an object from the top down """ brt = BRep_Tool() s = shape.ShapeType() if s == TopAbs_VERTEX: pnt = brt.Pnt(topods_Vertex(shape)) print(".." * level + "<Vertex %i: %s %s %s>" % (hash(shape), pnt.X(), pnt.Y(), pnt.Z())) else: print(".." * level, end="") print(shapeTypeString(shape)) it = TopoDS_Iterator(shape) while it.More(): shp = it.Value() it.Next() dumpTopology(shp, level + 1)
def dump_topology_to_string(shape, level=0, buffer=""): """ Reutnrs the details of an object from the top down """ brt = BRep_Tool() s = shape.ShapeType() if s == TopAbs_VERTEX: pnt = brt.Pnt(topods_Vertex(shape)) print(".." * level + "<Vertex %i: %s %s %s>\n" % (hash(shape), pnt.X(), pnt.Y(), pnt.Z())) else: print(".." * level, end="") print(shape_type_string(shape)) it = TopoDS_Iterator(shape) while it.More() and level < 5: # LEVEL MAX shp = it.Value() it.Next() dump_topology_to_string(shp, level + 1, buffer)
def dump_topology_to_string(shape: TopoDS_Shape, level: Optional[int] = 0, buffer: Optional[str] = "") -> None: """ Return the details of an object from the top down """ brt = BRep_Tool() s = shape.ShapeType() if s == TopAbs_VERTEX: pnt = brt.Pnt(topods_Vertex(shape)) print(".." * level + f"<Vertex {hash(shape)}: {pnt.X()} {pnt.Y()} {pnt.Z()}>\n") else: print(".." * level, end="") print(shape) it = TopoDS_Iterator(shape) while it.More() and level < 5: # LEVEL MAX shp = it.Value() it.Next() dump_topology_to_string(shp, level + 1, buffer)
def DumpTop(self, shape, level=0): """ Print the details of an object from the top down """ brt = BRep_Tool() s = shape.ShapeType() if s == TopAbs_VERTEX: pnt = brt.Pnt(topods_Vertex(shape)) dmp = " " * level dmp += "%s - " % shapeTypeString(shape) dmp += "%.5e %.5e %.5e" % (pnt.X(), pnt.Y(), pnt.Z()) print(dmp) else: dmp = " " * level dmp += shapeTypeString(shape) print(dmp) it = TopoDS_Iterator(shape) while it.More(): shp = it.Value() it.Next() self.DumpTop(shp, level + 1)
def shape_array(a_shape): iterator = TopoDS_Iterator(a_shape) out_shape = None while iterator.More(): print '---------- iterator ------' print iterator.Value().Reversed().Closed() classifier = BRepClass3d_SolidClassifier(iterator.Value(), gp_Pnt(15., 2., 1.), 0.000001) test = classifier.State() if (test == 0) and (not out_shape): out_shape = iterator.Value() iterator.Next() return out_shape
def is_on_solid(pts, shape): # are all of the pts points on shape ? iterator = TopoDS_Iterator(shape) belong = [False for p in pts] for i, p in enumerate(pts): classifier = BRepClass3d_SolidClassifier(shape, gp_Pnt(p[0], p[1], p[2]), 0.00001) test = classifier.State() if (test == 2): belong[i] = True if belong == [True for p in pts]: return True else: return False