/// <summary> /// Removes all segments in a layer with the specified order positions, and reclaims space. Other segments have their positions renumbered accordingly. /// </summary> /// <param name="removepos">the list of the positions to remove segments from. This list need not be ordered.</param> public virtual void Remove(int[] removepos) { SySal.TotalScan.Segment zs = new SySal.TotalScan.Segment(new SySal.Tracking.MIPEmulsionTrackInfo(), null); int dn = 0; foreach (int lyi in removepos) { if (Segments[lyi] != zs) { dn++; Segments[lyi] = zs; } } int n = Segments.Length; SySal.TotalScan.Segment[] newsegs = new Segment[n - dn]; int i, j; for (i = j = 0; i < n; i++) { if (Segments[i] != zs) { newsegs[j] = Segments[i]; if (newsegs[j] != null) { ((Segment)newsegs[j]).SetLayer(this, j); } j++; } } Segments = newsegs; }
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"); }
/// <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; } }
/// <summary> /// Makes a copy of a segment, providing minimum functions of a SySal.TotalScan.Flexi.Segment. /// </summary> /// <param name="s">the segment to be copied.</param> /// <param name="ds">the dataset to assign the segment to.</param> /// <returns>the copy of the segment.</returns> public static SySal.TotalScan.Flexi.Segment Copy(SySal.TotalScan.Segment s, SySal.TotalScan.Flexi.DataSet ds) { if (s is SySal.TotalScan.Flexi.Segment) { SySal.TotalScan.Flexi.Segment ns = (s as SySal.TotalScan.Flexi.Segment).Clone() as SySal.TotalScan.Flexi.Segment; ns.DataSet = ds; return(ns); } return(new SySal.TotalScan.Flexi.Segment(s, ds)); }
/// <summary> /// Seeks a kink in a track. /// </summary> /// <param name="t">the track where the kink is to be sought.</param> /// <param name="allowedkink">the number of entries must be identical to the number of segments of the track; then, the kink is checked for segments whose corresponding entry is set to <c>true</c> in this array.</param> public KinkSearchResult(SySal.TotalScan.Track t, bool[] allowedkink) { SySal.TotalScan.Segment[] segs = new SySal.TotalScan.Segment[t.Length]; int i; for (i = 0; i < t.Length; i++) { SySal.Tracking.MIPEmulsionTrackInfo info = t[i].Info; segs[i] = new SySal.TotalScan.Segment(info, new SySal.TotalScan.NullIndex()); } ComputeResult(segs, allowedkink); }
/// <summary> /// Seeks a kink in a track using the default requirements of the procedure (3/5 base tracks in the first plates, kink sought in the first 4 plates). /// </summary> /// <param name="tk">the track where the kink is being sought.</param> public KinkSearchResult(SySal.TotalScan.Flexi.Track tk) { SySal.Tracking.MIPEmulsionTrackInfo[] info = tk.BaseTracks; System.Collections.ArrayList ar = new System.Collections.ArrayList(); int i = info.Length - 1; double lastz = 0.0; if (i >= 0) { lastz = info[i].TopZ; ar.Add(info[i]); while (--i >= 0) { if (Math.Round((info[i].TopZ - lastz) / 1300.0) >= 1.0) { ar.Add(info[i]); lastz = info[i].TopZ; } } } if (ar.Count < 3) { TransverseSlopeRMS = LongitudinalSlopeRMS = TransverseMaxDeltaSlopeRatio = LongitudinalMaxDeltaSlopeRatio = KinkDelta = -1.0; KinkIndex = -1; ExceptionMessage = "At least 3 base tracks are needed to search for a kink."; return; } SySal.TotalScan.Segment[] segs = new SySal.TotalScan.Segment[ar.Count]; bool [] allowedkink = new bool[segs.Length - 1]; lastz = ((SySal.Tracking.MIPEmulsionTrackInfo)ar[0]).TopZ; for (i = 0; i < segs.Length; i++) { segs[i] = new SySal.TotalScan.Segment((SySal.Tracking.MIPEmulsionTrackInfo)ar[segs.Length - i - 1], new SySal.TotalScan.NullIndex()); if (i < segs.Length - 1 && Math.Round((segs[i].Info.TopZ - lastz) / 1300.0) <= 3.0) { allowedkink[i] = true; } } ComputeResult(segs, allowedkink); if (Math.Round((((SySal.Tracking.MIPEmulsionTrackInfo)ar[2]).TopZ - (lastz = ((SySal.Tracking.MIPEmulsionTrackInfo)ar[0]).TopZ)) / 1300.0) > 4.0) { TransverseMaxDeltaSlopeRatio = LongitudinalMaxDeltaSlopeRatio = KinkDelta = -1.0; KinkIndex = -1; ExceptionMessage = "At least 3 base tracks must be found in the 5 most upstream plates to search for a kink."; return; } if (KinkIndex >= 0) { KinkIndex = (int)segs[KinkIndex].Info.Field; } }
/// <summary> /// Adds segments to an existing layer with a specified mapping transformation. /// </summary> /// <param name="lay">the layer that is to receive the new segments.</param> /// <param name="addsegs">the segments to be added.</param> /// <param name="calinfo">the mapping transformation to be used.</param> public void AddToLayer(SySal.TotalScan.Flexi.Layer lay, SySal.TotalScan.Flexi.Segment [] addsegs, SySal.DAQSystem.Scanning.IntercalibrationInfo calinfo) { int i; SySal.TotalScan.Segment [] segs = new SySal.TotalScan.Segment[addsegs.Length]; for (i = 0; i < addsegs.Length; i++) { SySal.Tracking.MIPEmulsionTrackInfo info = addsegs[i].Info; info.Slope = calinfo.Deform(info.Slope); info.Intercept = calinfo.Transform(info.Intercept); addsegs[i].SetInfo(info); segs[i] = addsegs[i]; } lay.AddSegments(segs); }
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 a new Segment from a TotalScan Segment. /// </summary> /// <param name="seg">the segment to copy.</param> /// <param name="ds">the dataset marker to assign this data element to.</param> /// <remarks>The information of the original layer and track are lost.</remarks> public Segment(SySal.TotalScan.Segment seg, DataSet ds) { m_Index = seg.Index; m_Info = seg.Info; m_DataSet = ds; }
internal static double fSegTrackN(object o) { SySal.TotalScan.Segment s = (SySal.TotalScan.Segment)o; return(s.TrackOwner == null ? 0.0 : (double)s.TrackOwner.Length); }
internal static double fSegTrackPos(object o) { SySal.TotalScan.Segment s = (SySal.TotalScan.Segment)o; return(s.TrackOwner == null ? -1.0 : (double)s.PosInTrack); }
internal static double fSegDownVIP(object o) { SySal.TotalScan.Segment s = (SySal.TotalScan.Segment)o; return(s.TrackOwner == null || s.TrackOwner.Downstream_Vertex == null ? -1.0 : (double)s.TrackOwner.Downstream_Impact_Parameter); }
internal static double fSegDownVN(object o) { SySal.TotalScan.Segment s = (SySal.TotalScan.Segment)o; return(s.TrackOwner == null || s.TrackOwner.Downstream_Vertex == null ? -1.0 : (double)s.TrackOwner.Downstream_Vertex.Length); }
internal static double fSegUpVID(object o) { SySal.TotalScan.Segment s = (SySal.TotalScan.Segment)o; return(s.TrackOwner == null || s.TrackOwner.Upstream_Vertex == null ? -1.0 : (double)s.TrackOwner.Upstream_Vertex.Id); }