summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradrian-bowyer <adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223>2010-01-22 20:26:40 +0000
committeradrian-bowyer <adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223>2010-01-22 20:26:40 +0000
commit630319c16311746db981d8588e30acb25d2dc6f7 (patch)
tree408872ddb78ecb00ab9ed027f20a24d5e4af707c
parentbda3e531420a92508ec3d2741b95eee0811e2e74 (diff)
downloadreprap-backup-630319c16311746db981d8588e30acb25d2dc6f7.tar.gz
reprap-backup-630319c16311746db981d8588e30acb25d2dc6f7.zip
Making AllSTLSToBuild the master class for slicing.
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@3447 cb376a5e-1013-0410-a455-b6b1f9ac8223
-rw-r--r--trunk/users/adrian/host/src/org/reprap/geometry/Producer.java17
-rw-r--r--trunk/users/adrian/host/src/org/reprap/gui/AllSTLsToBuild.java128
2 files changed, 90 insertions, 55 deletions
diff --git a/trunk/users/adrian/host/src/org/reprap/geometry/Producer.java b/trunk/users/adrian/host/src/org/reprap/geometry/Producer.java
index 7d7155aa..cd426006 100644
--- a/trunk/users/adrian/host/src/org/reprap/geometry/Producer.java
+++ b/trunk/users/adrian/host/src/org/reprap/geometry/Producer.java
@@ -316,7 +316,7 @@ public class Producer {
layerRules.setLayingSupport(false);
- BooleanGridList slice, previousSlice;
+ //BooleanGridList slice, previousSlice;
int lastExtruder = -1;
int totalPhysicalExtruders = 0;
@@ -361,15 +361,11 @@ public class Producer {
allPolygons[physicalExtruder] = new RrPolygonList();
boolean shield = true;
- for(int i = 0; i < allSTLs.size(); i++)
+ for(int stl = 0; stl < allSTLs.size(); stl++)
{
- previousSlice = allSTLs.previousSlice(i);
- slice = allSTLs.slice(i, layerRules);
-
- if(slice.size() > 0)
- {
- RrPolygonList fills = allSTLs.computeInfill(slice, layerRules, previousSlice);
- RrPolygonList borders = allSTLs.computeOutlines(slice, layerRules, fills, shield);
+
+ RrPolygonList fills = allSTLs.computeInfill(stl, layerRules);
+ RrPolygonList borders = allSTLs.computeOutlines(stl, layerRules, fills, shield);
shield = false;
for(int pol = 0; pol < borders.size(); pol++)
{
@@ -381,7 +377,6 @@ public class Producer {
RrPolygon p = fills.polygon(pol);
allPolygons[p.getAttributes().getExtruder().getPhysicalExtruderNumber()].add(p);
}
- }
}
LayerProducer lp = new LayerProducer(allPolygons, layerRules, simulationPlot);
@@ -390,7 +385,7 @@ public class Producer {
reprap.finishedLayer(layerRules);
reprap.betweenLayers(layerRules);
//layer = null;
- slice = null;
+ //slice = null;
//slice.finalize();
allSTLs.destroyLayer();
diff --git a/trunk/users/adrian/host/src/org/reprap/gui/AllSTLsToBuild.java b/trunk/users/adrian/host/src/org/reprap/gui/AllSTLsToBuild.java
index 9def5bb6..3d9ab74b 100644
--- a/trunk/users/adrian/host/src/org/reprap/gui/AllSTLsToBuild.java
+++ b/trunk/users/adrian/host/src/org/reprap/gui/AllSTLsToBuild.java
@@ -73,6 +73,58 @@ public class AllSTLsToBuild
}
/**
+ * Ring buffer to hold previously computed slices for doing
+ * infill and support material calculations.
+ * @author ensab
+ *
+ */
+ class SliceRecords
+ {
+ private BooleanGridList[][] sliceRing;
+ private int[] layerNumber;
+ private int ringPointer;
+ private final int noLayer = Integer.MIN_VALUE;
+ private final int ringSize = 5;
+
+ public SliceRecords()
+ {
+ sliceRing = new BooleanGridList[ringSize][stls.size()];
+ layerNumber = new int[ringSize];
+ ringPointer = 0;
+ for(int layer = 0; layer < ringSize; layer++)
+ for(int stl = 0; stl < stls.size(); stl++)
+ {
+ sliceRing[layer][stl] = null;
+ layerNumber[layer] = noLayer;
+ }
+ }
+
+ public void set(BooleanGridList slice, int layer, int stl)
+ {
+ layerNumber[ringPointer] = layer;
+ sliceRing[ringPointer][stl] = slice;
+ ringPointer++;
+ if(ringPointer >= ringSize)
+ ringPointer = 0;
+ }
+
+ public BooleanGridList get(int layer, int stl)
+ {
+ int l = ringPointer;
+ for(int i = 0; i < ringSize; i++)
+ {
+ l--;
+ if(l < 0)
+ l = ringSize - 1;
+ if(layerNumber[l] == layer)
+ return sliceRing[l][stl];
+ }
+ Debug.d("SliceRecords.get(): layer not found.");
+ return null;
+ }
+ }
+
+ /**
* The list of things to be built
*/
private List<STLObject> stls;
@@ -88,15 +140,12 @@ public class AllSTLsToBuild
private RrInterval Zrange;
/**
- * The last slices calculated
- */
- private BooleanGridList[] previousSlices;
-
- /**
* Is the list editable?
*/
private boolean frozen;
+ private SliceRecords sliceRecords;
+
/**
* Simple constructor
*
@@ -107,7 +156,7 @@ public class AllSTLsToBuild
XYbox = null;
Zrange = null;
frozen = false;
- previousSlices = null;
+ sliceRecords = null;
}
/**
@@ -158,6 +207,8 @@ public class AllSTLsToBuild
private void freeze()
{
frozen = true;
+ if(sliceRecords == null)
+ sliceRecords = new SliceRecords();
}
/**
@@ -393,23 +444,30 @@ public class AllSTLsToBuild
* @param layerConditions
* @return
*/
- public RrPolygonList computeInfill(BooleanGridList outsides, LayerRules layerConditions, BooleanGridList previousSlice)
+ public RrPolygonList computeInfill(int stl, LayerRules layerConditions)
{
- //BooleanGridList outsides = this;
+ int layer = layerConditions.getMachineLayer();
+ BooleanGridList shapes = sliceRecords.get(layer, stl);
+ if(shapes == null)
+ {
+ shapes = slice(stl, layerConditions);
+ sliceRecords.set(shapes, layer, stl);
+ }
+ BooleanGridList previousSlice = sliceRecords.get(layer+1, stl);
BooleanGridList insides = null;
if(previousSlice != null && layerConditions.getModelLayer() > 1)
{
- insides = BooleanGridList.intersections(outsides, previousSlice);
- outsides = BooleanGridList.differences(outsides, previousSlice);
+ insides = BooleanGridList.intersections(shapes, previousSlice);
+ shapes = BooleanGridList.differences(shapes, previousSlice);
}
- outsides = outsides.offset(layerConditions, false);
+ shapes = shapes.offset(layerConditions, false);
if(insides != null)
insides = insides.offset(layerConditions, false);
- RrPolygonList hatchedPolygons = outsides.hatch(layerConditions, true);
+ RrPolygonList hatchedPolygons = shapes.hatch(layerConditions, true);
// if(layerConditions.getLayingSupport())
// offHatch = offHatch.union(layerConditions.getPrinter().getExtruders());
@@ -427,9 +485,17 @@ public class AllSTLsToBuild
* @param shield
* @return
*/
- public RrPolygonList computeOutlines(BooleanGridList shapes, LayerRules layerConditions, RrPolygonList hatchedPolygons, boolean shield)
+ public RrPolygonList computeOutlines(int stl, LayerRules layerConditions, RrPolygonList hatchedPolygons, boolean shield)
{
+ int layer = layerConditions.getMachineLayer();
+ BooleanGridList shapes = sliceRecords.get(layer, stl);
+ if(shapes == null)
+ {
+ shapes = slice(stl, layerConditions);
+ sliceRecords.set(shapes, layer, stl);
+ }
+
RrPolygonList borderPolygons;
if(layerConditions.getLayingSupport())
@@ -475,7 +541,7 @@ public class AllSTLsToBuild
* @param extruders
* @return
*/
- public BooleanGridList slice(int i, LayerRules layerRules)
+ private BooleanGridList slice(int stl, LayerRules layerRules)
{
freeze();
double z = layerRules.getModelZ() + layerRules.getZStep()*0.5;
@@ -496,19 +562,14 @@ public class AllSTLsToBuild
edges[extruderID] = new ArrayList<LineSegment>();
}
- if(previousSlices == null)
- {
- previousSlices = new BooleanGridList[stls.size()];
- for(int stl = 0; stl < stls.size(); stl++)
- previousSlices[stl] = null;
- }
+
// Generate all the edges for STLObject i at this z
- STLObject stl = stls.get(i);
- Transform3D trans = stl.getTransform();
+ STLObject stlObject = stls.get(stl);
+ Transform3D trans = stlObject.getTransform();
- BranchGroup bg = stl.getSTL();
+ BranchGroup bg = stlObject.getSTL();
java.util.Enumeration<?> enumKids = bg.getAllChildren();
while(enumKids.hasMoreElements())
@@ -546,29 +607,8 @@ public class AllSTLsToBuild
}
}
-// // No excuse for the garbage collector
-// for(extruderID = 0; extruderID < edges.length; extruderID++)
-// edges[extruderID] = null;
-// edges = null;
-
- // Remember for next time
-
- previousSlices[i] = rl;
-
return rl;
}
-
- /**
- * Get the slice computed last time for STLObject i.
- * @param i
- * @return
- */
- public BooleanGridList previousSlice(int i)
- {
- if(previousSlices == null)
- return null;
- return previousSlices[i];
- }
public void destroyLayer() {}