TINCreateIsolines.cpp
Go to the documentation of this file.
1 /*!
2 \file terralib/mnt/core/TINCreateIsolines.cpp
3 
4 \brief This file contains a class to generate isolines from TIN.
5 
6 */
7 
8 #include "TINCreateIsolines.h"
9 #include "Utils.h"
10 
11 #include "../../common/progress/TaskProgress.h"
12 
13 
15 {
16  if (!m_values.size())
17  return false;
18 
19  int32_t nodesid[3];
23  std::vector<te::gm::Point> ptline;
25  std::vector<te::gm::Point> pts;
26 
27  double cvalue;
28 
29  std::sort(m_values.begin(), m_values.end());
30 
31  double zmin = m_values[0];
32  double zmax = m_values[m_values.size() - 1];
33 
34  LoadTin(m_inDsrc, m_inDsetName, zmin, zmax);
35 
36  std::size_t ntri = m_triang.size();
37  te::common::TaskProgress task("Creating Isolines...");
38  task.setTotalSteps((int)(m_values.size()*ntri));
39 
40  for (size_t v = 0; v < m_values.size(); v++)
41  {
42  cvalue = m_values[v];
43 
44  for (size_t i = 0; i < ntri; i++)
45  {
46  if (!task.isActive())
47  return false;
48  task.pulse();
49  if (!NodesId((int32_t)i, nodesid))
50  continue;
51  for (size_t j = 0; j < 3; j++)
52  {
53  p3da[j].setX(m_node[(unsigned int)nodesid[j]].getNPoint().getX());
54  p3da[j].setY(m_node[(unsigned int)nodesid[j]].getNPoint().getY());
55  p3da[j].setZ(m_node[(unsigned int)nodesid[j]].getZ());
56  }
57  if (!testVertexValues(cvalue, p3da))
58  continue;
59 
60  // Define intersection between contour and triangle
61  defineInterTriangle(pts, p3da, cvalue);
62  }
63 
64  if (pts.size() > 2)
65  {
66  if (!extractLines(pts, m_isolist, m_tol))
67  {
68  return false;
69  }
70 
71  pts.clear();
72  }
73  }
74 
76 
77  return true;
78 }
79 
81  std::string inDsetName,
82  std::unique_ptr<te::da::DataSetType> inDsetType)
83 {
84  m_inDsrc = inDsrc;
85  m_inDsetName = inDsetName;
86  m_inDsetType = std::move(inDsetType);
87 }
88 
90 {
91  m_outDsrc = outDsrc;
92  m_outDsetName = dsname;
93 
94 }
95 
96 void te::mnt::TINCreateIsolines::setParams(std::vector<double> &val, std::vector<double> &gval, double tol)
97 {
98  m_values = val;
99  m_guidevalues = gval;
100  m_tol = tol;
101 }
102 
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType)
int m_srid
Attribute with spatial reference information.
Definition: Tin.h:596
void setParams(std::vector< double > &val, std::vector< double > &gval, double tol)
This file contains a class to generate isolines from a TIN. Adapted from SPRING.
te::da::DataSourcePtr m_outDsrc
bool NodesId(int32_t triangId, int32_t *nodeIds)
Method that reads the identification number of the nodes of a given triangle.
Definition: Tin.cpp:913
boost::shared_ptr< DataSource > DataSourcePtr
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
bool isActive() const
Verify if the task is active.
std::vector< TinTriang > m_triang
Triangulation triangles vector.
Definition: Tin.h:605
Utility functions for MNT support.
void setTotalSteps(int value)
Set the task total stepes.
te::da::DataSourcePtr m_inDsrc
std::vector< double > m_values
std::vector< double > m_guidevalues
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
A point with x and y coordinate values.
Definition: Point.h:50
std::unique_ptr< te::da::DataSetType > m_inDsetType
TEMNTEXPORT bool testVertexValues(double, te::gm::Point *)
Function that test the vertex values.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
TEMNTEXPORT bool extractLines(std::vector< te::gm::Point > &pline, std::vector< std::unique_ptr< te::gm::LineString > > &clinlist, double scale)
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:145
std::vector< TinNode > m_node
Triangulation nodes vector.
Definition: Tin.h:606
bool LoadTin(te::da::DataSourcePtr &inDsrc, std::string &inDsetName, double zmin=std::numeric_limits< double >::min(), double zmax=std::numeric_limits< double >::max())
Method used to load a triangular network (TIN)
Definition: Tin.cpp:1624
std::vector< std::unique_ptr< te::gm::LineString > > m_isolist
TEMNTEXPORT bool defineInterTriangle(std::vector< te::gm::Point > &, te::gm::Point *, double)
Function that defines the intersections between an isoline and a triangle.
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:159
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
TEMNTEXPORT bool SaveIso(std::string &outDsetName, te::da::DataSourcePtr &outDsrc, std::vector< std::unique_ptr< te::gm::LineString > > &isolist, std::vector< double > &guidevalues, int srid)
void setZ(const double &z)
It sets the Point z-coordinate value.
Definition: Point.h:173