SAGA API  v9.2
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 
257  //-----------------------------------------------------
258  CSG_TIN_Node * Add_Node (TSG_Point Point, CSG_Table_Record *pRecord, bool bUpdateNow);
259  bool Del_Node (sLong Index, bool bUpdateNow);
260 
261  sLong Get_Node_Count (void) const { return( Get_Count() ); }
262  CSG_TIN_Node * Get_Node (sLong Index) const { return( (CSG_TIN_Node *)Get_Record(Index) ); }
263 
264  sLong Get_Edge_Count (void) const { return( m_nEdges ); }
265  CSG_TIN_Edge * Get_Edge (sLong Index) const { return( Index >= 0 && Index < m_nEdges ? m_Edges[Index] : NULL ); }
266 
267  sLong Get_Triangle_Count (void) const { return( m_nTriangles ); }
268  CSG_TIN_Triangle * Get_Triangle (sLong Index) const { return( Index >= 0 && Index < m_nTriangles ? m_Triangles[Index] : NULL ); }
269 
270 
271 protected:
272 
273  typedef struct
274  {
275  int p1, p2;
276  }
277  TTIN_Edge;
278 
279  typedef struct
280  {
281  int p1, p2, p3;
282  }
284 
285 
286 protected:
287 
288  sLong m_nEdges, m_nTriangles;
289 
291 
293 
295 
296 
297  virtual bool On_Update (void);
298  virtual bool On_Reload (void);
299  virtual bool On_Delete (void);
300 
301  void _On_Construction (void);
302 
303  virtual CSG_Table_Record * _Get_New_Record (sLong Index);
304 
305  bool _Destroy_Nodes (void);
306  bool _Destroy_Edges (void);
307  bool _Destroy_Triangles (void);
308 
309  bool _Add_Edge (CSG_TIN_Node *a, CSG_TIN_Node *b);
310  bool _Add_Triangle (CSG_TIN_Node *a, CSG_TIN_Node *b, CSG_TIN_Node *c);
311 
312  bool _Triangulate (void);
313  bool _Triangulate (CSG_TIN_Node **Nodes, int nNodes, TTIN_Triangle *Triangles, int &nTriangles);
314  int _CircumCircle (double xp, double yp, double x1, double y1, double x2, double y2, double x3, double y3, double *xc, double *yc, double *r);
315 
316 };
317 
318 
320 // //
321 // //
322 // //
324 
325 //---------------------------------------------------------
328 
331 
334 
336 SAGA_API_DLL_EXPORT CSG_TIN * SG_Create_TIN (const char *File);
338 SAGA_API_DLL_EXPORT CSG_TIN * SG_Create_TIN (const wchar_t *File);
341 
342 
344 // //
345 // //
346 // //
348 
349 //---------------------------------------------------------
350 #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:372
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:265
CSG_TIN::m_Triangles
CSG_TIN_Triangle ** m_Triangles
Definition: tin.h:294
CSG_TIN::TTIN_Triangle
Definition: tin.h:280
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:714
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:1161
CSG_TIN::Get_Node
CSG_TIN_Node * Get_Node(sLong Index) const
Definition: tin.h:262
CSG_Table::Get_Record
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition: table.h:387
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:261
CSG_TIN::m_nTriangles
sLong m_nTriangles
Definition: tin.h:288
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:267
CSG_Table::Destroy
virtual bool Destroy(void)
Definition: table.cpp:327
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:274
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:281
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:385
CSG_Table::On_Update
virtual bool On_Update(void)
Definition: table.cpp:1292
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
CSG_Table::Create
bool Create(const CSG_Table &Table)
Definition: table.cpp:146
TSG_Data_Object_Type
TSG_Data_Object_Type
Definition: dataobject.h:117
shapes.h
CSG_String
Definition: api_core.h:557
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:264
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:290
CSG_TIN_Edge
Definition: tin.h:146
CSG_TIN::Get_Triangle
CSG_TIN_Triangle * Get_Triangle(sLong Index) const
Definition: tin.h:268
CSG_Shapes
Definition: shapes.h:773
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:793
CSG_TIN::TTIN_Edge::p2
int p2
Definition: tin.h:275
CSG_TIN::m_Edges
CSG_TIN_Edge ** m_Edges
Definition: tin.h:292
CSG_Table::_On_Construction
virtual void _On_Construction(void)
Definition: table.cpp:297
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