/******************************************************************************
*
* The MIT License (MIT)
*
* LiquidVolumeFX.MIConvexHull, Copyright (c) 2015 David Sehnal, Matthew Campbell
*
* 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.
*
*****************************************************************************/
using System.Collections.Generic;
using System.Linq;
namespace LiquidVolumeFX.MIConvexHull
{
///
/// Simple interface to unify different types of triangulations in the future.
///
/// The type of the t vertex.
/// The type of the t cell.
public interface ITriangulation
where TCell : TriangulationCell, new()
where TVertex : IVertex
{
///
/// Triangulation simplexes. For 2D - triangles, 3D - tetrahedrons, etc ...
///
/// The cells.
IEnumerable Cells { get; }
}
///
/// Factory class for creating triangulations.
///
public static class Triangulation
{
///
/// Creates the Delaunay triangulation of the input data.
///
/// The type of the t vertex.
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// ITriangulation<TVertex, DefaultTriangulationCell<TVertex>>.
public static ITriangulation> CreateDelaunay(
IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
where TVertex : IVertex
{
return DelaunayTriangulation>.Create(data, PlaneDistanceTolerance);
}
///
/// Creates the Delaunay triangulation of the input data.
///
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// ITriangulation<DefaultVertex, DefaultTriangulationCell<DefaultVertex>>.
public static ITriangulation> CreateDelaunay(
IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
{
var points = data.Select(p => new DefaultVertex { Position = p }).ToList();
return DelaunayTriangulation>.Create(points, PlaneDistanceTolerance);
}
///
/// Creates the Delaunay triangulation of the input data.
///
/// The type of the t vertex.
/// The type of the t face.
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// ITriangulation<TVertex, TFace>.
public static ITriangulation CreateDelaunay(IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
where TVertex : IVertex
where TFace : TriangulationCell, new()
{
return DelaunayTriangulation.Create(data, PlaneDistanceTolerance);
}
///
/// Create the voronoi mesh.
///
/// The type of the t vertex.
/// The type of the t cell.
/// The type of the t edge.
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// VoronoiMesh<TVertex, TCell, TEdge>.
public static VoronoiMesh CreateVoronoi(IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
where TCell : TriangulationCell, new()
where TVertex : IVertex
where TEdge : VoronoiEdge, new()
{
return VoronoiMesh.Create(data, PlaneDistanceTolerance);
}
///
/// Create the voronoi mesh.
///
/// The type of the t vertex.
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// VoronoiMesh<TVertex, DefaultTriangulationCell<TVertex>, VoronoiEdge<TVertex, DefaultTriangulationCell<TVertex>>>.
public static
VoronoiMesh
, VoronoiEdge>>
CreateVoronoi(IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
where TVertex : IVertex
{
return
VoronoiMesh
, VoronoiEdge>
>.Create(data, PlaneDistanceTolerance);
}
///
/// Create the voronoi mesh.
///
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// VoronoiMesh<DefaultVertex, DefaultTriangulationCell<DefaultVertex>, VoronoiEdge<DefaultVertex, DefaultTriangulationCell<DefaultVertex>>>.
public static
VoronoiMesh
,
VoronoiEdge>>
CreateVoronoi(IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
{
var points = data.Select(p => new DefaultVertex { Position = p.ToArray() }).ToList();
return
VoronoiMesh
,
VoronoiEdge>>.Create(points, PlaneDistanceTolerance);
}
///
/// Create the voronoi mesh.
///
/// The type of the t vertex.
/// The type of the t cell.
/// The data.
/// The plane distance tolerance (default is 1e-10). If too high, points
/// will be missed. If too low, the algorithm may break. Only adjust if you notice problems.
/// VoronoiMesh<TVertex, TCell, VoronoiEdge<TVertex, TCell>>.
public static VoronoiMesh> CreateVoronoi(
IList data,
double PlaneDistanceTolerance = Constants.DefaultPlaneDistanceTolerance)
where TVertex : IVertex
where TCell : TriangulationCell, new()
{
return VoronoiMesh>.Create(data, PlaneDistanceTolerance);
}
}
}