public string angleToRGB(Scientrace.Spot aCasualty, PhysicalObject3d physObj)
        {
            UnitVector inAngle = aCasualty.trace.traceline.direction;

            Scientrace.Parallelogram pg   = physObj.getDistributionSurface();
            Scientrace.NonzeroVector norm = physObj.getSurfaceNormal();

            UnitVector y = pg.plane.v.toUnitVector();
            UnitVector x = null;

            try {
                x = norm.crossProduct(y).tryToUnitVector();
            } catch { throw new ZeroNonzeroVectorException("The vertical vector (plane.v) is parallel to the unit normal."); }
            double dx = x.dotProduct(inAngle);
            double dy = y.dotProduct(inAngle);

            double lengthFraction = Math.Sqrt((dx * dx) + (dy * dy));
            //Console.WriteLine("Length: "+lengthFraction+ " vs: "+((x*dx)+(y*dy)).length);

            double angle = Math.Atan2(dy, dx);

            return(this.angleToHTML(angle, 2 * Math.Asin(lengthFraction) / Math.PI));

            //physObj.getSurfaceNormal()
            //aCasualty.object3d.
//		throw new Exception("Not yet implemented");
        }
Пример #2
0
 public void recordSpot(Scientrace.Spot spot)
 {
     this.spot_sema.WaitOne();
     if (spot == null)
     {
         throw new NullReferenceException("ERROR: why would you record a null value?");
     }
     this.spots.Add(spot);
     this.spot_sema.Release();
 }
Пример #3
0
 public void recordCasualty(Scientrace.Spot casualty)
 {
     this.casualty_sema.WaitOne();
     if (!casualty.loc.isValid())
     {
         throw new ArgumentOutOfRangeException("Casualty has an invalid location.");
     }
     this.casualties.Add(casualty);
     this.casualty_sema.Release();
 }
Пример #4
0
 public Spot(Scientrace.Spot copyFromSpot)
 {
     this.loc      = new Scientrace.Location(copyFromSpot.loc);
     this.object3d = copyFromSpot.object3d;
     // do not spot again, so don't recall spotted from object3d
     this.intensity         = copyFromSpot.intensity;
     this.trace             = copyFromSpot.trace;
     this.intensityFraction = copyFromSpot.intensityFraction;
     this.fillPolVecs();
 }
        public string getPhotonColourForPDPSource(Scientrace.Spot casualtySpot, PDPSource pdpSource, PhysicalObject3d physObj)
        {
            switch (pdpSource)
            {
            case PDPSource.Wavelength: return(this.wavelengthToRGB(casualtySpot.trace.wavelenght));

            case PDPSource.AngleWheel: return(this.angleToRGB(casualtySpot, physObj));
            }
            throw new Exception("Unknown PDPSource: " + pdpSource);
        }
        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);
        }
Пример #7
0
        public void writeSVGFile(System.IO.DirectoryInfo path)
        {
            double min_wl = this.min_wavelength;
            double max_wl = this.max_wavelength;
            int resolution = this.resolution;
            int canvaswidth = this.figure_size_width;
            int canvasheight = this.figure_size_height;

            /* base square positioning on the direction. Since spots have to be placed in a line,
             * it makes sense to start the axis along which it lies at zero towards the length or height
             * of the axis. The spots will be placed along other axis, which is therefore centered about
             * that axis (-0.5*width/length; 0.5*width/length). */
            Scientrace.Location squareloc = ( this.isHorizontal() ?
                                        (Scientrace.Vector.y1vector()*canvasheight*-0.5).toLocation() :
                                        (Scientrace.Vector.x1vector()*canvaswidth*-0.5).toLocation() );

            Scientrace.Rectangle legendSquare = new Scientrace.Rectangle(null, null,
                squareloc,
                (Scientrace.Vector.x1vector()*canvaswidth).tryToNonzeroVector(),
                (Scientrace.Vector.y1vector()*canvasheight).tryToNonzeroVector());

            Scientrace.HorizontalGridSurfaceMarker hormarker = new Scientrace.HorizontalGridSurfaceMarker(legendSquare);
            hormarker.minval = min_wl*1E9;
            hormarker.maxval = max_wl*1E9;
            hormarker.xunits = "nm";
            double textheight = hormarker.textheight();
            double imagewidth = legendSquare.viewBoxWidth()+((fontSizeBasedMarginLeft+fontSizeBasedMarginRight)*textheight);
            double imageheight = legendSquare.viewBoxHeight()+((fontSizeBasedMarginTop+fontSizeBasedMarginBottom)*textheight);

            //Scientrace.Parallelogram surface = legendSquare.getDistributionSurface();
            //double spotsize = Math.Sqrt(Math.Pow(surface.u.length,2)+Math.Pow(surface.v.length,2))*(0.005);

            double[] vb = legendSquare.getViewBorders();
            //		Console.WriteLine("canvaswidth: "+canvaswidth+ " vb[2]: "+vb[3]);

            string strokewidth = (((vb[2]-vb[0])+(vb[3]-vb[1]))/800.0).ToString("#.##############"); //0.25% linewidth
            string fullfilename = path.FullName+System.IO.Path.DirectorySeparatorChar+"wl_legend.svg";
            //Console.WriteLine("Writing legend to "+fullfilename);
            using (StreamWriter retstr = new StreamWriter(fullfilename)) {
            retstr.WriteLine(this.getSVGHeader());
            retstr.WriteLine(this.getSVGTagOpen(imagewidth, imageheight,
                              legendSquare.getAbsMarginViewBox(fontSizeBasedMarginLeft,fontSizeBasedMarginTop,
                                                                  fontSizeBasedMarginRight, fontSizeBasedMarginBottom,textheight)
                              ));

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

            retstr.WriteLine(hormarker.exportSVG());

            Scientrace.Location loc2d, tloc2d;
            int order = 5;
            string centerSpots = "<!-- END OF SPOTS CENTERS -->";
            double unitfraction = (Math.Pow(2,order)-1);
            double unitheight  = Convert.ToDouble(canvasheight)/unitfraction;

            //added "+(stepsize*0.001)" to condition to avoid float-boundary-problems
            for (double wavelength = min_wl; wavelength<=max_wl+(((max_wl-min_wl)/resolution)*0.001); wavelength=wavelength+((max_wl-min_wl)/resolution)) {
                Scientrace.Location loc =  this.relLocationVector(wavelength);
                Scientrace.Spot aSpot = new Scientrace.Spot(loc, legendSquare, 1, 1, null);
                loc2d = legendSquare.get2DLoc(aSpot.loc);

                if (loc2d==null) {throw new Exception("ERROR: loc2d created by "+legendSquare.tag+" == null");}

                double centerspotsize = (Convert.ToDouble(canvaswidth)/Convert.ToDouble(resolution))*0.5;
                loc2d.y = -centerspotsize+canvasheight;
                            //unitheight * (unitfraction-0.5);
            /*								(Math.Pow(2.0,order-1) * 0.5) +
                                (Math.Pow(2.0,order-1) - 1)
                                );*/

                centerSpots = this.spotSVGForWavelength(loc2d, centerspotsize, wavelength, 1)+centerSpots;

                for (int iorder = 1; iorder <= order; iorder++) {
                    tloc2d = loc2d;
                    tloc2d.y = unitheight * (
                                (Math.Pow(2.0,iorder-1) * 0.5) +
                                (Math.Pow(2.0,iorder-1) - 1)
                                );
                    retstr.WriteLine(this.spotSVGForWavelength(tloc2d, unitheight*(Math.Pow(2,(iorder-2))), wavelength, 0.25));
                    }
                }
            centerSpots = "<!-- START OF CENTERSPOTS-->"+centerSpots;
            retstr.WriteLine(centerSpots);
            retstr.WriteLine("</svg> ");

                //retstr.Close();
                }
        }
        public void writeSVGFile(System.IO.DirectoryInfo path)
        {
            double min_wl       = this.min_wavelength;
            double max_wl       = this.max_wavelength;
            int    resolution   = this.resolution;
            int    canvaswidth  = this.figure_size_width;
            int    canvasheight = this.figure_size_height;

            /* base square positioning on the direction. Since spots have to be placed in a line,
             * it makes sense to start the axis along which it lies at zero towards the length or height
             * of the axis. The spots will be placed along other axis, which is therefore centered about
             * that axis (-0.5*width/length; 0.5*width/length). */
            Scientrace.Location squareloc = (this.isHorizontal() ?
                                             (Scientrace.Vector.y1vector() * canvasheight * -0.5).toLocation() :
                                             (Scientrace.Vector.x1vector() * canvaswidth * -0.5).toLocation());

            Scientrace.Rectangle legendSquare = new Scientrace.Rectangle(null, null,
                                                                         squareloc,
                                                                         (Scientrace.Vector.x1vector() * canvaswidth).tryToNonzeroVector(),
                                                                         (Scientrace.Vector.y1vector() * canvasheight).tryToNonzeroVector());

            Scientrace.HorizontalGridSurfaceMarker hormarker = new Scientrace.HorizontalGridSurfaceMarker(legendSquare);
            hormarker.minval = min_wl * 1E9;
            hormarker.maxval = max_wl * 1E9;
            hormarker.xunits = "nm";
            double textheight  = hormarker.textheight();
            double imagewidth  = legendSquare.viewBoxWidth() + ((fontSizeBasedMarginLeft + fontSizeBasedMarginRight) * textheight);
            double imageheight = legendSquare.viewBoxHeight() + ((fontSizeBasedMarginTop + fontSizeBasedMarginBottom) * textheight);

            //Scientrace.Parallelogram surface = legendSquare.getDistributionSurface();
            //double spotsize = Math.Sqrt(Math.Pow(surface.u.length,2)+Math.Pow(surface.v.length,2))*(0.005);

            double[] vb = legendSquare.getViewBorders();
            //		Console.WriteLine("canvaswidth: "+canvaswidth+ " vb[2]: "+vb[3]);

            string strokewidth  = (((vb[2] - vb[0]) + (vb[3] - vb[1])) / 800.0).ToString("#.##############"); //0.25% linewidth
            string fullfilename = path.FullName + System.IO.Path.DirectorySeparatorChar + "wl_legend.svg";

            //Console.WriteLine("Writing legend to "+fullfilename);
            using (StreamWriter retstr = new StreamWriter(fullfilename)) {
                retstr.WriteLine(this.getSVGHeader());
                retstr.WriteLine(this.getSVGTagOpen(imagewidth, imageheight,
                                                    legendSquare.getAbsMarginViewBox(fontSizeBasedMarginLeft, fontSizeBasedMarginTop,
                                                                                     fontSizeBasedMarginRight, fontSizeBasedMarginBottom, textheight)
                                                    ));

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

                retstr.WriteLine(hormarker.exportSVG());

                Scientrace.Location loc2d, tloc2d;
                int    order        = 5;
                string centerSpots  = "<!-- END OF SPOTS CENTERS -->";
                double unitfraction = (Math.Pow(2, order) - 1);
                double unitheight   = Convert.ToDouble(canvasheight) / unitfraction;

                //added "+(stepsize*0.001)" to condition to avoid float-boundary-problems
                for (double wavelength = min_wl; wavelength <= max_wl + (((max_wl - min_wl) / resolution) * 0.001); wavelength = wavelength + ((max_wl - min_wl) / resolution))
                {
                    Scientrace.Location loc   = this.relLocationVector(wavelength);
                    Scientrace.Spot     aSpot = new Scientrace.Spot(loc, legendSquare, 1, 1, null);
                    loc2d = legendSquare.get2DLoc(aSpot.loc);

                    if (loc2d == null)
                    {
                        throw new Exception("ERROR: loc2d created by " + legendSquare.tag + " == null");
                    }

                    double centerspotsize = (Convert.ToDouble(canvaswidth) / Convert.ToDouble(resolution)) * 0.5;
                    loc2d.y = -centerspotsize + canvasheight;
                    //unitheight * (unitfraction-0.5);

/*								(Math.Pow(2.0,order-1) * 0.5) +
 *                                                              (Math.Pow(2.0,order-1) - 1)
 *                                                              );*/

                    centerSpots = this.spotSVGForWavelength(loc2d, centerspotsize, wavelength, 1) + centerSpots;

                    for (int iorder = 1; iorder <= order; iorder++)
                    {
                        tloc2d   = loc2d;
                        tloc2d.y = unitheight * (
                            (Math.Pow(2.0, iorder - 1) * 0.5) +
                            (Math.Pow(2.0, iorder - 1) - 1)
                            );
                        retstr.WriteLine(this.spotSVGForWavelength(tloc2d, unitheight * (Math.Pow(2, (iorder - 2))), wavelength, 0.25));
                    }
                }
                centerSpots = "<!-- START OF CENTERSPOTS-->" + centerSpots;
                retstr.WriteLine(centerSpots);
                retstr.WriteLine("</svg> ");

                //retstr.Close();
            }
        }