Пример #1
0
        public Scientrace.Rectangle parseXRectangleVectorBasedConstructor(XElement xsc)
        {
            Scientrace.Location location = this.X.getXLocation(xsc.Element("Location"));

            /* OLD method that caused a crashed on zerovectors.
             * Scientrace.NonzeroVector width = this.X.getXNzVector(xsc.Element("Width"));
             * Scientrace.NonzeroVector height = this.X.getXNzVector(xsc.Element("Height")); */

            Scientrace.Vector vwidth  = this.X.getXVector(xsc.Element("Width"));
            Scientrace.Vector vheight = this.X.getXVector(xsc.Element("Height"));
            if (vwidth.length * vheight.length == 0)
            {
                return(null);
            }
            Scientrace.NonzeroVector width  = vwidth.tryToNonzeroVector();
            Scientrace.NonzeroVector height = vheight.tryToNonzeroVector();

            /*string materialid = this.X
             *      .getXString(xsc.Attribute("Material"));
             * Scientrace.MaterialProperties material = Scientrace.MaterialProperties.FromIdentifier(materialid); */
            Scientrace.MaterialProperties material = new ShadowClassConstruct(this.parentcollection).getXMaterial(xsc);
            //Console.WriteLine("MAT CELL: "+material.GetType());
            Scientrace.Rectangle retcel = new Scientrace.Rectangle(this.parentcollection,
                                                                   material, location, width, height);
            this.addCommonObjectProperties(retcel, xsc);
            this.registerObject(xsc, retcel);
            return(retcel);
        }
Пример #2
0
        public Scientrace.CircularFresnelPrism parseXFresnelPrism(XElement xprism)
        {
            //check basic prerequisites
            if (xprism.Name.ToString() != "CircularFresnelPrism")
            {
                throw new XMLException("FresnelPrism does not match its name: " + xprism.Name.ToString());
            }
            Scientrace.Location location = this.X.getXVector(xprism.Element("Location")).toLocation();
            Scientrace.Vector   tsurfv1  = this.X.getXVector(xprism.Element("SurfaceVector1"));
            Scientrace.Vector   tsurfv2  = this.X.getXVector(xprism.Element("SurfaceVector2"));

            Scientrace.NonzeroVector surfv1, surfv2, zaxisheight;
            try {
                surfv1      = tsurfv1.tryToNonzeroVector();
                surfv2      = tsurfv2.tryToNonzeroVector();
                zaxisheight = surfv1.crossProduct(tsurfv2).tryToNonzeroVector();
            } catch {
                throw new XMLException("Parsing fresnel prism error: SurfaceVectors1 and 2 may not be zero.");
            }

            Scientrace.Vector tzaxis = this.X.getXVector(xprism.Element("Height"), zaxisheight);
            try {
                zaxisheight = tzaxis.tryToNonzeroVector();
            } catch {
                throw new XMLException("Parsing fresnel prism error: height vector may not be zero.");
            }

            double LongSideAngle  = this.X.getXAngle(xprism.Element("LongSideAngle"));
            double ShortSideAngle = this.X.getXAngle(xprism.Element("ShortSideAngle"));
            int    TeethCount     = this.X.getXInt(xprism.Attribute("TeethCount"));

            Scientrace.MaterialProperties material = new ShadowClassConstruct(this.parentcollection).getXMaterial(xprism);

            /*
             * string materialid = this.X.getXString(xprism.Attribute("Material"));
             * Scientrace.MaterialProperties material = Scientrace.MaterialProperties.FromIdentifier(materialid);
             */
            Scientrace.CircularFresnelPrism tretprism =
                new Scientrace.CircularFresnelPrism(this.parentcollection,
                                                    this.parentcollection.materialproperties, location, surfv1, surfv2, zaxisheight,
                                                    LongSideAngle, ShortSideAngle, TeethCount, material);
            this.addCommonObjectProperties(tretprism, xprism);
            return(tretprism);
        }
Пример #3
0
        public Scientrace.RectangularPrism parseXRectangularPrism(XElement xrectprism)
        {
            //try {
            //Console.WriteLine("Adding Square Prism");
            //check basic prerequisites
            if (xrectprism.Name.ToString() != "RectangularPrism")
            {
                throw new XMLException("RectangularPrism does not match its name: " + xrectprism.Name.ToString());
            }
            Scientrace.Vector width  = this.X.getXVectorByName(xrectprism, "Width");
            Scientrace.Vector length = this.X.getXVectorByName(xrectprism, "Length");
            Scientrace.Vector height = this.X.getXVectorByName(xrectprism, "Height");
            if (width.length * length.length * height.length == 0)
            {
                Console.WriteLine("WARNING: Rectangular Prism " + xrectprism.Attribute("Tag").Value + " has no volume and will " +
                                  "therefor not be created.");
                return(null);
            }
            Scientrace.Location location = null;
            if (xrectprism.Element("Center") == null)
            {
                location = this.X.getXVectorByName(xrectprism, "Location").toLocation();
            }
            else
            {
                location = (this.X.getXVectorByName(xrectprism, "Center") + (width * -0.5) + (length * -0.5) + (height * -0.5))
                           .toLocation();
            }

            Scientrace.MaterialProperties materialprops = this.getXMaterialForObject(xrectprism);

            /*
             * string materialid = this.X.getXStringByAttribute(xrectprism,"Material");
             * Scientrace.MaterialProperties material = Scientrace.MaterialProperties.FromIdentifier(materialid); */
            //tryToNonzeroVector operations below are permitted since the prism has a volume as was tested above.
            Scientrace.RectangularPrism tretprism = new Scientrace.RectangularPrism(this.parentcollection,
                                                                                    materialprops, location, width.tryToNonzeroVector(), height.tryToNonzeroVector(), length.tryToNonzeroVector());
            this.addCommonObjectProperties(tretprism, xrectprism);
            return(tretprism);

            /*	} catch(Exception e) {Console.WriteLine("Couldn't create RectangularPrism: "+this.X.getXString(xrectprism.Attribute("Tag")));
             *              throw(e);
             *      }*/
        }
Пример #4
0
        public Scientrace.PlaneBorderEnclosedVolume parseXTruncatedPyramid(XElement xTruncatedPyramid)
        {
            // Replaced with below: Scientrace.MaterialProperties materialprops = this.getXMaterial(xToppedPyramid.Element("Material"));
            Scientrace.MaterialProperties materialprops = this.getXMaterialForObject(xTruncatedPyramid);

            if ((xTruncatedPyramid.Name.ToString() != "TruncatedPyramid") && (xTruncatedPyramid.Name.ToString() != "ToppedPyramid"))
            {
                throw new XMLException("TruncatedPyramid does not match its name: " + xTruncatedPyramid.Name.ToString());
            }

            List <Scientrace.Location> front_corners = new List <Scientrace.Location>();

            Scientrace.Vector loc_sum = new Scientrace.Vector(0, 0, 0);
            foreach (XElement xFrontCorner in xTruncatedPyramid.Elements("Corner"))
            {
                Scientrace.Location loc = this.X.getXLocation(xFrontCorner);
                front_corners.Add(loc);
                loc_sum = loc_sum + loc;
            }
            Scientrace.Vector   loc_avg     = loc_sum / front_corners.Count;
            Scientrace.Location virtual_top = this.X.getXLocation(xTruncatedPyramid, "VirtualTop");
            // parsing topping plane data:
            XElement xTopPlane = xTruncatedPyramid.Element("TopPlane");

            if (xTopPlane == null)
            {
                throw new XMLException("TopPlane element not found... " + xTruncatedPyramid.ToString());
            }
            Scientrace.Location      topPlaneLoc    = this.X.getXLocation(xTopPlane, "Location");
            Scientrace.NonzeroVector topPlaneNormal = this.X.getXNzVectorByName(xTopPlane, "Normal");
            if (topPlaneNormal.dotProduct((topPlaneLoc - loc_avg)) > 0)
            {
                topPlaneNormal = topPlaneNormal.negative();
            }
            Scientrace.PlaneBorder topping_plane = new Scientrace.PlaneBorder(topPlaneLoc, topPlaneNormal);

            Scientrace.PlaneBorderEnclosedVolume tRetTruncatedPyramid = Scientrace.PlaneBorderEnclosedVolume.createTruncatedPyramid(this.parentcollection, materialprops,
                                                                                                                                    front_corners, virtual_top, topping_plane);
            return(tRetTruncatedPyramid);
        }
Пример #5
0
        public Scientrace.PlaneBorderEnclosedVolume parseXTruncatedPyramid(XElement xTruncatedPyramid)
        {
            // Replaced with below: Scientrace.MaterialProperties materialprops = this.getXMaterial(xToppedPyramid.Element("Material"));
            Scientrace.MaterialProperties materialprops = this.getXMaterialForObject(xTruncatedPyramid);

            if ((xTruncatedPyramid.Name.ToString() != "TruncatedPyramid") && (xTruncatedPyramid.Name.ToString() != "ToppedPyramid")) {
            throw new XMLException("TruncatedPyramid does not match its name: "+xTruncatedPyramid.Name.ToString());
            }

            List<Scientrace.Location> front_corners = new List<Scientrace.Location>();
            Scientrace.Vector loc_sum = new Scientrace.Vector(0,0,0);
            foreach (XElement xFrontCorner in xTruncatedPyramid.Elements("Corner")) {
            Scientrace.Location loc = this.X.getXLocation(xFrontCorner);
            front_corners.Add(loc);
            loc_sum = loc_sum + loc;
            }
            Scientrace.Vector loc_avg = loc_sum / front_corners.Count;
            Scientrace.Location virtual_top = this.X.getXLocation(xTruncatedPyramid, "VirtualTop");
            // parsing topping plane data:
            XElement xTopPlane = xTruncatedPyramid.Element("TopPlane");
            if (xTopPlane==null) {
            throw new XMLException("TopPlane element not found... "+xTruncatedPyramid.ToString());
            }
            Scientrace.Location topPlaneLoc = this.X.getXLocation(xTopPlane, "Location");
            Scientrace.NonzeroVector topPlaneNormal = this.X.getXNzVectorByName(xTopPlane, "Normal");
            if (topPlaneNormal.dotProduct((topPlaneLoc-loc_avg))>0) {
            topPlaneNormal = topPlaneNormal.negative();
            }
            Scientrace.PlaneBorder topping_plane = new Scientrace.PlaneBorder(topPlaneLoc, topPlaneNormal);

            Scientrace.PlaneBorderEnclosedVolume tRetTruncatedPyramid  = Scientrace.PlaneBorderEnclosedVolume.createTruncatedPyramid(this.parentcollection, materialprops,
            front_corners, virtual_top, topping_plane);
            return tRetTruncatedPyramid;
        }