otbImageReference.h 4.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*=========================================================================

  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 __otbImageReference_h
#define __otbImageReference_h

#include "itkPoint.h"
#include "itkMacro.h"

namespace otb
{
namespace ogr
{
/**\ingroup gGeometry
 * \class ImageReference
 * \todo See how mix it with the \c otb::ogr::DataSource wrapper as it was
 * with \c VectorData.
 * \since OTB v 3.14.0
33 34
 *
 * \ingroup OTBGdalAdapters
35 36 37 38 39 40 41 42 43 44 45
 */
template <typename TPrecision> class ImageReference
{
public:
  typedef TPrecision PrecisionType;
  enum { Dimension = 2 };
  /**\name Standard ITK typedefs */
  //@{
  itkTypeMacro(ImageReference, void);
  bool GetDebug() const
    {
46
    return m_Holder.GetDebug();
47 48 49 50 51 52 53 54 55 56 57 58 59 60
    }
  //@}
  /**\name Template-parameters typedefs */
  //@{
  typedef itk::Vector<PrecisionType, 2> SpacingType;
  typedef itk::Point<PrecisionType, 2>  OriginType;
  typedef itk::Point<PrecisionType, 2>  PointType;
  //@}

  /** Default constructor.
   * \post <tt>m_Spacing = {1,1}</tt>
   * \post <tt>m_Origin = {0,0}</tt>
   */
  ImageReference(itk::Object const& holder)
61
    : m_Holder(holder)
62 63 64 65 66 67 68 69 70
    {
    m_Spacing.Fill(1);
    m_Origin.Fill(0);
    }
  /** Init constructor.
   * \post <tt>m_Spacing = spacing</tt>
   * \post <tt>m_Origin = origin</tt>
   */
  ImageReference(SpacingType const& spacing, OriginType const& origin, itk::Object const& holder)
71
    : m_Holder(holder) , m_Spacing(spacing), m_Origin(origin)
72 73 74 75 76
    {
    }

  void Modified() const
    {
77
    m_Holder.Modified();
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    }

  /**\name Origin property
   * Represents the origin of the geometries in the image coordinates system.
   */
  //@{
  itkGetConstReferenceMacro(Origin, OriginType);     //!< Origin getter.
  itkSetMacro(Origin, OriginType);                   //!< Origin setter.
  void SetOrigin(const TPrecision origin[Dimension]) //!< Origin setter.
    {
    const OriginType p(origin);
    this->SetOrigin(p);
    }
  //@}

  /**\name Spacing property
   * Spacing of the geometries to put in the corresponding image coordinates.
   */
  //@{
  itkGetConstReferenceMacro(Spacing, SpacingType);         //!< Spacing getter.
  void SetSpacing(const SpacingType& spacing)              //!< Spacing setter.
    {
    // itkDebugMacro("setting Spacing to " << spacing);
    if (this->m_Spacing != spacing)
      {
      this->m_Spacing = spacing;
      this->Modified();
      }
    }
  void SetSpacing(const TPrecision spacing[Dimension]) //!< Spacing setter.
    {
    const SpacingType s(spacing);
    this->SetSpacing(s);
    }
  //@}

  /**
   * Projects a point from the Data Source coordinates system to the image
   * coordinates system.
   * \param[in] point  point in Data Source coordinates system
   * \param[out] physicalPoint  point in the image coordinates system.
   * \throw None
   */
  void TransformPointToPhysicalPoint(const PointType& point, PointType& physicalPoint) const
    {
    for (size_t i=0; i!=Dimension; ++i)
      physicalPoint[i] = point[i] * m_Spacing[i] + m_Origin[i];
    }

  /**
   * Projects a point from the Data Source coordinates system to the image
   * coordinates system.
   * \param[in] point  point in Data Source coordinates system
   * \return the point projected in the image coordinates system.
   * \throw None
   */
  void TransformPointToPhysicalPoint(const PointType& point) const
    {
    // why no loop on VDimension ?
    PointType physicalPoint;
    for (size_t i=0; i!=Dimension; ++i)
      physicalPoint[i] = point[i] * m_Spacing[i] + m_Origin[i];
    return physicalPoint;
    }

  /**
   * Assignment operator.
   * \param[in] rhs source data to be copied.
   * \throw None
   * \internal
   * Required because of the hack to provide a \c GetDebug() function which is
   * required by \c itkTypeMacro.
   */
  ImageReference& operator=(ImageReference const& rhs)
    {
    m_Spacing = rhs.m_Spacing;
    m_Origin  = rhs.m_Origin;
    return *this;
    }

private:
159
  itk::Object     const& m_Holder;
160 161 162 163 164 165 166 167 168 169 170 171 172
  SpacingType            m_Spacing;
  OriginType             m_Origin;
};

} // ogr namespace

} // end namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
// #include "otbImageReference.txx"
#endif

#endif // __otbImageReference_h