Beispiel #1
0
            public GridInterpolation(RTrackCell [,] g, double cellsize, SySal.BasicTypes.Rectangle refrect, int minmatches)
            {
                m_Grid   = g;
                CellSize = cellsize;
                RefRect  = refrect;
                SySal.BasicTypes.Vector2 c = new SySal.BasicTypes.Vector2();
                c.X        = 0.5 * (refrect.MinX + RefRect.MaxX);
                c.Y        = 0.5 * (refrect.MinY + RefRect.MaxY);
                XCells     = m_Grid.GetLength(0);
                YCells     = m_Grid.GetLength(1);
                MinMatches = minmatches;
                MaxXYCells = Math.Max(XCells, YCells);
                m_Grid2    = new RTrackCell[XCells, YCells];
                int ix, iy;

                for (ix = 0; ix < XCells; ix++)
                {
                    for (iy = 0; iy < YCells; iy++)
                    {
                        RTrackCell rrc = m_Grid[ix, iy];
                        RTrackCell rtc = new RTrackCell(rrc.Extents, c);
                        m_Grid2[ix, iy]         = rtc;
                        m_Grid2[ix, iy].Average = rtc.Center;
                        rtc.Result  = NumericalTools.ComputationResult.OK;
                        rtc.Matches = Math.Max(minmatches, rrc.Matches);
                        SySal.BasicTypes.Vector v = new SySal.BasicTypes.Vector();
                        EvaluateW(rtc.Center.X, rtc.Center.Y, ref v, ref rtc.AlignInfo);
                        rtc.SlopeAlignInfo.X = v.X;
                        rtc.SlopeAlignInfo.Y = v.Y;
                    }
                }
            }
Beispiel #2
0
            public bool Evaluate(double x, double y, ref SySal.BasicTypes.Vector sloped, ref SySal.DAQSystem.Scanning.IntercalibrationInfo posd)
            {
                double tx  = (x - RefRect.MinX) / CellSize - 0.5;
                double ty  = (y - RefRect.MinY) / CellSize - 0.5;
                int    ix  = (int)tx;
                int    iy  = (int)ty;
                double mux = tx - ix;
                double muy = ty - iy;

                double[,] w = new double[, ] {
                    { (1.0 - muy) * (1.0 - mux), (1.0 - muy) * mux }, { muy *(1.0 - mux), muy *mux }
                };
                int itx, ity;

                posd.MXX = posd.MXY = posd.MYX = posd.MYY = posd.TX = posd.TY = posd.TZ = 0.0;
                sloped.X = sloped.Y = 0;
                for (itx = 0; itx <= 1; itx++)
                {
                    int iix = ix + itx;
                    if (iix < 0)
                    {
                        iix = 0;
                    }
                    else if (iix >= XCells)
                    {
                        iix = XCells - 1;
                    }
                    for (ity = 0; ity <= 1; ity++)
                    {
                        int iiy = iy + ity;
                        if (iiy < 0)
                        {
                            iiy = 0;
                        }
                        else if (iiy >= YCells)
                        {
                            iiy = YCells - 1;
                        }
                        double     tw = w[ity, itx];
                        RTrackCell g  = m_Grid2[iix, iiy];

                        posd.MXX += g.AlignInfo.MXX * tw;
                        posd.MXY += g.AlignInfo.MXY * tw;
                        posd.MYX += g.AlignInfo.MYX * tw;
                        posd.MYY += g.AlignInfo.MYY * tw;
                        posd.TX  += (g.AlignInfo.TX + g.AlignInfo.MXX * (x - g.AlignInfo.RX) + g.AlignInfo.MXY * (y - g.AlignInfo.RY) + (g.AlignInfo.RX - x)) * tw;
                        posd.TY  += (g.AlignInfo.TY + g.AlignInfo.MYX * (x - g.AlignInfo.RX) + g.AlignInfo.MYY * (y - g.AlignInfo.RY) + (g.AlignInfo.RY - y)) * tw;
                        posd.TZ  += g.AlignInfo.TZ * tw;
                        sloped.X += g.SlopeAlignInfo.X * tw;
                        sloped.Y += g.SlopeAlignInfo.Y * tw;
                    }
                }
                sloped.Z = 0.0;
                posd.RX  = x;
                posd.RY  = y;
                return(true);
            }
Beispiel #3
0
        private void UpdatePT()
        {
            SySal.BasicTypes.Vector pb = new SySal.BasicTypes.Vector();
            pb.Z = 1.0 / Math.Sqrt(m_ParentSlopes.X * m_ParentSlopes.X + m_ParentSlopes.Y * m_ParentSlopes.Y + 1.0);
            pb.X = pb.Z * m_ParentSlopes.X;
            pb.Y = pb.Z * m_ParentSlopes.Y;
            double n  = pb.X * m_TotalP.X + pb.Y * m_TotalP.Y + pb.Z * m_TotalP.Z;
            double n2 = Math.Sqrt(m_TotalP.X * m_TotalP.X + m_TotalP.Y * m_TotalP.Y + m_TotalP.Z * m_TotalP.Z - n * n);

            txtPT.Text = n2.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
        }
Beispiel #4
0
        SySal.BasicTypes.Vector[] InterpolateNormalVector(SySal.BasicTypes.Vector start, SySal.BasicTypes.Vector finish, int steps, double smoothing)
        {
            SySal.BasicTypes.Vector[] ret = new SySal.BasicTypes.Vector[steps];
            start  = start.UnitVector;
            finish = finish.UnitVector;

            SySal.BasicTypes.Vector j = (start ^ finish);
            SySal.BasicTypes.Vector k = new SySal.BasicTypes.Vector();
            if (j.Norm2 > 0.0)
            {
                j = j.UnitVector;
            }
            k = j ^ start;

            double cf = finish * start;

            if (cf > 1.0)
            {
                cf = 1.0;
            }
            else if (cf < -1.0)
            {
                cf = -1.0;
            }

            double theta = Math.Acos(cf);

            if (finish * k < 0)
            {
                theta = -theta;
            }

            int i;

            for (i = 0; i < steps; i++)
            {
                double lambda = (double)i / (double)(steps - 1);
                double phi    = ((1.0 - smoothing) * lambda + smoothing * (1.0 - Math.Cos(Math.PI * lambda)) * 0.5) * theta;
                double cphi   = Math.Cos(phi);
                double sphi   = Math.Sin(phi);
                ret[i] = cphi * start + sphi * k;
            }

            return(ret);
        }
Beispiel #5
0
        void InterpolateCamera(SySal.BasicTypes.Vector startdir, SySal.BasicTypes.Vector startnorm, SySal.BasicTypes.Vector finishdir, SySal.BasicTypes.Vector finishnorm, int steps, double smoothing, System.Collections.ArrayList ar, string comment)
        {
            SySal.BasicTypes.Vector d = new SySal.BasicTypes.Vector();
            SySal.BasicTypes.Vector n = new SySal.BasicTypes.Vector();
            SySal.BasicTypes.Vector b = new SySal.BasicTypes.Vector();
            int i;

            SySal.BasicTypes.Vector[] td = InterpolateNormalVector(startdir, finishdir, steps, smoothing);
            SySal.BasicTypes.Vector[] tn = InterpolateNormalVector(startnorm, finishnorm, steps, smoothing);
            for (i = 0; i < steps; i++)
            {
                d = td[i];
                n = (tn[i] - ((tn[i] * td[i]) * td[i])).UnitVector;
                b = td[i] ^ n;
                ar.Add(new object[4] {
                    d, n, b, comment
                });
            }
        }
Beispiel #6
0
        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
        }
Beispiel #7
0
        private void btnMake_Click(object sender, EventArgs e)
        {
            SaveFileDialog sdlg = new SaveFileDialog();

            sdlg.Title  = "Select movie file";
            sdlg.Filter = "Animated GIF (*.gif)|*.gif";
            if (sdlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            double DX = 0.0, DY = 0.0, DZ = 0.0;
            double NX = 0.0, NY = 0.0, NZ = 0.0;
            double BX = 0.0, BY = 0.0, BZ = 0.0;
            double PX = 0.0, PY = 0.0, PZ = 0.0;

            gdiDisplay.GetCameraOrientation(ref DX, ref DY, ref DZ, ref NX, ref NY, ref NZ, ref BX, ref BY, ref BZ);
            gdiDisplay.GetCameraSpotting(ref PX, ref PY, ref PZ);
            Cursor oldc = Cursor;

            try
            {
                Cursor = Cursors.WaitCursor;
                gdiDisplay.AutoRender = false;
                Bitmap      b  = new Bitmap(gdiDisplay.Width, gdiDisplay.Height);
                GDI3D.Movie mv = new GDI3D.Movie(1);
                mv.Comment = txtComments.Text;
                int   i;
                Color bkcol   = gdiDisplay.BackColor;
                Color textcol = Color.FromArgb((bkcol.R + 128) % 256, (bkcol.G + 128) % 256, (bkcol.B + 128) % 256);
                System.Collections.ArrayList ar         = new System.Collections.ArrayList();
                SySal.BasicTypes.Vector      startdir   = new SySal.BasicTypes.Vector();
                SySal.BasicTypes.Vector      startnorm  = new SySal.BasicTypes.Vector();
                SySal.BasicTypes.Vector      finishdir  = new SySal.BasicTypes.Vector();
                SySal.BasicTypes.Vector      finishnorm = new SySal.BasicTypes.Vector();
                SySal.BasicTypes.Vector      loopdir    = new SySal.BasicTypes.Vector();
                SySal.BasicTypes.Vector      loopnorm   = new SySal.BasicTypes.Vector();
                if (chkViewXY.Checked)
                {
                    loopdir.X  = 0.0; loopdir.Y = 0.0; loopdir.Z = -1.0;
                    loopnorm.X = 0.0; loopnorm.Y = -1.0; loopnorm.Z = 0.0;
                }
                else if (chkViewXZ.Checked)
                {
                    loopdir.X  = 0.0; loopdir.Y = 1.0; loopdir.Z = 0.0;
                    loopnorm.X = 0.0; loopnorm.Y = 0.0; loopnorm.Z = -1.0;
                }
                else if (chkViewYZ.Checked)
                {
                    loopdir.X  = -1.0; loopdir.Y = 0.0; loopdir.Z = 0.0;
                    loopnorm.X = 0.0; loopnorm.Y = 0.0; loopnorm.Z = -1.0;
                }
                else if (chkViewYRot.Checked)
                {
                    loopdir.X  = 0.0; loopdir.Y = 0.0; loopdir.Z = -1.0;
                    loopnorm.X = 0.0; loopnorm.Y = -1.0; loopnorm.Z = 0.0;
                }
                else if (chkViewXYPan.Checked)
                {
                    loopdir.X  = 0.0; loopdir.Y = 0.0; loopdir.Z = -1.0;
                    loopnorm.X = 0.0; loopnorm.Y = -1.0; loopnorm.Z = 0.0;
                }
                else
                {
                    MessageBox.Show("At least one set of views must be selected.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                startdir  = loopdir;
                startnorm = loopnorm;
                if (chkViewXY.Checked)
                {
                    object[] o = new object[4];
                    o[0] = startdir;
                    o[1] = startnorm;
                    o[2] = startdir ^ startnorm;
                    o[3] = "XY";
                    for (i = 0; i < (int)DataMap[0, 1]; i++)
                    {
                        ar.Add(o);
                    }
                }
                if (chkViewXZ.Checked)
                {
                    finishdir.X  = 0.0; finishdir.Y = 1.0; finishdir.Z = 0.0;
                    finishnorm.X = 0.0; finishnorm.Y = 0.0; finishnorm.Z = -1.0;
                    InterpolateCamera(startdir, startnorm, finishdir, finishnorm, 90 / trkSpeed.Value, 1.0, ar, "");
                    startdir  = finishdir;
                    startnorm = finishnorm;
                    object[] o = new object[4];
                    o[0] = startdir;
                    o[1] = startnorm;
                    o[2] = startdir ^ startnorm;
                    o[3] = "XZ";
                    for (i = 0; i < (int)DataMap[1, 1]; i++)
                    {
                        ar.Add(o);
                    }
                }
                if (chkViewYZ.Checked)
                {
                    finishdir.X  = -1.0; finishdir.Y = 0.0; finishdir.Z = 0.0;
                    finishnorm.X = 0.0; finishnorm.Y = 0.0; finishnorm.Z = -1.0;
                    InterpolateCamera(startdir, startnorm, finishdir, finishnorm, 90 / trkSpeed.Value, 1.0, ar, "");
                    startdir  = finishdir;
                    startnorm = finishnorm;
                    object[] o = new object[4];
                    o[0] = startdir;
                    o[1] = startnorm;
                    o[2] = startdir ^ startnorm;
                    o[3] = "YZ";
                    for (i = 0; i < (int)DataMap[2, 1]; i++)
                    {
                        ar.Add(o);
                    }
                }
                if (chkViewYRot.Checked)
                {
                    finishdir.X  = 0.0; finishdir.Y = 0.0; finishdir.Z = -1.0;
                    finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0;
                    InterpolateCamera(startdir, startnorm, finishdir, finishnorm, 90 / trkSpeed.Value, 1.0, ar, "");
                    startdir.X = 1.0; startdir.Y = 0.0; startdir.Z = 0.0;
                    InterpolateCamera(finishdir, finishnorm, startdir, finishnorm, (int)DataMap[3, 1], 0.0, ar, "Y rot");
                    ar.RemoveAt(ar.Count - 1);
                    finishdir.X = 0.0; finishdir.Y = 0.0; finishdir.Z = 1.0;
                    InterpolateCamera(startdir, finishnorm, finishdir, finishnorm, (int)DataMap[3, 1], 0.0, ar, "Y rot");
                    ar.RemoveAt(ar.Count - 1);
                    startdir.X = -1.0; startdir.Y = 0.0; startdir.Z = 0.0;
                    InterpolateCamera(finishdir, finishnorm, startdir, finishnorm, (int)DataMap[3, 1], 0.0, ar, "Y rot");
                    ar.RemoveAt(ar.Count - 1);
                    finishdir.X = 0.0; finishdir.Y = 0.0; finishdir.Z = -1.0;
                    InterpolateCamera(startdir, finishnorm, finishdir, finishnorm, (int)DataMap[3, 1], 0.0, ar, "Y rot");
                    startdir = finishdir; startnorm = finishnorm;
                }
                if (chkViewXYPan.Checked)
                {
/*
 *                  finishdir.X = -0.3; finishdir.Y = -0.3; finishdir.Z = -1.0; finishdir = finishdir.UnitVector;
 *                  finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0; finishnorm = (finishnorm - (finishnorm * finishdir) * finishdir).UnitVector;
 *                  InterpolateCamera(startdir, startnorm, finishdir, finishnorm, 90 / trkSpeed.Value, 1.0, ar, "XY pan");
 *
 *                  startdir = finishdir; startnorm = finishnorm;
 *                  finishdir.X = 0.3; finishdir.Y = -0.3; finishdir.Z = -1.0; finishdir = finishdir.UnitVector;
 *                  finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0; finishnorm = (finishnorm - (finishnorm * finishdir) * finishdir).UnitVector;
 *                  InterpolateCamera(startdir, startnorm, finishdir, finishnorm, (int)DataMap[4, 1], 1.0, ar, "XY pan");
 *
 *                  startdir = finishdir; startnorm = finishnorm;
 *                  finishdir.X = 0.3; finishdir.Y = 0.3; finishdir.Z = -1.0; finishdir = finishdir.UnitVector;
 *                  finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0; finishnorm = (finishnorm - (finishnorm * finishdir) * finishdir).UnitVector;
 *                  InterpolateCamera(startdir, startnorm, finishdir, finishnorm, (int)DataMap[4, 1], 1.0, ar, "XY pan");
 *
 *                  startdir = finishdir; startnorm = finishnorm;
 *                  finishdir.X = -0.3; finishdir.Y = 0.3; finishdir.Z = -1.0; finishdir = finishdir.UnitVector;
 *                  finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0; finishnorm = (finishnorm - (finishnorm * finishdir) * finishdir).UnitVector;
 *                  InterpolateCamera(startdir, startnorm, finishdir, finishnorm, (int)DataMap[4, 1], 1.0, ar, "XY pan");
 *
 *                  startdir = finishdir; startnorm = finishnorm;
 *                  finishdir.X = 0.0; finishdir.Y = 0.0; finishdir.Z = -1.0;
 *                  finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0;
 *                  InterpolateCamera(startdir, startnorm, finishdir, finishnorm, 45 / trkSpeed.Value, 1.0, ar, "");
 *
 *                  startdir = finishdir;
 *                  startnorm = finishnorm;
 */
                    finishdir.X  = -0.1; finishdir.Y = 0; finishdir.Z = -1.0; finishdir = finishdir.UnitVector;
                    finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0; finishnorm = (finishnorm - (finishnorm * finishdir) * finishdir).UnitVector;
                    InterpolateCamera(startdir, startnorm, finishdir, finishnorm, 90 / trkSpeed.Value, 1.0, ar, "");
                    for (i = 0; i <= (int)DataMap[4, 1]; i += trkSpeed.Value)
                    {
                        double theta = (Math.PI * 2.0 * i) / (int)DataMap[4, 1];
                        double cth   = -Math.Cos(theta);
                        double sth   = -Math.Sin(theta);
                        finishdir.X  = cth * 0.1;
                        finishdir.Y  = sth * 0.1;
                        finishdir.Z  = -1.0;
                        finishdir    = finishdir.UnitVector;
                        finishnorm.X = 0.0; finishnorm.Y = -1.0; finishnorm.Z = 0.0; finishnorm = (finishnorm - (finishnorm * finishdir) * finishdir).UnitVector;
                        ar.Add(new object[] { finishdir, finishnorm, finishdir ^ finishnorm, "XY pan" });
                    }
                    startdir  = finishdir;
                    startnorm = finishnorm;
                }
                InterpolateCamera(startdir, startnorm, loopdir, loopnorm, 90 / trkSpeed.Value, 1.0, ar, "");

                pbGeneration.Maximum = ar.Count;
                pbGeneration.Value   = 0;
                foreach (object [] o in ar)
                {
                    SySal.BasicTypes.Vector d = (SySal.BasicTypes.Vector)o[0];
                    SySal.BasicTypes.Vector n = (SySal.BasicTypes.Vector)o[1];
                    gdiDisplay.SetCameraOrientation(d.X, d.Y, d.Z, n.X, n.Y, n.Z);
                    gdiDisplay.SetCameraSpotting(PX, PY, PZ);
                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
                    gdiDisplay.Render(g);
                    int margin = 0;
                    if (chkEvent.Checked)
                    {
                        g.DrawString("Event " + m_Event, new Font("Verdana", 12), new SolidBrush(Color.White), 0, margin);
                        margin += 16;
                    }
                    if (chkBrick.Checked)
                    {
                        g.DrawString("Brick " + m_Brick, new Font("Verdana", 12), new SolidBrush(Color.White), 0, margin);
                        margin += 16;
                    }
                    string comment = (string)o[3];
                    if (chkAddViewExplanation.Checked && comment != null && comment.Length > 0)
                    {
                        g.DrawString(comment, new Font("Verdana", 12), new SolidBrush(Color.White), 0, margin);
                        margin += 16;
                    }
                    mv.AddFrame(b);
                    pbGeneration.Value = mv.Frames;
                    Application.DoEvents();
                }
                mv.Save(sdlg.FileName);
                Cursor = oldc;
                MessageBox.Show("File correctly saved", "Movie generation OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception x)
            {
                Cursor = oldc;
                MessageBox.Show("Error saving file\r\n" + x.ToString(), "Movie generation error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            gdiDisplay.SetCameraOrientation(DX, DY, DZ, NX, NY, NZ);
            gdiDisplay.SetCameraSpotting(PX, PY, PZ);
            gdiDisplay.AutoRender = true;
        }
Beispiel #8
0
        private void Compute(bool comp_x, bool comp_y, object btn)
        {
            m_Running = true;
            EnableButtons(btn);
            m_Stop           = false;
            pbProgress.Value = 0.0;
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                try
                {
                    SySal.Processing.QuickMapping.QuickMapper QM    = new SySal.Processing.QuickMapping.QuickMapper();
                    SySal.Processing.QuickMapping.Configuration qmc = (SySal.Processing.QuickMapping.Configuration)QM.Config;
                    qmc.FullStatistics       = false;
                    qmc.UseAbsoluteReference = true;
                    qmc.PosTol   = S.PosTolerance;
                    qmc.SlopeTol = 1.0;
                    QM.Config    = qmc;
                    System.Collections.ArrayList xconv = new System.Collections.ArrayList();
                    System.Collections.ArrayList yconv = new System.Collections.ArrayList();
                    int sfi;
                    for (sfi = 0; sfi < SummaryFiles.Length; sfi++)
                    {
                        QuasiStaticAcquisition Q = new QuasiStaticAcquisition(SummaryFiles[sfi]);
                        foreach (QuasiStaticAcquisition.Sequence seq in Q.Sequences)
                        {
                            int ly;
                            SySal.Imaging.Cluster[] prevC = FilterClusters(seq.Layers[0].ReadClusters());
                            SySal.Imaging.Cluster[] nextC = null;
                            SySal.BasicTypes.Vector prevP = seq.Layers[0].Position;
                            SySal.BasicTypes.Vector nextP = new SySal.BasicTypes.Vector();
                            for (ly = 1; ly < seq.Layers.Length; ly++)
                            {
                                if (m_Stop)
                                {
                                    throw new Exception("Stopped.");
                                }
                                nextC = FilterClusters(seq.Layers[ly].ReadClusters());
                                nextP = seq.Layers[ly].Position;
                                this.Invoke(new dSetValue(SetValue), 100.0 * (((double)seq.Id + (double)(ly - 1) / (double)(seq.Layers.Length - 1)) / (double)(Q.Sequences.Length) + sfi) / SummaryFiles.Length);
                                SySal.BasicTypes.Vector2 dp   = new SySal.BasicTypes.Vector2(seq.Layers[ly].Position - seq.Layers[ly - 1].Position);
                                SySal.BasicTypes.Vector2 dp1  = dp; dp1.X /= S.MinConv; dp1.Y /= S.MinConv;
                                SySal.BasicTypes.Vector2 dp2  = dp; dp2.X /= S.MaxConv; dp2.Y /= S.MaxConv;
                                SySal.BasicTypes.Vector2 da   = new SySal.BasicTypes.Vector2(); da.X = 0.5 * (dp1.X + dp2.X); da.Y = 0.5 * (dp1.Y + dp2.Y);
                                SySal.BasicTypes.Vector2 dext = new SySal.BasicTypes.Vector2(); dext.X = Math.Abs(dp1.X - dp2.X); dext.Y = Math.Abs(dp1.Y - dp2.Y);
                                SySal.Tracking.MIPEmulsionTrackInfo[] prevmap = new SySal.Tracking.MIPEmulsionTrackInfo[prevC.Length];
                                int i;
                                for (i = 0; i < prevC.Length; i++)
                                {
                                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                                    info.Intercept.X = prevC[i].X;
                                    info.Intercept.Y = prevC[i].Y;
                                    prevmap[i]       = info;
                                }
                                SySal.Tracking.MIPEmulsionTrackInfo[] nextmap = new SySal.Tracking.MIPEmulsionTrackInfo[nextC.Length];
                                for (i = 0; i < nextC.Length; i++)
                                {
                                    nextmap[i] = new SySal.Tracking.MIPEmulsionTrackInfo();
                                }
                                double[,] convopt = new double[, ] {
                                    { 1.0, 1.0 }, { -1.0, 1.0 }, { -1.0, -1.0 }, { 1.0, -1.0 }
                                };
                                int o;
                                SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] bestpairs = new SySal.Scanning.PostProcessing.PatternMatching.TrackPair[0];
                                SySal.BasicTypes.Vector2 bestda = new SySal.BasicTypes.Vector2();
                                for (o = 0; o < convopt.GetLength(0); o++)
                                {
                                    try
                                    {
                                        for (i = 0; i < nextC.Length; i++)
                                        {
                                            SySal.Tracking.MIPEmulsionTrackInfo info = nextmap[i];
                                            info.Intercept.X = nextC[i].X + da.X * convopt[o, 0];
                                            info.Intercept.Y = nextC[i].Y + da.Y * convopt[o, 1];
                                            nextmap[i]       = info;
                                        }
                                        SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] prs = QM.Match(prevmap, nextmap, 0.0, dext.X, dext.Y);
                                        if (prs.Length > bestpairs.Length)
                                        {
                                            bestda.X  = da.X * convopt[o, 0];
                                            bestda.Y  = da.Y * convopt[o, 1];
                                            bestpairs = prs;
                                        }
                                    }
                                    catch (Exception xc) { }
                                }

                                if (bestpairs.Length >= S.MinMatches)
                                {
                                    double[] deltas = new double[bestpairs.Length];
                                    for (i = 0; i < bestpairs.Length; i++)
                                    {
                                        deltas[i] = bestpairs[i].First.Info.Intercept.X - nextC[bestpairs[i].Second.Index].X;
                                    }
                                    bestda.X = NumericalTools.Fitting.Quantiles(deltas, new double[] { 0.5 })[0];
                                    if (bestda.X != 0.0)
                                    {
                                        double v = dp.X / bestda.X;
                                        int pos  = xconv.BinarySearch(v);
                                        if (pos < 0)
                                        {
                                            pos = ~pos;
                                        }
                                        xconv.Insert(pos, v);
                                    }
                                    for (i = 0; i < bestpairs.Length; i++)
                                    {
                                        deltas[i] = bestpairs[i].First.Info.Intercept.Y - nextC[bestpairs[i].Second.Index].Y;
                                    }
                                    bestda.Y = NumericalTools.Fitting.Quantiles(deltas, new double[] { 0.5 })[0];
                                    if (bestda.Y != 0.0)
                                    {
                                        double v = dp.Y / bestda.Y;
                                        int pos  = yconv.BinarySearch(v);
                                        if (pos < 0)
                                        {
                                            pos = ~pos;
                                        }
                                        yconv.Insert(pos, v);
                                    }
                                    if (comp_x && xconv.Count > 0)
                                    {
                                        int bmin, bmax;
                                        bmin = (int)Math.Ceiling(xconv.Count * 0.16);
                                        bmax = (int)Math.Floor(xconv.Count * 0.84);
                                        if (bmax < bmin)
                                        {
                                            bmin = bmax;
                                        }
                                        double[] sample1s = (double[])xconv.GetRange(bmin, bmax - bmin + 1).ToArray(typeof(double));
                                        XConv             = NumericalTools.Fitting.Average(sample1s);
                                        this.Invoke(new dSetConv(SetConv), new object[] { true, XConv, 0.5 * (sample1s[sample1s.Length - 1] - sample1s[0]) / Math.Sqrt(sample1s.Length) });
                                    }
                                    if (comp_y && yconv.Count > 0)
                                    {
                                        int bmin, bmax;
                                        bmin = (int)Math.Ceiling(yconv.Count * 0.16);
                                        bmax = (int)Math.Floor(yconv.Count * 0.84);
                                        if (bmax < bmin)
                                        {
                                            bmin = bmax;
                                        }
                                        double[] sample1s = (double[])yconv.GetRange(bmin, bmax - bmin + 1).ToArray(typeof(double));
                                        YConv             = NumericalTools.Fitting.Average(sample1s);
                                        this.Invoke(new dSetConv(SetConv), new object[] { false, YConv, 0.5 * (sample1s[sample1s.Length - 1] - sample1s[0]) / Math.Sqrt(sample1s.Length) });
                                    }
                                }
                                prevP = nextP;
                                prevC = nextC;
                            }
                        }
                    }
                }
                catch (Exception xc1)
                {
                    iLog.Log("Compute", xc1.ToString());
                }
                m_Running = false;
                this.Invoke(new dEnableButtons(EnableButtons), btn);
            }));
            thread.Start();
        }
Beispiel #9
0
 /// <summary>
 /// Sets the reference center.
 /// </summary>
 /// <param name="r">the new reference center.</param>
 public void SetRefCenter(SySal.BasicTypes.Vector r)
 {
     m_RefCenter = r;
 }
Beispiel #10
0
 private void UpdateFit()
 {
     m_gdiDisplay.AutoRender = false;
     TrackList.BeginUpdate();
     try
     {
         m_TotalP.X = m_TotalP.Y = m_TotalP.Z = 0.0;
         TrackList.Items.Clear();
         int i;
         for (i = 0; i < m_VF.Count; i++)
         {
             SySal.BasicTypes.Vector            s  = new SySal.BasicTypes.Vector();
             SySal.TotalScan.VertexFit.TrackFit tf = m_VF.Track(i);
             s.Z = 1.0 / Math.Sqrt(1.0 + tf.Slope.X * tf.Slope.X + tf.Slope.Y * tf.Slope.Y);
             s.X = tf.Slope.X * s.Z;
             s.Y = tf.Slope.Y * s.Z;
             ListViewItem lvi = new ListViewItem(tf.Id.ToString());
             lvi.Tag = tf.Id;
             lvi.SubItems.Add(tf.Intercept.X.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Intercept.Y.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Intercept.Z.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Slope.X.ToString("F4", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Slope.Y.ToString("F4", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Weight.ToString("F3", System.Globalization.CultureInfo.InvariantCulture));
             if (tf is SySal.TotalScan.VertexFit.TrackFitWithMomentum)
             {
                 double p = ((SySal.TotalScan.VertexFit.TrackFitWithMomentum)tf).P;
                 lvi.SubItems.Add(p.ToString("F2", System.Globalization.CultureInfo.InvariantCulture));
                 m_TotalP.X += s.X * p;
                 m_TotalP.Y += s.Y * p;
                 m_TotalP.Z += s.Z * p;
             }
             else
             {
                 lvi.SubItems.Add("");
             }
             lvi.SubItems.Add(m_VF.TrackIP(tf).ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(m_VF.DisconnectedTrackIP(tf.Id).ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(Math.Min(Math.Abs(m_VF.Z - tf.MaxZ), Math.Abs(m_VF.Z - tf.MinZ)).ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             TrackList.Items.Add(lvi);
         }
         textX.Text = m_VF.X.ToString("F1", System.Globalization.CultureInfo.InvariantCulture);
         textY.Text = m_VF.Y.ToString("F1", System.Globalization.CultureInfo.InvariantCulture);
         textZ.Text = m_VF.Z.ToString("F1", System.Globalization.CultureInfo.InvariantCulture);
     }
     catch (Exception)
     {
         textX.Text = "";
         textY.Text = "";
         textZ.Text = "";
         TrackList.Items.Clear();
         int i;
         for (i = 0; i < m_VF.Count; i++)
         {
             SySal.TotalScan.VertexFit.TrackFit tf = m_VF.Track(i);
             ListViewItem lvi = new ListViewItem(tf.Id.ToString());
             lvi.Tag = tf.Id;
             lvi.SubItems.Add(tf.Intercept.X.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Intercept.Y.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Intercept.Z.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Slope.X.ToString("F4", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Slope.Y.ToString("F4", System.Globalization.CultureInfo.InvariantCulture));
             lvi.SubItems.Add(tf.Weight.ToString("F3", System.Globalization.CultureInfo.InvariantCulture));
             if (tf is SySal.TotalScan.VertexFit.TrackFitWithMomentum)
             {
                 lvi.SubItems.Add(((SySal.TotalScan.VertexFit.TrackFitWithMomentum)tf).P.ToString("F2", System.Globalization.CultureInfo.InvariantCulture));
             }
             else
             {
                 lvi.SubItems.Add("");
             }
             lvi.SubItems.Add("");
             lvi.SubItems.Add("");
             lvi.SubItems.Add("");
             TrackList.Items.Add(lvi);
         }
     }
     txtPx.Text = m_TotalP.X.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
     txtPy.Text = m_TotalP.Y.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
     txtPz.Text = m_TotalP.Z.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
     txtP.Text  = Math.Sqrt(m_TotalP.X * m_TotalP.X + m_TotalP.Y * m_TotalP.Y + m_TotalP.Z * m_TotalP.Z).ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
     UpdatePT();
     TrackList.EndUpdate();
     if (m_gdiDisplay.RemoveOwned(m_VF) > 0)
     {
         cmdAddToPlot_Click(this, null);
     }
     m_gdiDisplay.AutoRender = true;
     m_gdiDisplay.Render();
 }
Beispiel #11
0
            public bool EvaluateW(double x, double y, ref SySal.BasicTypes.Vector sloped, ref SySal.DAQSystem.Scanning.IntercalibrationInfo posd)
            {
                int    ix = (int)((x - RefRect.MinX) / CellSize - 0.5);
                int    iy = (int)((y - RefRect.MinY) / CellSize - 0.5);
                int    iix, iiy;
                int    i, j;
                double dx, dy;

                System.Collections.ArrayList arr = new System.Collections.ArrayList();
                if (ix >= 0 && ix < XCells && iy >= 0 && iy < YCells && m_Grid[ix, iy].Result == NumericalTools.ComputationResult.OK && m_Grid[ix, iy].Matches >= MinMatches)
                {
                    arr.Add(m_Grid[ix, iy]);
                }
                foreach (int [] dv in dirs)
                {
                    for (i = 0; i < MaxXYCells; i++)
                    {
                        iix = ix + dv[0] + i * dv[2];
                        if (iix < 0 || iix >= XCells)
                        {
                            continue;
                        }
                        iiy = iy + dv[1] + i * dv[3];
                        if (iiy < 0 || iiy >= YCells)
                        {
                            continue;
                        }
                        if (m_Grid[iix, iiy].Result == NumericalTools.ComputationResult.OK && m_Grid[iix, iiy].Matches >= MinMatches)
                        {
                            arr.Add(m_Grid[iix, iiy]);
                            break;
                        }
                    }
                }
                RTrackCell[] activecells         = (RTrackCell[])arr.ToArray(typeof(RTrackCell));
                if (activecells.Length == 0)
                {
                    return(false);
                }
                double[] w                       = new double[activecells.Length];
                double[] mw                      = new double[activecells.Length];
                double   w_all                   = 0.0;

                for (i = 0; i < activecells.Length; i++)
                {
                    dx    = x - activecells[i].Average.X;
                    dy    = y - activecells[i].Average.Y;
                    mw[i] = dx * dx + dy * dy;
                }
                for (i = 0; i < w.Length; i++)
                {
                    w[i] = 1.0;
                    for (j = 0; j < mw.Length; j++)
                    {
                        if (i != j)
                        {
                            w[i] *= mw[j];
                        }
                    }
                }
                for (i = 0; i < w.Length; i++)
                {
                    w_all += w[i];
                }
                for (i = 0; i < w.Length; i++)
                {
                    w[i] /= w_all;
                }
                posd.MXX = posd.MXY = posd.MYX = posd.MYY = posd.TX = posd.TY = posd.TZ = 0.0;
                sloped.X = sloped.Y = 0;
                for (i = 0; i < w.Length; i++)
                {
                    posd.MXX += activecells[i].AlignInfo.MXX * w[i];
                    posd.MXY += activecells[i].AlignInfo.MXY * w[i];
                    posd.MYX += activecells[i].AlignInfo.MYX * w[i];
                    posd.MYY += activecells[i].AlignInfo.MYY * w[i];
                    posd.TX  += (activecells[i].AlignInfo.TX + activecells[i].AlignInfo.MXX * (x - activecells[i].AlignInfo.RX) + activecells[i].AlignInfo.MXY * (y - activecells[i].AlignInfo.RY) + (activecells[i].AlignInfo.RX - x)) * w[i];
                    posd.TY  += (activecells[i].AlignInfo.TY + activecells[i].AlignInfo.MYX * (x - activecells[i].AlignInfo.RX) + activecells[i].AlignInfo.MYY * (y - activecells[i].AlignInfo.RY) + (activecells[i].AlignInfo.RY - y)) * w[i];
                    posd.TZ  += activecells[i].AlignInfo.TZ * w[i];
                    sloped.X += activecells[i].SlopeAlignInfo.X * w[i];
                    sloped.Y += activecells[i].SlopeAlignInfo.Y * w[i];
                }
                sloped.Z = 0.0;
                posd.RX  = x;
                posd.RY  = y;
                return(true);
            }
Beispiel #12
0
        static void Main(string[] args)
        {
            if (args.Length != 13 && args.Length != 4 && args.Length != 2)
            {
                Console.WriteLine("usage: FlattenTLG.exe <cell map> <TLG to be flattened> <output TLG> <min matches>");
                Console.WriteLine("   or");
                Console.WriteLine("usage: FlattenTLG.exe <cell map> <min matches>");
                Console.WriteLine("           (opens a console to query the transformation map generator)");
                Console.WriteLine("   or");
                Console.WriteLine("usage: FlattenTLG.exe <reference TLG (supposed flat)> <TLG to be flattened> <output TLG> <cell size> <slope tol> <pos tol> <pos sweep> <z projection> <selection string> <min matches> <z adjust> <z step> <parallel (true|false)>");
                Console.WriteLine("Selection function variables:");
                foreach (SelFunc sf in KnownFunctions)
                {
                    Console.WriteLine(sf.Name + " -> " + sf.Desc);
                }
                return;
            }
            bool   usereadymap = (args.Length < 13);
            bool   useconsole = (args.Length == 2);
            string reftlg = args[0];
            string worktlg = useconsole ? "" : args[1];
            string outtlg = useconsole ? "" : args[2];
            uint   MinMatches = 0;
            int    xcells = 0;
            int    ycells = 0;
            double cellsize = 0.0;
            int    ix, iy;
            int    i, j, k;

            SySal.BasicTypes.Vector2   Center  = new SySal.BasicTypes.Vector2();
            SySal.BasicTypes.Rectangle WorkRect;
            SySal.Scanning.Plate.IO.OPERA.LinkedZone worklz = null;
            if (useconsole == false)
            {
                worklz   = SySal.DataStreams.OPERALinkedZone.FromFile(worktlg);
                WorkRect = worklz.Extents;
            }
            else
            {
                WorkRect = new SySal.BasicTypes.Rectangle();
            }
            SySal.BasicTypes.Rectangle RefRect = new SySal.BasicTypes.Rectangle();
            RTrackCell[,] WorkCells;
            if (usereadymap)
            {
                MinMatches = Convert.ToUInt32(args[useconsole ? 1 : 3]);
                System.IO.StreamReader cr = new System.IO.StreamReader(args[0]);
                while (cr.EndOfStream == false)
                {
                    System.Text.RegularExpressions.Match m = rx_CellMap.Match(cr.ReadLine());
                    if (m.Success)
                    {
                        RefRect.MinX = Convert.ToDouble(m.Groups[1].Value);
                        RefRect.MaxX = Convert.ToDouble(m.Groups[2].Value);
                        RefRect.MinY = Convert.ToDouble(m.Groups[3].Value);
                        RefRect.MaxY = Convert.ToDouble(m.Groups[4].Value);
                        cellsize     = Convert.ToDouble(m.Groups[5].Value);
                        xcells       = Convert.ToInt32(m.Groups[6].Value);
                        ycells       = Convert.ToInt32(m.Groups[7].Value);
                        break;
                    }
                }
                Center.X  = 0.5 * (RefRect.MinX + RefRect.MaxX);
                Center.Y  = 0.5 * (RefRect.MinY + RefRect.MaxY);
                WorkCells = new RTrackCell[xcells, ycells];
                for (ix = 0; ix < xcells; ix++)
                {
                    for (iy = 0; iy < ycells; iy++)
                    {
                        SySal.BasicTypes.Rectangle rect = new SySal.BasicTypes.Rectangle();
                        rect.MinX                = RefRect.MinX + ix * cellsize;
                        rect.MaxX                = rect.MinX + cellsize;
                        rect.MinY                = RefRect.MinY + iy * cellsize;
                        rect.MaxY                = rect.MinY + cellsize;
                        WorkCells[ix, iy]        = new RTrackCell(rect, Center);
                        WorkCells[ix, iy].Result = NumericalTools.ComputationResult.InvalidInput;
                    }
                }
                while (cr.EndOfStream == false)
                {
                    System.Text.RegularExpressions.Match m = rx_Cell.Match(cr.ReadLine());
                    if (m.Success)
                    {
                        ix = Convert.ToInt32(m.Groups[1].Value);
                        iy = Convert.ToInt32(m.Groups[2].Value);
                        WorkCells[ix, iy].Result           = NumericalTools.ComputationResult.OK;
                        WorkCells[ix, iy].Matches          = Convert.ToInt32(m.Groups[3].Value);
                        WorkCells[ix, iy].Average.X        = Convert.ToDouble(m.Groups[4].Value);
                        WorkCells[ix, iy].Average.Y        = Convert.ToDouble(m.Groups[5].Value);
                        WorkCells[ix, iy].AlignInfo.MXX    = Convert.ToDouble(m.Groups[6].Value);
                        WorkCells[ix, iy].AlignInfo.MXY    = Convert.ToDouble(m.Groups[7].Value);
                        WorkCells[ix, iy].AlignInfo.MYX    = Convert.ToDouble(m.Groups[8].Value);
                        WorkCells[ix, iy].AlignInfo.MYY    = Convert.ToDouble(m.Groups[9].Value);
                        WorkCells[ix, iy].AlignInfo.TX     = Convert.ToDouble(m.Groups[10].Value);
                        WorkCells[ix, iy].AlignInfo.TY     = Convert.ToDouble(m.Groups[11].Value);
                        WorkCells[ix, iy].AlignInfo.TZ     = Convert.ToDouble(m.Groups[12].Value);
                        WorkCells[ix, iy].SlopeAlignInfo.X = Convert.ToDouble(m.Groups[13].Value);
                        WorkCells[ix, iy].SlopeAlignInfo.Y = Convert.ToDouble(m.Groups[14].Value);
                    }
                }
                cr.Close();
                if (useconsole)
                {
                    GridInterpolation G1 = new GridInterpolation(WorkCells, cellsize, RefRect, (int)MinMatches);
                    Console.WriteLine("Type a pair of coordinates ( X Y ) to get the transformation map.\r\nEOF (CTRL+Z to exit).");
                    double x, y;
                    string line;
                    while ((line = Console.ReadLine()) != null)
                    {
                        System.Text.RegularExpressions.Match m = rx_XY.Match(line);
                        x = Convert.ToDouble(m.Groups[1].Value);
                        y = Convert.ToDouble(m.Groups[2].Value);
                        SySal.BasicTypes.Vector dslope = new SySal.BasicTypes.Vector();
                        SySal.DAQSystem.Scanning.IntercalibrationInfo dpos = new SySal.DAQSystem.Scanning.IntercalibrationInfo();
                        bool result = G1.Evaluate(x, y, ref dslope, ref dpos);
                        Console.WriteLine(x + " " + y + " -> " + (result ? "OK" : "FAILED") + " " + dpos.RX + " " + dpos.RY + " " + dpos.MXX + " " + dpos.MXY + " " + dpos.MYX + " " + dpos.MYY + " " + dpos.TX + " " + dpos.TY + " " + dpos.TZ + " " + dslope.X + " " + dslope.Y);
                    }
                    return;
                }
            }
            else
            {
                cellsize = Convert.ToDouble(args[3]);
                double slopetol  = Convert.ToDouble(args[4]);
                double postol    = Convert.ToDouble(args[5]);
                double possweep  = Convert.ToDouble(args[6]);
                double DZ        = Convert.ToDouble(args[7]);
                string selstring = args[8];
                MinMatches = Convert.ToUInt32(args[9]);
                double ZAdj       = Convert.ToDouble(args[10]);
                double ZStep      = Convert.ToDouble(args[11]);
                bool   IsParallel = Convert.ToBoolean(args[12]);
                NumericalTools.CStyleParsedFunction S = new NumericalTools.CStyleParsedFunction(selstring);
                dSel[] pMap = new dSel[S.ParameterList.Length];
                for (j = 0; j < S.ParameterList.Length; j++)
                {
                    string sp = S.ParameterList[j];
                    for (i = 0; i < KnownFunctions.Length && String.Compare(sp, KnownFunctions[i].Name, true) != 0; i++)
                    {
                        ;
                    }
                    if (i == KnownFunctions.Length)
                    {
                        throw new Exception("Unknown parameter \"" + sp + "\".");
                    }
                    pMap[j] = KnownFunctions[i].Evaluate;
                }
                SySal.Scanning.Plate.IO.OPERA.LinkedZone reflz = SySal.DataStreams.OPERALinkedZone.FromFile(reftlg);
                RefRect = reflz.Extents;
                if (WorkRect.MinX > RefRect.MinX)
                {
                    RefRect.MinX = WorkRect.MinX;
                }
                if (WorkRect.MaxX < RefRect.MaxX)
                {
                    RefRect.MaxX = WorkRect.MaxX;
                }
                if (WorkRect.MinY > RefRect.MinY)
                {
                    RefRect.MinY = WorkRect.MinY;
                }
                if (WorkRect.MaxY < RefRect.MaxY)
                {
                    RefRect.MaxY = WorkRect.MaxY;
                }
                Center.X = 0.5 * (RefRect.MinX + RefRect.MaxX);
                Center.Y = 0.5 * (RefRect.MinY + RefRect.MaxY);
                xcells   = (int)Math.Ceiling((RefRect.MaxX - RefRect.MinX) / cellsize);
                ycells   = (int)Math.Ceiling((RefRect.MaxY - RefRect.MinY) / cellsize);
                Console.WriteLine("X/Y Cells: " + xcells + "/" + ycells);
                if (xcells <= 0 || ycells <= 0)
                {
                    throw new Exception("Null working area.");
                }
                RTrackCell[,] RefCells = new RTrackCell[xcells, ycells];
                WorkCells = new RTrackCell[xcells, ycells];
                for (ix = 0; ix < xcells; ix++)
                {
                    for (iy = 0; iy < ycells; iy++)
                    {
                        SySal.BasicTypes.Rectangle rect = new SySal.BasicTypes.Rectangle();
                        rect.MinX         = RefRect.MinX + ix * cellsize;
                        rect.MaxX         = rect.MinX + cellsize;
                        rect.MinY         = RefRect.MinY + iy * cellsize;
                        rect.MaxY         = rect.MinY + cellsize;
                        RefCells[ix, iy]  = new RTrackCell(rect, Center);
                        WorkCells[ix, iy] = new RTrackCell(rect, Center);
                    }
                }
                SySal.Scanning.Plate.IO.OPERA.LinkedZone lz;
                RTrackCell[,] rtc;
                for (i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        lz  = reflz;
                        rtc = RefCells;
                    }
                    else
                    {
                        lz  = worklz;
                        rtc = WorkCells;
                    }
                    for (j = 0; j < lz.Length; j++)
                    {
                        SySal.Scanning.MIPBaseTrack tk = lz[j] as SySal.Scanning.MIPBaseTrack;
                        for (k = 0; k < pMap.Length; k++)
                        {
                            S[k] = pMap[k](tk);
                        }
                        if (S.Evaluate() != 0.0)
                        {
                            ix = (int)((tk.Info.Intercept.X - RefRect.MinX) / cellsize);
                            iy = (int)((tk.Info.Intercept.Y - RefRect.MinY) / cellsize);
                            if (ix >= 0 && ix < xcells && iy >= 0 && iy < ycells)
                            {
                                RTrack rtr = new RTrack();
                                rtr.Slope.X    = tk.Info.Slope.X;
                                rtr.Slope.Y    = tk.Info.Slope.Y;
                                rtr.Position.X = tk.Info.Intercept.X;
                                rtr.Position.Y = tk.Info.Intercept.Y;
                                rtc[ix, iy].Add(rtr);
                            }
                        }
                    }
                }
                for (ix = 0; ix < xcells; ix++)
                {
                    for (iy = 0; iy < ycells; iy++)
                    {
                        Console.WriteLine("Ref " + RefCells[ix, iy].Average.X + " " + RefCells[ix, iy].Average.Y + " " + RefCells[ix, iy].Count);
                        Console.WriteLine("Work " + WorkCells[ix, iy].Average.X + " " + WorkCells[ix, iy].Average.Y + " " + WorkCells[ix, iy].Count);
                    }
                }
                SySal.Processing.QuickMapping.QuickMapper   QM  = new SySal.Processing.QuickMapping.QuickMapper();
                SySal.Processing.QuickMapping.Configuration qmc = QM.Config as SySal.Processing.QuickMapping.Configuration;
                qmc.FullStatistics       = false;
                qmc.UseAbsoluteReference = true;
                qmc.PosTol   = postol;
                qmc.SlopeTol = slopetol;
                for (ix = 0; ix < xcells; ix++)
                {
                    for (iy = 0; iy < ycells; iy++)
                    {
                        SySal.Tracking.MIPEmulsionTrackInfo[] rinfo = new SySal.Tracking.MIPEmulsionTrackInfo[RefCells[ix, iy].Count];
                        SySal.Tracking.MIPEmulsionTrackInfo[] winfo = new SySal.Tracking.MIPEmulsionTrackInfo[WorkCells[ix, iy].Count];
                        for (i = 0; i < 2; i++)
                        {
                            SySal.Tracking.MIPEmulsionTrackInfo[] inf = (i == 0) ? rinfo : winfo;
                            RTrackCell[,] cells = (i == 0) ? RefCells : WorkCells;
                            double dz = (i == 0) ? 0.0 : DZ;
                            for (j = 0; j < inf.Length; j++)
                            {
                                RTrack r = cells[ix, iy].Get(j);
                                inf[j]             = new SySal.Tracking.MIPEmulsionTrackInfo();
                                inf[j].Slope.X     = r.Slope.X;
                                inf[j].Slope.Y     = r.Slope.Y;
                                inf[j].Intercept.X = r.Position.X;
                                inf[j].Intercept.Y = r.Position.Y;
                                inf[j].Intercept.Z = dz;
                            }
                        }
                        SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] pairs = new SySal.Scanning.PostProcessing.PatternMatching.TrackPair[0];
                        double bestdz = 0.0;
                        if (rinfo.Length >= 2 && winfo.Length >= 2)
                        {
                            double dz1;
                            if (IsParallel)
                            {
                                System.Collections.ArrayList thrarr = new System.Collections.ArrayList();
                                for (dz1 = -ZAdj; dz1 <= ZAdj; dz1 += ZStep)
                                {
                                    MapThread mthr = new MapThread();
                                    mthr.m_rinfo    = rinfo;
                                    mthr.m_winfo    = winfo;
                                    mthr.m_DZ       = DZ + dz1;
                                    mthr.m_PosSweep = possweep;
                                    mthr.m_PosTol   = postol;
                                    mthr.m_SlopeTol = slopetol;
                                    mthr.m_Thread   = new System.Threading.Thread(new System.Threading.ThreadStart(mthr.Execute));
                                    mthr.m_Thread.Start();
                                    thrarr.Add(mthr);
                                }
                                foreach (MapThread mt in thrarr)
                                {
                                    mt.m_Thread.Join();
                                    if (mt.m_Pairs.Length > pairs.Length)
                                    {
                                        bestdz = mt.m_DZ - DZ;
                                        pairs  = mt.m_Pairs;
                                    }
                                }
                            }
                            else
                            {
                                for (dz1 = -ZAdj; dz1 <= ZAdj; dz1 += ZStep)
                                {
                                    SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] qairs = QM.Match(rinfo, winfo, DZ + dz1, possweep, possweep);
                                    if (qairs.Length > pairs.Length)
                                    {
                                        bestdz = dz1;
                                        pairs  = qairs;
                                    }
                                }
                            }
                        }
                        double[] alignpars = new double[7];
                        SySal.BasicTypes.Vector2 slopedelta = new SySal.BasicTypes.Vector2();
                        SySal.BasicTypes.Vector2 slopetolv  = new SySal.BasicTypes.Vector2();
                        double[] dslx = new double[pairs.Length];
                        double[] dsly = new double[pairs.Length];
                        for (j = 0; j < pairs.Length; j++)
                        {
                            dslx[j] = pairs[j].First.Info.Slope.X - pairs[j].Second.Info.Slope.X;
                        }
                        PeakFit(dslx, slopetol, out slopedelta.X, out slopetolv.X);
                        for (j = 0; j < pairs.Length; j++)
                        {
                            dsly[j] = pairs[j].First.Info.Slope.Y - pairs[j].Second.Info.Slope.Y;
                        }
                        PeakFit(dsly, slopetol, out slopedelta.Y, out slopetolv.Y);
                        int gooddslopes = 0;
                        for (j = 0; j < pairs.Length; j++)
                        {
                            if ((slopedelta.X - slopetolv.X) < dslx[j] && dslx[j] < (slopedelta.X + slopetolv.X) && (slopedelta.Y - slopetolv.Y) < dsly[j] && dsly[j] < (slopedelta.Y + slopetolv.Y))
                            {
                                gooddslopes++;
                            }
                        }
                        if (gooddslopes > 0)
                        {
                            double[] DX = new double[gooddslopes];
                            double[] DY = new double[gooddslopes];
                            double[] X  = new double[gooddslopes];
                            double[] Y  = new double[gooddslopes];
                            double[] SX = new double[gooddslopes];
                            double[] SY = new double[gooddslopes];
                            for (j = i = 0; j < pairs.Length; j++)
                            {
                                if ((slopedelta.X - slopetolv.X) < dslx[j] && dslx[j] < (slopedelta.X + slopetolv.X) && (slopedelta.Y - slopetolv.Y) < dsly[j] && dsly[j] < (slopedelta.Y + slopetolv.Y))
                                {
                                    X[i]  = pairs[j].Second.Info.Intercept.X - WorkCells[ix, iy].AlignInfo.RX;
                                    Y[i]  = pairs[j].Second.Info.Intercept.Y - WorkCells[ix, iy].AlignInfo.RY;
                                    SX[i] = pairs[j].Second.Info.Slope.X;
                                    SY[i] = pairs[j].Second.Info.Slope.Y;
                                    DX[i] = pairs[j].First.Info.Intercept.X - pairs[j].Second.Info.Intercept.X;
                                    DY[i] = pairs[j].First.Info.Intercept.Y - pairs[j].Second.Info.Intercept.Y;
                                    //System.IO.File.AppendAllText(@"c:\flattentlg.txt", "\r\n" + ix + " " + iy + " " + i + " " + j + " " + pairs.Length + " " + gooddslopes + " " + WorkCells[ix, iy].AlignInfo.RX + " " + WorkCells[ix, iy].AlignInfo.RY + " " + X[i] + " " + Y[i] + " " + SX[i] + " " + SY[i] + "  " + DX[i] + " " + DY[i] + " " + bestdz);
                                    i++;
                                }
                            }
                            WorkCells[ix, iy].Result = IteratedAffineFocusing(DX, DY, X, Y, SX, SY, postol, ref alignpars);
                        }
                        else
                        {
                            WorkCells[ix, iy].Result = NumericalTools.ComputationResult.InvalidInput;
                        }
                        WorkCells[ix, iy].Matches        = pairs.Length;
                        WorkCells[ix, iy].AlignInfo.TZ   = alignpars[6] + bestdz;
                        WorkCells[ix, iy].AlignInfo.TX   = alignpars[4];
                        WorkCells[ix, iy].AlignInfo.TY   = alignpars[5];
                        WorkCells[ix, iy].AlignInfo.MXX  = 1.0 + alignpars[0];
                        WorkCells[ix, iy].AlignInfo.MXY  = 0.0 + alignpars[1];
                        WorkCells[ix, iy].AlignInfo.MYX  = 0.0 + alignpars[2];
                        WorkCells[ix, iy].AlignInfo.MYY  = 1.0 + alignpars[3];
                        WorkCells[ix, iy].SlopeAlignInfo = slopedelta;
                        Console.WriteLine("Fit " + WorkCells[ix, iy].Result + " " + WorkCells[ix, iy].AlignInfo.MXX + " " + WorkCells[ix, iy].AlignInfo.MXY + " " + WorkCells[ix, iy].AlignInfo.MYX + " " + WorkCells[ix, iy].AlignInfo.MYY + " " + WorkCells[ix, iy].AlignInfo.TX + " " + WorkCells[ix, iy].AlignInfo.TY + " " + WorkCells[ix, iy].AlignInfo.TZ + " " + WorkCells[ix, iy].SlopeAlignInfo.X + " " + WorkCells[ix, iy].SlopeAlignInfo.Y);
                    }
                }
                int goodcells = 0;
                for (ix = 0; ix < xcells; ix++)
                {
                    for (iy = 0; iy < ycells; iy++)
                    {
                        if (WorkCells[ix, iy].Result == NumericalTools.ComputationResult.OK && WorkCells[ix, iy].Matches >= MinMatches)
                        {
                            goodcells++;
                        }
                    }
                }
                Console.WriteLine("Good cells: " + goodcells);

                Console.WriteLine("--------CELLS");
                Console.WriteLine("CELLMAP " + RefRect.MinX + " " + RefRect.MaxX + " " + RefRect.MinY + " " + RefRect.MaxY + " " + cellsize + " " + xcells + " " + ycells);
                Console.WriteLine("IX\tIY\tN\tX\tY\tMXX\tMXY\tMYX\tMYY\tTX\tTY\tTZ\tTDSX\tTDSY");
                for (ix = 0; ix < xcells; ix++)
                {
                    for (iy = 0; iy < ycells; iy++)
                    {
                        if (WorkCells[ix, iy].Result == NumericalTools.ComputationResult.OK && WorkCells[ix, iy].Matches >= MinMatches)
                        {
                            Console.WriteLine(ix + "\t" + iy + "\t" + WorkCells[ix, iy].Matches + "\t" + WorkCells[ix, iy].Average.X + "\t" + WorkCells[ix, iy].Average.Y + "\t" + WorkCells[ix, iy].AlignInfo.MXX + "\t" + WorkCells[ix, iy].AlignInfo.MXY + "\t" + WorkCells[ix, iy].AlignInfo.MYX + "\t" + WorkCells[ix, iy].AlignInfo.MYY + "\t" + WorkCells[ix, iy].AlignInfo.TX + "\t" + WorkCells[ix, iy].AlignInfo.TY + "\t" + WorkCells[ix, iy].AlignInfo.TZ + "\t" + WorkCells[ix, iy].SlopeAlignInfo.X + "\t" + WorkCells[ix, iy].SlopeAlignInfo.Y);
                        }
                    }
                }
                Console.WriteLine("--------ENDCELLS");
            }
            SySal.DataStreams.OPERALinkedZone.Writer outlzw = new SySal.DataStreams.OPERALinkedZone.Writer(outtlg, worklz.Id, worklz.Extents, worklz.Center, worklz.Transform);
            outlzw.SetZInfo(worklz.Top.TopZ, worklz.Top.BottomZ, worklz.Bottom.TopZ, worklz.Bottom.BottomZ);
            for (i = 0; i < ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.Side)worklz.Top).ViewCount; i++)
            {
                outlzw.AddView(((SySal.Scanning.Plate.IO.OPERA.LinkedZone.Side)worklz.Top).View(i), true);
            }
            for (i = 0; i < ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.Side)worklz.Bottom).ViewCount; i++)
            {
                outlzw.AddView(((SySal.Scanning.Plate.IO.OPERA.LinkedZone.Side)worklz.Bottom).View(i), false);
            }
            SySal.BasicTypes.Vector proj       = new SySal.BasicTypes.Vector();
            Console.WriteLine("Writing flattened TLG...");
            GridInterpolation G = new GridInterpolation(WorkCells, cellsize, RefRect, (int)MinMatches);

            System.DateTime start = System.DateTime.Now;
            for (i = 0; i < worklz.Length; i++)
            {
                if (i % 1000 == 0)
                {
                    System.DateTime nw = System.DateTime.Now;
                    if ((nw - start).TotalMilliseconds >= 10000)
                    {
                        Console.WriteLine((i * 100 / worklz.Length) + "%");
                        start = nw;
                    }
                }
                SySal.Tracking.MIPEmulsionTrackInfo           baseinfo      = worklz[i].Info;
                SySal.DAQSystem.Scanning.IntercalibrationInfo transforminfo = new SySal.DAQSystem.Scanning.IntercalibrationInfo();
                transforminfo.RX = Center.X;
                transforminfo.RY = Center.Y;
                SySal.BasicTypes.Vector tds = new SySal.BasicTypes.Vector();

                G.Evaluate(baseinfo.Intercept.X, baseinfo.Intercept.Y, ref tds, ref transforminfo);

                proj.X             = -baseinfo.Slope.X * transforminfo.TZ;
                proj.Y             = -baseinfo.Slope.Y * transforminfo.TZ;
                proj.Z             = 0.0;
                baseinfo.Intercept = transforminfo.Transform(baseinfo.Intercept) + proj;
                baseinfo.Slope     = transforminfo.Deform(baseinfo.Slope) + tds;
                SySal.Scanning.MIPIndexedEmulsionTrack toptk      = worklz[i].Top;
                SySal.Tracking.MIPEmulsionTrackInfo    topinfo    = toptk.Info;
                SySal.Scanning.MIPIndexedEmulsionTrack bottomtk   = worklz[i].Bottom;
                SySal.Tracking.MIPEmulsionTrackInfo    bottominfo = bottomtk.Info;
                topinfo.Intercept    = transforminfo.Transform(topinfo.Intercept) + proj;
                topinfo.Slope        = transforminfo.Deform(topinfo.Slope) + tds;
                bottominfo.Intercept = transforminfo.Transform(bottominfo.Intercept) + proj;
                bottominfo.Slope     = transforminfo.Deform(bottominfo.Slope) + tds;
                outlzw.AddMIPEmulsionTrack(topinfo, i, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)toptk).View.Id, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)toptk).OriginalRawData, true);
                outlzw.AddMIPEmulsionTrack(bottominfo, i, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)bottomtk).View.Id, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)bottomtk).OriginalRawData, false);
                outlzw.AddMIPBasetrack(baseinfo, i, i, i);
            }
            outlzw.Complete();
            Console.WriteLine("Written \"" + outtlg + "\".");
        }