/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="ConvexHullAlgorithm" /> class. /// </summary> /// <param name="vertices">The vertices.</param> /// <param name="lift">if set to <c>true</c> [lift].</param> /// <param name="PlaneDistanceTolerance">The plane distance tolerance.</param> /// <exception cref="System.InvalidOperationException">Dimension of the input must be 2 or greater.</exception> /// <exception cref="System.ArgumentException">There are too few vertices (m) for the n-dimensional space. (m must be greater + /// than the n, but m is + NumberOfVertices + and n is + NumOfDimensions</exception> /// <exception cref="InvalidOperationException">PointTranslationGenerator cannot be null if PointTranslationType is enabled. /// or /// Dimension of the input must be 2 or greater.</exception> /// <exception cref="ArgumentException">There are too few vertices (m) for the n-dimensional space. (m must be greater " + /// "than the n, but m is " + NumberOfVertices + " and n is " + Dimension</exception> internal ConvexHullAlgorithm(IVertex[] vertices, bool lift, double PlaneDistanceTolerance) { IsLifted = lift; Vertices = vertices; NumberOfVertices = vertices.Length; NumOfDimensions = DetermineDimension(); if (IsLifted) { NumOfDimensions++; } if (NumOfDimensions < 2) { throw new ConvexHullGenerationException(ConvexHullCreationResultOutcome.DimensionSmallerTwo, "Dimension of the input must be 2 or greater."); } if (NumOfDimensions == 2) { throw new ConvexHullGenerationException(ConvexHullCreationResultOutcome.DimensionTwoWrongMethod, "Dimension of the input is 2. Thus you should use the Create2D method" + " instead of the Create."); } if (NumberOfVertices <= NumOfDimensions) { throw new ConvexHullGenerationException(ConvexHullCreationResultOutcome.NotEnoughVerticesForDimension, "There are too few vertices (m) for the n-dimensional space. (m must be greater " + "than the n, but m is " + NumberOfVertices + " and n is " + NumOfDimensions); } this.PlaneDistanceTolerance = PlaneDistanceTolerance; UnprocessedFaces = new FaceList(); ConvexFaces = new IndexBuffer(); FacePool = new ConvexFaceInternal[(NumOfDimensions + 1) * 10]; // must be initialized before object manager AffectedFaceFlags = new bool[(NumOfDimensions + 1) * 10]; ObjectManager = new ObjectManager(this); Center = new double[NumOfDimensions]; TraverseStack = new IndexBuffer(); UpdateBuffer = new int[NumOfDimensions]; UpdateIndices = new int[NumOfDimensions]; EmptyBuffer = new IndexBuffer(); AffectedFaceBuffer = new IndexBuffer(); ConeFaceBuffer = new SimpleList <DeferredFace>(); SingularVertices = new HashSet <int>(); BeyondBuffer = new IndexBuffer(); ConnectorTable = new ConnectorList[Constants.ConnectorTableSize]; for (var i = 0; i < Constants.ConnectorTableSize; i++) { ConnectorTable[i] = new ConnectorList(); } VertexVisited = new bool[NumberOfVertices]; Positions = new double[NumberOfVertices * NumOfDimensions]; boundingBoxPoints = new List <int> [NumOfDimensions]; minima = new double[NumOfDimensions]; maxima = new double[NumOfDimensions]; mathHelper = new MathHelper(NumOfDimensions, Positions); }
/// <summary> /// Initializes a new instance of the <see cref="ConvexHullAlgorithm" /> class. /// </summary> /// <param name="vertices">The vertices.</param> /// <param name="lift">if set to <c>true</c> [lift].</param> /// <param name="PlaneDistanceTolerance">The plane distance tolerance.</param> /// <exception cref="System.InvalidOperationException">Dimension of the input must be 2 or greater.</exception> /// <exception cref="System.ArgumentException">There are too few vertices (m) for the n-dimensional space. (m must be greater + /// than the n, but m is + NumberOfVertices + and n is + NumOfDimensions</exception> /// <exception cref="InvalidOperationException">PointTranslationGenerator cannot be null if PointTranslationType is enabled. /// or /// Dimension of the input must be 2 or greater.</exception> /// <exception cref="ArgumentException">There are too few vertices (m) for the n-dimensional space. (m must be greater " + /// "than the n, but m is " + NumberOfVertices + " and n is " + Dimension</exception> private ConvexHullAlgorithm(IVertex[] vertices, bool lift, float PlaneDistanceTolerance) { IsLifted = lift; Vertices = vertices; NumberOfVertices = vertices.Length; NumOfDimensions = DetermineDimension(); if (IsLifted) { NumOfDimensions++; } if (NumOfDimensions < 2) { throw new InvalidOperationException("Dimension of the input must be 2 or greater."); } if (NumberOfVertices <= NumOfDimensions) { throw new ArgumentException( "There are too few vertices (m) for the n-dimensional space. (m must be greater " + "than the n, but m is " + NumberOfVertices + " and n is " + NumOfDimensions); } this.PlaneDistanceTolerance = PlaneDistanceTolerance; UnprocessedFaces = new FaceList(); ConvexFaces = new IndexBuffer(); FacePool = new ConvexFaceInternal[(NumOfDimensions + 1) * 10]; // must be initialized before object manager AffectedFaceFlags = new bool[(NumOfDimensions + 1) * 10]; ObjectManager = new ObjectManager(this); Center = new float[NumOfDimensions]; TraverseStack = new IndexBuffer(); UpdateBuffer = new int[NumOfDimensions]; UpdateIndices = new int[NumOfDimensions]; EmptyBuffer = new IndexBuffer(); AffectedFaceBuffer = new IndexBuffer(); ConeFaceBuffer = new SimpleList <DeferredFace>(); SingularVertices = new HashSet <int>(); BeyondBuffer = new IndexBuffer(); ConnectorTable = new ConnectorList[Constants.ConnectorTableSize]; for (var i = 0; i < Constants.ConnectorTableSize; i++) { ConnectorTable[i] = new ConnectorList(); } VertexVisited = new bool[NumberOfVertices]; Positions = new float[NumberOfVertices * NumOfDimensions]; boundingBoxPoints = new List <int> [NumOfDimensions]; minima = new float[NumOfDimensions]; maxima = new float[NumOfDimensions]; mathHelper = new MathHelper(NumOfDimensions, Positions); }
private void ConnectFace(FaceConnector connector) { uint index = connector.HashCode % 0x7e1; ConnectorList list = this.ConnectorTable[index]; for (FaceConnector connector2 = list.First; connector2 != null; connector2 = connector2.Next) { if (FaceConnector.AreConnectable(connector, connector2, this.Dimension)) { list.Remove(connector2); FaceConnector.Connect(connector2, connector); connector2.Face = null; connector.Face = null; this.ObjectManager.DepositConnector(connector2); this.ObjectManager.DepositConnector(connector); return; } } list.Add(connector); }
private void ConnectFace(FaceConnector connector) { uint num = connector.HashCode % 2017u; ConnectorList connectorList = ConnectorTable[num]; for (FaceConnector faceConnector = connectorList.First; faceConnector != null; faceConnector = faceConnector.Next) { if (FaceConnector.AreConnectable(connector, faceConnector, NumOfDimensions)) { connectorList.Remove(faceConnector); FaceConnector.Connect(faceConnector, connector); faceConnector.Face = null; connector.Face = null; ObjectManager.DepositConnector(faceConnector); ObjectManager.DepositConnector(connector); return; } } connectorList.Add(connector); }
/// <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); }