def _makeSlice(self, shapeToSlice, zLevel): s = Slice() #used to determine if a slice is identical to others. s.hatchDir = self.hatchReversed s.fillWidth = self.options.filling.fillWidth #change if layers are variable thickness s.sliceHeight = self.options.layerHeight s.zLevel = zLevel #make a cutting plane p = gp.gp_Pnt(0, 0, zLevel) origin = gp.gp_Pnt(0, 0, zLevel - 1) csys = gp.gp_Ax3(p, gp.gp().DZ()) cuttingPlane = gp.gp_Pln(csys) bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane) face = bff.Face() #odd, a halfspace is faster than a box? hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin) hs.Build() halfspace = hs.Solid() #make the cut bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace) cutShape = bc.Shape() foundFace = False for face in Topo(cutShape).faces(): if self._isAtZLevel(zLevel, face): foundFace = True log.debug("Face is at zlevel" + str(zLevel)) s.addFace(face) #TestDisplay.display.showShape(face); log.debug("Face" + str(face)) if self.options.useSliceFactoring: mySum = s.getCheckSum() #print 'Slice Created, Checksum is',mySum; for otherSlice in self.slices: #print "Slice Checksum=",otherSlice.getCheckSum(); if mySum == otherSlice.getCheckSum(): log.info( "This slice matches another one exactly. using that so we can save time." ) return otherSlice.copyToZ(zLevel) if not foundFace: log.warn("No faces found after slicing at zLevel " + str(zLevel) + " !. Skipping This layer completely") return None else: return s
def _makeSlice(self, shapeToSlice, zLevel): s = Slice() #change if layers are variable thickness s.sliceHeight = self.sliceHeight s.zLevel = zLevel #make a cutting plane p = gp.gp_Pnt(0, 0, zLevel) origin = gp.gp_Pnt(0, 0, zLevel - 1) csys = gp.gp_Ax3(p, gp.gp().DZ()) cuttingPlane = gp.gp_Pln(csys) bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane) face = bff.Face() #odd, a halfspace is faster than a box? hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin) hs.Build() halfspace = hs.Solid() #make the cut bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace) cutShape = bc.Shape() #search the shape for faces at the specified zlevel texp = TopExp.TopExp_Explorer() texp.Init(cutShape, TopAbs.TopAbs_FACE) foundFace = False while (texp.More()): face = ts.Face(texp.Current()) if self._isAtZLevel(zLevel, face): foundFace = True logging.debug("Face is at zlevel" + str(zLevel)) s.addFace(face, self.saveSliceFaces) texp.Next() #free memory face.Nullify() bc.Destroy() texp.Clear() texp.Destroy() if not foundFace: logging.warn("No faces found after slicing at zLevel " + str(zLevel) + " !. Skipping This layer completely") return None else: return s
def makeSection(self, cuttingPlane, shapeToSection, zLevel): """ Uses halfspaces to make a cut. """ bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane) face = bff.Face() origin = gp.gp_Pnt(0, 0, zLevel - 1) #odd, a halfspace is faster than a box? hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin) hs.Build() halfspace = hs.Solid() #make the cut bc = BRepAlgoAPI.BRepAlgoAPI_Cut(self.solid.shape, halfspace) cutShape = bc.Shape() ff = [] for face in Topo(cutShape).faces(): if OCCUtil.isFaceAtZLevel(zLevel, face): ff.append(face) return ff