Commit 23478eac authored by Cédric Traizet's avatar Cédric Traizet
Browse files

Merge branch '2040-RPC_model' of...

Merge branch '2040-RPC_model' of https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb into 2040-RPC_model
parents a0f7f9af 90c9c47d
Testing geopoint: [3.740934, 44.107956]
Testing InverseSensorModel: [3.740934, 44.107956] -> [14190.558, 13591.703]
Testing ForwardSensorModel: [14190.558, 13591.703] -> [3.740934, 44.107956, 0]
Testing geopoint: [1.4434869, 43.604688]
Testing InverseSensorModel: [1.4434869, 43.604688] -> [11234.024, 8199.2289]
Testing ForwardSensorModel: [11234.024, 8199.2289] -> [1.4434838, 43.604235, 0]
Testing geopoint: [1.4434869, 43.604688]
Testing InverseSensorModel: [1.4434869, 43.604688] -> [11234.662, 8124.3911]
Testing ForwardSensorModel: [11234.662, 8124.3911] -> [1.4434869, 43.604688, 0]
......@@ -40,6 +40,7 @@ otb_module(OTBTransform
OTBImageManipulation
OTBOssim
OTBTestKernel
OTBProjection
DESCRIPTION
"${DOCUMENTATION}"
......
......@@ -23,7 +23,6 @@ otb_module_test()
set(OTBTransformTests
otbTransformTestDriver.cxx
otbGenericRSTransformWithSRID.cxx
otbCreateInverseForwardSensorModel.cxx
otbLogPolarTransformResample.cxx
otbLogPolarTransform.cxx
otbGeocentricTransform.cxx
......@@ -34,6 +33,7 @@ otbInverseLogPolarTransform.cxx
otbInverseLogPolarTransformResample.cxx
otbStreamingResampleImageFilterWithAffineTransform.cxx
otbSarSensorModelAdapterTest.cxx
otbRPCTransformTest.cxx
)
add_executable(otbTransformTestDriver ${OTBTransformTests})
......@@ -61,38 +61,52 @@ otb_add_test(NAME prTvGenericRSTransformWithSRID COMMAND otbTransformTestDriver
${TEMP}/prTvGenericRSTransform_WithSRID.txt
)
otb_add_test(NAME prTvTestCreateInverseForwardSensorModel_Cevennes COMMAND otbTransformTestDriver
--compare-ascii ${EPSILON_4}
${BASELINE_FILES}/prTvTestCreateInverseForwardSensorModel_Cevennes.txt
${TEMP}/prTvTestCreateInverseForwardSensorModel_Cevennes.txt
otbCreateInverseForwardSensorModel
LARGEINPUT{QUICKBIRD/CEVENNES/06FEB12104912-P1BS-005533998070_01_P001.TIF}
${TEMP}/prTvTestCreateInverseForwardSensorModel_Cevennes.txt
3.740934
44.107956
otb_add_test(NAME trTvRPCTransformTest_ikonos_geom COMMAND otbTransformTestDriver
otbRPCTransformTest
${INPUTDATA}/ikonos/ikonos-1.geom # Geom
${INPUTDATA}/ikonos/ikonos-1.gcp2 # GCP
0.04 # GeoTol
0.1 # ImgTol
)
otb_add_test(NAME prTvTestCreateInverseForwardSensorModel_Toulouse COMMAND otbTransformTestDriver
--compare-ascii ${EPSILON_4}
${BASELINE_FILES}/prTvTestCreateInverseForwardSensorModel_Toulouse.txt
${TEMP}/prTvTestCreateInverseForwardSensorModel_Toulouse.txt
otbCreateInverseForwardSensorModel
LARGEINPUT{QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF}
${TEMP}/prTvTestCreateInverseForwardSensorModel_Toulouse.txt
1.44348693
43.60468837
otb_add_test(NAME trTvRPCTransformTest_ikonos_product COMMAND otbTransformTestDriver
otbRPCTransformTest
LARGEINPUT{IKONOS/BLOSSEVILLE/po_2619900_blu_0000000.tif} # Product
${INPUTDATA}/ikonos/ikonos-1.gcp2 # GCP
0.04 # GeoTol
0.1 # ImgTol
)
otb_add_test(NAME prTvTestCreateInverseForwardSensorModel_DEM COMMAND otbTransformTestDriver
--compare-ascii ${EPSILON_4}
${BASELINE_FILES}/prTvTestCreateInverseForwardSensorModel_DEM.txt
${TEMP}/prTvTestCreateInverseForwardSensorModel_DEM.txt
otbCreateInverseForwardSensorModel
LARGEINPUT{QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF}
${TEMP}/prTvTestCreateInverseForwardSensorModel_DEM.txt
1.44348693
43.60468837
${INPUTDATA}/DEM/srtm_directory/N43E001.hgt
otb_add_test(NAME trTvRPCTransformTest_quickbird COMMAND otbTransformTestDriver
otbRPCTransformTest
${INPUTDATA}/QB/qb-1.geom # Geom
${INPUTDATA}/QB/qb-1.gcp2 # GCP
0.024 # GeoTol
0.1 # ImgTol
)
otb_add_test(NAME trTvRPCTransformTest_spot6 COMMAND otbTransformTestDriver
otbRPCTransformTest
${INPUTDATA}/spot6/spot6-1.geom # Geom
${INPUTDATA}/spot6/spot6-1.gcp2 # GCP
0.06 # GeoTol
0.1 # ImgTol
)
otb_add_test(NAME trTvRPCTransformTest_worldview2 COMMAND otbTransformTestDriver
otbRPCTransformTest
${INPUTDATA}/wv2/wv2-1.geom # Geom
${INPUTDATA}/wv2/wv2-1.gcp2 # GCP
0.0185 # GeoTol
0.1 # ImgTol
)
otb_add_test(NAME trTvRPCTransformTest_pl_hnord COMMAND otbTransformTestDriver
otbRPCTransformTest
${INPUTDATA}/pleiades/pleiades-1.geom # Geom
${INPUTDATA}/pleiades/pleiades-1.gcp2 # GCP
0.02 # GeoTol
0.1 # ImgTol
)
otb_add_test(NAME bfTvLogPolarTransformResample COMMAND otbTransformTestDriver
......
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "itkPoint.h"
#include "itkEuclideanDistanceMetric.h"
#include "otbGeographicalDistance.h"
#include "otbImageMetadata.h"
#include "otbMetaDataKey.h"
#include "otbGeomMetadataSupplier.h"
#include "otbImageMetadataInterfaceFactory.h"
#include "otbMacro.h"
#include "otbDEMHandler.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbRPCForwardTransform.h"
#include "otbRPCInverseTransform.h"
using PointType = itk::Point<double, 3>;
using PointsContainerType = std::vector<PointType>;
using ForwardTransformType = otb::RPCForwardTransform<double, 3, 3>;
using InverseTransformType = otb::RPCInverseTransform<double, 3, 3>;
using DistanceType = itk::Statistics::EuclideanDistanceMetric<PointType>;
using GeographicalDistanceType = otb::GeographicalDistance<PointType>;
int otbRPCTransformTest(int itkNotUsed(argc), char* argv[])
{
bool success = true;
PointType imagePoint;
PointType geo3dPoint;
// Inputs
std::string rpcFile(argv[1]);
std::string gcpFileName(argv[2]);
double geoTol(atof(argv[3]));
double imgTol(atof(argv[4]));
// Tools
auto distance = DistanceType::New();
auto geoDistance = GeographicalDistanceType::New();
otb::ImageMetadata imd;
if (0 == rpcFile.compare(rpcFile.length() - 4, 4, "geom"))
{
// Fetching the RPC model from a GEOM file
otb::GeomMetadataSupplier geomSupplier(rpcFile);
for (int loop = 0 ; loop < geomSupplier.GetNbBands() ; ++loop)
imd.Bands.emplace_back();
auto imi = otb::ImageMetadataInterfaceFactory::CreateIMI(imd, geomSupplier);
imd = imi->GetImageMetadata();
geomSupplier.FetchRPC(imd);
}
else
{
// Fetching the RPC model from a product
using ImageType = otb::Image<double, 2>;
using ImageFileReaderType = otb::ImageFileReader<ImageType>;
auto reader = ImageFileReaderType::New();
reader->SetFileName(rpcFile);
reader->UpdateOutputInformation();
imd = reader->GetOutput()->GetImageMetadata();
}
// Setting the forward and inverse transform
auto ForwardTransform = ForwardTransformType::New();
ForwardTransform->SetMetadata(imd);
auto InverseTransform = InverseTransformType::New();
InverseTransform->SetMetadata(imd);
// Loading the GCP
PointsContainerType pointsContainer;
PointsContainerType geo3dPointsContainer;
std::ifstream file(gcpFileName, std::ios::in);
if (file)
{
std::string line;
while (getline(file, line))
{
if (line.find_first_of("#") != 0)
{
std::istringstream iss(line);
iss >> imagePoint[0] >> imagePoint[1] >> geo3dPoint[0] >> geo3dPoint[1] >> geo3dPoint[2];
imagePoint[2] = geo3dPoint[2];
pointsContainer.push_back(imagePoint);
geo3dPointsContainer.push_back(geo3dPoint);
}
}
file.close();
}
// For each CGP
for (PointsContainerType::iterator pointsIt = pointsContainer.begin(), geo3dPointsIt = geo3dPointsContainer.begin() ;
(pointsIt != pointsContainer.end()) && (geo3dPointsIt != geo3dPointsContainer.end()) ;
++pointsIt, ++geo3dPointsIt)
{
// std::cout << "Point: " << *pointsIt << " GeoPoint: " << *geo3dPointsIt << "\n";
// Testing forward transform
geo3dPoint = ForwardTransform->TransformPoint(*pointsIt);
auto forwardPointDistance = geoDistance->Evaluate(geo3dPoint, *geo3dPointsIt);
if (forwardPointDistance > geoTol)
{
std::cerr << "Geo distance between ForwardTransform->TransformPoint and GCP too high :\n"
<< "GCP: " << *geo3dPointsIt << " / computed: " << geo3dPoint << "\n"
<< "dist = " << forwardPointDistance << " (tol = " << geoTol << ")" << std::endl;
success = false;
}
// Testing inverse transform
imagePoint = InverseTransform->TransformPoint(*geo3dPointsIt);
auto inversePointDistance = distance->Evaluate(imagePoint, *pointsIt);
if (inversePointDistance > imgTol)
{
std::cerr << "Distance between InverseTransform->TransformPoint and GCP too high :\n"
<< "GCP: " << *pointsIt << " / computed: " << imagePoint << "\n"
<< "dist = " << inversePointDistance << " (tol = " << imgTol << ")" << std::endl;
success = false;
}
}
if (success)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
......@@ -23,8 +23,6 @@
void RegisterTests()
{
REGISTER_TEST(otbGenericRSTransformWithSRID);
REGISTER_TEST(otbCreateInverseForwardSensorModel);
// REGISTER_TEST(otbCreateProjectionWithOSSIM);
REGISTER_TEST(otbLogPolarTransformResample);
REGISTER_TEST(otbLogPolarTransform);
REGISTER_TEST(otbGeocentricTransform);
......@@ -36,4 +34,5 @@ void RegisterTests()
REGISTER_TEST(otbInverseLogPolarTransformResample);
REGISTER_TEST(otbStreamingResampleImageFilterWithAffineTransform);
REGISTER_TEST(otbSarSensorModelAdapterTest);
REGISTER_TEST(otbRPCTransformTest);
}
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