/// <summary> /// Adds a list of tracks. /// </summary> /// <param name="tks">the tracks to be added. Null values are allowed, leaving empty entries that can be filled later.</param> /// <returns>the ids assigned to the tracks</returns> public virtual int [] Insert(Track [] tks) { int n = Items.Length; int dn = tks.Length; SySal.TotalScan.Track[] newitems = new SySal.TotalScan.Track[n + dn]; int i; int [] newids = new int[dn]; for (i = 0; i < n; i++) { newitems[i] = Items[i]; } for (i = 0; i < dn; i++) { newitems[i + n] = tks[i]; if (tks[i] != null) { tks[i].SetId(i + n); } newids[i] = i + n; } Items = newitems; return(newids); }
/// <summary> /// Removes the tracks at the specified positions. /// </summary> /// <param name="pos">the position hosting the tracks to be removed.</param> /// <remarks>the ids of the tracks are recomputed.</remarks> public virtual void Remove(int [] pos) { int n = Items.Length; int dn = 0; SySal.TotalScan.Track ztk = new SySal.TotalScan.Track(); foreach (int tki in pos) { if (Items[tki] != ztk) { Items[tki] = ztk; dn++; } } SySal.TotalScan.Track[] newitems = new SySal.TotalScan.Track[n - dn]; int i, j; for (i = j = 0; i < n; i++) { if (Items[i] != ztk) { newitems[j] = Items[i]; if (newitems[j] != null) { ((Track)newitems[j]).SetId(j); } j++; } } Items = newitems; }
public bool Filter(SySal.TotalScan.Track t) { if (t.Length < 3) { return(false); } double dz = t.Upstream_Z - m_MainVertexPos.Z; if (Math.Round(dz / 1300.0) < -3.0 || Math.Round(dz / 1300.0) > 4.0) { return(false); } double ipcut = 800.0; SySal.Tracking.MIPEmulsionTrackInfo[] segs = ((SySal.TotalScan.Flexi.Track)t).BaseTracks; if (segs.Length < 2) { return(false); } SySal.BasicTypes.Vector p = t[t.Length - 1].Info.Intercept; SySal.BasicTypes.Vector s = segs[segs.Length - 1].Slope; s.Z = 1.0 / Math.Sqrt(s.X * s.X + s.Y * s.Y + 1.0); s.X *= s.Z; s.Y *= s.Z; p.X -= m_MainVertexPos.X; p.Y -= m_MainVertexPos.Y; p.Z -= m_MainVertexPos.Z; double dx = p.Y * s.Z - p.Z * s.Y; double dy = p.Z * s.X - p.X * s.Z; dz = p.X * s.Y - p.Y * s.X; return(dx * dx + dy * dy + dz * dz <= ipcut * ipcut); }
/// <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> /// Builds an empty list. /// </summary> public TrackList() : base() { Items = new SySal.TotalScan.Track[0]; }
/// <summary> /// Sets the owner track and position within the track for this segment. /// </summary> /// <param name="ly">the track to attach the segment to.</param> /// <param name="lypos">the position of the segment in the track.</param> /// <remarks>The track receives no notification of the newly attached segment. External code must maintain the consistency.</remarks> public virtual void SetTrack(SySal.TotalScan.Track tk, int tkpos) { m_TrackOwner = tk; m_PosInTrack = tkpos; }
/// <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); }
private void cmdToVertex_Click(object sender, EventArgs e) { if (m_VF.Count <= 0) { return; } SySal.TotalScan.Track [] tklist = new SySal.TotalScan.Track[m_VF.Count]; int i; System.Collections.ArrayList vtxaltered = new System.Collections.ArrayList(); for (i = 0; i < tklist.Length; i++) { SySal.TotalScan.VertexFit.TrackFit tf = m_VF.Track(i); tklist[i] = m_V.Tracks[((SySal.TotalScan.BaseTrackIndex)tf.Id).Id]; tklist[i].SetAttribute(SySal.TotalScan.Vertex.TrackWeightAttribute, tf.Weight); bool isupstream = (tklist[i].Downstream_Z + tklist[i].Upstream_Z) > (tf.MaxZ + tf.MinZ); SySal.TotalScan.Vertex vtxa = isupstream ? tklist[i].Upstream_Vertex : tklist[i].Downstream_Vertex; if (vtxa != null) { if (vtxaltered.Contains(vtxa) == false) { vtxaltered.Add(vtxa); } vtxa.RemoveTrack(tklist[i]); } } int[] ids = new int[vtxaltered.Count]; for (i = 0; i < ids.Length; i++) { ids[i] = ((SySal.TotalScan.Vertex)vtxaltered[i]).Id; } System.Collections.ArrayList vtxremove = new System.Collections.ArrayList(); foreach (SySal.TotalScan.Vertex vtx in vtxaltered) { try { vtx.NotifyChanged(); if (vtx.AverageDistance >= 0.0) { continue; } } catch (Exception) { vtxremove.Add(vtx.Id); } } ((SySal.TotalScan.Flexi.Volume.VertexList)m_V.Vertices).Remove((int[])vtxremove.ToArray(typeof(int))); SySal.TotalScan.Flexi.Vertex nv = new SySal.TotalScan.Flexi.Vertex(((SySal.TotalScan.Flexi.Track)tklist[0]).DataSet, m_V.Vertices.Length); nv.SetId(m_V.Vertices.Length); for (i = 0; i < tklist.Length; i++) { SySal.TotalScan.VertexFit.TrackFit tf = m_VF.Track(i); if ((tklist[i].Downstream_Z + tklist[i].Upstream_Z) > (tf.MaxZ + tf.MinZ)) { nv.AddTrack(tklist[i], false); tklist[i].SetUpstreamVertex(nv); } else { nv.AddTrack(tklist[i], true); tklist[i].SetDownstreamVertex(nv); } } try { nv.NotifyChanged(); if (nv.AverageDistance >= 0.0) { ((SySal.TotalScan.Flexi.Volume.VertexList)m_V.Vertices).Insert(new SySal.TotalScan.Flexi.Vertex[1] { nv }); } } catch (Exception x) { MessageBox.Show("Can't create new vertex - check geometry/topology.", "Vertex error", MessageBoxButtons.OK, MessageBoxIcon.Error); nv.SetId(-1); } if (nv.Id >= 0) { string s = ""; if (ids.Length > 0) { s += "\r\nVertices altered: {"; for (i = 0; i < ids.Length; i++) { if (i == 0) { s += ids[i].ToString(); } else { s += ", " + ids[i].ToString(); } } s += "}"; } if (vtxremove.Count > 0) { s += "\r\nVertices removed: {"; for (i = 0; i < vtxremove.Count; i++) { if (i == 0) { s += vtxremove[i].ToString(); } else { s += ", " + vtxremove[i].ToString(); } } s += "}"; } MessageBox.Show("New vertex " + nv.Id + " created." + s + "\r\nPlease regenerate the plot to see the changes.", "Vertex created", MessageBoxButtons.OK, MessageBoxIcon.Information); } TrackBrowser.RefreshAll(); VertexBrowser.RefreshAll(); }