Permalink
Browse files

Figured out the Java Area operations. Needs lots of re-work, but the …

…DXF export uses it and appears to work.
  • Loading branch information...
1 parent aa2db19 commit d5286f4ea7c56ae1159d18f8c8d7a98db5a2c27d @clothbot clothbot committed Sep 11, 2010
Showing with 175 additions and 10 deletions.
  1. +36 −0 Area.pde
  2. +4 −4 Path.pde
  3. +107 −0 Poly.pde
  4. +1 −0 Slice.pde
  5. +27 −6 SuperSkein.pde
View
@@ -0,0 +1,36 @@
+// SSArea class
+import java.awt.geom.Area;
+
+class SSArea extends Area {
+ float GridScale;
+ float HeadSpeed;
+ float FlowRate;
+
+ void SSArea() {
+ GridScale=0.01;
+ HeadSpeed=1000;
+ FlowRate=0;
+ }
+
+ void setGridScale(float aGridScale) {
+ GridScale=aGridScale;
+ }
+ float getGridScale() {
+ return(GridScale);
+ }
+
+ void setHeadSpeed(float aHeadSpeed) {
+ HeadSpeed=aHeadSpeed;
+ }
+ float getHeadSpeed() {
+ return(HeadSpeed);
+ }
+
+ void setFlowRate(float aFlowRate) {
+ FlowRate=aFlowRate;
+ }
+ float getFlowRate() {
+ return(FlowRate);
+ }
+
+}
View
@@ -34,10 +34,10 @@ class SSPath extends Path2D.Float {
// Closes the path if it is not already closed.
// A closed path is one that ends where it started.
- void close()
- {
- super.closePath();
- }
+// void close()
+// {
+// super.closePath();
+// }
// If the point is inside the closed path, returns true. False otherwise.
View
107 Poly.pde
@@ -0,0 +1,107 @@
+// SSPoly extends Polygon
+
+import java.awt.Polygon;
+
+class SSPoly extends Polygon {
+ float GridScale;
+ float HeadSpeed;
+ float Flowrate;
+ boolean debugFlag;
+
+ SSPoly() {
+ GridScale=0.01;
+ HeadSpeed=1000;
+ Flowrate=0;
+ debugFlag=false;
+ }
+
+ void setGridScale(float aFloat) {
+ GridScale=aFloat;
+ }
+ float getGridScale() {
+ return(GridScale);
+ }
+
+ void setHeadSpeed(float aFloat) {
+ HeadSpeed=aFloat;
+ }
+ float getHeadSpeed() {
+ return(HeadSpeed);
+ }
+
+ void setFlowrate(float aFloat) {
+ Flowrate=aFloat;
+ }
+ float getFlowrate() {
+ return(Flowrate);
+ }
+
+ void setDebugFlag(boolean aBool) {
+ debugFlag=aBool;
+ }
+ boolean getDebugFlag() {
+ return(debugFlag);
+ }
+
+ void addPoint(float fx, float fy) {
+ float scalefx=round(fx/GridScale);
+ float scalefy=round(fy/GridScale);
+ addPoint((int)scalefx,(int)scalefy);
+ }
+
+ boolean contains(float fx, float fy) {
+ float scalefx=round(fx/GridScale);
+ float scalefy=round(fy/GridScale);
+ boolean bContains = contains((int)scalefx,(int)scalefy);
+ return(bContains);
+ }
+
+ void translate(float fx, float fy) {
+ float scalefx=round(fx/GridScale);
+ float scalefy=round(fy/GridScale);
+ translate((int)scalefx,(int)scalefy);
+ }
+
+ ArrayList Path2Polys(SSPath thisPath) {
+ ArrayList returnList=new ArrayList();
+ SSPoly thisPoly=new SSPoly();
+ thisPoly.setDebugFlag(debugFlag);
+ thisPoly.setGridScale(GridScale);
+ returnList.add(thisPoly);
+ PathIterator pathIter=thisPath.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};
+ float[] startCoords={0.0,0.0,0.0,0.0,0.0,0.0};
+ int segType=pathIter.currentSegment(prevCoords);
+ segType=pathIter.currentSegment(startCoords);
+ pathIter.next();
+ while(!pathIter.isDone()) {
+ segType=pathIter.currentSegment(newCoords);
+ if(segType == PathIterator.SEG_LINETO ) {
+ if(debugFlag) print(".");
+ thisPoly.addPoint(prevCoords[0],prevCoords[1]);
+ segType=pathIter.currentSegment(prevCoords);
+ } else if( segType==PathIterator.SEG_CLOSE) {
+ if(debugFlag) println("\n Polygon: "+returnList.size()+" SEG_CLOSE: "+newCoords[0]+" "+newCoords[1]);
+ thisPoly.addPoint(prevCoords[0],prevCoords[1]);
+ segType=pathIter.currentSegment(prevCoords);
+ } else if(segType == PathIterator.SEG_MOVETO) {
+ if(debugFlag) println("\n Polygon: "+returnList.size()+" SEG_MOVETO: "+newCoords[0]+" "+newCoords[1]);
+ thisPoly=new SSPoly();
+ thisPoly.setDebugFlag(debugFlag);
+ thisPoly.setGridScale(GridScale);
+ returnList.add(thisPoly);
+ segType=pathIter.currentSegment(prevCoords);
+ segType=pathIter.currentSegment(startCoords);
+ } else {
+ println(" Polygon: "+returnList.size()+" segType: "+segType+"\n");
+ segType=pathIter.currentSegment(prevCoords);
+ }
+ pathIter.next();
+ }
+ if(debugFlag) println(" SSPoly Count: "+returnList.size()+"\n");
+ return(returnList);
+ }
+
+
+}
View
@@ -114,6 +114,7 @@ class Slice {
SlicePath.append(newLine,connectFlag);
prevPt = new PVector(newLine.x2,newLine.y2);
}
+ SlicePath.closePath();
}
}
View
@@ -5,6 +5,7 @@
//STL just breaks it for now.
import processing.dxf.*;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Area;
import java.awt.geom.PathIterator;
//The config file takes precedence over these parameters!
@@ -449,11 +450,29 @@ 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);
- PathIterator pathIter=ThisSlice.SlicePath.getPathIterator(new AffineTransform());
+ // 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));
+ }
+ 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};
- int segType=pathIter.currentSegment(prevCoords);
+ float[] startCoords={0.0,0.0,0.0,0.0,0.0,0.0};
+ int segType=pathIter.currentSegment(prevCoords);
+ segType=pathIter.currentSegment(startCoords);
pathIter.next();
while(!pathIter.isDone()) {
segType=pathIter.currentSegment(newCoords);
@@ -463,14 +482,16 @@ class DXFWriteProc implements Runnable{
pgDxf.line(prevCoords[0],prevCoords[1],newCoords[0],newCoords[1]);
segType=pathIter.currentSegment(prevCoords);
} else if( segType==PathIterator.SEG_CLOSE) {
- if(debugFlag) println(" Slice: "+DXFSliceNum+" SEG_CLOSE: "+newCoords[0]+" "+newCoords[1]+"\n");
- pgDxf.line(prevCoords[0],prevCoords[1],newCoords[0],newCoords[1]);
+ if(debugFlag) println("\n Slice: "+DXFSliceNum+" SEG_CLOSE: "+newCoords[0]+" "+newCoords[1]);
+ // pgDxf.line(prevCoords[0],prevCoords[1],newCoords[0],newCoords[1]);
+ pgDxf.line(newCoords[0],newCoords[1],startCoords[0],startCoords[1]);
segType=pathIter.currentSegment(prevCoords);
} else if(segType == PathIterator.SEG_MOVETO) {
- if(debugFlag) println(" Slice: "+DXFSliceNum+" SEG_MOVETO: "+newCoords[0]+" "+newCoords[1]+"\n");
+ if(debugFlag) println("\n Slice: "+DXFSliceNum+" SEG_MOVETO: "+newCoords[0]+" "+newCoords[1]);
segType=pathIter.currentSegment(prevCoords);
+ segType=pathIter.currentSegment(startCoords);
} else {
- println(" Slice: "+DXFSliceNum+" segType: "+segType+"\n");
+ println("\n Slice: "+DXFSliceNum+" segType: "+segType);
segType=pathIter.currentSegment(prevCoords);
}
pathIter.next();

0 comments on commit d5286f4

Please sign in to comment.