internal static TriangleIntersection CalcNearestTriangle(Vector3Class origin, Vector3Class direction, STLModel3D selectedModel, Vector3Class linkedCloneTranslation) { TriangleIntersection nearestTriangle = null; TriangleIntersection[] intersectedTriangles = null; if (selectedModel != null) { //model var intersectedSupportCones = new List <Triangle>(); var supportDistance = 50000f; var cameraPosition = linkedCloneTranslation != null ? origin : origin; if (IntersectionProvider.IntersectTriangle(cameraPosition, direction, selectedModel, IntersectionProvider.typeDirection.OneWay, false, linkedCloneTranslation != null ? linkedCloneTranslation: new Vector3Class(), out intersectedTriangles)) { if (intersectedTriangles != null) { foreach (var intersectedTriangle in intersectedTriangles) { if (intersectedTriangle != null && intersectedTriangle.IntersectionPoint != null) { var cameraDistance = (SceneView.CameraPosition - intersectedTriangle.IntersectionPoint).Length; if (cameraDistance < supportDistance) { supportDistance = cameraDistance; nearestTriangle = intersectedTriangle; } } } } } } return(nearestTriangle); }
internal static void FilterOnAngledPointAndWallThickness(MagsAISurfaceIntersectionData modelAngledSupportPoint, STLModel3D stlModel) { if (modelAngledSupportPoint.ModelIntersection != null && modelAngledSupportPoint.Filter == typeOfAutoSupportFilter.None) { if (!modelAngledSupportPoint.IsGroundSupport) { if (modelAngledSupportPoint.LastSupportedCenterAngle < 135 && modelAngledSupportPoint.LastSupportedCenterAngle > 90) { //calc horizontal normal in inverted direction var wallThicknessNormal = modelAngledSupportPoint.ModelIntersection.Normal; //convert to horizontal normal wallThicknessNormal.Z = 0; wallThicknessNormal.Normalize(); TriangleIntersection[] triangleIntersections = null; IntersectionProvider.IntersectTriangle(modelAngledSupportPoint.ModelIntersection.IntersectionPoint, wallThicknessNormal, stlModel, IntersectionProvider.typeDirection.OneWay, false, new Vector3Class(), out triangleIntersections); if (triangleIntersections != null) { //find nearest intersection point var distance = float.MaxValue; foreach (var intersectionPoint in triangleIntersections) { if (intersectionPoint != null) { if (VectorHelper.IsSameDirection((intersectionPoint.IntersectionPoint - modelAngledSupportPoint.ModelIntersection.IntersectionPoint), -wallThicknessNormal)) { var intersectionDistance = (modelAngledSupportPoint.ModelIntersection.IntersectionPoint - intersectionPoint.IntersectionPoint).Length; if (intersectionDistance > 0f && intersectionDistance < distance) { distance = intersectionDistance; } } } } if (distance != float.MaxValue && distance > 3f) { modelAngledSupportPoint.Filter = typeOfAutoSupportFilter.FilteredByDuplicatePoint; } } else { } } } } }
internal void UpdateTriangleReference(STLModel3D stlModel, SupportProfile selectedMaterialProfile) { var supportPointPosition = this.TopPoint; supportPointPosition.Z = this.SliceHeight - 1f; if (this._trianglesWithinXYRange == null) { CalcTrianglesWithinRange(supportPointPosition, selectedMaterialProfile, stlModel); } //find latest supportcone supported height TriangleIntersection[] trianglesIntersected = null; var trianglesAboveSupportPoint = new STLModel3D() { Triangles = new TriangleInfoList() }; trianglesAboveSupportPoint.Triangles[0] = this._trianglesWithinXYRange.Triangles[0].Where(s => s.Top > supportPointPosition.Z && s.Normal.Z < 0).ToList(); IntersectionProvider.IntersectTriangle(supportPointPosition, new Vector3Class(0, 0, 1), trianglesAboveSupportPoint, IntersectionProvider.typeDirection.OneWay, false, new Vector3Class(), out trianglesIntersected); if (trianglesIntersected != null) { var nearestLastSupportedHeight = new Vector3Class(); var nearestLastSupportedHeightDistance = float.MaxValue; foreach (var triangleIntersection in trianglesIntersected) { if (triangleIntersection != null) { if (triangleIntersection.IntersectionPoint.Z > supportPointPosition.Z) { var distance = triangleIntersection.IntersectionPoint.Z - supportPointPosition.Z; if (distance < nearestLastSupportedHeightDistance) { nearestLastSupportedHeightDistance = distance; nearestLastSupportedHeight = triangleIntersection.IntersectionPoint; this.ModelIntersection = triangleIntersection; } } } } } }
internal void UpdateBottomSupportedHeight(STLModel3D stlModel) { //find latest supportcone supported height TriangleIntersection[] trianglesIntersected = null; var supportPointPosition = this.TopPoint.AsVector3(); supportPointPosition.Z = this.SliceHeight; IntersectionProvider.IntersectTriangle(supportPointPosition, new Vector3Class(0, 0, -1), stlModel, IntersectionProvider.typeDirection.OneWay, false, new Vector3Class(), out trianglesIntersected); this.BottomPoint = new Vector3Class(supportPointPosition.Xy); if (trianglesIntersected != null) { var nearestLastSupportedHeight = new Vector3Class(); var nearestLastSupportedHeightDistance = float.MaxValue; foreach (var triangleIntersection in trianglesIntersected) { if (triangleIntersection != null) { if (triangleIntersection.IntersectionPoint.Z < supportPointPosition.Z) { var distance = (triangleIntersection.IntersectionPoint - supportPointPosition).Length; if (distance < nearestLastSupportedHeightDistance) { nearestLastSupportedHeightDistance = distance; nearestLastSupportedHeight = triangleIntersection.IntersectionPoint; } } } } if (nearestLastSupportedHeight != new Vector3Class()) { this.BottomPoint = nearestLastSupportedHeight; } } else { } }
internal void UpdateLastSupportedHeight(STLModel3D stlModel, SupportProfile selectedMaterialProfile, SortedDictionary <float, PolyTree> modelLayers) { //find latest supportcone supported height var supportPointPosition = this.TopPoint; supportPointPosition.Z = this.SliceHeight - 1; if (this._trianglesWithinXYRange == null) { CalcTrianglesWithinRange(supportPointPosition, selectedMaterialProfile, stlModel); } var trianglesAboveSupportPoint = new STLModel3D() { Triangles = new TriangleInfoList() }; trianglesAboveSupportPoint.Triangles[0] = this._trianglesWithinXYRange.Triangles[0].Where(s => s.Bottom > supportPointPosition.Z && s.Normal.Z > 0).ToList(); var maxLayerHeight = float.MinValue; var currentSupportConeSupportedLayer = MagsAIEngine.ConvertSupportPointsToCircles(new IntPoint(supportPointPosition), selectedMaterialProfile.SupportOverhangDistance); currentSupportConeSupportedLayer.Add(new IntPoint(supportPointPosition)); foreach (var t in currentSupportConeSupportedLayer) { TriangleIntersection[] trianglesIntersected = null; IntersectionProvider.IntersectTriangle(t.AsVector3(), new Vector3Class(0, 0, -1), trianglesAboveSupportPoint, IntersectionProvider.typeDirection.OneWay, false, new Vector3Class(), out trianglesIntersected); var nearestTriangleIntersection = float.MaxValue; TriangleIntersection nearestIntersectionPoint = null; if (trianglesIntersected != null) { foreach (var triangleIntersected in trianglesIntersected) { if (triangleIntersected != null) { if (triangleIntersected.IntersectionPoint.Z >= this.SliceHeight) { var distance = (new Vector3Class(supportPointPosition.X, supportPointPosition.Y, triangleIntersected.IntersectionPoint.Z) - supportPointPosition).Length; if (distance < nearestTriangleIntersection) { nearestTriangleIntersection = distance; nearestIntersectionPoint = triangleIntersected; } } } } } if (nearestIntersectionPoint != null && nearestIntersectionPoint.IntersectionPoint.Z > maxLayerHeight) { maxLayerHeight = nearestIntersectionPoint.IntersectionPoint.Z; } } if (maxLayerHeight == float.MinValue) { maxLayerHeight = 10000; } this.LastSupportedSliceHeight = maxLayerHeight; }
internal void UpdateLastSupportedHeight(STLModel3D stlModel, SortedDictionary <float, PolyTree> modelAngleLayers, SupportProfile selectedMaterialProfile) { var stopwatch = new Stopwatch(); stopwatch.Start(); if (this.Id == null || this.Id == Guid.Empty) { this.Id = Guid.NewGuid(); } //find latest supportcone supported height TriangleIntersection[] trianglesIntersected = null; var supportPointPosition = this.TopPoint.AsVector3(); supportPointPosition.Z = this.SliceHeight; var currentSupportConeSupportedLayer = MagsAIEngine.ConvertSupportPointsToCircles(this.TopPoint, this.OverhangDistance * this.SupportOverhangDistanceFactor); currentSupportConeSupportedLayer.Add(this.TopPoint); if (this._trianglesWithinXYRange == null) { CalcTrianglesWithinRange(supportPointPosition, selectedMaterialProfile, stlModel); } var trianglesAboveSupportPoint = new STLModel3D() { Triangles = new TriangleInfoList() }; trianglesAboveSupportPoint.Triangles[0] = this._trianglesWithinXYRange.Triangles[0].Where(s => s.Bottom > supportPointPosition.Z && s.Normal.Z > 0).ToList(); //IntersectionProvider.IntersectTriangle(supportPointPosition, new Vector3Class(0, 0, -1), trianglesAboveSupportPoint, IntersectionProvider.typeDirection.OneWay, false, new Vector3Class(), out trianglesIntersected); //if (trianglesIntersected != null) //{ // var nearestLastSupportedHeight = new Vector3Class(); // var nearestLastSupportedHeightDistance = float.MaxValue; // foreach (var triangleIntersection in trianglesIntersected) // { // if (triangleIntersection != null) // { // var distance = (triangleIntersection.IntersectionPoint - supportPointPosition).Length; // if (distance < nearestLastSupportedHeightDistance) // { // nearestLastSupportedHeightDistance = distance; // nearestLastSupportedHeight = triangleIntersection.IntersectionPoint; // } // } // } // if (nearestLastSupportedHeight != new Vector3Class()) // { // this.LastSupportedCenterSliceHeight = nearestLastSupportedHeight.Z; // } //} ////determine the last supported slice height using the half of material overhangdistance and removing the layers above //if (this.LastSupportedCenterAngle == 0f) //{ // this.UpdateTriangleReference(stlModel, selectedMaterialProfile); //} var maxLayerHeight = float.MinValue; foreach (var t in currentSupportConeSupportedLayer) { var tAsVector = t.AsVector3(); tAsVector.Z = 1000; TriangleIntersection[] trianglesIntersected2 = null; IntersectionProvider.IntersectTriangle(tAsVector, new Vector3Class(0, 0, -1), trianglesAboveSupportPoint, IntersectionProvider.typeDirection.OneWay, false, new Vector3Class(), out trianglesIntersected2); var nearestTriangleIntersection = float.MaxValue; TriangleIntersection nearestIntersectionPoint = null; if (trianglesIntersected2 != null) { foreach (var triangleIntersected in trianglesIntersected2) { if (triangleIntersected != null) { if (triangleIntersected.IntersectionPoint.Z >= this.SliceHeight) { var distance = (triangleIntersected.IntersectionPoint - supportPointPosition).Length; if (distance < nearestTriangleIntersection) { nearestTriangleIntersection = distance; nearestIntersectionPoint = triangleIntersected; } } } } } if (nearestIntersectionPoint != null && nearestIntersectionPoint.IntersectionPoint.Z > maxLayerHeight) { maxLayerHeight = nearestIntersectionPoint.IntersectionPoint.Z; } } if (maxLayerHeight == float.MinValue) { maxLayerHeight = 10000; } this.LastSupportedSliceHeight = maxLayerHeight; // Console.WriteLine("SurfaceIntersectionData: Measurement 2: " + maxLayerHeight); // Console.WriteLine("SurfaceIntersectionData: Measurement 2: " + stopwatch.ElapsedMilliseconds + "ms"); }