Commit 81bcab7a authored by Rashad Kanavath's avatar Rashad Kanavath

call ossimRPCModel::loadState if there is polynomial_format key

parent 1316f0a6
......@@ -93,7 +93,7 @@ GetMetadataByKey(const std::string& key) const
itkGenericExceptionMacro(<< "Keywordlist has no output with key " << key);
}
// Then if everything is ok, return the ossinString
// Then if everything is ok, return the ossimString
return it->second;
}
......@@ -102,6 +102,8 @@ ImageKeywordlist::
HasKey(const std::string& key) const
{
KeywordlistMap::const_iterator it = m_Keywordlist.find(key);
return (it != m_Keywordlist.end());
}
......@@ -138,14 +140,17 @@ ImageKeywordlist::
convertToGDALRPC(GDALRPCInfo &rpc) const
{
ossimKeywordlist geom_kwl;
this->convertToOSSIMKeywordlist(geom_kwl);
if( geom_kwl.hasKey("polynomial_format")) //RK
{
ossimRefPtr<ossimRpcModel> rpcModel = new ossimRpcModel;
if (rpcModel->loadState(geom_kwl))
{
ossimRpcModel::rpcModelStruct ossimRpcStruct;
rpcModel->getRpcParameters(ossimRpcStruct);
if (ossimRpcStruct.type == 'B')
{
rpc.dfSAMP_OFF = ossimRpcStruct.sampOffset;
......@@ -158,16 +163,16 @@ convertToGDALRPC(GDALRPCInfo &rpc) const
rpc.dfLAT_SCALE = ossimRpcStruct.latScale;
rpc.dfLONG_SCALE = ossimRpcStruct.lonScale;
rpc.dfHEIGHT_SCALE = ossimRpcStruct.hgtScale;
memcpy(rpc.adfLINE_NUM_COEFF, ossimRpcStruct.lineNumCoef, sizeof(double) * 20);
memcpy(rpc.adfLINE_DEN_COEFF, ossimRpcStruct.lineDenCoef, sizeof(double) * 20);
memcpy(rpc.adfSAMP_NUM_COEFF, ossimRpcStruct.sampNumCoef, sizeof(double) * 20);
memcpy(rpc.adfSAMP_DEN_COEFF, ossimRpcStruct.sampDenCoef, sizeof(double) * 20);
return true;
}
}
}
return false;
}
......@@ -218,6 +223,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
because the default include factory contains ossimQuickbirdTiffTileSource. */
ossimProjection * projection = ossimplugins::ossimPluginProjectionFactory::instance()
->createProjection(ossimFilename(filename.c_str()), 0);
if (projection)
{
otbMsgDevMacro(<< "OSSIM plugin projection instantiated ! ");
......@@ -228,6 +234,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
// Free memory
delete projection;
projection = 0;
}
/***********************************************/
......@@ -253,7 +260,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
hasMetaData = projection->saveState(geom_kwl);
}
}
// if the handler has found a sensor model, copy the tags found
if (hasMetaData && dynamic_cast<ossimSensorModel*>(projection))
{
......@@ -268,7 +275,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
delete handler;
}
}
/**********************************************************/
/* Third try : look for external geom file and RPC tags */
/**********************************************************/
......@@ -277,14 +284,14 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
// If still no metadata, try the ".geom" file
ossimFilename ossimGeomFile = ossimFilename(filename).setExtension(".geom");
otb_kwl = ReadGeometryFromGEOMFile(ossimGeomFile);
// also check any RPC tags
ImageKeywordlist rpc_kwl;
if (checkRpcTag)
{
rpc_kwl = ReadGeometryFromRPCTag(filename);
}
if (otb_kwl.HasKey("type"))
{
// external geom has a "type" keyword
......@@ -298,7 +305,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
{
rpc_kwl.ClearMetadataByKey("type");
}
ossimKeywordlist ossim_test_kwl;
otb_kwl.convertToOSSIMKeywordlist(ossim_test_kwl);
testProj = ossimProjectionFactoryRegistry::instance()
......@@ -310,7 +317,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
}
}
}
// copy keywords found in RPC tags if the external geom is not valid
if (!hasMetaData && rpc_kwl.GetSize() > 0)
{
......@@ -344,7 +351,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
// We then verify it is a valid sensor model by using otb::SensorModelAdapter
// which uses ossimSensorModelFactory and ossimPluginProjectionFactory internally,
// thus by-passing the need for a valid ossimImageHandler.
if (!hasMetaData)
{
otbMsgDevMacro(<< "OSSIM MetaData not present ! ");
......@@ -398,7 +405,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
{
ossimKeywordlist geom_kwl;
ImageKeywordlist otb_kwl;
// try to use GeoTiff RPC tag if present.
// Warning : RPC in subdatasets are not supported
GDALDriverH identifyDriverH = GDALIdentifyDriver(filename.c_str(), NULL);
......@@ -407,7 +414,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
// If no driver has identified the dataset, don't try to open it and exit
return otb_kwl;
}
GDALDatasetH datasetH = GDALOpen(filename.c_str(), GA_ReadOnly);
if (datasetH != NULL)
{
......@@ -420,7 +427,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
std::vector<double> lineDenCoefs;
std::vector<double> sampNumCoefs;
std::vector<double> sampDenCoefs;
for (unsigned int k=0; k<20; ++k)
{
lineNumCoefs.push_back(rpcStruct.adfLINE_NUM_COEFF[k]);
......@@ -428,7 +435,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
sampNumCoefs.push_back(rpcStruct.adfSAMP_NUM_COEFF[k]);
sampDenCoefs.push_back(rpcStruct.adfSAMP_DEN_COEFF[k]);
}
ossimRefPtr<ossimRpcModel> rpcModel = new ossimRpcModel;
rpcModel->setAttributes( rpcStruct.dfSAMP_OFF,
rpcStruct.dfLINE_OFF,
......@@ -444,10 +451,10 @@ ReadGeometryFromRPCTag(const std::string& filename)
sampDenCoefs,
lineNumCoefs,
lineDenCoefs);
double errorBias = 0.0;
double errorRand = 0.0;
// setup other metadata
rpcModel->setPositionError(errorBias,errorRand,true);
ossimDrect rectangle(0.0,
......@@ -455,27 +462,27 @@ ReadGeometryFromRPCTag(const std::string& filename)
static_cast<double>(dataset->GetRasterXSize()-1),
static_cast<double>(dataset->GetRasterYSize()-1));
rpcModel->setImageRect(rectangle);
ossimDpt size;
size.line = rectangle.height();
size.samp = rectangle.width();
rpcModel->setImageSize(size);
// Compute 4 corners and reference point
rpcModel->updateModel();
double heightOffset = rpcStruct.dfHEIGHT_OFF;
ossimGpt ulGpt, urGpt, lrGpt, llGpt;
ossimGpt refGndPt;
rpcModel->lineSampleHeightToWorld(rectangle.ul(), heightOffset, ulGpt);
rpcModel->lineSampleHeightToWorld(rectangle.ur(), heightOffset, urGpt);
rpcModel->lineSampleHeightToWorld(rectangle.lr(), heightOffset, lrGpt);
rpcModel->lineSampleHeightToWorld(rectangle.ll(), heightOffset, llGpt);
rpcModel->setGroundRect(ulGpt,urGpt,lrGpt,llGpt);
rpcModel->lineSampleHeightToWorld(rectangle.midPoint(), heightOffset, refGndPt);
rpcModel->setRefGndPt(refGndPt);
// compute ground sampling distance
try
{
......@@ -486,7 +493,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
{
otbMsgDevMacro(<< "OSSIM Compute ground sampling distance FAILED ! ");
}
if (rpcModel->saveState(geom_kwl))
{
otb_kwl.SetKeywordlist(geom_kwl);
......@@ -494,7 +501,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
}
GDALClose(datasetH);
}
return otb_kwl;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment