private void InitializeData(ConvexHullComputationConfig config) { this.UnprocessedFaces = new FaceList(); this.ConvexFaces = new IndexBuffer(); this.FacePool = new ConvexFaceInternal[(this.Dimension + 1) * 10]; this.AffectedFaceFlags = new bool[(this.Dimension + 1) * 10]; this.ObjectManager = new MIConvexHull.ObjectManager(this); this.Center = new double[this.Dimension]; this.TraverseStack = new IndexBuffer(); this.UpdateBuffer = new int[this.Dimension]; this.UpdateIndices = new int[this.Dimension]; this.EmptyBuffer = new IndexBuffer(); this.AffectedFaceBuffer = new IndexBuffer(); this.ConeFaceBuffer = new SimpleList <DeferredFace>(); this.SingularVertices = new HashSet <int>(); this.BeyondBuffer = new IndexBuffer(); this.ConnectorTable = new ConnectorList[0x7e1]; for (int i = 0; i < 0x7e1; i++) { this.ConnectorTable[i] = new ConnectorList(); } this.VertexMarks = new bool[this.Vertices.Length]; this.InitializePositions(config); this.MathHelper = new MIConvexHull.MathHelper(this.Dimension, this.Positions); }
/// <summary> /// Initialize buffers and lists. /// </summary> /// <param name="config"></param> void InitializeData(ConvexHullComputationConfig config) { ConvexHull = new IndexBuffer(); UnprocessedFaces = new FaceList(); ConvexFaces = new IndexBuffer(); FacePool = new ConvexFaceInternal[(Dimension + 1) * 10]; // must be initialized before object manager AffectedFaceFlags = new bool[(Dimension + 1) * 10]; ObjectManager = new MIConvexHull.ObjectManager(this); Center = new double[Dimension]; TraverseStack = new IndexBuffer(); UpdateBuffer = new int[Dimension]; UpdateIndices = new int[Dimension]; EmptyBuffer = new IndexBuffer(); AffectedFaceBuffer = new IndexBuffer(); ConeFaceBuffer = new SimpleList <DeferredFace>(); SingularVertices = new HashSet <int>(); BeyondBuffer = new IndexBuffer(); ConnectorTable = new ConnectorList[ConnectorTableSize]; for (int i = 0; i < ConnectorTableSize; i++) { ConnectorTable[i] = new ConnectorList(); } VertexMarks = new bool[Vertices.Length]; VertexAdded = new bool[Vertices.Length]; InitializePositions(config); MathHelper = new MIConvexHull.MathHelper(Dimension, Positions); }
public static ConvexHull <TVertex, TFace> Create(IList <TVertex> data, ConvexHullComputationConfig config) { if (data == null) { throw new ArgumentNullException("data"); } return(ConvexHullInternal.GetConvexHull <TVertex, TFace>(data, config)); }
/// <summary> /// Wraps the vertices and determines the dimension if it's unknown. /// </summary> /// <param name="vertices"></param> /// <param name="lift"></param> /// <param name="config"></param> private ConvexHullInternal(IVertex[] vertices, bool lift, ConvexHullComputationConfig config) { if (config.PointTranslationType != PointTranslationType.None && config.PointTranslationGenerator == null) { throw new InvalidOperationException("PointTranslationGenerator cannot be null if PointTranslationType is enabled."); } this.IsLifted = lift; this.Vertices = vertices; this.PlaneDistanceTolerance = config.PlaneDistanceTolerance; Dimension = DetermineDimension(); if (Dimension < 2) throw new InvalidOperationException("Dimension of the input must be 2 or greater."); if (lift) Dimension++; InitializeData(config); }
private ConvexHullInternal(IVertex[] vertices, bool lift, ConvexHullComputationConfig config) { if ((config.PointTranslationType != PointTranslationType.None) && (config.PointTranslationGenerator == null)) { throw new InvalidOperationException("PointTranslationGenerator cannot be null if PointTranslationType is enabled."); } this.IsLifted = lift; this.Vertices = vertices; this.PlaneDistanceTolerance = config.PlaneDistanceTolerance; this.Dimension = this.DetermineDimension(); if (this.Dimension < 2) { throw new InvalidOperationException("Dimension of the input must be 2 or greater."); } if (lift) { this.Dimension++; } this.InitializeData(config); }
/// <summary> /// Initialize the vertex positions based on the translation type from config. /// </summary> /// <param name="config"></param> void InitializePositions(ConvexHullComputationConfig config) { Positions = new double[Vertices.Length * Dimension]; int index = 0; if (IsLifted) { var origDim = Dimension - 1; var tf = config.PointTranslationGenerator; switch (config.PointTranslationType) { case PointTranslationType.None: foreach (var v in Vertices) { double lifted = 0.0; for (int i = 0; i < origDim; i++) { var t = v.Position[i]; Positions[index++] = t; lifted += t * t; } Positions[index++] = lifted; } break; case PointTranslationType.TranslateInternal: foreach (var v in Vertices) { double lifted = 0.0; for (int i = 0; i < origDim; i++) { var t = v.Position[i] + tf(); Positions[index++] = t; lifted += t * t; } Positions[index++] = lifted; } break; } } else { var tf = config.PointTranslationGenerator; switch (config.PointTranslationType) { case PointTranslationType.None: foreach (var v in Vertices) { for (int i = 0; i < Dimension; i++) Positions[index++] = v.Position[i]; } break; case PointTranslationType.TranslateInternal: foreach (var v in Vertices) { for (int i = 0; i < Dimension; i++) Positions[index++] = v.Position[i] + tf(); } break; } } }
/// <summary> /// Initialize buffers and lists. /// </summary> /// <param name="config"></param> void InitializeData(ConvexHullComputationConfig config) { UnprocessedFaces = new FaceList(); ConvexFaces = new IndexBuffer(); FacePool = new ConvexFaceInternal[(Dimension + 1) * 10]; // must be initialized before object manager AffectedFaceFlags = new bool[(Dimension + 1) * 10]; ObjectManager = new MIConvexHull.ObjectManager(this); Center = new double[Dimension]; TraverseStack = new IndexBuffer(); UpdateBuffer = new int[Dimension]; UpdateIndices = new int[Dimension]; EmptyBuffer = new IndexBuffer(); AffectedFaceBuffer = new IndexBuffer(); ConeFaceBuffer = new SimpleList<DeferredFace>(); SingularVertices = new HashSet<int>(); BeyondBuffer = new IndexBuffer(); ConnectorTable = new ConnectorList[ConnectorTableSize]; for (int i = 0; i < ConnectorTableSize; i++) ConnectorTable[i] = new ConnectorList(); VertexMarks = new bool[Vertices.Length]; InitializePositions(config); MathHelper = new MIConvexHull.MathHelper(Dimension, Positions); }
public static ConvexHull <DefaultVertex, DefaultConvexFace <DefaultVertex> > Create(IList <double[]> data, ConvexHullComputationConfig config = null) { if (< > f__am$cache0 == null) {
/// <summary> /// Initialize the vertex positions based on the translation type from config. /// </summary> /// <param name="config"></param> void InitializePositions(ConvexHullComputationConfig config) { Positions = new double[Vertices.Length * Dimension]; int index = 0; if (IsLifted) { var origDim = Dimension - 1; var tf = config.PointTranslationGenerator; switch (config.PointTranslationType) { case PointTranslationType.None: foreach (var v in Vertices) { double lifted = 0.0; for (int i = 0; i < origDim; i++) { var t = v.Position[i]; Positions[index++] = t; lifted += t * t; } Positions[index++] = lifted; } break; case PointTranslationType.TranslateInternal: foreach (var v in Vertices) { double lifted = 0.0; for (int i = 0; i < origDim; i++) { var t = v.Position[i] + tf(); Positions[index++] = t; lifted += t * t; } Positions[index++] = lifted; } break; } } else { var tf = config.PointTranslationGenerator; switch (config.PointTranslationType) { case PointTranslationType.None: foreach (var v in Vertices) { for (int i = 0; i < Dimension; i++) { Positions[index++] = v.Position[i]; } } break; case PointTranslationType.TranslateInternal: foreach (var v in Vertices) { for (int i = 0; i < Dimension; i++) { Positions[index++] = v.Position[i] + tf(); } } break; } } }
private void InitializePositions(ConvexHullComputationConfig config) { this.Positions = new double[this.Vertices.Length * this.Dimension]; int num = 0; if (!this.IsLifted) { Func <double> pointTranslationGenerator = config.PointTranslationGenerator; PointTranslationType pointTranslationType = config.PointTranslationType; if (pointTranslationType == PointTranslationType.None) { IVertex[] vertices = this.Vertices; int index = 0; while (index < vertices.Length) { IVertex vertex3 = vertices[index]; int num12 = 0; while (true) { if (num12 >= this.Dimension) { index++; break; } this.Positions[num++] = vertex3.Position[num12]; num12++; } } } else if (pointTranslationType == PointTranslationType.TranslateInternal) { IVertex[] vertices = this.Vertices; int index = 0; while (index < vertices.Length) { IVertex vertex4 = vertices[index]; int num14 = 0; while (true) { if (num14 >= this.Dimension) { index++; break; } this.Positions[num++] = vertex4.Position[num14] + pointTranslationGenerator(); num14++; } } } } else { int num2 = this.Dimension - 1; Func <double> pointTranslationGenerator = config.PointTranslationGenerator; PointTranslationType pointTranslationType = config.PointTranslationType; if (pointTranslationType == PointTranslationType.None) { IVertex[] vertices = this.Vertices; int index = 0; while (index < vertices.Length) { IVertex vertex = vertices[index]; double num4 = 0.0; int num5 = 0; while (true) { if (num5 >= num2) { this.Positions[num++] = num4; index++; break; } double num6 = vertex.Position[num5]; this.Positions[num++] = num6; num4 += num6 * num6; num5++; } } } else if (pointTranslationType == PointTranslationType.TranslateInternal) { IVertex[] vertices = this.Vertices; int index = 0; while (index < vertices.Length) { IVertex vertex2 = vertices[index]; double num8 = 0.0; int num9 = 0; while (true) { if (num9 >= num2) { this.Positions[num++] = num8; index++; break; } double num10 = vertex2.Position[num9] + pointTranslationGenerator(); this.Positions[num++] = num10; num8 += num10 * num10; num9++; } } } } }
internal static ConvexHull <TVertex, TFace> GetConvexHull <TVertex, TFace>(IList <TVertex> data, ConvexHullComputationConfig config) where TVertex : IVertex where TFace : ConvexFace <TVertex, TFace>, new() { config ??= new ConvexHullComputationConfig(); IVertex[] vertices = new IVertex[data.Count]; for (int i = 0; i < data.Count; i++) { vertices[i] = data[i]; } ConvexHullInternal internal2 = new ConvexHullInternal(vertices, false, config); internal2.FindConvexHull(); return(new ConvexHull <TVertex, TFace> { Points = internal2.GetHullVertices <TVertex>(data), Faces = internal2.GetConvexFaces <TVertex, TFace>() }); }
/// public static ConvexHull <DefaultVertex, DefaultConvexFace <DefaultVertex> > Create(IList <double[]> data, ConvexHullComputationConfig config) { var points = data.Select(p => new DefaultVertex { Position = p.ToArray() }).ToList(); return(ConvexHull <DefaultVertex, DefaultConvexFace <DefaultVertex> > .Create(points, config)); }
/// public static ConvexHull <TVertex, DefaultConvexFace <TVertex> > Create <TVertex>(IList <TVertex> data, ConvexHullComputationConfig config) where TVertex : IVertex { return(ConvexHull <TVertex, DefaultConvexFace <TVertex> > .Create(data, config)); }
/// public static ConvexHull <TVertex, TFace> Create <TVertex, TFace>(IList <TVertex> data, ConvexHullComputationConfig config) where TVertex : IVertex where TFace : ConvexFace <TVertex, TFace>, new() { return(ConvexHull <TVertex, TFace> .Create(data, config)); }
/// <summary> /// This is called by the "ConvexHull" class. /// </summary> /// <typeparam name="TVertex"></typeparam> /// <typeparam name="TFace"></typeparam> /// <param name="data"></param> /// <param name="config">If null, default ConvexHullComputationConfig.GetDefault() is used.</param> /// <returns></returns> internal static ConvexHull <TVertex, TFace> GetConvexHull <TVertex, TFace>(IList <TVertex> data, ConvexHullComputationConfig config) where TFace : ConvexFace <TVertex, TFace>, new() where TVertex : IVertex { config = config ?? new ConvexHullComputationConfig(); var vertices = new IVertex[data.Count]; for (int i = 0; i < data.Count; i++) { vertices[i] = data[i]; } ConvexHullInternal ch = new ConvexHullInternal(vertices, false, config); ch.FindConvexHull(); var hull = new TVertex[ch.ConvexHull.Count]; for (int i = 0; i < hull.Length; i++) { hull[i] = (TVertex)ch.Vertices[ch.ConvexHull[i]]; } return(new ConvexHull <TVertex, TFace> { Points = hull, Faces = ch.GetConvexFaces <TVertex, TFace>() }); }