Skip to content

Commit

Permalink
Cleaned up Area code. Added shell generation and simple bridge-detect…
Browse files Browse the repository at this point in the history
…ing code.
  • Loading branch information
clothbot committed Sep 11, 2010
1 parent d5286f4 commit d88ff72
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 15 deletions.
76 changes: 75 additions & 1 deletion Area.pde
Expand Up @@ -11,7 +11,7 @@ class SSArea extends Area {
HeadSpeed=1000;
FlowRate=0;
}

void setGridScale(float aGridScale) {
GridScale=aGridScale;
}
Expand All @@ -33,4 +33,78 @@ class SSArea extends Area {
return(FlowRate);
}

void Slice2Area(Slice thisSlice) {
SSPoly path2polys = new SSPoly();
path2polys.setGridScale(GridScale);
ArrayList PolyList = path2polys.Path2Polys(thisSlice.SlicePath);
for(int i=0;i<PolyList.size();i++) {
SSPoly thisPoly=(SSPoly) PolyList.get(i);
this.exclusiveOr(new Area((Polygon) thisPoly));
}
AffineTransform scaleAreaTransform = new AffineTransform();
scaleAreaTransform.setToScale(GridScale,GridScale);
this.transform(scaleAreaTransform);
}

void makeShell(float shellWidth) {
float sqt2=sqrt(2);
AffineTransform shiftTrans = new AffineTransform();

shiftTrans.setToTranslation(shellWidth,0); Area copyXP = this.createTransformedArea(shiftTrans);
copyXP.subtract(this);
shiftTrans.setToTranslation(-shellWidth,0); copyXP.transform(shiftTrans);
if(copyXP.isEmpty()) println(" makeShell: copyXP is Empty");

shiftTrans.setToTranslation(-shellWidth,0); Area copyXM = this.createTransformedArea(shiftTrans);
copyXM.subtract(this);
shiftTrans.setToTranslation(shellWidth,0); copyXM.transform(shiftTrans);
if(copyXM.isEmpty()) println(" makeShell: copyXM is Empty");

shiftTrans.setToTranslation(0,shellWidth); Area copyYP = this.createTransformedArea(shiftTrans);
copyYP.subtract(this);
shiftTrans.setToTranslation(0,-shellWidth); copyYP.transform(shiftTrans);
if(copyYP.isEmpty()) println(" makeShell: copyYP is Empty");

shiftTrans.setToTranslation(0,-shellWidth); Area copyYM = this.createTransformedArea(shiftTrans);
copyYM.subtract(this);
shiftTrans.setToTranslation(0,shellWidth); copyYM.transform(shiftTrans);
if(copyYM.isEmpty()) println(" makeShell: copyYM is Empty");

// Diagonals
shiftTrans.setToTranslation(shellWidth/sqt2,shellWidth/sqt2); Area copyXPYP = this.createTransformedArea(shiftTrans);
copyXPYP.subtract(this);
shiftTrans.setToTranslation(-shellWidth/sqt2,-shellWidth/sqt2); copyXPYP.transform(shiftTrans);
if(copyXPYP.isEmpty()) println(" makeShell: copyXPYP is Empty");

shiftTrans.setToTranslation(-shellWidth/sqt2,shellWidth/sqt2); Area copyXMYP = this.createTransformedArea(shiftTrans);
copyXMYP.subtract(this);
shiftTrans.setToTranslation(shellWidth/sqt2,-shellWidth/sqt2); copyXMYP.transform(shiftTrans);
if(copyXM.isEmpty()) println(" makeShell: copyXMYP is Empty");

shiftTrans.setToTranslation(shellWidth/sqt2,-shellWidth/sqt2); Area copyXPYM = this.createTransformedArea(shiftTrans);
copyXPYM.subtract(this);
shiftTrans.setToTranslation(-shellWidth/sqt2,shellWidth/sqt2); copyXPYM.transform(shiftTrans);
if(copyXPYM.isEmpty()) println(" makeShell: copyXPYM is Empty");

shiftTrans.setToTranslation(-shellWidth/sqt2,-shellWidth/sqt2); Area copyXMYM = this.createTransformedArea(shiftTrans);
copyXMYM.subtract(this);
shiftTrans.setToTranslation(shellWidth/sqt2,shellWidth/sqt2); copyXMYM.transform(shiftTrans);
if(copyYM.isEmpty()) println(" makeShell: copyXMYM is Empty");


Area innerArea=new Area(this);
innerArea.subtract(copyXP);
innerArea.subtract(copyXM);
innerArea.subtract(copyYP);
innerArea.subtract(copyYM);
innerArea.subtract(copyXPYP);
innerArea.subtract(copyXMYP);
innerArea.subtract(copyXPYM);
innerArea.subtract(copyXMYM);
if(innerArea.isEmpty()) {
println(" makeShell: innerArea is Empty");
} else {
this.subtract(innerArea);
}
}
}
34 changes: 20 additions & 14 deletions SuperSkein.pde
Expand Up @@ -442,6 +442,7 @@ class DXFWriteProc implements Runnable{
int sliceCount=0;
DXFSliceFileName = DXFSliceFilePrefix + "_" + LayerThickness + ".dxf";
print("DXF Slice File Name: " + DXFSliceFileName + "\n");
ArrayList SliceAreaList = new ArrayList();
pgDxf=(RawDXF) createGraphics(round(BuildPlatformWidth),round(BuildPlatformHeight),DXF,DXFSliceFileName);
beginRaw(pgDxf);
for(float ZLevel = 0;ZLevel<(STLFile.bz2-LayerThickness);ZLevel=ZLevel+LayerThickness)
Expand All @@ -450,23 +451,28 @@ class DXFWriteProc implements Runnable{
pgDxf.setLayer(DXFSliceNum);
DXFWriteFraction = (ZLevel/(STLFile.bz2-LayerThickness));
ThisSlice = new Slice(STLFile,ZLevel);
// PathIterator pathIter=ThisSlice.SlicePath.getPathIterator(new AffineTransform());
// lin = (SSLine) ThisSlice.Lines.get(0);
// Area thisArea = new Area(ThisSlice.SlicePath);
SSPoly path2polys = new SSPoly();
path2polys.setGridScale(0.01);
path2polys.setDebugFlag(debugFlag);
ArrayList PolyList = path2polys.Path2Polys(ThisSlice.SlicePath);
SSArea thisArea = new SSArea();
thisArea.setGridScale(path2polys.getGridScale());
for(int i=0;i<PolyList.size();i++) {
SSPoly thisPoly=(SSPoly) PolyList.get(i);
thisArea.exclusiveOr(new Area((Polygon) thisPoly));
thisArea.setGridScale(0.01);
thisArea.Slice2Area(ThisSlice);
SliceAreaList.add(thisArea);
if(ZLevel>0 && ZLevel <(STLFile.bz2-2*LayerThickness)) {
SSArea thisShell = new SSArea();
thisShell.setGridScale(thisArea.getGridScale());
thisShell.add(thisArea);
thisShell.makeShell(0.5);
SSArea bridgeCheck = new SSArea();
bridgeCheck.setGridScale(thisArea.getGridScale());
bridgeCheck.add(thisArea);
bridgeCheck.subtract( (SSArea) SliceAreaList.get(DXFSliceNum-1));
if( !bridgeCheck.isEmpty() ) {
println(" Bridges found in "+DXFSliceNum);
bridgeCheck.makeShell(0.25);
bridgeCheck.intersect(thisArea);
thisShell.add(bridgeCheck);
}
thisArea=thisShell;
}
AffineTransform scaleAreaTransform = new AffineTransform();
scaleAreaTransform.setToScale(thisArea.GridScale,thisArea.GridScale);
if(debugFlag) println("\n GridScale: "+thisArea.GridScale);
thisArea.transform(scaleAreaTransform);
PathIterator pathIter=thisArea.getPathIterator(new AffineTransform());
float[] newCoords={0.0,0.0,0.0,0.0,0.0,0.0};
float[] prevCoords={0.0,0.0,0.0,0.0,0.0,0.0};
Expand Down

0 comments on commit d88ff72

Please sign in to comment.