LCOV - code coverage report
Current view: top level - alg - gdallinearsystem.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 11 11 100.0 %
Date: 2024-05-04 12:52:34 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  Linear system solver
       5             :  * Author:   VIZRT Development Team.
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2017 Alan Thomas <alant@outlook.com.au>
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : /*! @cond Doxygen_Suppress */
      30             : 
      31             : #ifndef GDALLINEARSYSTEM_H_INCLUDED
      32             : #define GDALLINEARSYSTEM_H_INCLUDED
      33             : 
      34             : #include <vector>
      35             : 
      36             : /*
      37             :  * Matrix class with double entries.
      38             :  * The elements are stored in column major order in a vector.
      39             :  */
      40             : struct GDALMatrix
      41             : {
      42             :     /// Creates a matrix with zero rows and columns.
      43             :     GDALMatrix() = default;
      44             : 
      45             :     /// Creates a matrix with \a rows rows and \a col columns
      46             :     /// Its elements are initialized to 0.
      47         123 :     GDALMatrix(int rows, int cols)
      48         123 :         : n_rows(rows), n_cols(cols), v(rows * cols, 0.)
      49             :     {
      50         123 :     }
      51             : 
      52             :     /// Returns the number or rows of the matrix
      53         246 :     inline int getNumRows() const
      54             :     {
      55         246 :         return n_rows;
      56             :     }
      57             : 
      58             :     /// Returns the number or columns of the matrix.
      59         246 :     inline int getNumCols() const
      60             :     {
      61         246 :         return n_cols;
      62             :     }
      63             : 
      64             :     /// Returns the reference to the element at the position \a row, \a col.
      65    13599800 :     inline double &operator()(int row, int col)
      66             :     {
      67    13599800 :         return v[row + col * static_cast<size_t>(n_rows)];
      68             :     }
      69             : 
      70             :     /// Returns the element at the position \a row, \a col by value.
      71             :     inline double operator()(int row, int col) const
      72             :     {
      73             :         return v[row + col * static_cast<size_t>(n_rows)];
      74             :     }
      75             : 
      76             :     /// Returns the values of the matrix in column major order.
      77             :     double const *data() const
      78             :     {
      79             :         return v.data();
      80             :     }
      81             : 
      82             :     /// Returns the values of the matrix in column major order.
      83         123 :     double *data()
      84             :     {
      85         123 :         return v.data();
      86             :     }
      87             : 
      88             :     /// Resizes the matrix. All values are set to zero.
      89             :     void resize(int iRows, int iCols)
      90             :     {
      91             :         n_rows = iRows;
      92             :         n_cols = iCols;
      93             :         v.clear();
      94             :         v.resize(static_cast<size_t>(iRows) * iCols);
      95             :     }
      96             : 
      97             :   private:
      98             :     int n_rows = 0;
      99             :     int n_cols = 0;
     100             :     std::vector<double> v;
     101             : };
     102             : 
     103             : bool GDALLinearSystemSolve(GDALMatrix &A, GDALMatrix &RHS, GDALMatrix &X);
     104             : 
     105             : #endif /* #ifndef GDALLINEARSYSTEM_H_INCLUDED */
     106             : 
     107             : /*! @endcond */

Generated by: LCOV version 1.14