#region License /* MIT License Copyright(c) 2017-2018 Mattias Edlund Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #endregion using System; using Microsoft.Extensions.Logging; namespace MeshDecimator.Algorithms { /// /// A decimation algorithm. /// public abstract class DecimationAlgorithm { #region Delegates /// /// A callback for decimation status reports. /// /// The current iteration, starting at zero. /// The original count of triangles. /// The current count of triangles. /// The target count of triangles. public delegate void StatusReportCallback(int iteration, int originalTris, int currentTris, int targetTris); #endregion #region Fields private bool preserveBorders = false; private int maxVertexCount = 0; private bool verbose = false; private StatusReportCallback statusReportInvoker = null; #endregion #region Properties /// /// Gets or sets if borders should be kept. /// Default value: false /// [Obsolete("Use the 'DecimationAlgorithm.PreserveBorders' property instead.", false)] public bool KeepBorders { get { return preserveBorders; } set { preserveBorders = value; } } /// /// Gets or sets if borders should be preserved. /// Default value: false /// public bool PreserveBorders { get { return preserveBorders; } set { preserveBorders = value; } } /// /// Gets or sets if linked vertices should be kept. /// Default value: false /// [Obsolete("This feature has been removed, for more details why please read the readme.", true)] public bool KeepLinkedVertices { get { return false; } set { } } /// /// Gets or sets the maximum vertex count. Set to zero for no limitation. /// Default value: 0 (no limitation) /// public int MaxVertexCount { get { return maxVertexCount; } set { maxVertexCount = Math.MathHelper.Max(value, 0); } } /// /// Gets or sets if verbose information should be printed in the console. /// Default value: false /// public bool Verbose { get { return verbose; } set { verbose = value; } } /// /// Gets or sets the logger used for diagnostics. /// public ILogger? Logger { get; set; } #endregion #region Events /// /// An event for status reports for this algorithm. /// public event StatusReportCallback StatusReport { add { statusReportInvoker += value; } remove { statusReportInvoker -= value; } } #endregion #region Protected Methods /// /// Reports the current status of the decimation. /// /// The current iteration, starting at zero. /// The original count of triangles. /// The current count of triangles. /// The target count of triangles. protected void ReportStatus(int iteration, int originalTris, int currentTris, int targetTris) { var statusReportInvoker = this.statusReportInvoker; if (statusReportInvoker != null) { statusReportInvoker.Invoke(iteration, originalTris, currentTris, targetTris); } } #endregion #region Public Methods /// /// Initializes the algorithm with the original mesh. /// /// The mesh. public abstract void Initialize(Mesh mesh); /// /// Decimates the mesh. /// /// The target triangle count. public abstract void DecimateMesh(int targetTrisCount); /// /// Decimates the mesh without losing any quality. /// public abstract void DecimateMeshLossless(); /// /// Returns the resulting mesh. /// /// The resulting mesh. public abstract Mesh ToMesh(); #endregion } }