DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
graphbuilder.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
5 
6 // This program 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 // This program 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 along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 /* --------------------------------------------------------------------------
22  * DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
23  * AND EFFORT DISPLACEMENT
24  * Copyright (c) 2012, 2013, 2014 Francois Bastardie <fba@aqua.dtu.dk>
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 2 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License along
37  * with this program; if not, write to the Free Software Foundation, Inc.,
38  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39  * --------------------------------------------------------------------------
40  */
41 #ifndef GRAPHBUILDER_H
42 #define GRAPHBUILDER_H
43 
44 #include <QList>
45 #include <QPointF>
46 
47 #include <memory>
48 #include <ogrsf_frmts.h>
49 
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Wpragmas"
52 #pragma GCC diagnostic ignored "-Wshift-negative-value"
53 #pragma GCC diagnostic ignored "-Wunused-parameter"
54 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
55 #include <CGAL/Triangulation_vertex_base_with_info_2.h>
56 #include <CGAL/Delaunay_triangulation_2.h>
57 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
58 #pragma GCC diagnostic pop
59 
60 #include <utility>
61 
62 namespace displace {
63 namespace graphbuilders {
64 class GeographicGridBuilder;
65 }
66 }
67 
68 namespace deprecated {
69 
71 {
72 public:
73  class Feedback {
74  public:
75  virtual void setMax(int m) = 0;
76  virtual void setStep(int step) = 0;
77  };
78 
79  enum Type { Hex, Quad, HexTrivial, QuadTrivial };
80 
81  class Node {
82  public:
83  QPointF point;
84  int harbour;
85  QList<int> adiacencies;
86  QList<double> weight;
87  bool good;
88 
89  Node()
90  : point(), harbour(0), adiacencies(), weight(), good(false) {
91  }
92  };
93 
94  GraphBuilder();
95 
96  void setType (Type type) {
97  mType = type;
98  }
99 
100  void setDefaultDistance (double distance) {
101  mStep = distance;
102  }
103 
104  void setDistance1 (double distance) {
105  mStep1 = distance;
106  }
107 
108  void setDistance2 (double distance) {
109  mStep2 = distance;
110  }
111 
112  void setFeedback (Feedback *feedback) {
113  mFeedback = feedback;
114  }
115 
116  void setLimits (double lonMin, double lonMax, double latMin, double latMax) ;
117  void setIncludingShapefile1 (std::shared_ptr<OGRDataSource> src);
118  void setIncludingShapefile2 (std::shared_ptr<OGRDataSource> src);
119  void setExcludingShapefile (std::shared_ptr<OGRDataSource> src);
121  mRemoveEdgesInExcludeZone = en;
122  }
123  void setMaxLinks(int num = -1) {
124  mMaxLinks = num;
125  }
126  void setMinLinks(int num = -1) {
127  mMinLinks = num;
128  }
129 
130  QList<Node> buildGraph();
131 
132  static void pointSumWithBearing (const QPointF &p1, double dist, double bearing, QPointF &p2);
133  static const double earthRadius;
134 
135  bool outsideEnabled() const;
136  void setOutsideEnabled(bool outsideEnabled);
137  void setLinkLimits(double limit_km);
138 
139 private:
140  typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
141  typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned, K> Vb;
142 
143  /*
144  typedef CGAL::Triangulation_data_structure_2<Vb> Tds;
145  typedef CGAL::Delaunay_triangulation_2<K, Tds> Delaunay;*/
146 
147  typedef CGAL::Constrained_triangulation_face_base_2<K> Fb;
148  typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
149  typedef CGAL::Exact_predicates_tag Itag;
150  typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
151 
152  typedef CDT::Point Point;
153 
154  void fillWithNodes(displace::graphbuilders::GeographicGridBuilder *builder, QList<Node> &res, CDT &tri, std::vector<std::shared_ptr<OGRDataSource> > including, std::vector<std::shared_ptr<OGRDataSource> > excluding, bool outside, int &progress);
155  void pushAd(QList<Node> &node, int source, int target);
156 
157  Type mType;
158  bool mOutsideEnabled, mRemoveEdgesInExcludeZone;
159  double mStep, mStep1, mStep2;
160  double mLatMin, mLatMax, mLonMin, mLonMax;
161  double mLinkLimits;
162  int mMaxLinks, mMinLinks;
163 
164  std::shared_ptr<OGRDataSource> mShapefileInc1;
165  std::shared_ptr<OGRDataSource> mShapefileInc2;
166  std::shared_ptr<OGRDataSource> mShapefileExc;
167 
168  Feedback *mFeedback;
169 };
170 }
171 
172 #endif // GRAPHBUILDER_H
CGAL::Exact_predicates_inexact_constructions_kernel K
Definition: graphbuilder_shp.cpp:42
void setFeedback(Feedback *feedback)
Definition: graphbuilder.h:112
double dist(double x1, double y1, double x2, double y2)
Definition: myRutils.h:109
Definition: decisiontreemanager.h:13
CGAL::Triangulation_data_structure_2< Vb, Fb > TDS
Definition: graphbuilder_shp.cpp:46
Type
Definition: graphbuilder.h:79
An abstract class to build a grid of points on a map, based on certain parameters.
Definition: geographicgridbuilder.h:29
Node()
Definition: graphbuilder.h:89
Definition: graphbuilder.h:81
CDT::Point Point
Definition: graphbuilder_shp.cpp:50
Definition: graphbuilder.h:70
CGAL::Constrained_triangulation_face_base_2< K > Fb
Definition: graphbuilder_shp.cpp:45
QList< double > weight
Definition: graphbuilder.h:86
bool good
Definition: graphbuilder.h:87
int harbour
Definition: graphbuilder.h:84
CGAL::Triangulation_vertex_base_with_info_2< unsigned, K > Vb
Definition: graphbuilder_shp.cpp:43
void setDefaultDistance(double distance)
Definition: graphbuilder.h:100
QPointF point
Definition: graphbuilder.h:83
Definition: graphbuilder.h:68
void setExcludeZoneEdgeRemovalEnabled(bool en)
Definition: graphbuilder.h:120
void setMinLinks(int num=-1)
Definition: graphbuilder.h:126
bg::model::point< double, 2, bg::cs::cartesian > point
Definition: diffusion.cpp:28
void setMaxLinks(int num=-1)
Definition: graphbuilder.h:123
void setType(Type type)
Definition: graphbuilder.h:96
CGAL::Exact_predicates_tag Itag
Definition: graphbuilder_shp.cpp:47
static const double earthRadius
Definition: graphbuilder.h:133
Definition: graphbuilder.h:73
CGAL::Constrained_Delaunay_triangulation_2< K, TDS, Itag > CDT
Definition: graphbuilder_shp.cpp:48
double bearing(double x1, double y1, double x2, double y2)
Definition: myRutils.h:119
void setDistance2(double distance)
Definition: graphbuilder.h:108
QList< int > adiacencies
Definition: graphbuilder.h:85
void setDistance1(double distance)
Definition: graphbuilder.h:104