/// <summary> /// Update the current model with the descriptor contained in the one specified /// </summary> /// <param name="updatingModel"></param> public void UpdateModel(ModelManager2 updatingModel) { foreach (DescriptorInfo descriptorToMatch in updatingModel._descriptorManager.ActiveDescriptors) { DescriptorInfo[] matches = this._descriptorManager.GetClosestDescriptors(descriptorToMatch); if (matches.Length > 1) { if (_conflictResolveCallback == null) { throw new ArgumentNullException("ConflictResolvedCallback delegate set to null !"); } DescriptorInfo di = _conflictResolveCallback(descriptorToMatch, matches); if (di == null) { throw new ArgumentNullException("ConflictResolvedCallback returned null !"); } matches[0] = di; } matches[0].IDescriptor.Name = descriptorToMatch.IDescriptor.Name; matches[0].IDescriptor.Criteria = descriptorToMatch.IDescriptor.Criteria; // Add the closest match to the list of active Descriptor (so when trying to seve model it will be serialized) if (this._descriptorManager.SelectedDescriptors.Contains(matches[0]) == false) { this._descriptorManager.SelectedDescriptors.Add(matches[0]); } } }
/// <summary> /// Create Model /// </summary> /// <param name="silhouetteTolerance">Silhouette tolerance</param> /// <param name="xTolerance">x shift tolerance</param> /// <param name="yTolerance">y shift tolerance</param> /// <param name="imgTolerance">image tolerance</param> /// <param name="color">The ARGB tolerance</param> void IModelManager2Unmanaged.CreateModel(double silhouetteTolerance, double xTolerance, double yTolerance, double imgTolerance, IColor color) { System.Diagnostics.Debug.WriteLine("CreateModel() :" + "\n shapeTolerance = " + silhouetteTolerance.ToString() + "\n imgTolerance = " + imgTolerance.ToString() + "\n (x y) tolerance = (" + xTolerance.ToString() + yTolerance.ToString() + ")" + "\n (a,r,g,b) tolerance = (" + color.ToString() + ")\n"); //logging System.Diagnostics.Debug.WriteLine("Analyzing..."); Analyze(); System.Diagnostics.Debug.WriteLine("Adding Descriptors..."); Descriptors.SelectedDescriptors.AddRange(Descriptors.ActiveDescriptors); System.Collections.ArrayList descriptors = Descriptors.SelectedDescriptors; System.Diagnostics.Debug.WriteLine("Start Looping..."); for (int t = 0; t < descriptors.Count; t++) { ArrayList criteria = new ArrayList(); DescriptorInfo descr = (DescriptorInfo)descriptors[t]; descr.IDescriptor.Name = t.ToString(); if (silhouetteTolerance >= 0) { criteria.Add(new Criteria.SilhouetteCriterion(silhouetteTolerance)); } if (xTolerance >= 0) { criteria.Add(new Criteria.XPositionCriterion(xTolerance)); } if (yTolerance >= 0) { criteria.Add(new Criteria.YPositionCriterion(yTolerance)); } if (imgTolerance >= 0) { criteria.Add(new Criteria.TextureCriterion(imgTolerance)); } if ((ColorByte)color != ColorByte.Empty) { criteria.Add(new Criteria.ColorAverageCriterion((ColorDouble)color.ToColor())); } descr.IDescriptor.Criteria = (Criterion[])criteria.ToArray(typeof(Criterion)); } }
// Defaut resolver is non-optimal : return first descriptor from the conflicting list private DescriptorInfo InternalConflictResolver(DescriptorInfo descriptorToMatch, DescriptorInfo[] conflictingDescriptors) { return(conflictingDescriptors[0]); }
/// <summary> /// Add a relation between 2 descriptors (descriptor touch each other) /// </summary> /// <param name="descriptor">The touching descriptor</param> public void AddRelation(DescriptorInfo descriptor) { _neighbors.Add(descriptor); descriptor._neighbors.Add(this); }