public void AttachReaderStamps(TreeSpeciesStamps source) { int found = 0, total = 0; foreach (LightStampWithTreeSize stampItem in this.lightStampsWithTreeSizes) { LightStamp stamp = source.GetReaderStamp(stampItem.CrownRadius); stampItem.Stamp.SetReader(stamp); if (stamp != null) { ++found; } ++total; //si.crown_radius } //if (GlobalSettings.Instance.LogInfo()) //{ // Debug.WriteLine("attachReaderStamps: found " + found + " stamps of " + total); //} }
/** fast access for an individual stamp using a lookup table. * the dimensions of the lookup table are defined by class-constants. * If stamp is not found there, the more complete list of stamps is searched. */ public LightStamp GetStamp(float dbhInCm, float heightInM) { float hdRatio = 100.0F * heightInM / dbhInCm; TreeSpeciesStamps.GetClasses(dbhInCm, hdRatio, out int diameterClass, out int hdClass); // retrieve stamp from lookup table when tree is within the lookup table's size range LightStamp?stamp = null; if ((diameterClass < Constant.Stamp.DbhClassCount) && (diameterClass >= 0) && (hdClass < Constant.Stamp.HeightDiameterClassCount) && (hdClass >= 0)) { stamp = lightStampsByDbhAndHDRatio[diameterClass, hdClass]; } // find a stamp of matching diameter if the HD-ratio is out of range else if ((diameterClass < Constant.Stamp.DbhClassCount) && (diameterClass >= 0)) { //if (GlobalSettings.Instance.LogDebug()) //{ // Debug.WriteLine("HD for stamp out of range dbh " + dbhInCm + " and h=" + heightInM + " (using smallest/largeset HD)"); //} if (hdClass >= Constant.Stamp.HeightDiameterClassCount) { stamp = lightStampsByDbhAndHDRatio[diameterClass, Constant.Stamp.HeightDiameterClassCount - 1]; // tree is oversize } else { stamp = lightStampsByDbhAndHDRatio[diameterClass, 0]; // tree is underersize } } // find a stamp of matching height-diameter ratio if the DBH is out of range. else if (hdClass < Constant.Stamp.HeightDiameterClassCount && hdClass >= 0) { //if (GlobalSettings.Instance.LogDebug()) //{ // Debug.WriteLine("DBH for stamp out of range dbh " + dbhInCm + "and h=" + heightInM + " -> using largest available DBH."); //} if (diameterClass >= Constant.Stamp.DbhClassCount) { stamp = lightStampsByDbhAndHDRatio[Constant.Stamp.DbhClassCount - 1, hdClass]; // tree is oversize } else { stamp = lightStampsByDbhAndHDRatio[0, hdClass]; // tree is undersize } } // both DBH and HD ratio are out of range else if ((diameterClass >= Constant.Stamp.DbhClassCount) && (hdClass < 0)) { //if (GlobalSettings.Instance.LogDebug()) //{ // Debug.WriteLine("DBH AND HD for stamp out of range dbh " + dbhInCm + " and h=" + heightInM + "-> using largest available DBH/smallest HD."); //} stamp = lightStampsByDbhAndHDRatio[Constant.Stamp.DbhClassCount - 1, 0]; } // handle the case that DBH is too high and HD ratio is too high (not very likely) else if ((diameterClass >= Constant.Stamp.DbhClassCount) && (hdClass >= Constant.Stamp.HeightDiameterClassCount)) { //if (GlobalSettings.Instance.LogDebug()) //{ // Debug.WriteLine("DBH AND HD for stamp out of range dbh " + dbhInCm + " and h=" + heightInM + "-> using largest available DBH."); //} stamp = lightStampsByDbhAndHDRatio[Constant.Stamp.DbhClassCount - 1, Constant.Stamp.HeightDiameterClassCount - 1]; } if (stamp == null) { throw new ArgumentOutOfRangeException("Stamp for DBH " + dbhInCm + " and height " + heightInM + " not found."); } return(stamp); }
/** add a stamp to the internal storage. * After loading the function finalizeSetup() must be called to ensure that gaps in the matrix get filled. */ public void AddStamp(LightStamp stamp, float dbh, float hdRatio, float crownRadius) { TreeSpeciesStamps.GetClasses(dbh, hdRatio, out int diameterClass, out int hdClass); // decode dbh/hd-value this.AddStamp(stamp, diameterClass, hdClass, crownRadius, dbh, hdRatio); // dont set crownradius }