Example #1
0
        public string GenerateReport(ScriptContext context, MIRSRegistration mirsReg,
                                     IEnumerable <VVector> sourcePoints,
                                     IEnumerable <VVector> registeredPoints,
                                     IEnumerable <VVector> transformedPoints,
                                     RegStats stats)
        {
            // userid {0}, report time {1}, patient {2}, source dataset {3}, registered dataset {4}.
            string htmlStartFmt = @"
                <HTML>
                  <BODY text=""black"" bgColor=""white"">
                    <H2>Registration Report</H2>
                    Created by {0} on {1}
                    <br/><br/>
                    <table>
                      <tr><td>Patient:</td><td>{2}</td></tr>
                      <tr><td>Source Dataset:</td><td>{3}</td></tr>
                      <tr><td>Registered Dataset:</td><td>{4}</td></tr>
                    </table>";
            string htmlEnd      = "</BODY></HTML>";

            // reg id {0}, reg type {1}, min {2}, max{3}, mean {4}
            string htmlRegHeaderFmt = @"
                <H3>Registration:     {0} (type: {1})</H3>
                <H4>Error Statistics:</H4>
                <table>
                  <tr><td>Min:</td><td>{2:0.0}</td><td>mm</td></tr>
                  <tr><td>Max:</td><td>{3:0.0}</td><td>mm</td></tr>
                  <tr><td>Mean:</td><td>{4:0.0}</td><td>mm</td></tr>
                </table>
                <table border=""1"">
                  <tr>
                    <th>point #</th>
                    <th>Source Match Point</th>
                    <th>Registered Match Point</th>
                    <th>Derived Match Point</th>
                    <th>Distance (mm)</th>
                  </tr>";
            string htmlRegFooter    = "</table>";

            // point # {0}, source match point {1}, registered match point {2}, derived match point {3}, distance {4}
            string htmlPointRowFmt = @"
                <tr>
                <td>{0}</td>
                <td>{1:0.0}</td>
                <td>{2:0.0}</td>
                <td>{3:0.0}</td>
                <td>{4:0.0}</td>
                </tr>";

            // point.x {0}, point.y {1}, point.z {2}
            string htmlFirstIndividualPointFmt = @"
                <table>
                    <tr><td>x: {0:0.0}</td></tr>
                    <tr><td>y: {1:0.0}</td></tr>
                    <tr><td>z: {2:0.0}</td></tr>
                </table>";

            string htmlIndividualPointFmt = @"
                <table>
                    <tr><td>{0:0.0}</td></tr>
                    <tr><td>{1:0.0}</td></tr>
                    <tr><td>{2:0.0}</td></tr>
                </table>";

            string temp     = System.Environment.GetEnvironmentVariable("TEMP");
            string htmlPath = string.Format("{0}\\reg_report.html", temp);

            // open file "%temp%\points.html"
            using (System.IO.TextWriter writer = new System.IO.StreamWriter(htmlPath))
            {
                // build the HTML header and write that
                // userid {0}, report time {1}, patient {2}, source dataset {3}, registered dataset {4}.
                writer.Write(string.Format(htmlStartFmt, context.CurrentUser.Name, DateTime.Now,
                                           context.Patient.Id, mirsReg.SourceImage.Id, mirsReg.RegisteredImage.Id));

                // write the reg header
                writer.Write(string.Format(htmlRegHeaderFmt, mirsReg.Id, mirsReg.ToString(), stats.min, stats.max, stats.mean));

                // list points for the registration
                int numPoints = sourcePoints.Count();
                for (int i = 0; i < numPoints; i++)
                {
                    VVector source     = sourcePoints.ElementAt(i);
                    VVector registered = registeredPoints.ElementAt(i);
                    VVector derived    = transformedPoints.ElementAt(i);
                    double  distance   = VVector.Distance(registered, derived);
                    string  oneRow     =
                        string.Format(htmlPointRowFmt, i + 1,
                                      string.Format(htmlFirstIndividualPointFmt, source.x, source.y, source.z),
                                      string.Format(htmlIndividualPointFmt, registered.x, registered.y, registered.z),
                                      string.Format(htmlIndividualPointFmt, derived.x, derived.y, derived.z),
                                      distance.ToString(".0"));
                    writer.Write(oneRow);
                }
                // write the registration footer.
                writer.Write(htmlRegFooter);
                // end the HTML document
                writer.Write(htmlEnd);
            }
            return(htmlPath);
        }