LCOV - code coverage report
Current view: top level - core - qgsmaptopixelgeometrysimplifier.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 1 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :     qgsmaptopixelgeometrysimplifier.h
       3                 :            :     ---------------------
       4                 :            :     begin                : December 2013
       5                 :            :     copyright            : (C) 2013 by Alvaro Huarte
       6                 :            :     email                : http://wiki.osgeo.org/wiki/Alvaro_Huarte
       7                 :            : 
       8                 :            :  ***************************************************************************
       9                 :            :  *                                                                         *
      10                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      11                 :            :  *   it under the terms of the GNU General Public License as published by  *
      12                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      13                 :            :  *   (at your option) any later version.                                   *
      14                 :            :  *                                                                         *
      15                 :            :  ***************************************************************************/
      16                 :            : 
      17                 :            : #ifndef QGSMAPTOPIXELGEOMETRYSIMPLIFIER_H
      18                 :            : #define QGSMAPTOPIXELGEOMETRYSIMPLIFIER_H
      19                 :            : 
      20                 :            : #include "qgis_core.h"
      21                 :            : #include "qgis_sip.h"
      22                 :            : #include "qgsgeometrysimplifier.h"
      23                 :            : #include <QPolygonF>
      24                 :            : #include <memory>
      25                 :            : 
      26                 :            : class QgsAbstractGeometry;
      27                 :            : class QgsWkbPtr;
      28                 :            : class QgsConstWkbPtr;
      29                 :            : 
      30                 :            : 
      31                 :            : /**
      32                 :            :  * \ingroup core
      33                 :            :  * \brief Implementation of GeometrySimplifier using the "MapToPixel" algorithm
      34                 :            :  *
      35                 :            :  * Simplifies a geometry removing points within of the maximum distance difference that defines the MapToPixel info of a RenderContext request.
      36                 :            :  * This class enables simplify the geometries to be rendered in a MapCanvas target to speed up the vector drawing.
      37                 :            :  */
      38                 :          0 : class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
      39                 :            : {
      40                 :            :   public:
      41                 :            :     //! Types of simplification algorithms that can be used
      42                 :            :     enum SimplifyAlgorithm
      43                 :            :     {
      44                 :            :       Distance    = 0, //!< The simplification uses the distance between points to remove duplicate points
      45                 :            :       SnapToGrid  = 1, //!< The simplification uses a grid (similar to ST_SnapToGrid) to remove duplicate points
      46                 :            :       Visvalingam = 2, //!< The simplification gives each point in a line an importance weighting, so that least important points are removed first
      47                 :            :       SnappedToGridGlobal = 3, //!< Snap to a global grid based on the tolerance. Good for consistent results for incoming vertices, regardless of their feature
      48                 :            :     };
      49                 :            : 
      50                 :            :     //! Constructor
      51                 :            :     QgsMapToPixelSimplifier( int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
      52                 :            : 
      53                 :            :     //! Applicable simplification flags
      54                 :            :     enum SimplifyFlag
      55                 :            :     {
      56                 :            :       NoFlags          = 0, //!< No simplification can be applied
      57                 :            :       SimplifyGeometry = 1, //!< The geometries can be simplified using the current map2pixel context state
      58                 :            :       SimplifyEnvelope = 2, //!< The geometries can be fully simplified by its BoundingBox
      59                 :            :     };
      60                 :            : 
      61                 :            :   private:
      62                 :            :     //! Simplify the geometry using the specified tolerance
      63                 :            :     static std::unique_ptr<QgsAbstractGeometry> simplifyGeometry( int simplifyFlags, SimplifyAlgorithm simplifyAlgorithm, const QgsAbstractGeometry &geometry, double map2pixelTol, bool isaLinearRing );
      64                 :            : 
      65                 :            :   protected:
      66                 :            :     //! Current simplification flags
      67                 :            :     int mSimplifyFlags;
      68                 :            : 
      69                 :            :     //! Current algorithm
      70                 :            :     SimplifyAlgorithm mSimplifyAlgorithm;
      71                 :            : 
      72                 :            :     //! Distance tolerance for the simplification
      73                 :            :     double mTolerance;
      74                 :            : 
      75                 :            :     //! Returns the squared 2D-distance of the vector defined by the two points specified
      76                 :            :     static float calculateLengthSquared2D( double x1, double y1, double x2, double y2 );
      77                 :            : 
      78                 :            :     //! Returns whether the points belong to the same grid
      79                 :            :     static bool equalSnapToGrid( double x1, double y1, double x2, double y2, double gridOriginX, double gridOriginY, float gridInverseSizeXY );
      80                 :            : 
      81                 :            :   public:
      82                 :            :     //! Gets the simplification hints of the vector layer managed
      83                 :            :     int simplifyFlags() const { return mSimplifyFlags; }
      84                 :            :     //! Sets the simplification hints of the vector layer managed
      85                 :            :     void setSimplifyFlags( int simplifyFlags ) { mSimplifyFlags = simplifyFlags; }
      86                 :            : 
      87                 :            :     //! Gets the local simplification algorithm of the vector layer managed
      88                 :            :     SimplifyAlgorithm simplifyAlgorithm() const { return mSimplifyAlgorithm; }
      89                 :            :     //! Sets the local simplification algorithm of the vector layer managed
      90                 :            :     void setSimplifyAlgorithm( SimplifyAlgorithm simplifyAlgorithm ) { mSimplifyAlgorithm = simplifyAlgorithm; }
      91                 :            : 
      92                 :            :     QgsGeometry simplify( const QgsGeometry &geometry ) const override;
      93                 :            :     QgsAbstractGeometry *simplify( const QgsAbstractGeometry *geometry ) const override SIP_FACTORY;
      94                 :            : 
      95                 :            :     //! Sets the tolerance of the vector layer managed
      96                 :            :     void setTolerance( double value ) { mTolerance = value; }
      97                 :            : 
      98                 :            :     // MapToPixel simplification helper methods
      99                 :            :   public:
     100                 :            : 
     101                 :            :     //! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
     102                 :            :     static bool isGeneralizableByMapBoundingBox( const QgsRectangle &envelope, double map2pixelTol );
     103                 :            : 
     104                 :            :     //! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
     105                 :            :     inline bool isGeneralizableByMapBoundingBox( const QgsRectangle &envelope ) const
     106                 :            :     {
     107                 :            :       return isGeneralizableByMapBoundingBox( envelope, mTolerance );
     108                 :            :     }
     109                 :            : };
     110                 :            : 
     111                 :            : #endif // QGSMAPTOPIXELGEOMETRYSIMPLIFIER_H

Generated by: LCOV version 1.14