Commit eb2406ea authored by Julien Malik's avatar Julien Malik
Browse files

COMP: reintroduce VectorDataToImageFilter as a deprecated classes

parent c515d664
/*=========================================================================
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.
=========================================================================*/
#ifndef __otbVectorDataToImageFilter_h
#define __otbVectorDataToImageFilter_h
#include "itkImageSource.h"
#include "otbRGBAPixelConverter.h"
#include "otbVectorDataExtractROI.h"
#include "otbRemoteSensingRegion.h"
#include <mapnik/memory_datasource.hpp>
#include <mapnik/map.hpp>
namespace otb
{
/** \class VectorDataToImageFilter
* \brief <b>DEPRECATED</b>: See VectorDataToImageFilter
* \deprecated use VectorDataToImageFilter instead
* \sa VectorDataToImageFilter
*/
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. */
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
This diff is collapsed.
......@@ -871,6 +871,29 @@ ADD_TEST(coTvVectorDataToMapFilterNoFonts ${COMMON_TESTS9}
${TEMP}/coTvVectorDataToMapFilterNoFonts.png
)
# Deprecated class
ADD_TEST(coTvVectorDataToImageFilter ${COMMON_TESTS9}
--compare-image ${NOTOL}
${BASELINE}/coTvVectorDataToMapFilter.png
${TEMP}/coTvVectorDataToImageFilter.png
otbVectorDataToImageFilter
${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp
${TEMP}/coTvVectorDataToImageFilter.png
${INPUTDATA}/DejaVuSans.ttf # font
)
ADD_TEST(coTvVectorDataToImageFilterBinary ${COMMON_TESTS9}
--compare-image ${NOTOL}
${BASELINE}/coTvVectorDataToMapFilterBinary.png
${TEMP}/coTvVectorDataToImageFilterBinary.png
otbVectorDataToImageFilterBinary
${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp
${TEMP}/coTvVectorDataToImageFilterBinary.png
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
......@@ -1358,7 +1381,7 @@ otbVectorDataToMapFilter.cxx
otbVectorDataToMapFilterSensorModel.cxx
otbVectorDataToMapFilterWorld.cxx
otbVectorDataToMapFilterNoFonts.cxx
otbVectorDataToImageFilter.cxx
)
ENDIF(OTB_USE_MAPNIK)
......
......@@ -30,4 +30,8 @@ void RegisterTests()
REGISTER_TEST(otbVectorDataToMapFilterSensorModel);
REGISTER_TEST(otbVectorDataToMapFilterWorld);
REGISTER_TEST(otbVectorDataToMapFilterNoFonts);
// Deprecated
REGISTER_TEST(otbVectorDataToImageFilter);
REGISTER_TEST(otbVectorDataToImageFilterBinary);
}
/*=========================================================================
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 "otbVectorDataFileReader.h"
#include "otbImageFileWriter.h"
#include "otbVectorData.h"
#include "otbVectorDataProjectionFilter.h"
#include "otbVectorDataExtractROI.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