Model Layer cannot be loaded programmatically

classic Classic list List threaded Threaded
7 messages Options
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Model Layer cannot be loaded programmatically

Hello,
Recently, I upgrade my developing environment to Visual Studio 2017 on Window 10, so:
*I rebuild my OSG with version 3.6.1 R7;
*Build GDAL 2.3.0 and GEOS 3.7.0; (there is an error in the compilation in the GEOS header of osgEarth: unique_ptr does not exist, but it can be replace by Ptr)
*Build the latest osgEarth (08/06/2018);

My problem is that all my old projects cannot load programmatically any ModelLayer anymore. But if I run an earth  file with osgEarth_viewer , it will be loaded normally.

I used this code to load my ModelLayer:
        osgEarth::Drivers::OGRFeatureOptions fo;
	fo.ogrDriver() = "ESRI Shapefile";
	fo.url() = "WORLD_POLY.shp";
	fo.openWrite() = false;
	osg::ref_ptr< FeatureSource > features = FeatureSourceFactory::create(fo);
	features->open();

	FeatureGeomModelOptions  fgm_opt;
	StyleSheet* styleSheet = new StyleSheet();
	Style style;
	fgm_opt.featureOptions() = fo;
	AltitudeSymbol* alt = new AltitudeSymbol();
	alt->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
	alt->technique() = AltitudeSymbol::TECHNIQUE_MAP;
	style.add(alt);

	style.getOrCreate<PolygonSymbol>()->fill()->color() = Color::Red;
	style.getOrCreate<LineSymbol>()->stroke()->color() = Color::Yellow;
	styleSheet->addStyle(style);
	fgm_opt.styles() = styleSheet;
	ModelLayer * lay = new ModelLayer("vector", fgm_opt);
	map->addLayer(lay);

This code works on my old environment (old osgEarth + Visula Studio 2015), but fails with the latest one.


After digging in the manner how the earth file is read, I tried this code:
Layer* layer = Layer::create("model", fgm_opt.getConfig()); //fgm_opt from the above code
if (layer)
{
	cout << lay->getConfig().toJSON()<<"==="<< fgm_opt.getConfig().toJSON() << endl;
	map->addLayer(layer);
}
This one worked fine!!!.

I notice that the config for the ModelLayer that did not work is empty:
lay->getConfig().toJSON() = {"model":{"driver":{},"name":"vector"}} ???????????? why?????

But the FeatureGeomModelOptions was not empty:
 fgm_opt.getConfig().toJSON()=     {"":{"driver":"feature_geom","features":{"driver":"ogr","ogr_driver":"ESRI Shapefile","open_write":"false","url":"WORLD_POLY.shp"},"styles":{"style":{"name":{},"symbols":{"altitude":{"clamping":"terrain","technique":"map"},"line":{"stroke":{"color":"#ffff00ff"}},"polygon":{"fill":{"color":"#ff0000ff"}}}}}}}

So the modelLayer is not able to get the config. The driverOptions in ModelLayerOptions constructor (ModelLayer.cpp) is also empty.

Does this problem occure for the others, or it is just for me? where can the config be lost?

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Model Layer cannot be loaded programmatically

MCA,

Try using a FeatureModelLayer instead of a ModelLayer. FeatureModelLayer is a newer construct that is intended to replace the use of a ModelLayer with the feature_geom driver.

You can find usage information in the osgearth_features.cpp example. Hope this helps.
Glenn Waldron / Pelican Mapping
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: Model Layer cannot be loaded programmatically

Thanks gwaldron,

I think that I tested this example before, and it did not work. Even with the useMem, I got no vector displayed on the map. For the label it is ok.

So it will be the same problem, the configuration is not sent to featureModelLayer constructor.

I will test again this evening to confirm that, and I will let you know the results.

Thank you.
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: Model Layer cannot be loaded programmatically

In reply to this post by gwaldron
Hello again,
I tested the osgearth_features example again and it did not work for me (with useMem= true or false).
I set the notify level to debug, and as you can see in the this code:
https://pastebin.com/embed_js/D8Bk61Gk
there is no call to feature_geom driver.

The earth file is working perfectly on the other side.

Any help please.
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: Model Layer cannot be loaded programmatically

In reply to this post by gwaldron
Hello,

I am still facing the same problem. I took a look on the modelLayer.cpp and I found that the problem was in the ModelLayerOptions::ModelLayerOptions(const std::string& in_name, const ModelSourceOptions& driverOptions), the driverOptions.empty() is always true.

If I replace in my first code :
ModelLayer * lay = new ModelLayer("vector",  fgm_opt);
with:
ModelLayer * lay = new ModelLayer("vector", ConfigOptions( fgm_opt.getConfig()));
It will work!

The problem is that the FeatureGeomModelOptions is always empty, even if the FeatureGeomModelOptions::getConfig is not empty.

How can I fix that permanently?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Model Layer cannot be loaded programmatically

MCA,
I pushed a patch for this -- please give it a try. Thanks.
Glenn Waldron / Pelican Mapping
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: Model Layer cannot be loaded programmatically

Thanks, I have tested the latest version but still not good.

The Modellayer is now loaded, but there is no color for the edges of polygons. the stroke color is ignored!

Also, the osgEarth_features is still not working, the vector is not loaded at all (also with --mem).

I think the FeatureGeomModelOptions should be broken some where, but I still cannot find where.