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

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

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

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