/// <summary> /// Load an existing model /// </summary> /// <param name="modelFileName"></param> /// <returns></returns> private static ModelManager2 Load(string modelFileName) { Package package = null; ModelManager2 retVal = new ModelManager2(); try { package = Package.Load(modelFileName); if ((package.PackageCompare & PackageCompareTypes.ModelAnalytical) == 0) { // return(null); } retVal.Descriptors.Deserialize(package.MasterModel); retVal.Image = new ImageAdapter((package.IsFailureAnalysis) ? package.CapturedBitmap : package.MasterBitmap); } finally { if (package != null) { package.Dispose(); package = null; } } return(retVal); }
/// <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> /// Compare 2 models /// </summary> /// <param name="packagePath"></param> /// <returns></returns> public bool CompareModels(string packagePath) { ModelManager2 modelManager = ModelManager2.Load(packagePath); return(CompareModels(modelManager)); }
/// <summary> /// Compare 2 models /// </summary> /// <param name="modelManager"></param> /// <returns></returns> public bool CompareModels(ModelManager2 modelManager) { bool success = true; // Analyze(); modelManager.Analyze(); StreamWriter streamWriter = null; try { string found = "<Found>"; string notFound = "<NotFound>"; streamWriter = new StreamWriter(new MemoryStream(), System.Text.ASCIIEncoding.ASCII); #if DEBUG int debugCount = 0; #endif // DEBUG foreach (DescriptorInfo descriptorToFind in modelManager._descriptorManager.SelectedDescriptors) { bool match = _descriptorManager.IsDescriptorMatch(descriptorToFind, streamWriter); success &= match; streamWriter.Flush(); if (match) { // add to "found" section found += System.Text.ASCIIEncoding.ASCII.GetString(((MemoryStream)(streamWriter.BaseStream)).GetBuffer()).Trim('\0'); } else { // add to "NotFound" section notFound += System.Text.ASCIIEncoding.ASCII.GetString(((MemoryStream)(streamWriter.BaseStream)).GetBuffer()).Trim('\0'); } #if DEBUG debugCount++; #endif // DEBUG } found += "</Found>"; notFound += "</NotFound>"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("<DescriptorsDifferences result='" + success.ToString() + "'>" + found + notFound + "</DescriptorsDifferences>"); _modelDifferences = xmlDoc.DocumentElement; } finally { if (streamWriter != null) { streamWriter.Close(); streamWriter = null; } } if (success == false) { _failurePackage = Package.Create(true); _failurePackage.PackageCompare = PackageCompareTypes.ModelAnalytical; _failurePackage.MasterBitmap = ImageUtility.ToBitmap(modelManager.Image); // if MasterBitmap clonethe bmp, we need to dispose the original here _failurePackage.MasterModel = modelManager.Descriptors.Serialize(); // if MasterModel clone the stream, we need to close it here _failurePackage.CapturedBitmap = ImageUtility.ToBitmap(this.Image); // if MasterBitmap clonethe bmp, we need to dispose the original here _failurePackage.XmlDiff = this.ModelDifferences; } return(success); }
/// <summary> /// Create an instance of VScan with not image /// </summary> public VScan() { VScan.mVScan.Add(this); _originalData = new ModelManager2(); _filteredData = new ModelManager2(); }