Skip to content

Commit

Permalink
Merge branch '213-dichotomy-c-creation-de-la-classe-cardinalsine-en-c…
Browse files Browse the repository at this point in the history
…' into 'release'

Resolve "Dichotomy C++: Creation de la classe CardinalSine en C++"

See merge request 3d/PandoraBox/pandora2d!175
  • Loading branch information
lecontm committed Dec 19, 2024
2 parents 7c409d7 + a612352 commit c19d346
Show file tree
Hide file tree
Showing 38 changed files with 1,622 additions and 1,525 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
BasedOnStyle: Chromium
ColumnLimit: 100
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ repos:
types: [python]
- id: pylint
name: PyLint
entry: python -m pylint --rcfile=.pylintrc
entry: pylint
language: system
files: \.py$
types: [python]
require_serial: true
args: [
"--rcfile=.pylintrc"
]
stages: [pre-commit]
- id: mypy
name: mypy
Expand All @@ -31,3 +35,9 @@ repos:
rev: 0.6.1
hooks:
- id: nbstripout

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.4
hooks:
- id: clang-format
types_or: [c++, c, cuda]
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"show-module-summary",
"special-members",
]
suppress_warnings = ["ref.python"]
# Add any paths that contain templates here, relative to this directory.cd
templates_path = ["_templates"]

Expand Down
2 changes: 1 addition & 1 deletion pandora2d/interpolation_filter/bicubic_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

from pandora.margins import Margins

import interpolation_filter_bind # type: ignore[import-not-found] # pylint:disable=import-error
from .interpolation_filter import AbstractFilter
from ..interpolation_filter_cpp import interpolation_filter_bind


@AbstractFilter.register_subclass("bicubic")
Expand Down
18 changes: 18 additions & 0 deletions pandora2d/interpolation_filter_cpp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024 Centre National d'Etudes Spatiales (CNES).
#
# This file is part of PANDORA2D
#
# https://github.com/CNES/Pandora2D
#
# 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.
#
10 changes: 8 additions & 2 deletions pandora2d/interpolation_filter_cpp/include/alias.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ using t_Matrix = Eigen::MatrixXd;
*/
using t_Vector = Eigen::VectorXd;

const double MAX_FRACTIONAL_VALUE = 1 - (1. / pow(2, 9)); ///< MAX_FRACTIONAL_VALUE=0.998046875
/**
* @brief type used for arrays
*
*/
using t_Array = Eigen::ArrayXd;

const double MAX_FRACTIONAL_VALUE = 1 - (1. / pow(2, 9)); ///< MAX_FRACTIONAL_VALUE=0.998046875
///< corresponds to 1-1/2**9 where 9 is the maximal number of iterations for dichotomy

const double EPSILON = std::numeric_limits<float>::epsilon(); ///< Numeric limit of float type.
const double EPSILON = std::numeric_limits<float>::epsilon(); ///< Numeric limit of float type.
///< We use the same numeric limit used by Medicis.

#endif
58 changes: 28 additions & 30 deletions pandora2d/interpolation_filter_cpp/include/bicubic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,38 @@ This module contains functions associated to the Bicubic filter class for cpp.
*
*
*/
struct Bicubic : public abstractfilter::AbstractFilter
{
struct Bicubic : public abstractfilter::AbstractFilter {
/**
* @brief Construct a new Bicubic object
*
*/
Bicubic();

/**
* @brief Construct a new Bicubic object
*
*/
Bicubic();
/**
* @brief Destroy the Bicubic object
*
*/
~Bicubic() = default;

/**
* @brief Destroy the Bicubic object
*
*/
~Bicubic() = default;
/**
* @brief Get the coeffs object
*
* @param fractional_shift positive fractional shift of the subpixel
* position to be interpolated
* @return t_Vector, an array of interpolator coefficients
* whose size depends on the filter margins
*/
t_Vector get_coeffs(const double fractional_shift) override;

/**
* @brief Get the coeffs object
*
* @param fractional_shift positive fractional shift of the subpixel
* position to be interpolated
* @return t_Vector, an array of interpolator coefficients
* whose size depends on the filter margins
*/
t_Vector get_coeffs(const double fractional_shift) override;
/**
* @brief Get the alpha attribute
*
* @return float
*/
float get_alpha() const { return m_alpha; }

/**
* @brief Get the alpha attribute
*
* @return float
*/
float get_alpha() const { return m_alpha; }

private:
float m_alpha = -0.5; ///< alpha coefficient
private:
float m_alpha = -0.5; ///< alpha coefficient
};

#endif
123 changes: 123 additions & 0 deletions pandora2d/interpolation_filter_cpp/include/cardinal_sine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* Copyright (c) 2024 Centre National d'Etudes Spatiales (CNES).
*
* This file is part of PANDORA2D
*
* https://github.com/CNES/Pandora2D
*
* 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.
*/

/*
This module contains functions associated to the Cardinal Sine filter class for
cpp.
*/

#ifndef CARDINALSINEFILTER_HPP
#define CARDINALSINEFILTER_HPP

#include "interpolation_filter.hpp"

/**
* @brief Find index of a value in a container or throw if not found.
*
* @param value value to search for.
* @param container container to search in.
* @param message message of the error.
*
* @throws std::invalid_argument if provided value is not found in container.
*
* @return Eigen::Index
*/
Eigen::Index find_or_throw(const double value,
const t_Vector& container,
const std::string& message);

/**
* @brief Compute Cardinal Sine of x (with PI).
*
* @param x value to compute cardinal sine from.
* @return double cardinal sine of x.
*/
double sinc(double x);

/**
* @brief Contruct a vector of fractional shifts in interval [0,1[ with a step of fractional shift.
*
* @param fractional_shift
* @return t_Vector
*/
t_Vector fractional_range(double fractional_shift);

/**
* @brief Compute normalized cardinal sine coefficients windowed by a Gaussian.
*
* Will compute the `2 * filter_size + 1` coefficients for each given
* fractional_shift in `fractional_shifts` and store them in the returned
* NDArray where:
*
* - Each row corresponds to a specific fractional shift value.
* - Each column corresponds to a coefficient at a specific position.
*
* The Gaussian window width correspond to the size of the filter.
* @param filter_size size of the filter.
* @param fractional_shifts fractional shifts where to compute coefficients.
* @return t_Matrix (2*filter_size + 1) coeffcients for each fractional shift.
*/
t_Matrix compute_coefficient_table(int filter_size, const t_Vector& fractional_shifts);

/**
* @brief Cardinal sine filter
*
*/
struct CardinalSine : public abstractfilter::AbstractFilter {
/**
* @brief Construct a new CardinalSine object
*
*/
CardinalSine();

/**
* @brief Construct a new Cardinal Sine object
*
* @param half_size half filter size.
* @param fractional_shift interval between each interpolated point,
* sometimes referred to as precision. Expected value in the range [0,1[.
*/
CardinalSine(int half_size, double fractional_shift);

/**
* @brief Destroy the CardinalSine object
*
*/
~CardinalSine() = default;

/**
* @brief Get the coeffs object
*
* @param fractional_shift positive fractional shift of the subpixel
* position to be interpolated
*
* @throws std::invalid_argument if provided fractional_shift is not found
* precomputed table.
*
* @return t_Vector, an array of interpolator coefficients
* whose size depends on the filter margins
*/
t_Vector get_coeffs(const double fractional_shift) override;

private:
int m_half_size; ///< Half filter size
t_Vector m_fractional_shifts; ///< Fractional shifts used to compute coefficients
t_Matrix m_coeffs; ///< Pre-computed coefficients
};
#endif
Loading

0 comments on commit c19d346

Please sign in to comment.