/// <summary>
 /// Updates the support Profile.
 /// </summary>
 /// <param name="entity">The updated instance of the support profile.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
 /// <returns>The updated support profile</returns>
 public async Task <SupportProfile> UpdateAsync(SupportProfile entity, CancellationToken cancellationToken = default)
 {
     return(await Partner.ServiceClient.PutAsync <SupportProfile, SupportProfile>(
                new Uri(
                    $"/{PartnerService.Instance.ApiVersion}/{PartnerService.Instance.Configuration.Apis.UpdateSupportProfile.Path}",
                    UriKind.Relative),
                entity,
                cancellationToken).ConfigureAwait(false));
 }
示例#2
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                IPartner partner       = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);
                SupportProfile profile = await partner.Profiles.SupportProfile.GetAsync(CancellationToken).ConfigureAwait(false);

                profile.Email     = UpdateValue(SupportEmail, profile.Email);
                profile.Telephone = UpdateValue(SupportPhoneNumber, profile.Telephone);
                profile.Website   = UpdateValue(SupportWebsite, profile.Website);

                profile = await partner.Profiles.SupportProfile.UpdateAsync(profile, CancellationToken).ConfigureAwait(false);

                WriteObject(new PSSupportProfile(profile));
            }, true);
        }
示例#3
0
        private void CalcTrianglesWithinRange(Vector3Class supportPointPosition, SupportProfile selectedMaterialProfile, STLModel3D stlModel)
        {
            var boundryOffset = selectedMaterialProfile.SupportOverhangDistance;

            var modelTrianglesLeftBoundry        = supportPointPosition.X - boundryOffset;
            var modelTrianglesRightBoundry       = supportPointPosition.X + boundryOffset;
            var modelTrianglesBackBoundry        = supportPointPosition.Y - boundryOffset;
            var modelTrianglesFrontBoundry       = supportPointPosition.Y + boundryOffset;
            var currentSupportConeSupportedLayer = MagsAIEngine.ConvertSupportPointsToCircles(new IntPoint(supportPointPosition), selectedMaterialProfile.SupportOverhangDistance);

            currentSupportConeSupportedLayer.Add(new IntPoint(supportPointPosition));

            this._trianglesWithinXYRange = new STLModel3D
            {
                Triangles = stlModel.Triangles.GetTrianglesWithinXYBoundry(modelTrianglesLeftBoundry, modelTrianglesBackBoundry, modelTrianglesRightBoundry, modelTrianglesFrontBoundry)
            };
        }
示例#4
0
        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;
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        private SupportConeV2 CreateSubSupportConeWithinRange(SupportProfile supportProfile, int rotationAngle)
        {
            var rotationMatrix        = Matrix4.CreateRotationZ(OpenTK.MathHelper.DegreesToRadians(rotationAngle));
            var rotatedVector         = Vector3Class.Transform(new Vector3Class(supportProfile.SupportInfillDistance, 0, 0), rotationMatrix);
            var newSupportPointVector = rotatedVector - this.RefPointCSegment;

            newSupportPointVector.Z = 0;
            newSupportPointVector.Normalize();
            rotatedVector   = Vector3Class.Transform(newSupportPointVector, rotationMatrix);
            rotatedVector.Z = -1;
            rotatedVector.Normalize();

            if (this.Model.SupportHelperStructure == null)
            {
                this.Model.SupportHelperStructure = new List <SupportCone>();
            }

            var subSupportCone = new SupportConeV2(this.TopHeight, this.TopRadius, this.MiddleRadius, this.BottomHeight, this.BottomRadius, 26, new TriangleIntersection(new Triangle()
            {
                Normal = rotatedVector
            }, this.RefPointCSegment), Color.AntiqueWhite,
                                                   aSegmentRadius: this.ASegmentRadius,
                                                   aSegmentHeight: this.ASegmentHeight,
                                                   bSegmentRadius: this.BSegmentRadius,
                                                   bSegmentHeight: this.BSegmentHeight + (4 * this.MiddleRadius),
                                                   cSegmentRadius: this.CSegmentRadius,
                                                   dSegmentRadius: this.DSegmentRadius,
                                                   dSegmentHeight: this.DSegmentHeight
                                                   );

            //add support interlinks
            this.UpdateInterlinkConnections(subSupportCone, supportProfile);

            if (this.Model.SupportHelperStructure == null)
            {
                this.Model.SupportHelperStructure = new List <SupportCone>();
            }
            this.Model.SupportHelperStructure.Add(subSupportCone);

            this.UpdateBinding();

            return(subSupportCone);
        }
示例#6
0
        public List <List <IntPoint> > ToPolyPaths(SupportProfile selectedMaterialProfile)
        {
            var polyPaths   = new List <List <IntPoint> >();
            var polygonPath = new List <IntPoint>();

            //first pass add normal points as intpoint
            foreach (var surfaceLine in this)
            {
                polygonPath.Add(new IntPoint(surfaceLine.Point));
            }

            polygonPath.Add(new IntPoint(this[0].Point));

            //if (this.ClosedPath)
            //{
            //    polygonPath.Add(new IntPoint(this[0].Point));
            //    polyNode.m_polygon = polygonPath;
            //    polyNodes.Add(polyNode);
            //    polyNode = new PolyNode();
            //    polygonPath = new List<IntPoint>();
            //}

            ////second pass reverse points and append avg normal
            //for(var surfaceLineIndex = this.Count - 1;surfaceLineIndex >= 0;surfaceLineIndex--)
            //{
            //    var avgLineNormal = new Vector3Class();
            //    foreach(var normal in this[surfaceLineIndex].Normals)
            //    {
            //        avgLineNormal += normal;
            //    }

            //    avgLineNormal.Z = 0;
            //    avgLineNormal = avgLineNormal.Normalized();

            //    polygonPath.Add(new IntPoint(this[surfaceLineIndex].Point + (avgLineNormal * selectedMaterialProfile.SupportOverhangDistance)));
            //}

            if (polygonPath.Count > 0)
            {
                polyPaths.Add(polygonPath);
            }
            return(polyPaths);
        }
示例#7
0
        public void UpdateInterlinkConnections(SupportConeV2 targetSupportCone, SupportProfile supportProfile)
        {
            for (var intermittedHeight = this.BottomHeight + supportProfile.SupportIntermittedConnectionHeight; intermittedHeight < targetSupportCone.RefPointCSegment.Z; intermittedHeight += supportProfile.SupportIntermittedConnectionHeight)
            {
                var startPoint = new Vector3Class(this.RefPointCSegment.X, this.RefPointCSegment.Y, intermittedHeight);
                var endPoint   = targetSupportCone.RefPointCSegment;
                var xyDistance = endPoint - startPoint;
                xyDistance.Z = 0;
                endPoint.Z   = intermittedHeight + (supportProfile.SupportIntermittedConnectionHeight * xyDistance.Length);

                if (InterlinkConnections == null)
                {
                    this.InterlinkConnections = new SortedDictionary <float, List <SupportConeV2InterlinkConnection> >();
                }

                if (!this.InterlinkConnections.ContainsKey(intermittedHeight))
                {
                    this.InterlinkConnections.Add(intermittedHeight, new List <SupportConeV2InterlinkConnection>());
                }

                this.InterlinkConnections[intermittedHeight].Add(new SupportConeV2InterlinkConnection(0.1f, startPoint, endPoint, Color.Yellow));
            }
        }
示例#8
0
文件: Slice.cs 项目: Sidd710/tempRepo
        internal void ConvertModelIntersectionsToPolyTrees(float sliceHeight, AtumPrinter selectedPrinter, Material selectedMaterial, SupportProfile selectedMaterialProfile,
                                                           List <float[]> angleSideAngles, List <float[]> wallSideAngles,
                                                           bool usePixelsAsValues = true, bool includeAngledSide = false, bool includeWallSides = false)
        {
            var angledSides = new List <List <PolylineWithNormal> >();
            var wallSides   = new List <List <PolylineWithNormal> >();

            this.ModelPolyTrees[0] = PolyTree.FromListOfModelIntersectionsUsingPolygons(sliceHeight, this._modelIntersectionsZ, selectedPrinter,
                                                                                        angleSideAngles, wallSideAngles,
                                                                                        out angledSides, out wallSides,
                                                                                        usePixelsAsValues, processUnion: true,
                                                                                        includeAngledSides: includeAngledSide, includeWallSides: includeWallSides);


            if (includeAngledSide && angledSides.Count > 0)
            {
                this.ModelAnglesPolyTree = new PolyTree();
                var clipperOffset = new ClipperOffset();
                var clipperResult = new PolyTree();
                foreach (var angledSide in angledSides)
                {
                    var polyList = new List <IntPoint>();
                    foreach (var angledPolygon in angledSide)
                    {
                        polyList.Add(angledPolygon.Point);
                    }


                    ReducePointsInPath(polyList, MagsAIEngine.PixelOffsetOptimisation);

                    clipperOffset.AddPath(polyList, JoinType.jtMiter, EndType.etOpenButt);
                }

                clipperOffset.Execute(ref clipperResult, (selectedMaterialProfile.SupportOverhangDistance) * (CONTOURPOINT_TO_VECTORPOINT_FACTOR));
                clipperResult            = IntersectModelSliceLayer(this.ModelPolyTrees[0][0], clipperResult);
                this.ModelAnglesPolyTree = clipperResult;
                ReducePointsInPolyTree(this.ModelAnglesPolyTree, MagsAIEngine.PixelOffsetOptimisation);
            }

            //polytree using polygon offset
            if (includeWallSides && wallSides.Count > 0)
            {
                var clipperOffset = new ClipperOffset();
                foreach (var wallSide in wallSides)
                {
                    var polyList = new List <IntPoint>();
                    foreach (var wallPolygon in wallSide)
                    {
                        polyList.Add(wallPolygon.Point);
                    }

                    ReducePointsInPath(polyList, MagsAIEngine.PixelOffsetOptimisation);
                    clipperOffset.AddPath(polyList, JoinType.jtMiter, EndType.etOpenButt);
                }

                var clipperResult = new PolyTree();
                clipperOffset.Execute(ref clipperResult, (selectedMaterialProfile.SupportOverhangDistance / 2) * (CONTOURPOINT_TO_VECTORPOINT_FACTOR));
                clipperResult = IntersectModelSliceLayer(this.ModelWallPolyTree, clipperResult);

                this.ModelWallPolyTree = clipperResult;
                ReducePointsInPolyTree(this.ModelWallPolyTree, MagsAIEngine.PixelOffsetOptimisation);

                //TriangleHelper.SavePolyNodesContourToPng(this.ModelWallPolyTree._allPolys, "wall_" + sliceHeight.ToString("00.00"));
            }
        }
示例#9
0
文件: Slice.cs 项目: Sidd710/tempRepo
 internal List <MagsAIPolyLines> ConvertModelIntersectionsToPolyLines(float sliceHeight, SupportProfile selectedMaterialProfile, AtumPrinter selectedPrinter, bool usePixelsAsValues = true)
 {
     return(MagsAIPolyLines.FromListOfModelIntersectionsUsingPolyLines(sliceHeight, this._modelIntersectionsZ, selectedMaterialProfile, selectedPrinter, usePixelsAsValues));
 }
示例#10
0
        public static void Start(bool addHandlers)
        {
            //bind manufacturer comboxbox
            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(MaterialsBySupplier));

            _materialCatalog = new MaterialsCatalog();

            //if no material catalog is found then save default items
            try
            {
                //                var hasLocalWriteAccess = FileSystemManager.HasWriteAccess(Settings.BasePath);
                //                if (hasLocalWriteAccess)
                //                {
                //                    LoggingManager.WriteToLog("Material Manager", "Base Path", Settings.MaterialsPath);

                //                    if (!Directory.Exists(Settings.MaterialsPath))
                //                    {
                //                        LoggingManager.WriteToLog("Material Manager", "Creating Base Path", Settings.MaterialsPath);

                //                        Directory.CreateDirectory(Settings.MaterialsPath);

                //                        LoggingManager.WriteToLog("Material Manager", "Created Base Path", Settings.MaterialsPath);

                //                        //add default materials
                //                        LoggingManager.WriteToLog("Material Manager", "Saving default materials", Settings.MaterialsPath);

                //#if LOCTITE
                //                        var defaultMaterialFilePath = Path.Combine(Settings.MaterialsPath, "Henkel.xml");
                //                        File.WriteAllBytes(defaultMaterialFilePath, Properties.Resources.Material_Henkel_xml);
                //#else
                //                        var defaultMaterialFilePath = Path.Combine(Settings.MaterialsPath, "3DMaterials.xml");
                //                        File.WriteAllBytes(defaultMaterialFilePath, Properties.Resources.Material_3DMaterials_xml);
                //#endif

                //                        LoggingManager.WriteToLog("Material Manager", "Saved default materials", Settings.MaterialsPath);
                //                    }
                //                }
                //                else
                {
                    LoggingManager.WriteToLog("Material Manager", "Base Path", Settings.RoamingMaterialsPath);

                    if (!Directory.Exists(Settings.RoamingMaterialsPath))
                    {
                        LoggingManager.WriteToLog("Material Manager", "Creating Base Path", Settings.RoamingMaterialsPath);

                        Directory.CreateDirectory(Settings.RoamingMaterialsPath);

                        LoggingManager.WriteToLog("Material Manager", "Created Base Path", Settings.RoamingMaterialsPath);
                    }
                    //add default materials
                    if ((!Directory.Exists(Settings.MaterialsPath) && Directory.GetFiles(Settings.RoamingMaterialsPath).Length == 0))
                    {
                        LoggingManager.WriteToLog("Material Manager", "Saving default materials", Settings.RoamingMaterialsPath);

#if LOCTITE
                        File.WriteAllBytes(Path.Combine(Settings.RoamingMaterialsPath, "Henkel.xml"), Properties.Resources.Material_Henkel_xml);
#else
                        File.WriteAllBytes(Path.Combine(Settings.RoamingMaterialsPath, "3D-Materials.xml"), Properties.Resources.Material_3DMaterials_xml);
#endif


                        LoggingManager.WriteToLog("Material Manager", "Saved default materials", Settings.RoamingMaterialsPath);
                    }
                    else if ((Directory.Exists(Settings.MaterialsPath) && Directory.GetFiles(Settings.MaterialsPath).Length == 0))
                    {
                        try
                        {
                            LoggingManager.WriteToLog("Material Manager", "Saving default materials", Settings.MaterialsPath);

#if LOCTITE
                            File.WriteAllBytes(Path.Combine(Settings.MaterialsPath, "Henkel.xml"), Properties.Resources.Material_Henkel_xml);
#else
                            File.WriteAllBytes(Path.Combine(Settings.MaterialsPath, "3D-Materials.xml"), Properties.Resources.Material_3DMaterials_xml);
#endif

                            LoggingManager.WriteToLog("Material Manager", "Saved default materials", Settings.RoamingMaterialsPath);
                        }
                        catch
                        {
                        }
                    }
                }

                if (Directory.Exists(Settings.MaterialsPath))
                {
                    foreach (var supplierXML in Directory.GetFiles(Settings.MaterialsPath))
                    {
                        LoggingManager.WriteToLog("Material Manager", "Loading material", supplierXML);

                        var updateMaterialFile = false;
                        MaterialsBySupplier updateSupplierMaterials = null;
                        using (var materialReader = new StreamReader(supplierXML))
                        {
                            var supplierMaterials = (MaterialsBySupplier)serializer.Deserialize(materialReader);
                            supplierMaterials.FilePath = supplierXML.Replace("/", "\\");

                            LoggingManager.WriteToLog("Material Manager", "Loaded material", supplierXML);
                            _materialCatalog.Add(supplierMaterials);

                            foreach (var material in supplierMaterials.Materials)
                            {
                                if (material.Id == Guid.Empty)
                                {
                                    material.Id        = Guid.NewGuid();
                                    updateMaterialFile = true;
                                }

                                //material.TransitionLayers.Add(new DAL.Catalogs.MaterialTransitionLayer() { CT = 100, LI = 15 });

                                if (material.SupportProfiles == null || material.SupportProfiles.Count == 0)
                                {
                                    material.SupportProfiles.Add(new SupportProfile());
                                    material.SupportProfiles[0].Selected = true;
                                    material.SupportProfiles[0].Default  = true;
                                }
                            }

                            updateSupplierMaterials = supplierMaterials;

                            materialReader.Close();
                        }

                        if (updateMaterialFile)
                        {
                            updateSupplierMaterials.SaveToFile();
                        }
                    }

                    if (addHandlers)
                    {
                        AddMaterialWatcher(Settings.MaterialsPath.Replace("/", "\\"));
                    }
                }

                else if (Directory.Exists(Settings.RoamingMaterialsPath))
                {
                    foreach (var supplierXML in Directory.GetFiles(Settings.RoamingMaterialsPath))
                    {
                        LoggingManager.WriteToLog("Material Manager", "Loading material", supplierXML);

                        var updateMaterialFile = false;
                        MaterialsBySupplier updateSupplierMaterials = null;
                        using (var materialReader = new StreamReader(supplierXML))
                        {
                            var supplierMaterials = (MaterialsBySupplier)serializer.Deserialize(materialReader);
                            supplierMaterials.FilePath = supplierXML.Replace("/", "\\");;

                            LoggingManager.WriteToLog("Material Manager", "Loaded material", supplierXML);

                            var supplierNameFound = false;
                            foreach (var supplier in _materialCatalog)
                            {
                                if (!string.IsNullOrEmpty(supplier.Supplier))
                                {
                                    if (supplier.Supplier.ToLower().Trim() == supplierMaterials.Supplier.ToLower().Trim())
                                    {
                                        supplierNameFound = true;
                                        break;
                                    }
                                }
                            }

                            if (!supplierNameFound)
                            {
                                foreach (var material in supplierMaterials.Materials)
                                {
                                    if (material.Id == Guid.Empty)
                                    {
                                        material.Id        = Guid.NewGuid();
                                        updateMaterialFile = true;
                                    }
                                    // material.TransitionLayers.Add(new DAL.Catalogs.MaterialTransitionLayer() { CT = 100, LI = 15 });

                                    if (material.SupportProfiles == null || material.SupportProfiles.Count == 0)
                                    {
                                        material.SupportProfiles.Add(SupportProfile.CreateDefault());
                                    }
                                }
                                _materialCatalog.Add(supplierMaterials);
                            }

                            updateSupplierMaterials = supplierMaterials;

                            materialReader.Close();

                            if (updateMaterialFile)
                            {
                                updateSupplierMaterials.SaveToFile();
                            }
                        }
                    }

                    if (addHandlers)
                    {
                        AddMaterialWatcher(Settings.RoamingMaterialsPath.Replace("/", "\\"));
                    }
                }
            }
            catch (Exception exc)
            {
                new frmMessageBox("Material Manager", exc.ToString(), MessageBoxButtons.OK, MessageBoxDefaultButton.Button2).ShowDialog();
                LoggingManager.WriteToLog("Material Manager", "Exception", exc);
            }
        }
示例#11
0
        internal void LoadSelectedMaterial(Material selectedMaterial, MaterialsBySupplier selectedSupplier)
        {
            this._selectedMaterial = selectedMaterial;
            this._selectedSupplier = selectedSupplier;
            //resin properties
            try
            {
                this.btnResinModelColor.BackColor = selectedMaterial.ModelColor;
                this.txtResinName.Text            = selectedMaterial.Name;
                this.txtDisplayName.Text          = selectedMaterial.DisplayName;

                this.txtResinInitialLayers.Value        = selectedMaterial.InitialLayers;
                this.txtResinPreparationMovements.Value = selectedMaterial.PreparationLayersCount;
                this.txtResinShrinkFactor.Value         = (decimal)selectedMaterial.ShrinkFactor - 1;
                this.txtResinZBleedingOffset.Value      = (decimal)selectedMaterial.BleedingOffset;

                this.txtResinArticle.Text     = selectedMaterial.ArticleNumber;
                this.txtResinArticleURL.Text  = selectedMaterial.ArticleHTTP;
                this.txtResinBatch.Text       = selectedMaterial.BatchNumber;
                this.txtResinPrice.Text       = selectedMaterial.Price.ToString("0.00");
                this.txtResinDescription.Text = selectedMaterial.Description;


                //material properties
                this.txtLayerThickness1.Value              = (decimal)selectedMaterial.LT1;
                this.txtLayerThickness2.Value              = (decimal)selectedMaterial.LT2;
                this.txtLayerRehabTime1.Value              = (decimal)selectedMaterial.RT1;
                this.txtLayerRehabTime2.Value              = (decimal)selectedMaterial.RT2;
                this.txtLayerCurringTime1.Value            = (decimal)selectedMaterial.CT1;
                this.txtLayerCurringTime2.Value            = (decimal)selectedMaterial.CT2;
                this.txtLayerRehabTimeAfterCuring1.Value   = (decimal)selectedMaterial.RTAC1;
                this.txtLayerRehabTimeAfterCuring2.Value   = (decimal)selectedMaterial.RTAC2;
                this.txtLayerRetractionHeight1.Value       = (decimal)selectedMaterial.RH1;
                this.txtLayerRetractionHeight2.Value       = (decimal)selectedMaterial.RH2;
                this.txtLayerRetractionSpeedUp1.Value      = (decimal)selectedMaterial.RSU1;
                this.txtLayerRetractionSpeedUp2.Value      = (decimal)selectedMaterial.RSU2;
                this.txtLayerTimeAtTop1.Value              = (decimal)selectedMaterial.TAT1;
                this.txtLayerTimeAtTop2.Value              = (decimal)selectedMaterial.TAT2;
                this.txtLayerRetractionSpeedDown1.Value    = (decimal)selectedMaterial.RSD1;
                this.txtLayerRetractionSpeedDown2.Value    = (decimal)selectedMaterial.RSD2;
                this.txtLayerLightIntensityStrength1.Value = (decimal)selectedMaterial.LightIntensityPercentage1;
                this.txtLayerLightIntensityStrength2.Value = (decimal)selectedMaterial.LightIntensityPercentage2;

                this.txtLayerTransitionLayer1CT.Value   = 0;
                this.txtLayerTransitionLayer1LI.Value   = 0;
                this.txtLayerTransitionLayer1RTAC.Value = 0;
                this.txtLayerTransitionLayer2CT.Value   = 0;
                this.txtLayerTransitionLayer2LI.Value   = 0;
                this.txtLayerTransitionLayer2RTAC.Value = 0;
                this.txtLayerTransitionLayer3CT.Value   = 0;
                this.txtLayerTransitionLayer3LI.Value   = 0;
                this.txtLayerTransitionLayer3RTAC.Value = 0;
                this.txtLayerTransitionLayer4CT.Value   = 0;
                this.txtLayerTransitionLayer4LI.Value   = 0;
                this.txtLayerTransitionLayer4RTAC.Value = 0;
                this.txtLayerTransitionLayer5CT.Value   = 0;
                this.txtLayerTransitionLayer5LI.Value   = 0;
                this.txtLayerTransitionLayer5RTAC.Value = 0;

                if (selectedMaterial.TransitionLayers != null && selectedMaterial.TransitionLayers.Count > 0)
                {
                    if (selectedMaterial.TransitionLayers.Count > 4)
                    {
                        this.txtLayerTransitionLayer5CT.Value   = (decimal)selectedMaterial.TransitionLayers[4].CT;
                        this.txtLayerTransitionLayer5LI.Value   = (decimal)selectedMaterial.TransitionLayers[4].LI;
                        this.txtLayerTransitionLayer5RTAC.Value = (decimal)selectedMaterial.TransitionLayers[4].RTAC;
                    }
                    if (selectedMaterial.TransitionLayers.Count > 3)
                    {
                        this.txtLayerTransitionLayer4CT.Value   = (decimal)selectedMaterial.TransitionLayers[3].CT;
                        this.txtLayerTransitionLayer4LI.Value   = (decimal)selectedMaterial.TransitionLayers[3].LI;
                        this.txtLayerTransitionLayer4RTAC.Value = (decimal)selectedMaterial.TransitionLayers[3].RTAC;
                    }
                    if (selectedMaterial.TransitionLayers.Count > 2)
                    {
                        this.txtLayerTransitionLayer3CT.Value   = (decimal)selectedMaterial.TransitionLayers[2].CT;
                        this.txtLayerTransitionLayer3LI.Value   = (decimal)selectedMaterial.TransitionLayers[2].LI;
                        this.txtLayerTransitionLayer3RTAC.Value = (decimal)selectedMaterial.TransitionLayers[2].RTAC;
                    }
                    if (selectedMaterial.TransitionLayers.Count > 1)
                    {
                        this.txtLayerTransitionLayer2CT.Value   = (decimal)selectedMaterial.TransitionLayers[1].CT;
                        this.txtLayerTransitionLayer2LI.Value   = (decimal)selectedMaterial.TransitionLayers[1].LI;
                        this.txtLayerTransitionLayer2RTAC.Value = (decimal)selectedMaterial.TransitionLayers[1].RTAC;
                    }
                    if (selectedMaterial.TransitionLayers.Count > 0)
                    {
                        this.txtLayerTransitionLayer1CT.Value   = (decimal)selectedMaterial.TransitionLayers[0].CT;
                        this.txtLayerTransitionLayer1LI.Value   = (decimal)selectedMaterial.TransitionLayers[0].LI;
                        this.txtLayerTransitionLayer1RTAC.Value = (decimal)selectedMaterial.TransitionLayers[0].RTAC;
                    }
                }

                //support cone properties
                if (selectedMaterial.SupportProfiles == null || selectedMaterial.SupportProfiles.Count == 0)
                {
                    selectedMaterial.SupportProfiles = new List <SupportProfile>();
                    selectedMaterial.SupportProfiles.Add(SupportProfile.CreateDefault());
                }
                if (selectedMaterial.SupportProfiles.First().SupportTopRadius == 0 && selectedMaterial.SupportProfiles.First().SupportTopHeight == 0)
                {
                    selectedMaterial.SupportProfiles.Clear();
                    selectedMaterial.SupportProfiles.Add(SupportProfile.CreateDefault());
                }


                var defaultSupportProfile = selectedMaterial.SupportProfiles.First();
                this.txtSupportConeTopRadius.Value             = (decimal)defaultSupportProfile.SupportTopRadius;
                this.txtSupportConeTopHeight.Value             = (decimal)defaultSupportProfile.SupportTopHeight;
                this.txtSupportConeMiddleRadius.Value          = (decimal)defaultSupportProfile.SupportMiddleRadius;
                this.txtSupportConeBottomRadius.Value          = (decimal)defaultSupportProfile.SupportBottomRadius;
                this.txtSupportConeBottomHeight.Value          = (decimal)defaultSupportProfile.SupportBottomHeight;
                this.txtSupportConeBottomWidthCorrection.Value = (decimal)defaultSupportProfile.SupportBottomWidthCorrection;

                this.txtMAGSAIInfillDistance.Value   = (decimal)defaultSupportProfile.SupportInfillDistance <= 0 ? (decimal)2.1 : (decimal)defaultSupportProfile.SupportInfillDistance;
                this.txtMAGSAIOverhangDistance.Value = (decimal)defaultSupportProfile.SupportOverhangDistance <= 0 ? (decimal)2.1 : (decimal)defaultSupportProfile.SupportOverhangDistance;
                this.txtMAGSAIOutlineDistance.Value  = (decimal)defaultSupportProfile.SupportLowestPointsDistance <= 0 ? (decimal)2.1 : (decimal)defaultSupportProfile.SupportLowestPointsDistance;

                this.txtMAGSAILowestPointOffset1CenterDistanceFactor1.Value  = 0;
                this.txtMAGSAILowestPointOffset1OutlineDistanceFactor1.Value = 0;
                this.txtMAGSAILowestPointOffset1CenterDistanceFactor2.Value  = 0;
                this.txtMAGSAILowestPointOffset1OutlineDistanceFactor2.Value = 0;
                this.txtMAGSAILowestPointOffset1CenterDistanceFactor3.Value  = 0;
                this.txtMAGSAILowestPointOffset1OutlineDistanceFactor3.Value = 0;
                this.txtMAGSAILowestPointOffset1CenterDistanceFactor4.Value  = 0;
                this.txtMAGSAILowestPointOffset1OutlineDistanceFactor4.Value = 0;

                if (defaultSupportProfile.SupportLowestPointsOffset.Count > 0 && defaultSupportProfile.SupportLowestPointsDistanceOffset.Count > 0)
                {
                    this.txtMAGSAILowestPointOffset1CenterDistanceFactor1.Value  = (decimal)defaultSupportProfile.SupportLowestPointsOffset[0];
                    this.txtMAGSAILowestPointOffset1OutlineDistanceFactor1.Value = (decimal)defaultSupportProfile.SupportLowestPointsDistanceOffset[0];

                    if (defaultSupportProfile.SupportLowestPointsOffset.Count > 1 && defaultSupportProfile.SupportLowestPointsDistanceOffset.Count > 1)
                    {
                        this.txtMAGSAILowestPointOffset1CenterDistanceFactor2.Value  = (decimal)defaultSupportProfile.SupportLowestPointsOffset[1];
                        this.txtMAGSAILowestPointOffset1OutlineDistanceFactor2.Value = (decimal)defaultSupportProfile.SupportLowestPointsDistanceOffset[1];

                        if (defaultSupportProfile.SupportLowestPointsOffset.Count > 2 && defaultSupportProfile.SupportLowestPointsDistanceOffset.Count > 2)
                        {
                            this.txtMAGSAILowestPointOffset1CenterDistanceFactor3.Value  = (decimal)defaultSupportProfile.SupportLowestPointsOffset[2];
                            this.txtMAGSAILowestPointOffset1OutlineDistanceFactor3.Value = (decimal)defaultSupportProfile.SupportLowestPointsDistanceOffset[2];

                            if (defaultSupportProfile.SupportLowestPointsOffset.Count > 3 && defaultSupportProfile.SupportLowestPointsDistanceOffset.Count > 3)
                            {
                                this.txtMAGSAILowestPointOffset1CenterDistanceFactor4.Value  = (decimal)defaultSupportProfile.SupportLowestPointsOffset[3];
                                this.txtMAGSAILowestPointOffset1OutlineDistanceFactor4.Value = (decimal)defaultSupportProfile.SupportLowestPointsDistanceOffset[3];
                            }
                        }
                    }
                }

                this.txtMAGSAIAngledSurfaceDistance1.Value = this.txtMAGSAIAngledSurfaceDistance1.Minimum;
                this.txtMAGSAIAngledSurfaceDistance2.Value = this.txtMAGSAIAngledSurfaceDistance2.Minimum;

                if (defaultSupportProfile.SurfaceAngles.Count > 0 && defaultSupportProfile.SurfaceAngleDistanceFactors.Count > 0)
                {
                    this.txtMAGSAIAngledSurfaceDistance1.Value = (decimal)defaultSupportProfile.SurfaceAngleDistanceFactors[0];

                    if (defaultSupportProfile.SurfaceAngles.Count > 1 && defaultSupportProfile.SurfaceAngleDistanceFactors.Count > 1)
                    {
                        this.txtMAGSAIAngledSurfaceDistance2.Value = (decimal)defaultSupportProfile.SurfaceAngleDistanceFactors[1];
                    }
                }

                if (_magsAITabHidden)
                {
                    this.tbMaterialSettings.TabPages.Remove(this.tbMAGSAI);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }

            this.txtSupportConeTopHeight.ValueChanged             += UpdateSupportConeDrawing;
            this.txtSupportConeBottomHeight.ValueChanged          += UpdateSupportConeDrawing;
            this.txtSupportConeTopRadius.ValueChanged             += UpdateSupportConeDrawing;
            this.txtSupportConeMiddleRadius.ValueChanged          += UpdateSupportConeDrawing;
            this.txtSupportConeBottomRadius.ValueChanged          += UpdateSupportConeDrawing;
            this.txtSupportConeBottomWidthCorrection.ValueChanged += UpdateSupportConeDrawing;

            if (this.tbMaterialSettings.SelectedTab == this.tbSupportProperties)
            {
                this.tbMaterialSettings.Update();
                DrawSupportCone();
            }
        }
示例#12
0
        internal Dictionary <IntPoint, MagsAISurfaceIntersectionData> CalcSupportPoints(SortedDictionary <float, PolyTree> modelLayers, ConcurrentDictionary <float, ConcurrentDictionary <MagsAIIntersectionData, bool> > currentModelSupportPoints, float firstSurfaceAngleDistanceFactor, SupportProfile selectedMaterialProfile, float overhangFactor, ConcurrentDictionary <float, ConcurrentDictionary <float, ConcurrentDictionary <IntPoint, MagsAISurfaceIntersectionData> > > previousOverhangDistanceFactorBasedSupportPoints, STLModel3D stlModel, TriangleSurfaceInfo surface)
        {
            this.AddedSupportPoints        = new Dictionary <IntPoint, MagsAISurfaceIntersectionData>();
            this.AddedSupportPointsByLayer = new Dictionary <float, Dictionary <IntPoint, MagsAISurfaceIntersectionData> >();

            //create support cones that exists in each layer
            var previousSliceHeight = float.MaxValue;

            foreach (var sliceHeight in this.ModelContours.Keys.OrderBy(s => s))
            {
                var sliceContours = this.ModelContours[sliceHeight];
                sliceContours = ContourHelper.IntersectModelSliceLayer(sliceContours, modelLayers[sliceHeight]); //create contour offset using max border as model contour instead of extrude contour

                if (!this.AddedSupportPointsByLayer.ContainsKey(sliceHeight))
                {
                    this.AddedSupportPointsByLayer.Add(sliceHeight, new Dictionary <IntPoint, MagsAISurfaceIntersectionData>());
                }

                if (previousSliceHeight != float.MaxValue)
                {
                    var supportedLayerAsPolyTree = new PolyTree();
                    if (this.AddedSupportPointsByLayer.ContainsKey(previousSliceHeight))
                    {
                        foreach (var supportIntersectionData in this.AddedSupportPointsByLayer[previousSliceHeight].Values)
                        {
                            if (supportIntersectionData.UnsupportedContour)
                            {
                                this.AddedSupportPointsByLayer[sliceHeight].Add(supportIntersectionData.TopPoint, supportIntersectionData);
                            }
                        }
                    }

                    //added support circles from current diff layer with overhang distance
                    foreach (var overhangDistanceFactor in previousOverhangDistanceFactorBasedSupportPoints)
                    {
                        var previousAngleBasedSupportPointsAsCircles = new List <List <IntPoint> >();
                        if (overhangDistanceFactor.Value.ContainsKey(sliceHeight))
                        {
                            foreach (var previousAngleBasedSupportPoint in overhangDistanceFactor.Value[sliceHeight].Values)
                            {
                                AddPointToCurrentLayerWhenExistsInContour(sliceContours, previousAngleBasedSupportPoint, sliceHeight);
                            }
                        }
                    }

                    //check if supportcones where allready added using other algorithms
                    var supportSliceHeightsWithinRange = new List <float>()
                    {
                        (float)Math.Round(previousSliceHeight - (sliceHeight - previousSliceHeight), 2), sliceHeight
                    };
                    var supportSliceHeightsWithinRangeMin = supportSliceHeightsWithinRange[0];
                    var supportSliceHeightsWithinRangeMax = supportSliceHeightsWithinRange[1];
                    foreach (var supportPointIndex in currentModelSupportPoints)
                    {
                        foreach (var supportPointValue in supportPointIndex.Value.Keys)
                        {
                            if (supportPointValue.SliceHeight <= sliceHeight && supportPointValue.LastSupportSliceHeight >= supportSliceHeightsWithinRangeMin)
                            {
                                var supportSlicePointAsIntPoint = new IntPoint(supportPointValue.TopPoint);
                                if (!this.AddedSupportPointsByLayer[sliceHeight].ContainsKey(supportSlicePointAsIntPoint))
                                {
                                    var supportConePoint2 = new MagsAISurfaceIntersectionData();
                                    supportConePoint2.TopPoint               = supportSlicePointAsIntPoint;
                                    supportConePoint2.SliceHeight            = sliceHeight;
                                    supportConePoint2.OverhangDistanceFactor = firstSurfaceAngleDistanceFactor;
                                    supportConePoint2.ModelIntersection      = supportPointValue.ModelIntersection;
                                    supportConePoint2.LastSupportSliceHeight = supportPointValue.LastSupportSliceHeight;

                                    this.AddedSupportPointsByLayer[sliceHeight].Add(supportConePoint2.TopPoint, supportConePoint2);
                                }
                            }
                        }
                    }


                    //combine all previous found points
                    supportedLayerAsPolyTree = new PolyTree();
                    if (AddedSupportPointsByLayer.ContainsKey(sliceHeight))
                    {
                        var supportCircles = new List <List <IntPoint> >();
                        foreach (var addedSupportPointByLayer in AddedSupportPointsByLayer[sliceHeight].Values)
                        {
                            var outlineCirclePoints = MagsAIEngine.ConvertSupportPointsToCircles(addedSupportPointByLayer.TopPoint, selectedMaterialProfile.SupportOverhangDistance);
                            supportCircles.Add(outlineCirclePoints);
                            var outlineCirclePolygon = MagsAIEngine.MergeSupportCircles(new List <List <IntPoint> >()
                            {
                                outlineCirclePoints
                            });
                            var intersectedPolygons = ContourHelper.IntersectModelSliceLayer(ModelContours[sliceHeight], outlineCirclePolygon);

                            var intersectedPolygonFound = false;
                            foreach (var intersectedPolygon in intersectedPolygons._allPolys.Where(s => !s.IsHole))
                            {
                                if (ContourHelper.PointExistsInNotHolePolygon(intersectedPolygon, addedSupportPointByLayer.TopPoint))
                                {
                                    supportedLayerAsPolyTree._allPolys.Add(intersectedPolygon);
                                    break;
                                }
                            }

                            //check if intersected triangle is part of angle surface
                            if (!intersectedPolygonFound)
                            {
                                //check if triangle index is in surface
                                var pointFound = false;
                                foreach (var surfaceConnection in surface.Keys)
                                {
                                    if (addedSupportPointByLayer.ModelIntersection != null)
                                    {
                                        if (surfaceConnection.ArrayIndex == addedSupportPointByLayer.ModelIntersection.Index.ArrayIndex && surfaceConnection.TriangleIndex == addedSupportPointByLayer.ModelIntersection.Index.TriangleIndex)
                                        {
                                            foreach (var intersectedPolygon in intersectedPolygons._allPolys.Where(s => !s.IsHole))
                                            {
                                                supportedLayerAsPolyTree._allPolys.Add(intersectedPolygon);
                                                pointFound = true;
                                            }
                                            break;
                                        }
                                    }
                                }

                                if (!pointFound)
                                {
                                }
                            }
                        }

                        // TriangleHelper.SavePolyNodesContourToPng(ModelContours[sliceHeight]._allPolys, surface.Id.ToString("00") + "-" + sliceHeight.ToString("0.00") + "-" + overhangFactor.ToString(".00") + "-model");
//                        TriangleHelper.SavePolyNodesContourToPng(intersectedPolygons._allPolys, surface.Id.ToString("00") + "-" + sliceHeight.ToString("0.00") + "-" + overhangFactor.ToString(".00") + "-intersected");


                        //TriangleHelper.SavePolyNodesContourToPng(MagsAIEngine.MergeSupportCircles(supportCircles)._allPolys, surface.Id.ToString("00") + "-" + sliceHeight.ToString("0.00") + "-" + overhangFactor.ToString(".00") + "-supportcircles");

                        supportedLayerAsPolyTree = UnionModelSliceLayer(new PolyTree(), supportedLayerAsPolyTree);

                        //TriangleHelper.SavePolyNodesContourToPng(supportedLayerAsPolyTree._allPolys, surface.Id.ToString("00") + "-" + sliceHeight.ToString("0.00") + "-" + overhangFactor.ToString(".00") + "-supportedlayer");
                    }


                    //  this.SupportedLayers.Add(sliceHeight, supportedLayerAsPolyTree);
                    var unsupportedLayer = DifferenceModelSliceLayer(sliceContours, supportedLayerAsPolyTree);
                    ////if (sliceHeight >= 15f && sliceHeight <= 16f)
                    //    {
                    foreach (var verticalSurface in stlModel.Triangles.MagsAIVerticalSurfaces)
                    {
                        verticalSurface.UpdateBoundries(stlModel.Triangles);
                        if (verticalSurface.BottomPoint <= this.BottomPoint)
                        {
                            foreach (var workingSliceHeight in verticalSurface.VerticalSurfaceModelPolygons.Keys)
                            {
                                if (workingSliceHeight >= previousSliceHeight - 0.4f && workingSliceHeight <= sliceHeight)
                                {
                                    //TriangleHelper.SavePolyNodesContourToPng(verticalSurface.VerticalSurfaceModelPolygons[workingSliceHeight]._allPolys, sliceHeight.ToString("0.00") + "-" + workingSliceHeight + "-subtract-vertical-contour");

                                    unsupportedLayer = DifferenceModelSliceLayer(unsupportedLayer, verticalSurface.VerticalSurfaceModelPolygons[workingSliceHeight]);
                                    // TriangleHelper.SavePolyNodesContourToPng(unsupportedLayer._allPolys, sliceHeight.ToString("0.00") + "-unsupported-vertical-contour");
                                }
                            }
                        }
                    }
                    //}

                    //remove supportedLayer from current diff layer and previous found support points
                    //TriangleHelper.SavePolyNodesContourToPng(unsupportedLayer._allPolys, surface.Id.ToString("00") + "-" + sliceHeight.ToString(".00") + "-" + overhangFactor.ToString(".00") + "-surface-unsupported");
                    if (unsupportedLayer._allPolys.Count > 0)
                    {
                        while (unsupportedLayer._allPolys.Where(s => !s.IsHole).Count() > 0)
                        {
                            var skippedUnsupportedLayerPolyNodes = new List <PolyNode>();
                            foreach (var unsupportLayerHole in unsupportedLayer._allPolys.Where(s => s.IsHole))
                            {
                                skippedUnsupportedLayerPolyNodes.Add(unsupportLayerHole);
                            }

                            foreach (var areaToSmallPolygon in unsupportedLayer._allPolys.Where(s => !s.IsHole))
                            {
                                if ((Clipper.Area(areaToSmallPolygon.Contour) / (CONTOURPOINT_TO_VECTORPOINT_FACTOR * CONTOURPOINT_TO_VECTORPOINT_FACTOR)) < 2)
                                {
                                    skippedUnsupportedLayerPolyNodes.Add(areaToSmallPolygon);
                                }
                            }

                            foreach (var removePolygon in skippedUnsupportedLayerPolyNodes)
                            {
                                unsupportedLayer._allPolys.Remove(removePolygon);
                            }

                            skippedUnsupportedLayerPolyNodes.Clear();

                            foreach (var unsupportedLayerPolyNode in unsupportedLayer._allPolys)
                            {
                                var contourPolyTree = new PolyTree();
                                contourPolyTree._allPolys.Add(unsupportedLayerPolyNode);
                                //TriangleHelper.SavePolyNodesContourToPng(contourPolyTree._allPolys, "b");
                                var supportConeIntersections = MagsAIEngine.CalcContourSupportStructure(contourPolyTree, null, null, selectedMaterialProfile, sliceHeight, this, true, false);
                                if (supportConeIntersections.Count > 0)
                                {
                                    var supportConeIntersectionPolyTree = new PolyTree();
                                    foreach (var supportConeIntersection in supportConeIntersections)
                                    {
                                        if (supportConeIntersection.LowestPoints.Count == 0)
                                        {
                                            skippedUnsupportedLayerPolyNodes.Add(unsupportedLayerPolyNode);
                                        }
                                        else
                                        {
                                            var k = 0;
                                            foreach (var supportConeIntersectionPoint in supportConeIntersection.LowestPoints)
                                            {
                                                var supportConeIntersectionPointAsIntPoint = supportConeIntersectionPoint.Point;
                                                supportConeIntersectionPointAsIntPoint.Z = (int)(sliceHeight * CONTOURPOINT_TO_VECTORPOINT_FACTOR);
                                                var addedSupportPoint = new MagsAISurfaceIntersectionData()
                                                {
                                                    TopPoint = supportConeIntersectionPointAsIntPoint, SliceHeight = sliceHeight
                                                };
                                                addedSupportPoint.OverhangDistanceFactor = selectedMaterialProfile.SupportOverhangDistance * overhangFactor;
                                                var outlineCirclePoints  = MagsAIEngine.ConvertSupportPointsToCircles(supportConeIntersectionPointAsIntPoint, selectedMaterialProfile.SupportOverhangDistance * overhangFactor);
                                                var outlineCirclePolygon = MagsAIEngine.MergeSupportCircles(new List <List <IntPoint> >()
                                                {
                                                    outlineCirclePoints
                                                });


                                                var intersectedPolygons    = ContourHelper.IntersectModelSliceLayer(ModelContours[sliceHeight], outlineCirclePolygon);
                                                var intersectionPointFound = false;

                                                foreach (var intersectedPolygon in intersectedPolygons._allPolys.Where(s => !s.IsHole))
                                                {
                                                    if (ContourHelper.PointExistsInNotHolePolygon(intersectedPolygon, addedSupportPoint.TopPoint))
                                                    {
                                                        supportConeIntersectionPolyTree._allPolys.Add(intersectedPolygon);
                                                        intersectionPointFound = true;
                                                    }
                                                }

                                                if (!intersectionPointFound)
                                                {
                                                    foreach (var intersectedPolygon in intersectedPolygons._allPolys.Where(s => !s.IsHole))
                                                    {
                                                        supportConeIntersectionPolyTree._allPolys.Add(intersectedPolygon);
                                                    }
                                                }

//                                                TriangleHelper.SavePolyNodesContourToPng(outlineCirclePolygon._allPolys, sliceHeight.ToString("0.00") + "-" + k.ToString());

                                                addedSupportPoint.UpdateLastSupportedHeight(stlModel);
                                                addedSupportPoint.UpdateTriangleReference(stlModel);
                                                if (!this.AddedSupportPoints.ContainsKey(addedSupportPoint.TopPoint))
                                                {
                                                    this.AddedSupportPoints.Add(addedSupportPoint.TopPoint, addedSupportPoint);
                                                }

                                                if (!this.AddedSupportPointsByLayer[sliceHeight].ContainsKey(addedSupportPoint.TopPoint))
                                                {
                                                    addedSupportPoint.UnsupportedContour = true;
                                                    this.AddedSupportPointsByLayer[sliceHeight].Add(addedSupportPoint.TopPoint, addedSupportPoint);
                                                }


                                                k++;
                                            }
                                        }

                                        if (supportConeIntersectionPolyTree._allPolys.Count > 0)
                                        {
                                            unsupportedLayer = DifferenceModelSliceLayer(unsupportedLayer, supportConeIntersectionPolyTree);
                                            // TriangleHelper.SavePolyNodesContourToPng(unsupportedLayer._allPolys, "s");

                                            break;
                                        }
                                    }
                                }
                            }

                            if (skippedUnsupportedLayerPolyNodes.Count > 0)
                            {
                                foreach (var skippedUnsuppertedLayerPolyNode in skippedUnsupportedLayerPolyNodes)
                                {
                                    unsupportedLayer._allPolys.Remove(skippedUnsuppertedLayerPolyNode);
                                }
                            }
                        }
                    }

                    previousSliceHeight = sliceHeight;
                }


                if (previousSliceHeight == float.MaxValue)
                {
                    previousSliceHeight = sliceHeight;
                }
            }

            return(this.AddedSupportPoints);
        }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PSSupportProfile" /> class.
 /// </summary>
 /// <param name="profile">The base support profile for this instance.</param>
 public PSSupportProfile(SupportProfile profile)
 {
     this.CopyFrom(profile);
 }
示例#14
0
        public static List <MagsAIPolyLines> FromListOfModelIntersectionsUsingPolyLines(float sliceHeight, List <SlicePolyLine3D> intersectionPoints, SupportProfile selectedMaterialProfile, AtumPrinter selectedPrinter, bool usePixelsAsValues = true)
        {
            var result = new List <MagsAIPolyLines>();

            var intersectionLines = VectorHelper.Get2dLinesAsPixels(intersectionPoints, selectedPrinter);

            if (intersectionLines.Count > 0)
            {
                //convert intersectionLines to fast indexes
                var intersectionLookUp = new Dictionary <Vector3Class, List <Line3D> >();
                foreach (var intersectionPoint in intersectionLines)
                {
                    if (!intersectionLookUp.ContainsKey(intersectionPoint.StartPoint))
                    {
                        intersectionLookUp.Add(intersectionPoint.StartPoint, new List <Line3D>());
                    }
                    intersectionLookUp[intersectionPoint.StartPoint].Add(intersectionPoint);

                    if (!intersectionLookUp.ContainsKey(intersectionPoint.EndPoint))
                    {
                        intersectionLookUp.Add(intersectionPoint.EndPoint, new List <Line3D>());
                    }
                    intersectionLookUp[intersectionPoint.EndPoint].Add(intersectionPoint);
                }

                var polygonTriangleIndexes = new TriangeConnectionsIndexed();

                var p1          = intersectionLookUp.Keys.First();
                var currentLine = intersectionLookUp[p1].First();
                var p2          = currentLine.StartPoint == p1 ? currentLine.EndPoint : currentLine.StartPoint;

                RemoveFromIntersectionLookup(p1, p2, currentLine, intersectionLookUp);

                //if (intersectionLookUp.ContainsKey(p1))
                //{
                //    intersectionLookUp[p1].Remove(currentLine);
                //    if (intersectionLookUp[p1].Count == 0)
                //    {
                //        intersectionLookUp.Remove(p1);
                //    }
                //}

                //if (intersectionLookUp.ContainsKey(p2))
                //{
                //    intersectionLookUp[p2].Remove(currentLine);
                //    if (intersectionLookUp[p2].Count == 0)
                //    {
                //        intersectionLookUp.Remove(p2);
                //    }
                //}

                var polyLine = new MagsAIPolyLines();
                polyLine.Add(new MagsAIPolyLine()
                {
                    P1 = currentLine.StartPoint, P2 = currentLine.EndPoint, Normal = currentLine.Normal
                });

                while (intersectionLookUp.Count > 0)
                {
                    //find neighbors using P1 and P2
                    Line3D neightborP1 = null;
                    if (intersectionLookUp.ContainsKey(p1))
                    {
                        neightborP1 = intersectionLookUp[p1].FirstOrDefault();
                        if (neightborP1 != null)
                        {
                            polyLine.Insert(0, new MagsAIPolyLine()
                            {
                                P1 = neightborP1.StartPoint == p1 ? neightborP1.EndPoint : neightborP1.StartPoint, P2 = p1, Normal = neightborP1.Normal
                            });
                            p1 = neightborP1.StartPoint == p1 ? neightborP1.EndPoint : neightborP1.StartPoint;

                            RemoveFromIntersectionLookup(neightborP1.StartPoint, neightborP1.EndPoint, neightborP1, intersectionLookUp);
                        }
                    }

                    Line3D neightborP2 = null;
                    if (intersectionLookUp.ContainsKey(p2))
                    {
                        neightborP2 = intersectionLookUp[p2].FirstOrDefault();

                        if (neightborP2 != null)
                        {
                            polyLine.Add(new MagsAIPolyLine()
                            {
                                P1 = p2, P2 = neightborP2.StartPoint == p2 ? neightborP2.EndPoint : neightborP2.StartPoint, Normal = neightborP2.Normal
                            });
                            p2 = neightborP2.StartPoint == p2 ? neightborP2.EndPoint : neightborP2.StartPoint;

                            RemoveFromIntersectionLookup(neightborP2.StartPoint, neightborP2.EndPoint, neightborP2, intersectionLookUp);
                        }
                    }

                    //no lines found start new polyline
                    if (neightborP1 == null && neightborP2 == null && polyLine.Count > 0)
                    {
                        if (polyLine.Count > 1)
                        {
                            if (polyLine[0].P1 == polyLine.Last().P1&& polyLine[0].P2 == polyLine.Last().P2)
                            {
                                polyLine.RemoveAt(0);
                                polyLine.ClosedLine = true;
                            }

                            if (polyLine[0].P1 == polyLine.Last().P2)
                            {
                                polyLine.ClosedLine = true;
                            }
                        }

                        if (polyLine.Length > 5f)
                        {
                            result.Add(polyLine);
                        }

                        polyLine = new MagsAIPolyLines();

                        if (intersectionLookUp.Count > 0)
                        {
                            p1          = intersectionLookUp.Keys.First();
                            currentLine = intersectionLookUp[p1].First();
                            p2          = currentLine.StartPoint == p1 ? currentLine.EndPoint : currentLine.StartPoint;

                            RemoveFromIntersectionLookup(p1, p2, currentLine, intersectionLookUp);

                            polyLine.Add(new MagsAIPolyLine()
                            {
                                P1 = currentLine.StartPoint, P2 = currentLine.EndPoint, Normal = currentLine.Normal
                            });
                        }
                    }
                }

                if (polyLine.Count > 0)
                {
                    if (polyLine.Count > 1)
                    {
                        if (polyLine[0].P1 == polyLine.Last().P1&& polyLine[0].P2 == polyLine.Last().P2)
                        {
                            polyLine.RemoveAt(0);
                            polyLine.ClosedLine = true;
                        }

                        if (polyLine[0].P1 == polyLine.Last().P2)
                        {
                            polyLine.ClosedLine = true;
                        }
                    }

                    //check length of polyLine
                    if (polyLine.Length > 5f)
                    {
                        result.Add(polyLine);
                    }
                }
            }

            var objectIndex = 0;

            foreach (var r in result)
            {
                r.CalcPolyNode(selectedMaterialProfile, selectedPrinter, sliceHeight, objectIndex);
                objectIndex++;
            }

            return(result);
        }
示例#15
0
        internal void CalcPolyNode(SupportProfile selectedMaterialProfile, AtumPrinter selectedPrinter, float sliceHeight, int objectIndex)
        {
            this.PolyTree = new PolyTree();
            var polygonPoints = new List <IntPoint>();

            foreach (var polyLinePart in this)
            {
                var tStart = (polyLinePart.P1 - new Vector3Class(selectedPrinter.ProjectorResolutionX / 2, selectedPrinter.ProjectorResolutionY / 2, 0)) / 10f;
                tStart -= new Vector3Class(0.1f, 0.1f, 0);
                DebugPoints.Add(tStart);
                polygonPoints.Add(new IntPoint(tStart + new Vector3Class(0, 0, sliceHeight)));
            }

            //add the end of the line
            var tEnd = (this.Last().P2 - new Vector3Class(selectedPrinter.ProjectorResolutionX / 2, selectedPrinter.ProjectorResolutionY / 2, 0)) / 10f;

            tEnd -= new Vector3Class(0.1f, 0.1f, 0);
            polygonPoints.Add(new IntPoint(tEnd));

            //when not closed use normals to create offset points
            if (!ClosedLine)
            {
                this.Reverse();
                //  this.Reverse();
                var normalVector = new Vector3Class();
                foreach (var polyLinePart in this)
                {
                    normalVector  += polyLinePart.Normal;
                    normalVector.Z = 0;
                    normalVector.Normalize();
                    normalVector *= selectedMaterialProfile.SupportOverhangDistance / 2;

                    //do point offset
                    var tPoint = normalVector + ((polyLinePart.P1 - new Vector3Class(selectedPrinter.ProjectorResolutionX / 2, selectedPrinter.ProjectorResolutionY / 2, 0)) / 10f);
                    tPoint -= new Vector3Class(0.1f, 0.1f, 0);
                    DebugPoints.Add(tPoint + new Vector3Class(0, 0, sliceHeight));
                    polygonPoints.Add(new IntPoint(tPoint));

                    normalVector = polyLinePart.Normal;
                }

                var polyTreeOffset = new PolyTree();
                var polyNode       = new PolyNode();
                polyNode.m_polygon = polygonPoints;
                polyTreeOffset._allPolys.Add(polyNode);

                var c = new Clipper();
                c.AddPath(polyTreeOffset._allPolys[0].Contour, PolyType.ptClip, true);
                c.AddPath(new List <IntPoint>(), PolyType.ptSubject, true);

                c.Execute(ClipType.ctXor, this.PolyTree, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);

                //if (sliceHeight >=13 && sliceHeight <=15f)
                // TriangleHelper.SavePolyNodesContourToPng(this.PolyTree._allPolys, sliceHeight.ToString("0.00") + "-"  + objectIndex.ToString() + "-t2");
            }
            else
            {
                var polyTreeOffset = new PolyTree();
                var polyNode       = new PolyNode();
                polyNode.m_polygon = polygonPoints;
                polyTreeOffset._allPolys.Add(polyNode);
                polyTreeOffset = MagsAIEngine.ClipperOffset(polyTreeOffset, selectedMaterialProfile.SupportOverhangDistance / 2);

                if (polyTreeOffset._allPolys.Count > 0)
                {
                    var c = new Clipper();
                    c.AddPath(polygonPoints, PolyType.ptClip, true);
                    c.AddPath(polyTreeOffset._allPolys[0].Contour, PolyType.ptClip, true);
                    c.AddPath(new List <IntPoint>(), PolyType.ptSubject, true);

                    c.Execute(ClipType.ctXor, this.PolyTree, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
                }
            }
        }
        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");
        }
示例#17
0
        public void UpdateInterlinkConnections(SupportProfile supportProfile)
        {
            this.InterlinkDebugPoints = new List <Vector3>();
            this.InterlinkConnections = new SortedDictionary <float, List <SupportConeV2InterlinkConnection> >();

            //find nearest XY supportcones
            var supportConeDistances = new SortedDictionary <float, List <SupportConeV2> >();

            foreach (var supportCone in this.Model.SupportStructure.OfType <SupportConeV2>())
            {
                if (supportCone != null && supportCone.RefPointCSegment != this.RefPointCSegment)
                {
                    var supportConeDistanceXY = (this.RefPointCSegment.Xy - supportCone.RefPointCSegment.Xy).Length;
                    if (!supportConeDistances.ContainsKey(supportConeDistanceXY))
                    {
                        supportConeDistances.Add(supportConeDistanceXY, new List <SupportConeV2>());
                    }

                    supportConeDistances[supportConeDistanceXY].Add(supportCone);
                }
            }

            //check if there are support cones within the range of > 3x middle radius && distance < 5
            var supportConesWithinXYRange = new SortedDictionary <float, List <SupportConeV2> >();

            foreach (var xyDistance in supportConeDistances.Keys)
            {
                if (xyDistance > 2 * this.MiddleRadius && xyDistance < 5)
                {
                    if (!supportConesWithinXYRange.ContainsKey(xyDistance))
                    {
                        supportConesWithinXYRange.Add(xyDistance, new List <SupportConeV2>());
                    }

                    supportConesWithinXYRange[xyDistance].AddRange(supportConeDistances[xyDistance]);
                }
            }

            //create interlink at each intermitted height
            var supportConeHeight = this.RefPointCSegment.Z;
            var interlinkedSupportConesWithinRanges = new List <SupportConeV2>();

            for (var intermittedHeight = this.BottomHeight + supportProfile.SupportIntermittedConnectionHeight; intermittedHeight < supportConeHeight; intermittedHeight += supportProfile.SupportIntermittedConnectionHeight)
            {
                var interlinkSupportCones = new List <SupportConeV2>();

                //find first support cone that is high enough
                foreach (var supportConesWithinXYValues in supportConesWithinXYRange)
                {
                    foreach (var supportCone in supportConesWithinXYValues.Value)
                    {
                        if (interlinkSupportCones.Count == 2)
                        {
                            break;
                        }

                        if (supportCone != null)
                        {
                            if (supportCone.RefPointCSegment.Z - (supportProfile.SupportIntermittedConnectionHeight * supportConesWithinXYValues.Key) > intermittedHeight)
                            {
                                //check if support cone is within range
                                if (interlinkSupportCones.Count == 1)
                                {
                                    if (IsSupportConeWithinXYAngleRange(interlinkSupportCones.First(), supportCone, 120, 240))
                                    {
                                        interlinkSupportCones.Add(supportCone);

                                        if (!interlinkedSupportConesWithinRanges.Contains(supportCone))
                                        {
                                            interlinkedSupportConesWithinRanges.Add(supportCone);
                                        }

                                        //if ((supportCone.RefPointCSegment.Xy - interlinkSupportCones[0].RefPointCSegment.Xy).Length < 1.1)
                                        //{
                                        //    continue;
                                        //}
                                    }

                                    if (interlinkSupportCones.Count == 2)
                                    {
                                        break;
                                    }
                                }
                                else if (interlinkSupportCones.Count == 0)
                                {
                                    // no support cones then add first found
                                    if ((supportCone.RefPointCSegment.Xy - this.RefPointCSegment.Xy).Length < (supportProfile.SupportOverhangDistance * 1.1))
                                    {
                                        interlinkSupportCones.Add(supportCone);

                                        if (!interlinkedSupportConesWithinRanges.Contains(supportCone))
                                        {
                                            interlinkedSupportConesWithinRanges.Add(supportCone);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //create connections to interlinked support cones
                var startPoint = new Vector3Class(this.RefPointCSegment.X, this.RefPointCSegment.Y, intermittedHeight);

                foreach (var interLinkSupportCone in interlinkSupportCones)
                {
                    var endPoint   = interLinkSupportCone.RefPointCSegment;
                    var xyDistance = endPoint - startPoint;
                    xyDistance.Z = 0;
                    endPoint.Z   = intermittedHeight + (supportProfile.SupportIntermittedConnectionHeight * xyDistance.Length);

                    if (!this.InterlinkConnections.ContainsKey(intermittedHeight))
                    {
                        this.InterlinkConnections.Add(intermittedHeight, new List <SupportConeV2InterlinkConnection>());
                    }

                    this.InterlinkConnections[intermittedHeight].Add(new SupportConeV2InterlinkConnection(0.1f, startPoint, endPoint, Color.Yellow));
                }
            }

            var t = new List <SupportConeV2InterlinkConnection>();

            foreach (var v in this.InterlinkConnections.Values)
            {
                t.AddRange(v);
            }
            if (t.Count < 2)
            {
                var g = 0f;
                //this.InterlinkConnections.Add(0, new List<SupportConeV2InterlinkConnection>());
                //this.InterlinkConnections[0].Add(new SupportConeV2InterlinkConnection(0.1f, ( this.RefPointCSegment), (this.RefPointCSegment) + new Vector3Class(5,0,0), Color.Yellow));

                if (t.Count == 1)
                {
                    //create new support cone within the boundries of first and second support cone
                    CreateSubSupportConeWithinRange(interlinkedSupportConesWithinRanges.First(), supportProfile, 45);
                }
                else if (t.Count == 0)
                {
                    CreateSubSupportConeWithinRange(supportProfile, 45);
                    CreateSubSupportConeWithinRange(supportProfile, -45);
                    CreateSubSupportConeWithinRange(supportProfile, 135);
                    CreateSubSupportConeWithinRange(supportProfile, -135);
                }
            }

            //update opengl bindings using triangle array 1 index
            t.Clear();
            foreach (var v in this.InterlinkConnections.Values)
            {
                t.AddRange(v);
            }

            foreach (var interlinkConnection in t)
            {
                if (interlinkConnection != null)
                {
                    this.Triangles[0].AddRange(interlinkConnection.Triangles[0]);
                }
            }


            this.UpdateBinding();
        }
示例#18
0
        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;
        }