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

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

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