Implemented support for overriding the coordinate system and geo transform
using in generate of databases.
This commit is contained in:
parent
231b4c7564
commit
88bbdb325d
@ -139,64 +139,57 @@ int main( int argc, char **argv )
|
||||
argumentRead = false;
|
||||
|
||||
std::string def;
|
||||
osgTerrain::DataSet::Source* source = 0;
|
||||
|
||||
if (arguments.read(pos, "--cs",def))
|
||||
{
|
||||
argumentRead = true;
|
||||
currentCS = !def.empty() ? SanitizeSRS(def.c_str()) : "";
|
||||
std::cout<<"--cs "<<currentCS<<std::endl;
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--identity"))
|
||||
else if (arguments.read(pos, "--identity"))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = false;
|
||||
geoTransform.makeIdentity();
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--xx",geoTransform(0,0)))
|
||||
else if (arguments.read(pos, "--xx",geoTransform(0,0)))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = true;
|
||||
std::cout<<"--xs "<<geoTransform(0,0)<<std::endl;
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--xt",geoTransform(3,0)))
|
||||
else if (arguments.read(pos, "--xt",geoTransform(3,0)))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = true;
|
||||
std::cout<<"--xo "<<geoTransform(3,0)<<std::endl;
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--yy",geoTransform(1,1)))
|
||||
else if (arguments.read(pos, "--yy",geoTransform(1,1)))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = true;
|
||||
std::cout<<"--yy "<<geoTransform(1,1)<<std::endl;
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--yt",geoTransform(3,1)))
|
||||
else if (arguments.read(pos, "--yt",geoTransform(3,1)))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = true;
|
||||
std::cout<<"--yt "<<geoTransform(3,1)<<std::endl;
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--zz",geoTransform(2,2)))
|
||||
else if (arguments.read(pos, "--zz",geoTransform(2,2)))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = true;
|
||||
std::cout<<"--zz "<<geoTransform(2,2)<<std::endl;
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "--zt",geoTransform(3,2)))
|
||||
else if (arguments.read(pos, "--zt",geoTransform(3,2)))
|
||||
{
|
||||
argumentRead = true;
|
||||
geoTransformSet = true;
|
||||
std::cout<<"--zt "<<geoTransform(3,2)<<std::endl;
|
||||
}
|
||||
|
||||
osgTerrain::DataSet::Source* source = 0;
|
||||
if (arguments.read(pos, "-d",filename))
|
||||
else if (arguments.read(pos, "-d",filename))
|
||||
{
|
||||
argumentRead = true;
|
||||
|
||||
@ -207,8 +200,7 @@ int main( int argc, char **argv )
|
||||
source = new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::HEIGHT_FIELD,filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "-t",filename))
|
||||
else if (arguments.read(pos, "-t",filename))
|
||||
{
|
||||
argumentRead = true;
|
||||
|
||||
@ -218,8 +210,7 @@ int main( int argc, char **argv )
|
||||
source = new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::IMAGE,filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "-m",filename))
|
||||
else if (arguments.read(pos, "-m",filename))
|
||||
{
|
||||
argumentRead = true;
|
||||
|
||||
@ -229,6 +220,27 @@ int main( int argc, char **argv )
|
||||
source = new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::MODEL,filename);
|
||||
}
|
||||
}
|
||||
else if (arguments.read(pos, "-o",filename))
|
||||
{
|
||||
std::cout<<"-o "<<filename<<std::endl;
|
||||
|
||||
argumentRead = true;
|
||||
|
||||
std::string path = osgDB::getFilePath(filename);
|
||||
std::string base = path.empty()?osgDB::getStrippedName(filename):
|
||||
path +'/'+ osgDB::getStrippedName(filename);
|
||||
std::string extension = '.'+osgDB::getLowerCaseFileExtension(filename);
|
||||
|
||||
dataset->setDestinationTileBaseName(base);
|
||||
dataset->setDestinationTileExtension(extension);
|
||||
|
||||
if (!currentCS.empty()) dataset->setDestinationCoordinateSystem(currentCS);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if no argument read advance to next argument.
|
||||
++pos;
|
||||
}
|
||||
|
||||
if (source)
|
||||
{
|
||||
@ -248,26 +260,7 @@ int main( int argc, char **argv )
|
||||
|
||||
dataset->addSource(source);
|
||||
}
|
||||
|
||||
if (arguments.read(pos, "-o",filename))
|
||||
{
|
||||
std::cout<<"-o "<<filename<<std::endl;
|
||||
|
||||
argumentRead = true;
|
||||
|
||||
std::string path = osgDB::getFilePath(filename);
|
||||
std::string base = path.empty()?osgDB::getStrippedName(filename):
|
||||
path +'/'+ osgDB::getStrippedName(filename);
|
||||
std::string extension = '.'+osgDB::getLowerCaseFileExtension(filename);
|
||||
|
||||
dataset->setDestinationTileBaseName(base);
|
||||
dataset->setDestinationTileExtension(extension);
|
||||
|
||||
if (!currentCS.empty()) dataset->setDestinationCoordinateSystem(currentCS);
|
||||
}
|
||||
|
||||
// if no argument read advance to next argument.
|
||||
if (!argumentRead) ++pos;
|
||||
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ class DataSet : public osg::Referenced
|
||||
_numValuesY(0),
|
||||
_numValuesZ(0) {}
|
||||
|
||||
SpatialProperties& operator = (const SpatialProperties& sp)
|
||||
inline SpatialProperties& assignSpatialProperties(const SpatialProperties& sp)
|
||||
{
|
||||
if (&sp==this) return *this;
|
||||
|
||||
@ -71,6 +71,13 @@ class DataSet : public osg::Referenced
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void computeExtents()
|
||||
{
|
||||
_extents.init();
|
||||
_extents.expandBy( osg::Vec3(0.0,0.0,0.0)*_geoTransform);
|
||||
_extents.expandBy( osg::Vec3(_numValuesX,_numValuesY,0.0)*_geoTransform);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgTerrain::CoordinateSystem> _cs;
|
||||
osg::Matrixd _geoTransform;
|
||||
@ -189,15 +196,20 @@ class DataSet : public osg::Referenced
|
||||
bool getTemporaryFile() const { return _temporaryFile; }
|
||||
|
||||
void setCoordinateSystemPolicy(ParameterPolicy policy) { _coordinateSystemPolicy = policy; }
|
||||
ParameterPolicy getCoordinateSystemPolicy() const { return _coordinateSystemPolicy; }
|
||||
|
||||
void setCoordinateSystem(const std::string& wellKnownText) { _cs = new osgTerrain::CoordinateSystem(wellKnownText); }
|
||||
void setCoordinateSystem(osgTerrain::CoordinateSystem* cs) { _cs = cs; }
|
||||
osgTerrain::CoordinateSystem* getCoordinateSystem() { return _cs.get(); }
|
||||
|
||||
|
||||
void setGeoTransformPolicy(ParameterPolicy policy) { _geoTransformPolicy = policy; }
|
||||
ParameterPolicy getGeoTransformPolicy() const { return _geoTransformPolicy; }
|
||||
|
||||
void setGeoTransform(osg::Matrixd& transform) { _geoTransform = transform; }
|
||||
osg::Matrixd& getGeoTransform() { return _geoTransform; }
|
||||
|
||||
void assignCoordinateSystemAndGeoTransformAccordingToParameterPolicy();
|
||||
|
||||
void setSourceData(SourceData* data) { _sourceData = data; if (_sourceData.valid()) _sourceData->_source = this; }
|
||||
SourceData* getSourceData() { return _sourceData.get(); }
|
||||
|
@ -182,9 +182,7 @@ DataSet::SourceData* DataSet::SourceData::readData(Source* source)
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
geoTransform[0], geoTransform[3], 0.0, 1.0);
|
||||
|
||||
data->_extents.init();
|
||||
data->_extents.expandBy( osg::Vec3(0.0,0.0,0.0)*data->_geoTransform);
|
||||
data->_extents.expandBy( osg::Vec3(data->_numValuesX,data->_numValuesY,0.0)*data->_geoTransform);
|
||||
data->computeExtents();
|
||||
|
||||
}
|
||||
else if (gdalDataSet->GetGCPCount()>0 && gdalDataSet->GetGCPProjection())
|
||||
@ -229,23 +227,19 @@ DataSet::SourceData* DataSet::SourceData::readData(Source* source)
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
adfDstGeoTransform[0], adfDstGeoTransform[3], 0.0, 1.0);
|
||||
|
||||
data->_extents.init();
|
||||
data->_extents.expandBy( osg::Vec3(0.0,0.0,0.0)*data->_geoTransform);
|
||||
data->_extents.expandBy( osg::Vec3(nPixels,nLines,0.0)*data->_geoTransform);
|
||||
data->computeExtents();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << " No GeoTransform or GCP's - unable to compute position in space"<< std::endl;
|
||||
|
||||
data->_geoTransform.set( 512.0, 0.0, 0.0, 0.0,
|
||||
0.0, 512.0, 0.0, 0.0,
|
||||
data->_geoTransform.set( 1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
data->_extents.init();
|
||||
data->_extents.expandBy( osg::Vec3(0.0,0.0,0.0)*data->_geoTransform);
|
||||
data->_extents.expandBy( osg::Vec3(data->_numValuesX,data->_numValuesY,0.0)*data->_geoTransform);
|
||||
data->computeExtents();
|
||||
|
||||
}
|
||||
return data;
|
||||
@ -336,9 +330,7 @@ const DataSet::SpatialProperties& DataSet::SourceData::computeSpatialProperties(
|
||||
|
||||
GDALDestroyGenImgProjTransformer( hTransformArg );
|
||||
|
||||
sp._extents.init();
|
||||
sp._extents.expandBy( osg::Vec3(0.0,0.0,0.0)*sp._geoTransform);
|
||||
sp._extents.expandBy( osg::Vec3(nPixels,nLines,0.0)*sp._geoTransform);
|
||||
sp.computeExtents();
|
||||
|
||||
return sp;
|
||||
}
|
||||
@ -641,6 +633,7 @@ void DataSet::SourceData::readHeightField(DestinationData& destination)
|
||||
bool ignoreNoDataValue = true;
|
||||
|
||||
float* heightPtr = heightData;
|
||||
|
||||
for(int r=destY+destHeight-1;r>=destY;--r)
|
||||
{
|
||||
for(int c=destX;c<destX+destWidth;++c)
|
||||
@ -648,6 +641,8 @@ void DataSet::SourceData::readHeightField(DestinationData& destination)
|
||||
float h = *heightPtr++;
|
||||
if (h!=noDataValue) hf->setHeight(c,r,offset + h*scale);
|
||||
else if (!ignoreNoDataValue) hf->setHeight(c,r,noDataValueFill);
|
||||
|
||||
h = hf->getHeight(c,r);
|
||||
}
|
||||
}
|
||||
|
||||
@ -683,7 +678,41 @@ void DataSet::Source::loadSourceData()
|
||||
std::cout<<"DataSet::Source::loadSourceData() "<<_filename<<std::endl;
|
||||
|
||||
_sourceData = SourceData::readData(this);
|
||||
if (_sourceData.valid() && !_cs.valid()) _cs = _sourceData->_cs;
|
||||
|
||||
assignCoordinateSystemAndGeoTransformAccordingToParameterPolicy();
|
||||
}
|
||||
|
||||
void DataSet::Source::assignCoordinateSystemAndGeoTransformAccordingToParameterPolicy()
|
||||
{
|
||||
if (getCoordinateSystemPolicy()==PREFER_CONFIG_SETTINGS)
|
||||
{
|
||||
_sourceData->_cs = _cs;
|
||||
|
||||
std::cout<<"assigning CS from Source to Data."<<std::endl;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_cs = _sourceData->_cs;
|
||||
std::cout<<"assigning CS from Data to Source."<<std::endl;
|
||||
}
|
||||
|
||||
if (getGeoTransformPolicy()==PREFER_CONFIG_SETTINGS)
|
||||
{
|
||||
_sourceData->_geoTransform = _geoTransform;
|
||||
|
||||
std::cout<<"assigning GeoTransform from Source to Data."<<_geoTransform<<std::endl;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_geoTransform = _sourceData->_geoTransform;
|
||||
std::cout<<"assigning GeoTransform from Data to Source."<<_geoTransform<<std::endl;
|
||||
}
|
||||
|
||||
_sourceData->computeExtents();
|
||||
|
||||
_extents = _sourceData->_extents;
|
||||
}
|
||||
|
||||
bool DataSet::Source::needReproject(const osgTerrain::CoordinateSystem* cs) const
|
||||
@ -1004,25 +1033,17 @@ DataSet::Source* DataSet::Source::doReproject(const std::string& filename, osgTe
|
||||
newSource->_filename = filename;
|
||||
newSource->_temporaryFile = true;
|
||||
newSource->_cs = cs;
|
||||
newSource->_geoTransform.set( adfDstGeoTransform[1], adfDstGeoTransform[4], 0.0, 0.0,
|
||||
adfDstGeoTransform[2], adfDstGeoTransform[5], 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
adfDstGeoTransform[0], adfDstGeoTransform[3], 0.0, 1.0);
|
||||
newSource->_numValuesX = nPixels;
|
||||
newSource->_numValuesY = nLines;
|
||||
newSource->_geoTransform.set( adfDstGeoTransform[1], adfDstGeoTransform[4], 0.0, 0.0,
|
||||
adfDstGeoTransform[2], adfDstGeoTransform[5], 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
adfDstGeoTransform[0], adfDstGeoTransform[3], 0.0, 1.0);
|
||||
|
||||
newSource->_extents.init();
|
||||
newSource->_extents.expandBy( osg::Vec3(0.0,0.0,0.0)*newSource->_geoTransform);
|
||||
newSource->_extents.expandBy( osg::Vec3(nPixels,nLines,0.0)*newSource->_geoTransform);
|
||||
newSource->computeExtents();
|
||||
|
||||
// reload the newly created file.
|
||||
newSource->loadSourceData();
|
||||
|
||||
SourceData* newData = newSource->_sourceData.get();
|
||||
|
||||
// override the values in the new source data.
|
||||
newData->_cs = cs;
|
||||
newData->_extents = newSource->_extents;
|
||||
newData->_geoTransform = newSource->_geoTransform;
|
||||
|
||||
|
||||
return newSource;
|
||||
}
|
||||
@ -2008,7 +2029,6 @@ osg::Node* DataSet::CompositeDestination::createPagedLODScene()
|
||||
|
||||
if (_tiles.empty() && _children.size()==1) return _children.front()->createPagedLODScene();
|
||||
|
||||
|
||||
if (_type==GROUP)
|
||||
{
|
||||
osg::Group* group = new osg::Group;
|
||||
@ -2045,12 +2065,20 @@ osg::Node* DataSet::CompositeDestination::createPagedLODScene()
|
||||
if (node) tileNodes.push_back(node);
|
||||
}
|
||||
|
||||
float cutOffDistance = -FLT_MAX;
|
||||
for(ChildList::iterator citr=_children.begin();
|
||||
citr!=_children.end();
|
||||
++citr)
|
||||
{
|
||||
cutOffDistance = osg::maximum(cutOffDistance,(*citr)->_maxVisibleDistance);
|
||||
}
|
||||
|
||||
osg::PagedLOD* pagedLOD = new osg::PagedLOD;
|
||||
|
||||
float farDistance = 1e8;
|
||||
if (tileNodes.size()==1)
|
||||
{
|
||||
pagedLOD->addChild(tileNodes.front(),_maxVisibleDistance,farDistance);
|
||||
pagedLOD->addChild(tileNodes.front(),cutOffDistance,farDistance);
|
||||
}
|
||||
else if (tileNodes.size()>1)
|
||||
{
|
||||
@ -2061,11 +2089,11 @@ osg::Node* DataSet::CompositeDestination::createPagedLODScene()
|
||||
{
|
||||
group->addChild(*itr);
|
||||
}
|
||||
pagedLOD->addChild(group,_maxVisibleDistance,farDistance);
|
||||
pagedLOD->addChild(group,cutOffDistance,farDistance);
|
||||
}
|
||||
|
||||
pagedLOD->setFileName(1,getSubTileName());
|
||||
pagedLOD->setRange(1,0,_maxVisibleDistance);
|
||||
pagedLOD->setRange(1,0,cutOffDistance);
|
||||
|
||||
if (pagedLOD->getNumChildren()>0)
|
||||
pagedLOD->setCenter(pagedLOD->getBound().center());
|
||||
|
Loading…
Reference in New Issue
Block a user