Ejemplo n.º 1
0
        public virtual void run()
        {
            if (layer == null)
            {
                result = FilterGraphResult.error("Illegal: null feature layer");
            }
            else if (filter_graph == null)
            {
                result = FilterGraphResult.error("Illegal: null filter graph");
            }
            else if (env == null)
            {
                result = FilterGraphResult.error("Illegal: null filter environment");
            }
            else
            {
                env.getReport().markStartTime();

                // ensure the input SRS matches that of the layer:
                env.setInputSRS(layer.getSRS());

                // retrieve the features in the given extent:
                FeatureCursor cursor = layer.getCursor(env.getExtent());

                // and compile the filter graph:
                osg.Group temp = null;
                result      = filter_graph.computeNodes(cursor, env, temp);
                result_node = temp;

                env.getReport().markEndTime();
            }
        }
Ejemplo n.º 2
0
 protected virtual void buildIndex(Profile profile, osg.Group scene_graph)
 {
     //scene_graph = new osg.Group();
     if (lod.valid())
     {
         scene_graph.addChild(lod.get());
     }
 }
Ejemplo n.º 3
0
 public osg.Group getOrCreateSceneGraph()
 {
     if (!scene_graph.valid())
     {
         scene_graph = new osg.Group();
     }
     return(scene_graph.get());
 }
Ejemplo n.º 4
0
        /**
         * Compiles the entire cell graph.
         *
         * @param task_man
         *      Task manager to employ for parallel/distributed compilation
         *
         * @return
         *      True if the compilation succeeded, false if it failed.
         */
        //public  virtual osg.Group   compile( TaskManager  task_man =NULL)
        public virtual osg.Group compile(TaskManager my_task_man)
        {
            CompileSession cs = (CompileSessionImpl)startCompiling(my_task_man);

            while (continueCompiling(cs))
            {
                ;
            }

            if (finishCompiling(cs))
            {
                osg.Group result = cs.getOrCreateSceneGraph();
                //result.ref(); // since the CS will be destroyed, unref'ing the result
                return(result);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        protected osg.Node createLeafIndexNode(QuadKey key, SmartReadCallback cb)
        {
            osg.Group group = null;

            for (uint i = 0; i < 4; i++)
            {
                QuadKey quadrant_key = key.createSubKey(i);

                if (osgDB.fileExists(createAbsPathFromTemplate("g" + quadrant_key.toString())))
                {
                    if (!group)
                    {
                        group = new osg.Group();
                        group.setName(key.toString());
                    }

#if USE_PAGEDLODS_IN_INDEX
                    osg.PagedLOD *pointer = new osg.PagedLOD();
                    pointer.setFileName(0, createRelPathFromTemplate("g" + quadrant_key.toString()));
                    pointer.setRange(0, 0, 1e10);
                    pointer.setPriorityScale(0, 1000.0f); // top priority!
                    pointer.setPriorityOffset(0, 1000.0f);
                    setCenterAndRadius(pointer, quadrant_key.getExtent(), reader);
#else
                    osg.ProxyNode pointer = new osg.ProxyNode();
                    pointer.setLoadingExternalReferenceMode(osg.ProxyNode.LOAD_IMMEDIATELY);
                    pointer.setFileName(0, createRelPathFromTemplate("g" + quadrant_key.toString()));
                    //setCenterAndRadius( pointer, quadrant_key.getExtent(), reader );
#endif

                    group.addChild(pointer);
                }
            }

            return(group);
        }
Ejemplo n.º 6
0
 public osg.Group getOrCreateSceneGraph()
 {
     if (!scene_graph.valid())
     {
         scene_graph = new osg.Group();
     }
     return scene_graph.get();
 }
Ejemplo n.º 7
0
        protected osg.Node createIntermediateIndexNode(QuadKey key, float min_range, float max_range, SmartReadCallback cb)
        {
            osg.Group group = null;

            for (uint quadrant = 0; quadrant < 4; quadrant++)
            {
                QuadKey subkey = key.createSubKey(quadrant);

                if (osgDB.fileExists(createAbsPathFromTemplate("g" + subkey.toString())))
                {
                    if (!group)
                    {
                        group = new osg.Group();
                        group.setName(key.toString());
                    }

                    //osgGIS.notice() << "QK=" << subkey.toString() << ", Extent=" << subkey.getExtent().toString() << std.endl;

                    // enter the subtile set as a paged index node reference:
                    osg.PagedLOD plod = new osg.PagedLOD();
                    setCenterAndRadius(plod, subkey.getExtent(), reader);


#if USE_PAGEDLODS_IN_INDEX
                    osg.PagedLOD *pointer = new osg.PagedLOD();
                    pointer.setFileName(0, createRelPathFromTemplate("g" + subkey.toString()));
                    pointer.setRange(0, 0, 1e10);
                    pointer.setPriorityScale(0, 1000.0f); // top priority, hopefully
                    pointer.setPriorityOffset(0, 1000.0f);
                    pointer.setCenter(plod.getCenter());
                    pointer.setRadius(plod.getRadius());
#else
                    osg.ProxyNode pointer = new osg.ProxyNode();
                    pointer.setLoadingExternalReferenceMode(osg.ProxyNode.LOAD_IMMEDIATELY);
                    pointer.setFileName(0, createRelPathFromTemplate("g" + subkey.toString()));
                    //setCenterAndRadius( pointer, subkey.getExtent(), reader );
#endif

                    plod.addChild(pointer, max_range, 1e10);
                    plod.setFileName(1, createRelPathFromTemplate("i" + subkey.toString()));
                    plod.setRange(1, 0, max_range); // last one should always be min=0
                    plod.setPriorityScale(1, MY_PRIORITY_SCALE);

                    group.addChild(plod);



                    //osg.Geode* geode = new osg.Geode();

                    //osg.Sphere* g1 = new osg.Sphere( osg.Vec3(0,0,0), plod.getRadius() );
                    //osg.ShapeDrawable* sd1 = new osg.ShapeDrawable( g1 );
                    //sd1.setColor( osg.Vec4f(1,0,0,.2) );
                    //geode.addDrawable( sd1 );

                    ////osg.Vec3d p = terrain_srs.transform( subkey.getExtent().getCentroid() );
                    ////osg.Vec3d n = p; n.normalize();

                    ////osg.Geometry* g3 = new osg.Geometry();
                    ////osg.Vec3Array* v3 = new osg.Vec3Array(2);
                    ////(*v3)[0] = osg.Vec3d(0,0,0);
                    ////(*v3)[1] = n * 3000.0;
                    ////g3.setVertexArray( v3 );
                    ////osg.Vec4Array* c3 = new osg.Vec4Array(1);
                    ////(*c3)[0].set(1,1,0,1);
                    ////g3.setColorArray( c3 );
                    ////g3.setColorBinding(osg.Geometry.BIND_OVERALL);
                    ////g3.addPrimitiveSet( new osg.DrawArrays(GL_LINES, 0, 2) );
                    ////g3.getOrCreateStateSet().setMode( GL_LIGHTING, osg.StateAttribute.OFF );
                    ////geode.addDrawable( g3 );

                    ////osg.Sphere* g2 = new osg.Sphere( osg.Vec3(0,0,0), 25 );
                    ////osg.ShapeDrawable* sd2 = new osg.ShapeDrawable( g2 );
                    ////sd2.setColor( osg.Vec4f(1,1,0,1) );
                    ////geode.addDrawable( sd2 );

                    ////osg.Matrixd mx = osg.Matrixd.translate( p );
                    //osg.Matrixd mx = osg.Matrixd.translate( plod.getCenter() );
                    //osg.MatrixTransform* mt = new osg.MatrixTransform( mx );

                    //mt.addChild( geode );
                    //mt.getOrCreateStateSet().setMode( GL_BLEND, osg.StateAttribute.ON );
                    //mt.getOrCreateStateSet().setRenderingHint( osg.StateSet.TRANSPARENT_BIN );
                    //group.addChild( mt );
                }
            }

            return(group);
        }
Ejemplo n.º 8
0
        protected virtual void buildIndex(Profile _profile, osg.Group scene_graph)
        {
            QuadTreeProfile profile = (QuadTreeProfile)_profile;

            if (profile == null)
            {
                return;
            }

            //osgGIS.notice() << "Rebuilding index..." << std.endl;

            // first, determine the SRS of the output scene graph so that we can
            // make pagedlod/lod centroids.
            SpatialReference output_srs = map_layer.getOutputSRS(getSession(), getTerrainSRS());

            // first build the very top level.
            //scene_graph = new osg.Group();

            // the starting LOD is the best fit the the cell size:
            uint top_lod = getTopLod(profile.getQuadMap(), map_layer);

            SmartReadCallback reader = new SmartReadCallback();

            foreach (MapLayerLevelOfDetail i in map_layer.getLevels())
            {
                MapLayerLevelOfDetail level_def = i;
                uint lod = top_lod + level_def.getDepth();

                MapLayerLevelOfDetail sub_level_def = i + 1 != map_layer.getLevels().end() ? (i + 1).get() : null;
                float min_range, max_range;
                if (sub_level_def != null)
                {
                    min_range = sub_level_def.getMinRange();
                    max_range = sub_level_def.getMaxRange();
                }

                // get the extent of tiles that we will build based on the AOI:
                uint cell_xmin, cell_ymin, cell_xmax, cell_ymax;
                profile.getQuadMap().getCells(
                    map_layer.getAreaOfInterest(), lod,
                    cell_xmin, cell_ymin, cell_xmax, cell_ymax);

                for (uint y = cell_ymin; y <= cell_ymax; y++)
                {
                    for (uint x = cell_xmin; x <= cell_xmax; x++)
                    {
                        osg.Node node;

                        QuadKey key = new QuadKey(x, y, lod, profile.getQuadMap());

                        //osgGIS.notify( osg.NOTICE )
                        //    << "Cell: " << std.endl
                        //    << "   Quadkey = " << key.toString() << std.endl
                        //    << "   LOD = " << key.getLOD() << std.endl
                        //    << "   Extent = " << key.getExtent().toString() << " (w=" << key.getExtent().getWidth() << ", h=" << key.getExtent().getHeight() << ")" << std.endl
                        //    << std.endl;

                        node = sub_level_def ?
                               createIntermediateIndexNode(key, min_range, max_range, reader.get()) :
                               createLeafIndexNode(key, reader);

                        if (node.valid())
                        {
                            string out_file = createAbsPathFromTemplate("i" + key.toString());

                            if (!osgDB.writeNodeFile(*(node.get()), out_file))
                            {
                                // osgGIS.warn() << "FAILED to write index file " << out_file << std.endl;
                            }

                            // at the top level, assemble the root node
                            if (i == map_layer.getLevels().begin())
                            {
                                double top_min_range = sub_level_def != null ? 0 : level_def.getMinRange();

                                osg.PagedLOD plod = new osg.PagedLOD();
                                plod.setName(key.toString());
                                plod.setFileName(0, createRelPathFromTemplate("i" + key.toString()));
                                plod.setRange(0, top_min_range, level_def.getMaxRange());
                                plod.setPriorityScale(0, MY_PRIORITY_SCALE);
                                setCenterAndRadius(plod, key.getExtent(), reader.get());

                                //osgGIS.notice() << "QK=" << key.toString() << ", Ex=" << key.getExtent().toString() << ", Cen=" << key.getExtent().getCentroid().toString() << std.endl;


                                scene_graph.addChild(plod);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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;
        }
        protected osg.Node createLeafIndexNode(QuadKey key, SmartReadCallback cb)
        {
            osg.Group group = null;

            for (uint i = 0; i < 4; i++)
            {
                QuadKey quadrant_key = key.createSubKey(i);

                if (osgDB.fileExists(createAbsPathFromTemplate("g" + quadrant_key.toString())))
                {
                    if (!group)
                    {
                        group = new osg.Group();
                        group.setName(key.toString());
                    }

            #if USE_PAGEDLODS_IN_INDEX
            osg.PagedLOD* pointer = new osg.PagedLOD();
            pointer.setFileName( 0, createRelPathFromTemplate( "g" + quadrant_key.toString() ) );
            pointer.setRange( 0, 0, 1e10 );
            pointer.setPriorityScale( 0, 1000.0f ); // top priority!
            pointer.setPriorityOffset( 0, 1000.0f );
            setCenterAndRadius( pointer, quadrant_key.getExtent(), reader );
            #else
                    osg.ProxyNode pointer = new osg.ProxyNode();
                    pointer.setLoadingExternalReferenceMode(osg.ProxyNode.LOAD_IMMEDIATELY);
                    pointer.setFileName(0, createRelPathFromTemplate("g" + quadrant_key.toString()));
                    //setCenterAndRadius( pointer, quadrant_key.getExtent(), reader );
            #endif

                    group.addChild(pointer);
                }
            }

            return group;
        }
        protected osg.Node createIntermediateIndexNode(QuadKey key, float min_range, float max_range, SmartReadCallback cb)
        {
            osg.Group group = null;

            for (uint quadrant = 0; quadrant < 4; quadrant++)
            {
                QuadKey subkey = key.createSubKey(quadrant);

                if (osgDB.fileExists(createAbsPathFromTemplate("g" + subkey.toString())))
                {
                    if (!group)
                    {
                        group = new osg.Group();
                        group.setName(key.toString());
                    }

                    //osgGIS.notice() << "QK=" << subkey.toString() << ", Extent=" << subkey.getExtent().toString() << std.endl;

                    // enter the subtile set as a paged index node reference:
                    osg.PagedLOD plod = new osg.PagedLOD();
                    setCenterAndRadius(plod, subkey.getExtent(), reader);

            #if USE_PAGEDLODS_IN_INDEX
            osg.PagedLOD* pointer = new osg.PagedLOD();
            pointer.setFileName( 0, createRelPathFromTemplate( "g" + subkey.toString() ) );
            pointer.setRange( 0, 0, 1e10 );
            pointer.setPriorityScale( 0, 1000.0f ); // top priority, hopefully
            pointer.setPriorityOffset( 0, 1000.0f );
            pointer.setCenter( plod.getCenter() );
            pointer.setRadius( plod.getRadius() );
            #else
                    osg.ProxyNode pointer = new osg.ProxyNode();
                    pointer.setLoadingExternalReferenceMode(osg.ProxyNode.LOAD_IMMEDIATELY);
                    pointer.setFileName(0, createRelPathFromTemplate("g" + subkey.toString()));
                    //setCenterAndRadius( pointer, subkey.getExtent(), reader );
            #endif

                    plod.addChild(pointer, max_range, 1e10);
                    plod.setFileName(1, createRelPathFromTemplate("i" + subkey.toString()));
                    plod.setRange(1, 0, max_range); // last one should always be min=0
                    plod.setPriorityScale(1, MY_PRIORITY_SCALE);

                    group.addChild(plod);

                    //osg.Geode* geode = new osg.Geode();

                    //osg.Sphere* g1 = new osg.Sphere( osg.Vec3(0,0,0), plod.getRadius() );
                    //osg.ShapeDrawable* sd1 = new osg.ShapeDrawable( g1 );
                    //sd1.setColor( osg.Vec4f(1,0,0,.2) );
                    //geode.addDrawable( sd1 );

                    ////osg.Vec3d p = terrain_srs.transform( subkey.getExtent().getCentroid() );
                    ////osg.Vec3d n = p; n.normalize();

                    ////osg.Geometry* g3 = new osg.Geometry();
                    ////osg.Vec3Array* v3 = new osg.Vec3Array(2);
                    ////(*v3)[0] = osg.Vec3d(0,0,0);
                    ////(*v3)[1] = n * 3000.0;
                    ////g3.setVertexArray( v3 );
                    ////osg.Vec4Array* c3 = new osg.Vec4Array(1);
                    ////(*c3)[0].set(1,1,0,1);
                    ////g3.setColorArray( c3 );
                    ////g3.setColorBinding(osg.Geometry.BIND_OVERALL);
                    ////g3.addPrimitiveSet( new osg.DrawArrays(GL_LINES, 0, 2) );
                    ////g3.getOrCreateStateSet().setMode( GL_LIGHTING, osg.StateAttribute.OFF );
                    ////geode.addDrawable( g3 );

                    ////osg.Sphere* g2 = new osg.Sphere( osg.Vec3(0,0,0), 25 );
                    ////osg.ShapeDrawable* sd2 = new osg.ShapeDrawable( g2 );
                    ////sd2.setColor( osg.Vec4f(1,1,0,1) );
                    ////geode.addDrawable( sd2 );

                    ////osg.Matrixd mx = osg.Matrixd.translate( p );
                    //osg.Matrixd mx = osg.Matrixd.translate( plod.getCenter() );
                    //osg.MatrixTransform* mt = new osg.MatrixTransform( mx );

                    //mt.addChild( geode );
                    //mt.getOrCreateStateSet().setMode( GL_BLEND, osg.StateAttribute.ON );
                    //mt.getOrCreateStateSet().setRenderingHint( osg.StateSet.TRANSPARENT_BIN );
                    //group.addChild( mt );
                }
            }

            return group;
        }
Ejemplo n.º 13
0
 protected abstract void buildIndex(Profile profile, osg.Group group);
Ejemplo n.º 14
0
        protected virtual AttributedNodeList process(AttributedNodeList input, FilterEnv env)
        {
            Node  result;

            if ( input.Count > 1 )
            {
            result = new osg.Group();
            for( AttributedNodeList.iterator i = input.begin(); i != input.end(); i++ )
            {
            osg.Node  node = i.get().getNode();
            if ( node != null)
            {
                if ( getEmbedAttributes() )
                    embedAttributes( node, i.get().getAttributes() );

                result.asGroup().addChild( node );
            }
            }
            }
            else if ( input.Count == 1 )
            {
            result = input[0].getNode();

            if ( getEmbedAttributes() )
            embedAttributes( result.get(), input[0].getAttributes() );
            }
            else
            {
            return new AttributedNodeList();
            }

            // if there are no drawables or external refs, toss it.
            if ( !GeomUtils.hasDrawables( result.get() ) )
            {
            return AttributedNodeList();
            }

            // NEXT create a XFORM if there's a localization matrix in the SRS. This will
            // prevent jittering due to loss of precision.
              SpatialReference  input_srs = env.getInputSRS();

            if ( env.getExtent().getArea() > 0 && !input_srs.getReferenceFrame().isIdentity() )
            {
            Vector3D centroid = new Vector3D( 0, 0, 0 );
            osg.Matrixd irf = input_srs.getInverseReferenceFrame();
            osg.Vec3d centroid_abs = centroid * irf;
            osg.MatrixTransform xform = new osg.MatrixTransform( irf );

            xform.addChild( result);
            result = xform;

            if ( getApplyClusterCulling() && input_srs.isGeocentric() )
            {
            Vector3D normal = centroid_abs;
            normal.normalize();

            //osg.BoundingSphere bs = result.computeBound(); // force it
            // radius = distance from centroid inside which to disable CC altogether:
            //float radius = bs.radius();
            //osg.Vec3d control_point = bs.center();

            Vector3D control_point = centroid_abs;
            GeoPoint env_cen = input_srs.transform( env.getCellExtent().getCentroid() );
            GeoPoint env_sw  = input_srs.transform( env.getCellExtent().getSouthwest() );
            float radius = (env_cen-env_sw).length();

            // dot product: 0 = orthogonal to normal, -1 = equal to normal
            float deviation = -radius/input_srs.getEllipsoid().getSemiMinorAxis();

            osg.ClusterCullingCallback ccc = new osg.ClusterCullingCallback();
            ccc.set( control_point, normal, deviation, radius );

            osg.Group cull_group = new osg.Group();
            cull_group.setCullCallback( ccc );
            cull_group.addChild( xform );
            result = cull_group;

            //osgGIS.notify(osg.NOTICE) << "CCC: radius = " << radius << ", deviation = " << deviation << std.endl;

            //if ( getDrawClusterCullingNormals() == true )
            //{
            //    //DRAW CLUSTER-CULLING NORMALS
            //    osg.Geode* geode = new osg.Geode();
            //    osg.Geometry* g = new osg.Geometry();
            //    osg.Vec3Array* v = new osg.Vec3Array(2);
            //    (*v)[0] = control_point; (*v)[1] = control_point + (normal*radius);
            //    g.setVertexArray( v );
            //    osg.Vec4Array* c = new osg.Vec4Array(1);
            //    (*c)[0] = osg.Vec4f( 0,1,0,1 );
            //    g.setColorArray( c );
            //    g.setColorBinding( osg.Geometry.BIND_OVERALL );
            //    g.addPrimitiveSet( new osg.DrawArrays( osg.PrimitiveSet.LINES, 0, 2 ) );
            //    geode.addDrawable( g );
            //    cull_group.addChild( geode );
            //}
            }
            }

            if ( getCullBackfaces() )
            {
            result.getOrCreateStateSet().setAttributeAndModes( new osg.CullFace(), osg.StateAttribute.ON );
            }

            if ( getDisableLighting() )
            {
            result.getOrCreateStateSet().setMode( GL_LIGHTING, osg.StateAttribute.OFF );
            }

            if ( getLineWidth() > 0.0f )
            {
            result.getOrCreateStateSet().setAttribute( new osg.LineWidth( line_width ), osg.StateAttribute.ON );
            }

            if ( getPointSize() > 0.0f )
            {
            osg.Point point = new osg.Point();
            point.setSize( point_size );
            result.getOrCreateStateSet().setAttribute( point, osg.StateAttribute.ON );
            }

            if ( getAlphaBlending() )
            {
            osg.BlendFunc blend_func = new osg.BlendFunc();
            //blend_func.setFunction( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
            result.getOrCreateStateSet().setAttributeAndModes( blend_func, osg.StateAttribute.ON );
            result.getOrCreateStateSet().setRenderingHint( osg.StateSet.TRANSPARENT_BIN );
            }

            if ( getRasterOverlayScript() )
            {
            ScriptResult r = env.getScriptEngine().run( getRasterOverlayScript(), env );
            if ( r.isValid() )
            {
            RasterResource* raster = env.getSession().getResources().getRaster( r.asString() );
            if ( raster )
            {
                osg.Image* image = NULL;

                std.stringstream builder;

                string cell_id = env.getProperties().getValue( "compiler.cell_id", "" );
                if ( cell_id.length() > 0 )
                {
                    builder << "r" << cell_id << ".jpg";
                }
                else
                {
                    double x = env.getExtent().getCentroid().x();
                    double y = env.getExtent().getCentroid().y();
                    builder << std.setprecision(10) << "r" << x << "x" << y << ".jpg";
                }

                if ( raster.applyToStateSet( result.getOrCreateStateSet(), env.getExtent(), getRasterOverlayMaxSize(), &image ) )
                {
                    // Add this as a skin resource so the compiler can properly localize and deploy it.
                    image.setFileName( builder.str() );

                    env.getResourceCache().addSkin( result.getOrCreateStateSet() );
                }
            }
            }
            else
            {
            env.getReport().error( r.asString() );
            }
            }

            if ( getOptimize() )
            {
            //osgGIS.notice() << "[BuildNodes] Optimizing..." << std.endl;

            osgUtil.Optimizer opt;
            int opt_mask =
            osgUtil.Optimizer.DEFAULT_OPTIMIZATIONS |
            osgUtil.Optimizer.MERGE_GEODES |
            osgUtil.Optimizer.TRISTRIP_GEOMETRY |
            osgUtil.Optimizer.SPATIALIZE_GROUPS;

            // disable texture atlases, since they mess with our shared skin resources and
            // don't work correctly during multi-threaded building
            opt_mask &= ~osgUtil.Optimizer.TEXTURE_ATLAS_BUILDER;

            // I've seen this crash the app when dealing with certain ProxyNodes.
            // TODO: investigate this later.
            opt_mask &= ~osgUtil.Optimizer.REMOVE_REDUNDANT_NODES;

            // integrate the optimizer hints:
            opt_mask |= env.getOptimizerHints().getIncludedOptions();
            opt_mask &= ~( env.getOptimizerHints().getExcludedOptions() );

            opt.optimize( result.get(), opt_mask );

            GeometryCleaner cleaner;
            cleaner.clean( result.get() );
            }

            AttributedNodeList output;
            output.push_back( new AttributedNode( result.get() ) );

            return output;
        }
Ejemplo n.º 15
0
        protected virtual AttributedNodeList process(AttributedNodeList input, FilterEnv env)
        {
            Node result;

            if (input.Count > 1)
            {
                result = new osg.Group();
                for (AttributedNodeList.iterator i = input.begin(); i != input.end(); i++)
                {
                    osg.Node node = i.get().getNode();
                    if (node != null)
                    {
                        if (getEmbedAttributes())
                        {
                            embedAttributes(node, i.get().getAttributes());
                        }

                        result.asGroup().addChild(node);
                    }
                }
            }
            else if (input.Count == 1)
            {
                result = input[0].getNode();

                if (getEmbedAttributes())
                {
                    embedAttributes(result.get(), input[0].getAttributes());
                }
            }
            else
            {
                return(new AttributedNodeList());
            }

            // if there are no drawables or external refs, toss it.
            if (!GeomUtils.hasDrawables(result.get()))
            {
                return(AttributedNodeList());
            }

            // NEXT create a XFORM if there's a localization matrix in the SRS. This will
            // prevent jittering due to loss of precision.
            SpatialReference input_srs = env.getInputSRS();

            if (env.getExtent().getArea() > 0 && !input_srs.getReferenceFrame().isIdentity())
            {
                Vector3D            centroid     = new Vector3D(0, 0, 0);
                osg.Matrixd         irf          = input_srs.getInverseReferenceFrame();
                osg.Vec3d           centroid_abs = centroid * irf;
                osg.MatrixTransform xform        = new osg.MatrixTransform(irf);

                xform.addChild(result);
                result = xform;

                if (getApplyClusterCulling() && input_srs.isGeocentric())
                {
                    Vector3D normal = centroid_abs;
                    normal.normalize();

                    //osg.BoundingSphere bs = result.computeBound(); // force it
                    // radius = distance from centroid inside which to disable CC altogether:
                    //float radius = bs.radius();
                    //osg.Vec3d control_point = bs.center();

                    Vector3D control_point = centroid_abs;
                    GeoPoint env_cen       = input_srs.transform(env.getCellExtent().getCentroid());
                    GeoPoint env_sw        = input_srs.transform(env.getCellExtent().getSouthwest());
                    float    radius        = (env_cen - env_sw).length();

                    // dot product: 0 = orthogonal to normal, -1 = equal to normal
                    float deviation = -radius / input_srs.getEllipsoid().getSemiMinorAxis();

                    osg.ClusterCullingCallback ccc = new osg.ClusterCullingCallback();
                    ccc.set(control_point, normal, deviation, radius);

                    osg.Group cull_group = new osg.Group();
                    cull_group.setCullCallback(ccc);
                    cull_group.addChild(xform);
                    result = cull_group;


                    //osgGIS.notify(osg.NOTICE) << "CCC: radius = " << radius << ", deviation = " << deviation << std.endl;


                    //if ( getDrawClusterCullingNormals() == true )
                    //{
                    //    //DRAW CLUSTER-CULLING NORMALS
                    //    osg.Geode* geode = new osg.Geode();
                    //    osg.Geometry* g = new osg.Geometry();
                    //    osg.Vec3Array* v = new osg.Vec3Array(2);
                    //    (*v)[0] = control_point; (*v)[1] = control_point + (normal*radius);
                    //    g.setVertexArray( v );
                    //    osg.Vec4Array* c = new osg.Vec4Array(1);
                    //    (*c)[0] = osg.Vec4f( 0,1,0,1 );
                    //    g.setColorArray( c );
                    //    g.setColorBinding( osg.Geometry.BIND_OVERALL );
                    //    g.addPrimitiveSet( new osg.DrawArrays( osg.PrimitiveSet.LINES, 0, 2 ) );
                    //    geode.addDrawable( g );
                    //    cull_group.addChild( geode );
                    //}
                }
            }

            if (getCullBackfaces())
            {
                result.getOrCreateStateSet().setAttributeAndModes(new osg.CullFace(), osg.StateAttribute.ON);
            }

            if (getDisableLighting())
            {
                result.getOrCreateStateSet().setMode(GL_LIGHTING, osg.StateAttribute.OFF);
            }

            if (getLineWidth() > 0.0f)
            {
                result.getOrCreateStateSet().setAttribute(new osg.LineWidth(line_width), osg.StateAttribute.ON);
            }

            if (getPointSize() > 0.0f)
            {
                osg.Point point = new osg.Point();
                point.setSize(point_size);
                result.getOrCreateStateSet().setAttribute(point, osg.StateAttribute.ON);
            }

            if (getAlphaBlending())
            {
                osg.BlendFunc blend_func = new osg.BlendFunc();
                //blend_func.setFunction( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
                result.getOrCreateStateSet().setAttributeAndModes(blend_func, osg.StateAttribute.ON);
                result.getOrCreateStateSet().setRenderingHint(osg.StateSet.TRANSPARENT_BIN);
            }

            if (getRasterOverlayScript())
            {
                ScriptResult r = env.getScriptEngine().run(getRasterOverlayScript(), env);
                if (r.isValid())
                {
                    RasterResource *raster = env.getSession().getResources().getRaster(r.asString());
                    if (raster)
                    {
                        osg.Image *image = NULL;

                        std.stringstream builder;

                        string cell_id = env.getProperties().getValue("compiler.cell_id", "");
                        if (cell_id.length() > 0)
                        {
                            builder << "r" << cell_id << ".jpg";
                        }
                        else
                        {
                            double x = env.getExtent().getCentroid().x();
                            double y = env.getExtent().getCentroid().y();
                            builder << std.setprecision(10) << "r" << x << "x" << y << ".jpg";
                        }

                        if (raster.applyToStateSet(result.getOrCreateStateSet(), env.getExtent(), getRasterOverlayMaxSize(), &image))
                        {
                            // Add this as a skin resource so the compiler can properly localize and deploy it.
                            image.setFileName(builder.str());

                            env.getResourceCache().addSkin(result.getOrCreateStateSet());
                        }
                    }
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            if (getOptimize())
            {
                //osgGIS.notice() << "[BuildNodes] Optimizing..." << std.endl;

                osgUtil.Optimizer opt;
                int opt_mask =
                    osgUtil.Optimizer.DEFAULT_OPTIMIZATIONS |
                    osgUtil.Optimizer.MERGE_GEODES |
                    osgUtil.Optimizer.TRISTRIP_GEOMETRY |
                    osgUtil.Optimizer.SPATIALIZE_GROUPS;

                // disable texture atlases, since they mess with our shared skin resources and
                // don't work correctly during multi-threaded building
                opt_mask &= ~osgUtil.Optimizer.TEXTURE_ATLAS_BUILDER;

                // I've seen this crash the app when dealing with certain ProxyNodes.
                // TODO: investigate this later.
                opt_mask &= ~osgUtil.Optimizer.REMOVE_REDUNDANT_NODES;

                // integrate the optimizer hints:
                opt_mask |= env.getOptimizerHints().getIncludedOptions();
                opt_mask &= ~(env.getOptimizerHints().getExcludedOptions());

                opt.optimize(result.get(), opt_mask);

                GeometryCleaner cleaner;
                cleaner.clean(result.get());
            }

            AttributedNodeList output;

            output.push_back(new AttributedNode(result.get()));

            return(output);
        }
Ejemplo n.º 16
0
        /**
         * Runs the graph to generate a scene graph.
         *
         * Executes the graph by passing features to the first filter in the
         * chain. That filter will process the data, pass the results along to
         * the next filter, and so on until completion.
         *
         * @param cursor
         *      Source cursor for features to process
         * @param env
         *      Contextual compilation environment
         * @param output
         *      Group node that, upon success, contains resulting nodes of compiled scene
         *      as its children
         * @return
         *      A structure describing the result of the compilation.
         */
        public FilterGraphResult computeNodes(FeatureCursor cursor, FilterEnv env, osg.Group output)
        {
            FilterStateResult state_result;

            output = null;

            NodeFilterState output_state;

            // first build a new state chain corresponding to our filter prototype chain.
            FilterState first = null;

            foreach (Filter i in filter_prototypes)
            {
                FilterState next_state = i.newState();
                if (first == null)
                {
                    first = next_state;
                }
                else
                {
                    first.appendState(next_state);
                }

                if (next_state is NodeFilterState)
                {
                    output_state = (NodeFilterState)next_state;
                }
            }

            // now traverse the states.
            if (first != null)
            {
                int         count = 0;
                osg.Timer_t start = osg.Timer.instance().tick();

                env.setOutputSRS(env.getInputSRS());

                if (first is FeatureFilterState)
                {
                    FeatureFilterState state = (FeatureFilterState)first;
                    while (state_result.isOK() && cursor.hasNext())
                    {
                        state.push(wind(cursor.next()));
                        state_result = state.traverse(env);
                        count++;
                    }
                    if (state_result.isOK())
                    {
                        state_result = state.signalCheckpoint();
                    }
                }
                else if (first is FragmentFilterState)
                {
                    FragmentFilterState state = (FragmentFilterState)first;
                    while (state_result.isOK() && cursor.hasNext())
                    {
                        state.push(wind(cursor.next()));
                        state_result = state.traverse(env);
                        count++;
                    }
                    if (state_result.isOK())
                    {
                        state_result = state.signalCheckpoint();
                    }
                }
                else if (first is CollectionFilterState)
                {
                    CollectionFilterState state = (CollectionFilterState)first;
                    while (state_result.isOK() && cursor.hasNext())
                    {
                        state.push(wind(cursor.next()));
                        state_result = state.traverse(env);
                        count++;
                    }
                    if (state_result.isOK())
                    {
                        state_result = state.signalCheckpoint();
                    }
                }

                osg.Timer_t end = osg.Timer.instance().tick();

                double dur = osg.Timer.instance().delta_s(start, end);
                //osgGIS.notify( osg.ALWAYS ) << std.endl << "Time = " << dur << " s; Per Feature Avg = " << (dur/(double)count) << " s" << std.endl;
            }
            else
            {
                state_result.set(FilterStateResult.Status.STATUS_NODATA);
            }

            if (output_state != null && state_result.hasData())
            {
                output = new osg.Group();
                foreach (AttributedNode i in output_state.getOutput())
                {
                    output.addChild(i.getNode());
                }
            }

            if (state_result.isOK())
            {
                return(FilterGraphResult.ok(output_state.getLastKnownFilterEnv()));
            }
            else
            {
                return(FilterGraphResult.error("Filter graph failed to compute any nodes"));
            }
        }