Exemplo n.º 1
0
        private static void ReflectCellsRecursive(Sphere[] simplex, H3.Cell[] cells, Settings settings,
                                                  List <H3.Cell> completedCells, HashSet <Vector3D> completedCellIds)
        {
            if (0 == cells.Length)
            {
                return;
            }

            List <H3.Cell> newCells = new List <H3.Cell>();

            foreach (H3.Cell cell in cells)
            {
                //foreach( Sphere mirror in simplex )
                //for( int m=0; m<simplex.Length; m++ )
                for (int m = simplex.Length - 1; m >= 0; m--)
                {
                    Sphere mirror = simplex[m];
                    //if( m == 2 )
                    //	continue;

                    //if( completedCellIds.Count > 1000 )
                    //	return;

                    //if( completedCellIds.Count > settings.MaxEdges/5 )
                    if (completedCellIds.Count > settings.MaxEdges * 3)
                    {
                        throw new System.Exception("Maxing out cells - will result in uneven filling.");
                    }

                    H3.Cell newCell = cell.Clone();
                    newCell.Reflect(mirror);

                    // This tracks reflections across the cell facets.
                    newCell.Depths[m]++;
                    newCell.LastReflection = m;

                    //if( newCell.Depths[0] > 2 )
                    //	continue;

                    if (!CellOk(newCell, settings))
                    {
                        continue;
                    }

                    if (completedCellIds.Add(newCell.ID))
                    {
                        // Haven't seen this cell yet, so
                        // we'll need to recurse on it.
                        newCells.Add(newCell);
                        completedCells.Add(newCell);
                    }
                }
            }

            ReflectCellsRecursive(simplex, newCells.ToArray(), settings, completedCells, completedCellIds);
        }
Exemplo n.º 2
0
        private static void ReflectCellsRecursive2(Sphere[] simplex, H3.Cell[] cells, Settings settings,
                                                   List <H3.Cell> completedCells, HashSet <Vector3D> completedCellIds)
        {
            if (0 == cells.Length)
            {
                return;
            }

            List <H3.Cell> newCells = new List <H3.Cell>();

            foreach (H3.Cell cell in cells)
            {
                //foreach( Sphere mirror in simplex )
                for (int m = 0; m < simplex.Length; m++)
                {
                    Sphere mirror = simplex[m];
                    if (completedCellIds.Count > 250000)
                    {
                        return;
                    }

                    H3.Cell newCell = cell.Clone();
                    newCell.Reflect(mirror);
                    //if( !CellOk( newCell, settings ) )
                    bool cellOk = true;
                    foreach (H3.Cell.Facet f in cell.Facets)
                    {
                        if (f.Sphere.Radius < 0.002)
                        {
                            cellOk = false;
                        }
                    }
                    if (!cellOk)
                    {
                        continue;
                    }

                    // This tracks reflections across the cell facets.
                    newCell.Depths[m]++;

                    if (completedCellIds.Add(newCell.ID))
                    {
                        // Haven't seen this cell yet, so
                        // we'll need to recurse on it.
                        newCells.Add(newCell);
                        completedCells.Add(newCell);
                    }
                }
            }

            ReflectCellsRecursive2(simplex, newCells.ToArray(), settings, completedCells, completedCellIds);
        }
Exemplo n.º 3
0
        private static H3.Cell[] GenTruss(Sphere[] simplex, Mesh mesh, Vector3D cen, bool ball)
        {
            // We don't want to include the first mirror (which reflects across cells).
            Sphere[] mirrors    = simplex.Skip(1).ToArray();
            Sphere[] allMirrors = simplex.ToArray();

            // Simplices will be the "cells" in Recurse.CalcCells.
            H3.Cell.Facet[] simplexFacets = simplex.Select(m => new H3.Cell.Facet(m)).ToArray();

            H3.Cell startingCell = new H3.Cell(simplexFacets);
            startingCell.Center = cen;

            //FCOrient( startingCell );
            //return null;

            startingCell = startingCell.Clone();                // So our mirrors don't get munged after we reflect around later.
            H3.Cell[] simplices = Recurse.CalcCells(mirrors, new H3.Cell[] { startingCell }, new Recurse.Settings()
            {
                Ball = ball
            });
            //H3.Cell[] simplices = new H3.Cell[] { startingCell };

            // Subsets
            //return simplices.Where( s => s.Depths[0] == 1 ).ToArray();
            //return simplices.ToArray();

            List <H3.Cell> final = new List <H3.Cell>();

            final.AddRange(simplices);

            // Add in other truss cells.
            Recurse.Settings settings = new Recurse.Settings();
            foreach (int[] reflections in TrussReflections())
            {
                foreach (H3.Cell c in simplices)
                {
                    H3.Cell clone = c.Clone();
                    foreach (int r in reflections)
                    {
                        clone.Reflect(allMirrors[r]);
                    }
                    if (Recurse.CellOk(clone, settings))
                    {
                        final.Add(clone);
                    }
                }
            }

            return(final.ToArray());
        }