示例#1
0
            // <summary>
            /// Gets the slice borders for the specified slice description.
            /// </summary>
            public static Quadtree <F> Get(_SliceDesc <T, F> Slice)
            {
                if (Slice.Octree.Depth == 0)
                {
                    throw new ArgumentException();
                }

                Quadtree <F> tree;

                if (!_SliceCache.TryGetValue(Slice, out tree))
                {
                    Axis a  = Slice.Axis;
                    int  ai = (int)a;
                    int  l  = Slice.Level;
                    int  hs = 1 << (Slice.Octree.Depth - 1);

                    if (l == hs - 1)
                    {
                        Quadtree <F>[] children = new Quadtree <F> [4];
                        for (int r = 0; r < 4; r++)
                        {
                            children[r] = _SurfaceDesc <T, F> .Get(new _SurfaceDesc <T, F>()
                            {
                                Axis           = a,
                                Lower          = Slice.Octree[Cubia.Octree.Indices[ai, r, 0]],
                                Higher         = Slice.Octree[Cubia.Octree.Indices[ai, r, 1]],
                                SurfaceizeFunc = Slice.SurfaceizeFunc
                            });
                        }
                        tree = Quadtree <F> .Create(children[0].Depth + 1, children);
                    }
                    else
                    {
                        int            i        = l < hs ? 0 : 1;
                        Quadtree <F>[] children = new Quadtree <F> [4];
                        for (int r = 0; r < 4; r++)
                        {
                            children[r] = _SliceDesc <T, F> .Get(new _SliceDesc <T, F>()
                            {
                                Axis           = a,
                                Level          = l - (i *hs),
                                SurfaceizeFunc = Slice.SurfaceizeFunc,
                                Octree         = Slice.Octree[Cubia.Octree.Indices[ai, r, i]]
                            });
                        }
                        tree = Quadtree <F> .Create(children[0].Depth + 1, children);
                    }

                    _SliceCache[Slice] = tree;
                }
                return(tree);
            }
示例#2
0
 /// <summary>
 /// Gets all the values in that satisfy the EnumerateDesc.
 /// </summary>
 public static LinkedList <KeyValuePair <Point <int>, T> > Get(_EnumerateDesc Desc)
 {
     if (Desc.Quadtree.Depth == 0)
     {
         T val = Desc.Quadtree.Value;
         if (!val.Equals(Desc.Excluded))
         {
             LinkedList <KeyValuePair <Point <int>, T> > li = new LinkedList <KeyValuePair <Point <int>, T> >();
             li.AddLast(new KeyValuePair <Point <int>, T>(new Point <int>(0, 0), val));
             return(li);
         }
         else
         {
             return(new LinkedList <KeyValuePair <Point <int>, T> >());
         }
     }
     else
     {
         LinkedList <KeyValuePair <Point <int>, T> > res;
         if (!_Cache.TryGetValue(Desc, out res))
         {
             res = new LinkedList <KeyValuePair <Point <int>, T> >();
             int hsize = 1 << (Desc.Quadtree.Depth - 1);
             for (int x = 0; x < 2; x++)
             {
                 for (int y = 0; y < 2; y++)
                 {
                     Quadtree <T>   child = Desc.Quadtree.Children[x * 2 + y];
                     _EnumerateDesc desc  = new _EnumerateDesc()
                     {
                         Quadtree = child, Excluded = Desc.Excluded
                     };
                     LinkedList <KeyValuePair <Point <int>, T> > sublist = Get(desc);
                     foreach (KeyValuePair <Point <int>, T> it in sublist)
                     {
                         res.AddLast(new KeyValuePair <Point <int>, T>(Point.Add(it.Key, new Point <int>(x * hsize, y * hsize)), it.Value));
                     }
                 }
             }
             _Cache[Desc] = res;
         }
         else
         {
         }
         return(res);
     }
 }
示例#3
0
        /// <summary>
        /// Sends the vertices in a given quadtree of material information to the specified iterators.
        /// </summary>
        public static void SendQuadtree <R>(Quadtree <Material> Source, Axis PlaneAxis, int PlaneLevel, Point <int> Offset,
                                            IIterator <ColorNormalVertex, R> Positive, IIterator <ColorNormalVertex, R> Negative)
        {
            Material val;

            if (Source.Homogenous(out val))
            {
                IMaterial m = val.Description;
                if (m != null)
                {
                    int s = Source.Size;
                    ITileableMaterial tm = m as ITileableMaterial;

                    if (tm != null)
                    {
                        Vector <double> normal;
                        var             proj = Material.Project(PlaneAxis, val.Direction, PlaneLevel, new Point <int>(Offset.X, Offset.Y), new Point <int>(s, s), out normal);
                        Send(tm.CreateTileableRenderable(proj, normal, new Point <int>(s, s)), val.Direction == Polarity.Positive ? Positive : Negative);
                    }
                    else
                    {
                        for (int x = 0; x < s; x++)
                        {
                            for (int y = 0; y < s; y++)
                            {
                                Vector <double> normal;
                                var             proj = Material.Project(PlaneAxis, val.Direction, PlaneLevel, new Point <int>(x + Offset.X, y + Offset.Y), new Point <int>(1, 1), out normal);
                                Send(m.CreateRenderable(proj, normal), val.Direction == Polarity.Positive ? Positive : Negative);
                            }
                        }
                    }
                }
            }
            else
            {
                int hs = 1 << (Source.Depth - 1);
                for (int x = 0; x < 2; x++)
                {
                    for (int y = 0; y < 2; y++)
                    {
                        SendQuadtree(Source[x * 2 + y], PlaneAxis, PlaneLevel, new Point <int>(Offset.X + x * hs, Offset.Y + y * hs), Positive, Negative);
                    }
                }
            }
        }
示例#4
0
        public StaticRenderer(IEnumerableSurface <Material> Source)
        {
            IIterator <ColorNormalVertex, VBO <ColorNormalVertex> > vboc = VBO <ColorNormalVertex> .Create();

            IOctreeInteriorSurface <Material> ois = Source.Extend <IOctreeInteriorSurface <Material> >();

            if (ois != null)
            {
                Quadtree <Material>[,] slices = ois.Slices;
                for (int iax = 0; iax < 3; iax++)
                {
                    for (int l = 0; l < ois.Size - 1; l++)
                    {
                        Send(new QuadtreeSurface <Material>(slices[iax, l], Material.Default, (Axis)iax, l), vboc, vboc);
                    }
                }
                this._VBO = vboc.End();
                return;
            }

            Send(Source, vboc);
            this._VBO = vboc.End();
        }