LCOV - code coverage report
Current view: top level - analysis/interpolation - NormVecDecorator.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 10 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                           NormVecDecorator.h  -  description
       3                 :            :                              -------------------
       4                 :            :     copyright            : (C) 2004 by Marco Hugentobler
       5                 :            :     email                : mhugent@geo.unizh.ch
       6                 :            :  ***************************************************************************/
       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 NORMVECDECORATOR_H
      18                 :            : #define NORMVECDECORATOR_H
      19                 :            : 
      20                 :            : #include "TriDecorator.h"
      21                 :            : #include "qgis_sip.h"
      22                 :            : #include "TriangleInterpolator.h"
      23                 :            : #include "MathUtils.h"
      24                 :            : #include "qgslogger.h"
      25                 :            : #include "qgis_analysis.h"
      26                 :            : 
      27                 :            : #define SIP_NO_FILE
      28                 :            : 
      29                 :            : class QgsFeedback;
      30                 :            : 
      31                 :            : /**
      32                 :            :  * \ingroup analysis
      33                 :            :  * \brief Decorator class which adds the functionality of estimating normals at the data points.
      34                 :            :  * \note Not available in Python bindings.
      35                 :            : */
      36                 :            : class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
      37                 :            : {
      38                 :            :   public:
      39                 :            :     //! Enumeration for the state of a point. Normal means, that the point is not on a BreakLine, BreakLine means that the point is on a breakline (but not an end point of it) and EndPoint means, that it is an endpoint of a breakline.
      40                 :            :     enum PointState {Normal, BreakLine, EndPoint};
      41                 :            :     NormVecDecorator();
      42                 :            :     //! Constructor for TriDecorator with an existing triangulation
      43                 :            :     NormVecDecorator( QgsTriangulation *tin );
      44                 :            :     ~NormVecDecorator() override;
      45                 :            :     int addPoint( const QgsPoint &p ) override;
      46                 :            :     //! Calculates the normal at a point on the surface and assigns it to 'result'. Returns TRUE in case of success and FALSE in case of failure
      47                 :            :     bool calcNormal( double x, double y, QgsPoint &result SIP_OUT ) override;
      48                 :            :     //! Calculates the normal of a triangle-point for the point with coordinates x and y. This is needed, if a point is on a break line and there is no unique normal stored in 'mNormVec'. Returns FALSE, it something went wrong and TRUE otherwise
      49                 :            :     bool calcNormalForPoint( double x, double y, int pointIndex, Vector3D *result SIP_OUT );
      50                 :            :     bool calcPoint( double x, double y, QgsPoint &result SIP_OUT ) override;
      51                 :            :     //! Eliminates the horizontal triangles by swapping or by insertion of new points. If alreadyestimated is TRUE, a re-estimation of the normals will be done
      52                 :            :     void eliminateHorizontalTriangles() override;
      53                 :            :     //! Estimates the first derivative a point. Return TRUE in case of success and FALSE otherwise
      54                 :            :     bool estimateFirstDerivative( int pointno );
      55                 :            :     //! This method adds the functionality of estimating normals at the data points. Return TRUE in the case of success and FALSE otherwise
      56                 :            :     bool estimateFirstDerivatives( QgsFeedback *feedback = nullptr );
      57                 :            :     //! Returns a pointer to the normal vector for the point with the number n
      58                 :            :     Vector3D *getNormal( int n ) const;
      59                 :            :     //! Finds out, in which triangle a point with coordinates x and y is and assigns the triangle points to p1, p2, p3 and the estimated normals to v1, v2, v3. The vectors are normally taken from 'mNormVec', except if p1, p2 or p3 is a point on a breakline. In this case, the normal is calculated on-the-fly. Returns FALSE, if something went wrong and TRUE otherwise
      60                 :            :     bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, Vector3D *v1 SIP_OUT, QgsPoint &p2 SIP_OUT, Vector3D *v2 SIP_OUT, QgsPoint &p3 SIP_OUT, Vector3D *v3 SIP_OUT )  SIP_PYNAME( getTriangleVertices );
      61                 :            :     //! This function behaves similar to the one above. Additionally, the numbers of the points are returned (ptn1, ptn2, ptn3) as well as the PointStates of the triangle points (state1, state2, state3)
      62                 :            :     bool getTriangle( double x, double y, QgsPoint &p1 SIP_OUT, int &ptn1 SIP_OUT, Vector3D *v1 SIP_OUT, PointState *state1 SIP_OUT, QgsPoint &p2 SIP_OUT, int &ptn2 SIP_OUT, Vector3D *v2 SIP_OUT, PointState *state2 SIP_OUT, QgsPoint &p3 SIP_OUT, int &ptn3 SIP_OUT, Vector3D *v3 SIP_OUT, PointState *state3 SIP_OUT );
      63                 :            :     //! Returns the state of the point with the number 'pointno'
      64                 :            :     PointState getState( int pointno ) const;
      65                 :            :     //! Sets an interpolator
      66                 :            :     void setTriangleInterpolator( TriangleInterpolator *inter ) override;
      67                 :            :     //! Swaps the edge which is closest to the point with x and y coordinates (if this is possible) and forces recalculation of the concerned normals (if alreadyestimated is TRUE)
      68                 :            :     bool swapEdge( double x, double y ) override;
      69                 :            : 
      70                 :            :     bool saveTriangulation( QgsFeatureSink *sink, QgsFeedback *feedback = nullptr ) const override;
      71                 :            : 
      72                 :            :     QgsMesh triangulationToMesh( QgsFeedback *feedback = nullptr ) const override;
      73                 :            : 
      74                 :            :   protected:
      75                 :            :     //! Is TRUE, if the normals already have been estimated
      76                 :            :     bool alreadyestimated;
      77                 :            :     static const unsigned int DEFAULT_STORAGE_FOR_NORMALS = 100000;
      78                 :            :     //! Association with an interpolator object
      79                 :          0 :     TriangleInterpolator *mInterpolator = nullptr;
      80                 :            :     //! Vector that stores the normals for the points. If 'estimateFirstDerivatives()' was called and there is NULLPTR, this means, that the triangle point is on a breakline
      81                 :            :     QVector<Vector3D *> *mNormVec;
      82                 :            :     //! Vector who stores, it a point is not on a breakline, if it is a normal point of the breakline or if it is an endpoint of a breakline
      83                 :            :     QVector<PointState> *mPointState;
      84                 :            :     //! Sets the state (BreakLine, Normal, EndPoint) of a point
      85                 :            :     void setState( int pointno, PointState s );
      86                 :            : 
      87                 :            :   private:
      88                 :            :     NormVecDecorator( const NormVecDecorator & ) = delete;
      89                 :            :     NormVecDecorator &operator=( const NormVecDecorator & ) = delete;
      90                 :            : };
      91                 :            : 
      92                 :            : #ifndef SIP_RUN
      93                 :            : 
      94                 :          0 : inline NormVecDecorator::NormVecDecorator()
      95                 :          0 :   : mNormVec( new QVector<Vector3D*>( DEFAULT_STORAGE_FOR_NORMALS ) )
      96                 :          0 :   , mPointState( new QVector<PointState>( DEFAULT_STORAGE_FOR_NORMALS ) )
      97                 :          0 : {
      98                 :          0 :   alreadyestimated = false;
      99                 :          0 : }
     100                 :            : 
     101                 :            : inline NormVecDecorator::NormVecDecorator( QgsTriangulation *tin )
     102                 :            :   : TriDecorator( tin )
     103                 :            :   , mNormVec( new QVector<Vector3D*>( DEFAULT_STORAGE_FOR_NORMALS ) )
     104                 :            :   , mPointState( new QVector<PointState>( DEFAULT_STORAGE_FOR_NORMALS ) )
     105                 :            : {
     106                 :            :   alreadyestimated = false;
     107                 :            : }
     108                 :            : 
     109                 :          0 : inline void NormVecDecorator::setTriangleInterpolator( TriangleInterpolator *inter )
     110                 :            : {
     111                 :          0 :   mInterpolator = inter;
     112                 :          0 : }
     113                 :            : 
     114                 :            : inline Vector3D *NormVecDecorator::getNormal( int n ) const
     115                 :            : {
     116                 :            :   if ( mNormVec )
     117                 :            :   {
     118                 :            :     return mNormVec->at( n );
     119                 :            :   }
     120                 :            :   else
     121                 :            :   {
     122                 :            :     QgsDebugMsg( QStringLiteral( "warning, null pointer" ) );
     123                 :            :     return nullptr;
     124                 :            :   }
     125                 :            : }
     126                 :            : 
     127                 :            : #endif
     128                 :            : 
     129                 :            : #endif

Generated by: LCOV version 1.14