void ElevationQuery::reset() { // set read callback for IntersectionVisitor _ivrc = new osgSim::DatabaseCacheReadCallback(); _terrainModelLayers.clear(); _elevationLayers.clear(); osg::ref_ptr<const Map> map; if (_map.lock(map)) { map->getLayers(_elevationLayers); // cache a vector of terrain patch models. LayerVector layers; map->getLayers(layers); for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i) { if (i->get()->options().terrainPatch() == true) { _terrainModelLayers.push_back(i->get()); } } // revisions are now in sync. _mapRevision = map->getDataModelRevision(); } // clear any active envelope _envelope = 0L; }
bool MapFrame::sync() { bool changed = false; _elevationLayers.clear(); osg::ref_ptr<const Map> map; if ( _map.lock(map) ) { changed = map->sync( *this ); if ( changed ) { refreshComputedValues(); } _pool = map->getElevationPool(); } else { _layers.clear(); } for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i) { ElevationLayer* e = dynamic_cast<ElevationLayer*>(i->get()); if (e) _elevationLayers.push_back(e); } return changed; }
void MapFrame::refreshComputedValues() { _highestMinLevel = 0; _elevationLayers.clear(); for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i) { TerrainLayer* terrainLayer = dynamic_cast<TerrainLayer*>(i->get()); if (terrainLayer) { const optional<unsigned>& minLevel = terrainLayer->getTerrainLayerRuntimeOptions().minLevel(); if (minLevel.isSet() && minLevel.value() > _highestMinLevel) { _highestMinLevel = minLevel.value(); } ElevationLayer* elevation = dynamic_cast<ElevationLayer*>(terrainLayer); if (elevation) { _elevationLayers.push_back(elevation); } } } }
Config EarthFileSerializer2::serialize(const MapNode* input, const std::string& referrer) const { Config mapConf("map"); mapConf.set("version", "2"); if ( !input || !input->getMap() ) return mapConf; const Map* map = input->getMap(); MapFrame mapf( map ); // the map and node options: Config optionsConf = map->getInitialMapOptions().getConfig(); optionsConf.merge( input->getMapNodeOptions().getConfig() ); mapConf.add( "options", optionsConf ); // the layers LayerVector layers; mapf.getLayers(layers); for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i) { const Layer* layer = i->get(); Config layerConf = layer->getConfig(); if (!layerConf.empty()) { mapConf.add(layerConf); } } typedef std::vector< osg::ref_ptr<Extension> > Extensions; for(Extensions::const_iterator i = input->getExtensions().begin(); i != input->getExtensions().end(); ++i) { Extension* e = i->get(); Config conf = e->getConfigOptions().getConfig(); if ( !conf.key().empty() ) { mapConf.add( conf ); } } Config ext = input->externalConfig(); if ( !ext.empty() ) { ext.key() = "external"; mapConf.add( ext ); } // Re-write pathnames in the Config so they are relative to the new referrer. if ( _rewritePaths && !referrer.empty() ) { RewritePaths rewritePaths( referrer ); rewritePaths.setRewriteAbsolutePaths( _rewriteAbsolutePaths ); rewritePaths.apply( mapConf ); } return mapConf; }
bool MapFrame::containsLayer(UID uid) const { for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i) if (i->get()->getUID() == uid) return true; return false; }
bool MapFrame::containsEnabledLayer(UID uid) const { for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i) { if (i->get()->getUID() == uid) { return i->get()->getEnabled(); } } return false; }
void ElevationQuery::gatherTerrainModelLayers(const Map* map) { // cache a vector of terrain patch models. _terrainModelLayers.clear(); LayerVector layers; map->getLayers(layers); for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i) { if (i->get()->options().terrainPatch() == true) { _terrainModelLayers.push_back(i->get()); } } }
bool MapFrame::isCached( const TileKey& key ) const { // is there a map cache at all? osg::ref_ptr<const Map> map; if (_map.lock(map) && map->getCache() == 0L) return false; for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i) { TerrainLayer* layer = dynamic_cast<TerrainLayer*>(i->get()); if (layer) { if (!layer->getEnabled()) continue; // If we're cache only we should be fast if (layer->getCacheSettings()->cachePolicy()->isCacheOnly()) continue; // no-cache? always slow if (layer->getCacheSettings()->cachePolicy()->isCacheDisabled()) return false; // No tile source? skip it osg::ref_ptr< TileSource > source = layer->getTileSource(); if (!source.valid()) continue; //If the tile is blacklisted, it should also be fast. if (source->getBlacklist()->contains(key)) continue; //If no data is available on this tile, we'll be fast if (!source->hasData(key)) continue; if (!layer->isCached(key)) return false; } } return true; }
void MapFrame::refreshComputedValues() { // cache the min LOD based on all image/elev layers _highestMinLevel = 0; for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i) { TerrainLayer* terrainLayer = dynamic_cast<TerrainLayer*>(i->get()); if (terrainLayer) { const optional<unsigned>& minLevel = terrainLayer->getTerrainLayerRuntimeOptions().minLevel(); if (minLevel.isSet() && minLevel.value() > _highestMinLevel) { _highestMinLevel = minLevel.value(); } } } }
void TerrainCuller::apply(osg::Node& node) { // push the node's state. osg::StateSet* node_state = node.getStateSet(); TileNode* tileNode = dynamic_cast<TileNode*>(&node); if (tileNode) { _currentTileNode = tileNode; _currentTileDrawCommands = 0u; if (!_terrain.patchLayers().empty()) { // todo: check for patch/virtual const RenderBindings& bindings = _context->getRenderBindings(); TileRenderModel& renderModel = _currentTileNode->renderModel(); bool pushedMatrix = false; for (PatchLayerVector::const_iterator i = _terrain.patchLayers().begin(); i != _terrain.patchLayers().end(); ++i) { PatchLayer* layer = i->get(); if (layer->getAcceptCallback() == 0L || layer->getAcceptCallback()->acceptKey(_currentTileNode->getKey())) { // Push this tile's matrix if we haven't already done so: if (!pushedMatrix) { SurfaceNode* surface = tileNode->getSurfaceNode(); // push the surface matrix: osg::Matrix mvm = *getModelViewMatrix(); surface->computeLocalToWorldMatrix(mvm, this); pushModelViewMatrix(createOrReuseMatrix(mvm), surface->getReferenceFrame()); pushedMatrix = true; } // Add the draw command: DrawTileCommand* cmd = addDrawCommand(layer->getUID(), &renderModel, 0L, tileNode); if (cmd) { cmd->_drawPatch = true; cmd->_drawCallback = layer->getDrawCallback(); ++_currentTileDrawCommands; } } } if (pushedMatrix) { popModelViewMatrix(); } } } else { SurfaceNode* surface = dynamic_cast<SurfaceNode*>(&node); if (surface) { TileRenderModel& renderModel = _currentTileNode->renderModel(); // push the surface matrix: osg::Matrix mvm = *getModelViewMatrix(); surface->computeLocalToWorldMatrix(mvm, this); pushModelViewMatrix(createOrReuseMatrix(mvm), surface->getReferenceFrame()); // First go through any legit rendering pass data in the Tile and // and add a DrawCommand for each. for (unsigned p = 0; p < renderModel._passes.size(); ++p) { const RenderingPass& pass = renderModel._passes[p]; if (pass._layer.valid() && pass._layer->getRenderType() == Layer::RENDERTYPE_TILE) { if (addDrawCommand(pass._sourceUID, &renderModel, &pass, _currentTileNode)) { ++_currentTileDrawCommands; } } } // Next, add a DrawCommand for each tile layer not represented in the TerrainTileModel // as a rendering pass. for (LayerVector::const_iterator i = _terrain.tileLayers().begin(); i != _terrain.tileLayers().end(); ++i) { Layer* layer = i->get(); if (addDrawCommand(layer->getUID(), &renderModel, 0L, _currentTileNode)) { ++_currentTileDrawCommands; } } // If the culler added no draw commands for this tile... do something! if (_currentTileDrawCommands == 0) { //OE_INFO << LC << "Adding blank render.\n"; addDrawCommand(-1, &renderModel, 0L, _currentTileNode); } popModelViewMatrix(); _terrain._drawState->_bs.expandBy(surface->getBound()); _terrain._drawState->_box.expandBy(_terrain._drawState->_bs); } } traverse(node); }
void TerrainTileModelFactory::addColorLayers(TerrainTileModel* model, const Map* map, const TerrainEngineRequirements* reqs, const TileKey& key, const CreateTileModelFilter& filter, ProgressCallback* progress) { OE_START_TIMER(fetch_image_layers); int order = 0; LayerVector layers; map->getLayers(layers); for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i) { Layer* layer = i->get(); if (layer->getRenderType() != layer->RENDERTYPE_TERRAIN_SURFACE) continue; if (!layer->getEnabled()) continue; if (!filter.accept(layer)) continue; ImageLayer* imageLayer = dynamic_cast<ImageLayer*>(layer); if (imageLayer) { osg::Texture* tex = 0L; osg::Matrixf textureMatrix; if (imageLayer->isKeyInLegalRange(key) && imageLayer->mayHaveDataInExtent(key.getExtent())) { if (imageLayer->createTextureSupported()) { tex = imageLayer->createTexture( key, progress, textureMatrix ); } else { GeoImage geoImage = imageLayer->createImage( key, progress ); if ( geoImage.valid() ) { if ( imageLayer->isCoverage() ) tex = createCoverageTexture(geoImage.getImage(), imageLayer); else tex = createImageTexture(geoImage.getImage(), imageLayer); } } } // if this is the first LOD, and the engine requires that the first LOD // be populated, make an empty texture if we didn't get one. if (tex == 0L && _options.firstLOD() == key.getLOD() && reqs && reqs->fullDataAtFirstLodRequired()) { tex = _emptyTexture.get(); } if (tex) { tex->setName(model->getKey().str()); TerrainTileImageLayerModel* layerModel = new TerrainTileImageLayerModel(); layerModel->setImageLayer(imageLayer); layerModel->setTexture(tex); layerModel->setMatrix(new osg::RefMatrixf(textureMatrix)); model->colorLayers().push_back(layerModel); if (imageLayer->isShared()) { model->sharedLayers().push_back(layerModel); } if (imageLayer->isDynamic()) { model->setRequiresUpdateTraverse(true); } } } else // non-image kind of TILE layer: { TerrainTileColorLayerModel* colorModel = new TerrainTileColorLayerModel(); colorModel->setLayer(layer); model->colorLayers().push_back(colorModel); } } if (progress) progress->stats()["fetch_imagery_time"] += OE_STOP_TIMER(fetch_image_layers); }
void TerrainRenderData::setup(const MapFrame& frame, const RenderBindings& bindings, unsigned frameNum, osgUtil::CullVisitor* cv) { _bindings = &bindings; // Create a new State object to track sampler and uniform settings _drawState = new DrawState(); _drawState->_frame = frameNum; _drawState->_bindings = &bindings; // Make a drawable for each rendering pass (i.e. each render-able map layer). for(LayerVector::const_iterator i = frame.layers().begin(); i != frame.layers().end(); ++i) { Layer* layer = i->get(); if (layer->getEnabled()) { if (layer->getRenderType() == Layer::RENDERTYPE_TILE || layer->getRenderType() == Layer::RENDERTYPE_PATCH) { bool render = true; // If this is an image layer, check the enabled/visible states. VisibleLayer* visLayer = dynamic_cast<VisibleLayer*>(layer); if (visLayer) { render = visLayer->getVisible(); } if (render) { ImageLayer* imgLayer = dynamic_cast<ImageLayer*>(layer); // Make a list of "global" layers. There are layers whose data is not // represented in the TerrainTileModel, like a splatting layer or a patch // layer. The data for these is dynamic and not based on data fetched. if (imgLayer == 0L && layer->getRenderType() == Layer::RENDERTYPE_TILE) { tileLayers().push_back(layer); addLayerDrawable(layer); } else if (layer->getRenderType() == Layer::RENDERTYPE_PATCH) { PatchLayer* patchLayer = static_cast<PatchLayer*>(layer); // asumption! if (patchLayer->getAcceptCallback() != 0L && patchLayer->getAcceptCallback()->acceptLayer(*cv, cv->getCurrentCamera())) { patchLayers().push_back(dynamic_cast<PatchLayer*>(layer)); addLayerDrawable(layer); } } else { addLayerDrawable(layer); } } } } } // Include a "blank" layer for missing data. LayerDrawable* blank = addLayerDrawable(0L); blank->getOrCreateStateSet()->setDefine("OE_TERRAIN_RENDER_IMAGERY", osg::StateAttribute::OFF); }
void TerrainRenderData::setup(const Map* map, const RenderBindings& bindings, unsigned frameNum, osgUtil::CullVisitor* cv) { _bindings = &bindings; // Create a new State object to track sampler and uniform settings _drawState = new DrawState(); _drawState->_frame = frameNum; _drawState->_bindings = &bindings; // Is this a depth camera? Because if it is, we don't need any color layers. const osg::Camera* cam = cv->getCurrentCamera(); bool isDepthCamera = ClampableNode::isDepthCamera(cam); // Make a drawable for each rendering pass (i.e. each render-able map layer). LayerVector layers; map->getLayers(layers); for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i) { Layer* layer = i->get(); if (layer->getEnabled()) { bool render = (layer->getRenderType() == Layer::RENDERTYPE_TERRAIN_SURFACE) || // && !isDepthCamera) || (layer->getRenderType() == Layer::RENDERTYPE_TERRAIN_PATCH); if ( render ) { // If this is an image layer, check the enabled/visible states. VisibleLayer* visLayer = dynamic_cast<VisibleLayer*>(layer); if (visLayer) { render = visLayer->getVisible(); } if (render) { if (layer->getRenderType() == Layer::RENDERTYPE_TERRAIN_SURFACE) { LayerDrawable* ld = addLayerDrawable(layer); // If the current camera is depth-only, leave this layer in the set // but mark it as no-draw. We keep it in the set so the culler doesn't // inadvertently think it's an orphaned layer. if (isDepthCamera) { ld->_draw = false; } } else // if (layer->getRenderType() == Layer::RENDERTYPE_TERRAIN_PATCH) { PatchLayer* patchLayer = static_cast<PatchLayer*>(layer); // asumption! if (patchLayer->getAcceptCallback() != 0L && patchLayer->getAcceptCallback()->acceptLayer(*cv, cv->getCurrentCamera())) { patchLayers().push_back(dynamic_cast<PatchLayer*>(layer)); addLayerDrawable(layer); } } } } } } // Include a "blank" layer for missing data. LayerDrawable* blank = addLayerDrawable(0L); }