Exemplo n.º 1
0
        /// <summary>
        /// Removes all segments in a track 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 RemoveSegments(int[] removepos)
        {
            SySal.TotalScan.Flexi.Segment zs = new SySal.TotalScan.Flexi.Segment(new SySal.TotalScan.Segment(new SySal.Tracking.MIPEmulsionTrackInfo(), new NullIndex()), 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)
                {
                    ((Segment)(newsegs[j++] = Segments[i])).SetTrack(this, j);
                }
            }
            Segments = newsegs;
            NotifyChanged();
        }
Exemplo n.º 2
0
 /// <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));
 }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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
        }