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 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> /// 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); }
/// <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> public virtual void ImportVolume(DataSet ds, SySal.TotalScan.Volume v) { ImportVolume(ds, v, null); }
static void Main(string[] args) { // // TODO: Add code to start application here // if (args.Length != 3 && args.Length != 4) { ShowExplanation(); return; } CheckMode mode; bool dumpfound = false, dumpnotfound = false; if (String.Compare(args[0], "/3", true) == 0) { mode = CheckMode.Center; dumpfound = false; dumpnotfound = false; } else if (String.Compare(args[0], "/3f", true) == 0) { mode = CheckMode.Center; dumpfound = true; dumpnotfound = false; } else if (String.Compare(args[0], "/3n", true) == 0) { mode = CheckMode.Center; dumpfound = false; dumpnotfound = true; } else if (String.Compare(args[0], "/3a", true) == 0) { mode = CheckMode.Center; dumpfound = true; dumpnotfound = true; } else if (String.Compare(args[0], "/u", true) == 0) { mode = CheckMode.Upstream; dumpfound = false; dumpnotfound = false; } else if (String.Compare(args[0], "/uf", true) == 0) { mode = CheckMode.Upstream; dumpfound = true; dumpnotfound = false; } else if (String.Compare(args[0], "/un", true) == 0) { mode = CheckMode.Upstream; dumpfound = false; dumpnotfound = true; } else if (String.Compare(args[0], "/ua", true) == 0) { mode = CheckMode.Upstream; dumpfound = true; dumpnotfound = true; } else if (String.Compare(args[0], "/d", true) == 0) { mode = CheckMode.Downstream; dumpfound = false; dumpnotfound = false; } else if (String.Compare(args[0], "/df", true) == 0) { mode = CheckMode.Downstream; dumpfound = true; dumpnotfound = false; } else if (String.Compare(args[0], "/dn", true) == 0) { mode = CheckMode.Downstream; dumpfound = false; dumpnotfound = true; } else if (String.Compare(args[0], "/da", true) == 0) { mode = CheckMode.Downstream; dumpfound = true; dumpnotfound = true; } else { ShowExplanation(); return; } SySal.TotalScan.Volume v = (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(args[1], typeof(SySal.TotalScan.Volume)); if (v.Layers.Length != 3 && mode == CheckMode.Center) { Console.WriteLine("The TSR data must contain exactly 3 layers to use this check mode."); return; } else if (v.Layers.Length < 3) { Console.WriteLine("The TSR data must contain at least 3 layers."); return; } Exe x = new Exe(v); x.Check(mode, args[2], (args.Length == 4) ? new NumericalTools.CStyleParsedFunction(args[3]) : null, dumpfound, dumpnotfound); }
public Exe(SySal.TotalScan.Volume v) { Vol = v; SelectionFunction = null; }