[osg-users] Problem with highlight

Jeff Cote Jean-Francois.Cote at drdc-rddc.gc.ca
Wed Nov 18 11:32:51 PST 2009


Hi,

I have a terrain with some roads on it. I want to specify a route by selecting some roads one after another. So, what I want to do is: select road1, highlight it, select road2, highlight it ... . For now, only the last selected road will stay highlight and the other one just return to "normal". 
Is there a way to do this ? I'm using osgSim::OverlayNode.

Thx !
Jeff


Code:

void Road::Highlight(osgGIS::FeatureCursor& cursor)
{
	//A FilterGraph is a sequence of discrete data-processing units called Filters
	osgGIS::FilterGraph* graph = new osgGIS::FilterGraph();

	//Changes the shape type of incoming features
    osgGIS::ChangeShapeTypeFilter* change = new osgGIS::ChangeShapeTypeFilter();
	//Sets the shape type to which to change all feature shapes, in this case POLYGON
    change->setNewShapeType(osgGIS::GeoShape::TYPE_POLYGON);
	//Appends a filter to the end of the graph's filter chain
    graph->appendFilter(change);

	//Creates a polygon representing a region containing all points within a certain distance of all points on the source feature
	osgGIS::BufferFilter* buffer = new osgGIS::BufferFilter(20); //meters
	graph->appendFilter(buffer);
    
	//Transforms feature data by way of spatial reference reprojection and/or matrix transformation
    osgGIS::TransformFilter* xform = new osgGIS::TransformFilter();
	//Sets the spatial reference system into which to reproject feature geodata
    xform->setSRS(mTerrain_srs.get());
	//Sets whether to localize the feature geodata by transforming it so it is relative to the centroid of the graph's working extent 
    xform->setLocalize(true);
    graph->appendFilter(xform);

	//Assembles feature data into basic fragments (i.e. attributed drawables). It create basic OSG geometry from GIS feature data
    osgGIS::BuildGeomFilter* geom = new osgGIS::BuildGeomFilter();
	//Sets the script that evalutes to the color to apply to the geometry
	geom->setColorScript(new osgGIS::Script("vec4(1,1,1,1)"));
    graph->appendFilter(geom);

    graph->appendFilter(new osgGIS::CollectionFilter());

	//Assembles Fragment instances into osg::Node instances
    osgGIS::BuildNodesFilter* nodes = new osgGIS::BuildNodesFilter();
	//Sets whether to disable GL lighting on the resulting node graphs
    nodes->setDisableLighting(true);
    graph->appendFilter(nodes);

	//Compiles all or part of a FeatureLayer into an OSG scene graph
	osgGIS::SimpleLayerCompiler compiler(graph);
	osg::Node* result = compiler.compile(mLayer.get(), cursor);

	//Set the overlay subgraph which will be rendered to texture
	mOverlay->setOverlaySubgraph(result);
	mOverlay->
	//Inform the OverlayNode that the overlay texture needs to be updated
	mOverlay->dirtyOverlayTexture();
}


[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=19839#19839







More information about the osg-users mailing list