示例#1
0
        /// <summary>
        /// XML Load function
        /// </summary>
        /// <param name="camRoot">Root element of camera tag</param>
        /// <returns>Fully constructed PinholeCamera</returns>
        public static PinholeCamera LoadPinholeCamera(XmlElement camRoot)
        {
            PinholeCamera toReturn = new PinholeCamera();

            XmlNode node_vdp = camRoot.SelectSingleNode("vdp");
            if (node_vdp != null)
            {
                string str_vdp = ((XmlText)node_vdp.FirstChild).Data;
                float vdp = (float)Convert.ToSingle(str_vdp);
                toReturn.ViewPlaneDistance = vdp;
            }
            return toReturn;
        }
示例#2
0
        /// <summary>
        /// Load function for XML file
        /// </summary>
        /// <param name="camRoot">Root element of camera tag</param>
        /// <returns>A fully constructed Camera</returns>
        public static Camera LoadCamera(XmlElement camRoot)
        {
            string cam_type = camRoot.GetAttribute("type");
            Camera toReturn = new PinholeCamera();
            //If no camera type is defined, then return a default pinhole camera.
            if (!cam_type.Equals(""))
            {
                //Load subtype specific parameters in their own methods
                if (cam_type.Equals("pinhole"))
                {
                    toReturn = PinholeCamera.LoadPinholeCamera(camRoot);
                }
                else if(cam_type.Equals("thinlens"))
                {
                    toReturn = ThinLensCamera.LoadThinLensCamera(camRoot);
                }
                else
                {
                    Console.WriteLine("Unknown camera type: " + cam_type);
                }

                XmlNode node_zoom = camRoot.SelectSingleNode("zoom");
                if (node_zoom != null)
                {
                    string str_zoom = ((XmlText)node_zoom.FirstChild).Data;
                    float zoom = (float)Convert.ToSingle(str_zoom);
                    toReturn.Zoom = zoom;
                }

                //Load common attributes afterwards.
                XmlNode node_point = camRoot.SelectSingleNode("point");
                if (node_point != null)
                {
                    string str_point = ((XmlText)node_point.FirstChild).Data;
                    Point3D point = Point3D.FromCsv(str_point);
                    //if (point != null)
                    //{
                        toReturn.Eye = point;
                    //}
                }
                XmlNode node_lookat = camRoot.SelectSingleNode("lookat");
                if (node_lookat != null)
                {
                    string str_lookat = ((XmlText)node_lookat.FirstChild).Data;
                    Point3D lookat = Point3D.FromCsv(str_lookat);
                    //if (lookat != null)
                    //{
                        toReturn.LookAt = lookat;
                    //}
                }
                XmlNode node_exp = camRoot.SelectSingleNode("exposure");
                if (node_exp != null)
                {
                    string str_exp = ((XmlText)node_exp.FirstChild).Data;
                    float exposure = (float)Convert.ToSingle(str_exp);
                    toReturn.Exposure = exposure;
                }

                toReturn.compute_uvw();

                return toReturn;
            }
            else
            {
                Console.WriteLine("Camera type for camera " + camRoot.GetAttribute("id") + " not defined.");
                return toReturn;
            }
        }