/// <summary> /// Copies an existing layer into a FlexiLayer. /// </summary> /// <param name="ly">the original layer.</param> /// <param name="ds">the dataset to which the segments of this layer should be attached.</param> /// <remarks>The segments in the original dataset are copied to the new one, setting the LayerOwner and the position in the layer to the newly created object.</remarks> public Layer(SySal.TotalScan.Layer ly, SySal.TotalScan.Flexi.DataSet ds) : base() { m_Id = ly.Id; m_RefCenter = ly.RefCenter; m_BrickId = ly.BrickId; m_SheetId = ly.SheetId; m_Side = ly.Side; m_DownstreamZ = ly.DownstreamZ; m_UpstreamZ = ly.UpstreamZ; m_DownstreamZ_Updated = true; m_UpstreamZ_Updated = true; SetAlignmentData(ly.AlignData); m_RadiationLength = ly.RadiationLengh; m_UpstreamRadiationLength = ly.UpstreamRadiationLength; m_DownstreamRadiationLength = ly.DownstreamRadiationLength; int n = ly.Length; int i; Segments = new SySal.TotalScan.Segment[n]; for (i = 0; i < n; i++) { Segment seg = SySal.TotalScan.Flexi.Segment.Copy(ly[i], ds); seg.SetLayer(this, i); Segments[i] = seg; } }
static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Usage: ExtractLinkedIndex.exe <TSR OPERA persistence path> <sheet id> <output ASCII file>"); Console.WriteLine("or: ExtractLinkedIndex.exe <TSR OPERA persistence path> <sheet id> <output TLG file>"); return; } SySal.TotalScan.Volume v = (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(args[0], typeof(SySal.TotalScan.Volume)); int i, n; n = Convert.ToInt32(args[1]); SySal.TotalScan.Layer layer = null; for (i = 0; i < v.Layers.Length; i++) { layer = v.Layers[i]; if (layer.SheetId == n) { break; } } n = layer.Length; Console.WriteLine("Found layer " + layer.Id + " SheetId " + layer.SheetId); Console.WriteLine(n + " tracks found"); int selected = 0; if (args[2].ToLower().EndsWith(".tlg")) { System.Collections.ArrayList ar = new System.Collections.ArrayList(); for (i = 0; i < n; i++) { SySal.TotalScan.Segment s = layer[i]; if (s.TrackOwner != null && s.TrackOwner.Length > 1) { ar.Add(i); selected++; } } SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment ai = new SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment(); ai.Ids = (int[])ar.ToArray(typeof(int)); SySal.OperaPersistence.Persist(args[2], ai); } else { System.IO.StreamWriter w = new System.IO.StreamWriter(args[2], false); w.WriteLine("Index"); for (i = 0; i < n; i++) { SySal.TotalScan.Segment s = layer[i]; if (s.TrackOwner != null && s.TrackOwner.Length > 1) { w.WriteLine(i); selected++; } } w.Flush(); w.Close(); } Console.WriteLine(selected + " tracks selected"); }
static SySal.Tracking.MIPEmulsionTrackInfo[] layExtractMap(SySal.TotalScan.Layer lay, dMapFilter flt, bool useoriginal) { System.Collections.ArrayList ar = new System.Collections.ArrayList(); int n = lay.Length; int i; for (i = 0; i < n; i++) { SySal.Tracking.MIPEmulsionTrackInfo info = useoriginal ? lay[i].OriginalInfo : lay[i].Info; if (flt == null || flt(lay[i])) { ar.Add(info); } } return((SySal.Tracking.MIPEmulsionTrackInfo[])ar.ToArray(typeof(SySal.Tracking.MIPEmulsionTrackInfo))); }
/// <summary> /// Removes the layer at the specified position. /// </summary> /// <param name="pos">the position hosting the layer to be removed.</param> /// <remarks>the ids of the layers following the removed layer are recomputed.</remarks> public virtual void Remove(int pos) { int n = Items.Length; SySal.TotalScan.Layer[] newitems = new SySal.TotalScan.Layer[n - 1]; int i; for (i = 0; i < pos; i++) { newitems[i] = Items[i]; } for (++i; i < n; i++) { ((Layer)(newitems[i - 1] = Items[i])).SetId(i - 1); } Items = newitems; }
static SySal.Tracking.MIPEmulsionTrackInfo[] layExtractMap(SySal.TotalScan.Layer lay, SySal.BasicTypes.Rectangle r, dMapFilter flt, bool useoriginal) { System.Collections.ArrayList ar = new System.Collections.ArrayList(); int n = lay.Length; int i; for (i = 0; i < n; i++) { SySal.Tracking.MIPEmulsionTrackInfo info = useoriginal ? lay[i].OriginalInfo : lay[i].Info; if (info.Intercept.X < r.MinX || info.Intercept.X > r.MaxX || info.Intercept.Y < r.MinY || info.Intercept.Y > r.MaxY) { continue; } if (flt == null || flt(lay[i])) { ar.Add(info); } } return((SySal.Tracking.MIPEmulsionTrackInfo[])ar.ToArray(typeof(SySal.Tracking.MIPEmulsionTrackInfo))); }
/// <summary> /// Inserts a layer in Z order (using its <c>RefCenter.Z</c> information). /// </summary> /// <param name="ly">the layer to be inserted.</param> /// <remarks>the ids of the layers (including the newly inserted one) are recomputed.</remarks> public virtual void Insert(Layer ly) { int n = Items.Length; SySal.TotalScan.Layer[] newitems = new SySal.TotalScan.Layer[n + 1]; int i, j; double z = ly.RefCenter.Z; for (i = 0; i < n && z < Items[i].RefCenter.Z; i++) { ; } for (j = 0; j < i; j++) { newitems[j] = Items[j]; } newitems[j] = ly; ly.SetId(j); while (i < n) { ((Layer)(newitems[++j] = Items[i++])).SetId(j); } Items = newitems; }
static void Main(string[] args) { // // TODO: Add code to start application here // if (args.Length != 3) { System.Xml.Serialization.XmlSerializer xmls = null; Console.WriteLine("BatchReconstruct - performs volume reconstruction using LinkedZones from TLG files or OPERA DB tables."); Console.WriteLine("usage: batchreconstruct <XML list file> <output Opera persistence path> <XML config Opera persistence path>"); Console.WriteLine("or: batchreconstruct <DB volume> <output Opera persistence path> <XML config Opera persistence path>"); Console.WriteLine("or: batchreconstruct <input OPERA persistence path> <output Opera persistence path> <XML config Opera persistence path>"); Console.WriteLine("Full volumes are reprocessed for topological reconstruction only."); Console.WriteLine("---------------- DB volume example: db:\\8\\17723900.vol"); Console.WriteLine("First number is ID_EVENTBRICK, second is ID_VOLUME"); Console.WriteLine("---------------- XML list file example (source = filesystem):"); Input inputlist = new Input(); inputlist.Zones = new Zone[3]; inputlist.Zones[0] = new Zone(); inputlist.Zones[0].SheetId = 8; inputlist.Zones[0].Source = @"\\myserver.mydomain\myshare\plate_08.tlg"; inputlist.Zones[0].Z = 0.0; inputlist.Zones[0].AlignmentIgnoreListPath = @"\\myserver\mydomain\myshare\alignignore_plate_08.txt"; inputlist.Zones[1] = new Zone(); inputlist.Zones[1].SheetId = 9; inputlist.Zones[1].Source = @"\\myserver.mydomain\myshare\plate_09.tlg"; inputlist.Zones[1].Z = -1300.0; inputlist.Zones[2] = new Zone(); inputlist.Zones[2].SheetId = 10; inputlist.Zones[2].Source = @"\\myserver.mydomain\myshare\plate_10.tlg"; inputlist.Zones[2].Z = -2600.0; xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Input)); xmls.Serialize(Console.Out, inputlist); Console.WriteLine(); Console.WriteLine("---------------- XML list file example (source = OperaDB):"); inputlist.Zones[0].Source = @"db:\1002323.tlg"; inputlist.Zones[1].Source = @"db:\1006326.tlg"; inputlist.Zones[2].Source = @"db:\1009724.tlg"; xmls.Serialize(Console.Out, inputlist); Console.WriteLine(); Console.WriteLine("---------------- XML config file syntax:"); Console.WriteLine("XML configuration syntax:"); BatchReconstruct.Config C = new BatchReconstruct.Config(); C.ReconstructorConfig = (Configuration) new AlphaOmegaReconstructor().Config; xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Config)); xmls.Serialize(Console.Out, C); Console.WriteLine(); return; } #if !(DEBUG) try #endif { AlphaOmegaReconstructor R = new AlphaOmegaReconstructor(); System.Xml.Serialization.XmlSerializer xmls = null; xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Config)); Config config = (Config)xmls.Deserialize(new System.IO.StringReader(((SySal.OperaDb.ComputingInfrastructure.ProgramSettings)SySal.OperaPersistence.Restore(args[2], typeof(SySal.OperaDb.ComputingInfrastructure.ProgramSettings))).Settings)); R.Config = (SySal.Management.Configuration)config.ReconstructorConfig; R.Progress = new SySal.TotalScan.dProgress(Progress); R.Report = new SySal.TotalScan.dReport(Report); System.Text.RegularExpressions.Regex volrgx = new System.Text.RegularExpressions.Regex(@"db:\\(\d+)\\(\d+)\.vol"); System.Text.RegularExpressions.Match mrgx = volrgx.Match(args[0].ToLower()); Input inputlist = null; SySal.TotalScan.Volume OldVol = null; if (args[0].ToLower().EndsWith(".tsr")) { OldVol = (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(args[0], typeof(SySal.TotalScan.Volume)); } else { if (mrgx.Success && mrgx.Length == args[0].Length) { SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord(); SySal.OperaDb.OperaDbConnection conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword); conn.Open(); System.Data.DataSet ds = new System.Data.DataSet(); new SySal.OperaDb.OperaDbDataAdapter("SELECT TB_VOLUME_SLICES.ID_PLATE, TB_VOLUME_SLICES.ID_ZONE, VW_PLATES.Z FROM TB_VOLUME_SLICES INNER JOIN VW_PLATES ON (TB_VOLUME_SLICES.ID_EVENTBRICK = VW_PLATES.ID_EVENTBRICK AND TB_VOLUME_SLICES.ID_PLATE = VW_PLATES.ID) WHERE TB_VOLUME_SLICES.DAMAGED = 'N' AND TB_VOLUME_SLICES.ID_EVENTBRICK = " + mrgx.Groups[1].Value + " AND TB_VOLUME_SLICES.ID_VOLUME = " + mrgx.Groups[2].Value + " ORDER BY VW_PLATES.Z DESC", conn, null).Fill(ds); inputlist = new Input(); inputlist.Zones = new Zone[ds.Tables[0].Rows.Count]; int sli; for (sli = 0; sli < ds.Tables[0].Rows.Count; sli++) { inputlist.Zones[sli] = new Zone(); inputlist.Zones[sli].SheetId = Convert.ToInt32(ds.Tables[0].Rows[sli][0]); inputlist.Zones[sli].Source = "db:\\" + mrgx.Groups[1] + "\\" + ds.Tables[0].Rows[sli][1].ToString() + ".tlg"; inputlist.Zones[sli].Z = Convert.ToDouble(ds.Tables[0].Rows[sli][2]); } SySal.OperaPersistence.Connection = conn; SySal.OperaPersistence.LinkedZoneDetailLevel = SySal.OperaDb.Scanning.LinkedZone.DetailLevel.BaseFull; } else { System.IO.StreamReader r = new System.IO.StreamReader(args[0]); xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Input)); inputlist = (Input)xmls.Deserialize(r); r.Close(); } int i, j, c; for (i = 0; i < inputlist.Zones.Length; i++) { for (j = i + 1; j < inputlist.Zones.Length; j++) { if (inputlist.Zones[i].SheetId == inputlist.Zones[j].SheetId) { Console.WriteLine("Duplicate SheetId found. Sheets will be renumbered with the default sequence."); for (j = 0; j < inputlist.Zones.Length; j++) { inputlist.Zones[j].SheetId = j; } i = inputlist.Zones.Length; break; } } } for (i = 0; i < inputlist.Zones.Length; i++) { SySal.Scanning.Plate.IO.OPERA.LinkedZone lz = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(inputlist.Zones[i].Source, typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone)); c = lz.Length; SySal.TotalScan.Segment[] segs = new SySal.TotalScan.Segment[c]; double[] zcor = new double[c]; for (j = 0; j < c; j++) { zcor[j] = lz[j].Info.Intercept.Z; } double zmean = NumericalTools.Fitting.Average(zcor); double dgap; for (j = 0; j < c; j++) { SySal.Tracking.MIPEmulsionTrackInfo info = lz[j].Info; segs[j] = new SySal.TotalScan.Segment(info, new SySal.TotalScan.BaseTrackIndex(j)); dgap = zmean - info.Intercept.Z; info.Intercept.Z = zmean; info.Intercept.X += info.Slope.X * dgap; info.Intercept.Y += info.Slope.Y * dgap; info.TopZ += dgap; info.BottomZ += dgap; info.Intercept.Z = inputlist.Zones[i].Z; double tmptopz = info.TopZ; double tmpbotz = info.BottomZ; dgap = zmean - tmptopz; info.TopZ = inputlist.Zones[i].Z - dgap; info.BottomZ = inputlist.Zones[i].Z - (tmptopz - tmpbotz) - dgap; } SySal.BasicTypes.Vector refc = new SySal.BasicTypes.Vector(); refc.Z = inputlist.Zones[i].Z; SySal.TotalScan.Layer tmpLayer = new SySal.TotalScan.Layer(i, /*System.Convert.ToInt64(mrgx.Groups[1].Value)*/ 0, (int)inputlist.Zones[i].SheetId, 0, refc); tmpLayer.AddSegments(segs); R.AddLayer(tmpLayer); if (inputlist.Zones[i].AlignmentIgnoreListPath != null && inputlist.Zones[i].AlignmentIgnoreListPath.Trim().Length != 0) { if (inputlist.Zones[i].AlignmentIgnoreListPath.ToLower().EndsWith(".tlg")) { R.SetAlignmentIgnoreList(i, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment)SySal.OperaPersistence.Restore(inputlist.Zones[i].AlignmentIgnoreListPath, typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment))).Ids); } else { System.IO.StreamReader r = new System.IO.StreamReader(inputlist.Zones[i].AlignmentIgnoreListPath.Trim()); System.Collections.ArrayList tmpignorelist = new System.Collections.ArrayList(); string line; while ((line = r.ReadLine()) != null) { try { tmpignorelist.Add(System.Convert.ToInt32(line)); } catch (Exception) { } } ; r.Close(); R.SetAlignmentIgnoreList(i, (int[])tmpignorelist.ToArray(typeof(int))); } } Console.WriteLine("Loaded sheet {0} Id {1} Tracks {2}", i, inputlist.Zones[i].SheetId, c); lz = null; } } SySal.TotalScan.Volume V = (OldVol == null) ? R.Reconstruct() : R.RecomputeVertices(OldVol); Console.WriteLine("Result written to: " + SySal.OperaPersistence.Persist(args[1], V)); } #if !(DEBUG) catch (Exception x) { Console.Error.WriteLine(x.ToString()); } #endif }
/// <summary> /// Builds an empty list. /// </summary> public LayerList() : base() { Items = new SySal.TotalScan.Layer[0]; }
/// <summary> /// Sets the layer and position within the layer for this segment. /// </summary> /// <param name="ly">the layer to attach the segment to.</param> /// <param name="lypos">the position of the segment in the layer.</param> /// <remarks>The layer receives no notification of the newly attached segment. External code must maintain the consistency.</remarks> public virtual void SetLayer(SySal.TotalScan.Layer ly, int lypos) { m_LayerOwner = ly; m_PosInLayer = lypos; }
/// <summary> /// Imports a TotalScan Volume. /// </summary> /// <param name="ds">the dataset to which the volume to be imported belongs.</param> /// <param name="v">the volume to be imported.</param> /// <param name="fds">the dataset that should be imported; if this parameter is <c>null</c>, all datasets are imported.</param> /// <remarks>The dataset filter only applies to tracks and vertices. All segments are always imported. Track/Vertex dataset consistency should be guaranteed by the user.</remarks> public virtual void ImportVolume(DataSet ds, SySal.TotalScan.Volume v, DataSet fds) { System.Collections.ArrayList dsa = new System.Collections.ArrayList(); dsa.Add(ds); SySal.BasicTypes.Cuboid c = v.Extents; if (c.MinX < m_Extents.MinX) { m_Extents.MinX = c.MinX; } if (c.MaxX > m_Extents.MaxX) { m_Extents.MaxX = c.MaxX; } if (c.MinY < m_Extents.MinY) { m_Extents.MinY = c.MinY; } if (c.MaxY > m_Extents.MaxY) { m_Extents.MaxY = c.MaxY; } if (c.MinZ < m_Extents.MinZ) { m_Extents.MinZ = c.MinZ; } if (c.MaxZ > m_Extents.MaxZ) { m_Extents.MaxZ = c.MaxZ; } if (m_Layers.Length == 0) { m_RefCenter = v.RefCenter; } int i, j; Layer[] tl = new Layer[v.Layers.Length]; bool[] isnewlayer = new bool[v.Layers.Length]; int[] oldlength = new int[v.Layers.Length]; for (i = 0; i < v.Layers.Length; i++) { for (j = 0; j < Layers.Length && (Layers[j].BrickId != v.Layers[i].BrickId || Layers[j].SheetId != v.Layers[i].SheetId || Layers[j].Side != v.Layers[i].Side); j++) { ; } if (j == Layers.Length) { isnewlayer[i] = true; tl[i] = new Layer(v.Layers[i], ds); ((LayerList)m_Layers).Insert(tl[i]); } else { isnewlayer[i] = false; tl[i] = (SySal.TotalScan.Flexi.Layer)Layers[j]; oldlength[i] = tl[i].Length; SySal.TotalScan.Flexi.Segment[] segs = new SySal.TotalScan.Flexi.Segment[v.Layers[i].Length]; SySal.TotalScan.Layer li = v.Layers[i]; for (j = 0; j < segs.Length; j++) { segs[j] = SySal.TotalScan.Flexi.Segment.Copy(li[j], ds); //new SySal.TotalScan.Flexi.Segment(li[j], ds); } tl[i].Add(segs); } } Track[] tt = null;// = new Track[v.Tracks.Length]; System.Collections.ArrayList ato = new System.Collections.ArrayList(); int[] ixremap = new int[v.Tracks.Length]; for (i = 0; i < v.Tracks.Length; i++) { SySal.TotalScan.Track otk = v.Tracks[i]; if (otk is SySal.TotalScan.Flexi.Track) { if (fds != null && SySal.TotalScan.Flexi.DataSet.AreEqual(fds, ((SySal.TotalScan.Flexi.Track)otk).DataSet) == false) { ixremap[i] = -1; continue; } } ixremap[i] = m_Tracks.Length + i; Track tk = new Track(ds, ixremap[i]); SySal.TotalScan.Flexi.DataSet tds = null; if (otk is SySal.TotalScan.Flexi.Track) { tds = ((SySal.TotalScan.Flexi.Track)otk).DataSet; } SySal.TotalScan.Attribute[] a = otk.ListAttributes(); foreach (SySal.TotalScan.Attribute a1 in a) { if (tds == null && a1.Index is SySal.TotalScan.NamedAttributeIndex && ((SySal.TotalScan.NamedAttributeIndex)a1.Index).Name.StartsWith(DataSetString)) { tds = new DataSet(); tds.DataType = ((SySal.TotalScan.NamedAttributeIndex)a1.Index).Name.Substring(DataSetString.Length); tds.DataId = (long)a1.Value; } else { tk.SetAttribute(a1.Index, a1.Value); } } if (fds != null && (tds == null || SySal.TotalScan.Flexi.DataSet.AreEqual(fds, tds))) { tds = ds; } if (tds != null) { bool found = false; foreach (SySal.TotalScan.Flexi.DataSet dsi in dsa) { if (SySal.TotalScan.Flexi.DataSet.AreEqual(dsi, tds)) { tds = dsi; found = true; break; } } if (found == false) { dsa.Add(tds); } tk.DataSet = tds; } SySal.TotalScan.Flexi.Segment[] segs = new SySal.TotalScan.Flexi.Segment[otk.Length]; for (j = 0; j < segs.Length; j++) { if (otk[j].PosInLayer >= 0) { /* * segs[j] = (SySal.TotalScan.Flexi.Segment)v.Layers[otk[j].LayerOwner.Id][otk[j].PosInLayer]; * segs[j].DataSet = tk.DataSet; */ if (isnewlayer[otk[j].LayerOwner.Id]) { segs[j] = (SySal.TotalScan.Flexi.Segment)tl[otk[j].LayerOwner.Id][otk[j].PosInLayer]; } else { segs[j] = (SySal.TotalScan.Flexi.Segment)tl[otk[j].LayerOwner.Id][oldlength[otk[j].LayerOwner.Id] + otk[j].PosInLayer]; } segs[j].DataSet = tk.DataSet; } else { (segs[j] = SySal.TotalScan.Flexi.Segment.Copy(otk[j], tk.DataSet)).SetLayer(tl[otk[j].LayerOwner.Id], -1); tl[otk[j].LayerOwner.Id].Add(new SySal.TotalScan.Flexi.Segment[1] { segs[j] }); segs[j].DataSet = tk.DataSet; } } tk.AddSegments(segs); ato.Add(tk); } tt = (SySal.TotalScan.Flexi.Track [])ato.ToArray(typeof(SySal.TotalScan.Flexi.Track)); ato.Clear(); Vertex[] tv = null; // new Vertex[v.Vertices.Length]; for (i = 0; i < v.Vertices.Length; i++) { SySal.TotalScan.Vertex ovx = v.Vertices[i]; if (ovx is SySal.TotalScan.Flexi.Vertex) { if (fds != null && SySal.TotalScan.Flexi.DataSet.AreEqual(fds, ((SySal.TotalScan.Flexi.Vertex)ovx).DataSet) == false) { continue; } } Vertex vx = new Vertex(ds, m_Vertices.Length + i); SySal.TotalScan.Flexi.DataSet tds = null; if (ovx is SySal.TotalScan.Flexi.Vertex) { tds = ((SySal.TotalScan.Flexi.Vertex)ovx).DataSet; } SySal.TotalScan.Attribute[] a = ovx.ListAttributes(); foreach (SySal.TotalScan.Attribute a1 in a) { if (tds == null && a1.Index is SySal.TotalScan.NamedAttributeIndex && ((SySal.TotalScan.NamedAttributeIndex)a1.Index).Name.StartsWith(DataSetString)) { tds = new DataSet(); tds.DataType = ((SySal.TotalScan.NamedAttributeIndex)a1.Index).Name.Substring(DataSetString.Length); tds.DataId = (long)a1.Value; } else { vx.SetAttribute(a1.Index, a1.Value); } } if (fds != null && (tds == null || SySal.TotalScan.Flexi.DataSet.AreEqual(fds, tds))) { tds = ds; } if (tds != null) { bool found = false; foreach (SySal.TotalScan.Flexi.DataSet dsi in dsa) { if (SySal.TotalScan.Flexi.DataSet.AreEqual(dsi, tds)) { tds = dsi; found = true; break; } } if (found == false) { dsa.Add(tds); } vx.DataSet = tds; } for (j = 0; j < ovx.Length; j++) { SySal.TotalScan.Track otk = ovx[j]; if (ixremap[otk.Id] < 0) { break; } if (otk.Upstream_Vertex == ovx) { vx.AddTrack(tt[ixremap[otk.Id]], false); tt[ixremap[otk.Id]].SetUpstreamVertex(vx); } else { vx.AddTrack(tt[ixremap[otk.Id]], true); tt[ixremap[otk.Id]].SetDownstreamVertex(vx); } } if (j < ovx.Length) { continue; } vx.SetPos(ovx.X, ovx.Y, ovx.Z, ovx.DX, ovx.DY, ovx.AverageDistance); ato.Add(vx); } tv = (SySal.TotalScan.Flexi.Vertex[])ato.ToArray(typeof(SySal.TotalScan.Flexi.Vertex)); ato.Clear(); ixremap = null; ((TrackList)m_Tracks).Insert(tt); ((VertexList)m_Vertices).Insert(tv); }
internal void Check(CheckMode mode, string textout, NumericalTools.Function slf, bool dumpfound, bool dumpnotfound) { Mode = mode; SelectionFunction = slf; string [] pars = new string[0]; if (slf != null) { pars = slf.ParameterList; if (pars.Length == 0) { throw new Exception("The selection function must have parameters."); } } System.IO.StreamWriter wr = null; int Searched = 0, Found = 0; SySal.DAQSystem.Scanning.IntercalibrationInfo Inv = new SySal.DAQSystem.Scanning.IntercalibrationInfo(); try { wr = new System.IO.StreamWriter(textout); wr.WriteLine("ID\tPX\tPY\tSX\tSY\tN"); SySal.TotalScan.Layer lay = null; switch (Mode) { case CheckMode.Center: lay = Vol.Layers[1]; break; case CheckMode.Upstream: lay = Vol.Layers[Vol.Layers.Length - 1]; break; case CheckMode.Downstream: lay = Vol.Layers[0]; break; default: throw new Exception("Unsupported mode"); } Inv.RX = Vol.RefCenter.X + lay.AlignData.TranslationX; Inv.RY = Vol.RefCenter.Y + lay.AlignData.TranslationY; double iden = 1.0 / (lay.AlignData.AffineMatrixXX * lay.AlignData.AffineMatrixYY - lay.AlignData.AffineMatrixXY * lay.AlignData.AffineMatrixYX); Inv.MXX = lay.AlignData.AffineMatrixYY * iden; Inv.MXY = -lay.AlignData.AffineMatrixXY * iden; Inv.MYX = -lay.AlignData.AffineMatrixYX * iden; Inv.MYY = lay.AlignData.AffineMatrixXX * iden; Inv.TX = -lay.AlignData.TranslationX; Inv.TY = -lay.AlignData.TranslationY; int tkn = Vol.Tracks.Length; int t, p; SySal.TotalScan.Track tk; string ps; double ipx, ipy, isx, isy; for (t = 0; t < tkn; t++) { tk = Vol.Tracks[t]; if (SelectionFunction != null) { for (p = 0; p < pars.Length; p++) { ps = pars[p].ToUpper(); switch (ps) { case "N": SelectionFunction[p] = tk.Length; break; case "DZ": SelectionFunction[p] = tk.Downstream_Z; break; case "UZ": SelectionFunction[p] = tk.Upstream_Z; break; case "DSX": SelectionFunction[p] = tk.Downstream_SlopeX; break; case "DSY": SelectionFunction[p] = tk.Downstream_SlopeY; break; case "USX": SelectionFunction[p] = tk.Upstream_SlopeX; break; case "USY": SelectionFunction[p] = tk.Upstream_SlopeY; break; case "D0X": SelectionFunction[p] = tk.Downstream_PosX - tk.Downstream_SlopeX * tk.Downstream_PosZ; break; case "D0Y": SelectionFunction[p] = tk.Downstream_PosY - tk.Downstream_SlopeY * tk.Downstream_PosZ; break; case "U0X": SelectionFunction[p] = tk.Upstream_PosX - tk.Upstream_SlopeX * tk.Upstream_PosZ; break; case "U0Y": SelectionFunction[p] = tk.Upstream_PosY - tk.Upstream_SlopeY * tk.Upstream_PosZ; break; case "DPX": SelectionFunction[p] = tk.Downstream_PosX + tk.Downstream_SlopeX * (tk.Downstream_Z - tk.Downstream_PosZ); break; case "DPY": SelectionFunction[p] = tk.Downstream_PosY + tk.Downstream_SlopeY * (tk.Downstream_Z - tk.Downstream_PosZ); break; case "UPX": SelectionFunction[p] = tk.Upstream_PosX + tk.Upstream_SlopeX * (tk.Upstream_Z - tk.Upstream_PosZ); break; case "UPY": SelectionFunction[p] = tk.Upstream_PosY + tk.Upstream_SlopeY * (tk.Upstream_Z - tk.Upstream_PosZ); break; default: throw new Exception("Unknown parameter " + ps); } } if (SelectionFunction.Evaluate() == 0) { continue; } } switch (Mode) { case CheckMode.Center: { if (tk.UpstreamLayerId == 2 && tk.DownstreamLayerId == 0) { Searched++; if (tk.Length == 3) { Found++; if (dumpfound) { SySal.Tracking.MIPEmulsionTrackInfo info = tk[1].Info; ipx = Inv.MXX * (info.Intercept.X - Inv.RX) + Inv.MXY * (info.Intercept.Y - Inv.RY) + Inv.TX + Inv.RX; ipy = Inv.MYX * (info.Intercept.X - Inv.RX) + Inv.MYY * (info.Intercept.Y - Inv.RY) + Inv.TY + Inv.RY; isx = Inv.MXX * info.Slope.X + Inv.MXY * info.Slope.Y; isy = Inv.MYX * info.Slope.X + Inv.MYY * info.Slope.Y; wr.WriteLine(tk.Id + "\t" + ipx.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + ipy.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isx.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isy.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + tk.Length); } } else { if (dumpnotfound) { SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo(); info.Intercept.X = tk.Downstream_PosX + tk.Downstream_SlopeX * (lay.RefCenter.Z - tk.Downstream_PosZ); info.Intercept.Y = tk.Downstream_PosY + tk.Downstream_SlopeY * (lay.RefCenter.Z - tk.Downstream_PosZ); info.Slope.X = tk.Downstream_SlopeX; info.Slope.Y = tk.Downstream_SlopeY; ipx = Inv.MXX * (info.Intercept.X - Inv.RX) + Inv.MXY * (info.Intercept.Y - Inv.RY) + Inv.TX + Inv.RX; ipy = Inv.MYX * (info.Intercept.X - Inv.RX) + Inv.MYY * (info.Intercept.Y - Inv.RY) + Inv.TY + Inv.RY; isx = Inv.MXX * info.Slope.X + Inv.MXY * info.Slope.Y; isy = Inv.MYX * info.Slope.X + Inv.MYY * info.Slope.Y; wr.WriteLine(tk.Id + "\t" + ipx.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + ipy.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isx.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isy.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + tk.Length); } } } } break; case CheckMode.Upstream: { if (tk.DownstreamLayerId == 0 && tk.Length >= (Vol.Layers.Length - 1)) { Searched++; if (tk.Length == Vol.Layers.Length) { Found++; if (dumpfound) { SySal.Tracking.MIPEmulsionTrackInfo info = tk[tk.Length - 1].Info; ipx = Inv.MXX * (info.Intercept.X - Inv.RX) + Inv.MXY * (info.Intercept.Y - Inv.RY) + Inv.TX + Inv.RX; ipy = Inv.MYX * (info.Intercept.X - Inv.RX) + Inv.MYY * (info.Intercept.Y - Inv.RY) + Inv.TY + Inv.RY; isx = Inv.MXX * info.Slope.X + Inv.MXY * info.Slope.Y; isy = Inv.MYX * info.Slope.X + Inv.MYY * info.Slope.Y; wr.WriteLine(tk.Id + "\t" + ipx.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + ipy.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isx.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isy.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + tk.Length); } } else { if (dumpnotfound) { SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo(); info.Intercept.X = tk.Upstream_PosX + tk.Upstream_SlopeX * (lay.RefCenter.Z - tk.Upstream_PosZ); info.Intercept.Y = tk.Upstream_PosY + tk.Upstream_SlopeY * (lay.RefCenter.Z - tk.Upstream_PosZ); info.Slope.X = tk.Upstream_SlopeX; info.Slope.Y = tk.Upstream_SlopeY; ipx = Inv.MXX * (info.Intercept.X - Inv.RX) + Inv.MXY * (info.Intercept.Y - Inv.RY) + Inv.TX + Inv.RX; ipy = Inv.MYX * (info.Intercept.X - Inv.RX) + Inv.MYY * (info.Intercept.Y - Inv.RY) + Inv.TY + Inv.RY; isx = Inv.MXX * info.Slope.X + Inv.MXY * info.Slope.Y; isy = Inv.MYX * info.Slope.X + Inv.MYY * info.Slope.Y; wr.WriteLine(tk.Id + "\t" + ipx.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + ipy.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isx.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isy.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + tk.Length); } } } } break; case CheckMode.Downstream: { if (tk.UpstreamLayerId == (Vol.Layers.Length - 1) && tk.Length >= (Vol.Layers.Length - 1)) { Searched++; if (tk.Length == Vol.Layers.Length) { Found++; if (dumpfound) { SySal.Tracking.MIPEmulsionTrackInfo info = tk[0].Info; ipx = Inv.MXX * (info.Intercept.X - Inv.RX) + Inv.MXY * (info.Intercept.Y - Inv.RY) + Inv.TX + Inv.RX; ipy = Inv.MYX * (info.Intercept.X - Inv.RX) + Inv.MYY * (info.Intercept.Y - Inv.RY) + Inv.TY + Inv.RY; isx = Inv.MXX * info.Slope.X + Inv.MXY * info.Slope.Y; isy = Inv.MYX * info.Slope.X + Inv.MYY * info.Slope.Y; wr.WriteLine(tk.Id + "\t" + ipx.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + ipy.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isx.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isy.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + tk.Length); } } else { if (dumpnotfound) { SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo(); info.Intercept.X = tk.Downstream_PosX + tk.Downstream_SlopeX * (lay.RefCenter.Z - tk.Downstream_PosZ); info.Intercept.Y = tk.Downstream_PosY + tk.Downstream_SlopeY * (lay.RefCenter.Z - tk.Downstream_PosZ); info.Slope.X = tk.Downstream_SlopeX; info.Slope.Y = tk.Downstream_SlopeY; ipx = Inv.MXX * (info.Intercept.X - Inv.RX) + Inv.MXY * (info.Intercept.Y - Inv.RY) + Inv.TX + Inv.RX; ipy = Inv.MYX * (info.Intercept.X - Inv.RX) + Inv.MYY * (info.Intercept.Y - Inv.RY) + Inv.TY + Inv.RY; isx = Inv.MXX * info.Slope.X + Inv.MXY * info.Slope.Y; isy = Inv.MYX * info.Slope.X + Inv.MYY * info.Slope.Y; wr.WriteLine(tk.Id + "\t" + ipx.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + ipy.ToString("F1", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isx.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + isy.ToString("F4", System.Globalization.CultureInfo.InvariantCulture) + "\t" + tk.Length); } } } } break; } } wr.Flush(); } catch (Exception x) { Console.WriteLine("Unrecoverable error:\n" + x.Message); } finally { if (wr != null) { wr.Close(); } Console.WriteLine("Searched: " + Searched); Console.WriteLine("Found: " + Found); if (Searched > 1) { double p = (double)Found / (double)Searched; Console.WriteLine("Efficiency: " + (p * 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + "% \xb1" + (Math.Sqrt(p * (1.0 - p) / Searched) * 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + "%"); } } }
/// <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 }