From bed support generation has tests for many scenarios and passes them.
This commit is contained in:
parent
7addfd4bc8
commit
6ac91df984
2 changed files with 270 additions and 59 deletions
|
|
@ -28,8 +28,15 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.Tests.Automation;
|
||||
using MatterHackers.VectorMath;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MatterControl.Tests.MatterControl
|
||||
|
|
@ -38,41 +45,196 @@ namespace MatterControl.Tests.MatterControl
|
|||
public class SupportGeneratorTests
|
||||
{
|
||||
[Test, Category("Support Generator")]
|
||||
public void SupportExtentsTests()
|
||||
public async Task SupportsFromBedTests()
|
||||
{
|
||||
// make a cube in the air and ensure that no mater where it is placed, support is always under the entire extents
|
||||
InteractiveScene scene = new InteractiveScene();
|
||||
var supportGenerator = new SupportGenerator(scene);
|
||||
// Set the static data to point to the directory of MatterControl
|
||||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
|
||||
|
||||
// make a single cube in the air and ensure that support is generated
|
||||
// _________
|
||||
// | |
|
||||
// | |
|
||||
// |_______|
|
||||
//
|
||||
//______________
|
||||
{
|
||||
InteractiveScene scene = new InteractiveScene();
|
||||
|
||||
var cube = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabb = cube.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cube.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabb.MinXYZ.Z + 15);
|
||||
scene.Children.Add(cube);
|
||||
|
||||
var supportGenerator = new SupportGenerator(scene);
|
||||
supportGenerator.SupportType = SupportGenerator.SupportGenerationType.From_Bed;
|
||||
await supportGenerator.Create(null, CancellationToken.None);
|
||||
Assert.Greater(scene.Children.Count, 1, "We should have added some support");
|
||||
foreach (var support in scene.Children.Where(i => i.OutputType == PrintOutputTypes.Support))
|
||||
{
|
||||
Assert.AreEqual(0, support.GetAxisAlignedBoundingBox().MinXYZ.Z, .001, "Support columns are all on the bed");
|
||||
Assert.AreEqual(15, support.GetAxisAlignedBoundingBox().ZSize, 15, "Support columns should be the right height from the bed");
|
||||
}
|
||||
}
|
||||
|
||||
// make a cube on the bed and single cube in the air and ensure that support is not generated
|
||||
// _________
|
||||
// | |
|
||||
// | |
|
||||
// |_______|
|
||||
// _________
|
||||
// | |
|
||||
// | |
|
||||
//___|_______|___
|
||||
{
|
||||
InteractiveScene scene = new InteractiveScene();
|
||||
|
||||
var cubeOnBed = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabbBed = cubeOnBed.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cubeOnBed.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabbBed.MinXYZ.Z);
|
||||
scene.Children.Add(cubeOnBed);
|
||||
|
||||
var cubeInAair = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabbAir = cubeInAair.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cubeInAair.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabbAir.MinXYZ.Z + 25);
|
||||
scene.Children.Add(cubeInAair);
|
||||
|
||||
var supportGenerator = new SupportGenerator(scene);
|
||||
supportGenerator.SupportType = SupportGenerator.SupportGenerationType.From_Bed;
|
||||
await supportGenerator.Create(null, CancellationToken.None);
|
||||
Assert.AreEqual(2, scene.Children.Count, "We should not have added support");
|
||||
}
|
||||
|
||||
// make a cube on the bed and single cube in the air that intersects it and ensure that support is not generated
|
||||
// _________
|
||||
// | |
|
||||
// |______ | // top cube actually exactly on top of bottom cube
|
||||
// ||______||
|
||||
// | |
|
||||
//___|_______|___
|
||||
{
|
||||
InteractiveScene scene = new InteractiveScene();
|
||||
|
||||
var cubeOnBed = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabbBed = cubeOnBed.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cubeOnBed.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabbBed.MinXYZ.Z);
|
||||
scene.Children.Add(cubeOnBed);
|
||||
|
||||
var cubeInAair = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabbAir = cubeInAair.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cubeInAair.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabbAir.MinXYZ.Z + 15);
|
||||
scene.Children.Add(cubeInAair);
|
||||
|
||||
var supportGenerator = new SupportGenerator(scene);
|
||||
supportGenerator.SupportType = SupportGenerator.SupportGenerationType.From_Bed;
|
||||
await supportGenerator.Create(null, CancellationToken.None);
|
||||
Assert.AreEqual(2, scene.Children.Count, "We should not have added support");
|
||||
}
|
||||
|
||||
// Make a cube above the bed and a second above that. Ensure only one set of support material
|
||||
// _________
|
||||
// | |
|
||||
// | |
|
||||
// |_______|
|
||||
// _________
|
||||
// | |
|
||||
// | |
|
||||
// |_______|
|
||||
//_______________
|
||||
{
|
||||
InteractiveScene scene = new InteractiveScene();
|
||||
|
||||
var cube5AboveBed = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabb5Above = cube5AboveBed.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cube5AboveBed.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabb5Above.MinXYZ.Z + 5);
|
||||
scene.Children.Add(cube5AboveBed);
|
||||
|
||||
var cube30AboveBed = await CubeObject3D.Create(20, 20, 20);
|
||||
var aabb30Above = cube30AboveBed.GetAxisAlignedBoundingBox();
|
||||
// move it so the bottom is 15 above the bed
|
||||
cube30AboveBed.Matrix = Matrix4X4.CreateTranslation(0, 0, -aabb30Above.MinXYZ.Z + 30);
|
||||
scene.Children.Add(cube30AboveBed);
|
||||
|
||||
var supportGenerator = new SupportGenerator(scene);
|
||||
supportGenerator.SupportType = SupportGenerator.SupportGenerationType.From_Bed;
|
||||
await supportGenerator.Create(null, CancellationToken.None);
|
||||
|
||||
Assert.Greater(scene.Children.Count, 1, "We should have added some support");
|
||||
foreach (var support in scene.Children.Where(i => i.OutputType == PrintOutputTypes.Support))
|
||||
{
|
||||
Assert.AreEqual(0, support.GetAxisAlignedBoundingBox().MinXYZ.Z, .001, "Support columns are all on the bed");
|
||||
Assert.AreEqual(5, support.GetAxisAlignedBoundingBox().ZSize, 15, "Support columns should be the right height from the bed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test, Category("Support Generator"), Ignore("WIP")]
|
||||
[Test, Category("Support Generator")]
|
||||
public void TopBottomWalkingTest()
|
||||
{
|
||||
// a box in the air
|
||||
{
|
||||
var planes = new List<(double z, bool bottom)>()
|
||||
{
|
||||
(0, false), // top at 0 (the bed)
|
||||
(5, true), // bottom at 5 (the bottom of a box)
|
||||
(10, false), // top at 10 (the top of the box)
|
||||
};
|
||||
|
||||
int bottom = SupportGenerator.GetNextBottom(0, planes);
|
||||
Assert.AreEqual(1, bottom); // we get the bottom
|
||||
|
||||
int bottom1 = SupportGenerator.GetNextBottom(1, planes);
|
||||
Assert.AreEqual(-1, bottom1, "There are no more bottoms so we get back a -1.");
|
||||
}
|
||||
|
||||
// two boxes, the bottom touching the bed, the top touching the bottom
|
||||
{
|
||||
var planes = new List<(double z, bool bottom)>()
|
||||
{
|
||||
(0, false), // top at 0 (the bed)
|
||||
(0, true), // bottom at 0 (box a on bed)
|
||||
(10, false), // top at 10 (box a top)
|
||||
(10, true), // bottom at 10 (box b bottom)
|
||||
(20, false) // top at 20 (box b top)
|
||||
};
|
||||
|
||||
int bottom = SupportGenerator.GetNextBottom(0, planes);
|
||||
Assert.AreEqual(-1, bottom, "The boxes are sitting on the bed and no support is required");
|
||||
}
|
||||
|
||||
// two boxes, the bottom touching the bed, the top inside the bottom
|
||||
{
|
||||
var planes = new List<(double z, bool bottom)>()
|
||||
{
|
||||
(0, false), // top at 0 (the bed)
|
||||
(0, true), // bottom at 0 (box a on bed)
|
||||
(5, true), // bottom at 5 (box b bottom)
|
||||
(10, false), // top at 10 (box a top)
|
||||
(20, false) // top at 20 (box b top)
|
||||
};
|
||||
|
||||
int bottom = SupportGenerator.GetNextBottom(0, planes);
|
||||
Assert.AreEqual(-1, bottom, "The boxes are sitting on the bed and no support is required");
|
||||
}
|
||||
|
||||
// get next top skips any tops before checking for bottom
|
||||
{
|
||||
var planes = new List<(double z, bool bottom)>()
|
||||
{
|
||||
(0, false),
|
||||
(5, true),
|
||||
(5, true),
|
||||
(10, false),
|
||||
};
|
||||
|
||||
int bottom = SupportGenerator.GetNextBottom(0, planes);
|
||||
Assert.AreEqual(1, bottom);
|
||||
|
||||
int bottom1 = SupportGenerator.GetNextBottom(1, planes);
|
||||
Assert.AreEqual(0, bottom);
|
||||
}
|
||||
|
||||
{
|
||||
var planes = new List<(double z, bool bottom)>()
|
||||
{
|
||||
(10, false),
|
||||
(10, true),
|
||||
(20, false)
|
||||
};
|
||||
|
||||
int bottom = SupportGenerator.GetNextBottom(0, planes);
|
||||
Assert.AreEqual(0, bottom);
|
||||
int top = SupportGenerator.GetNextTop(0, planes);
|
||||
Assert.AreEqual(2, top);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue