<commit_before>/*=========================================================================

  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
{
/**\ingroup GeometriesFilters
 * \class GeometriesToGeometriesFilter
 * Root abstract class for all geometries to geometries filters.
 * \since OTB v 3.14.0
 */
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                        OutputGeometriesType;
  // typedef GeometriesSet::Pointer               InputGeometriesPointer;
  // typedef GeometriesSet::Pointer               OutputGeometriesPointer;
  //@}

  /**\name Standard ITK macros */
  //@{
  /** Run-time type information (and related methods). */
  itkTypeMacro(GeometriesToGeometriesFilter, GeometriesSource);
  //@}

  /**\name Single input GeometriesSet property */
  //@{
  virtual void SetInput(const InputGeometriesType *input);
  const InputGeometriesType * GetInput(void);
  //@}

protected:
  /** Default constructor.
   * Does nothing.
   */
  GeometriesToGeometriesFilter();
  /** Destructor.
   * Does nothing.
   */
  virtual ~GeometriesToGeometriesFilter();

  virtual void GenerateOutputInformation(void);
  virtual void GenerateData(void);

private:
  void Process(OutputGeometriesType &inout);
  void Process(InputGeometriesType const& source, OutputGeometriesType &destination);
  /**\name Filter specialization hooks.
   * Filter specialization hooks.
   * These functions are meant to be specialized by the actual filter.
   */
  //@{
  /**
   * Hook that actually filters an OGR \c Layer.
   * \param[in]     source      Input layer
   * \param[in,out] destination Output layer
   *
   * \note When <tt>source == destination</tt>, it means this is an inplace
   * filter.
   */
  virtual void                     DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const=0;

  /**
   * Hook used to determine the \c OGRSpatialReference when creating a new layer.
   * \param[in] source  source \c Layer for reference (in case it has relevant
   * information).
   * \return a new \c OGRSpatialReference that the client code shall release
   * with the appropiate OGR function.
   * \return 0 by default.
   * \todo Return a <tt>unique_ptr<OGRSpatialReference></tt>.
   */
  virtual OGRSpatialReference*     DoDefineNewLayerSpatialReference(ogr::Layer const& source) const;

  /**
   * Hook used to determine the type of the new layer.
   * \param[in] source  source \c Layer.
   * \return by default the same type as the one from the \c source \c Layer.
   */
  virtual OGRwkbGeometryType       DoDefineNewLayerGeometryType(ogr::Layer const& source) const;

  /**
   * Hook used to determine the options for  creating a new layer.
   * \param[in] source  source \c Layer for reference (in case it has relevant
   * information).
   * \return nothing by default.
   */
  virtual std::vector<std::string> DoDefineNewLayerOptions(ogr::Layer const& source) const;

  /**
   * Hook used to define the fields of the new layer.
   * \param[in] source  source \c Layer -- for reference
   * \param[in,out] dest  destination \c Layer
   */
  virtual void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer & dest) const = 0;

  /** Hook used to conclude the initialization phase.
   * As ITK doesn't follow a <em>the constructor set the object in a final, and
   * ready to be used, state</em>, this step is required to do that once all
   * filter attributes have been set.
   *
   * The default implementation does nothing.
   */
  virtual void                     DoFinalizeInitialisation() {}
  //@}
  friend struct ::ProcessVisitor;
  };

/**\ingroup GeometriesFilters
 * Helper class to operate an exact copy of the fields from a source layer.
 * \since OTB v 3.14.0
 */
struct FieldCopyTransformation
  {
  OGRFeatureDefn & getDefinition(ogr::Layer & outLayer) const
    {
    return outLayer.GetLayerDefn();
    }
  /**
   * In-place transformation: does nothing.
   * \param[in] inoutFeature  \c Feature to change.
   * \throw Nothing
   */
  void fieldsTransform(ogr::Feature const& inoutFeature) const
    {
    // default => do nothing for in-place transformation
    }
  /**
   * By-Copy transformation: copies all fields.
   * \param[in] inFeature  input \c Feature
   * \param[in,out] outFeature  output \c Feature
   *
   * \throw itk::ExceptionObject if the fields cannot be copied.
   */
  void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature & outFeature) const
    {
    // default => copy all fields for copy transformation
    assert(inFeature.GetSize() == outFeature.GetSize());
    for (size_t i=0,N=inFeature.GetSize(); i!=N; ++i)
      {
      outFeature[i].Assign(inFeature[i]);
      }
    }

  /**
   * Defines the fields in the destination layer.
   * \param[in] source  source \c Layer
   * \param[in,out] dest  destination \c Layer
   * \throw itk::ExceptionObject in case the operation can't succeed.
   */
  void DefineFields(ogr::Layer const& source, ogr::Layer & dest) const
    {
    OGRFeatureDefn & inDefinition = source.GetLayerDefn();
    for (int i=0,N=inDefinition.GetFieldCount(); i!=N; ++i)
      {
      dest.CreateField(*inDefinition.GetFieldDefn(i));
      }
    }
  };

<commit_msg>BUG: when converting between different formats, field names can be changed<commit_after>/*=========================================================================

  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
{
/**\ingroup GeometriesFilters
 * \class GeometriesToGeometriesFilter
 * Root abstract class for all geometries to geometries filters.
 * \since OTB v 3.14.0
 */
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                        OutputGeometriesType;
  // typedef GeometriesSet::Pointer               InputGeometriesPointer;
  // typedef GeometriesSet::Pointer               OutputGeometriesPointer;
  //@}

  /**\name Standard ITK macros */
  //@{
  /** Run-time type information (and related methods). */
  itkTypeMacro(GeometriesToGeometriesFilter, GeometriesSource);
  //@}

  /**\name Single input GeometriesSet property */
  //@{
  virtual void SetInput(const InputGeometriesType *input);
  const InputGeometriesType * GetInput(void);
  //@}

protected:
  /** Default constructor.
   * Does nothing.
   */
  GeometriesToGeometriesFilter();
  /** Destructor.
   * Does nothing.
   */
  virtual ~GeometriesToGeometriesFilter();

  virtual void GenerateOutputInformation(void);
  virtual void GenerateData(void);

private:
  void Process(OutputGeometriesType &inout);
  void Process(InputGeometriesType const& source, OutputGeometriesType &destination);
  /**\name Filter specialization hooks.
   * Filter specialization hooks.
   * These functions are meant to be specialized by the actual filter.
   */
  //@{
  /**
   * Hook that actually filters an OGR \c Layer.
   * \param[in]     source      Input layer
   * \param[in,out] destination Output layer
   *
   * \note When <tt>source == destination</tt>, it means this is an inplace
   * filter.
   */
  virtual void                     DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const=0;

  /**
   * Hook used to determine the \c OGRSpatialReference when creating a new layer.
   * \param[in] source  source \c Layer for reference (in case it has relevant
   * information).
   * \return a new \c OGRSpatialReference that the client code shall release
   * with the appropiate OGR function.
   * \return 0 by default.
   * \todo Return a <tt>unique_ptr<OGRSpatialReference></tt>.
   */
  virtual OGRSpatialReference*     DoDefineNewLayerSpatialReference(ogr::Layer const& source) const;

  /**
   * Hook used to determine the type of the new layer.
   * \param[in] source  source \c Layer.
   * \return by default the same type as the one from the \c source \c Layer.
   */
  virtual OGRwkbGeometryType       DoDefineNewLayerGeometryType(ogr::Layer const& source) const;

  /**
   * Hook used to determine the options for  creating a new layer.
   * \param[in] source  source \c Layer for reference (in case it has relevant
   * information).
   * \return nothing by default.
   */
  virtual std::vector<std::string> DoDefineNewLayerOptions(ogr::Layer const& source) const;

  /**
   * Hook used to define the fields of the new layer.
   * \param[in] source  source \c Layer -- for reference
   * \param[in,out] dest  destination \c Layer
   */
  virtual void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer & dest) const = 0;

  /** Hook used to conclude the initialization phase.
   * As ITK doesn't follow a <em>the constructor set the object in a final, and
   * ready to be used, state</em>, this step is required to do that once all
   * filter attributes have been set.
   *
   * The default implementation does nothing.
   */
  virtual void                     DoFinalizeInitialisation() {}
  //@}
  friend struct ::ProcessVisitor;
  };

/**\ingroup GeometriesFilters
 * Helper class to operate an exact copy of the fields from a source layer.
 * \since OTB v 3.14.0
 */
struct FieldCopyTransformation
  {
  OGRFeatureDefn & getDefinition(ogr::Layer & outLayer) const
    {
    return outLayer.GetLayerDefn();
    }
  /**
   * In-place transformation: does nothing.
   * \param[in] inoutFeature  \c Feature to change.
   * \throw Nothing
   */
  void fieldsTransform(ogr::Feature const& inoutFeature) const
    {
    // default => do nothing for in-place transformation
    }
  /**
   * By-Copy transformation: copies all fields.
   * \param[in] inFeature  input \c Feature
   * \param[in,out] outFeature  output \c Feature
   *
   * \throw itk::ExceptionObject if the fields cannot be copied.
   */
  void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature & outFeature) const
    {
    // default => copy all fields for copy transformation

    //assert(inFeature.GetSize() == outFeature.GetSize());

    for (size_t i=0,N=inFeature.GetSize(); i!=N; ++i)
      {
      outFeature[inFeature[i].GetName()].Assign(inFeature[i]);
      }
    }

  /**
   * Defines the fields in the destination layer.
   * \param[in] source  source \c Layer
   * \param[in,out] dest  destination \c Layer
   * \throw itk::ExceptionObject in case the operation can't succeed.
   */
  void DefineFields(ogr::Layer const& source, ogr::Layer & dest) const
    {
    OGRFeatureDefn & inDefinition = source.GetLayerDefn();
    for (int i=0,N=inDefinition.GetFieldCount(); i!=N; ++i)
      {
      dest.CreateField(*inDefinition.GetFieldDefn(i));
      }
    }
  };


{'fraction_non_alphanumeric': 0.1222499609923545, 'fraction_numerical': 0.002028397565922921, 'mean_word_length': 3.178292046936115, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1219318', 'n_tokens_mistral': 3838, 'n_tokens_neox': 3691, 'n_words': 1158}