/*** 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); }
/** * 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; }
public virtual void runSynchronousPostProcess(Report report) { if (need_to_compile) { if (!getResult().isOK()) { // osgGIS.notice() << getName() << " failed to compile: " << getResult().getMessage() << std.endl; return; } if (output_status == CellCompiler.OutputStatus.OUTPUT_EMPTY) //!getResultNode() || !has_drawables ) { // osgGIS.info() << getName() << " resulted in no geometry" << std.endl; result_node = null; return; } if (packager.valid()) { // TODO: we should probably combine the following two calls into one: // update any texture/model refs in preparation for packaging: packager.rewriteResourceReferences(getResultNode()); // copy resources to their final destination packager.packageResources(env.getResourceCache(), report); // write the node data itself osg.Node node_to_package = getResultNode(); if (!packager.packageNode(node_to_package.get(), abs_output_uri)) //, env.getCellExtent(), min_range, max_range ) ) { //osgGIS.warn() << getName() << " failed to package node to output location" << std.endl; result = FilterGraphResult.error("Cell built OK, but failed to deploy to disk/archive"); } } } }
/** * 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; }
void LayerCompiler.localizeResources(string output_folder) { // collect the resources marked as used. ResourceList resources_to_localize = getSession().getResourcesUsed(true); osgDB.ReaderWriter.Options local_options = new osgDB.ReaderWriter.Options(); foreach (Resource i in resources_to_localize) { Resource resource = i; // if we are localizing resources, attempt to copy each one to the output folder: if (getLocalizeResources()) { if (resource is SkinResource) { SkinResource skin = (SkinResource)resource; /******/ Image image = null; //skin.getImage(); if (image != null) { string filename = osgDB.getSimpleFileName(image.getFileName()); Image output_image = image.get(); if (getCompressTextures()) { output_image = ImageUtils.convertRGBAtoDDS(image.get()); filename = osgDB.getNameLessExtension(filename) + ".dds"; output_image.setFileName(filename); } if (getArchive() && !getArchive().fileExists(filename)) { osgDB.ReaderWriter.WriteResult r = getArchive().writeImage(*(output_image.get()), filename, local_options.get()); if (r.error()) { //TODO osgGIS.notify( osg.WARN ) << " Failure to copy image " << filename << " into the archive" << std.endl; } } else { if (osgDB.fileExists(output_folder)) { if (!osgDB.writeImageFile(*(output_image.get()), PathUtils.combinePaths(output_folder, filename), local_options.get())) { //TODO osgGIS.notify( osg.WARN ) << " FAILED to copy image " << filename << " into the folder " << output_folder << std.endl; } } else { //TODO osgGIS.notify( osg.WARN ) << " FAILD to localize image " << filename << ", folder " << output_folder << " not found" << std.endl; } } } } else if (resource is ModelResource) { ModelResource model = (ModelResource)resource; osg.Node node = osgDB.readNodeFile(model.getAbsoluteURI()); if (node.valid()) { string filename = osgDB.getSimpleFileName(model.getAbsoluteURI()); if (getArchive() != null) { osgDB.ReaderWriter.WriteResult r = getArchive().writeNode(*(node.get()), filename, local_options.get()); if (r.error()) { //TODO osgGIS.notify( osg.WARN ) << " Failure to copy model " << filename << " into the archive" << std.endl; } } else { if (osgDB.fileExists(output_folder)) { if (!osgDB.writeNodeFile(*(node.get()), osgDB.concatPaths(output_folder, filename), local_options.get())) { //TODO osgGIS.notify( osg.WARN ) << " FAILED to copy model " << filename << " into the folder " << output_folder << std.endl; } } else { //TODO osgGIS.notify( osg.WARN ) << " FAILD to localize model " << filename << ", folder " << output_folder << " not found" << std.endl; } } } } } // now remove any single-use (i.e. non-shared) resources (whether we are localizing them or not) if (resource.isSingleUse()) { getSession().getResources().removeResource(resource); } } }
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); } }