All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PtMarker.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file PtMarker.cpp
22 
23  \brief This file contains several utility routines for dealing with point markers.
24  */
25 
26 
27 // TerraLib
28 #include "../color/RGBAColor.h"
29 #include "PtMarker.h"
30 
32 {
33  switch(type)
34  {
36  return CreateMarkerSquare(width, cor);
38  return CreateMarkerDiamond(width, cor);
40  return CreateMarkerCircle(width, cor);
42  return CreateMarkerCrossedCircle(width, cor);
44  return CreateMarkerSemiEllipseLeft(width, cor);
46  return CreateMarkerSemiEllipseRight(width, cor);
48  return CreateMarkerSemiEllipseUp(width, cor);
50  return CreateMarkerSemiEllipseDown(width, cor);
52  return CreateMarkerTriangleLeft(width, cor);
54  return CreateMarkerTriangleRight(width, cor);
56  return CreateMarkerTriangleUp(width, cor);
58  return CreateMarkerTriangleDown(width, cor);
60  return CreateMarkerFourRays(width, cor);
62  return CreateMarkerCross(width, cor);
63  case te::map::MarkerX:
64  return CreateMarkerX(width, cor);
66  return CreateMarkerDash(width, cor);
67  case te::map::MarkerDot:
68  return CreateMarkerDot(width, cor);
70  return CreateMarkerPixel(width, cor);
71  default:
72  return 0;
73  }
74 }
75 
77 {
78  int a, b, d, i, k, m, n, ini, fim, kfim;
79 
80  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
81  for(i = 0; i < width; ++i)
82  {
84  if(p == 0)
85  return 0;
86  marker[i] = p;
87  memset(p, 0, width * sizeof(te::color::RGBAColor));
88  }
89 
90  d = 2;
91  if(width < 7)
92  d = 1;
93 
94  m = width / 2;
95  ini = 0;
96  if(width%2 == 0)
97  ini++;
98  for(i = ini; i < width; ++i)
99  {
100  marker[i][m] = cor;
101  marker[m][i] = cor;
102  }
103 
104  kfim = (int)((double)width * 3. / 8. + .5);
105  k = d;
106  n = 1;
107  while(true)
108  {
109  ini = k;
110  if(width % 2 == 0)
111  ini++;
112  fim = width - k;
113  a = m - n;
114  b = m + n;
115  for(i = ini; i < fim; ++i)
116  {
117  marker[i][a] = cor;
118  marker[i][b] = cor;
119  marker[a][i] = cor;
120  marker[b][i] = cor;
121  }
122  ++n;
123  k += d;
124  if(k > kfim)
125  break;
126  }
127 
128  return marker;
129 }
130 
132 {
133  int i, j, k, ini, fim;
134  double m;
135 
136  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
137  for(i = 0; i < width; ++i)
138  {
140  if(p == 0)
141  return 0;
142  marker[i] = p;
143  memset(p, 0, width * sizeof(te::color::RGBAColor));
144  }
145 
146  m = width / 2;
147  i = 0;
148  k = 0;
149  while(i < (int)m)
150  {
151  ini = (int)m-k;
152  fim = (int)m+k;
153  for(j = ini; j <= fim; ++j)
154  marker[i][j] = cor;
155  ++i;
156  ++k;
157  }
158  int f = i - 2;
159  while(f >= 0 && i < width)
160  {
161  for(j = 0; j < width; ++j)
162  marker[i][j] = marker[f][j];
163  --f;
164  ++i;
165  }
166 
167  return marker;
168 }
169 
171 {
172  int i, j;
173 
174  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
175  for(i = 0; i < width; ++i)
176  {
178  if(p == 0)
179  return 0;
180  marker[i] = p;
181  }
182 
183  for(i = 0; i < width; ++i)
184  {
185  for(j = 0; j < width; ++j)
186  marker[i][j] = cor;
187  }
188 
189  return marker;
190 }
191 
193 {
194  int i, j, m;
195 
196  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
197  for(i = 0; i < width; ++i)
198  {
200  if(p == 0)
201  return 0;
202  marker[i] = p;
203  }
204 
205  double a, b, r;
206  m = width / 2;
207  r = m * m;
208 
209  for(i = 0; i < width; ++i)
210  {
211  for(j = 0; j < width; ++j)
212  {
213  a = i - m;
214  a *= a;
215  b = j - m;
216  b *= b;
217  if(a+b < r)
218  marker[i][j] = cor;
219  }
220  }
221 
222  return marker;
223 }
224 
226 {
227  int i, j, m;
228 
229 
230  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
231  for(i = 0; i < width; ++i)
232  {
234  if(p == 0)
235  return 0;
236  marker[i] = p;
237  }
238 
239  double a, b, r;
240  m = width / 2;
241  double w = (double)width * .7;
242  r = (int)(w/2. * w/2.);
243 
244  for(i = 0; i < width; ++i)
245  {
246  for(j = 0; j < width; ++j)
247  {
248  a = i - m;
249  a *= a;
250  b = j - m;
251  b *= b;
252  if(a+b < r)
253  marker[i][j] = cor;
254  }
255  }
256 
257  for(i = 0; i < width; ++i)
258  marker[i][m] = cor;
259  for(j = 0; j < width; ++j)
260  marker[m][j] = cor;
261 
262  return marker;
263 }
264 
266 {
267  int i, j, mx, my;
268 
269  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
270  for(i = 0; i < width; ++i)
271  {
273  if(p == 0)
274  return 0;
275  marker[i] = p;
276  }
277 
278  double a, b, rx, ry;
279  mx = width/2 - 1;
280  rx = mx * mx;
281  my = width - 1;
282  ry = my * my;
283 
284  for(i = 0; i < width; ++i)
285  {
286  for(j = 0; j < width; ++j)
287  {
288  a = i - mx;
289  a *= a;
290  b = j - my;
291  b *= b;
292  if(a/rx + b/ry < 1)
293  marker[i][j] = cor;
294  }
295  }
296 
297  return marker;
298 }
299 
301 {
302  int i, j, mx, my;
303 
304  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
305  for(i = 0; i < width; ++i)
306  {
308  if(p == 0)
309  return 0;
310  marker[i] = p;
311  }
312 
313  double a, b, rx, ry;
314  mx = width/2 - 1;
315  rx = mx * mx;
316  my = width - 1;
317  ry = my * my;
318 
319  for(i = 0; i < width; ++i)
320  {
321  for(j = 0; j < width; ++j)
322  {
323  a = i - mx;
324  a *= a;
325  b = j;
326  b *= b;
327  if(a/rx + b/ry < 1)
328  marker[i][j] = cor;
329  }
330  }
331 
332  return marker;
333 }
334 
336 {
337  int i, j, mx, my;
338 
339  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
340  for(i = 0; i < width; ++i)
341  {
343  if(p == 0)
344  return 0;
345  marker[i] = p;
346  }
347 
348  double a, b, rx, ry;
349  mx = width - 1;
350  rx = mx * mx;
351  my = width/2 - 1;
352  ry = my * my;
353 
354  for(i = 0; i < width; ++i)
355  {
356  for(j = 0; j < width; ++j)
357  {
358  a = i - mx;
359  a *= a;
360  b = j - my;
361  b *= b;
362  if(a/rx + b/ry < 1)
363  marker[i][j] = cor;
364  }
365  }
366 
367  return marker;
368 }
369 
371 {
372  int i, j, mx, my;
373 
374  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
375  for(i = 0; i < width; ++i)
376  {
378  if(p == 0)
379  return 0;
380  marker[i] = p;
381  }
382 
383  double a, b, rx, ry;
384  mx = width - 1;
385  rx = mx * mx;
386  my = width/2 - 1;
387  ry = my * my;
388 
389  for(i = 0; i < width; ++i)
390  {
391  for(j = 0; j < width; ++j)
392  {
393  a = i;
394  a *= a;
395  b = j - my;
396  b *= b;
397  if(a/rx + b/ry < 1)
398  marker[i][j] = cor;
399  }
400  }
401 
402  return marker;
403 }
404 
406 {
407  int i, j, k, ini, fim;
408 
409  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
410  for(i = 0; i < width; ++i)
411  {
413  if(p == 0)
414  return 0;
415  marker[i] = p;
416  memset(p, 0, width * sizeof(te::color::RGBAColor));
417  }
418 
419  j = width - 1;
420  k = 0;
421  while(j >= 0)
422  {
423  ini = k;
424  fim = width - k;
425  for(i = ini; i < fim; ++i)
426  marker[i][j] = cor;
427  --j;
428  if(j%2)
429  ++k;
430  }
431 
432  return marker;
433 }
434 
436 {
437  int i, j, k, ini, fim;
438 
439  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
440  for(i = 0; i < width; ++i)
441  {
443  if(p == 0)
444  return 0;
445  marker[i] = p;
446  memset(p, 0, width * sizeof(te::color::RGBAColor));
447  }
448 
449  j = 0;
450  k = 0;
451  while(j < width)
452  {
453  ini = k;
454  fim = width - k;
455  for(i = ini; i < fim; ++i)
456  marker[i][j] = cor;
457  ++j;
458  if(j%2)
459  ++k;
460  }
461 
462  return marker;
463 }
464 
466 {
467  int i, j, k, ini, fim;
468 
469  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
470  for(i = 0; i < width; ++i)
471  {
473  if(p == 0)
474  return 0;
475  marker[i] = p;
476  memset(p, 0, width * sizeof(te::color::RGBAColor));
477  }
478 
479  i = width - 1;
480  k = 0;
481  while(i >= 0)
482  {
483  ini = k;
484  fim = width - k;
485  for(j = ini; j < fim; ++j)
486  marker[i][j] = cor;
487  --i;
488  if(i%2)
489  ++k;
490  }
491 
492  return marker;
493 }
494 
496 {
497  int i, j, k, ini, fim;
498 
499  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
500  for(i = 0; i < width; ++i)
501  {
503  if(p == 0)
504  return 0;
505  marker[i] = p;
506  memset(p, 0, width * sizeof(te::color::RGBAColor));
507  }
508 
509  i = 0;
510  k = 0;
511  while(i < width)
512  {
513  ini = k;
514  fim = width - k;
515  for(j = ini; j < fim; ++j)
516  marker[i][j] = cor;
517  ++i;
518  if(i%2)
519  ++k;
520  }
521 
522  return marker;
523 }
524 
526 {
527  int i, m;
528 
529  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
530  for(i = 0; i < width; ++i)
531  {
533  if(p == 0)
534  return 0;
535  marker[i] = p;
536  memset(p, 0, width * sizeof(te::color::RGBAColor));
537  }
538 
539  m = width / 2;
540  for(i = 0; i < width; ++i)
541  {
542  marker[i][m] = cor;
543  marker[m][i] = cor;
544  }
545 
546  return marker;
547 }
548 
550 {
551  int i;
552 
553  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
554  for(i = 0; i < width; ++i)
555  {
557  if(p == 0)
558  return 0;
559  marker[i] = p;
560  memset(p, 0, width * sizeof(te::color::RGBAColor));
561  }
562 
563  for(i = 0; i < width; ++i)
564  {
565  marker[i][i] = cor;
566  marker[i][width-1-i] = cor;
567  }
568 
569  return marker;
570 }
571 
573 {
574  int i, m;
575 
576  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
577  for(i = 0; i < width; ++i)
578  {
580  if(p == 0)
581  return 0;
582  marker[i] = p;
583  memset(p, 0, width * sizeof(te::color::RGBAColor));
584  }
585 
586  m = width / 2;
587  for(i = 0; i < width; ++i)
588  marker[m][i] = cor;
589 
590  return marker;
591 }
592 
594 {
595  return te::map::CreateMarkerCircle(width, cor);
596 }
597 
599 {
600  int i, m;
601 
602  te::color::RGBAColor** marker = new te::color::RGBAColor*[width];
603  for(i = 0; i < width; ++i)
604  {
606  if(p == 0)
607  return 0;
608  marker[i] = p;
609  memset(p, 0, width * sizeof(te::color::RGBAColor));
610  }
611 
612  m = width / 2;
613  marker[m][m] = cor;
614 
615  return marker;
616 }
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerX(int width, const te::color::RGBAColor &color)
It create a x marker.
Definition: PtMarker.cpp:549
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerCrossedCircle(int width, const te::color::RGBAColor &color)
It create a colorssed circle marker.
Definition: PtMarker.cpp:225
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerDash(int width, const te::color::RGBAColor &color)
It create a dash marker.
Definition: PtMarker.cpp:572
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerSemiEllipseUp(int width, const te::color::RGBAColor &color)
It create a semi ellipse left marker.
Definition: PtMarker.cpp:335
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerSemiEllipseLeft(int width, const te::color::RGBAColor &color)
It create a semi ellipse left marker.
Definition: PtMarker.cpp:265
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerFourRays(int width, const te::color::RGBAColor &color)
It creates a four rays marker.
Definition: PtMarker.cpp:76
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerDot(int width, const te::color::RGBAColor &color)
It create a dot marker.
Definition: PtMarker.cpp:593
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerCircle(int width, const te::color::RGBAColor &color)
It create a circle marker.
Definition: PtMarker.cpp:192
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerTriangleUp(int width, const te::color::RGBAColor &color)
It create a semi triangle up marker.
Definition: PtMarker.cpp:465
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerDiamond(int width, const te::color::RGBAColor &color)
It create a diamond marker.
Definition: PtMarker.cpp:131
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerTriangleLeft(int width, const te::color::RGBAColor &color)
It create a semi triangle left marker.
Definition: PtMarker.cpp:405
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerSemiEllipseRight(int width, const te::color::RGBAColor &color)
It create a semi ellipse right marker.
Definition: PtMarker.cpp:300
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerTriangleRight(int width, const te::color::RGBAColor &color)
It create a semi triangle right marker.
Definition: PtMarker.cpp:435
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerPixel(int width, const te::color::RGBAColor &color)
It create a pixel marker.
Definition: PtMarker.cpp:598
TEMAPEXPORT te::color::RGBAColor ** CreateMarker(PtMarkerType type, int width, const te::color::RGBAColor &color)
It creates a point marker.
Definition: PtMarker.cpp:31
PtMarkerType
Definition: Enums.h:95
This file contains several utility routines for dealing with point markers.
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerCross(int width, const te::color::RGBAColor &color)
It create a cross marker.
Definition: PtMarker.cpp:525
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerSquare(int width, const te::color::RGBAColor &color)
It create a square marker.
Definition: PtMarker.cpp:170
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerTriangleDown(int width, const te::color::RGBAColor &color)
It create a semi triangle down marker.
Definition: PtMarker.cpp:495
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
TEMAPEXPORT te::color::RGBAColor ** CreateMarkerSemiEllipseDown(int width, const te::color::RGBAColor &color)
It create a semi ellipse down marker.
Definition: PtMarker.cpp:370