LCOV - code coverage report
Current view: top level - frmts/pcraster - pcrasterutil.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 3 30 10.0 %
Date: 2024-05-01 14:25:35 Functions: 1 10 10.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  PCRaster Integration
       5             :  * Purpose:  PCRaster driver support declarations.
       6             :  * Author:   Kor de Jong, Oliver Schmitz
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) PCRaster owners
      10             :  *
      11             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : #ifndef INCLUDED_PCRASTERUTIL
      31             : #define INCLUDED_PCRASTERUTIL
      32             : 
      33             : #include "csf.h"
      34             : #include "gdal_priv.h"
      35             : #include "pcrtypes.h"
      36             : 
      37             : GDALDataType cellRepresentation2GDALType(CSF_CR cellRepresentation);
      38             : 
      39             : CSF_VS string2ValueScale(const std::string &string);
      40             : 
      41             : std::string valueScale2String(CSF_VS valueScale);
      42             : 
      43             : std::string cellRepresentation2String(CSF_CR cellRepresentation);
      44             : 
      45             : CSF_VS GDALType2ValueScale(GDALDataType type);
      46             : 
      47             : /*
      48             : CSF_CR             string2PCRasterCellRepresentation(
      49             :                                         const std::string& string);
      50             :                                         */
      51             : 
      52             : CSF_CR GDALType2CellRepresentation(GDALDataType type, bool exact);
      53             : 
      54             : void *createBuffer(size_t size, CSF_CR type);
      55             : 
      56             : void deleteBuffer(void *buffer, CSF_CR type);
      57             : 
      58             : bool isContinuous(CSF_VS valueScale);
      59             : 
      60             : double missingValue(CSF_CR type);
      61             : 
      62             : void alterFromStdMV(void *buffer, size_t size, CSF_CR cellRepresentation,
      63             :                     double missingValue);
      64             : 
      65             : void alterToStdMV(void *buffer, size_t size, CSF_CR cellRepresentation,
      66             :                   double missingValue);
      67             : 
      68             : MAP *mapOpen(std::string const &filename, MOPEN_PERM mode);
      69             : 
      70             : CSF_VS fitValueScale(CSF_VS valueScale, CSF_CR cellRepresentation);
      71             : 
      72             : void castValuesToBooleanRange(void *buffer, size_t size,
      73             :                               CSF_CR cellRepresentation);
      74             : 
      75             : void castValuesToDirectionRange(void *buffer, size_t size);
      76             : 
      77             : void castValuesToLddRange(void *buffer, size_t size);
      78             : 
      79             : template <typename T> struct CastToBooleanRange
      80             : {
      81           0 :     void operator()(T &value) const
      82             :     {
      83           0 :         if (!pcr::isMV(value))
      84             :         {
      85           0 :             if (value != 0)
      86             :             {
      87           0 :                 value = T(value > T(0));
      88             :             }
      89             :             else
      90             :             {
      91           0 :                 pcr::setMV(value);
      92             :             }
      93             :         }
      94           0 :     }
      95             : };
      96             : 
      97             : template <> struct CastToBooleanRange<UINT1>
      98             : {
      99         100 :     void operator()(UINT1 &value) const
     100             :     {
     101         100 :         if (!pcr::isMV(value))
     102             :         {
     103           0 :             value = UINT1(value > UINT1(0));
     104             :         }
     105         100 :     }
     106             : };
     107             : 
     108             : template <> struct CastToBooleanRange<UINT2>
     109             : {
     110           0 :     void operator()(UINT2 &value) const
     111             :     {
     112           0 :         if (!pcr::isMV(value))
     113             :         {
     114           0 :             value = UINT2(value > UINT2(0));
     115             :         }
     116           0 :     }
     117             : };
     118             : 
     119             : template <> struct CastToBooleanRange<UINT4>
     120             : {
     121           0 :     void operator()(UINT4 &value) const
     122             :     {
     123           0 :         if (!pcr::isMV(value))
     124             :         {
     125           0 :             value = UINT4(value > UINT4(0));
     126             :         }
     127           0 :     }
     128             : };
     129             : 
     130             : struct CastToDirection
     131             : {
     132           0 :     void operator()(REAL4 &value) const
     133             :     {
     134           0 :         REAL4 factor = static_cast<REAL4>(M_PI / 180.0);
     135           0 :         if (!pcr::isMV(value))
     136             :         {
     137           0 :             value = REAL4(value * factor);
     138             :         }
     139           0 :     }
     140             : };
     141             : 
     142             : struct CastToLdd
     143             : {
     144           0 :     void operator()(UINT1 &value) const
     145             :     {
     146           0 :         if (!pcr::isMV(value))
     147             :         {
     148           0 :             if ((value < 1) || (value > 9))
     149             :             {
     150           0 :                 CPLError(CE_Warning, CPLE_IllegalArg,
     151             :                          "PCRaster driver: incorrect LDD value used, assigned "
     152             :                          "MV instead");
     153           0 :                 pcr::setMV(value);
     154             :             }
     155             :             else
     156             :             {
     157           0 :                 value = UINT1(value);
     158             :             }
     159             :         }
     160           0 :     }
     161             : };
     162             : 
     163             : #endif  // INCLUDED_PCRASTERUTIL

Generated by: LCOV version 1.14