public override Point3d getNeighbourhoodFreePosByIndex(int x, int y, int z, int radius, Libutility util)
        {
            Point3d retpt = new Point3d(-1, -1, -1);

            if (radius < 1)
            {
                return(retpt);
            }
            int start_x = x - radius > 0 ? x - radius : 0;
            int start_y = y - radius > 0 ? y - radius : 0;
            int start_z = z - radius > 0 ? z - radius : 0;
            int end_x   = x + radius < u ? x + radius : u - 1;
            int end_y   = y + radius < v ? y + radius : v - 1;
            int end_z   = z + radius < w ? z + radius : w - 1;
            int count   = (end_x - start_x + 1) * (end_y - start_y + 1) * (end_z - start_z + 1); //
            //int[] ids = new int[count];
            List <Point3d> freePos = new List <Point3d>();

            for (int i = end_x; i >= start_x; i--)
            {
                for (int j = end_y; j >= start_y; j--)
                {
                    //for (int k = end_z; k >= start_z; k--)
                    //{
                    if (particle_ids[i, j, 0] == -1)
                    {
                        //retpt = new Point3d(i, j, k);
                        freePos.Add(uv_positions[i, j, 0]);
                        //return retpt;
                    }
                    //}
                }
            }
            int lens = freePos.Count;

            if (lens == 0)
            {
                return(retpt);
            }
            retpt = freePos[util.getRand(lens)];
            return(retpt);
        }
 public override Point3d getNeighbourhoodFreePosByIndex(int x, int y, int z, int radius, Libutility util)
 {
     Point3d retpt = new Point3d(-1, -1, -1);
     if (radius < 1)
     {
         return retpt;
     }
     int start_x = x - radius > 0 ? x - radius : 0;
     int start_y = y - radius > 0 ? y - radius : 0;
     int start_z = z - radius > 0 ? z - radius : 0;
     int end_x = x + radius < u ? x + radius : u - 1;
     int end_y = y + radius < v ? y + radius : v - 1;
     int end_z = z + radius < w ? z + radius : w - 1;
     int count = (end_x - start_x + 1) * (end_y - start_y + 1) * (end_z - start_z + 1); //
     //int[] ids = new int[count];
     List<Point3d> freePos = new List<Point3d>();
     for (int i = end_x; i >= start_x; i--)
     {
         for (int j = end_y; j >= start_y; j--)
         {
             //for (int k = end_z; k >= start_z; k--)
             //{
                 if (particle_ids[i, j, 0] == -1)
                 {
                     //retpt = new Point3d(i, j, k);
                     freePos.Add(uv_positions[i, j, 0]);
                     //return retpt;
                 }
             //}
         }
     }
     int lens = freePos.Count;
     if (lens == 0)
         return retpt;
     retpt = freePos[util.getRand(lens)];
     return retpt;
 }
Esempio n. 3
0
        /*
         * public trailInfo getOffsetTrailValue(int x, int y, int z, Vector3d orient, float viewangle, float offsetangle, float offsetsteps, Libutility util)
         * {
         * Point3f origin = new Point3f(x, y, z);
         * Plane oriplane = new Plane(origin, orient);
         * float u = offsetsteps * util.sinlut[(int) viewangle] * util.coslut[(int) offsetangle];
         * float v = offsetsteps * util.sinlut[(int) viewangle] * util.sinlut[(int) offsetangle];
         * float w = offsetsteps * util.coslut[(int) viewangle];
         * Point3d target = oriplane.PointAt(u, v, w);
         * int tx = (int) Math.Round(target.X);
         * int ty = (int) Math.Round(target.Y);
         * int tz = (int) Math.Round(target.Z);
         * float tr = 0;
         * if (tx < 0 || tx >= _x || ty < 0 || ty >= _y || tz < 0 || tz >= _z)
         *  tr = -1;
         * else
         *  tr = trail[tx, ty, tz];
         * trailInfo newinfo = new trailInfo(new Point3d(tx, ty, tz), tr);
         * return newinfo;
         * }*/

        public override Point3d getNeighbourhoodFreePosByIndex(int x, int y, int z, int radius, Libutility util)
        {
            Point3d retpt = new Point3d(-1, -1, -1);

            if (radius < 1)
            {
                return(retpt);
            }

            /*
             * int times = 0;
             * int tpz;
             * int tpy;
             * int tpx;
             * do
             * {
             * tpx = util.getRand(x - radius, x + radius + 1);
             * tpy = util.getRand(y - radius, y + radius + 1);
             * tpz = util.getRand(z - radius, z + radius + 1);
             * times++;
             * }
             * while (particle_ids[tpx, tpy, tpz] != -1 && times < 20);
             * if (particle_ids[tpx, tpy, tpz] != -1)
             * return retpt;
             * else
             * return new Point3d(tpx, tpy, tpz);
             */

            int start_x = x - radius > 0 ? x - radius : 0;
            int start_y = y - radius > 0 ? y - radius : 0;
            int start_z = z - radius > 0 ? z - radius : 0;
            int end_x   = x + radius < u ? x + radius : u - 1;
            int end_y   = y + radius < v ? y + radius : v - 1;
            int end_z   = z + radius < w ? z + radius : w - 1;
            int count   = (end_x - start_x + 1) * (end_y - start_y + 1) * (end_z - start_z + 1); //
            //int[] ids = new int[count];
            List <Point3d> freePos = new List <Point3d>();

            for (int i = end_x; i >= start_x; i--)
            {
                for (int j = end_y; j >= start_y; j--)
                {
                    for (int k = end_z; k >= start_z; k--)
                    {
                        if (particle_ids[i, j, k] == -1)
                        {
                            //retpt = new Point3d(i, j, k);
                            freePos.Add(positions[i, j, k]);
                            //return retpt;
                        }
                    }
                }
            }
            int lens = freePos.Count;

            if (lens == 0)
            {
                return(retpt);
            }
            retpt = freePos[util.getRand(lens)];
            return(retpt);
        }