Example #1
0
        static BuildTarget decodeTarget(XmlElement e, Project proj)
        {
            BuildTarget target = null;

            if (e != null)
            {
                target = new BuildTarget();
                target.setName(e.GetAttribute("name"));

                Terrain terrain = proj.getTerrain(e.GetAttribute("terrain"));
                target.setTerrain(terrain);

                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode i in layers)
                {
                    XmlElement elem       = (XmlElement)i;
                    string     layer_name = elem.InnerText;
                    if (!string.IsNullOrEmpty(layer_name))
                    {
                        BuildLayer layer = proj.getLayer(layer_name);
                        if (layer != null)
                        {
                            target.addLayer(layer);
                        }
                    }
                }
            }
            return(target);
        }
Example #2
0
        static XmlElement encodeLayer(XmlDocument doc, BuildLayer layer)
        {
            XmlElement e = null;

            if (layer != null)
            {
                e = doc.CreateElement("layer");
                e.SetAttribute("name", layer.getName());

                switch (layer.getType())
                {
                case BuildLayer.LayerType.TYPE_CORRELATED:
                    e.SetAttribute("type", "correlated");
                    break;

                case BuildLayer.LayerType.TYPE_GRIDDED:
                    e.SetAttribute("type", "gridded");
                    break;

                case BuildLayer.LayerType.TYPE_QUADTREE:
                    e.SetAttribute("type", "quadtree");
                    break;
                }
                e.SetAttribute("source", layer.getSource().getName());
                e.SetAttribute("terrain", layer.getTerrain().getName());
                e.SetAttribute("target", layer.getTargetPath());

                foreach (BuildLayerSlice it in layer.getSlices())
                {
                    e.AppendChild(encodeSlice(doc, it));
                }

                foreach (Property it in layer.getProperties())
                {
                    e.AppendChild(encodeProperty(doc, it));
                }
            }
            return(e);
        }
Example #3
0
 public void addLayer(BuildLayer _layer)
 {
     layers.Add(_layer);
 }
Example #4
0
        protected bool build(BuildLayer layer)
        {
            string work_dir_name = project.getAbsoluteWorkingDirectory();

            if (string.IsNullOrEmpty(work_dir_name))
            {
                work_dir_name = "work_" + project.getName();
            }

            string work_dir = PathUtils.combinePaths(
                project.getBaseURI(),
                work_dir_name);

            if (osgDB.makeDirectory(work_dir))
            {
                Registry.instance().setWorkDirectory(work_dir);
            }

            //osgGIS.notice() << "Building layer \"" << layer.getName() << "\"." << std.endl;

            // first create and initialize a Session that will share data across the build.
            Session session = new Session();

            // add shared scripts to the session:
            foreach (Script i in project.getScripts())
            {
                session.addScript(i);
            }

            // add shared resources to the session:
            foreach (Resource i in project.getResources())
            {
                session.getResources().addResource(i);
            }

            // now establish the source data record form this layer and open a feature layer
            // that connects to that source.
            Source source = layer.getSource(); // default source.. may be overriden in slices

            //if ( !source )
            //{
            //    //TODO: log error
            //    osgGIS.notify( osg.WARN )
            //        << "No source specified for layer \"" << layer.getName() << "\"." << std.endl;
            //    return false;
            //}



            // recursively build any sources that need building.
            if (source && !build(source, session.get()))
            {
                // osgGIS.warn()
                //    << "Unable to build source \"" << source.getName() << "\" or one of its dependencies."
                //     << std.endl;
                return(false);
            }

            FeatureLayer feature_layer;

            if (source != null)
            {
                feature_layer = Registry.instance().createFeatureLayer(source.getAbsoluteURI());

                if (feature_layer == null)
                {
                    //TODO: log error
                    //osgGIS.warn()
                    //    << "Cannot access source \"" << source.getName()
                    //    << "\" for layer \"" << layer.getName() << "\"." << std.endl;
                    return(false);
                }
            }

            // The reference terrain:
            osg.Node         terrain_node;
            SpatialReference terrain_srs;
            GeoExtent        terrain_extent;

            Terrain terrain = layer.getTerrain();

            if (!getTerrainData(terrain, terrain_node, terrain_srs, terrain_extent))
            {
                return(false);
            }

            // output file:
            string output_file = layer.getAbsoluteTargetPath();

            osgDB.makeDirectoryForFile(output_file);
            if (!osgDB.fileExists(osgDB.getFilePath(output_file)))
            {
                //osgGIS.warn()
                //    << "Unable to establish target location for layer \""
                //    << layer.getName() << "\" at \"" << output_file << "\"."
                //    << std.endl;
                return(false);
            }

            // whether to include textures in IVE files:
            bool inline_ive_textures = layer.getProperties().getBoolValue("inline_textures", false);

            // TODO: deprecate this as we move towards the ResourcePackager...
            osgDB.ReaderWriter.Options options;
            if (inline_ive_textures)
            {
                options = new osgDB.ReaderWriter.Options("noWriteExternalReferenceFiles useOriginalExternalReferences");
            }
            else
            {
                options = new osgDB.ReaderWriter.Options("noTexturesInIVEFile noWriteExternalReferenceFiles useOriginalExternalReferences");
            }

            osgDB.Registry.instance().setOptions(options);


            osgDB.Archive archive;
            string        archive_file = output_file;

            if (osgDB.getLowerCaseFileExtension(output_file) == "osga")
            {
                archive     = osgDB.openArchive(output_file, osgDB.Archive.CREATE, 4096);
                output_file = "out.ive";

                // since there's no way to set the master file name...fake it out
                osg.Group dummy = new osg.Group();
                archive.writeNode(dummy, output_file);
            }

            // intialize a task manager if necessary:
            TaskManager manager =
                num_threads > 1? new TaskManager(num_threads) :
                num_threads < 1? new TaskManager() :
                null;



            // prep the map layer definition:
            MapLayer map_layer = new MapLayer();

            // a resource packager if necessary will copy ext-ref files to the output location:
            ResourcePackager packager = new ResourcePackager();

            packager.setArchive(archive.get());
            packager.setOutputLocation(osgDB.getFilePath(output_file));

            if (layer.getProperties().getBoolValue("localize_resources", false))
            {
                packager.setMaxTextureSize(layer.getProperties().getIntValue("max_texture_size", 0));
                packager.setCompressTextures(layer.getProperties().getBoolValue("compress_textures", false));
                packager.setInlineTextures(layer.getProperties().getBoolValue("inline_textures", false));
            }

            if (!addSlicesToMapLayer(layer.getSlices(), layer.getEnvProperties(), map_layer, packager, 0, session, source))
            {
                //osgGIS.warn() << "Failed to add all slices to layer " << layer.getName() << std.endl;
                return(false);
            }

            // calculate the grid cell size:
            double col_size = layer.getProperties().getDoubleValue("col_size", -1.0);
            double row_size = layer.getProperties().getDoubleValue("row_size", -1.0);

            if (col_size <= 0.0 || row_size <= 0.0)
            {
                int num_cols = Math.Max(1, layer.getProperties().getIntValue("num_cols", 1));
                int num_rows = Math.Max(1, layer.getProperties().getIntValue("num_rows", 1));
                col_size = map_layer.getAreaOfInterest().getWidth() / (double)num_cols;
                row_size = map_layer.getAreaOfInterest().getHeight() / (double)num_rows;
            }
            map_layer.setCellWidth(col_size);
            map_layer.setCellHeight(row_size);
            map_layer.setEncodeCellRadius(layer.getProperties().getBoolValue("encode_cell_radius", true));


            MapLayerCompiler compiler;

            // figure out which compiler to use:
            if (layer.getType() == BuildLayer.LayerType.TYPE_QUADTREE)
            {
                compiler = new QuadTreeMapLayerCompiler(map_layer, session);
            }
            else if (layer.getType() == BuildLayer.LayerType.TYPE_GRIDDED)
            {
                compiler = new GriddedMapLayerCompiler(map_layer.get(), session.);
            }
            else if (layer.getType() == BuildLayer.LayerType.TYPE_SIMPLE)
            {
                compiler = new SimpleMapLayerCompiler(map_layer, session);
            }

            if (compiler.get())
            {
                compiler.setAbsoluteOutputURI(output_file);
                compiler.setPaged(layer.getProperties().getBoolValue("paged", true));
                compiler.setTerrain(terrain_node.get(), terrain_srs, terrain_extent);
                compiler.setArchive(archive.get(), archive_file);
                compiler.setResourcePackager(packager.get());

                // build the layer and write the root file to output:
                osg.Group result = compiler.compile(manager.get());

                if (result != null)
                {
                    packager.packageNode(result.get(), output_file);
                }
            }

            if (archive != null)
            {
                archive.close();
            }

            //osgGIS.notice() << "Done building layer \"" << layer.getName() << "\"." << std.endl;

            return(true);
        }
Example #5
0
 public void setSearchLayer(BuildLayer value)
 {
     search_layer = value;
 }
Example #6
0
 public void setBuildLayer(BuildLayer value)
 {
     build_layer = value;
 }
Example #7
0
        static Project decodeProject(XmlElement e, string source_uri)
        {
            if (e == null || !e.Name.Equals("project"))
            {
                throw new ApplicationException("First XML element must be <project/> tag");
            }

            Project project = null;

            if (e != null)
            {
                project = new Project();
                project.setSourceURI(source_uri);
                project.setName(e.GetAttribute("name"));
                project.setWorkingDirectory(e.GetAttribute("workdir"));

#if TODO_DANI //includes
                // includes
                XmlNodeList includes = e.GetElementsByTagName("include");
                foreach (XmlNode j in includes)
                {
                    decodeInclude((XmlElement)j, project);
                }
#endif
                // scripts
                XmlNodeList scripts = e.GetElementsByTagName("script");
                foreach (XmlNode j in scripts)
                {
                    Script script = decodeScript((XmlElement)j, project);
                    if (script != null)
                    {
                        project.getScripts().Add(script);
                    }
                }

                //some project variables.
                XmlNodeList engines = e.GetElementsByTagName("scriptEngine");
                foreach (XmlElement engine in engines)
                {
                    Registry.instance().LoadAndRegistryEngine(engine.GetAttribute("Class"), engine.GetAttribute("Assembly"));
                }

                XmlNodeList nl = e.GetElementsByTagName("mogreRender");
                foreach (XmlElement n in nl)
                {
                    decodeMogreRender(n, project);
                }

#if !TODO_DANI //resources
                // resources
                XmlNodeList resources = e.GetElementsByTagName("resource");
                foreach (XmlNode j in resources)
                {
                    Resource resource = decodeResource((XmlElement)j, project);
                    if (resource != null)
                    {
                        project.getResources().Add(resource);
                    }
                }
#endif

                // graphs
                XmlNodeList graphs = e.GetElementsByTagName("graph");
                foreach (XmlNode j in graphs)
                {
                    FilterGraph graph = decodeFilterGraph((XmlElement)j, project);
                    if (graph != null)
                    {
                        project.getFilterGraphs().Add(graph);
                    }
                }

#if TODO_DANI //terrains
                // terrains (depends on resources)
                XmlNodeList terrains = e.GetElementsByTagName("terrain");
                foreach (XmlNode j in terrains)
                {
                    Terrain terrain = decodeTerrain((XmlElement)j, project);
                    if (terrain != null)
                    {
                        project.getTerrains().Add(terrain);
                    }
                }
#endif

                // sources - 2 passes, since a source can reference another source
                XmlNodeList sources = e.GetElementsByTagName("source");
                foreach (XmlNode j in sources)
                {
                    // TODO Dani, meter esto en un try catch

                    Source source = decodeSource((XmlElement)j, project, 0);
                    if (source != null)
                    {
                        project.getSources().Add(source);

#if TODO_DANI
                        // also add each source as a feature layer resource
                        Resource resource = MogreGis.Registry.instance().createResourceByType("FeatureLayerResource");
                        resource.setBaseURI(project.getBaseURI());
                        resource.setURI(source.getURI());
                        resource.setName(source.getName());
                        project.getResources().Add(resource);
#endif
                    }
                }
                foreach (XmlNode j in sources)
                {
                    decodeSource((XmlElement)j, project, 1);
                }

                //#if TODO_DANI //layers

                // layers
                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode j in layers)
                {
                    BuildLayer layer = decodeLayer((XmlElement)j, project);
                    if (layer != null)
                    {
                        project.getLayers().Add(layer);

                        // automatically add a target for this layer alone:
                        BuildTarget layer_target = new BuildTarget();
                        layer_target.setName(layer.getName());
                        layer_target.addLayer(layer);
                        project.getTargets().Add(layer_target);
                    }
                }

                //#endif

#if TODO_DANI //targets
                // targets
                XmlNodeList targets = e.GetElementsByTagName("target");
                foreach (XmlNode j in targets)
                {
                    BuildTarget target = decodeTarget((XmlElement)j, project);
                    if (target != null)
                    {
                        project.getTargets().Add(target);
                    }
                }
#endif

#if TODO_DANI //maps
                // maps
                XmlNodeList maps = e.GetElementsByTagName("map");
                foreach (XmlNode j in maps)
                {
                    RuntimeMap map = decodeRuntimeMap((XmlElement)j, project);
                    if (map != null)
                    {
                        project.getMaps().Add(map);
                    }
                }
#endif
            }
            return(project);
        }
Example #8
0
        static BuildLayer decodeLayer(XmlElement e, Project proj)
        {
            BuildLayer layer = null;

            if (e != null)
            {
                layer = new BuildLayer();

#if TODO_DANI
                layer.setBaseURI(proj.getBaseURI());
#endif

                layer.setName(e.GetAttribute("name"));

                string type = e.GetAttribute("type");
                if (type == "correlated")
                {
                    layer.setType(BuildLayer.LayerType.TYPE_CORRELATED);
                }
                else if (type == "gridded")
                {
                    layer.setType(BuildLayer.LayerType.TYPE_GRIDDED);
                }
                else if (type == "quadtree" || type == "new")
                {
                    layer.setType(BuildLayer.LayerType.TYPE_QUADTREE);
                }

                string source = e.GetAttribute("source");
                layer.setSource(proj.getSource(source));

                string terrain = e.GetAttribute("terrain");
                layer.setTerrain(proj.getTerrain(terrain));

                layer.setTargetPath(e.GetAttribute("target"));

                XmlNodeList slices = e.GetElementsByTagName("slice");
                foreach (XmlNode i in slices)
                {
                    BuildLayerSlice slice = decodeSlice((XmlElement)i, proj);
                    if (slice != null)
                    {
                        layer.getSlices().Add(slice);
                    }
                }

#if TODO_DANI
                XmlNodeList props = e.GetElementsByTagName("property");
                foreach (XmlNode i in props)
                {
                    XmlElement k_e   = (XmlElement)i;
                    string     name  = k_e.GetAttribute("name");
                    string     value = k_e.GetAttribute("value");
                    layer.getProperties().Add(new Property(name, value));
                }

                XmlNodeList env_props = e.GetElementsByTagName("env_property");
                foreach (XmlNode i in env_props)
                {
                    XmlElement k_e   = (XmlElement)i;
                    string     name  = k_e.GetAttribute("name");
                    string     value = k_e.GetAttribute("value");
                    layer.getEnvProperties().Add(new Property(name, value));
                }
#endif
            }
            return(layer);
        }