Пример #1
0
 public static Vector PhotonDirection(ref Photon p) {
     return new Vector(
         DirectionDiscretizationHelper.SinTheta(p.Theta) * DirectionDiscretizationHelper.CosPhi(p.Phi),
         DirectionDiscretizationHelper.SinTheta(p.Theta) * DirectionDiscretizationHelper.SinPhi(p.Phi),
         DirectionDiscretizationHelper.CosTheta(p.Theta)
         );
 }
Пример #2
0
        public void QueryMap(ref Point pos, float maxDist, int nphotons, out Photon[] result)
        {

            result = new Photon[nphotons];
            var ix = this.hashGrid[(int)this.Hash(ref pos)];

            result = ix.ToArray();
        }
Пример #3
0
        public void QueryMap(ref Point pos, float maxDist, int nphotons, out Photon[] result) {
            var np = new NearestPhotons();
            np.dist = new float[nphotons + 1];
            np.index = Enumerable.Repeat(new Photon() {Plane = 255}, nphotons + 1).ToArray();
            np.pos = pos;
            np.max = nphotons;
            np.gotHeap = 0;
            np.found = 0;

            np.dist[0] = maxDist * maxDist;
            this.LocatePhotons(ref np, 1);
            result = np.found > 0 ? np.index.Skip(1).ToArray() : new Photon[0];
        }
Пример #4
0
            public void Construct(Photon[] points)
            {
                this.pointsCount = points.Length;
                bbox = new AABB(points.Select(item => item.Position));
                Counts = new int[pointsCount];
                Table = new Photon[pointsCount];
                var maxPhotonRadius = 1.2f;
                float cellSize = MathLab.Sqrt(maxPhotonRadius) * 2f;
                //std::cerr << "Hash grid cell size: " << cellSize <<std::endl;
                var invCellSize = 1f / cellSize;

                foreach (var point in points)
                {
                    Vector hh = (point.Position - bbox.Min) * invCellSize;
                    int ix = Math.Abs((int)(hh.x));
                    int iy = Math.Abs((int)(hh.y));
                    int iz = Math.Abs((int)(hh.z));
                    var hash = Hash(ix, iy, iz, pointsCount);
                    Table[hash] = point;
                    Interlocked.Add(ref Counts[hash], 1);
                }
            }
Пример #5
0
        public void Balance()
        {

            if (this.photonsCount == 0)
                return;

            var maxRadius2 = 0f;
            var prevPos = photons[0].Position;
            for (int index = 1; index < photons.Length; index++)
            {
                var photon = photons[index];
                var radius = (prevPos - photon.Position).Length;
                if (radius > maxRadius2)
                {
                    maxRadius2 = radius;
                }
                prevPos = photon.Position;
            }

            Photon[] table = new Photon[this.photons.Length];
            cellSize = MathLab.Sqrt(maxRadius2) * CellSizeScale;

            var invCellSize = 1f / cellSize;

            foreach (var point in photons)
            {
                Vector hh = (point.Position - bbox.Min) * invCellSize;
                int ix = Math.Abs((int)(hh.x));
                int iy = Math.Abs((int)(hh.y));
                int iz = Math.Abs((int)(hh.z));
                var hash = Hash(ix, iy, iz, photonsCount);
                table[hash] = point;
                Interlocked.Add(ref counts[hash], 1);
            }

            this.photons = table;
        }
Пример #6
0
        public void Balance() {

            /*
              if (storedPhotons == 0)
            return;
        photons = photonList.toArray(new Photon[photonList.size()]);
        photonList = null;
        Photon[] temp = new Photon[storedPhotons + 1];
        balanceSegment(temp, 1, 1, storedPhotons);
        photons = temp;
        halfStoredPhotons = storedPhotons / 2;
        log2n = (int) Math.ceil(Math.log(storedPhotons) / Math.log(2.0));

             
             
             */
            if (this.photonsCount == 0)
                return;

            Photon[] photonz = new Photon[this.photons.Length];
            Array.Copy(this.photons.ToArray(), photonz, this.photons.Length);
            List<Photon> photonList = new List<Photon>(photonz);
            photonz = null;

            var temp = Enumerable.Repeat(new Photon(), photonsCount + 1).ToList();

            this.BalanceSegment(ref temp, ref photonList, 1, 1, this.photonsCount);

            this.photons = temp.ToArray();
            this.Half = this.photons.Length / 2;

            //if (photonsCount > 1)
            //{
            //    List<Photon> pa1 = new List<Photon>(photonsCount + 1);
            //    List<Photon> pa2 = new List<Photon>(photonsCount + 1);
            //    PrepareList(photonsCount + 1,ref pa1);
            //    PrepareList(photonsCount + 1,ref pa2);

            //    for (int i =0 ;i <photonsCount; i++)
            //    {
            //        pa2[i] = photons[i];
            //    }

            //    BalanceSegment(ref pa1, ref pa2, 1, 1, photonsCount);
            //    pa2 = null;
            //    int d;
            //    int j = 1;
            //    int foo = 1;

            //    Photon fooPhoton = photons[j];
            //    for(int i = 0; i < photonsCount; i++)
            //    {
            //        d = pa1.IndexOf(pa1[j])  - photonsCount; // TODO INCORRECT
            //        pa1[j] = Photon.NullPhoton;
            //       // pa1.Remove(pa1[j]);

            //        if (d != foo)
            //            photons[j] = photons[d];
            //        else
            //        {
            //            photons[j] = fooPhoton;

            //            if (i < photonsCount)
            //            {
            //                for (; foo <= photonsCount; foo ++ )
            //                {
            //                    if ((!Photon.IsNull(pa1[foo])))
            //                        break;
            //                    fooPhoton = photons[foo];
            //                    j = foo;
            //                }
            //                continue;
            //            }
            //            j = d;
            //        }
            //    }
            //    pa1 = null;

            //    Half = photonsCount/2 + 1;

            //}
        }