source: trunk/SRC/ToBeReviewed/TRIANGULATION/ciseauxtri.pro @ 246

Last change on this file since 246 was 231, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1;+
2;
3; @file_comments
4; Delete arrays which do not have to be drawn thanks to 2 tests:
5;     1) Corners of the array must be in the window
6;     2) Lengthes of side of triangles expressed in normalized
7;        coordinates must not surpass a sill length.
8;
9; @categories
10;
11; @param TRIANG
12;
13; @param GLAM
14;
15; @param GPHI
16;
17; @keyword _EXTRA
18; Used to pass keywords
19;
20; @uses
21; common.pro
22;
23; @history
24; Sebastien Masson (smasson\@lodyc.jussieu.fr)
25;                       20/2/99
26;
27; @version
28; $Id$
29;
30;-
31;
32FUNCTION ciseauxtri, triang, glam, gphi, _EXTRA = ex
33;---------------------------------------------------------
34;
35  compile_opt idl2, strictarrsubs
36;
37@cm_4mesh
38  IF NOT keyword_set(key_forgetold) THEN BEGIN
39@updatenew
40  ENDIF
41;---------------------------------------------------------
42  IF NOT keyword_set(key_periodic) AND NOT keyword_set(key_irregular) $
43    AND NOT (!map.projection LE 7 AND !map.projection NE 0) $
44    AND NOT (!map.projection EQ 14 OR !map.projection EQ 15 $
45             OR !map.projection EQ 18) THEN return, triang
46;
47   tempsun = systime(1)         ; For key_performance
48;
49   taille = size(glam)
50   nx = taille[1]
51   ny = taille[2]
52
53   tempdeux = systime(1)        ; For key_performance =2
54   z = convert_coord(glam[*],gphi[*],/data,/to_normal)
55   x = z[0, *]
56   y = z[1, *]
57   tempvar = SIZE(TEMPORARY(z)) ; delete z
58   IF testvar(var = key_performance) EQ 2 THEN $
59    print, 'temps ciseauxtri: convert_coord data to_normal', systime(1)-tempdeux
60;
61; Beware, following the projection, some points x or y can become NaN
62; (see points behind the Earth in an orthographic projection).
63; In this case, we have to remove all triangle which contain one of these points.
64;
65   if (!map.projection LE 7 AND !map.projection NE 0) $
66    OR !map.projection EQ 14 OR !map.projection EQ 15 OR !map.projection EQ 18 then begin
67      tempdeux = systime(1)     ; For key_performance =2
68;
69      test = (x*y)[triang]
70      test = finite(temporary(test), /nan)
71      test = total(temporary(test), 1)
72      ind = where(temporary(test) EQ 0)
73;
74      if ind[0] NE -1 then triang = triang[*, temporary(ind)] ELSE return,  -1
75      trichanged = 1b
76      IF testvar(var = key_performance) EQ 2 THEN $
77       print, 'temps ciseauxtri: recherche points a NAN', systime(1)-tempdeux
78   endif
79;
80   seuil = 5 < (min([nx, ny])-2)
81;
82; Now we delete tringles whose one side has a size superior to 1/sill from the domain reserved for the drawing.
83;
84
85   if keyword_set(key_periodic)  then begin
86      tempdeux = systime(1)     ; For key_performance =2
87;
88      xtri = x[triang]
89      xtri = xtri-shift(xtri, 1, 0)
90      testx = abs(temporary(xtri)) GT ((!p.position[2]-!p.position[0])/seuil)
91      testx = total(temporary(testx), 1)
92;
93      ytri = y[triang]
94      ytri = ytri-shift(ytri, 1, 0)
95      testy = abs(temporary(ytri)) GT ((!p.position[3]-!p.position[1])/seuil)
96      testy = total(temporary(testy), 1)
97;
98      test = temporary(testx)+temporary(testy)
99      ind=where(temporary(test) EQ 0)
100;
101      IF testvar(var = key_performance) EQ 2 THEN $
102       print, 'temps ciseauxtri: trouver les triangles trop grands', systime(1)-tempdeux
103;
104      tempdeux = systime(1)     ; For key_performance =2
105      if ind[0] NE -1 then triang = triang[*, temporary(ind)] ELSE return,  -1
106      trichanged = 1b
107      IF testvar(var = key_performance) EQ 2 THEN $
108       print, 'temps ciseauxtri: virer les triangles trop grands', systime(1)-tempdeux
109   endif
110;
111; We delete all triangle which are out of the valid frame
112;
113    if keyword_set(key_irregular) then begin
114
115       tempdeux = systime(1)     ; For key_performance =2
116       xtri = x[triang]
117       test1 = xtri GE !p.position[0]
118       test2 = xtri LE !p.position[2]
119       undefine, xtri
120       testx = temporary(test1)*temporary(test2)
121       testx = total(temporary(testx), 1)
122;
123       ytri = y[triang]
124       test1 = ytri GE !p.position[1]
125       test2 = ytri LE !p.position[3]
126       undefine, ytri
127       testy = temporary(test1)*temporary(test2)
128       testy = total(temporary(testy), 1)
129;
130       test = temporary(testx)*temporary(testy);
131;
132       ind=where(temporary(test) NE 0)
133;
134       if ind[0] NE -1 then triang = triang[*, temporary(ind)] ELSE return,  -1
135       trichanged = 1b
136       IF testvar(var = key_performance) EQ 2 THEN $
137        print, 'temps ciseauxtri: virer les triangles hors du cadre', systime(1)-tempdeux
138    ENDIF
139;
140;        Last sort.
141;
142   if keyword_set(trichanged) then BEGIN
143;
144; We have to check that triangles we keep do not form a triangulation
145; in which 2 triangles have a common summit without have a common side.
146;
147; We constitute the list of rectangles we want to keep (we keep every
148; rectangle containing a triangle)
149;
150; In definetri, we have construct triangles just so the first and the
151; last summit are those of the diagonale of the rectangle defined by
152; the mesh size. To find from which rectangle a triangle comes, we look
153; for the min of the index following x and following y of each triangle.
154; Then we go by again this indexion following x and y in an indexion
155; following nx*ny/
156;
157      tempdeux = systime(1)     ; For key_performance =2
158; y indexes of rectangles
159      indytriang = (triang[0, *]/nx) < (triang[2, *]/nx)
160; x indexes of rectangles
161      indxtriang0 = triang[0, *]-nx*(triang[0, *]/nx)
162      indxtriang2 = triang[2, *]-nx*(triang[2, *]/nx)
163      indxmin = indxtriang0 < indxtriang2
164; Beware in the case where the grid is periodic and where we have all points
165; following x, triangles which assure the periodicity in x have indexes
166; following x which are 0 and nx-1. They belong to rectangles of the column
167; nx-1 and not to column 0.
168      if keyword_set(key_periodic) AND nx EQ jpi then BEGIN
169      indxmax = indxtriang0 > indxtriang2
170      indxtriang = indxmin + (nx-1)*(indxmin EQ 0 AND indxmax EQ (nx-1))
171      ENDIF ELSE indxtriang = indxmin
172      listrect = nx*indytriang+indxtriang
173      IF testvar(var = key_performance) EQ 2 THEN $
174       print, 'temps ciseauxtri: liste des rectangles', systime(1)-tempdeux
175;
176; Now we have this list, we will make sure that we do not have triangles
177; with only a common summit.
178;
179      test = bytarr(nx, ny)
180      test[listrect] = 1
181      dejavire = 1b-test
182;
183      tempdeux = systime(1)     ; For key_performance =2
184      vire1 = 0
185      vire2 = 0
186      while (vire1[0] NE -1 OR vire2[0] NE -1) ne 0 do begin
187         vire1 = where( (test*shift(test, -1, -1) $
188                         *(1-shift(test, 0, -1))*(1-shift(test, -1, 0))) EQ 1)
189         if vire1[0] NE -1 THEN test[vire1] = 0 ; We delete the rectangle
190         vire2 = where( ((1-test)*(1-shift(test, -1, -1)) $
191                         *shift(test, 0, -1)*shift(test, -1, 0)) EQ 1)
192; We delete the top rectangle (same x index but equal to 1)
193         if vire2[0] NE -1 THEN test[vire2+nx] = 0
194      ENDWHILE
195;stop
196      test = test+temporary(dejavire)
197;
198      avirer = where(temporary(test) EQ 0)
199      IF testvar(var = key_performance) EQ 2 THEN $
200       print, 'temps ciseauxtri: determination des rectangles a virer', systime(1)-tempdeux
201;
202      if avirer[0] NE -1 then begin
203      tempdeux = systime(1)     ; For key_performance =2
204      indnx = n_elements(listrect)
205      indny = n_elements(avirer)
206      ind = listrect[*]#replicate(1l, indny)
207      ind = ind EQ replicate(1, indnx)#avirer[*]
208      if indny GT 1 then ind = total(ind, 2)
209      ind = where(ind EQ 0)
210      if ind[0] NE -1 then triang = triang[*, ind] ELSE return,  -1
211      endif
212      IF testvar(var = key_performance) EQ 2 THEN $
213       print, 'temps ciseauxtri: derniere retouche de la triangulation', systime(1)-tempdeux
214   endif
215;
216;
217   if keyword_set(key_performance) THEN print, 'temps ciseauxtri', systime(1)-tempsun
218;
219   return,  triang
220end
Note: See TracBrowser for help on using the repository browser.