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