<commit_before>// __BEGIN_LICENSE__
//  Copyright (c) 2006-2012, United States Government as represented by the
//  Administrator of the National Aeronautics and Space Administration. All
//  rights reserved.
//
//  The NASA Vision Workbench is 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.
// __END_LICENSE__


#ifndef __VW_CARTOGRAPHY_PROJGEOREFERENCE_H__
#define __VW_CARTOGRAPHY_PROJGEOREFERENCE_H__

#include <vw/Cartography/GeoReferenceBase.h>
#include <vw/FileIO/DiskImageResource.h>
#include <vw/Core/Exception.h>

// Boost
#include <boost/algorithm/string.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>

#if defined(VW_HAVE_PKG_PROTOBUF) && VW_HAVE_PKG_PROTOBUF==1
#include <vw/Cartography/GeoReferenceDesc.pb.h>
#endif

// Forward declaration of Proj.4 things. C++ needs forward declaration of
// typedefs so we can call it PJ instead of projPJ. Bad if Proj ever
// changes their struct names; we suddenly have a difficult to find bug.
// If the Proj API ever changes and this breaks, see if there's a new name
// for this structure.
#if !defined(PROJECTS_H)
typedef void* projPJ;
typedef void* projCtx;
#else
typedef PJ* projPJ;
typedef projCtx_t *projCtx;
#endif

namespace vw {
namespace cartography {

  // Here is some machinery to keep track of an initialized proj.4
  // projection context using a smart pointer.
  //
  // Implementation of the methods to this class change based on what
  // Proj4 version is available. So unfortunately, the methods and
  // private variables are a mash up of what is needed for the 4.7 and
  // 4.8 versions.
  class ProjContext {
    boost::shared_ptr<void> m_proj_ctx_ptr; //  Only used for Proj4.8
    boost::shared_ptr<void> m_proj_ptr;
    std::string m_proj4_str;
    char** split_proj4_string(std::string const& proj4_str, int &num_strings);

  public:
    ProjContext() : m_proj4_str("") {};
    ProjContext(std::string const& proj4_str);
    ProjContext(ProjContext const& other ); // Only used for Proj4.8
    inline projPJ proj_ptr() const {
      VW_ASSERT( !m_proj4_str.empty(),
                 ArgumentErr() << "ProjContext: Projection not initialized." );
      return m_proj_ptr.get();
    }
    int error_no() const;
  };

  /// The georeference class contains the mapping from image coordinates
  /// (u,v) to geospatial coordinates (typically lat/lon, or possibly
  /// meters in a UTM grid cell, etc.)
  class GeoReference : public GeoReferenceBase {
    Matrix<double,3,3> m_transform, m_inv_transform, m_shifted_transform, m_inv_shifted_transform;
    std::string m_proj_projection_str, m_gml_str;
    ProjContext m_proj_context;
    bool m_is_projected;

    void init_proj();

    /// This method returns a version of the affine transform
    /// compatible with the VW standard notion that (0,0) is the
    /// center of the top left pixel.  If pixel_interpretation() is
    /// set to PixelAsArea, this method will adjust the affine
    /// transform my 0.5 pixels right and down.
    Matrix3x3 const& vw_native_transform() const;
    Matrix3x3 const& vw_native_inverse_transform() const;

  public:

    /// Construct a default georeference.  This georeference will use
    /// the identity matrix as the initial transformation matrix, and
    /// select the default datum (WGS84) and projection (geographic).
    GeoReference();

    /// Takes a geodetic datum.  The affine transform defaults to the identity matrix.
    GeoReference(Datum const& datum);

    /// Takes a geodetic datum and an affine transformation matrix
    GeoReference(Datum const& datum, Matrix<double,3,3> const& transform);

    /// Takes a geodetic datum and an affine transformation matrix and pixel interpretation
    GeoReference(Datum const& datum, Matrix<double,3,3> const& transform, PixelInterpretation pixel_interpretation);

#if defined(VW_HAVE_PKG_PROTOBUF) && VW_HAVE_PKG_PROTOBUF==1
    /// Construct a GeoReference from a GeoReferenceDesc
    GeoReference(GeoReferenceDesc const& desc);

    /// Create a GeoReferenceDesc for the georef
    GeoReferenceDesc build_desc();
#endif
<commit_msg>cartography: GeoReference switch over to void pointers<commit_after>// __BEGIN_LICENSE__
//  Copyright (c) 2006-2012, United States Government as represented by the
//  Administrator of the National Aeronautics and Space Administration. All
//  rights reserved.
//
//  The NASA Vision Workbench is 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.
// __END_LICENSE__


#ifndef __VW_CARTOGRAPHY_PROJGEOREFERENCE_H__
#define __VW_CARTOGRAPHY_PROJGEOREFERENCE_H__

#include <vw/Cartography/GeoReferenceBase.h>
#include <vw/FileIO/DiskImageResource.h>
#include <vw/Core/Exception.h>

// Boost
#include <boost/algorithm/string.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>

#if defined(VW_HAVE_PKG_PROTOBUF) && VW_HAVE_PKG_PROTOBUF==1
#include <vw/Cartography/GeoReferenceDesc.pb.h>
#endif

namespace vw {
namespace cartography {

  // Here is some machinery to keep track of an initialized proj.4
  // projection context using a smart pointer.
  //
  // Implementation of the methods to this class change based on what
  // Proj4 version is available. So unfortunately, the methods and
  // private variables are a mash up of what is needed for the 4.7 and
  // 4.8 versions.
  class ProjContext {
    boost::shared_ptr<void> m_proj_ctx_ptr; //  Only used for Proj4.8
    boost::shared_ptr<void> m_proj_ptr;
    std::string m_proj4_str;
    char** split_proj4_string(std::string const& proj4_str, int &num_strings);

  public:
    ProjContext() : m_proj4_str("") {};
    ProjContext(std::string const& proj4_str);
    ProjContext(ProjContext const& other ); // Only used for Proj4.8
    inline void* proj_ptr() const {
      VW_ASSERT( !m_proj4_str.empty(),
                 ArgumentErr() << "ProjContext: Projection not initialized." );
      return m_proj_ptr.get();
    }
    int error_no() const;
  };

  /// The georeference class contains the mapping from image coordinates
  /// (u,v) to geospatial coordinates (typically lat/lon, or possibly
  /// meters in a UTM grid cell, etc.)
  class GeoReference : public GeoReferenceBase {
    Matrix<double,3,3> m_transform, m_inv_transform, m_shifted_transform, m_inv_shifted_transform;
    std::string m_proj_projection_str, m_gml_str;
    ProjContext m_proj_context;
    bool m_is_projected;

    void init_proj();

    /// This method returns a version of the affine transform
    /// compatible with the VW standard notion that (0,0) is the
    /// center of the top left pixel.  If pixel_interpretation() is
    /// set to PixelAsArea, this method will adjust the affine
    /// transform my 0.5 pixels right and down.
    Matrix3x3 const& vw_native_transform() const;
    Matrix3x3 const& vw_native_inverse_transform() const;

  public:
    /// Construct a default georeference.  This georeference will use
    /// the identity matrix as the initial transformation matrix, and
    /// select the default datum (WGS84) and projection (geographic).
    GeoReference();

    /// Takes a geodetic datum.  The affine transform defaults to the
    /// identity matrix.
    GeoReference(Datum const& datum);

    /// Takes a geodetic datum and an affine transformation matrix
    GeoReference(Datum const& datum, Matrix<double,3,3> const& transform);

    /// Takes a geodetic datum and an affine transformation matrix and
    /// pixel interpretation
    GeoReference(Datum const& datum, Matrix<double,3,3> const& transform, PixelInterpretation pixel_interpretation);

#if defined(VW_HAVE_PKG_PROTOBUF) && VW_HAVE_PKG_PROTOBUF==1
    /// Construct a GeoReference from a GeoReferenceDesc
    GeoReference(GeoReferenceDesc const& desc);

    /// Create a GeoReferenceDesc for the georef
    GeoReferenceDesc build_desc();
#endif

{'fraction_non_alphanumeric': 0.08829218341108204, 'fraction_numerical': 0.01058140857890545, 'mean_word_length': 3.723267060720043, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2250023', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2641, 'n_words': 928}