def addEntireLayer(self, layerIndex): "Add entire thread layer." surroundingLoops = self.islandLayers[layerIndex] for line in self.threadLayers[layerIndex].beforeExtrusionLines: self.addLine(line) euclidean.addToThreadsRemoveFromSurroundings(self.oldOrderedLocation, surroundingLoops, self)
def addFill( self, layerIndex ): "Add fill to the slice layer." # if layerIndex > 5: # return alreadyFilledArounds = [] arounds = [] back = - 999999999.0 layerExtrusionWidth = self.extrusionWidth layerFillInset = self.fillInset layer = self.rotatedLayers[ layerIndex ].toBeginningLoops self.addLine( '(<layerStart> ' + str( layer[ 0 ][ 0 ].z ) + ' )' ) # Indicate that a new layer is starting. if self.rotatedLayers[ layerIndex ].rotation != None: layerExtrusionWidth = self.extrusionWidth * self.bridgeExtrusionWidthOverSolid layerFillInset = self.fillInset * self.bridgeExtrusionWidthOverSolid self.addLine( '(<bridgeLayer> )' ) # Indicate that this is a bridge layer. doubleExtrusionWidth = 2.0 * layerExtrusionWidth muchGreaterThanLayerFillInset = 3.0 * layerFillInset endpoints = [] fill = [] aroundInset = 0.7 * layerFillInset front = - back slightlyGreaterThanFill = 1.01 * layerFillInset layerRotationAroundZAngle = self.getLayerRoundZ( layerIndex ) reverseRotationAroundZAngle = complex( layerRotationAroundZAngle.real, - layerRotationAroundZAngle.imag ) rotatedExtruderLoops = [] stretch = 0.5 * layerExtrusionWidth loops = [] for thread in layer: loops.append( thread[ 1 : ] ) surroundingSlices = [] layerRemainder = layerIndex % int( round( self.fillPreferences.diaphragmPeriod.value ) ) if layerRemainder >= int( round( self.fillPreferences.diaphragmThickness.value ) ): for surroundingIndex in range( 1, self.solidSurfaceThickness + 1 ): self.addRotatedSlice( layerIndex - surroundingIndex, reverseRotationAroundZAngle, surroundingSlices ) self.addRotatedSlice( layerIndex + surroundingIndex, reverseRotationAroundZAngle, surroundingSlices ) extraShells = self.fillPreferences.extraShellsSparseLayer.value if len( surroundingSlices ) < self.doubleSolidSurfaceThickness: if self.lastExtraShells != self.fillPreferences.extraShellsBase.value: extraShells = self.fillPreferences.extraShellsBase.value self.lastExtraShells = extraShells surroundingLoops = euclidean.getSurroundingLoops( layerExtrusionWidth, loops ) for extraShellIndex in range( extraShells ): createFillForSurroundings( surroundingLoops ) fillLoops = euclidean.getFillOfSurroundings( surroundingLoops ) for loop in fillLoops: alreadyFilledLoop = [] alreadyFilledArounds.append( alreadyFilledLoop ) planeRotatedPerimeter = euclidean.getPathRoundZAxisByPlaneAngle( reverseRotationAroundZAngle, loop ) rotatedExtruderLoops.append( planeRotatedPerimeter ) circleNodes = intercircle.getCircleNodesFromLoop( planeRotatedPerimeter, slightlyGreaterThanFill ) centers = intercircle.getCentersFromCircleNodes( circleNodes ) for center in centers: alreadyFilledInset = intercircle.getInsetFromClockwiseLoop( center, layerFillInset ) # if euclidean.isWiddershins( alreadyFilledInset ) == euclidean.isWiddershins( center ): if euclidean.getMaximumSpan( alreadyFilledInset ) > muchGreaterThanLayerFillInset or euclidean.isWiddershins( alreadyFilledInset ): alreadyFilledLoop.append( alreadyFilledInset ) around = intercircle.getInsetFromClockwiseLoop( center, aroundInset ) if euclidean.isPathInsideLoop( planeRotatedPerimeter, around ) != euclidean.isWiddershins( planeRotatedPerimeter ): arounds.append( around ) for point in around: back = max( back, point.y ) front = min( front, point.y ) fillWidth = back - front numberOfIntervals = int( math.floor( fillWidth / layerExtrusionWidth ) ) fillRemainder = fillWidth - float( numberOfIntervals ) * layerExtrusionWidth halfFillRemainder = 0.5 * fillRemainder back -= halfFillRemainder front += halfFillRemainder horizontalSegments = [] for fillLine in range( numberOfIntervals + 1 ): y = front + float( fillLine ) * layerExtrusionWidth lineSegments = getHorizontalSegments( rotatedExtruderLoops, alreadyFilledArounds, y ) horizontalSegments.append( lineSegments ) removedEndpoints = [] for fillLine in range( len( horizontalSegments ) ): y = front + float( fillLine ) * layerExtrusionWidth horizontalEndpoints = horizontalSegments[ fillLine ] surroundingXIntersections = getSurroundingXIntersections( len( alreadyFilledArounds ), self.doubleSolidSurfaceThickness, surroundingSlices, y ) addSparseEndpoints( doubleExtrusionWidth, endpoints, self.fillDensity, fillLine, horizontalSegments, removedEndpoints, surroundingXIntersections ) if len( endpoints ) < 1: euclidean.addToThreadsRemoveFromSurroundings( self.oldOrderedLocation, surroundingLoops, self ) return stretchedXSegments = [] for beginningEndpoint in endpoints[ : : 2 ]: beginningPoint = beginningEndpoint.point stretchedXSegment = StretchedXSegment().getFromXYStretch( beginningPoint.x, beginningPoint.y, beginningEndpoint.otherEndpoint.point.x, stretch ) stretchedXSegments.append( stretchedXSegment ) endpointFirst = endpoints[ 0 ] endpoints.remove( endpointFirst ) otherEndpoint = endpointFirst.otherEndpoint endpoints.remove( otherEndpoint ) nextEndpoint = None path = [] paths = [] if len( endpoints ) > 1: nextEndpoint = otherEndpoint.getNearestMiss( arounds, endpoints, layerExtrusionWidth, path, stretchedXSegments ) if nextEndpoint != None: if nextEndpoint.point.distance2( endpointFirst.point ) < nextEndpoint.point.distance2( otherEndpoint.point ): endpointFirst = endpointFirst.otherEndpoint otherEndpoint = endpointFirst.otherEndpoint path.append( endpointFirst.point ) path.append( otherEndpoint.point ) while len( endpoints ) > 1: nextEndpoint = otherEndpoint.getNearestMiss( arounds, endpoints, layerExtrusionWidth, path, stretchedXSegments ) if nextEndpoint == None: paths.append( path ) path = [] nextEndpoint = otherEndpoint.getNearestEndpoint( endpoints ) path.append( nextEndpoint.point ) endpoints.remove( nextEndpoint ) if nextEndpoint.isOtherEndpointExtrudable( path ): otherEndpoint = nextEndpoint.otherEndpoint path.append( otherEndpoint.point ) endpoints.remove( otherEndpoint ) else: otherEndpoint = nextEndpoint paths.append( path ) for removedEndpoint in removedEndpoints: addAroundClosest( arounds, layerExtrusionWidth, paths, removedEndpoint ) for path in paths: addPath( layerFillInset, fill, path, layerRotationAroundZAngle ) euclidean.transferPathsToSurroundingLoops( fill, surroundingLoops ) euclidean.addToThreadsRemoveFromSurroundings( self.oldOrderedLocation, surroundingLoops, self )
def addFill(self, layerIndex): "Add fill to the slice layer." # if layerIndex > 5: # return alreadyFilledArounds = [] arounds = [] back = -999999999.0 layerExtrusionWidth = self.extrusionWidth layerFillInset = self.fillInset layer = self.rotatedLayers[layerIndex].toBeginningLoops self.addLine('(<layerStart> ' + str(layer[0][0].z) + ' )') # Indicate that a new layer is starting. if self.rotatedLayers[layerIndex].rotation != None: layerExtrusionWidth = self.extrusionWidth * self.bridgeExtrusionWidthOverSolid layerFillInset = self.fillInset * self.bridgeExtrusionWidthOverSolid self.addLine( '(<bridgeLayer> )') # Indicate that this is a bridge layer. doubleExtrusionWidth = 2.0 * layerExtrusionWidth muchGreaterThanLayerFillInset = 3.0 * layerFillInset endpoints = [] fill = [] aroundInset = 0.7 * layerFillInset front = -back slightlyGreaterThanFill = 1.01 * layerFillInset layerRotationAroundZAngle = self.getLayerRoundZ(layerIndex) reverseRotationAroundZAngle = complex(layerRotationAroundZAngle.real, -layerRotationAroundZAngle.imag) rotatedExtruderLoops = [] stretch = 0.5 * layerExtrusionWidth loops = [] for thread in layer: loops.append(thread[1:]) surroundingSlices = [] layerRemainder = layerIndex % int( round(self.fillPreferences.diaphragmPeriod.value)) if layerRemainder >= int( round(self.fillPreferences.diaphragmThickness.value)): for surroundingIndex in range(1, self.solidSurfaceThickness + 1): self.addRotatedSlice(layerIndex - surroundingIndex, reverseRotationAroundZAngle, surroundingSlices) self.addRotatedSlice(layerIndex + surroundingIndex, reverseRotationAroundZAngle, surroundingSlices) extraShells = self.fillPreferences.extraShellsSparseLayer.value if len(surroundingSlices) < self.doubleSolidSurfaceThickness: if self.lastExtraShells != self.fillPreferences.extraShellsBase.value: extraShells = self.fillPreferences.extraShellsBase.value self.lastExtraShells = extraShells surroundingLoops = euclidean.getSurroundingLoops( layerExtrusionWidth, loops) for extraShellIndex in range(extraShells): createFillForSurroundings(surroundingLoops) fillLoops = euclidean.getFillOfSurroundings(surroundingLoops) for loop in fillLoops: alreadyFilledLoop = [] alreadyFilledArounds.append(alreadyFilledLoop) planeRotatedPerimeter = euclidean.getPathRoundZAxisByPlaneAngle( reverseRotationAroundZAngle, loop) rotatedExtruderLoops.append(planeRotatedPerimeter) circleNodes = intercircle.getCircleNodesFromLoop( planeRotatedPerimeter, slightlyGreaterThanFill) centers = intercircle.getCentersFromCircleNodes(circleNodes) for center in centers: alreadyFilledInset = intercircle.getInsetFromClockwiseLoop( center, layerFillInset) # if euclidean.isWiddershins( alreadyFilledInset ) == euclidean.isWiddershins( center ): if euclidean.getMaximumSpan( alreadyFilledInset ) > muchGreaterThanLayerFillInset or euclidean.isWiddershins( alreadyFilledInset): alreadyFilledLoop.append(alreadyFilledInset) around = intercircle.getInsetFromClockwiseLoop( center, aroundInset) if euclidean.isPathInsideLoop( planeRotatedPerimeter, around ) != euclidean.isWiddershins(planeRotatedPerimeter): arounds.append(around) for point in around: back = max(back, point.y) front = min(front, point.y) fillWidth = back - front numberOfIntervals = int(math.floor(fillWidth / layerExtrusionWidth)) fillRemainder = fillWidth - float( numberOfIntervals) * layerExtrusionWidth halfFillRemainder = 0.5 * fillRemainder back -= halfFillRemainder front += halfFillRemainder horizontalSegments = [] for fillLine in range(numberOfIntervals + 1): y = front + float(fillLine) * layerExtrusionWidth lineSegments = getHorizontalSegments(rotatedExtruderLoops, alreadyFilledArounds, y) horizontalSegments.append(lineSegments) removedEndpoints = [] for fillLine in range(len(horizontalSegments)): y = front + float(fillLine) * layerExtrusionWidth horizontalEndpoints = horizontalSegments[fillLine] surroundingXIntersections = getSurroundingXIntersections( len(alreadyFilledArounds), self.doubleSolidSurfaceThickness, surroundingSlices, y) addSparseEndpoints(doubleExtrusionWidth, endpoints, self.fillDensity, fillLine, horizontalSegments, removedEndpoints, surroundingXIntersections) if len(endpoints) < 1: euclidean.addToThreadsRemoveFromSurroundings( self.oldOrderedLocation, surroundingLoops, self) return stretchedXSegments = [] for beginningEndpoint in endpoints[::2]: beginningPoint = beginningEndpoint.point stretchedXSegment = StretchedXSegment().getFromXYStretch( beginningPoint.x, beginningPoint.y, beginningEndpoint.otherEndpoint.point.x, stretch) stretchedXSegments.append(stretchedXSegment) endpointFirst = endpoints[0] endpoints.remove(endpointFirst) otherEndpoint = endpointFirst.otherEndpoint endpoints.remove(otherEndpoint) nextEndpoint = None path = [] paths = [] if len(endpoints) > 1: nextEndpoint = otherEndpoint.getNearestMiss( arounds, endpoints, layerExtrusionWidth, path, stretchedXSegments) if nextEndpoint != None: if nextEndpoint.point.distance2( endpointFirst.point) < nextEndpoint.point.distance2( otherEndpoint.point): endpointFirst = endpointFirst.otherEndpoint otherEndpoint = endpointFirst.otherEndpoint path.append(endpointFirst.point) path.append(otherEndpoint.point) while len(endpoints) > 1: nextEndpoint = otherEndpoint.getNearestMiss( arounds, endpoints, layerExtrusionWidth, path, stretchedXSegments) if nextEndpoint == None: paths.append(path) path = [] nextEndpoint = otherEndpoint.getNearestEndpoint(endpoints) path.append(nextEndpoint.point) endpoints.remove(nextEndpoint) if nextEndpoint.isOtherEndpointExtrudable(path): otherEndpoint = nextEndpoint.otherEndpoint path.append(otherEndpoint.point) endpoints.remove(otherEndpoint) else: otherEndpoint = nextEndpoint paths.append(path) for removedEndpoint in removedEndpoints: addAroundClosest(arounds, layerExtrusionWidth, paths, removedEndpoint) for path in paths: addPath(layerFillInset, fill, path, layerRotationAroundZAngle) euclidean.transferPathsToSurroundingLoops(fill, surroundingLoops) euclidean.addToThreadsRemoveFromSurroundings(self.oldOrderedLocation, surroundingLoops, self)
def addEntireLayer( self, layerIndex ): "Add entire thread layer." surroundingLoops = self.islandLayers[ layerIndex ] for line in self.threadLayers[ layerIndex ].beforeExtrusionLines: self.addLine( line ) euclidean.addToThreadsRemoveFromSurroundings( self.oldOrderedLocation, surroundingLoops, self )