2017-10-20 17:24:43 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2019-01-28 10:53:09 -08:00
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
/**************************** OBSOLETE! ******************************/
|
|
|
|
|
|
/************************ USE NEWER VERSION **************************/
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
2017-10-23 12:49:41 -07:00
|
|
|
|
using System;
|
2017-10-20 17:24:43 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2017-12-31 10:03:21 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2017-10-23 12:49:41 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-10-20 17:24:43 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-02-20 18:27:52 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2021-06-18 15:29:14 -07:00
|
|
|
|
using MatterHackers.PolygonMesh;
|
2021-11-26 12:49:42 -08:00
|
|
|
|
using MatterHackers.PolygonMesh.Csg;
|
2017-10-20 17:24:43 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|
|
|
|
|
{
|
2019-01-27 18:12:19 -08:00
|
|
|
|
[Obsolete("Use IntersectionObject3D_2 instead", false)]
|
2018-06-20 08:09:35 -07:00
|
|
|
|
public class IntersectionObject3D : MeshWrapperObject3D
|
2018-03-15 10:03:48 -07:00
|
|
|
|
{
|
|
|
|
|
|
public IntersectionObject3D()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Intersection";
|
|
|
|
|
|
}
|
2018-05-29 17:46:59 -07:00
|
|
|
|
|
2019-01-08 17:51:30 -08:00
|
|
|
|
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
2018-05-29 17:46:59 -07:00
|
|
|
|
{
|
2019-01-28 14:19:40 -08:00
|
|
|
|
if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Children)
|
|
|
|
|
|
|| invalidateType.InvalidateType.HasFlag(InvalidateType.Matrix)
|
|
|
|
|
|
|| invalidateType.InvalidateType.HasFlag(InvalidateType.Mesh))
|
2018-06-01 18:30:44 -07:00
|
|
|
|
&& invalidateType.Source != this
|
2018-06-20 17:16:38 -07:00
|
|
|
|
&& !RebuildLocked)
|
|
|
|
|
|
{
|
2019-01-08 17:51:30 -08:00
|
|
|
|
await Rebuild();
|
2018-06-20 17:16:38 -07:00
|
|
|
|
}
|
2019-01-28 14:19:40 -08:00
|
|
|
|
else if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties)
|
2018-06-20 17:16:38 -07:00
|
|
|
|
&& invalidateType.Source == this)
|
2018-06-01 18:30:44 -07:00
|
|
|
|
{
|
2019-01-08 17:51:30 -08:00
|
|
|
|
await Rebuild();
|
2018-06-01 18:30:44 -07:00
|
|
|
|
}
|
2019-01-28 14:19:40 -08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnInvalidate(invalidateType);
|
|
|
|
|
|
}
|
2018-05-29 17:46:59 -07:00
|
|
|
|
}
|
2018-03-15 10:03:48 -07:00
|
|
|
|
|
2019-01-08 17:51:30 -08:00
|
|
|
|
public override Task Rebuild()
|
2017-10-20 17:24:43 -07:00
|
|
|
|
{
|
2019-01-08 17:51:30 -08:00
|
|
|
|
var rebuildLocks = this.RebuilLockAll();
|
2017-10-23 12:49:41 -07:00
|
|
|
|
|
2019-01-08 17:51:30 -08:00
|
|
|
|
return ApplicationController.Instance.Tasks.Execute("Intersection".Localize(), null, (reporter, cancellationToken) =>
|
2017-12-26 17:54:42 -08:00
|
|
|
|
{
|
2018-02-20 18:27:52 -08:00
|
|
|
|
var progressStatus = new ProgressStatus();
|
2019-01-08 17:51:30 -08:00
|
|
|
|
reporter.Report(progressStatus);
|
2017-12-26 17:54:42 -08:00
|
|
|
|
|
2018-11-13 07:59:13 -08:00
|
|
|
|
try
|
2017-10-23 12:49:41 -07:00
|
|
|
|
{
|
2019-01-08 17:51:30 -08:00
|
|
|
|
Intersect(cancellationToken, reporter);
|
2017-12-26 17:54:42 -08:00
|
|
|
|
}
|
2019-01-28 14:19:40 -08:00
|
|
|
|
catch
|
2018-06-01 18:30:44 -07:00
|
|
|
|
{
|
2019-01-28 14:19:40 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-03 17:58:03 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
rebuildLocks.Dispose();
|
|
|
|
|
|
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
|
|
|
|
|
});
|
2017-12-31 10:03:21 -08:00
|
|
|
|
return Task.CompletedTask;
|
2017-12-26 17:54:42 -08:00
|
|
|
|
});
|
2017-10-20 17:24:43 -07:00
|
|
|
|
}
|
2019-01-08 17:51:30 -08:00
|
|
|
|
|
|
|
|
|
|
private void Intersect(CancellationToken cancellationToken, IProgress<ProgressStatus> reporter)
|
|
|
|
|
|
{
|
|
|
|
|
|
ResetMeshWrapperMeshes(Object3DPropertyFlags.All, cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
var participants = this.DescendantsAndSelf().Where((obj) => obj.OwnerID == this.ID);
|
|
|
|
|
|
|
|
|
|
|
|
if (participants.Count() > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
var first = participants.First();
|
|
|
|
|
|
|
|
|
|
|
|
var totalOperations = participants.Count() - 1;
|
|
|
|
|
|
double amountPerOperation = 1.0 / totalOperations;
|
2021-11-22 08:01:33 -08:00
|
|
|
|
double ratioCompleted = 0;
|
2019-01-08 17:51:30 -08:00
|
|
|
|
|
|
|
|
|
|
ProgressStatus progressStatus = new ProgressStatus();
|
|
|
|
|
|
foreach (var remove in participants)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (remove != first)
|
|
|
|
|
|
{
|
2021-06-18 15:29:14 -07:00
|
|
|
|
var result = BooleanProcessing.Do(remove.Mesh,
|
|
|
|
|
|
remove.WorldMatrix(),
|
|
|
|
|
|
first.Mesh,
|
|
|
|
|
|
first.WorldMatrix(),
|
2021-11-22 08:01:33 -08:00
|
|
|
|
CsgModes.Intersect,
|
|
|
|
|
|
ProcessingModes.Polygons,
|
|
|
|
|
|
ProcessingResolution._64,
|
|
|
|
|
|
ProcessingResolution._64,
|
2021-06-18 15:29:14 -07:00
|
|
|
|
reporter,
|
|
|
|
|
|
amountPerOperation,
|
2021-11-22 08:01:33 -08:00
|
|
|
|
ratioCompleted,
|
2021-06-18 15:29:14 -07:00
|
|
|
|
progressStatus,
|
|
|
|
|
|
cancellationToken);
|
2019-01-08 17:51:30 -08:00
|
|
|
|
|
|
|
|
|
|
var inverse = first.WorldMatrix();
|
|
|
|
|
|
inverse.Invert();
|
|
|
|
|
|
result.Transform(inverse);
|
|
|
|
|
|
using (first.RebuildLock())
|
|
|
|
|
|
{
|
|
|
|
|
|
first.Mesh = result;
|
|
|
|
|
|
}
|
|
|
|
|
|
remove.Visible = false;
|
|
|
|
|
|
|
2021-11-22 08:01:33 -08:00
|
|
|
|
ratioCompleted += amountPerOperation;
|
|
|
|
|
|
progressStatus.Progress0To1 = ratioCompleted;
|
2019-01-08 17:51:30 -08:00
|
|
|
|
reporter.Report(progressStatus);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-20 17:24:43 -07:00
|
|
|
|
}
|
2017-10-23 12:49:41 -07:00
|
|
|
|
}
|