Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type private baseSampler(n,sets, samplingMethod, length) =
- let indexMap : ConcurrentDictionary<int,int> = new ConcurrentDictionary<int,int>()
- let setMap : ConcurrentDictionary<int,int> = new ConcurrentDictionary<int,int>()
- let samplerMap : (float*float*float)[][] = Array.init sets (fun i -> (samplingMethod n))
- let n = n
- let sets = sets
- member this.length = length
- member this.getNext (id:int) =
- if indexMap.IsEmpty || (not (indexMap.ContainsKey(id)))
- then
- indexMap.TryAdd (id, (samplerMap.[0].Length-1)) |> ignore
- if setMap.IsEmpty || (not (setMap.ContainsKey(id)))
- then
- setMap.TryAdd (id, ran.Next(0,samplerMap.Length-1)) |> ignore
- let returnIndex = indexMap.Item id
- let setIndex = setMap.Item id
- if returnIndex <= 0 // check if there are more samples left (0 if no)
- then
- let sampleSetLength = samplerMap.[0].Length-1
- setMap.TryUpdate (id,ran.Next(0,samplerMap.Length-1), setIndex) |> ignore
- indexMap.TryUpdate (id,sampleSetLength,returnIndex) |> ignore
- indexMap.TryUpdate (id,returnIndex-1, returnIndex) |> ignore
- samplerMap.[setIndex].[returnIndex]
- member this.getNextReg (id:int) =
- if n = 1
- then (0.5,0.5,0.0)
- else
- if indexMap.IsEmpty || (not (indexMap.ContainsKey(id)))
- then
- indexMap.TryAdd(id, this.length-1) |> ignore
- let returnIndex = indexMap.Item id
- if returnIndex = 0
- then
- indexMap.TryUpdate (id, this.length-1, returnIndex) |> ignore
- indexMap.TryUpdate (id, returnIndex-1, returnIndex) |> ignore
- samplerMap.[0].[returnIndex]
- interface ISampler with
- member this.getNext id = this.getNext id
- member this.length = length
- member this.n = n
- member this.sets = sets
- member this.samplingMethod i = samplingMethod i
- type private RegularSampler(n) =
- inherit baseSampler(n, 1, mkRegular, n*n)
- interface ISampler with
- override this.getNext id = this.getNextReg id
- type private RandomSampler(n, sets) =
- inherit baseSampler(n, sets, mkRandom, n)
- type private JitteredSampler(n, sets) =
- inherit baseSampler(n, sets, mkJitter, n*n)
- type private NRookSampler(n, sets) =
- inherit baseSampler(n, sets, mkNRook, n)
- type private MultiJittered(n, sets) =
- inherit baseSampler(n, sets, mkMultiJitter, n*n)
- type private hemiSampler(sampler:ISampler, e) =
- inherit baseSampler(sampler.n,sampler.sets,sampler.samplingMethod,sampler.length)
- interface ISampler with
- override this.samplingMethod i = transformToHemiMap (sampler.samplingMethod i) e
- type private discSampler(sampler:ISampler) =
- inherit baseSampler(sampler.n,sampler.sets,sampler.samplingMethod,sampler.length)
- interface ISampler with
- override this.samplingMethod i = transformToDiscMap (sampler.samplingMethod i)
- override this.getNext id = this.getNext id
- let mkRegularSampler n = new RegularSampler(n) :> ISampler
- let mkRandomSampler n sets = new RandomSampler(n, sets) :> ISampler
- let mkJitteredSampler n sets = new JitteredSampler(n, sets) :> ISampler
- let mkNRookSampler n sets = new NRookSampler(n, sets) :> ISampler
- let mkMultiJitteredSampler n sets = new MultiJittered(n, sets) :> ISampler
- let mkDiscSampler sampler:ISampler = new discSampler(sampler) :> ISampler
- let mkHemiSampler sampler:ISampler = new hemiSampler(sampler) :> ISampler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement