public VoronoiGrid CreateGrid(VoronoiNodes nodes, int firstCornerNodeIndice) { List <Node> mesherNodes = WrapInMesherNodes(nodes.Nodes); VoronoiGrid grid = CreateGrid(mesherNodes, firstCornerNodeIndice); return(grid); }
static VoronoiNodes ExtractVoronoiNodes(IMesh <T> mesh) { IList <T> nodeList = mesh.Nodes; IList <VoronoiNode> voronoiNodeList = CastAsVoronoiNodes(nodeList); VoronoiNodes nodes = new VoronoiNodes(voronoiNodeList); return(nodes); }
public VoronoiGrid CreateGrid(VoronoiNodes nodes, Settings settings) { List <Node> mesherNodes = WrapInMesherNodes(nodes.Nodes); BoundaryMesh <Node> mesh = CreateMesh(mesherNodes, settings); VoronoiGrid grid = Convert2VoronoiGrid(mesh, settings); return(grid); }
public VoronoiGrid ConvertToVoronoiGrid( IMesh <T> mesh) { boundaryConverter.Clear(); (GridCommons grid, int[][] aggregation) = ExtractGridCommonsAndCellAggregation(mesh.Cells, boundaryConverter); VoronoiNodes nodes = ExtractVoronoiNodes(mesh); VoronoiGrid voronoiGrid = new VoronoiGrid(grid, aggregation, nodes, boundary); voronoiGrid.FirstCornerNodeIndice = mesh.CornerNodeIndice; return(voronoiGrid); }
bool IsPermutation(Map map, VoronoiNodes source, VoronoiNodes target) { for (int i = 0; i < source.Nodes.Count; ++i) { VoronoiNode sourceNode = source.Nodes[i]; VoronoiNode targetNode = target.Nodes[map.GetMapping(i)]; if ((sourceNode.Position - targetNode.Position).Abs() > 1e-10) { return(false); } } return(true); }
public static VoronoiGrid Convert2VoronoiGrid <T>(BoundaryMesh <T> mesh, VoronoiInfo info) where T : IVoronoiNodeCastable { IReadOnlyList <MeshCell <T> > cells = mesh.GetCells(); (GridCommons grid, int[][] aggregation) = ExtractGridCommonsAndCellAggregation(cells); IList <T> nodeList = mesh.GetNodes(); IList <VoronoiNode> voronoiNodeList = Cast(nodeList); VoronoiNodes nodes = new VoronoiNodes(voronoiNodeList); VoronoiGrid voronoiGrid = new VoronoiGrid(grid, aggregation, nodes, info); return(voronoiGrid); }
public MappedVoronoiGrid CreateGrid(VoronoiNodes nodes, int firstCornerNodeIndice) { List <TrackableNode> mesherNodes = WrapInMesherNodes(nodes.Nodes); VoronoiGrid grid = CreateGrid(mesherNodes, firstCornerNodeIndice); ConnectionMap resultMap = ExtractMap(base.mesh.Nodes); ConnectionMap inputMap = GetInputMap(resultMap, nodes.Count); MappedVoronoiGrid movingGrid = new MappedVoronoiGrid { Result = grid, InputNodesToResultNodes = inputMap, ResultNodesToInputNodes = resultMap }; return(movingGrid); }
public TrackedVoronoiGrid CreateGrid(VoronoiNodes nodes, Settings settings) { List <TrackableNode> mesherNodes = WrapInMesherNodes(nodes.Nodes); BoundaryMesh <TrackableNode> mesh = CreateMesh(mesherNodes, settings); VoronoiGrid grid = Convert2VoronoiGrid(mesh, settings); OneWayArrayMap resultMap = ExtractMap(mesh.GetNodes()); OneWayArrayMap inputMap = GetInputMap(resultMap, nodes.Count); TrackedVoronoiGrid movingGrid = new TrackedVoronoiGrid { Result = grid, InputNodesToResultNodes = inputMap, ResultNodesToInputNodes = resultMap }; return(movingGrid); }
public void MapMultipleCellsPeriodic() { byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 1, "Dirichlet" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames, BoundingBox = GridShapes.Rectangle(2, 2) }; NodeTrackingVoronoiMesher mesher = new NodeTrackingVoronoiMesher( new VoronoiMesher <TrackableNode> .Settings() { Boundary = gridBoundary, NumberOfLloydIterations = 0, }); int numberOfNodes = 200; MultidimensionalArray array = MultidimensionalArray.Create(numberOfNodes, 2); Random random = new Random(0); for (int i = 0; i < numberOfNodes; ++i) { array[i, 0] = 2.0 * random.NextDouble() - 1.0; array[i, 1] = 2.0 * random.NextDouble() - 1.0; } VoronoiNodes nodes = new VoronoiNodes(array); MappedVoronoiGrid grid = mesher.CreateGrid(nodes, 0); bool mapsNodesOntoItself = IsPermutation(grid.InputNodesToResultNodes, nodes, grid.Result.Nodes); Assert.IsTrue(mapsNodesOntoItself); MappedVoronoiGrid grid2 = mesher.CreateGrid(grid.Result.Nodes, 0); mapsNodesOntoItself = IsPermutation(grid2.InputNodesToResultNodes, grid.Result.Nodes, grid2.Result.Nodes); Assert.IsTrue(mapsNodesOntoItself); }
public void MapOneCellPeriodic() { byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 1, "Dirichlet" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames, BoundingBox = GridShapes.Rectangle(2, 2), }; NodeTrackingVoronoiMesher mesher = new NodeTrackingVoronoiMesher( new VoronoiMesher <TrackableNode> .Settings() { Boundary = gridBoundary, NumberOfLloydIterations = 0, }); MultidimensionalArray array = MultidimensionalArray.Create(8, 2); array.SetRow(0, new double[] { -0.9, 0.7 }); array.SetRow(1, new double[] { -0.8, -0.4 }); array.SetRow(2, new double[] { 0, 0.5 }); array.SetRow(3, new double[] { 0.05, 0 }); array.SetRow(4, new double[] { 0.1, -0.5 }); array.SetRow(5, new double[] { 0.8, 0.8 }); array.SetRow(6, new double[] { 1.2, 0.2 }); array.SetRow(7, new double[] { 0.5, -0.6 }); VoronoiNodes nodes = new VoronoiNodes(array); MappedVoronoiGrid grid = mesher.CreateGrid(nodes, 0); Assert.IsTrue(( grid.Result.Nodes.Nodes[grid.InputNodesToResultNodes.GetMapping(0)].Position - new Vector(-0.9, 0.7)).Abs() < 1e-12); }