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()
Beispiel #2
0
    def fixDefects(self):
        """
			fixes a shape
		"""
        sf = ShapeFix.ShapeFix_Shape(self.shape)
        sf.SetMaxTolerance(TOLERANCE)

        msgRegistrator = ShapeExtend.ShapeExtend_MsgRegistrator()
        sf.SetMsgRegistrator(msgRegistrator.GetHandle())

        sf.Perform()

        #log.info("ShapeFix Complete.");
        #for i in range(0,18):
        #	log.info( "ShapeFix Status %d --> %s" % ( i, sf.Status(i) ));

        fixedShape = sf.Shape()
        #fixedShape = shape;

        #if the resulting shape is a compound, we need to convert
        #each shell to a solid, and then re-create a new compound of solids
        """
		if fixedShape.ShapeType() == TopAbs.TopAbs_COMPOUND:
	
			log.warn("Shape is a compound. Creating solids for each shell.");
			builder= BRep.BRep_Builder();
			newCompound = TopoDS.TopoDS_Compound();
			#newCompound = TopoDS.TopoDS_CompSolid();
			builder.MakeCompound(newCompound);
			#builder.MakeCompSolid(newCompound);
			for shell in Topo(fixedShape).shells():
				
				solidBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(shell);
				solid = solidBuilder.Solid();
				sa = SolidAnalyzer(solid);
				print sa.friendlyDimensions();
				builder.Add(newCompound, solid);
			
			#time.sleep(4);
			#Topology.dumpTopology(newCompound);
			return newCompound;  #return temporarily after the first one
		else:
			log.info("Making Solid from the Shell...");
	
			solidBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(ts.Shell(fixedShape));
			return solidBuilder.Solid();
		"""
        self.shape = fixedShape
Beispiel #3
0
def fixShape(shape):
    """
		fixes a shape
	"""
    log.info("Fixing holes and degenerated Meshes...")
    sf = ShapeFix.ShapeFix_Shape(shape)
    sf.SetMaxTolerance(TOLERANCE)

    msgRegistrator = ShapeExtend.ShapeExtend_MsgRegistrator()
    sf.SetMsgRegistrator(msgRegistrator.GetHandle())

    sf.Perform()

    log.info("ShapeFix Complete.")
    for i in range(0, 18):
        log.info("ShapeFix Status %d --> %s" % (i, sf.Status(i)))

    fixedShape = sf.Shape()
    #fixedShape = shape;
    return fixedShape
    #if the resulting shape is a compound, we need to convert
    #each shell to a solid, and then re-create a new compound of solids
    if fixedShape.ShapeType() == TopAbs.TopAbs_COMPOUND:

        log.warn("Shape is a compound. Creating solids for each shell.")
        builder = BRep.BRep_Builder()
        newCompound = TopoDS.TopoDS_Compound()
        #newCompound = TopoDS.TopoDS_CompSolid();
        builder.MakeCompound(newCompound)
        #builder.MakeCompSolid(newCompound);
        for shell in Topo(fixedShape).shells():

            solidBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(shell)
            solid = solidBuilder.Solid()
            builder.Add(newCompound, solid)

        #time.sleep(4);
        #Topology.dumpTopology(newCompound);
        return newCompound
        #return temporarily after the first one
    else:
        log.info("Making Solid from the Shell...")

        solidBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(
            ts.Shell(fixedShape))
        return solidBuilder.Solid()
Beispiel #4
0
 def __init__(self):
     self.edges = [];
     self.fixer = ShapeFix.ShapeFix_Wire();
     self.wireData = ShapeExtend.ShapeExtend_WireData();