[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
[150] | 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. |
---|
[2] | 10 | ; |
---|
[150] | 11 | ; @categories |
---|
[2] | 12 | ; |
---|
[150] | 13 | ; @param TRIANG |
---|
| 14 | ; |
---|
| 15 | ; @param GLAM |
---|
[2] | 16 | ; |
---|
[150] | 17 | ; @param GPHI |
---|
[2] | 18 | ; |
---|
[150] | 19 | ; @keyword ALL |
---|
| 20 | ; |
---|
| 21 | ; @keyword _EXTRA |
---|
| 22 | ; Used to pass your keywords. |
---|
[2] | 23 | ; |
---|
[150] | 24 | ; @uses |
---|
| 25 | ; common.pro |
---|
[2] | 26 | ; |
---|
[150] | 27 | ; @history |
---|
[157] | 28 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[150] | 29 | ; 20/2/99 |
---|
[2] | 30 | ; |
---|
[150] | 31 | ; @version |
---|
| 32 | ; $Id$ |
---|
| 33 | ; |
---|
[2] | 34 | ;- |
---|
| 35 | ;------------------------------------------------------------ |
---|
| 36 | ;------------------------------------------------------------ |
---|
| 37 | ;------------------------------------------------------------ |
---|
[150] | 38 | FUNCTION ciseauxtri, triang, glam, gphi, ALL = all, _EXTRA = ex |
---|
[29] | 39 | ;--------------------------------------------------------- |
---|
[114] | 40 | ; |
---|
| 41 | compile_opt idl2, strictarrsubs |
---|
| 42 | ; |
---|
[29] | 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 | ; |
---|
[150] | 53 | tempsun = systime(1) ; For key_performance |
---|
[29] | 54 | ; |
---|
[2] | 55 | taille = size(glam) |
---|
| 56 | nx = taille[1] |
---|
| 57 | ny = taille[2] |
---|
| 58 | |
---|
[150] | 59 | tempdeux = systime(1) ; For key_performance =2 |
---|
[29] | 60 | z = convert_coord(glam[*],gphi[*],/data,/to_normal) |
---|
| 61 | x = z[0, *] |
---|
| 62 | y = z[1, *] |
---|
[2] | 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 | ; |
---|
[150] | 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. |
---|
[2] | 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 |
---|
[150] | 73 | tempdeux = systime(1) ; For key_performance =2 |
---|
[29] | 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 |
---|
[2] | 82 | IF testvar(var = key_performance) EQ 2 THEN $ |
---|
| 83 | print, 'temps ciseauxtri: recherche points a NAN', systime(1)-tempdeux |
---|
| 84 | endif |
---|
| 85 | ; |
---|
[29] | 86 | seuil = 5 < (min([nx, ny])-2) |
---|
[2] | 87 | ; |
---|
[150] | 88 | ; Now we delete tringles whose one side has a size superior to 1/sill from the domain reserved for the drawing. |
---|
[2] | 89 | ; |
---|
| 90 | |
---|
[29] | 91 | if keyword_set(key_periodic) then begin |
---|
[150] | 92 | tempdeux = systime(1) ; For key_performance =2 |
---|
[2] | 93 | ; |
---|
[29] | 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 | ; |
---|
[2] | 107 | IF testvar(var = key_performance) EQ 2 THEN $ |
---|
| 108 | print, 'temps ciseauxtri: trouver les triangles trop grands', systime(1)-tempdeux |
---|
| 109 | ; |
---|
[150] | 110 | tempdeux = systime(1) ; For key_performance =2 |
---|
[29] | 111 | if ind[0] NE -1 then triang = triang[*, temporary(ind)] ELSE return, -1 |
---|
| 112 | trichanged = 1b |
---|
[2] | 113 | IF testvar(var = key_performance) EQ 2 THEN $ |
---|
| 114 | print, 'temps ciseauxtri: virer les triangles trop grands', systime(1)-tempdeux |
---|
| 115 | endif |
---|
| 116 | ; |
---|
[150] | 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 |
---|
[2] | 119 | ; |
---|
[29] | 120 | if keyword_set(key_irregular) then begin |
---|
[2] | 121 | |
---|
[150] | 122 | tempdeux = systime(1) ; For key_performance =2 |
---|
[29] | 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) |
---|
[2] | 129 | ; |
---|
[29] | 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 | ; |
---|
[150] | 147 | ; Last sort. |
---|
[2] | 148 | ; |
---|
[29] | 149 | if keyword_set(trichanged) then BEGIN |
---|
[2] | 150 | ; |
---|
[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. |
---|
[2] | 153 | ; |
---|
[150] | 154 | ; We constitute the list of rectangles we want to keep (we keep every |
---|
| 155 | ; rectangle containing a triangle) |
---|
[2] | 156 | ; |
---|
[150] | 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/ |
---|
[2] | 163 | ; |
---|
[150] | 164 | tempdeux = systime(1) ; For key_performance =2 |
---|
| 165 | ; y indexes of rectangles |
---|
[2] | 166 | indytriang = (triang[0, *]/nx) < (triang[2, *]/nx) |
---|
[150] | 167 | ; x indexes of rectangles |
---|
[2] | 168 | indxtriang0 = triang[0, *]-nx*(triang[0, *]/nx) |
---|
| 169 | indxtriang2 = triang[2, *]-nx*(triang[2, *]/nx) |
---|
| 170 | indxmin = indxtriang0 < indxtriang2 |
---|
[150] | 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. |
---|
[29] | 175 | if keyword_set(key_periodic) AND nx EQ jpi then BEGIN |
---|
[2] | 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 | ; |
---|
[150] | 183 | ; Now we have this list, we will make sure that we do not have triangles |
---|
| 184 | ; with only a common summit. |
---|
[2] | 185 | ; |
---|
| 186 | test = bytarr(nx, ny) |
---|
| 187 | test[listrect] = 1 |
---|
| 188 | dejavire = 1b-test |
---|
| 189 | ; |
---|
[150] | 190 | tempdeux = systime(1) ; For key_performance =2 |
---|
[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) |
---|
[150] | 196 | if vire1[0] NE -1 THEN test[vire1] = 0 ; We delete the rectangle |
---|
[2] | 197 | vire2 = where( ((1-test)*(1-shift(test, -1, -1)) $ |
---|
| 198 | *shift(test, 0, -1)*shift(test, -1, 0)) EQ 1) |
---|
[150] | 199 | ; We delete the top rectangle (same x index but equal to 1) |
---|
[2] | 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 |
---|
[150] | 210 | tempdeux = systime(1) ; For key_performance =2 |
---|
[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 |
---|
[29] | 225 | ; |
---|
[2] | 226 | return, triang |
---|
| 227 | end |
---|