Commit 9269526e authored by Victor Poughon's avatar Victor Poughon

REFAC: remove TileMapImageIO

parent 9c5a6e7e
......@@ -249,7 +249,6 @@ SET( OTB_EXAMPLES_SRCS
${OTB_SOURCE_DIR}/Examples/IO/OGRWrappersExample.cxx
${OTB_SOURCE_DIR}/Examples/IO/DEMToImageGenerator.cxx
${OTB_SOURCE_DIR}/Examples/IO/DEMHandlerExample.cxx
${OTB_SOURCE_DIR}/Examples/IO/TileMapImageIOExample.cxx
${OTB_SOURCE_DIR}/Examples/Filtering/BinaryThresholdImageFilter.cxx
${OTB_SOURCE_DIR}/Examples/Filtering/ThresholdImageFilter.cxx
${OTB_SOURCE_DIR}/Examples/Filtering/CannyEdgeDetectionImageFilter.cxx
......
\chapter{Online data}\label{sec:Online}
With almost every computer connected to the Internet, the amount of
online information is steadily growing. It is quite easy to retrieve
valuable information. OTB has a few experimental classes for this
purpose.
For these examples to work, you need to have OTB compiled with the
\texttt{OTB\_USE\_CURL} option to \texttt{ON} (and the curl library
installed somewhere).
Let's see what we can do.
\section{Name to Coordinates}
\label{sec:NamesToCoordinates}
\input{PlaceNameToLonLatExample.tex}
\section{Open Street Map}
\label{sec:OpenStreetMap}
The power of sharing which is a driving force in open source software such
as OTB can also be demonstrated for data collection. One good example is
Open Street Map (\url{http://www.openstreetmap.org/}).
In this project, hundreds of thousands of users upload GPS data and draw maps of their
surroundings. The coverage is impressive and this data is freely available.
It is even possible to get the vector data (not covered yet by OTB), but
here we will focus on retrieving some nice maps for any place in the world. The following
example describes the method. This part is pretty experimental and the code is
not as polished as the rest of the library. You've been warned!
\input{TileMapImageIOExample.tex}
......@@ -246,7 +246,6 @@ colorlinks,linkcolor={blue},citecolor={blue},urlcolor={blue},
\input{ChangeDetection.tex}
\input{Hyperspectral.tex}
\input{Visualization.tex}
\input{Online.tex}
%%% \input{Applications.tex}
......
......@@ -73,9 +73,6 @@ target_link_libraries(StreamingImageReadWrite ${OTB_LIBRARIES})
add_executable(VectorDataIOExample VectorDataIOExample.cxx)
target_link_libraries(VectorDataIOExample ${OTB_LIBRARIES})
add_executable(TileMapImageIOExample TileMapImageIOExample.cxx)
target_link_libraries(TileMapImageIOExample ${OTB_LIBRARIES})
if(BUILD_TESTING)
add_subdirectory(test)
endif()
/*
* Copyright (C) 2005-2017 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.
*/
// Software Guide : BeginCommandLineArgs
// INPUTS: {osmfile.otb}
// OUTPUTS: {openStreetMap-Toulouse.png}
// ${GeneratedFolder} 1.4835345 43.55968261 13
// Software Guide : EndCommandLineArgs
// Software Guide : BeginCommandLineArgs
// INPUTS: {osmfile.otb}
// OUTPUTS: {openStreetMap-Singapore.png}
// ${GeneratedFolder} 103.780646 1.297643 13
// Software Guide : EndCommandLineArgs
// Software Guide : BeginLatex
//
// First, we need to include several headers. There will be a bit of
// manual work going on here.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkRGBPixel.h"
#include "otbImageFileReader.h"
#include "otbTileMapImageIO.h"
#include "otbInverseSensorModel.h"
#include "otbForwardSensorModel.h"
#include "otbExtractROI.h"
#include "otbImageFileWriter.h"
#include "otbTileMapTransform.h"
#include "otbWorldFile.h"
// Software Guide : EndCodeSnippet
int main(int argc, char* argv[])
{
if (argc != 7)
{
std::cout << argv[0] << " <inputFilename> <outputFilename> "
<< "<cacheDirectory> <lon> <lat> <depth>"
<< std::endl;
return EXIT_FAILURE;
}
// Software Guide : BeginLatex
//
// We retrieve the input parameters:
// \begin{itemize}
// \item the input filename is a simple text file specifying the access
// modality to open street map data;
// \item the output file is the image where you want to save the result;
// \item the cache directory is necessary to keep the data retrieved from
// the internet. It can also be reused to minimize network access;
// \item longitude of the center of the scene;
// \item latitude of the center of the scene;
// \item depth which is inversely related to the resolution: when you increase
// the depth by one, you divide the resolution by two.
// \end{itemize}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
std::string inputFilename = argv[1];
std::string outputFilename = argv[2];
std::string cacheDirectory = argv[3];
double lon = atof(argv[4]);
double lat = atof(argv[5]);
int depth = atoi(argv[6]);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We now instantiate the reader. As some parameters need to be given to the
// IO which is an \doxygen{otb}{TileMapImageIO}, we need to manually create it:
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::RGBPixel<unsigned char> RGBPixelType;
typedef otb::Image<RGBPixelType, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::TileMapImageIO ImageIOType;
ImageIOType::Pointer tileIO = ImageIOType::New();
ReaderType::Pointer readerTile = ReaderType::New();
tileIO->SetDepth(depth);
tileIO->SetCacheDirectory(cacheDirectory);
readerTile->SetImageIO(tileIO);
readerTile->SetFileName(inputFilename);
readerTile->UpdateOutputInformation();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Now, we potentially have an image of several Peta-Bytes covering the whole world
// in the reader
// that's why we don't want to do an update before extracting a specific
// area.
//
// The coordinates are referred with an origin at the North Pole and the
// change date meridian in Mercator projection. So we need to translate the latitude
// and the longitude in this funny coordinate system:
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::TileMapTransform<otb::TransformDirection::FORWARD> TransformType;
TransformType::Pointer transform = TransformType::New();
transform->SetDepth(depth);
typedef itk::Point <double, 2> PointType;
PointType lonLatPoint;
lonLatPoint[0] = lon;
lonLatPoint[1] = lat;
PointType tilePoint;
tilePoint = transform->TransformPoint(lonLatPoint);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// This enables us to use the \doxygen{otb}{ExtractROI} to retrieve only
// the area of interest and to avoid crashing our memory-limited computer.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
long int startX = static_cast<long int>(tilePoint[0]);
long int startY = static_cast<long int>(tilePoint[1]);
long int sizeX = 500;
long int sizeY = 500;
std::cerr << startX << ", " << startY << std::endl;
std::cerr << sizeX << ", " << sizeY << std::endl;
typedef otb::ExtractROI<RGBPixelType, RGBPixelType> ExtractROIFilterType;
ExtractROIFilterType::Pointer extractROIOsmFilter = ExtractROIFilterType::New();
extractROIOsmFilter->SetStartX(startX - sizeX / 2);
extractROIOsmFilter->SetStartY(startY - sizeY / 2);
extractROIOsmFilter->SetSizeX(sizeX);
extractROIOsmFilter->SetSizeY(sizeY);
extractROIOsmFilter->SetInput(readerTile->GetOutput());
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Finally, we just plug this to the writer to save our nice map of
// the area:
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(extractROIOsmFilter->GetOutput());
writer->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We also want to create the associated world file to be able to use this
// new image in a GIS system. For this, we need to compute the coordinates
// of the top left corner and the spacing in latitude and longitude.
//
// For that, we use the inverse transform to convert the corner coordinates into
// latitude and longitude.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef otb::TileMapTransform<otb::TransformDirection::INVERSE> InverseTransformType;
InverseTransformType::Pointer transformInverse = InverseTransformType::New();
transformInverse->SetDepth(depth);
double lonUL, latUL, lonSpacing, latSpacing;
tilePoint[0] = startX - sizeX / 2;
tilePoint[1] = startY - sizeY / 2;
lonLatPoint = transformInverse->TransformPoint(tilePoint);
lonUL = lonLatPoint[0];
latUL = lonLatPoint[1];
tilePoint[0] = startX + sizeX / 2;
tilePoint[1] = startY + sizeY / 2;
lonLatPoint = transformInverse->TransformPoint(tilePoint);
lonSpacing = (lonLatPoint[0] - lonUL) / (sizeX - 1);
latSpacing = (lonLatPoint[1] - latUL) / (sizeY - 1);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Now that we have all the information, we can write the world file
// which has the wld extension. This is a simple text file containing
// the coordinates of the center of the top left pixel and the x and y
// spacing.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
otb::WorldFile::Pointer worldFile = otb::WorldFile::New();
worldFile->SetImageFilename(outputFilename);
worldFile->SetLonOrigin(lonUL);
worldFile->SetLatOrigin(latUL);
worldFile->SetLonSpacing(lonSpacing);
worldFile->SetLatSpacing(latSpacing);
worldFile->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Figure~\ref{fig:TILEMAPIMAGEIOEXAMPLE} shows the output images created from
// open street map data.
//
// \begin{figure}
// \center
// \includegraphics[width=0.45\textwidth]{openStreetMap-Toulouse.eps}
// \includegraphics[width=0.45\textwidth]{openStreetMap-Singapore.eps}
// \itkcaption[Open street map]{Map created from open street map showing the OTB headquarters}
// \label{fig:TILEMAPIMAGEIOEXAMPLE}
// \end{figure}
//
// If your street is missing, go and improve the map by adding it yourself.
//
// Software Guide : EndLatex
return EXIT_SUCCESS;
}
......@@ -100,16 +100,3 @@ otb_add_test(NAME ioTeImageToKmzAndMapFileProductExample COMMAND ${OTB_TEST_DRIV
)
set_property(TEST ioTeImageToKmzAndMapFileProductExample PROPERTY RESOURCE_LOCK web_access)
endif()
otb_add_test(NAME ioTeTileMapImageIOExampleTest COMMAND ${OTB_TEST_DRIVER}
--compare-image 10.0
${BASELINE}/openStreetMap.png
${TEMP}/openStreetMap.png
Execute $<TARGET_FILE:TileMapImageIOExample>
${INPUTDATA}/osmfile.otb
${TEMP}/openStreetMap.png
${TEMP}
1.4835345
43.55968261
12
)
#
# Copyright (C) 2005-2017 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.
#
project(OTBIOTileMap)
set(OTBIOTileMap_LIBRARIES OTBIOTileMap)
otb_module_impl()
/*
* Copyright (C) 2005-2017 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.
*/
#ifndef otbTileMapImageIO_h
#define otbTileMapImageIO_h
/* C++ Libraries */
#include <string>
#include <vector>
//#include "stdlib.h"
/* ITK Libraries */
#include "otbImageIOBase.h"
#include "otbImageRegionTileMapSplitter.h"
#include "otbCurlHelperInterface.h"
#include "OTBIOTileMapExport.h"
namespace otb
{
namespace TileMapAddressingStyle
{
enum TileMapAddressingStyle {GM = 0, OSM = 1, NEARMAP = 2, LOCAL = 3};
}
/** \class TileMapImageIO
* \deprecated
* \brief ImageIO object for reading and writing TileMap images
*
*
*
* \ingroup OTBIOTileMap
*/
class OTBIOTileMap_DEPRECATED_EXPORT TileMapImageIO : public otb::ImageIOBase
{
public:
typedef unsigned char InputPixelType;
/** Standard class typedefs. */
typedef TileMapImageIO Self;
typedef otb::ImageIOBase Superclass;
typedef itk::SmartPointer<Self> Pointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(TileMapImageIO, otb::ImageIOBase);
typedef itk::ImageIORegion ImageIORegion;
/** Set/Get the level of compression for the output images.
* 0-9; 0 = none, 9 = maximum. */
itkSetMacro(CompressionLevel, int);
itkGetMacro(CompressionLevel, int);
/** Set/Get the maximum number of connections */
itkSetMacro(MaxConnect, int);
itkGetMacro(MaxConnect, int);
virtual void SetCacheDirectory(const char* _arg);
virtual void SetCacheDirectory(const std::string& _arg);
itkGetStringMacro(CacheDirectory);
itkSetMacro(Depth, int);
itkGetMacro(Depth, int);
itkGetStringMacro(FileSuffix);
itkSetStringMacro(FileSuffix);
/** Determine the file type. Returns true if this ImageIO can read the
* file specified. */
bool CanReadFile(const char*) override;
/** Determine the file type. Returns true if the ImageIO can stream read the specified file */
bool CanStreamRead() override
{
return true;
}
/** Set the spacing and dimension information for the set filename. */
void ReadImageInformation() override;
/** Reads the data from disk into the memory buffer provided. */
void Read(void* buffer) override;
/** Determine the file type. Returns true if this ImageIO can read the
* file specified. */
bool CanWriteFile(const char*) override;
/** Determine the file type. Returns true if the ImageIO can stream write the specified file */
bool CanStreamWrite() override
{
return true;
}
/** Writes the spacing and dimensions of the image.
* Assumes SetFileName has been called with a valid file name. */
void WriteImageInformation() override;
/** Writes the data to disk from the memory buffer provided. Make sure
* that the IORegion has been set properly. */
void Write(const void* buffer) override;
/** Get the number of overviews available into the file specified
* This imageIO didn't support overviews */
unsigned int GetOverviewsCount() override
{
// MANTIS-1154: Source image is always considered as the best
// resolution overview.
return 1;
}
/** Get information about overviews available into the file specified
* This imageIO didn't support overviews */
std::vector<std::string> GetOverviewsInfo() override
{
std::vector<std::string> desc;
return desc;
}
/** Provide hist about the output container to deal with complex pixel
* type (Not used here) */
void SetOutputImagePixelType( bool itkNotUsed(isComplexInternalPixelType),
bool itkNotUsed(isVectorImage)) override{}
protected:
/** Constructor.*/
TileMapImageIO();
/** Destructor.*/
~TileMapImageIO() override;
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
/** Read all information on the image*/
void InternalReadImageInformation();
/** Write all information on the image*/
void InternalWriteImageInformation();
unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(unsigned int numberOfRequestedSplits,
const ImageIORegion& pasteRegion) const override;
ImageIORegion GetSplitRegionForWritingCanStreamWrite(unsigned int ithPiece,
unsigned int numberOfActualSplits,
const ImageIORegion& pasteRegion) const override;
/** Number of bands of the image*/
int m_NbBands;
/** Determines the level of compression for written files.
* Range 0-9; 0 = none, 9 = maximum , default = 4 */
int m_CompressionLevel;
private:
/** Struct to save filename & tile associates */
typedef struct
{
int numTileX;
int numTileY;
double x;
double y;
std::string filename;
} TileNameAndCoordType;
TileMapImageIO(const Self &) = delete;
void operator =(const Self&) = delete;
void InternalWrite(double x, double y, const void* buffer);
void BuildFileName(const std::ostringstream& quad, std::ostringstream& filename, bool inCache = true) const;
void FillCacheFaults(void* buffer) const;
int XYToQuadTree(double x, double y, std::ostringstream& quad) const;
int XYToQuadTree2(double x, double y, std::ostringstream& quad) const;
/** CURL Multi */
void GenerateTileInfo(double x, double y, int numTileX, int numTileY);
bool CanReadFromCache(const std::string& filename);
void GenerateURL(double x, double y);
void GenerateBuffer(unsigned char * p);
void ReadTile(const std::string& filename, void * buffer);
std::vector<std::string> m_ListFilename;
std::vector<std::string> m_ListURLs;
std::vector<TileNameAndCoordType> m_ListTiles;
int m_MaxConnect;
CurlHelperInterface::Pointer m_Curl;
/** Byte per pixel pixel */
int m_BytePerPixel;
/** Tile size (heavily tested for the default 256 only) */
int m_TileSize;
/** Resolution depth*/
int m_Depth;
bool m_UseCache;
std::string m_CacheDirectory;
std::string m_ServerName;
std::string m_FileSuffix;
TileMapAddressingStyle::TileMapAddressingStyle m_AddressMode;
bool m_FlagWriteImageInformation;
bool m_FileNameIsServerName;
typedef otb::ImageRegionTileMapSplitter<2> SplitterType;
SplitterType::Pointer m_TileMapSplitter;
};
} // end namespace otb
#endif // otbTileMapImageIO_h
/*
* Copyright (C) 2005-2017 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.
*/
#ifndef otbTileMapImageIOFactory_h
#define otbTileMapImageIOFactory_h
#include "itkObjectFactoryBase.h"
#include "OTBIOTileMapExport.h"
namespace otb
{
/** \class TileMapImageIOFactory
* \deprecated
* \brief Creation of a TileMapImageIO object using object factory.
*
* \ingroup OTBIOTileMap
*/
class OTBIOTileMap_DEPRECATED_EXPORT TileMapImageIOFactory : public itk::ObjectFactoryBase
{
public:
/** Standard class typedefs. */
typedef TileMapImageIOFactory Self;
typedef itk::ObjectFactoryBase Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Class methods used to interface with the registered factories. */
const char* GetITKSourceVersion(void) const override;
const char* GetDescription(void) const override;
/** Method for class instantiation. */
itkFactorylessNewMacro(Self);
static TileMapImageIOFactory * FactoryNew() { return new TileMapImageIOFactory; }
/** Run-time type information (and related methods). */
itkTypeMacro(TileMapImageIOFactory, itk::ObjectFactoryBase);
/** Register one factory of this type */
static void RegisterOneFactory(void)
{
TileMapImageIOFactory::Pointer TileMapFactory = TileMapImageIOFactory::New();
itk::ObjectFactoryBase::RegisterFactory(TileMapFactory);
}
protected:
TileMapImageIOFactory();
~TileMapImageIOFactory() override;
private:
TileMapImageIOFactory(const Self &) = delete;
void operator =(const Self&) = delete;
};
} // end namespace otb
#endif
/*
* Copyright (C) 2005-2017 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.
*/
#ifndef otbTileMapImageIOHelper_h
#define otbTileMapImageIOHelper_h
#include "itkObject.h"
#include "itkObjectFactory.h"
#include <string>
#include <sstream>
#include "OTBIOTileMapExport.h"
namespace otb
{
/** \class TileMapImageIOHelper
* \deprecated
* \brief This class IO TileMapImage