本文整理汇总了C++中ControlCanvas类的典型用法代码示例。如果您正苦于以下问题:C++ ControlCanvas类的具体用法?C++ ControlCanvas怎么用?C++ ControlCanvas使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ControlCanvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupOverlayView
void
setupOverlayView( osgViewer::View* view, osg::Group* parent, MapNode* mapNode )
{
ControlCanvas* canvas = ControlCanvas::getOrCreate(view);
VBox* v = canvas->addControl(new VBox());
v->setBackColor( Color(Color::Black,0.75) );
{
HBox* camBox = v->addControl(new HBox());
{
camBox->addControl(s_cameraCheck = new CheckBoxControl(true, new Toggle(parent,"camera")));
camBox->addControl(new LabelControl("Camera", Color("#00ff00")));
}
//HBox* overlayBox = v->addControl(new HBox());
//{
// overlayBox->addControl(s_overlayCheck = new CheckBoxControl(false, new Toggle(parent,"overlay")));
// overlayBox->addControl(new LabelControl("Overlay", Color("#00ffff")));
//}
HBox* isectBox = v->addControl(new HBox());
{
isectBox->addControl(s_intersectionCheck = new CheckBoxControl(true, new Toggle(parent,"intersection")));
isectBox->addControl(new LabelControl("Intersection",Color("#ff7f00")));
}
HBox* rttBox = v->addControl(new HBox());
{
rttBox->addControl(s_rttCheck = new CheckBoxControl(true, new Toggle(parent,"rtt")));
rttBox->addControl(new LabelControl("RTT", Color("#ffff00")));
}
}
view->addEventHandler( new PHDumper(mapNode, parent) );
}
示例2: createControlPanel
Container*
createControlPanel(osgViewer::View* view)
{
ControlCanvas* canvas = ControlCanvas::getOrCreate(view);
VBox* vbox = canvas->addControl(new VBox());
vbox->setChildSpacing(10);
return vbox;
}
示例3: main
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
s_mapNode = MapNode::load(arguments);
if ( !s_mapNode )
{
OE_WARN << "Unable to load earth file." << std::endl;
return -1;
}
osg::Group* root = new osg::Group();
viewer.setSceneData( root );
// install the programmable manipulator.
viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() );
// The MapNode will render the Map object in the scene graph.
root->addChild( s_mapNode );
// Make the readout:
Grid* grid = new Grid();
grid->setControl(0,0,new LabelControl("Coords (Lat, Long):"));
grid->setControl(0,1,new LabelControl("Vertical Datum:"));
grid->setControl(0,2,new LabelControl("Height (MSL):"));
grid->setControl(0,3,new LabelControl("Height (HAE):"));
grid->setControl(0,4,new LabelControl("Isect (HAE):"));
grid->setControl(0,5,new LabelControl("Resolution:"));
s_posLabel = grid->setControl(1,0,new LabelControl(""));
s_vdaLabel = grid->setControl(1,1,new LabelControl(""));
s_mslLabel = grid->setControl(1,2,new LabelControl(""));
s_haeLabel = grid->setControl(1,3,new LabelControl(""));
s_mapLabel = grid->setControl(1,4,new LabelControl(""));
s_resLabel = grid->setControl(1,5,new LabelControl(""));
const SpatialReference* mapSRS = s_mapNode->getMapSRS();
s_vdaLabel->setText( mapSRS->getVerticalDatum() ?
mapSRS->getVerticalDatum()->getName() :
Stringify() << "geodetic (" << mapSRS->getEllipsoid()->getName() << ")" );
ControlCanvas* canvas = new ControlCanvas();
root->addChild(canvas);
canvas->addControl( grid );
// An event handler that will respond to mouse clicks:
viewer.addEventHandler( new QueryElevationHandler() );
// add some stock OSG handlers:
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
return viewer.run();
}
示例4: createControlPanel
void
createControlPanel( osgViewer::View* view )
{
ControlCanvas* canvas = ControlCanvas::getOrCreate( view );
s_masterGrid = new Grid();
s_masterGrid->setBackColor(0,0,0,0.5);
s_masterGrid->setMargin( 10 );
s_masterGrid->setPadding( 10 );
s_masterGrid->setChildSpacing( 10 );
s_masterGrid->setChildVertAlign( Control::ALIGN_CENTER );
s_masterGrid->setAbsorbEvents( true );
s_masterGrid->setVertAlign( Control::ALIGN_TOP );
//The image layers
s_imageBox = new Grid();
s_imageBox->setBackColor(0,0,0,0.5);
s_imageBox->setMargin( 10 );
s_imageBox->setPadding( 10 );
s_imageBox->setChildSpacing( 10 );
s_imageBox->setChildVertAlign( Control::ALIGN_CENTER );
s_imageBox->setAbsorbEvents( true );
s_imageBox->setVertAlign( Control::ALIGN_TOP );
s_masterGrid->setControl( 0, 0, s_imageBox );
//the elevation layers
s_elevationBox = new Grid();
s_elevationBox->setBackColor(0,0,0,0.5);
s_elevationBox->setMargin( 10 );
s_elevationBox->setPadding( 10 );
s_elevationBox->setChildSpacing( 10 );
s_elevationBox->setChildVertAlign( Control::ALIGN_CENTER );
s_elevationBox->setAbsorbEvents( true );
s_elevationBox->setVertAlign( Control::ALIGN_TOP );
s_masterGrid->setControl( 1, 0, s_elevationBox );
//The image layers
s_modelBox = new Grid();
s_modelBox->setBackColor(0,0,0,0.5);
s_modelBox->setMargin( 10 );
s_modelBox->setPadding( 10 );
s_modelBox->setChildSpacing( 10 );
s_modelBox->setChildVertAlign( Control::ALIGN_CENTER );
s_modelBox->setAbsorbEvents( true );
s_modelBox->setVertAlign( Control::ALIGN_TOP );
s_masterGrid->setControl( 2, 0, s_modelBox );
canvas->addControl( s_masterGrid );
}
示例5: createControlPanel
osg::Node*
createControlPanel( osgViewer::View* view )
{
ControlCanvas* canvas = ControlCanvas::get( view );
// the outer container:
s_layerBox = new Grid();
s_layerBox->setBackColor(0,0,0,0.5);
s_layerBox->setMargin( 10 );
s_layerBox->setPadding( 10 );
s_layerBox->setChildSpacing( 10 );
s_layerBox->setChildVertAlign( Control::ALIGN_CENTER );
s_layerBox->setAbsorbEvents( true );
s_layerBox->setVertAlign( Control::ALIGN_BOTTOM );
canvas->addControl( s_layerBox );
return canvas;
}
示例6: createControlPanel
void
createControlPanel( osgViewer::View* view )
{
ControlCanvas* canvas = ControlCanvas::getOrCreate( view );
s_masterGrid = new Grid();
s_masterGrid->setMargin( 5 );
s_masterGrid->setPadding( 5 );
s_masterGrid->setChildSpacing( 10 );
s_masterGrid->setChildVertAlign( Control::ALIGN_CENTER );
s_masterGrid->setAbsorbEvents( true );
s_masterGrid->setVertAlign( Control::ALIGN_TOP );
//The Map layers
s_activeBox = new Grid();
s_activeBox->setBackColor(0,0,0,0.5);
s_activeBox->setMargin( 10 );
s_activeBox->setPadding( 10 );
s_activeBox->setChildSpacing( 10 );
s_activeBox->setChildVertAlign( Control::ALIGN_CENTER );
s_activeBox->setAbsorbEvents( true );
s_activeBox->setVertAlign( Control::ALIGN_TOP );
s_masterGrid->setControl( 0, 0, s_activeBox );
//the removed layers
s_inactiveBox = new Grid();
s_inactiveBox->setBackColor(0,0,0,0.5);
s_inactiveBox->setMargin( 10 );
s_inactiveBox->setPadding( 10 );
s_inactiveBox->setChildSpacing( 10 );
s_inactiveBox->setChildVertAlign( Control::ALIGN_CENTER );
s_inactiveBox->setAbsorbEvents( true );
s_inactiveBox->setVertAlign( Control::ALIGN_TOP );
s_masterGrid->setControl( 0, 1, s_inactiveBox );
canvas->addControl( s_masterGrid );
}
示例7: main
//
// NOTE: run this sample from the repo/tests directory.
//
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
s_viewer = &viewer;
// Start by creating the map:
s_mapNode = MapNode::load(arguments);
if ( !s_mapNode )
{
Map* map = new Map();
// Start with a basemap imagery layer; we'll be using the GDAL driver
// to load a local GeoTIFF file:
GDALOptions basemapOpt;
basemapOpt.url() = "../data/world.tif";
map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) );
// That's it, the map is ready; now create a MapNode to render the Map:
MapNodeOptions mapNodeOptions;
mapNodeOptions.enableLighting() = false;
s_mapNode = new MapNode( map, mapNodeOptions );
}
s_mapNode->setNodeMask( 0x01 );
// Define a style for the feature data.
Style style = buildStyle( Color::Yellow, 2.0f );
//LineString* line = new LineString();
Geometry* geom = GeometryUtils::geometryFromWKT("POLYGON((191.026667 87.63333,114.75 78,89.5 77.333336,81.833336 75.333336,70.683334 74.5,70.916664 73.666664,68.666664 73.666664,66.291664 71.505,57.65 71.166664,58 73.9,48.616665 73,49.198334 71.43,49.5 70.5,43.266666 68.666664,32.083332 71.5,32.083332 74,35 74,35 81,32 81,32 90,191.026667 87.63333))");
OE_NOTICE << "Geometry " << GeometryUtils::geometryToWKT(geom) << std::endl;
Feature* feature = new Feature(geom, s_mapNode->getMapSRS(), Style(), s_fid++);
s_featureNode = new FeatureNode( s_mapNode, feature );
s_featureNode->setStyle( style );
s_editorsRoot = new osg::Group;
s_root = new osg::Group;
s_root->addChild( s_mapNode.get() );
s_root->addChild( s_featureNode.get() );
s_root->addChild( s_editorsRoot.get() );
//Setup the controls
ControlCanvas* canvas = ControlCanvas::getOrCreate( &viewer );
s_root->addChild( canvas );
Grid *toolbar = createToolBar( );
canvas->addControl( toolbar );
canvas->setNodeMask( 0x1 << 1 );
int col = 0;
LabelControl* addVerts = new LabelControl("Add Verts");
toolbar->setControl(col++, 0, addVerts );
addVerts->addEventHandler( new AddVertsModeHandler());
LabelControl* edit = new LabelControl("Edit");
toolbar->setControl(col++, 0, edit );
edit->addEventHandler(new EditModeHandler());
unsigned int row = 0;
Grid *styleBar = createToolBar( );
styleBar->setPosition(0, 50);
canvas->addControl( styleBar );
//Make a list of styles
styleBar->setControl(0, row++, new LabelControl("Styles") );
unsigned int numStyles = 8;
for (unsigned int i = 0; i < numStyles; ++i)
{
float w = 50;
osg::Vec4 color = randomColor();
float widths[3] = {2, 4, 8};
unsigned int r = row++;
for (unsigned int j = 0; j < 3; j++)
{
Control* l = new Control();
l->setBackColor( color );
l->addEventHandler(new ChangeStyleHandler(buildStyle( color, widths[j] ) ));
l->setSize(w,5 * widths[j]);
styleBar->setControl(j, r, l);
}
}
viewer.setSceneData( s_root.get() );
viewer.setCameraManipulator( new EarthManipulator() );
if ( s_mapNode )
viewer.getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(s_mapNode) );
// add some stock OSG handlers:
//.........这里部分代码省略.........
示例8: VBox
void
MapNodeHelper::parse(MapNode* mapNode,
osg::ArgumentParser& args,
osgViewer::View* view,
osg::Group* root,
Control* userControl ) const
{
// this is a dubious move.
if ( !root )
root = mapNode;
// options to use for the load
osg::ref_ptr<osgDB::Options> dbOptions = Registry::instance()->cloneOrCreateOptions();
// parse out custom example arguments first:
bool useSky = args.read("--sky");
bool useOcean = args.read("--ocean");
bool useMGRS = args.read("--mgrs");
bool useDMS = args.read("--dms");
bool useDD = args.read("--dd");
bool useCoords = args.read("--coords") || useMGRS || useDMS || useDD;
bool useOrtho = args.read("--ortho");
bool useAutoClip = args.read("--autoclip");
float ambientBrightness = 0.2f;
args.read("--ambientBrightness", ambientBrightness);
std::string kmlFile;
args.read( "--kml", kmlFile );
std::string imageFolder;
args.read( "--images", imageFolder );
std::string imageExtensions;
args.read("--image-extensions", imageExtensions);
// install a canvas for any UI controls we plan to create:
ControlCanvas* canvas = ControlCanvas::get(view, false);
Container* mainContainer = canvas->addControl( new VBox() );
mainContainer->setAbsorbEvents( true );
mainContainer->setBackColor( Color(Color::Black, 0.8) );
mainContainer->setHorizAlign( Control::ALIGN_LEFT );
mainContainer->setVertAlign( Control::ALIGN_BOTTOM );
// install the user control:
if ( userControl )
mainContainer->addControl( userControl );
// look for external data in the map node:
const Config& externals = mapNode->externalConfig();
const Config& skyConf = externals.child("sky");
const Config& oceanConf = externals.child("ocean");
const Config& annoConf = externals.child("annotations");
const Config& declutterConf = externals.child("decluttering");
Config viewpointsConf = externals.child("viewpoints");
// some terrain effects.
const Config& normalMapConf = externals.child("normal_map");
const Config& detailTexConf = externals.child("detail_texture");
const Config& lodBlendingConf = externals.child("lod_blending");
const Config& vertScaleConf = externals.child("vertical_scale");
const Config& contourMapConf = externals.child("contour_map");
// backwards-compatibility: read viewpoints at the top level:
const ConfigSet& old_viewpoints = externals.children("viewpoint");
for( ConfigSet::const_iterator i = old_viewpoints.begin(); i != old_viewpoints.end(); ++i )
viewpointsConf.add( *i );
// Loading a viewpoint list from the earth file:
if ( !viewpointsConf.empty() )
{
std::vector<Viewpoint> viewpoints;
const ConfigSet& children = viewpointsConf.children();
if ( children.size() > 0 )
{
for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i )
{
viewpoints.push_back( Viewpoint(*i) );
}
}
if ( viewpoints.size() > 0 )
{
Control* c = ViewpointControlFactory().create(viewpoints, view);
if ( c )
mainContainer->addControl( c );
}
}
// Adding a sky model:
if ( useSky || !skyConf.empty() )
{
double hours = skyConf.value( "hours", 12.0 );
SkyNode* sky = new SkyNode( mapNode->getMap() );
sky->setAmbientBrightness( ambientBrightness );
sky->setDateTime( DateTime(2011, 3, 6, hours) );
sky->attach( view );
//.........这里部分代码省略.........
示例9: if
void
MapNodeHelper::parse(MapNode* mapNode,
osg::ArgumentParser& args,
osgViewer::View* view,
osg::Group* root,
Container* userContainer ) const
{
if ( !root )
root = mapNode;
// options to use for the load
osg::ref_ptr<osgDB::Options> dbOptions = Registry::instance()->cloneOrCreateOptions();
// parse out custom example arguments first:
bool useMGRS = args.read("--mgrs");
bool useDMS = args.read("--dms");
bool useDD = args.read("--dd");
bool useCoords = args.read("--coords") || useMGRS || useDMS || useDD;
bool useAutoClip = args.read("--autoclip");
bool animateSky = args.read("--animate-sky");
bool showActivity = args.read("--activity");
bool useLogDepth = args.read("--logdepth");
bool useLogDepth2 = args.read("--logdepth2");
bool kmlUI = args.read("--kmlui");
if (args.read("--verbose"))
osgEarth::setNotifyLevel(osg::INFO);
if (args.read("--quiet"))
osgEarth::setNotifyLevel(osg::FATAL);
float ambientBrightness = 0.2f;
args.read("--ambientBrightness", ambientBrightness);
std::string kmlFile;
args.read( "--kml", kmlFile );
std::string imageFolder;
args.read( "--images", imageFolder );
std::string imageExtensions;
args.read("--image-extensions", imageExtensions);
// animation path:
std::string animpath;
if ( args.read("--path", animpath) )
{
view->setCameraManipulator( new osgGA::AnimationPathManipulator(animpath) );
}
// Install a new Canvas for our UI controls, or use one that already exists.
ControlCanvas* canvas = ControlCanvas::getOrCreate( view );
Container* mainContainer;
if ( userContainer )
{
mainContainer = userContainer;
}
else
{
mainContainer = new VBox();
mainContainer->setAbsorbEvents( true );
mainContainer->setBackColor( Color(Color::Black, 0.8) );
mainContainer->setHorizAlign( Control::ALIGN_LEFT );
mainContainer->setVertAlign( Control::ALIGN_BOTTOM );
}
canvas->addControl( mainContainer );
// Add an event handler to toggle the canvas with a key press;
view->addEventHandler(new ToggleCanvasEventHandler(canvas) );
// look for external data in the map node:
const Config& externals = mapNode->externalConfig();
//const Config& screenSpaceLayoutConf =
// externals.hasChild("screen_space_layout") ? externals.child("screen_space_layout") :
// externals.child("decluttering"); // backwards-compatibility
// some terrain effects.
// TODO: Most of these are likely to move into extensions.
const Config& lodBlendingConf = externals.child("lod_blending");
const Config& vertScaleConf = externals.child("vertical_scale");
// Shadowing.
if (args.read("--shadows"))
{
int unit;
if ( mapNode->getTerrainEngine()->getResources()->reserveTextureImageUnit(unit, "ShadowCaster") )
{
ShadowCaster* caster = new ShadowCaster();
caster->setTextureImageUnit( unit );
caster->setLight( view->getLight() );
caster->getShadowCastingGroup()->addChild( mapNode );
if ( mapNode->getNumParents() > 0 )
{
//.........这里部分代码省略.........
示例10: main
int
main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 );
osgViewer::Viewer viewer(arguments);
// load the .earth file from the command line.
osg::Node* earthNode = MapNodeHelper().load( arguments, &viewer );
if (!earthNode)
{
OE_NOTICE << "Unable to load earth model." << std::endl;
return 1;
}
MapNode* mapNode = MapNode::findMapNode( earthNode );
if ( !mapNode )
{
OE_NOTICE << "Input file was not a .earth file" << std::endl;
return 1;
}
earthNode->setNodeMask( 0x1 );
osgEarth::Util::EarthManipulator* earthManip = new EarthManipulator();
viewer.setCameraManipulator( earthManip );
osg::Group* root = new osg::Group();
root->addChild( earthNode );
//Create the MeasureToolHandler
MeasureToolHandler* measureTool = new MeasureToolHandler(root, mapNode);
measureTool->setIntersectionMask( 0x1 );
viewer.addEventHandler( measureTool );
//Create some controls to interact with the measuretool
ControlCanvas* canvas = new ControlCanvas( &viewer );
root->addChild( canvas );
canvas->setNodeMask( 0x1 << 1 );
Grid* grid = new Grid();
grid->setBackColor(0,0,0,0.5);
grid->setMargin( 10 );
grid->setPadding( 10 );
grid->setChildSpacing( 10 );
grid->setChildVertAlign( Control::ALIGN_CENTER );
grid->setAbsorbEvents( true );
grid->setVertAlign( Control::ALIGN_BOTTOM );
canvas->addControl( grid );
//Add a label to display the distance
// Add a text label:
grid->setControl( 0, 0, new LabelControl("Distance:") );
LabelControl* label = new LabelControl();
label->setFont( osgEarth::Registry::instance()->getDefaultFont() );
label->setFontSize( 24.0f );
label->setHorizAlign( Control::ALIGN_LEFT );
label->setText("click to measure");
grid->setControl( 1, 0, label );
//Add a callback to update the label when the distance changes
measureTool->addEventHandler( new MyMeasureToolCallback(label) );
Style style = measureTool->getLineStyle();
style.getOrCreate<LineSymbol>()->stroke()->color() = Color::Red;
style.getOrCreate<LineSymbol>()->stroke()->width() = 4.0f;
measureTool->setLineStyle(style);
//Add a checkbox to control if we are doing path based measurement or just point to point
grid->setControl( 0, 1, new LabelControl("Path"));
CheckBoxControl* checkBox = new CheckBoxControl(false);
checkBox->setHorizAlign(Control::ALIGN_LEFT);
checkBox->addEventHandler( new TogglePathHandler(measureTool));
grid->setControl( 1, 1, checkBox);
//Add a toggle to set the mode of the measuring tool
grid->setControl( 0, 2, new LabelControl("Great Circle"));
CheckBoxControl* mode = new CheckBoxControl(true);
mode->setHorizAlign(Control::ALIGN_LEFT);
mode->addEventHandler( new ToggleModeHandler(measureTool));
grid->setControl( 1, 2, mode);
//Add a mouse coords readout:
LabelControl* mouseLabel = new LabelControl();
grid->setControl( 0, 3, new LabelControl("Mouse:"));
grid->setControl( 1, 3, mouseLabel );
viewer.addEventHandler(new MouseCoordsTool(mapNode, mouseLabel) );
viewer.setSceneData( root );
// add some stock OSG handlers:
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgViewer::ThreadingHandler());
viewer.addEventHandler(new osgViewer::LODScaleHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
//.........这里部分代码省略.........
示例11: VBox
void
MapNodeHelper::parse(MapNode* mapNode,
osg::ArgumentParser& args,
osgViewer::View* view,
osg::Group* root,
Control* userControl ) const
{
if ( !root )
root = mapNode;
// parse out custom example arguments first:
bool useSky = args.read("--sky");
bool useOcean = args.read("--ocean");
bool useMGRS = args.read("--mgrs");
bool useDMS = args.read("--dms");
bool useDD = args.read("--dd");
bool useCoords = args.read("--coords") || useMGRS || useDMS || useDD;
std::string kmlFile;
args.read( "--kml", kmlFile );
// install a canvas for any UI controls we plan to create:
ControlCanvas* canvas = ControlCanvas::get(view, false);
Container* mainContainer = canvas->addControl( new VBox() );
mainContainer->setBackColor( Color(Color::Black, 0.8) );
mainContainer->setHorizAlign( Control::ALIGN_LEFT );
mainContainer->setVertAlign( Control::ALIGN_BOTTOM );
// install the user control:
if ( userControl )
mainContainer->addControl( userControl );
// look for external data in the map node:
const Config& externals = mapNode->externalConfig();
const Config& skyConf = externals.child("sky");
const Config& oceanConf = externals.child("ocean");
const Config& annoConf = externals.child("annotations");
const Config& declutterConf = externals.child("decluttering");
Config viewpointsConf = externals.child("viewpoints");
// backwards-compatibility: read viewpoints at the top level:
const ConfigSet& old_viewpoints = externals.children("viewpoint");
for( ConfigSet::const_iterator i = old_viewpoints.begin(); i != old_viewpoints.end(); ++i )
viewpointsConf.add( *i );
// Loading a viewpoint list from the earth file:
if ( !viewpointsConf.empty() )
{
std::vector<Viewpoint> viewpoints;
const ConfigSet& children = viewpointsConf.children();
if ( children.size() > 0 )
{
for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i )
{
viewpoints.push_back( Viewpoint(*i) );
}
}
if ( viewpoints.size() > 0 )
{
Control* c = ViewpointControlFactory().create(viewpoints, view);
if ( c )
mainContainer->addControl( c );
}
}
// Adding a sky model:
if ( useSky || !skyConf.empty() )
{
double hours = skyConf.value( "hours", 12.0 );
SkyNode* sky = new SkyNode( mapNode->getMap() );
sky->setDateTime( 2011, 3, 6, hours );
sky->attach( view );
root->addChild( sky );
Control* c = SkyControlFactory().create(sky, view);
if ( c )
mainContainer->addControl( c );
}
// Adding an ocean model:
if ( useOcean || !oceanConf.empty() )
{
OceanSurfaceNode* ocean = new OceanSurfaceNode( mapNode, oceanConf );
if ( ocean )
{
root->addChild( ocean );
Control* c = OceanControlFactory().create(ocean, view);
if ( c )
mainContainer->addControl(c);
}
}
// Loading KML from the command line:
if ( !kmlFile.empty() )
{
//.........这里部分代码省略.........
示例12: main
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
bool test1 = arguments.read("--test1");
bool test2 = arguments.read("--test2");
bool test3 = arguments.read("--test3");
bool test4 = arguments.read("--test4");
bool test5 = arguments.read("--test5");
bool ok = test1 || test2 || test3 || test4 || test5;
if ( !ok )
{
return usage("");
}
osg::Group* root = new osg::Group();
viewer.setSceneData( root );
// add a canvas:
ControlCanvas* canvas = new ControlCanvas();
root->addChild( canvas );
// and a label:
LabelControl* label = new LabelControl();
canvas->addControl(label);
if ( !test5 )
{
osg::Node* earthNode = osgDB::readNodeFile( "http://osgearth.org/demo.earth" );
if (!earthNode)
{
return usage( "Unable to load earth model." );
}
if ( test1 )
{
root->addChild( TEST_1::run(earthNode) );
label->setText( "Function injection test: the map appears hazy at high altitude." );
}
else if ( test2 )
{
root->addChild( TEST_2::run(earthNode) );
label->setText( "Accept callback test: the map turns red when viewport width > 1000" );
}
else if ( test3 )
{
root->addChild( TEST_3::run(earthNode) );
label->setText( "Shader LOD test: the map turns red between 500K and 1M meters altitude" );
}
else if ( test4 )
{
root->addChild( TEST_4::run(earthNode) );
label->setText("Memory management test; monitor memory for stability");
}
viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() );
}
else // if ( test5 )
{
root->addChild( TEST_5::run() );
label->setText( "Leakage test: red tri on the left, blue on the right." );
}
// add some stock OSG handlers:
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgViewer::ThreadingHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
return viewer.run();
}
示例13: VBox
void
MapNodeHelper::parse(MapNode* mapNode,
osg::ArgumentParser& args,
osgViewer::View* view,
osg::Group* root,
Control* userControl ) const
{
// this is a dubious move.
if ( !root )
root = mapNode;
// options to use for the load
osg::ref_ptr<osgDB::Options> dbOptions = Registry::instance()->cloneOrCreateOptions();
// parse out custom example arguments first:
bool useSky = args.read("--sky");
bool useOcean = args.read("--ocean");
bool useMGRS = args.read("--mgrs");
bool useDMS = args.read("--dms");
bool useDD = args.read("--dd");
bool useCoords = args.read("--coords") || useMGRS || useDMS || useDD;
bool useOrtho = args.read("--ortho");
bool useAutoClip = args.read("--autoclip");
float ambientBrightness = 0.4f;
args.read("--ambientBrightness", ambientBrightness);
std::string kmlFile;
args.read( "--kml", kmlFile );
// install a canvas for any UI controls we plan to create:
ControlCanvas* canvas = ControlCanvas::get(view, false);
Container* mainContainer = canvas->addControl( new VBox() );
mainContainer->setBackColor( Color(Color::Black, 0.8) );
mainContainer->setHorizAlign( Control::ALIGN_LEFT );
mainContainer->setVertAlign( Control::ALIGN_BOTTOM );
// install the user control:
if ( userControl )
mainContainer->addControl( userControl );
// look for external data in the map node:
const Config& externals = mapNode->externalConfig();
const Config& skyConf = externals.child("sky");
const Config& oceanConf = externals.child("ocean");
const Config& annoConf = externals.child("annotations");
const Config& declutterConf = externals.child("decluttering");
Config viewpointsConf = externals.child("viewpoints");
// backwards-compatibility: read viewpoints at the top level:
const ConfigSet& old_viewpoints = externals.children("viewpoint");
for( ConfigSet::const_iterator i = old_viewpoints.begin(); i != old_viewpoints.end(); ++i )
viewpointsConf.add( *i );
// Loading a viewpoint list from the earth file:
if ( !viewpointsConf.empty() )
{
std::vector<Viewpoint> viewpoints;
const ConfigSet& children = viewpointsConf.children();
if ( children.size() > 0 )
{
for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i )
{
viewpoints.push_back( Viewpoint(*i) );
}
}
if ( viewpoints.size() > 0 )
{
Control* c = ViewpointControlFactory().create(viewpoints, view);
if ( c )
mainContainer->addControl( c );
}
}
// Adding a sky model:
if ( useSky || !skyConf.empty() )
{
double hours = skyConf.value( "hours", 12.0 );
SkyNode* sky = new SkyNode( mapNode->getMap() );
sky->setAmbientBrightness( ambientBrightness );
sky->setDateTime( 2011, 3, 6, hours );
sky->attach( view );
root->addChild( sky );
Control* c = SkyControlFactory().create(sky, view);
if ( c )
mainContainer->addControl( c );
}
// Adding an ocean model:
if ( useOcean || !oceanConf.empty() )
{
OceanSurfaceNode* ocean = new OceanSurfaceNode( mapNode, oceanConf );
if ( ocean )
{
root->addChild( ocean );
//.........这里部分代码省略.........
示例14: createControls
/** creates some UI controls for adjusting the decluttering parameters. */
void
createControls( osgViewer::View* view )
{
ControlCanvas* canvas = ControlCanvas::getOrCreate(view);
// title bar
VBox* vbox = canvas->addControl(new VBox(Control::ALIGN_NONE, Control::ALIGN_BOTTOM, 2, 1 ));
vbox->setBackColor( Color(Color::Black, 0.5) );
vbox->addControl( new LabelControl("osgEarth Tracks Demo", Color::Yellow) );
// checkbox that toggles decluttering of tracks
struct ToggleDecluttering : public ControlEventHandler {
void onValueChanged( Control* c, bool on ) {
Decluttering::setEnabled( on );
}
};
HBox* dcToggle = vbox->addControl( new HBox() );
dcToggle->addControl( new CheckBoxControl(true, new ToggleDecluttering()) );
dcToggle->addControl( new LabelControl("Declutter") );
// checkbox that toggles the coordinate display
struct ToggleCoords : public ControlEventHandler {
void onValueChanged( Control* c, bool on ) {
g_showCoords = on;
}
};
HBox* coordsToggle = vbox->addControl( new HBox() );
coordsToggle->addControl( new CheckBoxControl(true, new ToggleCoords()) );
coordsToggle->addControl( new LabelControl("Show locations") );
// grid for the slider controls so they look nice
Grid* grid = vbox->addControl( new Grid() );
grid->setHorizFill( true );
grid->setChildHorizAlign( Control::ALIGN_LEFT );
grid->setChildSpacing( 6 );
unsigned r=0;
// event handler for changing decluttering options
struct ChangeFloatOption : public ControlEventHandler {
optional<float>& _param;
LabelControl* _label;
ChangeFloatOption( optional<float>& param, LabelControl* label ) : _param(param), _label(label) { }
void onValueChanged( Control* c, float value ) {
_param = value;
_label->setText( Stringify() << std::fixed << std::setprecision(1) << value );
Decluttering::setOptions( g_dcOptions );
}
};
grid->setControl( 0, r, new LabelControl("Sim loop duration:") );
LabelControl* speedLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_duration) );
HSliderControl* speedSlider = grid->setControl( 1, r, new HSliderControl(
600.0, 30.0, *g_duration, new ChangeFloatOption(g_duration, speedLabel) ) );
speedSlider->setHorizFill( true, 200 );
grid->setControl( 0, ++r, new LabelControl("Min scale:") );
LabelControl* minAnimationScaleLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.minAnimationScale()) );
grid->setControl( 1, r, new HSliderControl(
0.0, 1.0, *g_dcOptions.minAnimationScale(), new ChangeFloatOption(g_dcOptions.minAnimationScale(), minAnimationScaleLabel) ) );
grid->setControl( 0, ++r, new LabelControl("Min alpha:") );
LabelControl* alphaLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.minAnimationAlpha()) );
grid->setControl( 1, r, new HSliderControl(
0.0, 1.0, *g_dcOptions.minAnimationAlpha(), new ChangeFloatOption(g_dcOptions.minAnimationAlpha(), alphaLabel) ) );
grid->setControl( 0, ++r, new LabelControl("Activate time (s):") );
LabelControl* actLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.inAnimationTime()) );
grid->setControl( 1, r, new HSliderControl(
0.0, 2.0, *g_dcOptions.inAnimationTime(), new ChangeFloatOption(g_dcOptions.inAnimationTime(), actLabel) ) );
grid->setControl( 0, ++r, new LabelControl("Deactivate time (s):") );
LabelControl* deactLabel = grid->setControl( 2, r, new LabelControl(Stringify() << std::fixed << std::setprecision(1) << *g_dcOptions.outAnimationTime()) );
grid->setControl( 1, r, new HSliderControl(
0.0, 2.0, *g_dcOptions.outAnimationTime(), new ChangeFloatOption(g_dcOptions.outAnimationTime(), deactLabel) ) );
}
示例15: main
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
bool test1 = arguments.read("--test1");
bool test2 = arguments.read("--test2");
bool test3 = arguments.read("--test3");
bool test4 = arguments.read("--test4");
bool test5 = arguments.read("--test5");
bool test6 = arguments.read("--test6");
bool test7 = arguments.read("--test7");
bool test8 = arguments.read("--test8");
bool test9 = arguments.read("--test9");
bool ok = test1 || test2 || test3 || test4 || test5 || test6 || test7 || test8||test9;
bool ui = !arguments.read("--noui");
if ( !ok )
{
return usage("");
}
osg::Group* root = new osg::Group();
viewer.setSceneData( root );
LabelControl* label = new LabelControl();
if ( ui )
{
// add a canvas:
ControlCanvas* canvas = new ControlCanvas();
root->addChild( canvas );
// and a label:
canvas->addControl(label);
}
if ( test1 || test2 || test3 || test4 || test6 )
{
osg::Node* earthNode = osgDB::readNodeFile( "gdal_tiff.earth" );
if (!earthNode)
{
return usage( "Unable to load earth model." );
}
if ( test1 )
{
root->addChild( TEST_1::run(earthNode) );
if (ui) label->setText( "Function injection test: the map appears hazy at high altitude." );
}
else if ( test2 )
{
root->addChild( TEST_2::run(earthNode) );
if (ui) label->setText( "Accept callback test: the map turns red when viewport width > 1000" );
}
else if ( test3 )
{
root->addChild( TEST_3::run(earthNode) );
if (ui) label->setText( "Shader LOD test: the map turns red between 500K and 1M meters altitude" );
}
else if ( test4 )
{
root->addChild( TEST_4::run(earthNode) );
if (ui) label->setText("Memory management test; monitor memory for stability");
}
else if ( test6 )
{
root->addChild( TEST_6::run(earthNode) );
if (ui) label->setText("State Memory Stack test; top row, both=blue. bottom left=red, bottom right=normal.");
}
viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() );
}
else if ( test5 )
{
osgEarth::Registry::instance()->getCapabilities();
root->addChild( TEST_5::run() );
if (ui) label->setText( "Leakage test: red tri on the left, blue on the right." );
}
else if ( test7 )
{
root->addChild( TEST_7::run( osgDB::readNodeFiles(arguments) ) );
if (ui) label->setText("Geometry Shader Injection Test.");
}
else if (test8)
{
root->addChild( TEST_8::run() );
if (ui) label->setText("Serialization test");
}
else if (test9)
{
osg::Node* earthNode = osgDB::readNodeFile( "readymap.earth" );
if (!earthNode)
{
return usage( "Unable to load earth model." );
}
root->addChild(TEST_9::run(earthNode));
if (ui) label->setText("DP Shader Test - see code comments");
viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() );
//.........这里部分代码省略.........