void SetFirstCellToCellContaining(Vector start) { //Find cell that contains boundaryLine.Start; bool foundFirstCell = false; //Check if boundaryLine.Start is still in cell, else search neighborhood foreach (MeshCell <T> cell in EnumerateCellsInConcentricCircles()) { Vector[] verts = Array.ConvertAll(cell.Vertices, item => (Vector)item); //At this point, every cell is convex! bool isInside = PolygonTesselation.PointInConvexPolygon(verts, start); if (isInside) { foundFirstCell = true; boundary.FirstCorner = cell; break; } } if (!foundFirstCell) { throw new Exception("First cell could not be found: boundaryLine.start not inside a cell"); } }
public (MeshCell <T>, IEnumerator <Edge <T> >) GetFirst(Line boundaryLine) { //Find cell that contains boundaryLine.Start; bool foundFirstCell = false; if (insideCell == null) { //SetFirst Cell: any random cell. Influences runtime, though insideCell = Cells[0]; foundFirstCell = true; } //Check if boundaryLine.Start is still in cell, else search neighborhood foreach (MeshCell <T> cell in CellsOnSameSideOfBoundary_Iterative(insideCell)) { Vector[] verts = Array.ConvertAll(cell.Vertices, item => (Vector)item); //At this point, every cell is convex! bool isInside = PolygonTesselation.PointInConvexPolygon(verts, (Vector)boundaryLine.start); if (isInside) { foundFirstCell = true; insideCell = cell; break; } } if (foundFirstCell) { AfterCutRidgeEnumerator enumerator = new AfterCutRidgeEnumerator(insideCell.Edges, insideCell.Edges[1]); enumerator.Reset(); return(insideCell, enumerator); } else { throw new Exception("First cell could not be found: boundaryLine.start not inside a cell"); } }
static (GridCommons, int[][]) ExtractGridCommonsAndCellAggregation( IEnumerable <MeshCell <T> > cells, BoundaryConverter boundaryConverter) { List <BoSSS.Foundation.Grid.Classic.Cell> cellsGridCommons = new List <BoSSS.Foundation.Grid.Classic.Cell>(); List <int[]> aggregation = new List <int[]>(); foreach (MeshCell <T> cell in cells) { //Convert to BoSSSCell : Triangulate Vector[] voronoiCellVertices = cell.Vertices.Select(voVtx => voVtx.Position).ToArray(); int[,] iVtxTri = PolygonTesselation.TesselatePolygon(voronoiCellVertices); //SortDescendingArea(iVtxTri, voronoiCellVertices); int[] Agg2Pt = new int[iVtxTri.GetLength(0)]; bool isBoundaryCell = IsBoundary(cell); for (int iTri = 0; iTri < iVtxTri.GetLength(0); iTri++) { // loop over triangles of voronoi cell int iV0 = iVtxTri[iTri, 0]; int iV1 = iVtxTri[iTri, 1]; int iV2 = iVtxTri[iTri, 2]; Vector V0 = voronoiCellVertices[iV0]; Vector V1 = voronoiCellVertices[iV1]; Vector V2 = voronoiCellVertices[iV2]; (iV0, iV1, iV2) = Rearrange(iV0, iV1, iV2, V0, V1, V2); V0 = voronoiCellVertices[iV0]; V1 = voronoiCellVertices[iV1]; V2 = voronoiCellVertices[iV2]; Vector D1 = V1 - V0; Vector D2 = V2 - V0; bool positive = true; if (D1.CrossProduct2D(D2) < 0) { if (isBoundaryCell) { Console.WriteLine($"Cell{cell.Node.AsVoronoiNode().Position} not positive. It is probably not convex."); positive = false; int it = iV0; iV0 = iV2; iV2 = it; Vector vt = V0; V0 = V2; V2 = vt; D1 = V1 - V0; D2 = V2 - V0; } else { throw new Exception($"Created negatively oriented cell. Node = {cell.Node.AsVoronoiNode().Position}"); } } //if(D1.CrossProduct2D(D2) < 1.0e-7) //{ // Console.WriteLine($"Created very small cell. Node = {cell.Node.AsVoronoiNode().Position}, Area= {D1.CrossProduct2D(D2)}, positive = {positive}"); //} Cell Cj = new Cell() { GlobalID = cellsGridCommons.Count, Type = CellType.Triangle_3, }; Cj.TransformationParams = MultidimensionalArray.Create(3, 2); Cj.TransformationParams.SetRowPt(0, V0); Cj.TransformationParams.SetRowPt(1, V1); Cj.TransformationParams.SetRowPt(2, V2); Agg2Pt[iTri] = cellsGridCommons.Count; cellsGridCommons.Add(Cj); //Save BoundaryInformation if (isBoundaryCell) { List <BoundaryFace> tags; if (positive) { tags = GetBoundaryFacesOfTriangle(cell, iV0, iV1, iV2); } else { tags = GetBoundaryFacesOfNegativeTriangle(cell, iV0, iV1, iV2); } boundaryConverter.RegisterBoundaries(Cj, tags); } Cj.NodeIndices = new int[] { cell.Vertices[iV0].ID, cell.Vertices[iV1].ID, cell.Vertices[iV2].ID }; } aggregation.Add(Agg2Pt); } GridCommons grid = new Grid2D(Triangle.Instance) { Cells = cellsGridCommons.ToArray() }; //PrintEdgeTags(cellsGridCommons); boundaryConverter.RegisterEdgesTo(grid); return(grid, aggregation.ToArray()); }