1 /********************************************************************** 2 * 3 * PostGIS - Spatial Types for PostgreSQL 4 * http://postgis.net 5 * 6 * PostGIS is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * PostGIS is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with PostGIS. If not, see <http://www.gnu.org/licenses/>. 18 * 19 ********************************************************************** 20 * 21 * Copyright 2014 Nicklas Avén 22 * 23 **********************************************************************/ 24 25 #include "qgsabstractgeometry.h" 26 #include "qgscurve.h" 27 28 #define SIP_NO_FILE 29 30 #ifndef _EFFECTIVEAREA_H 31 #define _EFFECTIVEAREA_H 1 32 33 34 #define LWDEBUG // 35 #define LWDEBUGF // 36 #define FP_MAX std::max 37 #define FLAGS_GET_Z( flags ) ( ( flags ) & 0x01 ) 38 #define LW_MSG_MAXLEN 256 39 #define lwalloc qgsMalloc 40 #define lwfree qgsFree 41 #define lwerror qWarning 42 43 44 /** 45 * This structure is placed in an array with one member per point. 46 * It has links into the minheap rtee and keeps track of eliminated points. 47 */ 48 struct areanode 49 { 50 double area; 51 int treeindex; 52 int prev; 53 int next; 54 }; 55 56 /** 57 * This structure holds a minheap tree that is used to keep track of what points 58 * that has the smallest effective area. 59 * When eliminating points the neighbor points has its effective area affected 60 * and the minheap helps to resort efficient. 61 */ 62 struct MINHEAP 63 { 64 int maxSize; 65 int usedSize; 66 areanode **key_array = nullptr; 67 }; 68 69 /** 70 * Structure to hold point array and its arealist. 71 */ 72 struct EFFECTIVE_AREAS 73 { EFFECTIVE_AREASEFFECTIVE_AREAS74 EFFECTIVE_AREAS( const QgsCurve &curve ) 75 : is3d( curve.is3D() ) 76 { 77 curve.points( inpts ); 78 initial_arealist = new areanode[ inpts.size()]; 79 res_arealist = new double[ inpts.size()]; 80 } 81 ~EFFECTIVE_AREASEFFECTIVE_AREAS82 ~EFFECTIVE_AREAS() 83 { 84 delete [] initial_arealist; 85 delete [] res_arealist; 86 } 87 88 EFFECTIVE_AREAS( const EFFECTIVE_AREAS &other ) = delete; 89 EFFECTIVE_AREAS &operator=( const EFFECTIVE_AREAS &other ) = delete; 90 91 bool is3d; 92 QgsPointSequence inpts; 93 areanode *initial_arealist = nullptr; 94 double *res_arealist = nullptr; 95 96 97 }; 98 99 void ptarray_calc_areas( EFFECTIVE_AREAS *ea, int avoid_collaps, int set_area, double trshld ); 100 101 #endif /* _EFFECTIVEAREA_H */ 102