} //end constructClassName public Scientrace.Object3d constructDoubleConvexLens(XElement xel) { ShadowScientrace.ShadowObject3d shDCLens = this.getShadowObject3dBase(xel, typeof(Scientrace.DoubleConvexLens)); shDCLens.arguments.Add("focal_length", this.X.getXNullDouble(xel, "FocalLength")); shDCLens.arguments.Add("focus_wavelength", this.X.getXNullDouble(xel, "FocusWavelength")); shDCLens.arguments.Add("lens_diameter", this.X.getXNullDouble(xel, "LensDiameter")); shDCLens.arguments.Add("sphere1_radius", this.X.getXNullDouble(xel, "Radius1")); shDCLens.arguments.Add("sphere2_radius", this.X.getXNullDouble(xel, "Radius2")); shDCLens.arguments.Add("lens_center", this.X.getXLocation(xel, "Center", null)); shDCLens.arguments.Add("optical_axis", this.X.getXNzVectorByName(xel, "OpticalAxis", //Still try depricated name: LensPlaneNormal this.X.getXNzVectorByName(xel, "LensPlaneNormal", null))); shDCLens.arguments.Add("sphere1_center_loc", this.X.getXLocation(xel, "Sphere1Center", null)); shDCLens.arguments.Add("sphere2_center_loc", this.X.getXLocation(xel, "Sphere2Center", null)); if (shDCLens.hasArgument("focal_length")) { return(shDCLens.factory("FocalLength_and_Diameter")); } if (shDCLens.hasArgument("lens_diameter")) { return(shDCLens.factory("TwoRadii_and_Diameter")); } if (shDCLens.hasArgument("sphere2_center_loc")) { return(shDCLens.factory("TwoRadii_and_Locations")); } throw new Exception("Factory method not set/known"); }
} //end constructFresnelLens public Scientrace.Object3d constructFresnelLensRing(XElement xel) //replace ClassName by actuall class name for readability purposes { ShadowScientrace.ShadowObject3d shadowO3D = this.getShadowObject3dBase(xel, typeof(Scientrace.FresnelLensRing)); /* replaced by above: * ShadowScientrace.ShadowObject3d shadowO3D = * new ShadowScientrace.ShadowObject3d(typeof(Scientrace.FresnelLensRing), this.parentcollection, //ClassName * this.getXMaterial(xel)); */ Console.WriteLine("LENSRING ADDED"); shadowO3D.arguments.Add("lens_plano_center", this.X.getXLocation(xel, "LensPlanoCenter", null)); shadowO3D.arguments.Add("lens_sphere_location", this.X.getXLocation(xel, "LensSphereCenter", null)); shadowO3D.arguments.Add("lens_sphere_radius", this.X.getXNullDouble(xel, "LensSphereRadius")); shadowO3D.arguments.Add("lens_sphere_radians_min", this.X.getXAngleByName(xel, "MinAngle")); shadowO3D.arguments.Add("lens_sphere_radians_max", this.X.getXAngleByName(xel, "MaxAngle")); shadowO3D.arguments.Add("orientation_from_sphere_center", this.X.getXNzVectorByName(xel, "OpticalAxis", null).toUnitVector()); //base the constructor method on the parameters submitted by the user if (shadowO3D.hasArgument("lens_plano_center")) { return(shadowO3D.factory("PlanoCenterAndRadians")); } if (shadowO3D.hasArgument("lens_sphere_location")) { return(shadowO3D.factory("SphereCenterAndRadians")); } /*if (shadowO3D.hasArgument("Z")) * return shadowO3D.factory((int)ShadowScientrace.classNameFactoryMethod.ConstructorMethod2);*/ throw new Exception("Factory method not set/known"); } //end constructClassName
/***************************** TEMPLATE ************************************** * public Scientrace.Object3d constructClassName(XElement xel) { //replace ClassName by actuall class name for readability purposes * ShadowScientrace.ShadowObject3d shadowO3D = * new ShadowScientrace.ShadowObject3d(typeof(Scientrace.ClassName), this.parentcollection, //ClassName * this.getXMaterial(xel)); * * shadowO3D.arguments.Add("X", this.X.getXLocation(XElement, "X", null)); * //use the NullDouble so the constructor can decide whether this value is mandatory * shadowO3D.arguments.Add("Y", this.X.getXNullDouble(XElement, "Y", null)); * shadowO3D.arguments.Add("Z", this.X.getXNzVectorByName(XElement, "Z", null)); * * //base the constructor method on the parameters submitted by the user * if (shadowO3D.hasArgument("X")) * return shadowO3D.factory((int)ShadowScientrace.classNameFactoryMethod.ConstructorMethod1); * if (shadowO3D.hasArgument("Z")) * return shadowO3D.factory((int)ShadowScientrace.classNameFactoryMethod.ConstructorMethod2); * throw new Exception("Factory method not set/known"); * } //end constructClassName **************************** TEMPLATE END *************************************/ public Scientrace.Object3d constructRectangle(XElement xel) { ShadowScientrace.ShadowObject3d shRectangle = this.getShadowObject3dBase(xel, typeof(Scientrace.Rectangle)); //new ShadowScientrace.ShadowObject3d(typeof(Scientrace.Rectangle), this.parentcollection, this.getXMaterial(xel)); shRectangle.arguments.Add("center_location", this.X.getXLocation(xel, "Center", null)); shRectangle.arguments.Add("corner_location", this.X.getXLocation(xel, "Location", null)); shRectangle.arguments.Add("width", this.X.getXNzVectorSuggestions(xel, "Width", Scientrace.Vector.ZeroVector(), null)); shRectangle.arguments.Add("height", this.X.getXNzVectorSuggestions(xel, "Height", Scientrace.Vector.ZeroVector(), null)); // shRectangle.arguments.Add("width", this.X.getXNzVectorByName(xel, "Width", null)); // shRectangle.arguments.Add("height", this.X.getXNzVectorByName(xel, "Height", null)); Scientrace.Vector normal = this.X.getXNzVectorByName(xel, "Normal", null); Scientrace.Location pointing_towards = null; if (normal != null) { if (shRectangle.hasArgument("center_location")) { pointing_towards = shRectangle.getLocation("center_location") + normal; } else { throw new XMLException("Normal is defined for Rectangle, but cannot be used without a Center. \n" + xel.ToString()); } } shRectangle.arguments.Add("pointing_towards", this.X.getXLocation(xel, "PointingTowards", pointing_towards)); shRectangle.arguments.Add("orthogonal_direction", this.X.getXUnitVectorByName(xel, "OrthogonalDirection", null)); shRectangle.arguments.Add("side_length", this.X.getXNullDouble(xel, "SideLength")); if (shRectangle.hasArgument("center_location")) { return(shRectangle.factory("Center_and_Sidelength")); } if (shRectangle.hasArgument("corner_location")) { return(shRectangle.factory("Loc_width_height")); } throw new XMLException("Cannot create Rectangle for XML:\n" + xel.ToString()); }
} //end calcTriangleHeightVector public Scientrace.Object3d constructTriangularPrism(XElement xel) { /* Example: * <Prism> * <Location xyz="10;-50;10" /> * <Length xyz="0;100;0" /> * <Width xyz="10;0;0" /> * <Height xyz="5;0;5" /> * <Material Class="NFormula" Formula="1.5+(nm*0.01)" /> * </Prism> */ if (!xel.Name.ToString().IsIn("TriangularPrism", "Prism")) // != "TriangularPrism") { { throw new XMLException("TriangularPrism does not match its name: " + xel.Name.ToString()); } ShadowScientrace.ShadowObject3d shadowO3D = new ShadowScientrace.ShadowObject3d(typeof(Scientrace.TriangularPrism), this.parentcollection, //ClassName this.getXMaterial(xel)); // Base parameters: shadowO3D.arguments.Add("corner_location", this.X.getXLocation(xel, "Location", null)); shadowO3D.arguments.Add("perfect_top", this.X.getXBool(xel, "PerfectFront", true)); shadowO3D.arguments.Add("length", this.X.getXNzVectorByName(xel, "Length")); shadowO3D.arguments.Add("width", this.X.getXNzVectorByName(xel, "Width")); // Optional parameters // TRY: shadowO3D.arguments.Add("height", this.X.getXNzVectorByName(xel, "Height", null)); // ELSE: if (!shadowO3D.hasArgument("height")) { shadowO3D.arguments.Add("heightdir", this.X.getXNzVectorByName(xel, "HeightDirection")); shadowO3D.arguments.Add("angle", this.X.getXAngleByName(xel, "Angle")); shadowO3D.arguments.Add("height", this.calcTriangleHeightVector(shadowO3D)); } //if (! //just throw a warning if prism has no volume. this.triangularPrismHasVolume(shadowO3D); // ) throw new XMLException("Prism has no volume..."); Scientrace.TriangularPrism tretprism = new Scientrace.TriangularPrism(shadowO3D); return(tretprism); }
public Scientrace.Object3d constructFresnelLens(XElement xel) { /* due to the complex structure of the fresnelLens (a collection) * the generic getShadowObject3dBase method cannot be used */ ShadowScientrace.ShadowObject3d shadowO3D = new ShadowScientrace.ShadowObject3d(typeof(Scientrace.FresnelLens), this.parentcollection, this.parentcollection.materialproperties); shadowO3D.arguments.Add("double_convex", this.X.getXBool(xel, "DoubleConvex", false)); //base parameters // Both // Some settings when FocalVector is present if ((xel.Element("FocalVector") != null) || xel.Element("FocalLocation") != null) { //LensPlanoCenter must be defined. Absense will not be tolerated combined with FocalLocation or FocalVector Scientrace.Location planoCenter = this.X.getXLocation(xel, "LensPlanoCenter"); Scientrace.NonzeroVector focalVec; if (xel.Element("FocalLocation") != null) { // the relative nonzerovector based on two locations must be checked after comparing both, which implies manual error checking/throwing. Scientrace.Vector focalLoc = this.X.getXVectorByName(xel, "FocalLocation"); try { focalVec = (focalLoc - planoCenter).tryToNonzeroVector(); } catch (Exception e) { Console.WriteLine("ERROR: focal vector ({FocalLocation: " + focalLoc.trico() + "} - {LensPlanoCenter:" + planoCenter.trico() + "}) cannot be zero."); throw(e); } } else { focalVec = this.X.getXNzVectorByName(xel, "FocalVector"); } shadowO3D.arguments.Add("orientation_from_sphere_center", focalVec.toUnitVector()); shadowO3D.arguments.Add("focal_length", focalVec.length); } else { //possible options: //or shadowO3D.arguments.Add("lens_sphere_radius", this.X.getXNullDouble(xel, "LensSphereRadius")); //or shadowO3D.arguments.Add("focal_length", this.X.getXNullDouble(xel, "FocalLength")); shadowO3D.arguments.Add("orientation_from_sphere_center", this.X.getXNzVectorByName(xel, "OpticalAxis").toUnitVector()); shadowO3D.arguments.Add("lens_sphere_location", this.X.getXLocation(xel, "LensSphereCenter", null)); } shadowO3D.arguments.Add("lens_plano_center", this.X.getXLocation(xel, "LensPlanoCenter", null)); shadowO3D.arguments.Add("width_rings_count", this.X.getXNullDouble(xel, "WidthRings")); shadowO3D.arguments.Add("height_rings_count", this.X.getXNullDouble(xel, "HeightRings")); shadowO3D.arguments.Add("angle_rings_count", this.X.getXNullDouble(xel, "AngleRings")); shadowO3D.arguments.Add("var_rings_count", this.X.getXNullDouble(xel, "VarRings")); shadowO3D.arguments.Add("focus_wavelength", this.X.getXNullDouble(xel, "FocusWavelength")); shadowO3D.arguments.Add("lens_material", this.getXMaterial(xel)); shadowO3D.arguments.Add("draw_3d_segment_linecount", this.X.getXNullInt(xel, "Draw3DLineCount")); //possible options: //or shadowO3D.arguments.Add("lens_sphere_radians_min", this.X.getXNullAngleByName(xel, "MinAngle")); shadowO3D.arguments.Add("lens_sphere_radians_max", this.X.getXNullAngleByName(xel, "MaxAngle")); //or shadowO3D.arguments.Add("lens_radius", this.X.getXNullDouble(xel, "Radius", (double?)0.5 * this.X.getXNullDouble(xel, "Diameter"))); //base the constructor method on the parameters submitted by the user if (shadowO3D.hasArgument("var_rings_count")) //various radius rings are also equal width { return(shadowO3D.factory("VarRings")); } if (shadowO3D.hasArgument("angle_rings_count")) { return(shadowO3D.factory("EqualAngleRings")); } if (shadowO3D.hasArgument("width_rings_count")) { return(shadowO3D.factory("EqualWidthRings")); } if (shadowO3D.hasArgument("height_rings_count")) { return(shadowO3D.factory("EqualHeightRings")); } throw new Exception("Factory method not set/known"); } //end constructFresnelLens
public Scientrace.Object3d constructFresnelLens(XElement xel) { /* due to the complex structure of the fresnelLens (a collection) * the generic getShadowObject3dBase method cannot be used */ ShadowScientrace.ShadowObject3d shadowO3D = new ShadowScientrace.ShadowObject3d(typeof(Scientrace.FresnelLens), this.parentcollection, this.parentcollection.materialproperties); shadowO3D.arguments.Add("double_convex", this.X.getXBool(xel, "DoubleConvex", false)); //base parameters // Both // Some settings when FocalVector is present if ((xel.Element("FocalVector") != null) || xel.Element("FocalLocation") != null) { //LensPlanoCenter must be defined. Absense will not be tolerated combined with FocalLocation or FocalVector Scientrace.Location planoCenter = this.X.getXLocation(xel, "LensPlanoCenter"); Scientrace.NonzeroVector focalVec; if (xel.Element("FocalLocation") != null) { // the relative nonzerovector based on two locations must be checked after comparing both, which implies manual error checking/throwing. Scientrace.Vector focalLoc = this.X.getXVectorByName(xel, "FocalLocation"); try { focalVec = (focalLoc - planoCenter).tryToNonzeroVector(); } catch(Exception e) { Console.WriteLine("ERROR: focal vector ({FocalLocation: "+focalLoc.trico()+"} - {LensPlanoCenter:"+planoCenter.trico()+"}) cannot be zero."); throw(e); } } else { focalVec = this.X.getXNzVectorByName(xel, "FocalVector"); } shadowO3D.arguments.Add("orientation_from_sphere_center", focalVec.toUnitVector()); shadowO3D.arguments.Add("focal_length", focalVec.length); } else { //possible options: //or shadowO3D.arguments.Add("lens_sphere_radius", this.X.getXNullDouble(xel, "LensSphereRadius")); //or shadowO3D.arguments.Add("focal_length", this.X.getXNullDouble(xel, "FocalLength")); shadowO3D.arguments.Add("orientation_from_sphere_center", this.X.getXNzVectorByName(xel, "OpticalAxis").toUnitVector()); shadowO3D.arguments.Add("lens_sphere_location", this.X.getXLocation(xel, "LensSphereCenter", null)); } shadowO3D.arguments.Add("lens_plano_center", this.X.getXLocation(xel, "LensPlanoCenter", null)); shadowO3D.arguments.Add("width_rings_count", this.X.getXNullDouble(xel, "WidthRings")); shadowO3D.arguments.Add("height_rings_count", this.X.getXNullDouble(xel, "HeightRings")); shadowO3D.arguments.Add("angle_rings_count", this.X.getXNullDouble(xel, "AngleRings")); shadowO3D.arguments.Add("var_rings_count", this.X.getXNullDouble(xel, "VarRings")); shadowO3D.arguments.Add("focus_wavelength", this.X.getXNullDouble(xel, "FocusWavelength")); shadowO3D.arguments.Add("lens_material", this.getXMaterial(xel)); shadowO3D.arguments.Add("draw_3d_segment_linecount", this.X.getXNullInt(xel, "Draw3DLineCount")); //possible options: //or shadowO3D.arguments.Add("lens_sphere_radians_min", this.X.getXNullAngleByName(xel, "MinAngle")); shadowO3D.arguments.Add("lens_sphere_radians_max", this.X.getXNullAngleByName(xel, "MaxAngle")); //or shadowO3D.arguments.Add("lens_radius", this.X.getXNullDouble(xel, "Radius", (double?)0.5*this.X.getXNullDouble(xel, "Diameter"))); //base the constructor method on the parameters submitted by the user if (shadowO3D.hasArgument("var_rings_count")) //various radius rings are also equal width return shadowO3D.factory("VarRings"); if (shadowO3D.hasArgument("angle_rings_count")) return shadowO3D.factory("EqualAngleRings"); if (shadowO3D.hasArgument("width_rings_count")) return shadowO3D.factory("EqualWidthRings"); if (shadowO3D.hasArgument("height_rings_count")) return shadowO3D.factory("EqualHeightRings"); throw new Exception("Factory method not set/known"); }
public Scientrace.Object3d constructTriangularPrism(XElement xel) { /* Example: <Prism> <Location xyz="10;-50;10" /> <Length xyz="0;100;0" /> <Width xyz="10;0;0" /> <Height xyz="5;0;5" /> <Material Class="NFormula" Formula="1.5+(nm*0.01)" /> </Prism> */ if (!xel.Name.ToString().IsIn("TriangularPrism", "Prism")) { // != "TriangularPrism") { throw new XMLException("TriangularPrism does not match its name: "+xel.Name.ToString()); } ShadowScientrace.ShadowObject3d shadowO3D = new ShadowScientrace.ShadowObject3d(typeof(Scientrace.TriangularPrism), this.parentcollection, //ClassName this.getXMaterial(xel)); // Base parameters: shadowO3D.arguments.Add("corner_location", this.X.getXLocation(xel, "Location", null)); shadowO3D.arguments.Add("perfect_top", this.X.getXBool(xel, "PerfectFront", true)); shadowO3D.arguments.Add("length", this.X.getXNzVectorByName(xel, "Length")); shadowO3D.arguments.Add("width", this.X.getXNzVectorByName(xel, "Width")); // Optional parameters // TRY: shadowO3D.arguments.Add("height", this.X.getXNzVectorByName(xel, "Height", null)); // ELSE: if (!shadowO3D.hasArgument("height")) { shadowO3D.arguments.Add("heightdir", this.X.getXNzVectorByName(xel, "HeightDirection")); shadowO3D.arguments.Add("angle", this.X.getXAngleByName(xel, "Angle")); shadowO3D.arguments.Add("height", this.calcTriangleHeightVector(shadowO3D)); } //if (! //just throw a warning if prism has no volume. this.triangularPrismHasVolume(shadowO3D); // ) throw new XMLException("Prism has no volume..."); Scientrace.TriangularPrism tretprism = new Scientrace.TriangularPrism(shadowO3D); return tretprism; }