SAGA API Version 9.14
Loading...
Searching...
No Matches
map_tin.cpp
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// map_shapes_tin.cpp //
15// //
16// Copyright (C) 2026 by //
17// Olaf Conrad //
18// //
19//-------------------------------------------------------//
20// //
21// This file is part of 'SAGA - System for Automated //
22// Geoscientific Analyses'. SAGA is free software; you //
23// can redistribute it and/or modify it under the terms //
24// of the GNU General Public License as published by the //
25// Free Software Foundation, either version 2 of the //
26// License, or (at your option) any later version. //
27// //
28// SAGA is distributed in the hope that it will be //
29// useful, but WITHOUT ANY WARRANTY; without even the //
30// implied warranty of MERCHANTABILITY or FITNESS FOR A //
31// PARTICULAR PURPOSE. See the GNU General Public //
32// License for more details. //
33// //
34// You should have received a copy of the GNU General //
35// Public License along with this program; if not, see //
36// <http://www.gnu.org/licenses/>. //
37// //
38//-------------------------------------------------------//
39// //
40// e-mail: oconrad@saga-gis.org //
41// //
42// contact: Olaf Conrad //
43// Institute of Geography //
44// University of Hamburg //
45// Germany //
46// //
48
49//---------------------------------------------------------
50#include "map_symbology.h"
51
52#include "map_layer.h"
53
54
56// //
57// //
58// //
60
61//---------------------------------------------------------
69
70
72// //
74
75//---------------------------------------------------------
77{
79
80 //-----------------------------------------------------
81 // Display...
82
83 Parameters.Add_Node("NODE_DISPLAY", "DISPLAY_SHOW" , _TL("Show" ), _TL(""));
84 Parameters.Add_Bool("DISPLAY_SHOW", "DISPLAY_NODES", _TL("Nodes"), _TL(""), false);
85 Parameters.Add_Bool("DISPLAY_SHOW", "DISPLAY_EDGES", _TL("Edges"), _TL(""), true);
86 Parameters.Add_Bool("DISPLAY_SHOW", "DISPLAY_FACES", _TL("Faces"), _TL(""), true);
87
88 //-----------------------------------------------------
89 return( true );
90}
91
92
94// //
96
97//---------------------------------------------------------
98bool CSG_Map_TIN::Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
99{
100 if( Flags & PARAMETER_CHECK_VALUES )
101 {
102 // nop
103 }
104
105 //-----------------------------------------------------
106 if( Flags & PARAMETER_CHECK_ENABLE )
107 {
108 // nop
109 }
110
111 return( CSG_Map_Layer::Parameter_Changed(Parameters, Parameter, Flags) );
112}
113
114
116// //
118
119//---------------------------------------------------------
121{
123
124 //-----------------------------------------------------
125 Set_Fields_Choice(m_Parameters["CLASSIFIED_FIELD" ], false, false, false);
126 Set_Fields_Choice(m_Parameters["CLASSIFIED_NORMALIZE" ], true, true, true);
127 Set_Fields_Choice(m_Parameters["STRETCH_FIELD" ], true, false, false);
128 Set_Fields_Choice(m_Parameters["STRETCH_NORMALIZE"], true, true, true);
129
130 //-----------------------------------------------------
131 return( true );
132}
133
134
136// //
138
139//---------------------------------------------------------
141{
143
144 //-----------------------------------------------------
145 switch( m_Parameters["COLOR_SYMBOLS"].asInt() )
146 {
147 default: // CSG_Map_Symbology::SINGLE
148 m_Stretch.Value = -1;
149 m_Stretch.Normal = -1;
150 break;
151
152 case 1: // CSG_Map_Symbology::CLASSIFIED
153 m_Stretch.Value = Get_Fields_Choice(m_Parameters["CLASSIFIED_FIELD" ]);
154 m_Stretch.Normal = Get_Fields_Choice(m_Parameters["CLASSIFIED_NORMALIZE"]);
155 m_Stretch.Scale = 1.;
156 break;
157
158 case 2: // CSG_Map_Symbology::DISCRETE
159 case 3: // CSG_Map_Symbology::GRADUATED
160 m_Stretch.Value = Get_Fields_Choice(m_Parameters["STRETCH_FIELD" ]);
161 m_Stretch.Normal = Get_Fields_Choice(m_Parameters["STRETCH_NORMALIZE"]);
162 m_Stretch.Scale = m_Parameters["STRETCH_NORMALIZE_FORMAT"].asInt() == 0 ? 1. : 100.;
163 break;
164 }
165
166 if( m_Stretch.Value < 0 )
167 {
169 }
170
171 //-----------------------------------------------------
172 return( true );
173}
174
175
177// //
179
180//---------------------------------------------------------
182{
183 return( false );
184}
185
186
188// //
190
191//---------------------------------------------------------
192void CSG_Map_TIN::On_Draw(CSG_Map_DC &dc_Map, int Flags)
193{
194 if( m_pObject && Get_Extent().Intersects(dc_Map.rWorld()) != INTERSECTION_None )
195 {
196 if( m_Parameters("DISPLAY_FACES")->asBool() ) { _Draw_Triangles(dc_Map); }
197 if( m_Parameters("DISPLAY_EDGES")->asBool() ) { _Draw_Edges (dc_Map); }
198 if( m_Parameters("DISPLAY_NODES")->asBool() ) { _Draw_Points (dc_Map); }
199 }
200}
201
202
204// //
206
207//---------------------------------------------------------
208void CSG_Map_TIN::_Draw_Points(CSG_Map_DC &dc_Map)
209{
210 for(int i=0; i<m_pObject->asTIN()->Get_Node_Count(); i++)
211 {
212 TSG_Point_Int Point = dc_Map.World2DC(m_pObject->asTIN()->Get_Node(i)->Get_Point());
213
214 dc_Map.DrawCircle(Point.x, Point.y, 5);
215 }
216}
217
218//---------------------------------------------------------
219void CSG_Map_TIN::_Draw_Edges(CSG_Map_DC &dc_Map)
220{
221 for(int i=0; i<m_pObject->asTIN()->Get_Edge_Count(); i++)
222 {
223 TSG_Point_Int Point[2]; CSG_TIN_Edge *pEdge = m_pObject->asTIN()->Get_Edge(i);
224
225 Point[0] = dc_Map.World2DC(pEdge->Get_Node(0)->Get_Point());
226 Point[1] = dc_Map.World2DC(pEdge->Get_Node(1)->Get_Point());
227
228 dc_Map.DrawLine(Point[0].x, Point[0].y, Point[1].x, Point[1].y);
229 }
230}
231
232//---------------------------------------------------------
233void CSG_Map_TIN::_Draw_Triangles(CSG_Map_DC &dc_Map)
234{
235 if( dc_Map.Draw_Image_Begin(m_Parameters("TRANSPARENCY")->asDouble() / 100.) )
236 {
237 for(sLong iTriangle=0; iTriangle<m_pObject->asTIN()->Get_Triangle_Count(); iTriangle++)
238 {
239 CSG_TIN_Triangle *pTriangle = m_pObject->asTIN()->Get_Triangle(iTriangle);
240
241 if( dc_Map.rWorld().Intersects(pTriangle->Get_Extent()) != INTERSECTION_None )
242 {
243 TPoint p[3];
244
245 if( m_Stretch.Value < 0 )
246 {
247 for(int iNode=0; iNode<3; iNode++)
248 {
249 CSG_TIN_Node *pNode = pTriangle->Get_Node(iNode);
250
251 TSG_Point_Int Point = dc_Map.World2DC(pNode->Get_Point());
252
253 p[iNode].x = Point.x; p[iNode].y = Point.y; p[iNode].z = 0.;
254 }
255
256 _Draw_Triangle(dc_Map, p);
257 }
258 else
259 {
260 bool bOkay = true;
261
262 for(int iNode=0; bOkay && iNode<3; iNode++)
263 {
264 CSG_TIN_Node *pNode = pTriangle->Get_Node(iNode); double Value;
265
266 if( (bOkay = CSG_Map_Layer::Get_Field_Value(pNode->Get_Index(), m_Stretch.Value, m_Stretch.Normal, m_Stretch.Scale, Value)) == true )
267 {
268 TSG_Point_Int Point = dc_Map.World2DC(pNode->Get_Point());
269
270 p[iNode].x = Point.x; p[iNode].y = Point.y; p[iNode].z = Value;
271 }
272 }
273
274 if( bOkay )
275 {
276 _Draw_Triangle(dc_Map, p);
277 }
278 }
279 }
280 }
281
282 dc_Map.Draw_Image_End();
283 }
284}
285
286
288// //
290
291//---------------------------------------------------------
292#define SORT_POINTS_Y(a, b) if( p[a].y < p[b].y ) { TPoint pp = p[a]; p[a] = p[b]; p[b] = pp; }
293#define SORT_POINTS_X(a, b) if( p[a].x < p[b].x ) { TPoint pp = p[a]; p[a] = p[b]; p[b] = pp; }
294
295#define DRAW_PIXEL(x, y, z) { int c; if( m_pSymbology->Get_Class_Color_byValue(z, c) ) { dc_Map.Draw_Image_Pixel(x, y, c); } }
296
297//---------------------------------------------------------
298void CSG_Map_TIN::_Draw_Triangle(CSG_Map_DC &dc_Map, TPoint p[3])
299{
300 SORT_POINTS_Y(1, 0); SORT_POINTS_Y(2, 0); SORT_POINTS_Y(2, 1);
301
302 if( p[2].y == p[0].y )
303 {
304 if( p[0].y >= 0 && p[0].y < dc_Map.rDC().GetHeight() )
305 {
306 SORT_POINTS_X(1, 0); SORT_POINTS_X(2, 0); SORT_POINTS_X(2, 1);
307
308 if( p[2].x == p[0].x )
309 {
310 if( p[0].x >= 0 && p[0].x < dc_Map.rDC().GetWidth() )
311 {
312 DRAW_PIXEL(p[0].x, p[0].y, p[0].z > p[1].z
313 ? (p[0].z > p[2].z ? p[0].z : p[2].z)
314 : (p[1].z > p[2].z ? p[1].z : p[2].z)
315 );
316 }
317 }
318 else
319 {
320 _Draw_Triangle_Line(dc_Map, p[0].x, p[1].x, p[0].y, p[0].z, p[1].z);
321 _Draw_Triangle_Line(dc_Map, p[1].x, p[2].x, p[0].y, p[1].z, p[2].z);
322 }
323 }
324 }
325
326 //-----------------------------------------------------
327 else if( !((p[0].y < 0 && p[2].y < 0) || (p[0].y >= dc_Map.rDC().GetHeight() && p[2].y >= dc_Map.rDC().GetHeight())) )
328 {
329 double dy = p[2].y - p[0].y;
330 double dx_a = (p[2].x - p[0].x) / dy;
331 double dz_a = (p[2].z - p[0].z) / dy;
332 double x_a = p[0].x;
333 double z_a = p[0].z;
334
335 for(int i=0, j=1; i<2; i++, j++)
336 {
337 if( (dy = p[j].y - p[i].y) > 0. )
338 {
339 double dx = (p[j].x - p[i].x) / dy;
340 double dz = (p[j].z - p[i].z) / dy;
341 double x = p[i].x;
342 double z = p[i].z;
343 int y = p[i].y;
344
345 if( y < 0 )
346 {
347 x -= y * dx;
348 z -= y * dz;
349 y = 0;
350 x_a = p[0].x - p[0].y * dx_a;
351 z_a = p[0].z - p[0].y * dz_a;
352 }
353
354 int yn = p[j].y; if( yn > dc_Map.rDC().GetHeight() ) { yn = dc_Map.rDC().GetHeight(); }
355
356 for( ; y<yn; y++, x+=dx, z+=dz, x_a+=dx_a, z_a+=dz_a)
357 {
358 if( x < x_a )
359 {
360 _Draw_Triangle_Line(dc_Map, (int)x, (int)x_a, y, z, z_a);
361 }
362 else
363 {
364 _Draw_Triangle_Line(dc_Map, (int)x_a, (int)x, y, z_a, z);
365 }
366 }
367 }
368 }
369 }
370}
371
372//---------------------------------------------------------
373inline void CSG_Map_TIN::_Draw_Triangle_Line(CSG_Map_DC &dc_Map, int xa, int xb, int y, double za, double zb)
374{
375 double dz = xb - xa;
376
377 if( dz > 0. )
378 {
379 dz = (zb - za) / dz;
380
381 if( xa < 0 )
382 {
383 za -= dz * xa;
384 xa = 0;
385 }
386
387 if( xb >= dc_Map.rDC().GetWidth() )
388 {
389 xb = dc_Map.rDC().GetWidth() - 1;
390 }
391
392 for(int x=xa; x<=xb; x++, za+=dz)
393 {
394 DRAW_PIXEL(x, y, za);
395 }
396 }
397 else if( xa >= 0 && xa < dc_Map.rDC().GetWidth() )
398 {
399 DRAW_PIXEL(xa, y, za);
400 }
401}
402
403
405// //
406// //
407// //
409
410//---------------------------------------------------------
signed long long sLong
Definition api_core.h:158
#define _TL(s)
Definition api_core.h:1619
class CSG_TIN * asTIN(bool bPolymorph=false) const
bool Draw_Image_Begin(double Transparency, Mode Mode=Mode::Transparent)
Definition map_dc.cpp:374
void DrawCircle(int x, int y, int radius)
Definition map_dc.cpp:556
const CSG_Rect & rWorld(void) const
Definition map_dc.h:124
void DrawLine(int x1, int y1, int x2, int y2)
Definition map_dc.cpp:524
const wxRect & rDC(void) const
Definition map_dc.h:129
bool Draw_Image_End(void)
Definition map_dc.cpp:418
const double & World2DC(void) const
Definition map_dc.h:131
virtual bool Parameters_Changed(void)
bool Set_Fields_Choice(CSG_Parameter &Choice, bool bNumeric, bool bAddNone, bool bSelectNone=false)
bool Get_Field_Value(sLong Index, int Field, int Normalize, double Scale, wxString &Value) const
static int Get_Fields_Choice(CSG_Parameter &Choice)
virtual bool DataObject_Changed(void)
virtual bool Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
CSG_Data_Object * m_pObject
Definition map_layer.h:151
bool Set_Object(CSG_Data_Object *pObject)
CSG_Rect Get_Extent(void) const
CSG_Parameters m_Parameters
Definition map_layer.h:149
class CSG_Map_Symbology * m_pSymbology
Definition map_layer.h:153
virtual bool Add_Parameters(CSG_Parameters &Parameters)
CSG_Map_Layer(void)
Definition map_layer.h:90
virtual bool Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
Definition map_tin.cpp:98
virtual bool DataObject_Changed(void)
Definition map_tin.cpp:120
virtual bool Add_Parameters(CSG_Parameters &Parameters)
Definition map_tin.cpp:76
virtual bool asImage(CSG_Grid *pImage)
Definition map_tin.cpp:181
CSG_Map_TIN(CSG_TIN *pTIN=NULL)
Definition map_tin.cpp:62
virtual bool Parameters_Changed(void)
Definition map_tin.cpp:140
class CSG_Map_TIN::CStretch m_Stretch
virtual void On_Draw(CSG_Map_DC &dc_Map, int Flags)
Definition map_tin.cpp:192
CSG_Parameter * Add_Node(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, bool bCollapsed=false)
CSG_Parameter * Add_Bool(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, bool Value=false)
TSG_Intersection Intersects(const CSG_Rect &Rect) const
CSG_TIN_Node * Get_Node(int iNode)
Definition tin.h:151
const TSG_Point & Get_Point(void)
Definition tin.h:100
CSG_TIN_Node * Get_Node(int iNode)
Definition tin.h:178
const CSG_Rect & Get_Extent(void)
Definition tin.h:180
Definition tin.h:222
CSG_TIN_Node * Get_Node(sLong Index) const
Definition tin.h:263
sLong Get_Index(void) const
Definition table.h:136
@ SG_DATAOBJECT_TYPE_TIN
Definition dataobject.h:122
struct SSG_Point_Int TSG_Point_Int
@ INTERSECTION_None
Definition geo_tools.h:102
#define asDouble(i)
#define SORT_POINTS_Y(a, b)
Definition map_tin.cpp:292
#define DRAW_PIXEL(x, y, z)
Definition map_tin.cpp:295
#define SORT_POINTS_X(a, b)
Definition map_tin.cpp:293
#define PARAMETER_CHECK_ENABLE
Definition parameters.h:191
#define PARAMETER_CHECK_VALUES
Definition parameters.h:190