public VertexFitForm(string name, GDI3D.Control.GDIDisplay gdidisp, SySal.TotalScan.Flexi.Volume v) { InitializeComponent(); m_V = v; m_FitName = name; m_gdiDisplay = gdidisp; m_ParentSlopes.X = 0.0; m_ParentSlopes.Y = 0.059; txtParentSX.Text = m_ParentSlopes.X.ToString(System.Globalization.CultureInfo.InvariantCulture); txtParentSY.Text = m_ParentSlopes.Y.ToString(System.Globalization.CultureInfo.InvariantCulture); Text = "VertexFit \"" + name + "\""; }
/// <summary> /// Adds segments, tracks and vertices of a volume to another one. /// </summary> /// <param name="refvol">the volume to be augmented with the content of the other.</param> /// <param name="addvol">segments, tracks and vertices from this volume are added to the other.</param> /// <param name="ds">the dataset that should be assigned to imported tracks.</param> /// <param name="fds">the dataset that should be imported; if this parameter is <c>null</c>, all datasets are imported.</param> /// <param name="flt">track mapping filter function.</param> /// <param name="logstrw">the stream where logging information is to be dumped; set to <c>null</c> to disable logging.</param> public void AddToVolume(SySal.TotalScan.Flexi.Volume refvol, SySal.TotalScan.Flexi.Volume addvol, SySal.TotalScan.Flexi.DataSet ds, SySal.TotalScan.Flexi.DataSet fds, MapManager.dMapFilter flt, System.IO.TextWriter logstrw) { if (logstrw != null) { logstrw.WriteLine("Begin AddToVolume."); } #if !DEBUG try { #endif int i, j, n; SySal.DAQSystem.Scanning.IntercalibrationInfo[] calinfo = new SySal.DAQSystem.Scanning.IntercalibrationInfo[addvol.Layers.Length]; for (i = 0; i < addvol.Layers.Length; i++) { for (j = 0; j < refvol.Layers.Length && (refvol.Layers[j].BrickId != addvol.Layers[i].BrickId || refvol.Layers[j].SheetId != addvol.Layers[i].SheetId || refvol.Layers[j].Side != addvol.Layers[i].Side); j++) { ; } if (j == refvol.Layers.Length) { throw new Exception("No reference layer found for Brick/Sheet/Side = " + addvol.Layers[i].BrickId + "/" + addvol.Layers[i].SheetId + "/" + addvol.Layers[i].Side); } if (logstrw != null) { logstrw.WriteLine("Seeking mapping for layer " + i + " Brick/Sheet/Side " + refvol.Layers[i].BrickId + "/" + refvol.Layers[i].SheetId + "/" + refvol.Layers[i].Side); } calinfo[i] = MapTransform(MapManager.ExtractMap(refvol.Layers[j], (MapSide)refvol.Layers[j].Side, flt, true), MapManager.ExtractMap(addvol.Layers[i], (MapSide)refvol.Layers[j].Side, flt, true), null, logstrw); } for (i = 0; i < addvol.Layers.Length; i++) { SySal.TotalScan.Layer lay = addvol.Layers[i]; n = lay.Length; SySal.DAQSystem.Scanning.IntercalibrationInfo cinfo = calinfo[i]; SySal.DAQSystem.Scanning.IntercalibrationInfo alinfo = new SySal.DAQSystem.Scanning.IntercalibrationInfo(); SySal.TotalScan.AlignmentData al = lay.AlignData; alinfo.MXX = al.AffineMatrixXX * cinfo.MXX + al.AffineMatrixXY * cinfo.MYX; alinfo.MXY = al.AffineMatrixXX * cinfo.MXY + al.AffineMatrixXY * cinfo.MYY; alinfo.MYX = al.AffineMatrixYX * cinfo.MXX + al.AffineMatrixYY * cinfo.MYX; alinfo.MYY = al.AffineMatrixYX * cinfo.MXY + al.AffineMatrixYY * cinfo.MYY; double rx = lay.RefCenter.X - cinfo.RX; double ry = lay.RefCenter.Y - cinfo.RY; alinfo.RX = lay.RefCenter.X; alinfo.RY = lay.RefCenter.Y; double dx = cinfo.MXX * rx + cinfo.MXY * ry - rx + cinfo.TX; double dy = cinfo.MYX * rx + cinfo.MYY * ry - ry + cinfo.TY; alinfo.TX = al.AffineMatrixXX * dx + al.AffineMatrixXY * dy + al.TranslationX; alinfo.TY = al.AffineMatrixYX * dx + al.AffineMatrixYY * dy + al.TranslationY; for (j = 0; j < n; j++) { SySal.TotalScan.Flexi.Segment seg = (SySal.TotalScan.Flexi.Segment)lay[j]; SySal.Tracking.MIPEmulsionTrackInfo info = seg.OriginalInfo; info.Slope = alinfo.Deform(info.Slope); info.Intercept = alinfo.Transform(info.Intercept); seg.SetInfo(info); } } if (logstrw != null) { logstrw.Write("Importing volume..."); } refvol.ImportVolume(ds, addvol, fds); if (logstrw != null) { logstrw.WriteLine("Done."); } #if !DEBUG } catch (Exception x) { if (logstrw != null) { logstrw.WriteLine("Error:\r\n" + x.ToString()); } } finally { if (logstrw != null) { logstrw.WriteLine("End AddToVolume."); } } #endif }
static void Main(string[] args) { bool postolDefined = false; bool slopetolDefined = false; bool mapsizeDefined = false; bool maxposoffsetDefined = false; bool minmatchesDefined = false; bool quickDefined = false; bool inputrefFileDefined = false; bool inputaddFileDefined = false; bool outputFileDefined = false; bool refdatasetDefined = false; bool adddatasetDefined = false; bool filterdatasetDefined = false; bool inputConfigDefined = false; bool logfileDefined = false; bool filterDefined = false; bool refbrickDefined = false; bool addbrickDefined = false; string FilterText = ""; string RefFileIn = ""; string AddFileIn = ""; string OutFile = ""; string RefDataSetName = ""; string AddDataSetName = ""; string FilterDataSetName = ""; string ConfigFile = ""; string LogFile = null; long RefBrick = 0; long AddBrick = 0; SySal.Processing.MapMerge.MapMerger MM = new SySal.Processing.MapMerge.MapMerger(); SySal.Processing.MapMerge.Configuration C = (SySal.Processing.MapMerge.Configuration)MM.Config; SySal.Processing.MapMerge.MapManager.dMapFilter Filter = null; try { int argnum; for (argnum = 0; argnum < args.Length; argnum++) { switch (args[argnum].ToLower()) { case swEditConfig: { System.Windows.Forms.Application.EnableVisualStyles(); System.Xml.Serialization.XmlSerializer xmls2 = new System.Xml.Serialization.XmlSerializer(typeof(SySal.Processing.MapMerge.Configuration)); try { C = (SySal.Processing.MapMerge.Configuration)xmls2.Deserialize(new System.IO.StringReader(System.IO.File.ReadAllText(args[argnum + 1]))); } catch (Exception) { }; SySal.Processing.MapMerge.EditConfigForm ec = new SySal.Processing.MapMerge.EditConfigForm(); ec.C = C; if (ec.ShowDialog() == DialogResult.OK) { System.IO.StringWriter w = new System.IO.StringWriter(); xmls2.Serialize(w, C); System.IO.File.WriteAllText(args[argnum + 1], w.ToString()); } return; } case swPosTol: { postolDefined = true; C.PosTol = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } case swSlopeTol: { slopetolDefined = true; C.SlopeTol = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } case swMaxOffset: { maxposoffsetDefined = true; C.MaxPosOffset = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } case swMapSize: { mapsizeDefined = true; C.MapSize = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } case swMinMatches: { minmatchesDefined = true; C.MinMatches = System.Convert.ToInt32(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } case swQuick: { quickDefined = true; break; } case swFilter: { filterDefined = true; FilterText = args[argnum + 1]; argnum++; break; } case swRefInput: { inputrefFileDefined = true; RefFileIn = args[argnum + 1]; argnum++; break; } case swAddInput: { inputaddFileDefined = true; AddFileIn = args[argnum + 1]; argnum++; break; } case swOutput: { outputFileDefined = true; OutFile = args[argnum + 1]; argnum++; break; } case swConfig: { inputConfigDefined = true; ConfigFile = args[argnum + 1]; argnum++; break; } case swRefDataSet: { refdatasetDefined = true; RefDataSetName = args[argnum + 1]; argnum++; break; } case swAddDataSet: { adddatasetDefined = true; AddDataSetName = args[argnum + 1]; argnum++; break; } case swFilterDataSet: { filterdatasetDefined = true; FilterDataSetName = args[argnum + 1]; argnum++; break; } case swLog: { logfileDefined = true; LogFile = args[argnum + 1]; argnum++; break; } case swRefBrick: { refbrickDefined = true; RefBrick = System.Convert.ToInt64(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } case swAddBrick: { addbrickDefined = true; AddBrick = System.Convert.ToInt64(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture); argnum++; break; } default: throw new Exception("Unsupported switch: \"" + args[argnum] + "\"."); } } if (quickDefined) { C.FavorSpeedOverAccuracy = true; } if (filterDefined) { Filter = new SySal.Processing.MapMerge.MapManager.dMapFilter(new ObjFilter(SegmentFilterFunctions, FilterText).Value); } if (inputConfigDefined) { System.Xml.Serialization.XmlSerializer xmls1 = new System.Xml.Serialization.XmlSerializer(typeof(SySal.Processing.MapMerge.Configuration)); System.IO.StreamReader r1 = new System.IO.StreamReader(ConfigFile); C = (SySal.Processing.MapMerge.Configuration)xmls1.Deserialize(r1); r1.Close(); } if (inputrefFileDefined == false) { throw new Exception("Reference volume must be defined."); } if (refdatasetDefined == false) { RefDataSetName = "TSR"; } if (inputaddFileDefined == false) { throw new Exception("Please define the volume to be imported."); } if (adddatasetDefined == false) { throw new Exception("Please define the dataset name to assign to imported data."); } if (outputFileDefined == false) { throw new Exception("The output file must be defined."); } } catch (Exception x) { Console.WriteLine("Usage: MapMerge.exe {parameters}"); Console.WriteLine("parameters"); Console.WriteLine(swPosTol + " -> position tolerance (optional)."); Console.WriteLine(swSlopeTol + " -> slope tolerance (optional)."); Console.WriteLine(swMapSize + " -> map size (optional)."); Console.WriteLine(swMaxOffset + " -> maximum position offset (optional)."); Console.WriteLine(swMinMatches + " -> minimum number of matches per map (optional)."); Console.WriteLine(swQuick + " -> favor speed over accuracy (optional)."); Console.WriteLine(swRefInput + " -> reference volume."); Console.WriteLine(swRefDataSet + " -> dataset name to assign to reference data (default is \"TSR\")."); Console.WriteLine(swRefBrick + " -> reset reference brick to specified brick number."); Console.WriteLine(swAddInput + " -> volume to import."); Console.WriteLine(swAddDataSet + " -> dataset name to assign to imported data."); Console.WriteLine(swFilterDataSet + " -> dataset name to filter imported data (leave blank for no filter)."); Console.WriteLine(swAddBrick + " -> reset brick to assign to imported data."); Console.WriteLine(swOutput + " -> output file name."); Console.WriteLine(swLog + " -> log file (optional) - use \"con\" for console output."); Console.WriteLine(swConfig + " -> configuration file (optional)."); Console.WriteLine(swFilter + " -> selection function for track matching (optional)."); Console.WriteLine(); Console.WriteLine("Variables that can be used for track filtering:"); foreach (FilterF ff in SegmentFilterFunctions) { Console.WriteLine(ff.Name + " -> " + ff.HelpText); } Console.WriteLine(); Console.WriteLine(x.ToString()); return; } System.IO.TextWriter logw = null; if (logfileDefined) { if (String.Compare(LogFile.Trim(), "con", true) == 0) { logw = Console.Out; } else { logw = new System.IO.StreamWriter(LogFile); } } MM.Config = C; SySal.TotalScan.NamedAttributeIndex.RegisterFactory(); SySal.TotalScan.BaseTrackIndex.RegisterFactory(); SySal.TotalScan.MIPMicroTrackIndex.RegisterFactory(); SySal.OperaDb.TotalScan.DBMIPMicroTrackIndex.RegisterFactory(); SySal.OperaDb.TotalScan.DBNamedAttributeIndex.RegisterFactory(); SySal.TotalScan.Flexi.Volume refv = new SySal.TotalScan.Flexi.Volume(); SySal.TotalScan.Flexi.DataSet rds = new SySal.TotalScan.Flexi.DataSet(); rds.DataId = RefBrick; rds.DataType = RefDataSetName; refv.ImportVolume(rds, (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(RefFileIn, typeof(SySal.TotalScan.Volume))); if (RefBrick > 0) { int n = refv.Layers.Length; int i; for (i = 0; i < n; i++) { if (refv.Layers[i].BrickId == 0) { ((SySal.TotalScan.Flexi.Layer)refv.Layers[i]).SetBrickId(RefBrick); } } } SySal.TotalScan.Flexi.DataSet ads = new SySal.TotalScan.Flexi.DataSet(); ads.DataId = AddBrick; ads.DataType = AddDataSetName; SySal.TotalScan.Flexi.DataSet fds = new SySal.TotalScan.Flexi.DataSet(); if (FilterDataSetName.Length > 0) { fds.DataId = AddBrick; fds.DataType = FilterDataSetName.Trim(); } else { fds = null; } SySal.TotalScan.Flexi.Volume addv = new SySal.TotalScan.Flexi.Volume(); addv.ImportVolume(ads, (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(AddFileIn, typeof(SySal.TotalScan.Volume)), fds); if (AddBrick > 0) { int n = addv.Layers.Length; int i; for (i = 0; i < n; i++) { if (addv.Layers[1].BrickId == 0) { ((SySal.TotalScan.Flexi.Layer)addv.Layers[i]).SetBrickId(AddBrick); } } } MM.AddToVolume(refv, addv, ads, null, Filter, logw); if (logw != null && logw != Console.Out) { logw.Flush(); logw.Close(); logw = null; } Console.WriteLine("Result written to " + SySal.OperaPersistence.Persist(OutFile, refv)); }
public static VertexFitForm Browse(string name, GDI3D.Control.GDIDisplay gdidisp, TrackSelector updatefits, SySal.TotalScan.Flexi.Volume v) { foreach (VertexFitForm b in AvailableBrowsers) { if (String.Compare(b.FitName, name, true) == 0) { b.BringToFront(); return(b); } } VertexFitForm newb = new VertexFitForm(name, gdidisp, v); newb.Show(); AvailableBrowsers.Add(newb); newb.m_TrackSelector = updatefits; return(newb); }