Commit e4e82131 authored by Guillaume Pasero's avatar Guillaume Pasero

REFAC: remove VectorDataToImageFilter (see OGRDataSourceToLabelImageFilter)

parent 3ae4e295
/*
* 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 otbVectorDataToImageFilter_h
#define otbVectorDataToImageFilter_h
#include "itkImageSource.h"
#include "otbRGBAPixelConverter.h"
#include "otbVectorDataExtractROI.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <mapnik/memory_datasource.hpp>
#include <mapnik/map.hpp>
#pragma GCC diagnostic pop
#else
#include <mapnik/memory_datasource.hpp>
#include <mapnik/map.hpp>
#endif
namespace otb
{
/** \class VectorDataToImageFilter
* \brief <b>DEPRECATED</b>: See VectorDataToImageFilter
* \deprecated use VectorDataToImageFilter instead
* \sa VectorDataToImageFilter
*
* \ingroup OTBVectorDataRendering
*/
template <class TVectorData, class TImage>
class ITK_EXPORT VectorDataToImageFilter : public itk::ImageSource<TImage>
{
public:
/** Standard class typedefs. */
typedef VectorDataToImageFilter Self;
typedef itk::ImageSource<TImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(VectorDataToImageFilter, ImageSource);
/** Some typedefs. */
typedef TVectorData VectorDataType;
typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename ImageType::Pointer ImagePointer;
typedef typename VectorDataType::ConstPointer VectorDataConstPointer;
typedef typename VectorDataType::DataTreeType::TreeNodeType InternalTreeNodeType;
typedef typename InternalTreeNodeType::ChildrenListType ChildrenListType;
typedef VectorDataExtractROI<VectorDataType> VectorDataExtractROIType;
typedef RemoteSensingRegion<double> RemoteSensingRegionType;
typedef typename RemoteSensingRegionType::SizeType SizePhyType;
/** Number of dimensions. */
itkStaticConstMacro(ImageDimension, unsigned int,
TImage::ImageDimension);
/** Image size typedef. */
typedef itk::Size<itkGetStaticConstMacro(ImageDimension)> SizeType;
/** Image index typedef. */
typedef typename TImage::IndexType IndexType;
/** Image spacing, origin and direction typedef */
typedef typename TImage::SpacingType SpacingType;
typedef typename TImage::PointType OriginType;
typedef typename TImage::DirectionType DirectionType;
/** Region typedef */
typedef typename TImage::RegionType RegionType;
/** RGBA Converter typedef */
typedef RGBAPixelConverter<unsigned char, PixelType> RGBAConverterType;
/** typedef specific to mapnik */
typedef boost::shared_ptr<mapnik::memory_datasource> datasource_ptr;
/** */
typedef enum
{
OSM,
Binary
} RenderingStyleType;
/** Set/Get the vector data input of this process object. */
using Superclass::SetInput;
virtual void SetInput(const VectorDataType *input);
virtual void SetInput(unsigned int idx, const VectorDataType *input);
const VectorDataType * GetInput(void);
const VectorDataType * GetInput(unsigned int idx);
/** Set the size of the output image. */
itkSetMacro(Size, SizeType);
/** Get the size of the output image. */
itkGetConstReferenceMacro(Size, SizeType);
/** Set the origin of the vector data.
* \sa GetOrigin() */
itkSetMacro(Origin, OriginType);
virtual void SetOrigin(const double origin[2]);
virtual void SetOrigin(const float origin[2]);
itkGetConstReferenceMacro(Origin, OriginType);
/** Set the spacing (size of a pixel) of the vector data.
* \sa GetSpacing() */
virtual void SetSpacing(const SpacingType& spacing);
virtual void SetSpacing(const double spacing[2]);
virtual void SetSpacing(const float spacing[2]);
itkGetConstReferenceMacro(Spacing, SpacingType);
/** Get/Set methods for the scale factor */
itkSetMacro(ScaleFactor, double);
itkGetMacro(ScaleFactor, double);
/** */
void AddStyle(const std::string& style)
{
m_StyleList.push_back(style);
}
/** Clear the style list */
void ClearStyleList()
{
m_StyleList.clear();
}
/** Specify if the output image is to be uses as an overlar
* (with transparent background) or not (with blue background).
*/
itkSetMacro(UseAsOverlay, bool);
itkGetMacro(UseAsOverlay, bool);
itkBooleanMacro(UseAsOverlay);
/** Get/Set methods for the rendering style type (OSM or Binary) */
itkSetMacro(RenderingStyleType, RenderingStyleType);
itkGetMacro(RenderingStyleType, RenderingStyleType);
/** Add accessors to the font filename */
itkSetStringMacro(FontFileName);
itkGetStringMacro(FontFileName);
/** Add accessors to the Projection in the WKT format */
itkSetStringMacro(VectorDataProjectionWKT);
itkGetStringMacro(VectorDataProjectionWKT);
protected:
/** Constructor */
VectorDataToImageFilter();
/** Destructor */
virtual ~VectorDataToImageFilter() {}
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void GenerateOutputInformation();
virtual void GenerateData(void);
virtual void BeforeThreadedGenerateData();
private:
VectorDataToImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
void ProcessNode(InternalTreeNodeType * source, datasource_ptr mDatasource);
SpacingType m_Spacing;
OriginType m_Origin;
SizeType m_Size;
IndexType m_StartIndex;
DirectionType m_Direction;
// font file name
std::string m_FontFileName;
//This factor is used to flip the data on the Y axis when using a
//sensor model geometry (where the Y coordinate increases top-down)
int m_SensorModelFlip;
//this parameter is used only in the case of sensor geometry
//to adjust the scale
double m_ScaleFactor;
//style list
std::vector<std::string> m_StyleList;
//Overlay option: change the backgroup (blue or transparent)
bool m_UseAsOverlay;
//Projection in the proj.4 format (for mapnik)
std::string m_VectorDataProjectionProj4;
//Projection in the WKT format
std::string m_VectorDataProjectionWKT;
//Rendering style type
RenderingStyleType m_RenderingStyleType;
//RGBA Converter
typename RGBAConverterType::Pointer m_RGBAConverter;
//Internal Tiling
unsigned int m_NbTile;
std::vector<RegionType> m_TilingRegions;
std::vector<mapnik::Map> m_Maps;
std::vector< std::vector<typename VectorDataExtractROIType::Pointer> >
m_VectorDataExtractors;
}; // end class
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbVectorDataToImageFilter.txx"
#endif
#endif
......@@ -26,7 +26,6 @@ otbVectorDataToMapFilterWorld.cxx
otbVectorDataToMapFilter.cxx
otbVectorDataToMapFilterNew.cxx
otbVectorDataToMapFilterNoFonts.cxx
otbVectorDataToImageFilter.cxx
otbVectorDataToMapFilterSensorModel.cxx
)
......@@ -82,25 +81,6 @@ otb_add_test(NAME coTvVectorDataToMapFilterNoFonts COMMAND otbVectorDataRenderin
${TEMP}/coTvVectorDataToMapFilterNoFonts.png
)
otb_add_test(NAME coTvVectorDataToImageFilter COMMAND otbVectorDataRenderingTestDriver
--compare-image ${NOTOL}
${BASELINE}/coTvVectorDataToMapFilter.png
${TEMP}/coTvVectorDataToImageFilter.png
otbVectorDataToImageFilter
LARGEINPUT{VECTOR/MidiPyrenees/roads.shp}
${TEMP}/coTvVectorDataToImageFilter.png
${INPUTDATA}/DejaVuSans.ttf # font
)
otb_add_test(NAME coTvVectorDataToImageFilterBinary COMMAND otbVectorDataRenderingTestDriver
--compare-image ${NOTOL}
${BASELINE}/coTvVectorDataToMapFilterBinary.png
${TEMP}/coTvVectorDataToImageFilterBinary.png
otbVectorDataToImageFilterBinary
LARGEINPUT{VECTOR/MidiPyrenees/roads.shp}
${TEMP}/coTvVectorDataToImageFilterBinary.png
)
otb_add_test(NAME coTvVectorDataToMapFilterSensorModel COMMAND otbVectorDataRenderingTestDriver
--compare-image ${NOTOL}
${BASELINE}/coTvVectorDataToMapFilterSensorModel.png
......
......@@ -27,7 +27,5 @@ void RegisterTests()
REGISTER_TEST(otbVectorDataToMapFilterBinary);
REGISTER_TEST(otbVectorDataToMapFilterNew);
REGISTER_TEST(otbVectorDataToMapFilterNoFonts);
REGISTER_TEST(otbVectorDataToImageFilter);
REGISTER_TEST(otbVectorDataToImageFilterBinary);
REGISTER_TEST(otbVectorDataToMapFilterSensorModel);
}
/*
* 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.
*/
#include "otbVectorDataFileReader.h"
#include "otbImageFileWriter.h"
#include "otbVectorData.h"
#include "otbVectorDataProjectionFilter.h"
#include <fstream>
#include <iostream>
#include "itkRGBAPixel.h"
#include "otbImage.h"
#include "otbVectorDataToImageFilter.h"
int otbVectorDataToImageFilter(int argc, char * argv [])
{
if (argc < 4)
{
std::cout << argv[0] << " <input vector filename> <input image filename> <font filename>" << std::endl;
return EXIT_FAILURE;
}
//Read the vector data
typedef otb::VectorData<> VectorDataType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
reader->SetFileName(argv[1]);
//Reproject the vector data in the proper projection
typedef otb::VectorDataProjectionFilter<VectorDataType, VectorDataType> ProjectionFilterType;
ProjectionFilterType::Pointer projection = ProjectionFilterType::New();
projection->SetInput(reader->GetOutput());
std::string projectionRefWkt =
"PROJCS[\"UTM Zone 31, Northern Hemisphere\", GEOGCS[\"WGS 84\", DATUM[\"WGS_1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\",\"9108\"]], AXIS[\"Lat\", NORTH], AXIS[\"Long\", EAST], AUTHORITY[\"EPSG\",\"4326\"]], PROJECTION[\"Transverse_Mercator\"], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 3], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], UNIT[\"Meter\", 1]]";
projection->SetOutputProjectionRef(projectionRefWkt);
//Convert the vector data into an image
typedef itk::RGBAPixel<unsigned char> PixelType;
typedef otb::Image<PixelType, 2> ImageType;
ImageType::SizeType size;
size[0] = 500;
size[1] = 500;
ImageType::PointType origin;
origin[0] = 374149.980555821; //UL easting
origin[1] = 4829183.99443839; //UL northing
ImageType::SpacingType spacing;
spacing[0] = 0.6;
spacing[1] = -0.6;
typedef otb::RemoteSensingRegion<double> RegionType;
RegionType region;
RegionType::SizeType sizeInUnit;
sizeInUnit[0] = size[0] * spacing[0];
sizeInUnit[1] = size[1] * spacing[1];
region.SetSize(sizeInUnit);
region.SetOrigin(origin);
region.SetRegionProjection(projectionRefWkt);
typedef otb::VectorDataExtractROI<VectorDataType> ExtractROIType;
ExtractROIType::Pointer extractROI = ExtractROIType::New();
extractROI->SetRegion(region);
extractROI->SetInput(projection->GetOutput());
typedef otb::VectorDataToImageFilter<VectorDataType, ImageType> VectorDataToImageFilterType;
VectorDataToImageFilterType::Pointer vectorDataRendering = VectorDataToImageFilterType::New();
vectorDataRendering->SetInput(extractROI->GetOutput());
vectorDataRendering->SetSize(size);
vectorDataRendering->SetOrigin(origin);
vectorDataRendering->SetSpacing(spacing);
vectorDataRendering->SetFontFileName(argv[3]);
vectorDataRendering->AddStyle("minor-roads-casing");
vectorDataRendering->AddStyle("roads-text");
//Save the image in a file
typedef otb::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(vectorDataRendering->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
return EXIT_SUCCESS;
}
int otbVectorDataToImageFilterBinary(int argc, char * argv [])
{
if (argc < 3)
{
std::cout << argv[0] << " <input vector filename> <input image filename>" << std::endl;
return EXIT_FAILURE;
}
//Read the vector data
typedef otb::VectorData<> VectorDataType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
reader->SetFileName(argv[1]);
//Reproject the vector data in the proper projection
typedef otb::VectorDataProjectionFilter<VectorDataType, VectorDataType> ProjectionFilterType;
ProjectionFilterType::Pointer projection = ProjectionFilterType::New();
projection->SetInput(reader->GetOutput());
std::string projectionRefWkt =
"PROJCS[\"UTM Zone 31, Northern Hemisphere\", GEOGCS[\"WGS 84\", DATUM[\"WGS_1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\",\"9108\"]], AXIS[\"Lat\", NORTH], AXIS[\"Long\", EAST], AUTHORITY[\"EPSG\",\"4326\"]], PROJECTION[\"Transverse_Mercator\"], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 3], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], UNIT[\"Meter\", 1]]";
projection->SetOutputProjectionRef(projectionRefWkt);
//Convert the vector data into an image
typedef itk::RGBAPixel<unsigned char> PixelType;
typedef otb::Image<PixelType, 2> ImageType;
ImageType::SizeType size;
size[0] = 500;
size[1] = 500;
ImageType::PointType origin;
origin[0] = 374149.980555821; //UL easting
origin[1] = 4829183.99443839; //UL northing
ImageType::SpacingType spacing;
spacing[0] = 0.6;
spacing[1] = -0.6;
typedef otb::RemoteSensingRegion<double> RegionType;
RegionType region;
RegionType::SizeType sizeInUnit;
sizeInUnit[0] = size[0] * spacing[0];
sizeInUnit[1] = size[1] * spacing[1];
region.SetSize(sizeInUnit);
region.SetOrigin(origin);
region.SetRegionProjection(projectionRefWkt);
typedef otb::VectorDataExtractROI<VectorDataType> ExtractROIType;
ExtractROIType::Pointer extractROI = ExtractROIType::New();
extractROI->SetRegion(region);
extractROI->SetInput(projection->GetOutput());
typedef otb::VectorDataToImageFilter<VectorDataType, ImageType> VectorDataToImageFilterType;
VectorDataToImageFilterType::Pointer vectorDataRendering = VectorDataToImageFilterType::New();
vectorDataRendering->SetInput(extractROI->GetOutput());
vectorDataRendering->SetSize(size);
vectorDataRendering->SetOrigin(origin);
vectorDataRendering->SetSpacing(spacing);
vectorDataRendering->SetRenderingStyleType(VectorDataToImageFilterType::Binary);
//Save the image in a file
typedef otb::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(vectorDataRendering->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
return EXIT_SUCCESS;
}
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