Commit 096bd7cd authored by Christophe Palmann's avatar Christophe Palmann

TEST: rmved some tests related to projections and metadata (sources) 1

parent 6dd6c35e
......@@ -2,7 +2,7 @@ otb_module_test()
set(OTBOSSIMAdaptersTests
otbOSSIMAdaptersTestDriver.cxx
otbImageKeywordlist.cxx
##>otbImageKeywordlist.cxx
otbOssimJpegFileRessourceLeakTest.cxx
otbMapProjectionAdapterTest.cxx
otbOssimElevManagerTest2.cxx
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include "otbMacro.h"
#include "otbImageKeywordlist.h"
#include "ossim/base/ossimKeywordlist.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "ossim/projection/ossimProjection.h"
#include "ossim/projection/ossimProjectionFactoryRegistry.h"
#include "ossim/base/ossimFilename.h"
#pragma GCC diagnostic pop
#else
#include "ossim/projection/ossimProjection.h"
#include "ossim/projection/ossimProjectionFactoryRegistry.h"
#include "ossim/base/ossimFilename.h"
#endif
#include "ossim/ossimPluginProjectionFactory.h"
int otbImageKeywordlist(int argc, char* argv[])
{
if (argc != 4)
{
std::cout << argv[0] << " <input filename> <output filename> <output filename2>" << std::endl;
return EXIT_FAILURE;
}
char * filename = argv[1];
char * outFilename = argv[2];
char * outFilename2 = argv[3];
std::ofstream file;
file.open(outFilename);
file << std::setprecision(15);
std::ofstream file2;
file2.open(outFilename2);
file2 << std::setprecision(15);
bool hasMetaData = false;
ossimKeywordlist geom_kwl, geom_kwl2, geom_kwl3;
/** Don't use FactoryRegistry because of its default factory that can conflict
* with plugins factor (cf. TSX .tif image read as QB)*/
// test ossim plugin factory
ossimProjection * projection = ossimplugins::ossimPluginProjectionFactory::instance()->createProjection(
ossimFilename(filename), 0);
// if ossim plugins factory failed, then test ossim factory
if (!projection)
{
projection = ossimProjectionFactoryRegistry::instance()->createProjection(ossimFilename(filename), 0);
if (!projection)
{
itkGenericExceptionMacro(<< "OSSIM Instanciate projection FAILED ! ");
return EXIT_FAILURE;
}
}
hasMetaData = projection->saveState(geom_kwl);
if (!hasMetaData)
{
std::cerr << "ERROR: projection saveState return with a false flag !" << std::endl;
return EXIT_FAILURE;
}
otb::ImageKeywordlist otb_kwl;
otb_kwl.SetKeywordlist(geom_kwl);
otb_kwl.convertToOSSIMKeywordlist(geom_kwl2);
hasMetaData = projection->loadState(geom_kwl2);
if (!hasMetaData)
{
std::cerr << "ERROR: projection loadState return with a false flag !" << std::endl;
return EXIT_FAILURE;
}
hasMetaData = projection->saveState(geom_kwl3);
if (!hasMetaData)
{
std::cerr << "ERROR: projection saveState return with a false flag !" << std::endl;
return EXIT_FAILURE;
}
otb::ImageKeywordlist otb_kwl2;
otb_kwl2.SetKeywordlist(geom_kwl3);
file << "*** KEYWORD LIST ***\n";
file << otb_kwl;
file2 << "*** KEYWORD LIST ***\n";
file2 << otb_kwl2;
/** Search keyword in meter_per_pixel to truncate precision */
ossimString s;
double valueX, valueY;
otb_kwl.convertToOSSIMKeywordlist(geom_kwl2);
file << std::fixed << std::setprecision(5);
file2 << std::fixed << std::setprecision(5);
s = geom_kwl2.find("meters_per_pixel_x");
if (s != "")
{
valueX = s.toDouble();
file << "truncate_meter_per_pixel_x " << valueX << std::endl;
}
s = geom_kwl2.find("meters_per_pixel_y");
if (s != "")
{
valueY = s.toDouble();
file << "truncate_meter_per_pixel_y " << valueY << std::endl;
}
otb_kwl2.convertToOSSIMKeywordlist(geom_kwl3);
s = geom_kwl3.find("meters_per_pixel_x");
if (s != "")
{
valueX = s.toDouble();
file2 << "truncate_meter_per_pixel_x " << valueX << std::endl;
}
s = geom_kwl3.find("meters_per_pixel_y");
if (s != "")
{
valueY = s.toDouble();
file2 << "truncate_meter_per_pixel_y " << valueY << std::endl;
}
file.close();
file2.close();
return EXIT_SUCCESS;
}
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(otbImageKeywordlist);
//##>REGISTER_TEST(otbImageKeywordlist);
REGISTER_TEST(otbOssimJpegFileRessourceLeakTest);
REGISTER_TEST(otbMapProjectionAdapterTest);
REGISTER_TEST(otbOssimElevManagerTest2);
......
......@@ -9,7 +9,8 @@ set(OTBImageBaseTests
otbExtractROI2.cxx
otbComplexToVectorImageCastFilter.cxx
otbMultiChannelExtractROI.cxx
otbVectorImageTest.cxx
##>otbVectorImageTest.cxx
otbVectorImageLegacyTest.cxx
otbExtractROITestMetaData.cxx
otbTestMultiExtractMultiUpdate.cxx
otbExtractROI.cxx
......
......@@ -10,7 +10,7 @@ void RegisterTests()
REGISTER_TEST(otbComplexToVectorImageCastFilterTest);
REGISTER_TEST(otbMultiChannelExtractROI);
REGISTER_TEST(otbVectorImageLegacyTest);
REGISTER_TEST(otbVectorImageTest);
//##>REGISTER_TEST(otbVectorImageTest);
REGISTER_TEST(otbExtractROITestMetaData);
REGISTER_TEST(otbTestMultiExtractMultiUpdate);
REGISTER_TEST(otbExtractROI);
......
......@@ -123,34 +123,34 @@ int otbVectorImageLegacyTest(int argc, char* argv[])
return EXIT_SUCCESS;
}
int otbVectorImageTest(int argc, char* argv[])
{
if (argc < 3)
{
std::cout << argv[0] << "<image> <output information>" << std::endl;
return EXIT_FAILURE;
}
const char * inputFilename = argv[1];
const char * outputAsciiFilename = argv[2];
typedef double PixelType;
const unsigned int Dimension = 2;
typedef otb::VectorImage<PixelType, Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFilename);
reader->UpdateOutputInformation();
std::ofstream file;
ImageType::Pointer image = ImageType::New();
image = reader->GetOutput();
std::cout << image << std::endl;
file.open(outputAsciiFilename);
file << std::setprecision(15);
file << image;
file.close();
return EXIT_SUCCESS;
}
/*##>int otbVectorImageTest(int argc, char* argv[])
##>{
##> if (argc < 3)
##> {
##> std::cout << argv[0] << "<image> <output information>" << std::endl;
##> return EXIT_FAILURE;
##> }
##> const char * inputFilename = argv[1];
##> const char * outputAsciiFilename = argv[2];
##> typedef double PixelType;
##> const unsigned int Dimension = 2;
##> typedef otb::VectorImage<PixelType, Dimension> ImageType;
##> typedef otb::ImageFileReader<ImageType> ReaderType;
##> ReaderType::Pointer reader = ReaderType::New();
##> reader->SetFileName(inputFilename);
##> reader->UpdateOutputInformation();
##> std::ofstream file;
##> ImageType::Pointer image = ImageType::New();
##> image = reader->GetOutput();
##> std::cout << image << std::endl;
##> file.open(outputAsciiFilename);
##> file << std::setprecision(15);
##> file << image;
##> file.close();
##> return EXIT_SUCCESS;
##>}*/
......@@ -13,10 +13,10 @@ otbLogPolarTransform.cxx
otbGenericRSTransformNew.cxx
otbLogPolarTransformNew.cxx
otbForwardSensorModelGrid.cxx
otbSensorModel.cxx
##>otbSensorModel.cxx
otbGeocentricTransform.cxx
otbCreateProjectionWithOTB.cxx
otbSensorModelGrid.cxx
##>otbSensorModelGrid.cxx
otbGeocentricTransformNew.cxx
otbGenericMapProjection.cxx
otbStreamingWarpImageFilter.cxx
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iomanip>
#include <iostream>
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbForwardSensorModel.h"
#include "otbInverseSensorModel.h"
#include "otbDEMHandler.h"
int otbSensorModel(int argc, char* argv[])
{
if (argc != 3)
{
std::cout << argv[0] << " <input filename> <output filename>" << std::endl;
return EXIT_FAILURE;
}
char * filename = argv[1];
char * outFilename = argv[2];
std::ofstream file;
file.open(outFilename);
file << std::setprecision(15);
typedef otb::VectorImage<double, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
reader->UpdateOutputInformation();
file << "*** KEYWORD LIST ***\n";
file << reader->GetOutput()->GetImageKeywordlist();
file << "\n*** TRANSFORM ***\n";
otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(16.19688987731934);
typedef otb::ForwardSensorModel<double> ForwardSensorModelType;
ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New();
forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( forwardSensorModel->IsValidSensorModel() == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
itk::Point<double, 2> imagePoint;
imagePoint[0] = 10;
imagePoint[1] = 10;
// imagePoint[0]=3069;
// imagePoint[1]=1218;
itk::Point<double, 2> geoPoint;
geoPoint = forwardSensorModel->TransformPoint(imagePoint);
file << "Image to geo: " << imagePoint << " -> " << geoPoint << "\n";
typedef otb::InverseSensorModel<double> InverseSensorModelType;
InverseSensorModelType::Pointer inverseSensorModel = InverseSensorModelType::New();
inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( inverseSensorModel->IsValidSensorModel() == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
itk::Point<double, 2> reversedImagePoint;
reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint);
file << "Geo to image: " << geoPoint << " -> " << reversedImagePoint << "\n";
file.close();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iostream>
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbForwardSensorModel.h"
#include "otbInverseSensorModel.h"
int otbSensorModelGrid(int argc, char* argv[])
{
if (argc != 6)
{
std::cout << argv[0] << " <input filename> <output filename in x> <output filename in y> <size_x> <size_y>" << std::endl;
return EXIT_FAILURE;
}
char * filename = argv[1];
char * outFilenameX = argv[2];
char * outFilenameY = argv[3];
unsigned int size_x((unsigned int)atoi(argv[4]));
unsigned int size_y((unsigned int)atoi(argv[5]));
typedef otb::VectorImage<double, 2> VectorImageType;
typedef otb::Image<double, 2> ImageType;
typedef otb::ImageFileReader<VectorImageType> ReaderType;
typedef otb::ImageFileWriter<ImageType> WriterType;
typedef VectorImageType::SizeType SizeType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
reader->UpdateOutputInformation();
WriterType::Pointer writeErrorX = WriterType::New();
writeErrorX->SetFileName(outFilenameX);
WriterType::Pointer writeErrorY = WriterType::New();
writeErrorY->SetFileName(outFilenameY);
SizeType sizeIn = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
SizeType sizeOut;
sizeOut[0] = size_x;
sizeOut[1] = size_y;
ImageType::RegionType region;
region.SetIndex(0, 0);
region.SetSize(sizeOut);
ImageType::Pointer outputErrorX = ImageType::New();
outputErrorX->SetRegions(region);
outputErrorX->Allocate();
ImageType::Pointer outputErrorY = ImageType::New();
outputErrorY->SetRegions(region);
outputErrorY->Allocate();
const double averageElevation = 16.19688987731934;
otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(averageElevation);
typedef otb::ForwardSensorModel<double> ForwardSensorModelType;
ForwardSensorModelType::Pointer forwardSensorModel = ForwardSensorModelType::New();
forwardSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( forwardSensorModel->IsValidSensorModel() == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
typedef otb::InverseSensorModel<double> InverseSensorModelType;
InverseSensorModelType::Pointer inverseSensorModel = InverseSensorModelType::New();
inverseSensorModel->SetImageGeometry(reader->GetOutput()->GetImageKeywordlist());
if( inverseSensorModel->IsValidSensorModel() == false )
{
std::cout<<"Invalid Model pointer m_Model == NULL!\n The ossim keywordlist is invalid!"<<std::endl;
return EXIT_FAILURE;
}
double deltaX = static_cast<double>(sizeIn[0]) / static_cast<double>(size_x);
double deltaY = static_cast<double>(sizeIn[1]) / static_cast<double>(size_y);
for(unsigned int i = 0; i < size_x; ++i)
{
for(unsigned int j = 0; j < size_y; ++j)
{
itk::Point<double, 2> imagePoint;
imagePoint[0] = deltaX * i;
imagePoint[1] = deltaY * j;
itk::Point<double, 2> geoPoint;
geoPoint = forwardSensorModel->TransformPoint(imagePoint);
itk::Point<double, 2> reversedImagePoint;
reversedImagePoint = inverseSensorModel->TransformPoint(geoPoint);
double errorX = imagePoint[0] - reversedImagePoint[0];
double errorY = imagePoint[1] - reversedImagePoint[1];
ImageType::IndexType index;
index[0]= i;
index[1]= j;
outputErrorX->SetPixel(index, errorX);
outputErrorY->SetPixel(index, errorY);
}
}
writeErrorX->SetInput(outputErrorX);
writeErrorX->Update();
writeErrorY->SetInput(outputErrorY);
writeErrorY->Update();
return EXIT_SUCCESS;
}
......@@ -12,10 +12,10 @@ void RegisterTests()
REGISTER_TEST(otbGenericRSTransformNew);
REGISTER_TEST(otbLogPolarTransformNew);
REGISTER_TEST(otbForwardSensorModelGrid);
REGISTER_TEST(otbSensorModel);
//##>REGISTER_TEST(otbSensorModel);
REGISTER_TEST(otbGeocentricTransform);
REGISTER_TEST(otbCreateProjectionWithOTB);
REGISTER_TEST(otbSensorModelGrid);
//##>REGISTER_TEST(otbSensorModelGrid);
REGISTER_TEST(otbGeocentricTransformNew);
REGISTER_TEST(otbGenericMapProjection);
REGISTER_TEST(otbStreamingWarpImageFilter);
......
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