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 
25 namespace te
26 {
27  namespace mnt
28  {
29  /*!
30  \class TINGeneration
31 
32  \brief Class to generate TIN.
33 
34  \ingroup mnt
35 
36  */
37  class TEMNTEXPORT TINGeneration : public Tin
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  */
316  bool OrderLines();
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 
348  std::string m_inDsetName_sample;
349  std::unique_ptr<te::da::DataSetType> m_inDsetType_sample;
350 
352  std::string m_inDsetName_point;
353  std::unique_ptr<te::da::DataSetType> m_inDsetType_point;
354 
356  std::string m_inDsetName_break;
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 
Tin.h
This file contains a class to define a TIN. Adapted from SPRING.
te::mnt::TINGeneration::ModifyBoundTriangles
bool ModifyBoundTriangles()
Method that modifies the bounds of Triangles.
te::mnt::TINGeneration::setMaxdist
void setMaxdist(double maxdist)
Definition: TINGeneration.h:96
te::mnt::TINGeneration::borderUp
bool borderUp()
te::mnt::TINGeneration::m_outDsrc
te::da::DataSourcePtr m_outDsrc
Definition: TINGeneration.h:359
te::gm::MultiPoint
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:54
te::mnt::TINGeneration::m_tolerance_break
double m_tolerance_break
Triangulation breaklines simplification tolerance.
Definition: TINGeneration.h:372
te::mnt::TINGeneration::InsertBreakNodes
bool InsertBreakNodes(te::gm::MultiLineString &breaklines)
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::mnt::TINGeneration::ReadBreakLines
size_t ReadBreakLines(te::gm::MultiPoint &mpt, te::gm::MultiLineString &isolines, std::string &geostype)
te::mnt::TINGeneration::m_inDsetName_point
std::string m_inDsetName_point
Definition: TINGeneration.h:352
te::mnt::TINGeneration::DeleteNode
bool DeleteNode(int32_t node)
Method used to delete a node in a TIN (Triangular Irregular Network)
te::mnt::TINGeneration::m_tolerance
double m_tolerance
Triangulation lines simplification tolerance.
Definition: TINGeneration.h:368
te::mnt::Tin
Class to define TIN strutures.
Definition: Tin.h:277
te::mnt::TINGeneration::m_method
int m_method
Triangulation method Delanay or Smaller Angle.
Definition: TINGeneration.h:374
te::mnt::TINGeneration::CreateDelaunay
bool CreateDelaunay()
Method that creates a Delaunay triangulation.
te::mnt::TINGeneration::m_inDsrc_sample
te::da::DataSourcePtr m_inDsrc_sample
Definition: TINGeneration.h:347
te::mnt::TINGeneration::setOutput
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the Datasource that is being used to save TIN.
te::mnt::TINGeneration::LoadTin
bool LoadTin()
Method used to load a triangular network (TIN)
te::mnt::TINGeneration::IsIsolineSegment
bool IsIsolineSegment(int32_t linid)
Method that veryfies if the Isoline is a segment.
te::mnt::TINGeneration::m_inDsrc_point
te::da::DataSourcePtr m_inDsrc_point
Definition: TINGeneration.h:351
te::mnt::TINGeneration
Class to generate TIN.
Definition: TINGeneration.h:38
te::mnt::TINGeneration::m_outDsetName
std::string m_outDsetName
Definition: TINGeneration.h:360
te::mnt::TINGeneration::IsolinesConstrained
bool IsolinesConstrained()
Method that define the Constrained Isolines.
te::mnt::TINGeneration::setTolerance
void setTolerance(double tolerance)
Definition: TINGeneration.h:93
te::mnt::TINGeneration::CreateInitialTriangles
bool CreateInitialTriangles(size_t nsamples)
te::mnt::TINGeneration::RegeneratewithNewPoints
bool RegeneratewithNewPoints(std::vector< te::gm::Point > &p3dl, std::vector< bool > &fixed)
te::mnt::TINGeneration::SaveTin
bool SaveTin()
te::mnt::TINGeneration::neigh_union
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)
te::mnt::TINGeneration::setMinedgesize
void setMinedgesize(double minedgesize)
Definition: TINGeneration.h:99
te::mnt::TINGeneration::OrderLines
bool OrderLines()
Method that order lines.
te::mnt::TINGeneration::m_inDsetType_break
std::unique_ptr< te::da::DataSetType > m_inDsetType_break
Definition: TINGeneration.h:357
te::mnt::TINGeneration::run
bool run()
Generate TIN \ return true or false.
te::mnt::TINGeneration::setInput
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.
te::mnt::TINGeneration::m_minedgesize
double m_minedgesize
Triangulation edges minimum size.
Definition: TINGeneration.h:370
te::mnt::TINGeneration::m_atrZ_point
std::string m_atrZ_point
Definition: TINGeneration.h:363
te::mnt::TINGeneration::~TINGeneration
~TINGeneration()
te::mnt::TINGeneration::TestDelaunay
bool TestDelaunay(int32_t linId)
Method used to test if the triangulation follows the Delaunay rule.
te::mnt::TINGeneration::IsBreaklineSegment
bool IsBreaklineSegment(int32_t linid)
Method that veryfies if the Breakline is a segment.
te::mnt::TINGeneration::TestFlatTriangles
bool TestFlatTriangles()
Method that test if has flat triangles and regenerate them.
te::mnt::TINGeneration::UpdateTriangles
bool UpdateTriangles(int32_t t, int32_t tv, int32_t ai)
Method used to Update Triangles of a given triangulation.
te::mnt::TINGeneration::TestIsolines
bool TestIsolines(int iter)
Method that test the Isolines.
te::mnt::TINGeneration::FindInterPoints
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.
te::mnt::TINGeneration::TwoNewTriangles
bool TwoNewTriangles(int32_t t, int32_t nodeId, int32_t *testLines)
Method used to create two new triangles in a TIN (Triangular Irregular Network)
te::mnt::InputType
InputType
Input types.
Definition: Enums.h:49
te::mnt::TINGeneration::m_atrZ_sample
std::string m_atrZ_sample
Definition: TINGeneration.h:362
te::mnt::TINGeneration::TestDelaunay
bool TestDelaunay(int32_t tri1Id, int32_t tri2Id, int32_t tri3Id)
Method used to test if the triangulation follows the Delaunay rule.
te::mnt::TINGeneration::ReGenerateDelaunay
bool ReGenerateDelaunay(int32_t nt, int32_t ntbase, int32_t contr)
Method that regenerates a Delaunay triangulation.
te::mnt::TINGeneration::DuplicateTriangle
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)
te::mnt::TINGeneration::TestDelaunay
bool TestDelaunay(int32_t triId, short nviz)
Method used to test if the triangulation follows the Delaunay rule.
te::mnt::TINGeneration::m_inDsrc_break
te::da::DataSourcePtr m_inDsrc_break
Definition: TINGeneration.h:355
te::mnt::TINGeneration::InsertNodes
bool InsertNodes(const te::gm::MultiPoint &mpt, const te::gm::MultiLineString &mls)
te::mnt::TINGeneration::m_inDsetName_break
std::string m_inDsetName_break
Definition: TINGeneration.h:356
te::mnt::TINGeneration::TestDelaunay
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.
te::mnt::TINGeneration::OnIsolineSegment
bool OnIsolineSegment(int32_t linid, te::gm::Point &pt3d, bool &fixed)
Method that checks if a point 3D is on the isoline segment.
te::mnt::TINGeneration::m_inDsetType_sample
std::unique_ptr< te::da::DataSetType > m_inDsetType_sample
Definition: TINGeneration.h:349
te::mnt::TINGeneration::setParams
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.
te::mnt::TINGeneration::TINGeneration
TINGeneration()
Default constructor.
te::mnt::TINGeneration::m_inDsetType_point
std::unique_ptr< te::da::DataSetType > m_inDsetType_point
Definition: TINGeneration.h:353
te::da::DataSourcePtr
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1449
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::gm::MultiLineString
MultiLineString is a MultiCurve whose elements are LineStrings.
Definition: MultiLineString.h:55
te::mnt::TINGeneration::InsertBreakLines
bool InsertBreakLines()
te::mnt::TINGeneration::ExchangePolygon
int32_t ExchangePolygon(int32_t triangId, int32_t newPolyId, unsigned short edge)
Method that exchanges polygon.
te::mnt::TINGeneration::CreateMinAngleTriangulation
bool CreateMinAngleTriangulation()
Method used to create a Triangulation using the Minimum Angle Method.
te::gm::Geometry
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
te::mnt::TINGeneration::TestAngleBetweenNormals
bool TestAngleBetweenNormals(int32_t triId, short nviz)
Method used to test the angle between two normals.
te::mnt::TINGeneration::IsNeighborOnIsoOrBreakline
bool IsNeighborOnIsoOrBreakline(int32_t triId, unsigned short nviz)
te::mnt::TINGeneration::GenerateDelaunay
bool GenerateDelaunay(int32_t nt, int32_t ntbase, int32_t contr)
Method that generates a Delaunay triangulation.
te::mnt::TINGeneration::m_inDsetName_sample
std::string m_inDsetName_sample
Definition: TINGeneration.h:348
TEMNTEXPORT
#define TEMNTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:41
te::mnt::TINGeneration::setBreakLine
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.
te::mnt::TINGeneration::ReCreateDelaunay
bool ReCreateDelaunay()
Method that recreates a Delaunay triangulation.
te::mnt::TINGeneration::DupNeighTriangle
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)
te::gm::Point
A point with x and y coordinate values.
Definition: Point.h:51
te::mnt::TINGeneration::NodeExchange
bool NodeExchange(int32_t oldNode, int32_t newNode)
Method used to exchange two nodes in a TIN (Triangular Irregular Network)
te::mnt::TINGeneration::m_maxdist
double m_maxdist
Triangulation lines simplification maximum distance.
Definition: TINGeneration.h:369
te::mnt::TINGeneration::setMethod
void setMethod(int method)
Definition: TINGeneration.h:102
te::mnt::TINGeneration::InsertNode
bool InsertNode(int32_t nodeid, int type)
Method used to insert a node in a TIN (Triangular Irregular Network)