Improving support generation in dual extrusion scenarios

issue: MatterHackers/MCCentral#5275
Dual extruder support fail
This commit is contained in:
LarsBrubaker 2019-04-10 17:01:21 -07:00
parent 488c369164
commit 2be74c87a0
3 changed files with 69 additions and 67 deletions

View file

@ -354,11 +354,9 @@ namespace MatterHackers.MatterControl.DesignTools
if (!nextPlaneIsBottom // if the next plane is a top, we don't have any space from the bed to the part to put support if (!nextPlaneIsBottom // if the next plane is a top, we don't have any space from the bed to the part to put support
|| planes[1].z > minimumSupportHeight) // if the next plane is a bottom and is not far enough away, there is no space to put any support || planes[1].z > minimumSupportHeight) // if the next plane is a bottom and is not far enough away, there is no space to put any support
{ {
var firstBottomAboveBed = GetNextBottom(0, planes); var firstBottomAboveBed = GetNextBottom(0, planes, minimumSupportHeight);
var firstTopAboveBed = GetNextTop(0, planes);
if (firstBottomAboveBed >= 0 if (firstBottomAboveBed >= 0)
&& firstBottomAboveBed < firstTopAboveBed)
{ {
AddSupportColumn(supportColumnsToAdd, xPos, yPos, 0, planes[firstBottomAboveBed].z + .01); AddSupportColumn(supportColumnsToAdd, xPos, yPos, 0, planes[firstBottomAboveBed].z + .01);
} }
@ -368,21 +366,26 @@ namespace MatterHackers.MatterControl.DesignTools
{ {
int i = 0; int i = 0;
double lastTopZ = 0; double lastTopZ = 0;
int lastBottom = i; int lastBottom = -1;
var nextPlaneIsBottom = planes.Count > 1 && planes[1].bottom; var nextPlaneIsBottom = planes.Count > 1 && planes[1].bottom;
// if the next plane (the one above the bed) is a bottom, we have a part on the bed and will not generate support // if the next plane (the one above the bed) is a bottom, we have a part on the bed and will not generate support
if (nextPlaneIsBottom && planes[1].z <= minimumSupportHeight) if (nextPlaneIsBottom && planes[1].z <= minimumSupportHeight)
{ {
// go up to the next top // go up to the next top
i = GetNextTop(i, planes); i = GetNextTop(i, planes, minimumSupportHeight);
lastTopZ = planes[i].z; if (i >= 0)
{
lastTopZ = planes[i].z;
}
} }
do while (i != -1
&& i != lastBottom
&& i < planes.Count)
{ {
lastBottom = i; lastBottom = i;
// find all open areas in the list and add support // find all open areas in the list and add support
i = GetNextBottom(i, planes); i = GetNextBottom(i, planes, minimumSupportHeight);
if (i >= 0) if (i >= 0)
{ {
if (i < planes.Count if (i < planes.Count
@ -390,15 +393,14 @@ namespace MatterHackers.MatterControl.DesignTools
{ {
AddSupportColumn(supportColumnsToAdd, xPos, yPos, lastTopZ, planes[i].z); AddSupportColumn(supportColumnsToAdd, xPos, yPos, lastTopZ, planes[i].z);
} }
i = GetNextTop(i + 1, planes); i = GetNextTop(i + 1, planes, minimumSupportHeight);
if (i < planes.Count) if (i >= 0
&& i < planes.Count)
{ {
lastTopZ = planes[i].z; lastTopZ = planes[i].z;
} }
} }
} while (i != -1 }
&& i != lastBottom
&& i < planes.Count);
} }
} }
@ -472,71 +474,70 @@ namespace MatterHackers.MatterControl.DesignTools
return detectedPlanes; return detectedPlanes;
} }
public static int GetNextBottom(int i, List<(double z, bool bottom)> planes) public static int GetNextBottom(int i, List<(double z, bool bottom)> planes, double skipDist)
{ {
// if we are starting this search from a top while (i < planes.Count)
if(i < planes.Count // valid i
&& !planes[i].bottom // starting on a top
&& planes.Count > i + 1 // valid next layer
&& planes[i + 1].bottom // next layer is a bottom
&& planes[i + 1].z <= planes[i].z) // next layer is <= or current top z
{ {
// skip all the bottoms that are the same as our current top // if we are on a bottom
while (i < planes.Count if (planes[i].bottom)
&& planes.Count > i + 1
&& planes[i + 1].bottom)
{ {
// move up to the next plane and re-evaluate
i++; i++;
} }
} else // we are on a top
bool foundBottom = false;
// all the tops
while (i < planes.Count
&& !planes[i].bottom)
{
i++;
if(i <planes.Count
&& planes[i].bottom)
{ {
foundBottom = true; // if the next plane is a bottom and more than skipDistanc away
if (i + 1 < planes.Count
&& planes[i + 1].bottom
&& planes[i + 1].z > planes[i].z + skipDist)
{
// this is the next bottom we are looking for
return i + 1;
}
else // move up to the next plane and re-evaluate
{
i++;
}
} }
} }
// then look for the last bottom before next top
while (i < planes.Count
&& planes[i].bottom
&& planes.Count > i + 1
&& planes[i + 1].bottom)
{
i++;
foundBottom = true;
}
if (foundBottom)
{
return i;
}
return -1; return -1;
} }
public static int GetNextTop(int i, List<(double z, bool bottom)> planes) public static int GetNextTop(int i, List<(double z, bool bottom)> planes, double skipDist)
{ {
if(i < planes.Count if (!planes[i].bottom)
&& !planes[i].bottom)
{ {
// skip the one we are
i++; i++;
} }
while (i < planes.Count while (i < planes.Count)
&& planes[i].bottom)
{ {
i++; // if we are on a bottom
if (planes[i].bottom)
{
// move up to the next plane and re-evaluate
i++;
}
else // we are on a top
{
// if the next plane is a bottom and more than skipDistanc away
if (i + 1 < planes.Count
&& planes[i + 1].bottom
&& planes[i + 1].z > planes[i].z + skipDist)
{
// this is the next top we are looking for
return i;
}
else // move up to the next plane and re-evaluate
{
i++;
}
}
} }
return i; return -1;
} }
// function to get all the columns that need support generation // function to get all the columns that need support generation

@ -1 +1 @@
Subproject commit 14f4fb447f973f2f52fd787e014757ca6d06820e Subproject commit afd799f6d27bf549934f764bd307dd5c2b2192d7

View file

@ -482,10 +482,10 @@ namespace MatterControl.Tests.MatterControl
(10, false), // top at 10 (the top of the box) (10, false), // top at 10 (the top of the box)
}; };
int bottom = SupportGenerator.GetNextBottom(0, planes); int bottom = SupportGenerator.GetNextBottom(0, planes, 0);
Assert.AreEqual(1, bottom); // we get the bottom Assert.AreEqual(1, bottom); // we get the bottom
int bottom1 = SupportGenerator.GetNextBottom(1, planes); int bottom1 = SupportGenerator.GetNextBottom(1, planes, 0);
Assert.AreEqual(-1, bottom1, "There are no more bottoms so we get back a -1."); Assert.AreEqual(-1, bottom1, "There are no more bottoms so we get back a -1.");
} }
@ -500,7 +500,7 @@ namespace MatterControl.Tests.MatterControl
(20, false) // top at 20 (box b top) (20, false) // top at 20 (box b top)
}; };
int bottom = SupportGenerator.GetNextBottom(0, planes); int bottom = SupportGenerator.GetNextBottom(0, planes, 0);
Assert.AreEqual(-1, bottom, "The boxes are sitting on the bed and no support is required"); Assert.AreEqual(-1, bottom, "The boxes are sitting on the bed and no support is required");
} }
@ -515,7 +515,7 @@ namespace MatterControl.Tests.MatterControl
(20, false) // top at 20 (box b top) (20, false) // top at 20 (box b top)
}; };
int bottom = SupportGenerator.GetNextBottom(0, planes); int bottom = SupportGenerator.GetNextBottom(0, planes, 0);
Assert.AreEqual(-1, bottom, "The boxes are sitting on the bed and no support is required"); Assert.AreEqual(-1, bottom, "The boxes are sitting on the bed and no support is required");
} }
@ -526,11 +526,12 @@ namespace MatterControl.Tests.MatterControl
(0, false), (0, false),
(5, true), (5, true),
(10, false), (10, false),
(20, false) (20, false),
(25, true)
}; };
int top = SupportGenerator.GetNextTop(0, planes); int top = SupportGenerator.GetNextTop(0, planes, 0);
Assert.AreEqual(2, top); Assert.AreEqual(3, top);
} }
} }
} }