<commit_before>
// Copyright (c) 2015 <NAME>.

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef OPENMVG_CAMERA_INTRINSICS_H
#define OPENMVG_CAMERA_INTRINSICS_H

#include "openMVG/numeric/numeric.h"
#include "openMVG/cameras/Camera_Common.hpp"
#include "openMVG/geometry/pose3.hpp"
#include "openMVG/stl/hash.hpp"
#include <vector>
#include <cereal/cereal.hpp> // Serialization

namespace openMVG {
namespace cameras {

/// Basis class for all intrinsic parameters of a camera
/// Store the image size & define all basis optical modelization of a camera
struct IntrinsicBase
{
  unsigned int _w, _h;
  double _initialFocalLengthPix = -1;
  std::string _serialNumber;

  IntrinsicBase(unsigned int w = 0, unsigned int h = 0, const std::string& serialNumber = ""):_w(w), _h(h), _serialNumber(serialNumber)
  {}
  virtual ~IntrinsicBase()
  {}
  
  virtual IntrinsicBase* clone() const = 0;
  virtual void assign(const IntrinsicBase& other) = 0;

  virtual bool isValid() const { return _w != 0 && _h != 0; }
  
  unsigned int w() const {return _w;}
  unsigned int h() const {return _h;}
  const std::string& serialNumber() const {return _serialNumber;}
  double initialFocalLengthPix() const {return _initialFocalLengthPix;}
  
  void setWidth(unsigned int w) { _w = w;}
  void setHeight(unsigned int h) { _h = h;}
  void setSerialNumber(const std::string& serialNumber)
  {
    _serialNumber = serialNumber;
  }
  void setInitialFocalLengthPix(double initialFocalLengthPix)
  {
    _initialFocalLengthPix = initialFocalLengthPix;
  }

  // Operator ==
  bool operator==(const IntrinsicBase& other) const {
    return _w == other._w &&
           _h == other._h &&
           _serialNumber == other._serialNumber &&
           getType() == other.getType() &&
           getParams() == other.getParams();
  }

  /// Projection of a 3D point into the camera plane (Apply pose, disto (if any) and Intrinsics)
  Vec2 project(
    const geometry::Pose3 & pose,
    const Vec3 & pt3D) const
  {
    const Vec3 X = pose(pt3D); // apply pose
    if (this->have_disto()) // apply disto & intrinsics
      return this->cam2ima( this->add_disto(X.head<2>()/X(2)) );
    else // apply intrinsics
      return this->cam2ima( X.head<2>()/X(2) );
  }

  /// Compute the residual between the 3D projected point X and an image observation x
  Vec2 residual(const geometry::Pose3 & pose, const Vec3 & X, const Vec2 & x) const
  {
    const Vec2 proj = this->project(pose, X);
    return x - proj;
  }
  
  Mat2X residuals(const geometry::Pose3 & pose, const Mat3X & X, const Mat2X & x) const
  {
    assert(X.cols() == x.cols());
    const std::size_t numPts = x.cols();
    Mat2X residuals = Mat2X::Zero(2, numPts);<commit_msg>[cameras] allow to project a point without applying the distortion<commit_after>
// Copyright (c) 2015 <NAME>.

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef OPENMVG_CAMERA_INTRINSICS_H
#define OPENMVG_CAMERA_INTRINSICS_H

#include "openMVG/numeric/numeric.h"
#include "openMVG/cameras/Camera_Common.hpp"
#include "openMVG/geometry/pose3.hpp"
#include "openMVG/stl/hash.hpp"
#include <vector>
#include <cereal/cereal.hpp> // Serialization

namespace openMVG {
namespace cameras {

/// Basis class for all intrinsic parameters of a camera
/// Store the image size & define all basis optical modelization of a camera
struct IntrinsicBase
{
  unsigned int _w, _h;
  double _initialFocalLengthPix = -1;
  std::string _serialNumber;

  IntrinsicBase(unsigned int w = 0, unsigned int h = 0, const std::string& serialNumber = ""):_w(w), _h(h), _serialNumber(serialNumber)
  {}
  virtual ~IntrinsicBase()
  {}
  
  virtual IntrinsicBase* clone() const = 0;
  virtual void assign(const IntrinsicBase& other) = 0;

  virtual bool isValid() const { return _w != 0 && _h != 0; }
  
  unsigned int w() const {return _w;}
  unsigned int h() const {return _h;}
  const std::string& serialNumber() const {return _serialNumber;}
  double initialFocalLengthPix() const {return _initialFocalLengthPix;}
  
  void setWidth(unsigned int w) { _w = w;}
  void setHeight(unsigned int h) { _h = h;}
  void setSerialNumber(const std::string& serialNumber)
  {
    _serialNumber = serialNumber;
  }
  void setInitialFocalLengthPix(double initialFocalLengthPix)
  {
    _initialFocalLengthPix = initialFocalLengthPix;
  }

  // Operator ==
  bool operator==(const IntrinsicBase& other) const {
    return _w == other._w &&
           _h == other._h &&
           _serialNumber == other._serialNumber &&
           getType() == other.getType() &&
           getParams() == other.getParams();
  }

  /// Projection of a 3D point into the camera plane (Apply pose, disto (if any) and Intrinsics)
  Vec2 project(
    const geometry::Pose3 & pose,
    const Vec3 & pt3D,
    bool applyDistortion = true) const
  {
    const Vec3 X = pose(pt3D); // apply pose
    if (applyDistortion && this->have_disto()) // apply disto & intrinsics
      return this->cam2ima( this->add_disto(X.head<2>()/X(2)) );
    else // apply intrinsics
      return this->cam2ima( X.head<2>()/X(2) );
  }

  /// Compute the residual between the 3D projected point X and an image observation x
  Vec2 residual(const geometry::Pose3 & pose, const Vec3 & X, const Vec2 & x) const
  {
    const Vec2 proj = this->project(pose, X);
    return x - proj;
  }
  
  Mat2X residuals(const geometry::Pose3 & pose, const Mat3X & X, const Mat2X & x) const
  {
    assert(X.cols() == x.cols());
    const std::size_t numPts = x.cols();
    Mat2X residuals = Mat2X::Zero(2, numPts);
{'fraction_non_alphanumeric': 0.12014376176621598, 'fraction_numerical': 0.014376176621598494, 'mean_word_length': 3.509259259259259, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '1678133', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1896, 'n_words': 592}