예제 #1
0
        public void writeSVG(Scientrace.PhysicalObject3d anObject)
        {
            foreach (Scientrace.PDPSource pdpSource in this.exportPDPSources)
            {
                foreach (Scientrace.SurfaceSide side in anObject.surface_sides)
                {
                    DateTime start_time = DateTime.Now;
                    //Write down SVG trace-pattern of an object for side "side"
                    string filename = this.svgfilename.Replace("%o", anObject.tag + "-" + side.ToString() + "-" + pdpSource.ToString());
                    this.writeExportDataToFile(this.exportSVG(anObject, side, pdpSource), filename, side.ToString() + "@" + anObject.tag + "-SVG", start_time);
                }
            }

            /*
             * StreamWriter writestream;
             *
             * foreach (Scientrace.PDPSource pdpSource in this.exportPDPSources)
             * foreach (Scientrace.SurfaceSide side in anObject.surface_sides) {
             *
             *      //Write down SVG trace-pattern of an object for side "side"
             *      string filename = this.exportpath+this.svgfilename.Replace("%o",anObject.tag+"-"+side.ToString()+"-"+pdpSource.ToString());
             *      Console.WriteLine("Writing SVG to: " +filename);
             *      using (writestream = new StreamWriter(filename)) {
             *              writestream.Write(this.exportSVG(anObject, side, pdpSource));
             *              }
             *      }
             */
        }
예제 #2
0
        public override void write(Scientrace.PhysicalObject3d anObject)
        {
            Scientrace.UnitVector normvec = anObject.getSurfaceNormal();
            this.fillPlaneVectors(normvec);

            this.write2dHistogramForPlane(anObject, "A = ref x norm", this.plane_a_vecs[normvec]);
            this.write2dHistogramForPlane(anObject, "B = norm x A", this.plane_b_vecs[normvec]);
            this.write2dHistogramForPlane(anObject, "1D histogram", null);
        }
예제 #3
0
 public DistributionSquare getDistributionSquare(Scientrace.PhysicalObject3d anObject, int order)
 {
     Scientrace.Parallelogram      surface = anObject.getDistributionSurface();
     Scientrace.DistributionSquare ds      = new Scientrace.DistributionSquare(0, order, surface.plane.loc, surface.plane.u, surface.plane.v);
     foreach (Scientrace.Spot aSpot in this.spots)
     {
         ds.addSpot(aSpot.loc);
     }
     return(ds);
 }
/* Histogram methods */
        protected void writeExportHistograms(Scientrace.PhysicalObject3d anObject)
        {
            foreach (TraceJournalExportable exportable in this.exportables)
            {
                if (exportable.export)
                {
                    exportable.write(anObject);
                    //exportable.writeAngleHistogramCSV(anObject);
                }
            }
        }
        public string spotDescriptor(Scientrace.Spot aSpot, Scientrace.PhysicalObject3d anObject, bool bracket)
        {
            string retstr = "intensity:" + String.Format("{0:#.##E+00}", aSpot.intensity) +           //display absolute intensity
                            "(" + (String.Format("{0:0.00}", aSpot.intensityFraction * 100)) + "%)" + //display intensity as a percentage
                            ", wavelength:" + String.Format("{0:00.0}", aSpot.trace.wavelenght * 1E9) + "nm" +
                            ", " + aSpot.trace.ToCompactString() +
                            //", #"+aSpot.GetHashCode()+ //hash code for spot
                            "\nroot: " + aSpot.trace.getParentRoot().ToCompactString()
            ;

            //Console.WriteLine("wl = "+aSpot.trace.wavelenght.ToString());

            return(bracket ? "( " + retstr + " )" : retstr);
        }
예제 #6
0
        public override void write(Scientrace.PhysicalObject3d anObject)
        {
            Dictionary <string, double> angle_histogram = this.getHistogramTemplate();

            foreach (Scientrace.Spot casualty in this.tj.spots)
            {
                //only count casualties for current object.
                if (casualty.object3d != anObject)
                {
                    continue;
                }

                if (casualty == null)
                {
                    Console.WriteLine("Error: Casualty is null when writing angle histogram for {" + anObject.ToString() + "}...");
                    continue;
                }

                //The angle on which the histogram bin is based.
                double angle_rad = anObject.getSurfaceNormal().negative().angleWith(casualty.trace.traceline.direction);

                //Moved to new method: radiansToRoundedDegString

                /*double angle_deg = angle_rad*180/Math.PI;
                 * double angle_deg_mod =((180+angle_deg)%360)-180;
                 * string bin = this.toResString(angle_deg_mod);*/
                string bin = this.radiansToRoundedDegString(angle_rad);

                double reweigh_factor = (this.lightsource_weigh_intensity)
                                ? (casualty.trace.lightsource.weighted_intensity / casualty.trace.lightsource.total_lightsource_intensity)
                                : 1;
                this.addToBin(angle_histogram, bin, casualty.intensity * reweigh_factor, true);

                /*
                 * //Console.WriteLine("bin: "+bin+", angledegmod:"+angle_deg_mod+", hist_res:"+this.angle_histogram_resolution);
                 * if (angle_histogram.ContainsKey(bin)) //{
                 *      angle_histogram[bin] = angle_histogram[bin]+casualty.intensity;
                 *      //Console.WriteLine("bin {"+bin+"} increased."); }
                 *      else {
                 *      this.addToOtherBin(casualty.intensity, angle_histogram);
                 *      //Console.WriteLine("WARNING: BIN {"+bin+"} NOT FOUND FOR HISTOGRAM."+angle_deg_mod+"/"+angle_deg);\
                 *      } */
            }

            string angle_histogram_csv_filename = this.tj.exportpath + this.angle_histogram_csv_filename.Replace("%o", anObject.tag);

            this.appendWriteWithConfigVariables(angle_histogram_csv_filename, angle_histogram);
        }
예제 #7
0
        public void write2dHistogramForPlane(Scientrace.PhysicalObject3d anObject, string plane_descr, Scientrace.UnitVector plane_vector)
        {
            Scientrace.UnitVector normvec = anObject.getSurfaceNormal();

            Dictionary <string, double> angle_histogram = this.getHistogramTemplate();

            foreach (Scientrace.Spot casualty in this.tj.spots)
            {
                //only count casualties for current object.
                if (casualty.object3d != anObject)
                {
                    continue;
                }

                if (casualty == null)
                {
                    Console.WriteLine("Error: Casualty is null when writing angle histogram2d for {" + anObject.ToString() + "} plane {" + plane_descr + "}...");
                    continue;
                }

                double angle_rad;
                if (plane_vector == null)
                {
                    angle_rad = anObject.getSurfaceNormal().negative().angleWith(casualty.trace.traceline.direction);
                }
                else
                {
                    //2d unraveling
                    Scientrace.Vector vecOnPlane = casualty.trace.traceline.direction.projectOnPlaneWithNormal(plane_vector);
                    //The angle on which the histogram bin is based.
                    angle_rad = normvec.negative().angleWith(vecOnPlane);
                }

                string bin = this.radiansToRoundedDegString(angle_rad);

                double reweigh_factor = (this.lightsource_weigh_intensity)
                                ? (casualty.trace.lightsource.weighted_intensity / casualty.trace.lightsource.total_lightsource_intensity)
                                : 1;
                //Console.WriteLine("Line: "+casualty.trace.traceline.direction.trico()+" becomes: "+vecOnPlane.trico()+" angle:"+angle_rad+" / "+bin);
                this.addToBin(angle_histogram, bin, casualty.intensity * reweigh_factor, true);
            }

            string angle_histogram_csv_filename = this.tj.exportpath + this.angle_histogram_csv_filename.Replace("%o", anObject.tag).Replace("%t", this.tag).Replace("%s", plane_descr.Replace(" ", "_"));

            this.addHist2dConfigVars(normvec, plane_descr);
            //this.extra_exportable_config_vars.Add(plane_description, plane_vector);
            this.appendWriteWithConfigVariables(angle_histogram_csv_filename, angle_histogram);
        }
        public string exportSVGOpening(Scientrace.PhysicalObject3d anObject)
        {
            double[] vb = anObject.getViewBorders();
            //double ToTot = ((vb[2]-vb[0])+(vb[3]-vb[1]))/100;
            double        ToX         = anObject.svgxsize / (vb[2] - vb[0]);
            double        ToY         = anObject.svgysize / (vb[3] - vb[1]);
            double        ToTot       = Math.Sqrt(Math.Pow(ToX, 2) + Math.Pow(ToY, 2));
            string        strokewidth = (ToTot * ((vb[2] - vb[0]) + (vb[3] - vb[1])) / 800.0).ToString("#.##############"); //0.25% linewidth
            StringBuilder retstr      = new StringBuilder(1024);

            retstr.Append(@"<?xml version='1.0' standalone='no'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>


<svg width='1600' height='1200' version='1.1' viewBox='" + anObject.getRelMarginViewBox(0.1, 0.1, 0.25, 0.25) + @"'
xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
<rect width='100%' height='100%' fill='white' />
<desc>Drawing center crosshair</desc>");
            if (this.svggrid)       // GRID
            {
                retstr.Append(@"<g stroke='lightgray'>
<line x1='" + vb[0] + "' y1='" + (vb[1] + ((vb[3] - vb[1]) / 4.0)) + "' x2='" + vb[2] + "' y2='" + (vb[1] + ((vb[3] - vb[1]) / 4.0)) + "' stroke-width='" + strokewidth + @"'  />
<line x1='" + vb[0] + "' y1='" + (vb[1] + ((vb[3] - vb[1]) * 3.0 / 4.0)) + "' x2='" + vb[2] + "' y2='" + (vb[1] + ((vb[3] - vb[1]) * 3.0 / 4.0)) + "' stroke-width='" + strokewidth + @"'  />
<line x1='" + (vb[0] + ((vb[2] - vb[0]) / 4.0)) + "' y1='" + vb[1] + "' x2='" + (vb[0] + ((vb[2] - vb[0]) / 4.0)) + "' y2='" + vb[3] + "' stroke-width='" + strokewidth + @"'  />
<line x1='" + (vb[0] + ((vb[2] - vb[0]) * 3.0 / 4.0)) + "' y1='" + vb[1] + "' x2='" + (vb[0] + ((vb[2] - vb[0]) * 3.0 / 4.0)) + "' y2='" + vb[3] + "' stroke-width='" + strokewidth + @"'  />
</g>
<g stroke='gray'>
<line x1='" + vb[0] + "' y1='" + (vb[1] + ((vb[3] - vb[1]) / 2.0)) + "' x2='" + vb[2] + "' y2='" + (vb[1] + ((vb[3] - vb[1]) / 2.0)) + "' stroke-width='" + strokewidth + @"'  />
<line x1='" + (vb[0] + ((vb[2] - vb[0]) / 2.0) + "' y1='" + vb[1]) + "' x2='" + (vb[0] + ((vb[2] - vb[0]) / 2.0)) + "' y2='" + vb[3] + "' stroke-width='" + strokewidth + @"'  />
</g>");
            } // END GRID CODE

            retstr.Append(@"<desc>Drawing borders</desc>
<rect x='" + vb[0] + "' y='" + vb[1] + "' width='" + (vb[2] - vb[0]) + "' height='" + (vb[3] - vb[1]) + @"'
        fill='none' stroke='black' stroke-width='" + strokewidth + @"'/>

<desc>Spots on the surface:</desc>");
            return(retstr.ToString());
        }
예제 #9
0
 public HorizontalGridSurfaceMarker(Scientrace.PhysicalObject3d parentObject) : base(parentObject)
 {
 }
예제 #10
0
 public SurfaceMarker(Scientrace.PhysicalObject3d parentObject)
 {
     this.marksObject = parentObject;
 }
예제 #11
0
 public SurfaceMarker(Scientrace.PhysicalObject3d parentObject)
 {
     this.marksObject = parentObject;
 }
 public abstract void write(Scientrace.PhysicalObject3d anObject);
        public string exportSVG(Scientrace.PhysicalObject3d anObject, Scientrace.SurfaceSide side, Scientrace.PDPSource pdpSource)
        {
            //Scientrace.Parallelogram surface = anObject.getDistributionSurface();
            //this.spotsize = Math.Sqrt(Math.Pow(surface.u.length,2)+Math.Pow(surface.v.length,2))*this.spotdiagonalfraction;
            this.spotsize = Math.Sqrt(Math.Pow(anObject.svgxsize, 2) + Math.Pow(anObject.svgysize, 2)) * this.spotdiagonalfraction;
            StringBuilder retstr = new StringBuilder(10000000);     // this string may become very big, allocating this amount of memory may help.

            retstr.Append(this.exportSVGOpening(anObject));

            Scientrace.Location loc2d;

            StringBuilder pol_lines   = new StringBuilder("<!-- START OF POLARISATION LINES -->", 300000);
            StringBuilder centerSpots = new StringBuilder("<!-- START OF SPOTS CENTERS -->", 300000);

            //Console.WriteLine("Now writing "+this.spots.Count+" spots");
            //int icount = 0;
            foreach (Scientrace.Spot casualty in this.spots)
            {
                if ((casualty.object3d == anObject) &&
                    (anObject.directedTowardsObjectside(side, casualty.trace)))
                {
                    loc2d = anObject.getSVG2DLoc(casualty.loc);


//				double pol_fac_1 = Math.Pow(casualty.pol_vec_1.length,2)*1.0;//*casualty.pol_vec_1.length * casualty.intensity*3;
//				double pol_fac_2 = Math.Pow(casualty.pol_vec_2.length,2)*1.0;//*casualty.pol_vec_2.length * casualty.intensity*3;

                    double pol_fac_1 = Math.Pow(casualty.pol_vec_1.length, 1) * 1.00 * Math.Sqrt(casualty.intensity);       //*casualty.pol_vec_1.length * casualty.intensity*3;
                    double pol_fac_2 = Math.Pow(casualty.pol_vec_2.length, 1) * 1.00 * Math.Sqrt(casualty.intensity);       //*casualty.pol_vec_2.length * casualty.intensity*3;

                    Scientrace.Vector pol_vec_1_2d = (anObject.get2DLoc(
                                                          casualty.pol_vec_1.projectOnPlaneWithNormal(anObject.getSurfaceNormal()).toLocation()
                                                          ) - anObject.get2DLoc(Location.ZeroLoc())).normaliseIfNotZero() * pol_fac_1;
                    Scientrace.Vector pol_vec_2_2d = (anObject.get2DLoc(
                                                          casualty.pol_vec_2.projectOnPlaneWithNormal(anObject.getSurfaceNormal()).toLocation()
                                                          ) - anObject.get2DLoc(Location.ZeroLoc())).normaliseIfNotZero() * pol_fac_2;

                    if (this.svg_export_photoncloud)
                    {
                        retstr.Append(@"<g>
<circle cx='" + loc2d.x + "' cy='" + (anObject.svgysize - loc2d.y) + "' r='" + (Math.Sqrt(casualty.intensity) * this.spotsize) + "' style='" +
                                      "fill:" + this.getPhotonColourForPDPSource(casualty, pdpSource, anObject)
                                      + @";fill-opacity:0.3;stroke:none'>
<title><!-- Tooltip -->" + this.spotDescriptor(casualty, anObject, true) + @"</title>
</circle>
</g>");
                    }             // end if draw photoncloud (to create the frogg-egg kinda image)

                    centerSpots.Append(@"<g>
<circle cx='" + loc2d.x + "' cy='" + (anObject.svgysize - loc2d.y) + "' r='" + (Math.Sqrt(casualty.intensity) * this.spotsize / (this.svg_export_photoncloud?4:1)) + "' style='" +
                                       "fill:" + this.getPhotonColourForPDPSource(casualty, pdpSource, anObject)
                                       + @";fill-opacity:8;stroke:none'>
<title><!-- Tooltip -->" + this.spotDescriptor(casualty, anObject, false) + @"</title>
</circle>
</g>");
                    pol_lines.Append(@"
 <line x1='" + (loc2d.x - (pol_vec_1_2d.x * this.spotsize)) + "' y1='" + (anObject.svgysize - (loc2d.y - (pol_vec_1_2d.y * this.spotsize))) + "' x2='" + (loc2d.x + (pol_vec_1_2d.x * this.spotsize)) + "' y2='" + (anObject.svgysize - (loc2d.y + (pol_vec_1_2d.y * this.spotsize))) + "' style='stroke:rgb(0,96,192);stroke-width:" + (casualty.intensity * this.spotsize / 5) + @"' />
 <line x1='" + (loc2d.x - (pol_vec_2_2d.x * this.spotsize)) + "' y1='" + (anObject.svgysize - (loc2d.y - (pol_vec_2_2d.y * this.spotsize))) + "' x2='" + (loc2d.x + (pol_vec_2_2d.x * this.spotsize)) + "' y2='" + (anObject.svgysize - (loc2d.y + (pol_vec_2_2d.y * this.spotsize))) + "' style='stroke:rgb(192,96,0);stroke-width:" + (casualty.intensity * this.spotsize / 5) + @"' />
 <line x1='" + (loc2d.x - (pol_vec_1_2d.x * this.spotsize)) + "' y1='" + (anObject.svgysize - (loc2d.y - (pol_vec_1_2d.y * this.spotsize))) + "' x2='" + (loc2d.x + (pol_vec_1_2d.x * this.spotsize)) + "' y2='" + (anObject.svgysize - (loc2d.y + (pol_vec_1_2d.y * this.spotsize))) + "' style='stroke:rgb(256,256,256);stroke-width:" + (casualty.intensity * this.spotsize / 8) + @"' />
 <line x1='" + (loc2d.x - (pol_vec_2_2d.x * this.spotsize)) + "' y1='" + (anObject.svgysize - (loc2d.y - (pol_vec_2_2d.y * this.spotsize))) + "' x2='" + (loc2d.x + (pol_vec_2_2d.x * this.spotsize)) + "' y2='" + (anObject.svgysize - (loc2d.y + (pol_vec_2_2d.y * this.spotsize))) + "' style='stroke:rgb(256,256,256);stroke-width:" + (casualty.intensity * this.spotsize / 8) + @"' />
");
                }                 // end condition for spot to be on the correct object and from the proper direction
            }
            centerSpots.Append("<!-- END OF CENTERSPOTS -->");
            pol_lines.Append("<!-- END OF POLARISATION LINES -->");
            retstr.Append(centerSpots);
            retstr.Append(pol_lines);
            foreach (Scientrace.SurfaceMarker marker in anObject.markers)
            {
                retstr.Append(marker.exportSVG());
            }
            if (this.inline_legend)
            {
                retstr.Append("<!-- Start Legend for " + pdpSource.ToString() + " -->");
                retstr.Append(this.colourLegend(pdpSource));
                retstr.Append("<!-- End Legend for " + pdpSource.ToString() + " -->");
            }
            retstr.Append("</svg> ");
            return(retstr.ToString());
        }
/* End of Dictionary Export methods */


        public void writePhotondumpCSV(Scientrace.PhysicalObject3d anObject)
        {
            Scientrace.Location loc2d;
            List <string>       header = new List <string>();

            // FIELDS: IDENTIFIER DIRX DIRY DIRZ SURFACEANGLE LOCX LOCY LOCZ ...
            // ... 2DLOCX 2DLOCY 2DLOCZ WAVELENGTH RGBCOLOUR DISTANCE INTENSITY INTENSITYFRACTION

            header.Add("IDENTIFIER");
            header.Add("DIRX");
            header.Add("DIRY");
            header.Add("DIRZ");
            header.Add("SURFACEANGLE");
            header.Add("LOCX");
            header.Add("LOCY");
            header.Add("LOCZ");
            header.Add("2DLOCX");
            header.Add("2DLOCY");
            header.Add("2DLOCZ");
            header.Add("WAVELENGTH");
            header.Add("RGBCOLOR");
            header.Add("DISTANCE");
            header.Add("CASUALTYINTENSITY");
            header.Add("TRACESOURCEINTENSITY");
            header.Add("INTENSITYFRACTION");
            header.Add("Pol1DirX");
            header.Add("Pol1DirY");
            header.Add("Pol1DirZ");
            header.Add("Pol1Len");
            header.Add("Pol2DirX");
            header.Add("Pol2DirY");
            header.Add("Pol2DirZ");
            header.Add("Pol2Len");
            //string csvphotondumpfilename = this.exportpath+this.config_id.Replace("%","-")+this.yieldtablefilename.Replace("%o", anObject.tag)+".tracedump.csv";
            string csvphotondumpfilename = this.exportpath + this.photondumpfilename.Replace("%o", anObject.tag);

            using (StreamWriter csvphotondumpwritestream = new StreamWriter(csvphotondumpfilename)) {
                csvphotondumpwritestream.WriteLine(TraceJournal.csvLine(header));
                foreach (Scientrace.Spot casualty in this.spots)
                {
                    if (casualty == null)
                    {
                        Console.WriteLine("WARNING: Casualty null value found. That's weird...");
                    }
                    List <string> body = new List <string>();
                    if (casualty.object3d == anObject)
                    {
                        try {
                            loc2d = anObject.get2DLoc(casualty.loc);
                            body.Add(casualty.trace.traceid);                          // IDENTIFIER
                            body.Add(casualty.trace.traceline.direction.x.ToString()); // DIRX
                            body.Add(casualty.trace.traceline.direction.y.ToString()); // DIRY
                            body.Add(casualty.trace.traceline.direction.z.ToString()); // DIRZ
                            body.Add(anObject.getSurfaceNormal().angleWith(casualty.trace.traceline.direction).ToString());
                            body.Add(casualty.loc.x.ToString());                       //LOCX
                            body.Add(casualty.loc.y.ToString());                       //LOCY
                            body.Add(casualty.loc.z.ToString());                       //LOCZ
                            body.Add(loc2d.x.ToString());                              //2DLOCX
                            body.Add(loc2d.y.ToString());                              //2DLOCY
                            body.Add(loc2d.z.ToString());                              //2DLOCZ
                            body.Add(casualty.trace.wavelenght.ToString());
                            body.Add(this.wavelengthToRGB(casualty.trace.wavelenght));
                            body.Add(casualty.trace.tracedistance.ToString());
                            body.Add(casualty.intensity.ToString());
                            body.Add(casualty.trace.original_intensity.ToString());
                            body.Add(casualty.intensityFraction.ToString());
                            body.Add(casualty.pol_vec_1.x.ToString());
                            body.Add(casualty.pol_vec_1.y.ToString());
                            body.Add(casualty.pol_vec_1.z.ToString());
                            body.Add(casualty.pol_vec_1.length.ToString());
                            body.Add(casualty.pol_vec_2.x.ToString());
                            body.Add(casualty.pol_vec_2.y.ToString());
                            body.Add(casualty.pol_vec_2.z.ToString());
                            body.Add(casualty.pol_vec_2.length.ToString());
                            csvphotondumpwritestream.WriteLine(TraceJournal.csvLine(body));
                        } catch { Console.WriteLine("Some of the attributes messed up..."); }
                    }
                }
            }
        }