Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }