diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesProjectionFilter.h b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesProjectionFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..a34a189ddbf2bdd395e03e6da9745b77612727d7 --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesProjectionFilter.h @@ -0,0 +1,66 @@ +/*========================================================================= + + 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 __otbGeometriesProjectionFilter_h +#define __otbGeometriesProjectionFilter_h + +#include "otbGeometriesToGeometriesFilter.h" + +namespace otb +{ +class ITK_EXPORT GeometriesProjectionFilter : public GeometriesToGeometriesFilter + { +public: + /**\name Standard ITK typedefs */ + //@{ + typedef GeometriesProjectionFilter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + //@} + + /**\name I/O typedefs */ + //@{ + typedef SuperClass::InputGeometriesType InputGeometriesType; + typedef SuperClass::InputGeometriesPointer InputGeometriesPointer; + typedef SuperClass::OutputGeometriesType OutputGeometriesType; + typedef SuperClass::OutputGeometriesPointer OutputGeometriesPointer; + //@} + + /**\name Standard macros */ + //@{ + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(GeometriesProjectionFilter, GeometriesToGeometriesFilter); + //@} + +protected: + GeometriesProjectionFilter(); + virtual ~GeometriesProjectionFilter(); + + virtual DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination); + + }; +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbGeometriesProjectionFilter.txx" +#endif + +#endif // __otbGeometriesProjectionFilter_h diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSet.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSet.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4f4c3d7af9bca40adaf1ab13ff13b618e59911f1 --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSet.cxx @@ -0,0 +1,66 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +/*===========================================================================*/ +/*===============================[ Includes ]================================*/ +/*===========================================================================*/ +#include "otbGeometriesSet.h" + +/*===========================================================================*/ +/*==============================[ other stuff ]==============================*/ +/*===========================================================================*/ + +otb::GeometriesSet::GeometriesSet() +{ +} + +/*virtual*/ otb::GeometriesSet::~GeometriesSet() +{ +} + +void otb::GeometriesSet::Set(ogr::Layer layer) +{ + m_geometriesSet = layer; +} + +void otb::GeometriesSet::Set(ogr::DataSource::Pointer datasource) +{ + m_geometriesSet = datasource; +} + +struct Printer : boost::static_visitor<> +{ + Printer(std::ostream& os, itk::Indent indent) + : m_os(os), m_indent(indent) {} + void operator()(otb::ogr::Layer layer) const + { + layer.PrintSelf(m_os, m_indent); + } + void operator()(otb::ogr::DataSource::Pointer datasource) const + { + datasource->Print(m_os, m_indent); + } +private: + std::ostream &m_os; + itk::Indent m_indent; +}; + +void otb::GeometriesSet::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->apply(Printer(os, indent)); +} diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSet.h b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSet.h new file mode 100644 index 0000000000000000000000000000000000000000..3fe6a7c68cbe3a80d4a5222d1f32af45aaf393e7 --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSet.h @@ -0,0 +1,98 @@ +/*========================================================================= + + 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 __otbGeometriesSet_h +#define __otbGeometriesSet_h + +#include <boost/variant.hpp> +#include "itkDataObject.h" +// #include "otbOGRLayerWrapper.h" +#include "otbOGRDataSourceWrapper.h" + +namespace otb +{ +class ITK_EXPORT GeometriesSet : public itk::DataObject + { +public: + /**\name Standard ITK typedefs */ + //@{ + typedef GeometriesSet Self; + typedef itk::DataObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + //@} + + /**\name Standard macros */ + //@{ + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(GeometriesSet, itk::DataObject); + //@} + + /**\name Geometries accessors */ + //@{ + void Set(ogr::Layer layer); + void Set(ogr::DataSource::Pointer datasource); + //@} + + template <typename Visitor> + void apply(Visitor const& visitor) + { + boost::apply_visitor(visitor, m_geometriesSet); + } + + template <typename Visitor> + void apply(Visitor const& visitor) const + { + boost::apply_visitor(visitor, m_geometriesSet); + } + + template <typename Visitor> + void apply(Visitor const& visitor, Self & visitable) + { + boost::apply_visitor(visitor, m_geometriesSet, visitable.m_geometriesSet); + } + + template <typename Visitor> + void apply(Visitor const& visitor, Self /*const*/& visitable) const + { + boost::apply_visitor(visitor, m_geometriesSet, visitable.m_geometriesSet); + } + + +protected: + /** Default constructor. */ + GeometriesSet(); + /** Destructor. */ + virtual ~GeometriesSet(); + + /** Prints self to stream. */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; +private: + typedef boost::variant<ogr::DataSource::Pointer, ogr::Layer> AnyGeometriesSetType; + AnyGeometriesSetType m_geometriesSet; + }; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +// #include "otbGeometriesSet.txx" +#endif + +#endif // __otbGeometriesSet_h diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSource.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSource.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7578c1dbe5edd976ee7c60ac93b55cba08680a5a --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSource.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +/*===========================================================================*/ +/*===============================[ Includes ]================================*/ +/*===========================================================================*/ +#include "otbGeometriesSource.h" +#include "otbGeometriesSet.h" + +/*===========================================================================*/ +/*==============================[ other stuff ]==============================*/ +/*===========================================================================*/ + +otb::GeometriesSource::GeometriesSource() +{ + Superclass::SetNumberOfRequiredOutputs(1); + // The default behaviour is to prepare a in-memory OGR datasource in case + // filters are piped. + // In the filter is meant to produce a file, use SetOutput, or the New(string) + // function to built the GeometriesSource and filters + ogr::DataSource::Pointer inMemoryDS = ogr::DataSource::New(); + Superclass::SetNthOutput(0, inMemoryDS); +} + +/*virtual*/ otb::GeometriesSource::~GeometriesSource() +{ +} + +/*virtual*/ +otb::GeometriesSource::OutputGeometriesType* otb::GeometriesSource::GetOutput(void ) +{ + return static_cast<GeometriesSet*> (Superclass::GetOutput(0)); +} + +/*virtual*/ +otb::GeometriesSource::OutputGeometriesType* otb::GeometriesSource::GetOutput(unsigned int idx) +{ + return static_cast<GeometriesSet*> (Superclass::GetOutput(idx)); +} + +/*virtual*/ +void otb::GeometriesSource::SetOutput(OutputGeometriesType* output, unsigned int idx/* = 0 */) +{ + Superclass::SetNthOutput(idx, output); +} diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSource.h b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSource.h new file mode 100644 index 0000000000000000000000000000000000000000..6ac58575b85bd718a8ac76c334e55ea1bf7b6eab --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesSource.h @@ -0,0 +1,92 @@ +/*========================================================================= + + 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 __otbGeometriesSource_h +#define __otbGeometriesSource_h + +#include <boost/noncopyable.hpp> +#include "itkProcessObject.h" +#include "itkObjectFactory.h" +#include "itkMacro.h" + +// Forward declarations +namespace otb +{ +namespace ogr +{ +class DataSource; +class Layer; +} // ogr namespace +class GeometriesSet; +} // otb namespace + + +namespace otb +{ + +// todo: disable graft +class ITK_EXPORT GeometriesSource : public itk::ProcessObject, boost::noncopyable + { +public: + /**\name Standard ITK typedefs */ + //@{ + typedef GeometriesSource Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + //@} + + /**\name I/O typedefs */ + //@{ + typedef GeometriesSet OutputGeometriesType; + // typedef GeometriesSet::Pointer OutputGeometriesPointer; + //@} + + + /**\name Standard macros */ + //@{ + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(VectorDataSource, itk::ProcessObject); + //@} + + /** Overriding \c GetOutput() functions */ + virtual OutputGeometriesType* GetOutput(void); + /** Overriding \c GetOutput() functions */ + virtual OutputGeometriesType* GetOutput(unsigned int idx); + + virtual void SetOutput(OutputGeometriesType* output, unsigned int idx = 0); + +protected: + GeometriesSource(); + virtual ~GeometriesSource(); + + // Inherited definition is enough + // void PrintSelf(std::ostream& os, itk::Indent indent) const; + + // /** Ensures that the output vector data are cleared before processing. */ + // virtual void AllocateOutputs(); + }; +} // end namespace otb + +// #ifndef OTB_MANUAL_INSTANTIATION +// #include "otbGeometriesSource.txx" +// #endif + +#endif // __otbGeometriesSource_h diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e838625644d7a32400fa733ba80b2a30aa8a622b --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx @@ -0,0 +1,124 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +/*===========================================================================*/ +/*===============================[ Includes ]================================*/ +/*===========================================================================*/ +#include "otbGeometriesToGeometriesFilter.h" +#include "otbGeometriesSet.h" +#include "itkMacro.h" +#include "itkTimeProbe.h" +#include "otbMacro.h" + +/*===========================================================================*/ +/*==============================[ other stuff ]==============================*/ +/*===========================================================================*/ + +otb::GeometriesToGeometriesFilter::GeometriesToGeometriesFilter() +{ +} + +/*virtual*/ otb::GeometriesToGeometriesFilter::~GeometriesToGeometriesFilter() +{ +} + +/*virtual*/ void otb::GeometriesToGeometriesFilter::SetInput( + const InputGeometriesType * input) +{ + // Process object is not const-correct so the const_cast is required here + this->itk::ProcessObject::SetNthInput( + 0, + const_cast<InputGeometriesType *>(input)); +} + +const otb::GeometriesToGeometriesFilter::InputGeometriesType * +otb::GeometriesToGeometriesFilter::GetInput(void ) +{ + return static_cast <InputGeometriesType*>(Superclass::GetInput(0)); +} + + +struct ProcessVisitor : boost::static_visitor<> +{ + ProcessVisitor(otb::GeometriesToGeometriesFilter const& filter) + : m_filter(filter) {} + void operator()(otb::ogr::Layer const& source, otb::ogr::Layer & destination) const + { + std::cout << "G2GF: Process Visitor: L -> L ("<< source.GetName()<<")...\n"; + m_filter.DoProcessLayer(source, destination); + } + void operator()(otb::ogr::DataSource::Pointer source, otb::ogr::DataSource::Pointer destination) const + { + std::cout << "G2GF: Process Visitor: DS("<<source->ogr().GetName()<<") -> DS("<<source->ogr().GetName()<<") ...\n"; + for (otb::ogr::DataSource::const_iterator b = source->begin(), e = source->end() + ; b != e + ; ++b + ) + { + otb::ogr::Layer const& sourceLayer = *b; + otb::ogr::Layer destLayer = destination->CreateLayer( + sourceLayer.GetName(), 0, sourceLayer.GetGeomType()); + m_filter.DoProcessLayer(sourceLayer, destLayer); + } + } + + template <typename GT1, typename GT2> void operator()(GT1 const&, GT2 &) const + { + assert(!"You shall not mix DataSources and Layers in GeometriesToGeometriesFilter"); + itkGenericExceptionMacro(<<"You shall not mix DataSources and Layers in GeometriesToGeometriesFilter"); + } +private: + otb::GeometriesToGeometriesFilter const& m_filter; +}; + +/*virtual*/ void otb::GeometriesToGeometriesFilter::Process( + InputGeometriesType const& source, OutputGeometriesType & destination) +{ + std::cout << "G2GF: Processing ...\n"; + // si layer, appelle virt process layer + // si DS, loop et appelle virt process layer + source.apply(ProcessVisitor(*this), destination); +} + +/*virtual*/ +void otb::GeometriesToGeometriesFilter::GenerateOutputInformation(void ) +{ + Superclass::GenerateOutputInformation(); + +#if 0 + // Apply only with data sources + OutputGeometriesType::Pointer output = this->GetOutput(); + InputGeometriesType::Pointer input = this->GetInput(); + output->SetMetaDataDictionary(input->GetMetaDataDictionary()); +#endif +} + +/*virtual*/ +void otb::GeometriesToGeometriesFilter::GenerateData(void ) +{ + // this->AllocateOutputs(); + OutputGeometriesType::Pointer output = this->GetOutput(); + InputGeometriesType::ConstPointer input = this->GetInput(); + + // Start recursive processing + itk::TimeProbe chrono; + chrono.Start(); + this->Process(*input, *output); + chrono.Stop(); + otbMsgDevMacro(<< "GeometriesToGeometriesFilter: geometries processed in " << chrono.GetMeanTime() << " seconds."); +} diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.h b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..54c1108f7a48111e9f8d7c4b1c829fd2c87c5ca9 --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.h @@ -0,0 +1,177 @@ +/*========================================================================= + + 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 __otbGeometriesToGeometriesFilter_h +#define __otbGeometriesToGeometriesFilter_h + +#include "otbGeometriesSource.h" +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include "otbOGRFeatureWrapper.h" +#include "otbOGRLayerWrapper.h" + +struct ProcessVisitor; +namespace otb +{ +class ITK_EXPORT GeometriesToGeometriesFilter : public GeometriesSource + { +public: + /**\name Standard ITK typedefs */ + //@{ + typedef GeometriesToGeometriesFilter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + //@} + + /**\name I/O typedefs */ + //@{ + typedef GeometriesSet InputGeometriesType; + // typedef GeometriesSet::Pointer InputGeometriesPointer; + typedef GeometriesSet OutputGeometriesType; + // typedef GeometriesSet::Pointer OutputGeometriesPointer; + //@} + + /**\name Standard macros */ + //@{ + /** Method for creation through the object factory. */ + // itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(GeometriesToGeometriesFilter, GeometriesSource); + //@} + + virtual void SetInput(const InputGeometriesType *input); + const InputGeometriesType * GetInput(void); + +protected: + /** Constructor */ + GeometriesToGeometriesFilter(); + /** Destructor */ + virtual ~GeometriesToGeometriesFilter(); + + virtual void GenerateOutputInformation(void); + virtual void GenerateData(void); + +private: + void Process( + InputGeometriesType const& source, OutputGeometriesType &destination); + virtual void DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const=0; + friend struct ::ProcessVisitor; + }; + + +template <class TransformationFunctor, class TransformedElementType> +struct TransformationFunctorDispatcher + { + }; + +template <class TransformationFunctor> +struct TransformationFunctorDispatcher<TransformationFunctor, ogr::Layer> + { + typedef typename TransformationFunctor::TransformedElementType TransformedElementType; + BOOST_MPL_ASSERT((boost::is_same<ogr::Layer, TransformedElementType>)); + TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor){ } + void operator()(ogr::Layer const& in, ogr::Layer & out) const + { + m_functor(in, out); + } +private: + TransformationFunctor m_functor; + }; + + +template <class TransformationFunctor> +struct TransformationFunctorDispatcher<TransformationFunctor, OGRGeometry> + { + typedef typename TransformationFunctor::TransformedElementType TransformedElementType; + BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, TransformedElementType>)); + TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor){ } + void operator()(ogr::Layer const& in, ogr::Layer & out) const + { + OGRFeatureDefn & defn = out.GetLayerDefn(); + for (ogr::Layer::const_iterator b = in.begin(), e = in.end() + ; b != e + ; ++b + ) + { + ogr::Feature const feat = *b; + ogr::UniqueGeometryPtr g = m_functor(feat.GetGeometry()); + // TODO: field transformations... + ogr::Feature dest(defn); + dest.SetGeometryDirectly(boost::move(g)); + out.CreateFeature(dest); + } + } +private: + TransformationFunctor m_functor; + }; + + +template <class TransformationFunctor> +class ITK_EXPORT DefaultGeometriesToGeometriesFilter : public GeometriesToGeometriesFilter +{ +public: + /**\name Standard ITK typedefs */ + //@{ + typedef DefaultGeometriesToGeometriesFilter Self; + typedef GeometriesToGeometriesFilter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + //@} + /**\name Class typedefs */ + //@{ + typedef TransformationFunctor TransformationFunctorType; + typedef typename TransformationFunctor::TransformedElementType TransformedElementType; + typedef TransformationFunctorDispatcher<TransformationFunctorType, TransformedElementType> + TransformationFunctorDispatcherType; + //@} + + /**\name Standard macros */ + //@{ + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(DefaultGeometriesToGeometriesFilter, GeometriesToGeometriesFilter); + //@} + +protected: + /** Default constructor. */ + DefaultGeometriesToGeometriesFilter(); + /** Destructor. */ + virtual ~DefaultGeometriesToGeometriesFilter(); + + /** Prints self to stream. */ + // void PrintSelf(std::ostream& os, itk::Indent indent) const; + + virtual void DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const + { + m_TransformationFunctor(source, destination); // if TransformedElementType == layer + }; +private: + TransformationFunctorDispatcherType m_TransformationFunctor; +}; + + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbGeometriesToGeometriesFilter.txx" +#endif + +#endif // __otbGeometriesToGeometriesFilter_h diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.txx b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..76f76ab4af36e912a13c6792a66e80111ff289fa --- /dev/null +++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.txx @@ -0,0 +1,37 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +/*===========================================================================*/ +/*===============================[ Includes ]================================*/ +/*===========================================================================*/ + +/*===========================================================================*/ +/*==============================[ other stuff ]==============================*/ +/*===========================================================================*/ + +template <class TransformationFunctor> +inline +otb::DefaultGeometriesToGeometriesFilter<TransformationFunctor>::DefaultGeometriesToGeometriesFilter() +: m_TransformationFunctor(TransformationFunctor()) +{} + +template <class TransformationFunctor> +inline +/*virtual*/ +otb::DefaultGeometriesToGeometriesFilter<TransformationFunctor>::~DefaultGeometriesToGeometriesFilter() +{} diff --git a/Examples/Filtering/CMakeLists.txt b/Examples/Filtering/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e59c88e32f9858cb39a4d9b3bccbca41853133e6 --- /dev/null +++ b/Examples/Filtering/CMakeLists.txt @@ -0,0 +1,300 @@ +PROJECT(FilteringExamples) +INCLUDE_REGULAR_EXPRESSION("^.*$") + +ADD_EXECUTABLE(CompositeFilterExample CompositeFilterExample.cxx ) +TARGET_LINK_LIBRARIES(CompositeFilterExample OTBCommon OTBIO ITKBasicFilters) + +ADD_EXECUTABLE(GradientMagnitudeImageFilter GradientMagnitudeImageFilter.cxx ) +TARGET_LINK_LIBRARIES(GradientMagnitudeImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(GradientMagnitudeRecursiveGaussianImageFilter GradientMagnitudeRecursiveGaussianImageFilter.cxx ) +TARGET_LINK_LIBRARIES(GradientMagnitudeRecursiveGaussianImageFilter +OTBCommon OTBIO) + +ADD_EXECUTABLE(SecondDerivativeRecursiveGaussianImageFilter SecondDerivativeRecursiveGaussianImageFilter.cxx ) +TARGET_LINK_LIBRARIES(SecondDerivativeRecursiveGaussianImageFilter +OTBCommon OTBIO) + +ADD_EXECUTABLE(BinaryThresholdImageFilter BinaryThresholdImageFilter.cxx ) +TARGET_LINK_LIBRARIES(BinaryThresholdImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(ThresholdImageFilter ThresholdImageFilter.cxx ) +TARGET_LINK_LIBRARIES(ThresholdImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(CannyEdgeDetectionImageFilter CannyEdgeDetectionImageFilter.cxx ) +TARGET_LINK_LIBRARIES(CannyEdgeDetectionImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(DerivativeImageFilter DerivativeImageFilter.cxx ) +TARGET_LINK_LIBRARIES(DerivativeImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(MedianImageFilter MedianImageFilter.cxx ) +TARGET_LINK_LIBRARIES(MedianImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(MeanImageFilter MeanImageFilter.cxx ) +TARGET_LINK_LIBRARIES(MeanImageFilter OTBCommon OTBIO) + +ADD_EXECUTABLE(MathematicalMorphologyBinaryFilters MathematicalMorphologyBinaryFilters.cxx ) +TARGET_LINK_LIBRARIES(MathematicalMorphologyBinaryFilters OTBCommon +OTBIO) + +ADD_EXECUTABLE(MathematicalMorphologyGrayscaleFilters MathematicalMorphologyGrayscaleFilters.cxx ) +TARGET_LINK_LIBRARIES(MathematicalMorphologyGrayscaleFilters OTBCommon +OTBIO) + +ADD_EXECUTABLE(DiscreteGaussianImageFilter DiscreteGaussianImageFilter.cxx ) +TARGET_LINK_LIBRARIES(DiscreteGaussianImageFilter OTBCommon OTBIO ITKBasicFilters) + +ADD_EXECUTABLE(LaplacianRecursiveGaussianImageFilter1 LaplacianRecursiveGaussianImageFilter1.cxx ) +TARGET_LINK_LIBRARIES(LaplacianRecursiveGaussianImageFilter1 OTBCommon +OTBIO ITKBasicFilters) + +ADD_EXECUTABLE(LaplacianRecursiveGaussianImageFilter2 LaplacianRecursiveGaussianImageFilter2.cxx ) +TARGET_LINK_LIBRARIES(LaplacianRecursiveGaussianImageFilter2 OTBCommon +OTBIO ITKBasicFilters) + +ADD_EXECUTABLE(GradientAnisotropicDiffusionImageFilter GradientAnisotropicDiffusionImageFilter.cxx ) +TARGET_LINK_LIBRARIES(GradientAnisotropicDiffusionImageFilter +OTBCommon OTBIO ITKBasicFilters) + +ADD_EXECUTABLE(DanielssonDistanceMapImageFilter DanielssonDistanceMapImageFilter.cxx ) +TARGET_LINK_LIBRARIES(DanielssonDistanceMapImageFilter OTBCommon OTBIO +ITKCommon ITKBasicFilters) + +ADD_EXECUTABLE(GeometriesFilter GeometriesFilter.cxx) +TARGET_LINK_LIBRARIES(GeometriesFilter OTBOGRAdapters) + +IF(OTB_USE_MAPNIK) +ADD_EXECUTABLE(RasterizationExample RasterizationExample.cxx) +TARGET_LINK_LIBRARIES(RasterizationExample OTBCommon OTBIO OTBBasicFilters) +ENDIF(OTB_USE_MAPNIK) + +IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) + + +SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/Filtering) + +SET(INPUTDATA ${OTB_DATA_ROOT}/Examples) +SET(TEMP ${OTB_BINARY_DIR}/Testing/Temporary) + +SET(EXE_TESTS ${CXX_TEST_PATH}/otbFilteringExamplesTests) + +SET(TOL 0.0) +SET(PNGTOL 2) + +# ------- MathematicalMorphologyBinaryFiltersTest---------- + +ADD_TEST(fiTeMathematicalMorphologyBinaryFiltersTest ${EXE_TESTS} + --compare-n-images ${TOL} 2 + ${BASELINE}/MathematicalMorphologyBinaryErosionOutput.png + ${TEMP}/MathematicalMorphologyBinaryErosionOutput.png + ${BASELINE}/MathematicalMorphologyBinaryDilationOutput.png + ${TEMP}/MathematicalMorphologyBinaryDilationOutput.png + MathematicalMorphologyBinaryFiltersTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/MathematicalMorphologyBinaryErosionOutput.png + ${TEMP}/MathematicalMorphologyBinaryDilationOutput.png + 150 180 +) + +# ------- DanielssonDistanceMapImageFilterTest---------- + +ADD_TEST(fiTeDanielssonDistanceMapImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 2 + ${BASELINE}/DanielssonDistanceMapImageFilterOutput1.png + ${TEMP}/DanielssonDistanceMapImageFilterOutput1.png + ${BASELINE}/DanielssonDistanceMapImageFilterOutput2.png + ${TEMP}/DanielssonDistanceMapImageFilterOutput2.png + DanielssonDistanceMapImageFilterTest + ${INPUTDATA}/FivePoints.png + ${TEMP}/DanielssonDistanceMapImageFilterOutput1.png + ${TEMP}/DanielssonDistanceMapImageFilterOutput2.png +) + +# ------- MeanImageFilterTest---------- + +ADD_TEST(fiTeMeanImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/MeanImageFilterOutput.png + ${TEMP}/MeanImageFilterOutput.png + MeanImageFilterTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/MeanImageFilterOutput.png +) + +# ------- ThresholdImageFilterTest---------- + +ADD_TEST(fiTeThresholdImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 3 + ${BASELINE}/ThresholdImageFilterOutputBelow.png + ${TEMP}/ThresholdImageFilterOutputBelow.png + ${BASELINE}/ThresholdImageFilterOutputAbove.png + ${TEMP}/ThresholdImageFilterOutputAbove.png + ${BASELINE}/ThresholdImageFilterOutputOutside.png + ${TEMP}/ThresholdImageFilterOutputOutside.png + ThresholdImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/ThresholdImageFilterOutputBelow.png + ${TEMP}/ThresholdImageFilterOutputAbove.png + ${TEMP}/ThresholdImageFilterOutputOutside.png +) + +# ------- GradientMagnitudeRecursiveGaussianImageFilterTest---------- + +ADD_TEST(fiTeGradientMagnitudeRecursiveGaussianImageFilterTest ${EXE_TESTS} + --compare-n-images ${PNGTOL} 1 + ${BASELINE}/GradientMagnitudeRecursiveGaussianImageFilterOutput3.png + ${TEMP}/GradientMagnitudeRecursiveGaussianImageFilterOutput3.png + GradientMagnitudeRecursiveGaussianImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/GradientMagnitudeRecursiveGaussianImageFilterOutput3.png + 3 +) + +# ------- GradientMagnitudeRecursiveGaussianImageFilterTest---------- + +ADD_TEST(fiTeGradientMagnitudeRecursiveGaussianImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/GradientMagnitudeRecursiveGaussianImageFilterOutput5.png + ${TEMP}/GradientMagnitudeRecursiveGaussianImageFilterOutput5.png + GradientMagnitudeRecursiveGaussianImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/GradientMagnitudeRecursiveGaussianImageFilterOutput5.png + 5 +) + +# ------- GradientAnisotropicDiffusionImageFilterTest---------- + +ADD_TEST(fiTeGradientAnisotropicDiffusionImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/GradientAnisotropicDiffusionImageFilterOutput.png + ${TEMP}/GradientAnisotropicDiffusionImageFilterOutput.png + GradientAnisotropicDiffusionImageFilterTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/GradientAnisotropicDiffusionImageFilterOutput.png + 5 0.125 3 +) + +# ------- GradientMagnitudeImageFilterTest---------- + +ADD_TEST(fiTeGradientMagnitudeImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/GradientMagnitudeImageFilterOutput.png + ${TEMP}/GradientMagnitudeImageFilterOutput.png + GradientMagnitudeImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/GradientMagnitudeImageFilterOutput.png +) + +# ------- MathematicalMorphologyGrayscaleFiltersTest---------- + +ADD_TEST(fiTeMathematicalMorphologyGrayscaleFiltersTest ${EXE_TESTS} + --compare-n-images ${TOL} 2 + ${BASELINE}/MathematicalMorphologyGrayscaleErosionOutput.png + ${TEMP}/MathematicalMorphologyGrayscaleErosionOutput.png + ${BASELINE}/MathematicalMorphologyGrayscaleDilationOutput.png + ${TEMP}/MathematicalMorphologyGrayscaleDilationOutput.png + MathematicalMorphologyGrayscaleFiltersTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/MathematicalMorphologyGrayscaleErosionOutput.png + ${TEMP}/MathematicalMorphologyGrayscaleDilationOutput.png + 150 180 +) + +# ------- LaplacianRecursiveGaussianImageFilter1Test---------- + +ADD_TEST(fiTeLaplacianRecursiveGaussianImageFilter1Test ${EXE_TESTS} + --compare-n-images ${TOL} 2 + ${BASELINE}/LaplacianRecursiveGaussianImageFilteroutput5.hdr + ${TEMP}/LaplacianRecursiveGaussianImageFilteroutput5.hdr + ${BASELINE}/LaplacianRecursiveGaussianImageFilterOutput5.png + ${TEMP}/LaplacianRecursiveGaussianImageFilterOutput5.png + LaplacianRecursiveGaussianImageFilter1Test + ${INPUTDATA}/ROISpot5.png + ${TEMP}/LaplacianRecursiveGaussianImageFilteroutput5.hdr + 5 + ${TEMP}/LaplacianRecursiveGaussianImageFilterOutput5.png +) + + +# ------- LaplacianRecursiveGaussianImageFilter2Test---------- + +ADD_TEST(fiTeLaplacianRecursiveGaussianImageFilter2Test ${EXE_TESTS} + --compare-n-images ${TOL} 2 + ${BASELINE}/LaplacianRecursiveGaussianImageFilter2output5.hdr + ${TEMP}/LaplacianRecursiveGaussianImageFilter2output5.hdr + ${BASELINE}/LaplacianRecursiveGaussianImageFilter2Output5.png + ${TEMP}/LaplacianRecursiveGaussianImageFilter2Output5.png + LaplacianRecursiveGaussianImageFilter2Test + ${INPUTDATA}/ROISpot5.png + ${TEMP}/LaplacianRecursiveGaussianImageFilter2output5.hdr + 5 + ${TEMP}/LaplacianRecursiveGaussianImageFilter2Output5.png +) + +# ------- CannyEdgeDetectionImageFilterTest---------- + +ADD_TEST(fiTeCannyEdgeDetectionImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/CannyEdgeDetectorImageFilterOutput.png + ${TEMP}/CannyEdgeDetectorImageFilterOutput.png + CannyEdgeDetectionImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/CannyEdgeDetectorImageFilterOutput.png + 2 +) + +# ------- DiscreteGaussianImageFilterTest---------- + +ADD_TEST(fiTeDiscreteGaussianImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/DiscreteGaussianImageFilterOutput.png + ${TEMP}/DiscreteGaussianImageFilterOutput.png + DiscreteGaussianImageFilterTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/DiscreteGaussianImageFilterOutput.png + 4 9 +) + +# ------- MedianImageFilterTest---------- + +ADD_TEST(fiTeMedianImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/MedianImageFilterOutput.png + ${TEMP}/MedianImageFilterOutput.png + MedianImageFilterTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/MedianImageFilterOutput.png +) + +# ------- BinaryThresholdImageFilterTest---------- + +ADD_TEST(fiTeBinaryThresholdImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 1 + ${BASELINE}/BinaryThresholdImageFilterOutput.png + ${TEMP}/BinaryThresholdImageFilterOutput.png + BinaryThresholdImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/BinaryThresholdImageFilterOutput.png + 150 180 0 255 +) + +# ------- DerivativeImageFilterTest---------- + +ADD_TEST(fiTeDerivativeImageFilterTest ${EXE_TESTS} + --compare-n-images ${TOL} 2 + ${BASELINE}/DerivativeImageFilterFloatOutput.hdr + ${TEMP}/DerivativeImageFilterFloatOutput.hdr + ${BASELINE}/DerivativeImageFilterOutput.png + ${TEMP}/DerivativeImageFilterOutput.png + DerivativeImageFilterTest + ${INPUTDATA}/ROISpot5.png + ${TEMP}/DerivativeImageFilterFloatOutput.hdr + ${TEMP}/DerivativeImageFilterOutput.png + 1 0 +) + +INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Testing/Code) +ADD_EXECUTABLE(otbFilteringExamplesTests otbFilteringExamplesTests.cxx) +TARGET_LINK_LIBRARIES(otbFilteringExamplesTests ITKAlgorithms ITKStatistics OTBBasicFilters OTBCommon OTBDisparityMap OTBIO OTBSpatialReasoning OTBChangeDetection OTBFeatureExtraction OTBLearning OTBMultiScale OTBTesting) + +ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) diff --git a/Examples/Filtering/GeometriesFilter.cxx b/Examples/Filtering/GeometriesFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..814354d09873ae6a62233a6380cb1df14afd58d5 --- /dev/null +++ b/Examples/Filtering/GeometriesFilter.cxx @@ -0,0 +1,87 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +/*===========================================================================*/ +/*===============================[ Includes ]================================*/ +/*===========================================================================*/ +#include "otbGeometriesToGeometriesFilter.h" +#include <string> +#include <iostream> +#include "otbOGRDataSourceWrapper.h" +#include "otbGeometriesSet.h" + +/*===========================================================================*/ +/*==============================[ other stuff ]==============================*/ +/*===========================================================================*/ +struct SwapXYFunctor +{ + typedef OGRGeometry TransformedElementType; + otb::ogr::UniqueGeometryPtr operator()(OGRGeometry const* in) const + { + otb::ogr::UniqueGeometryPtr out(in ? in->clone() : 0); + if (out) + { + out->swapXY(); + } + return boost::move(out); + } +}; + +int main (int argc, char **argv) +{ + if (argc < 2) + { + std::cerr << " inputGeometriesFile [outputGeometriesFile]" << std::endl; + return EXIT_FAILURE; + } + try + { + const bool workingInplace = argc==2; + + const std::string inputFile = argv[1]; + const std::string outputFile = workingInplace ? argv[1] : argv[2]; + + otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New( + inputFile, + workingInplace ? otb::ogr::DataSource::Modes::write : otb::ogr::DataSource::Modes::read); + otb::ogr::DataSource::Pointer output = workingInplace + ? input + : otb::ogr::DataSource::New( outputFile, otb::ogr::DataSource::Modes::write); + std::cout << "input: " << input -> ogr().GetName() << " should be: " << inputFile << "\n"; + std::cout << "output: " << output -> ogr().GetName() << " should be: " << outputFile << "\n"; + std::cout << "\n"; + + otb::DefaultGeometriesToGeometriesFilter<SwapXYFunctor>::Pointer filter + = otb::DefaultGeometriesToGeometriesFilter<SwapXYFunctor>::New(); + otb::GeometriesSet::Pointer in_set = otb::GeometriesSet::New(); + in_set->Set(input); + filter->SetInput(in_set); + otb::GeometriesSet::Pointer out_set = otb::GeometriesSet::New(); + out_set->Set(output); + filter->SetOutput(out_set); + out_set->Update(); + + filter -> Print(std::cout, 0); + return EXIT_SUCCESS; + } + catch (std::exception const& e) + { + std::cerr << e.what() << "\n"; + } + return EXIT_FAILURE; +}