示例#1
0
 public void SplatProvider(IRandomProvider rnd)
 {
     Clean();
     
     //using (var gs = Graphics.FromImage(this.canvas.Image))
     for (int i = 0; i < this.canvas.Image.Width*this.canvas.Image.Height;i++)
     {
         int x = Math.Min((int) (this.canvas.Image.Width*rnd.NextFloat()), canvas.Image.Width - 1);
         int y = Math.Min((int) (this.canvas.Image.Height*rnd.NextFloat()), canvas.Image.Height - 1);
         (this.canvas.Image as Bitmap).SetPixel(x, y, 
             //Color.FromArgb((int)(255 * rnd.NextFloat()), (int)(255 * rnd.NextFloat()), (int)(255 * rnd.NextFloat()))
             Color.White
             );
     }
 }
示例#2
0
 public CameraSample GetCameraSample(float x, float y, IRandomProvider sampler)
 {
     var res = new CameraSample()
         {
             imageX = x,
             imageY = y,
         };
     if (sampler != null)
     {
         res.lensU = sampler.NextFloat();
         res.lensV = sampler.NextFloat();
         res.time = sampler.NextFloat();
     }
     IRay ray;
     this.Camera.GetRay(x, y, out ray);
     res.EyeRay = (RayData)ray;
     return res;
 }
示例#3
0
        public static List <Vector3> PruneEdges(List <Vector3> Edges, float connectedness, IRandomProvider RNG)
        {
            //this random will be used for randomly adding back some pruned edges.
            // System.Random RNG = new Random();

            //this list will be returned.
            List <Vector3> result = new List <Vector3>();
            //sort edges by weight (stored in Vector3.Z)
            List <Vector3> SortedEdges = Edges.OrderBy(v => v.Z).ToList();
            //List of tree items
            List <DisTreeItem> tree = new List <DisTreeItem>();
            //list of nodes
            //this implementation allows for arbitrary numeric indices
            List <int> itemlist = new List <int>();

            //find all possible nodes from the edges
            foreach (Vector3 edge in SortedEdges)
            {
                //Get edge's start and end nodes
                int A = (int)edge.X;
                int B = (int)edge.Y;
                //check if either already exists, add if not
                if (!itemlist.Contains(A))
                {
                    itemlist.Add(A);
                }
                if (!itemlist.Contains(B))
                {
                    itemlist.Add(B);
                }
            }
            //create a tree item from each found node
            foreach (int i in itemlist)
            {
                tree.Add(new DisTreeItem(i));
            }
            //sort the tree by ID (node number) so we can tree[i]
            tree = tree.OrderBy(v => v.ID).ToList();
            //go through all edges starting with lowest
            foreach (Vector3 edge in SortedEdges)
            {
                //get start and end node id
                int A = (int)edge.X;
                int B = (int)edge.Y;
                //get the relevant tree items
                DisTreeItem a = tree[A];
                DisTreeItem b = tree[B];
                //if the roots are different, the nodes connected by this edge belong to different trees
                //this edge becomes part of the final spanning tree.
                if (a.Root() != b.Root())
                {
                    //merge the trees, smaller tree gets attached to the larger one.
                    a.Combine(b);
                    result.Add(edge);
                }
                //otherwise the edge creates a cycle and should be discarded
                else
                {
                    //however, a certain percentage is kept to keep things interesting
                    if (connectedness > RNG.NextFloat())
                    {
                        //we do not update the tree here
                        result.Add(edge);
                    }
                }
            }

            return(result);
        }