Loading...
Searching...
No Matches
TINGeneration.h
Go to the documentation of this file.
1
2/*!
3\file terralib/mnt/core/TINGeneration.h
4
5\brief This file contains a class to generate TIN.
6 Adapted from SPRING
7
8 */
9
10#ifndef __TERRALIB_MNT_INTERNAL_TINGENERATION_H
11#define __TERRALIB_MNT_INTERNAL_TINGENERATION_H
12
13// Terralib Includes
14#include "Config.h"
15#include "Tin.h"
16
17#include "../../dataaccess/dataset/DataSet.h"
18#include "../../dataaccess/dataset/DataSetType.h"
19#include "../../dataaccess/datasource/DataSource.h"
20
21#include "../../geometry/MultiLineString.h"
22#include "../../geometry/MultiPoint.h"
23#include "../../geometry/Point.h"
24
25namespace te
26{
27 namespace mnt
28 {
29 /*!
30 \class TINGeneration
31
32 \brief Class to generate TIN.
33
34 \ingroup mnt
35
36 */
38 {
39 public:
40 /*! \brief Default constructor. */
42
44
45 /*!
46 \brief Generate TIN
47 \ return true or false.
48 */
49 bool run();
50
51 /*!
52 \brief It sets the Datasource that is being used to generate TIN.
53 \param inDsrc The datasource being used.
54 \param inDsetName datasource name
55 \param inDsetType input DataSetType
56 \param type Input type: Sample or Isoline
57 */
59 std::string inDsetName,
60 std::unique_ptr<te::da::DataSetType> inDsetType,
61 InputType type);
62
63 /*!
64 \brief It sets the BreakLine Datasource that is being used to generate TIN.
65 \param inDsrc The datasource contains breaklines.
66 \param inDsetName
67 \param inDsetType
68 \param tol breaklines simplification tolerance in meters.
69 */
70 void setBreakLine(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr<te::da::DataSetType> inDsetType, double tol);
71
72 /*!
73 \brief It sets the Datasource that is being used to save TIN.
74 \param inDsrc The output datasource.
75 \param dsname
76 */
77 void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname);
78
79 /*!
80 \brief It sets the parameters to generate TIN.
81 \param tolerance lines simplification tolerance in meters.
82 \param maxdist lines simplification maximum distance in meters.
83 \param minedgesize edges minimum size in meters.
84 \param atrz_iso isolines attribute contains Z value.
85 \param atrz_pt samples attribute contains Z value.
86 */
87 void setParams(const double& tolerance,
88 const double &maxdist,
89 const double &minedgesize,
90 const std::string &atrz_iso, const std::string &atrz_pt);
91
92 /*! Function used to set Triangulation lines simplification tolerance */
93 void setTolerance(double tolerance) { m_tolerance = tolerance; };
94
95 /*! Function used to set Triangulation lines simplification maximum distance */
96 void setMaxdist(double maxdist) { m_maxdist = maxdist; };
97
98 /*! Function used to set Triangulation edges minimum size */
99 void setMinedgesize(double minedgesize) { m_minedgesize = minedgesize; };
100
101 /*! Function used to set Triangulation method Delanay or Smaller Angle */
102 void setMethod(int method) { m_method = method; }
103
104 protected:
105 /*! Create the two initial triangles, based on box.*/
106 bool CreateInitialTriangles(size_t nsamples);
107
108 /*! Convert samples to nodes and insert them in Tin.
109 If farther than a tolerance from the closest point.*/
111
112 bool SaveTin();
113
114 /*!
115 \brief Method used to insert a node in a TIN (Triangular Irregular Network)
116 \param nodeId is the node identification number
117 \param type is the node type (0 - if Delaunay)
118 \return true if the node is inserted with no errors or false otherwise
119 */
120 bool InsertNode(int32_t nodeid, int type);
121
122 /*!
123 \brief Method used to delete a node in a TIN (Triangular Irregular Network)
124 \param node is the node identification number
125 \return true if the node is deleted with no errors or false otherwise
126 */
127 bool DeleteNode(int32_t node);
128
129 /*!
130 \brief Method used to exchange two nodes in a TIN (Triangular Irregular Network)
131 \param oldNnode is the old node identification number
132 \param newNnode is the new node identification number
133 \return true if the nodes are exchanged with no errors or false otherwise
134 */
135 bool NodeExchange(int32_t oldNode, int32_t newNode);
136
137 /*!
138 \brief Method used to create two new triangles in a TIN (Triangular Irregular Network)
139 \param t is a triangle identification number
140 \param nodeId is a node identification number
141 \param testLines is a pointer to a vector with number of lines to be tested
142 \return true if the triangles are created with no errors or false otherwise
143 */
144 bool TwoNewTriangles(int32_t t, int32_t nodeId, int32_t* testLines);
145
146 /*!
147 \brief Method used to duplicate a triangle in a TIN (Triangular Irregular Network)
148 \param t is a triangle identification number
149 \param n is the node identification number
150 \param v is a vertex identification number
151 \param testLines is a pointer to a vector with number of lines to be tested
152 \return id of new edge the duplicated triangles with no errors or -1 otherwise
153 */
154 int32_t DuplicateTriangle(int32_t t, short n, int32_t v, int32_t* testLines);
155
156 /*!
157 \brief Method used to duplicate a neighbour triangle in a TIN (Triangular Irregular Network)
158 \param tv is a triangle identification number
159 \param an0 is an edge identification number
160 \param v is a vertex identification number
161 \param testLines is a pointer to a vector with number of lines to be tested
162 \return true if the neighbor triangle is duplicated with no errors or false otherwise
163 */
164 bool DupNeighTriangle(int32_t tv, int32_t an0, short, int32_t v, int32_t *testLines);
165
166 /*!
167 \brief Method used to test if the triangulation follows the Delaunay rule
168 \param tri1Id is the identification number of the first triangle
169 \param tri2Id is the identification number of the second triangle
170 \param tri3Id is the identification number of the third triangle
171 \return true if the triangulation is Delaunay or FALSE otherwise
172 */
173
174 bool TestDelaunay(int32_t tri1Id, int32_t tri2Id, int32_t tri3Id);
175 /*!
176 \brief Method used to test if the triangulation follows the Delaunay rule
177 \param tri1Id is the identification number of the first triangle
178 \param tri2Id is the identification number of the second triangle
179 \param tri3Id is the identification number of the third triangle
180 \param tri4Id is the identification number of the fourth triangle
181 \return true if the triangulation is Delaunay or false otherwise
182 */
183 bool TestDelaunay(int32_t tri1Id, int32_t tri2Id, int32_t tri3Id, int32_t tri4Id);
184
185 /*!
186 \brief Method used to test if the triangulation follows the Delaunay rule
187 \param linId is the identification number of a line
188 \return true if the triangulation is Delaunay or false otherwise
189 */
190 bool TestDelaunay(int32_t linId);
191
192 /*!
193 \brief Method used to test if the triangulation follows the Delaunay rule
194 \param triId is a triangle identification number
195 \param nviz is the number of the neighbor of the triangle triId
196 \return true if the triangulation is Delaunay or false otherwise
197 */
198 bool TestDelaunay(int32_t triId, short nviz);
199
200 /*!
201 \brief Method used to Update Triangles of a given triangulation
202 \param t is a triangle identification number
203 \param tv is a triangle identification number
204 \param ai is a side number of a triangle
205 \return true if the triangles are updated or false otherwise
206 */
207 bool UpdateTriangles(int32_t t, int32_t tv, int32_t ai);
208
209
210 /*!
211 \brief Method that exchanges polygon
212 \param triangId is the triangle identification number
213 \param newPolyId is the new Polygon identification number
214 \param edge is the edge number of the triangle
215 \return the line identification
216 */
217 int32_t ExchangePolygon(int32_t triangId, int32_t newPolyId, unsigned short edge);
218
219 /*!
220 \brief Method that veryfies if the Isoline is a segment
221 \param linid is the line identification number
222 \return TRUE if the isoline is a segment or False otherwise
223 */
224 bool IsIsolineSegment(int32_t linid);
225
226 /*!
227 \brief Method that veryfies if the Breakline is a segment
228 \param linid is the line identification number
229 \return TRUE if the breakline is a segment or False otherwise
230 */
231 bool IsBreaklineSegment(int32_t linid);
232
233 bool IsNeighborOnIsoOrBreakline(int32_t triId, unsigned short nviz);
234
235 /*!
236 \brief Method that creates a Delaunay triangulation
237 \return TRUE if the triangulation is created with no errors or False otherwise
238 */
240
241 /*!
242 \brief Method that generates a Delaunay triangulation
243 \param nt is the triangle number
244 \param ntbase is the base triangle number
245 \param contr is a counter
246 \return TRUE if the triangulation is generated with no errors or False otherwise
247 */
248 bool GenerateDelaunay(int32_t nt, int32_t ntbase, int32_t contr);
249
250 /*!
251 \brief Method that modifies the bounds of Triangles
252 \return TRUE if the triangulation is generated with no errors or False otherwise
253 */
255
256 /*!
257 \brief Method that define the Constrained Isolines
258 \return TRUE if the Isolines are defined or FALSE otherwise
259 */
261
262 /*!
263 \brief Method that test the Isolines
264 \return true if the isolines are modified or false otherwise
265 */
266 bool TestIsolines(int iter);
267
268 /*!
269 \brief Method used to load a triangular network (TIN)
270 \return true if the TIN is loaded with no errors or false otherwise
271 */
272 bool LoadTin();
273
274
275 /*!
276 \brief Method used to create a Triangulation using the Minimum Angle Method
277 \return TRUE if the triangulation is created with no errors or FALSE otherwise
278 */
280
281 /*!
282 \brief Method used to test the angle between two normals
283 \param triId is the triangle identification number
284 \param nviz is the number of the neighbour triangle
285 \return TRUE if the angle is smaller than old triangles or FALSE otherwise
286 */
287 bool TestAngleBetweenNormals(int32_t triId, short nviz);
288
289 size_t ReadBreakLines(te::gm::MultiPoint &mpt, te::gm::MultiLineString &isolines, std::string &geostype);
290
292
294
295 /*!
296 \brief Method fint the point that intersects two triangles containing points pf and pn
297 \param pf is a pointer to the first point
298 \param pn is a pointer to the last point
299 \param p3d is a pointer to a list of Point3d objects
300 \return TRUE if the point is found with no errors or FALSE otherwise
301 */
302 bool FindInterPoints(te::gm::Point &pf, te::gm::Point &pn, std::vector<te::gm::Point> &p3d, std::vector<bool> &fixed);
303
304 /*!
305 \brief Method that checks if a point 3D is on the isoline segment
306 \param linid is the line identification number
307 \param pt3d is a pointer to a list of Point3D objects
308 \return TRUE if the point is on the isoline segment or FALSE otherwise
309 */
310 bool OnIsolineSegment(int32_t linid, te::gm::Point &pt3d, bool &fixed);
311
312 /*!
313 \brief Method that order lines
314 \return TRUE if the lines were ordered with no errors or FALSE otherwise
315 */
317
318 /*!
319 \brief Method that recreates a Delaunay triangulation
320 \return TRUE if the triangulation is recreated with no errors or False otherwise
321 */
323
324
325 /*!
326 \brief Method that regenerates a Delaunay triangulation
327 \param nt is the triangle number
328 \param ntbase is the base triangle number
329 \param contr is a counter
330 \return TRUE if the triangulation is regenerated with no errors or False otherwise
331 */
332 bool ReGenerateDelaunay(int32_t nt, int32_t ntbase, int32_t contr);
333
334 /*!
335 \brief Method that test if has flat triangles and regenerate them
336 */
338
339 bool RegeneratewithNewPoints(std::vector<te::gm::Point> &p3dl, std::vector<bool> &fixed);
340
341 te::gm::Geometry* neigh_union(te::gm::Geometry* tri_union, int32_t tri, std::vector<int32_t> &used_tri_all, std::map<int32_t, te::gm::Polygon> &pol_tri);
342
343 bool borderUp();
344
345 protected:
346
349 std::unique_ptr<te::da::DataSetType> m_inDsetType_sample;
350
353 std::unique_ptr<te::da::DataSetType> m_inDsetType_point;
354
357 std::unique_ptr<te::da::DataSetType> m_inDsetType_break;
358
360 std::string m_outDsetName;
361
362 std::string m_atrZ_sample;
363 std::string m_atrZ_point;
364
365 //te::gm::MultiPoint m_Points;
366 //te::gm::MultiLineString m_Lines;
367
368 double m_tolerance; //!< Triangulation lines simplification tolerance.
369 double m_maxdist; //!< Triangulation lines simplification maximum distance.
370 double m_minedgesize; //!< Triangulation edges minimum size.
371
372 double m_tolerance_break; //!< Triangulation breaklines simplification tolerance.
373
374 int m_method; //!< Triangulation method Delanay or Smaller Angle
375 };
376 } // end namespace mnt
377} // end namespace te
378
379#endif
380
This file contains a class to define a TIN. Adapted from SPRING.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition Geometry.h:78
MultiLineString is a MultiCurve whose elements are LineStrings.
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition MultiPoint.h:54
A point with x and y coordinate values.
Definition Point.h:51
Class to generate TIN.
bool TestFlatTriangles()
Method that test if has flat triangles and regenerate them.
bool IsIsolineSegment(int32_t linid)
Method that veryfies if the Isoline is a segment.
bool DupNeighTriangle(int32_t tv, int32_t an0, short, int32_t v, int32_t *testLines)
Method used to duplicate a neighbour triangle in a TIN (Triangular Irregular Network)
bool TestAngleBetweenNormals(int32_t triId, short nviz)
Method used to test the angle between two normals.
bool CreateDelaunay()
Method that creates a Delaunay triangulation.
bool LoadTin()
Method used to load a triangular network (TIN)
te::da::DataSourcePtr m_inDsrc_sample
bool run()
Generate TIN \ return true or false.
bool RegeneratewithNewPoints(std::vector< te::gm::Point > &p3dl, std::vector< bool > &fixed)
TINGeneration()
Default constructor.
bool IsolinesConstrained()
Method that define the Constrained Isolines.
bool InsertNodes(const te::gm::MultiPoint &mpt, const te::gm::MultiLineString &mls)
bool TestDelaunay(int32_t linId)
Method used to test if the triangulation follows the Delaunay rule.
int32_t ExchangePolygon(int32_t triangId, int32_t newPolyId, unsigned short edge)
Method that exchanges polygon.
bool NodeExchange(int32_t oldNode, int32_t newNode)
Method used to exchange two nodes in a TIN (Triangular Irregular Network)
te::da::DataSourcePtr m_inDsrc_break
std::string m_inDsetName_sample
bool IsNeighborOnIsoOrBreakline(int32_t triId, unsigned short nviz)
double m_tolerance_break
Triangulation breaklines simplification tolerance.
te::gm::Geometry * neigh_union(te::gm::Geometry *tri_union, int32_t tri, std::vector< int32_t > &used_tri_all, std::map< int32_t, te::gm::Polygon > &pol_tri)
bool FindInterPoints(te::gm::Point &pf, te::gm::Point &pn, std::vector< te::gm::Point > &p3d, std::vector< bool > &fixed)
Method fint the point that intersects two triangles containing points pf and pn.
void setParams(const double &tolerance, const double &maxdist, const double &minedgesize, const std::string &atrz_iso, const std::string &atrz_pt)
It sets the parameters to generate TIN.
bool GenerateDelaunay(int32_t nt, int32_t ntbase, int32_t contr)
Method that generates a Delaunay triangulation.
std::string m_inDsetName_break
bool TestDelaunay(int32_t tri1Id, int32_t tri2Id, int32_t tri3Id)
Method used to test if the triangulation follows the Delaunay rule.
te::da::DataSourcePtr m_inDsrc_point
int m_method
Triangulation method Delanay or Smaller Angle.
te::da::DataSourcePtr m_outDsrc
bool DeleteNode(int32_t node)
Method used to delete a node in a TIN (Triangular Irregular Network)
bool InsertNode(int32_t nodeid, int type)
Method used to insert a node in a TIN (Triangular Irregular Network)
bool TestDelaunay(int32_t triId, short nviz)
Method used to test if the triangulation follows the Delaunay rule.
std::unique_ptr< te::da::DataSetType > m_inDsetType_break
size_t ReadBreakLines(te::gm::MultiPoint &mpt, te::gm::MultiLineString &isolines, std::string &geostype)
bool OnIsolineSegment(int32_t linid, te::gm::Point &pt3d, bool &fixed)
Method that checks if a point 3D is on the isoline segment.
bool CreateInitialTriangles(size_t nsamples)
bool InsertBreakNodes(te::gm::MultiLineString &breaklines)
void setTolerance(double tolerance)
double m_maxdist
Triangulation lines simplification maximum distance.
bool UpdateTriangles(int32_t t, int32_t tv, int32_t ai)
Method used to Update Triangles of a given triangulation.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, InputType type)
It sets the Datasource that is being used to generate TIN.
bool ReGenerateDelaunay(int32_t nt, int32_t ntbase, int32_t contr)
Method that regenerates a Delaunay triangulation.
void setBreakLine(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, double tol)
It sets the BreakLine Datasource that is being used to generate TIN.
double m_minedgesize
Triangulation edges minimum size.
void setMinedgesize(double minedgesize)
void setMaxdist(double maxdist)
bool IsBreaklineSegment(int32_t linid)
Method that veryfies if the Breakline is a segment.
bool ReCreateDelaunay()
Method that recreates a Delaunay triangulation.
bool TestDelaunay(int32_t tri1Id, int32_t tri2Id, int32_t tri3Id, int32_t tri4Id)
Method used to test if the triangulation follows the Delaunay rule.
bool TwoNewTriangles(int32_t t, int32_t nodeId, int32_t *testLines)
Method used to create two new triangles in a TIN (Triangular Irregular Network)
double m_tolerance
Triangulation lines simplification tolerance.
std::string m_inDsetName_point
bool CreateMinAngleTriangulation()
Method used to create a Triangulation using the Minimum Angle Method.
bool TestIsolines(int iter)
Method that test the Isolines.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the Datasource that is being used to save TIN.
void setMethod(int method)
bool OrderLines()
Method that order lines.
int32_t DuplicateTriangle(int32_t t, short n, int32_t v, int32_t *testLines)
Method used to duplicate a triangle in a TIN (Triangular Irregular Network)
std::unique_ptr< te::da::DataSetType > m_inDsetType_sample
std::unique_ptr< te::da::DataSetType > m_inDsetType_point
bool ModifyBoundTriangles()
Method that modifies the bounds of Triangles.
Class to define TIN strutures.
Definition Tin.h:277
boost::shared_ptr< DataSource > DataSourcePtr
InputType
Input types.
Definition Enums.h:49
TerraLib.
#define TEMNTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition Config.h:41
Proxy configuration file for TerraView (see terraview_config.h).