コード例 #1
0
        public Vector3D Sample()
        {
            Vector3D output;

            IntervalSampler sampler = m_sampler;

            output.X = sampler.Sample(out sampler);

            if (sampler != null)
            {
                output.Y = sampler.Sample(out sampler);
            }
            else
            {
                output.Y = MyUtils.GetRandomDouble(m_bBox.Min.Y, m_bBox.Max.Y);
            }

            if (sampler != null)
            {
                output.Z = sampler.Sample(out sampler);
            }
            else
            {
                output.Z = MyUtils.GetRandomDouble(m_bBox.Min.Z, m_bBox.Max.Z);
            }

            System.Diagnostics.Debug.Assert(sampler == null, "Inconsistency in MyBBSetSampler");

            return(output);
        }
コード例 #2
0
            public double Sample(out IntervalSampler childSampler)
            {
                // TODO: Implement divide & conquer for speedup
                double sample     = MyUtils.GetRandomDouble(0.0, TotalWeight);
                double lastLimit  = m_min;
                double lastWeight = 0.0;

                for (int i = 0; i < m_entries.Count; ++i)
                {
                    if (m_entries[i].CumulativeWeight >= sample)
                    {
                        childSampler = m_entries[i].Sampler;
                        double weightRange = m_entries[i].CumulativeWeight - lastWeight;
                        double t           = (sample - lastWeight) / weightRange;
                        return(t * m_entries[i].UpperLimit + (1.0 - t) * lastLimit);
                    }

                    lastLimit  = m_entries[i].UpperLimit;
                    lastWeight = m_entries[i].CumulativeWeight;
                }

                System.Diagnostics.Debug.Assert(false, "Shouldn't get here!");
                childSampler = null;
                return(m_max);
            }