protected virtual void buildIndex(Profile profile, osg.Group scene_graph)
 {
     //scene_graph = new osg.Group();
     if (lod.valid())
     {
         scene_graph.addChild(lod.get());
     }
 }
 public CompileSessionImpl(TaskManager _task_man,
     Profile _profile,
     uint _total_tasks,
     osg.Timer_t _start_time)
 {
     task_man = _task_man;
     profile = _profile;
     total_tasks = _total_tasks; start_time = _start_time;
     //NOP
 }
        protected void setCenterAndRadius(osg.Node node, GeoExtent cell_extent, SmartReadCallback reader)
        {
            SpatialReference srs = map_layer.getOutputSRS(getSession(), getTerrainSRS());
            // first get the output srs centroid:
            GeoPoint centroid = srs.transform(cell_extent.getCentroid());
            GeoPoint sw = srs.transform(cell_extent.getSouthwest());

            double radius = map_layer.getEncodeCellRadius() ?
                (centroid - sw).length() :
                -1.0;

            if (terrain_node.valid() && terrain_srs != null)
            {
                GeoPoint clamped;
                for (int t = 0; t < 5; t++)
                {
                    clamped = GeomUtils.clampToTerrain(centroid, terrain_node.get(), terrain_srs, reader);
                    if (!clamped.isValid())
                    {
                        // if the clamp failed, it's due to the geocentric intersection bug in which the isect
                        // fails when coplanar with a tile boundary/skirt. Fudge the centroid and try again.
                        double fudge = 0.001 * ((double)(1 + (Random.Rand() % 10)));
                        centroid.X += fudge;
                        centroid.Y -= fudge;
                        centroid.Z += fudge * fudge;
                    }
                    else
                    {
                        break;
                    }
                }

                if (!clamped.isValid())
                {
                    SpatialReference geo = srs.getGeographicSRS();
                    GeoPoint latlon = geo.transform(centroid);
                    //osgGIS.warn() << "*** UNABLE TO CLAMP CENTROID: ***" << latlon.toString() << std.endl;
                }
                else
                {
                    centroid = clamped;
                }
            }
            else
            {
                //osgGIS.warn() << "*** Failed to clamp Center/Radius for cell" << std.endl;
            }

            if (node is osg.LOD)
            {
                osg.LOD plod = (osg.LOD)node;
                plod.setCenter(centroid);
                plod.setRadius(radius);
            }
            else if (node is osg.ProxyNode)
            {
                osg.ProxyNode proxy = (osg.ProxyNode)node;
                proxy.setCenter(centroid);
                proxy.setRadius(radius);
            }
        }
 protected abstract void buildIndex(Profile profile, osg.Group group);
        /**
         * Sets the reference terrain against which to compile.
         */
        //public  void setTerrain(
        //    osg.Node               terrain,
        //      SpatialReference  terrain_srs =NULL,
        //      GeoExtent         terrain_extent =GeoExtent.infinite() )
        public void setTerrain(osg.Node _terrain,
            SpatialReference _terrain_srs,
            GeoExtent _terrain_extent)
        {
            terrain_node = _terrain;
            terrain_srs = (SpatialReference)_terrain_srs;
            terrain_extent = _terrain_extent;

            if (terrain_srs == null)
                terrain_srs = MogreGis.Registry.SRSFactory().createSRSfromTerrain(terrain_node.get());

            //if ( !terrain_srs.valid() )
            //    osgGIS.warn() << "[MapLayerCompiler] WARNING: cannot determine SRS of terrain!" << std.endl;
        }
 /**
  * Creates a new SRS from data found in an osg::CoordinateSystemNode.
  *
  * @param cs_node
  *      Node for which to determine the SRS
  * @return
  *      A spatial reference. Caller is responsible for deleting
  *      the return object.
  */
 public SpatialReference createGeocentricSRS(osg.CoordinateSystemNode cs_node);
 protected void generateNormals(osg.Geometry geom)
 {
     if (geom != null)
     {
         osgUtil.SmoothingVisitor smoother;
         smoother.smooth(out geom);
     }
 }
        protected void applyOverlayTexturing(osg.Geometry geom, Feature input, FilterEnv env)
        {
            GeoExtent tex_extent;

            if (getRasterOverlayScript() != null)
            {
                // if there's a raster script for this filter, we're applying textures per-feature:
                tex_extent = new GeoExtent(
                    input.getExtent().getSouthwest().getAbsolute(),
                    input.getExtent().getNortheast().getAbsolute());
            }
            else
            {
                // otherwise prepare the geometry for an overlay texture covering the entire working extent:
                tex_extent = env.getExtent();
            }

            float width = (float)tex_extent.getWidth();
            float height = (float)tex_extent.getHeight();

            // now visit the verts and calculate texture coordinates for each one.
            osg.Vec3Array verts = (osg.Vec3Array)(geom.getVertexArray());
            if (verts != null)
            {
                // if we are dealing with geocentric data, we will need to xform back to a real
                // projection in order to determine texture coords:
                GeoExtent tex_extent_geo;
                if (env.getInputSRS().isGeocentric())
                {
                    tex_extent_geo = new GeoExtent(
                        tex_extent.getSRS().getGeographicSRS().transform(tex_extent.getSouthwest()),
                        tex_extent.getSRS().getGeographicSRS().transform(tex_extent.getNortheast()));
                }

                osg.Vec2Array texcoords = new osg.Vec2Array(verts.size());
                for (int j = 0; j < verts.size(); j++)
                {
                    // xform back to raw SRS w.o. ref frame:
                    GeoPoint vert = new GeoPoint(verts[j], env.getInputSRS());
                    GeoPoint vert_map = vert.getAbsolute();
                    float tu, tv;
                    if (env.getInputSRS().isGeocentric())
                    {
                        tex_extent_geo.getSRS().transformInPlace(vert_map);
                        tu = (vert_map.X - tex_extent_geo.getXMin()) / width;
                        tv = (vert_map.Y - tex_extent_geo.getYMin()) / height;
                    }
                    else
                    {
                        tu = (vert_map.X - tex_extent.getXMin()) / width;
                        tv = (vert_map.Y - tex_extent.getYMin()) / height;
                    }
                    (*texcoords)[j].set(tu, tv);
                }
                geom.setTexCoordArray(0, texcoords);
            }

            // if we are applying the raster per-feature, do so now.
            // TODO: deprecate? will we ever use this versus the BuildNodesFilter overlay? maybe
            if (getRasterOverlayScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getRasterOverlayScript(), input, env);
                if (r.isValid())
                {
                    RasterResource raster = env.getSession().getResources().getRaster(r.asString());
                    if (raster != null)
                    {
                        Image image = null;
                        std.stringstream builder;
                        builder << "rtex_" << input.getOID() << ".jpg"; //TODO: dds with DXT1 compression

                        osg.StateSet raster_ss = new osg.StateSet();
                        if (raster.applyToStateSet(raster_ss.get(), tex_extent, getRasterOverlayMaxSize(), out image))
                        {
                            image.setFileName(builder.str());
                            geom.setStateSet(raster_ss.get());

                            // add this as a skin resource so the compiler can properly localize and deploy it.
                            env.getResourceCache().addSkin(raster_ss.get());
                        }
                    }
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }
        }
 public void rewriteResourceReferences(osg.Node node)
 {
     throw new NotImplementedException();
 }
 public bool packageNode(osg.Node node, string abs_uri)
 {
     throw new NotImplementedException();
 }
 static void fixMipmapSettings(osg.StateSet ss)
 {
     for (uint i = 0; i < ss.getTextureAttributeList().size(); i++)
     {
         osg.Texture2D tex = (osg.Texture2D)(ss.getTextureAttribute(i, osg.StateAttribute.TEXTURE));
         if (tex != null)
         {
             tex.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR_MIPMAP_LINEAR);
             tex.setFilter(osg.Texture.MAG_FILTER, osg.Texture.LINEAR);
         }
     }
 }
Exemple #12
0
        /*** Statics ********************************************************/
        static bool getTerrainData(Terrain terrain,
            out osg.Node out_terrain_node,
            out SpatialReference out_terrain_srs,
            out GeoExtent out_terrain_extent)
        {
            if (terrain != null)
            {
                if (!string.IsNullOrEmpty(terrain.getURI()))
                {
                    out_terrain_node = osgDB.readNodeFile(terrain.getAbsoluteURI());
                }

                // first check for an explicity defined SRS:
                out_terrain_srs = terrain.getExplicitSRS();
                if (out_terrain_srs != null && out_terrain_srs.isGeographic())
                {
                    // and make it geocentric if necessary..
                    out_terrain_srs = Registry.SRSFactory().createGeocentricSRS(out_terrain_srs.get());
                }

                if (out_terrain_node != null)
                {
                    // if the SRS wasn't explicit, try to read it from the scene graph:
                    if (out_terrain_srs == null)
                    {
                        out_terrain_srs = Registry.SRSFactory().createSRSfromTerrain(out_terrain_node.get());
                    }

                    //osgGIS.notice()
                    //    << "Loaded TERRAIN from \"" << terrain.getAbsoluteURI() << "\", SRS = "
                    //    << (out_terrain_srs != null? out_terrain_srs.getName() : "unknown")
                    //    << std.endl;
                }

                else if (!string.IsNullOrEmpty(terrain.getURI()))
                {
                    //osgGIS.warn()
                    //    << "Unable to load data for terrain \""
                    //    << terrain.getName() << "\"."
                    //    << std.endl;

                    return false;
                }
            }

            out_terrain_extent = new GeoExtent(-180, -90, 180, 90,
                                    Registry.instance().getSRSFactory().createWGS84());

            return true;
        }
        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);
                            }
                        }
                    }
                }
            }
        }