SAGA API  v9.5
tin.h
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // tin.h //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Goldschmidtstr. 5 //
45 // 37077 Goettingen //
46 // Germany //
47 // //
48 // e-mail: oconrad@saga-gis.org //
49 // //
51 
52 //---------------------------------------------------------
53 #ifndef HEADER_INCLUDED__SAGA_API__tin_H
54 #define HEADER_INCLUDED__SAGA_API__tin_H
55 
56 
58 // //
59 // //
60 // //
62 
63 //---------------------------------------------------------
75 // //
77 // //
78 // //
80 
81 //---------------------------------------------------------
82 #include "shapes.h"
83 
84 
86 // //
87 // //
88 // //
90 
91 //---------------------------------------------------------
93 {
94  friend class CSG_TIN;
95 
96 public:
97 
98  int Get_ID (void) { return( m_ID ); }
99 
100  const TSG_Point & Get_Point (void) { return( m_Point ); }
101  double Get_X (void) { return( m_Point.x ); }
102  double Get_Y (void) { return( m_Point.y ); }
103 
104  int Get_Neighbor_Count (void) { return( m_nNeighbors ); }
105  CSG_TIN_Node * Get_Neighbor (int iNeighbor) { return( iNeighbor >= 0 && iNeighbor < m_nNeighbors ? m_Neighbors[iNeighbor] : NULL ); }
106  double Get_Gradient (int iNeighbor, int iField);
107 
108  int Get_Triangle_Count (void) { return( m_nTriangles ); }
109  class CSG_TIN_Triangle * Get_Triangle (int iTriangle) { return( iTriangle >= 0 && iTriangle < m_nTriangles ? m_Triangles[iTriangle] : NULL ); }
110 
111  bool Get_Polygon (CSG_Points &Points);
112  double Get_Polygon_Area (void);
113 
114 
115 private:
116 
117  CSG_TIN_Node(CSG_TIN *pOwner, sLong Index);
118  virtual ~CSG_TIN_Node(void);
119 
120 
121  int m_ID, m_nNeighbors, m_nTriangles;
122 
123  TSG_Point m_Point;
124 
125  CSG_TIN_Node **m_Neighbors;
126 
127  class CSG_TIN_Triangle **m_Triangles;
128 
129 
130  bool _Add_Neighbor (CSG_TIN_Node *pNeighbor);
131  bool _Add_Triangle (class CSG_TIN_Triangle *pTriangle);
132 
133  bool _Del_Relations (void);
134 
135 };
136 
137 
139 // //
140 // //
141 // //
143 
144 //---------------------------------------------------------
146 {
147  friend class CSG_TIN;
148 
149 public:
150 
151  CSG_TIN_Node * Get_Node (int iNode) { return( m_Nodes[iNode % 2] ); }
152 
153 
154 private:
155 
157  virtual ~CSG_TIN_Edge(void);
158 
159 
160  CSG_TIN_Node *m_Nodes[2];
161 
162 };
163 
164 
166 // //
167 // //
168 // //
170 
171 //---------------------------------------------------------
173 {
174  friend class CSG_TIN;
175 
176 public:
177 
178  CSG_TIN_Node * Get_Node (int iNode) { return( m_Nodes[iNode % 3] ); }
179 
180  const CSG_Rect & Get_Extent (void) { return( m_Extent ); }
181 
182  double Get_Area (void) { return( m_Area ); }
183 
184  bool is_Containing (const TSG_Point &p);
185  bool is_Containing (double x, double y);
186 
187  bool Get_Value (int zField, const TSG_Point &p, double &z);
188  bool Get_Value (int zField, double x, double y, double &z);
189 
190  bool Get_Gradient (int zField, double &Decline, double &Azimuth);
191 
192  void Get_CircumCircle (TSG_Point &Point, double &Radius) { Point = m_Center; Radius = m_Radius; }
193  double Get_CircumCircle_Radius (void) { return( m_Radius ); }
194  TSG_Point Get_CircumCircle_Point (void) { return( m_Center ); }
195 
196 
197 private:
198 
200  virtual ~CSG_TIN_Triangle(void);
201 
202 
203  double m_Area, m_Radius;
204 
205  TSG_Point m_Center;
206 
208 
209  CSG_TIN_Node *m_Nodes[3];
210 
211 };
212 
213 
215 // //
216 // //
217 // //
219 
220 //---------------------------------------------------------
222 {
223 public:
224 
225  CSG_TIN(void);
226 
227  CSG_TIN (const CSG_TIN &TIN);
228  bool Create (const CSG_TIN &TIN);
229 
230  CSG_TIN (CSG_Shapes *pShapes);
231  bool Create (CSG_Shapes *pShapes);
232 
233  CSG_TIN (const CSG_String &File);
234  bool Create (const CSG_String &File);
235  CSG_TIN (const char *File);
236  bool Create (const char *File);
237  CSG_TIN (const wchar_t *File);
238  bool Create (const wchar_t *File);
239 
240  virtual ~CSG_TIN(void);
241 
242  virtual bool Destroy (void);
243 
244  virtual TSG_Data_Object_Type Get_ObjectType (void) const { return( SG_DATAOBJECT_TYPE_TIN ); }
245 
246  virtual bool Save (const CSG_String &File, int Format = 0);
247  virtual bool Save (const char *File, int Format = 0) { return( Save(CSG_String(File), Format) ); }
248  virtual bool Save (const wchar_t *File, int Format = 0) { return( Save(CSG_String(File), Format) ); }
249 
250  virtual bool Assign (CSG_Data_Object *pObject);
251 
252  virtual bool is_Valid (void) const { return( Get_Count() >= 3 ); }
253 
254  const CSG_Rect & Get_Extent (void) { Update(); return( m_Extent ); }
255 
256  bool Triangulate (bool bOn = true, bool bUpdate = false);
257 
258  //-----------------------------------------------------
259  CSG_TIN_Node * Add_Node (const TSG_Point &Point, CSG_Table_Record *pRecord = NULL, bool bUpdateNow = false);
260  bool Del_Node (sLong Index, bool bUpdateNow);
261 
262  sLong Get_Node_Count (void) const { return( Get_Count() ); }
263  CSG_TIN_Node * Get_Node (sLong Index) const { return( (CSG_TIN_Node *)Get_Record(Index) ); }
264 
265  sLong Get_Edge_Count (void) const { return( m_nEdges ); }
266  CSG_TIN_Edge * Get_Edge (sLong Index) const { return( Index >= 0 && Index < m_nEdges ? m_Edges[Index] : NULL ); }
267 
268  sLong Get_Triangle_Count (void) const { return( m_nTriangles ); }
269  CSG_TIN_Triangle * Get_Triangle (sLong Index) const { return( Index >= 0 && Index < m_nTriangles ? m_Triangles[Index] : NULL ); }
270  CSG_TIN_Triangle * Add_Triangle (CSG_TIN_Node *p0, CSG_TIN_Node *p1, CSG_TIN_Node *p2);
271  CSG_TIN_Triangle * Add_Triangle (CSG_TIN_Node *p[3]);
272 
273 
274 protected:
275 
276  typedef struct
277  {
278  int p1, p2;
279  }
280  TTIN_Edge;
281 
282  typedef struct
283  {
284  int p1, p2, p3;
285  }
287 
288 
289 protected:
290 
291  bool m_bTriangulate{true};
292 
293  sLong m_nEdges, m_nTriangles;
294 
296 
298 
300 
301 
302  virtual bool On_Update (void);
303  virtual bool On_Reload (void);
304  virtual bool On_Delete (void);
305 
306  void _On_Construction (void);
307 
308  virtual CSG_Table_Record * _Get_New_Record (sLong Index);
309 
310  bool _Destroy_Nodes (void);
311  bool _Destroy_Edges (void);
312  bool _Destroy_Triangles (void);
313 
314  CSG_TIN_Edge * _Add_Edge (CSG_TIN_Node *a, CSG_TIN_Node *b);
315  CSG_TIN_Triangle * _Add_Triangle (CSG_TIN_Node *a, CSG_TIN_Node *b, CSG_TIN_Node *c);
316 
317  bool _Triangulate (void);
318  bool _Triangulate (CSG_TIN_Node **Nodes, int nNodes, TTIN_Triangle *Triangles, int &nTriangles);
319  int _CircumCircle (double xp, double yp, double x1, double y1, double x2, double y2, double x3, double y3, double *xc, double *yc, double *r);
320 
321 };
322 
323 
325 // //
326 // //
327 // //
329 
330 //---------------------------------------------------------
333 
336 
339 
341 SAGA_API_DLL_EXPORT CSG_TIN * SG_Create_TIN (const char *File);
343 SAGA_API_DLL_EXPORT CSG_TIN * SG_Create_TIN (const wchar_t *File);
346 
347 
349 // //
350 // //
351 // //
353 
354 //---------------------------------------------------------
355 #endif // #ifndef HEADER_INCLUDED__SAGA_API__tin_H
CSG_Rect
Definition: geo_tools.h:471
CSG_TIN_Node::Get_ID
int Get_ID(void)
Definition: tin.h:98
CSG_Table::Assign
virtual bool Assign(CSG_Data_Object *pTable)
Definition: table.cpp:377
CSG_TIN_Triangle::Get_CircumCircle_Radius
double Get_CircumCircle_Radius(void)
Definition: tin.h:193
CSG_TIN::Get_Edge
CSG_TIN_Edge * Get_Edge(sLong Index) const
Definition: tin.h:266
CSG_TIN::m_Triangles
CSG_TIN_Triangle ** m_Triangles
Definition: tin.h:299
CSG_TIN::TTIN_Triangle
Definition: tin.h:283
CSG_TIN::Save
virtual bool Save(const char *File, int Format=0)
Definition: tin.h:247
CSG_Data_Object::Update
bool Update(bool bForce=false)
Definition: dataobject.cpp:773
CSG_TIN_Node::Get_X
double Get_X(void)
Definition: tin.h:101
CSG_Table_Record
Definition: table.h:130
SG_Create_TIN
SAGA_API_DLL_EXPORT CSG_TIN * SG_Create_TIN(void)
Definition: tin.cpp:63
CSG_TIN_Triangle::Get_Node
CSG_TIN_Node * Get_Node(int iNode)
Definition: tin.h:178
CSG_Table::Get_Value
virtual bool Get_Value(sLong Index, int iField, CSG_String &Value) const
Definition: table.cpp:1157
CSG_TIN::Get_Node
CSG_TIN_Node * Get_Node(sLong Index) const
Definition: tin.h:263
CSG_Table::Get_Record
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition: table.h:394
CSG_TIN::is_Valid
virtual bool is_Valid(void) const
Definition: tin.h:252
CSG_TIN::Get_Node_Count
sLong Get_Node_Count(void) const
Definition: tin.h:262
CSG_TIN::m_nTriangles
sLong m_nTriangles
Definition: tin.h:293
CSG_TIN::Get_ObjectType
virtual TSG_Data_Object_Type Get_ObjectType(void) const
Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking.
Definition: tin.h:244
CSG_TIN::Get_Triangle_Count
sLong Get_Triangle_Count(void) const
Definition: tin.h:268
CSG_Table::Destroy
virtual bool Destroy(void)
Definition: table.cpp:332
CSG_Table::On_Reload
virtual bool On_Reload(void)
Definition: table_io.cpp:64
CSG_TIN::Save
virtual bool Save(const wchar_t *File, int Format=0)
Definition: tin.h:248
CSG_Table::On_Delete
virtual bool On_Delete(void)
Definition: table_io.cpp:70
SSG_Point
Definition: geo_tools.h:128
CSG_TIN_Triangle::Get_CircumCircle_Point
TSG_Point Get_CircumCircle_Point(void)
Definition: tin.h:194
CSG_TIN_Node::Get_Triangle_Count
int Get_Triangle_Count(void)
Definition: tin.h:108
CSG_TIN
Definition: tin.h:222
CSG_TIN::TTIN_Edge
Definition: tin.h:277
CSG_TIN::Get_Extent
const CSG_Rect & Get_Extent(void)
Definition: tin.h:254
CSG_Data_Object
Definition: dataobject.h:180
CSG_TIN::TTIN_Triangle::p3
int p3
Definition: tin.h:284
sLong
signed long long sLong
Definition: api_core.h:158
CSG_TIN_Node::Get_Y
double Get_Y(void)
Definition: tin.h:102
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:392
CSG_Table::On_Update
virtual bool On_Update(void)
Definition: table.cpp:1288
CSG_TIN_Triangle::Get_CircumCircle
void Get_CircumCircle(TSG_Point &Point, double &Radius)
Definition: tin.h:192
SAGA_API_DLL_EXPORT
#define SAGA_API_DLL_EXPORT
Definition: api_core.h:94
SG_DATAOBJECT_TYPE_TIN
@ SG_DATAOBJECT_TYPE_TIN
Definition: dataobject.h:122
CSG_TIN_Edge::Get_Node
CSG_TIN_Node * Get_Node(int iNode)
Definition: tin.h:151
CSG_Points
Definition: geo_tools.h:184
CSG_Table
Definition: table.h:283
CSG_TIN_Triangle::Get_Extent
const CSG_Rect & Get_Extent(void)
Definition: tin.h:180
CSG_TIN_Triangle
Definition: tin.h:173
TSG_Data_Object_Type
TSG_Data_Object_Type
Definition: dataobject.h:117
shapes.h
CSG_String
Definition: api_core.h:563
CSG_TIN_Node::Get_Neighbor
CSG_TIN_Node * Get_Neighbor(int iNeighbor)
Definition: tin.h:105
CSG_TIN::Get_Edge_Count
sLong Get_Edge_Count(void) const
Definition: tin.h:265
CSG_TIN_Node::Get_Neighbor_Count
int Get_Neighbor_Count(void)
Definition: tin.h:104
CSG_TIN_Node
Definition: tin.h:93
CSG_TIN::m_Extent
CSG_Rect m_Extent
Definition: tin.h:295
CSG_TIN_Edge
Definition: tin.h:146
CSG_Table::Create
bool Create(void)
Definition: table.cpp:139
CSG_TIN::Get_Triangle
CSG_TIN_Triangle * Get_Triangle(sLong Index) const
Definition: tin.h:269
CSG_Shapes
Definition: shapes.h:775
CSG_Table::Save
virtual bool Save(const CSG_String &File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED)
Definition: table_io.cpp:155
CSG_TIN_Triangle::Get_Area
double Get_Area(void)
Definition: tin.h:182
CSG_TIN_Node::Get_Triangle
class CSG_TIN_Triangle * Get_Triangle(int iTriangle)
Definition: tin.h:109
CSG_Table::_Get_New_Record
virtual CSG_Table_Record * _Get_New_Record(sLong Index)
Definition: table.cpp:789
CSG_TIN::TTIN_Edge::p2
int p2
Definition: tin.h:278
CSG_TIN::m_Edges
CSG_TIN_Edge ** m_Edges
Definition: tin.h:297
CSG_Table::_On_Construction
virtual void _On_Construction(void)
Definition: table.cpp:302
CSG_Table::CSG_TIN
friend class CSG_TIN
Definition: table.h:285
CSG_TIN_Node::Get_Point
const TSG_Point & Get_Point(void)
Definition: tin.h:100