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