internal void calcBlockSize(IFrequencyBasedSelecter master) { if (master.Frequency != -1 && SubBlockHeight != -1 && NumSubBlocks != -1) { BlockSize = master.Frequency * SubBlockHeight * NumSubBlocks; } }
bool ValidateFreqSelecter(IFrequencyBasedSelecter freqSelecter) { //ensure sampler frequency matches sample group freqency if (freqSelecter != null && freqSelecter.Frequency != this.SamplingFrequency || freqSelecter.ITreeFrequency != this.InsuranceFrequency) { //older versions of FMSC.Sampling would use -1 instead of 0 if InsuranceFrequency was 0 if (freqSelecter.ITreeFrequency == -1 && this.InsuranceFrequency == 0) { return true; } return false; } else { return true; } }
//Methods public void initBlock(IFrequencyBasedSelecter master) { if (this.SelectionList == null) { this.SelectionList = new List<SampleItem>(); } else { SelectionList.Clear(); } if (master == null) { throw new System.ArgumentNullException("master can't be null"); } calcBlockSize(master); boolItem nextSelection; //temp value IntInterval subBlock;//interval from the start to the end of the current subblock //select selection numbers for each subBlock for (int i = 0; i < this.NumSubBlocks; i++) { //calculate the range of the current subblock subBlock.Start = i * (master.Frequency * this.SubBlockHeight); subBlock.End = (i + 1) * (master.Frequency * this.SubBlockHeight); //get a random item in the range of the current subblock nextSelection = new boolItem(master.Rand.Next(subBlock.Start, subBlock.End)); if (master.IsSelectingITrees) { if (master.InsuranceCounter.Next()) { nextSelection.IsInsuranceItem = true; } else { nextSelection.IsSelected = true; } } else { nextSelection.IsSelected = true; } this.selectionList.Add(nextSelection); } //select remaining selection numbers for (int i = 0; i < this.NumSubBlocks; i++) { nextSelection = new boolItem(); //keep requesting new selection nubers untill you get one //that you dont already have do { nextSelection.Index = master.Rand.Next(0, this.NumSubBlocks * this.SubBlockHeight * master.Frequency); } while (this.selectionList.Contains(nextSelection)); if (master.IsSelectingITrees) { if (master.InsuranceCounter.Next()) { nextSelection.IsInsuranceItem = true; } else { nextSelection.IsSelected = true; } } else { nextSelection.IsSelected = true; } this.selectionList.Add(nextSelection); } if (master.IsSelectingITrees) { int i = 0; boolItem item = new boolItem(i); //loop though the intire block for (; i < BlockSize; i++) { //if nothing already exists at that block index if (!selectionList.Contains(item)) { //see if it might be an insurance item if (master.InsuranceCounter.Next()) { item.IsInsuranceItem = true; SelectionList.Add(item); item = new boolItem(); } } item.Index = i + 1; } } this.selectionList.Sort(); }