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

Last change on this file since 192 was 192, checked in by smasson, 18 years ago

several bugfix + new strsed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
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) Lengthes of side of triangles expressed in normalized
9;        coordinates must not surpass a sill length.
10;
11; @categories
12;
13; @param TRIANG
14;
15; @param GLAM
16;
17; @param GPHI
18;
19; @keyword _EXTRA
20; Used to pass your keywords.
21;
22; @uses
23; common.pro
24;
25; @history
26; Sebastien Masson (smasson\@lodyc.jussieu.fr)
27;                       20/2/99
28;
29; @version
30; $Id$
31;
32;-
33;------------------------------------------------------------
34;------------------------------------------------------------
35;------------------------------------------------------------
36FUNCTION ciseauxtri, triang, glam, gphi, _EXTRA = ex
37;---------------------------------------------------------
38;
39  compile_opt idl2, strictarrsubs
40;
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;
51   tempsun = systime(1)         ; For key_performance
52;
53   taille = size(glam)
54   nx = taille[1]
55   ny = taille[2]
56
57   tempdeux = systime(1)        ; For key_performance =2
58   z = convert_coord(glam[*],gphi[*],/data,/to_normal)
59   x = z[0, *]
60   y = z[1, *]
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;
65; Beware, following the projection, some points x or y can become NaN
66; (see points behind the Earth in an orthographic projection).
67; In this case, we have to remove all triangle which contain one of these points.
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
71      tempdeux = systime(1)     ; For key_performance =2
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
80      IF testvar(var = key_performance) EQ 2 THEN $
81       print, 'temps ciseauxtri: recherche points a NAN', systime(1)-tempdeux
82   endif
83;
84   seuil = 5 < (min([nx, ny])-2)
85;
86; Now we delete tringles whose one side has a size superior to 1/sill from the domain reserved for the drawing.
87;
88
89   if keyword_set(key_periodic)  then begin
90      tempdeux = systime(1)     ; For key_performance =2
91;
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)
101;
102      test = temporary(testx)+temporary(testy)
103      ind=where(temporary(test) EQ 0)
104;
105      IF testvar(var = key_performance) EQ 2 THEN $
106       print, 'temps ciseauxtri: trouver les triangles trop grands', systime(1)-tempdeux
107;
108      tempdeux = systime(1)     ; For key_performance =2
109      if ind[0] NE -1 then triang = triang[*, temporary(ind)] ELSE return,  -1
110      trichanged = 1b
111      IF testvar(var = key_performance) EQ 2 THEN $
112       print, 'temps ciseauxtri: virer les triangles trop grands', systime(1)-tempdeux
113   endif
114;
115; We delete all triangle which are out of the valid frame
116;
117    if keyword_set(key_irregular) then begin
118
119       tempdeux = systime(1)     ; For key_performance =2
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)
126;
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;
144;        Last sort.
145;
146   if keyword_set(trichanged) then BEGIN
147;
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.
150;
151; We constitute the list of rectangles we want to keep (we keep every
152; rectangle containing a triangle)
153;
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
157; for the min of the index folowing x and following y of each triangle.
158; Then we go by again this indexion following x and y in an indexion
159; following nx*ny/
160;
161      tempdeux = systime(1)     ; For key_performance =2
162; y indexes of rectangles
163      indytriang = (triang[0, *]/nx) < (triang[2, *]/nx)
164; x indexes of rectangles
165      indxtriang0 = triang[0, *]-nx*(triang[0, *]/nx)
166      indxtriang2 = triang[2, *]-nx*(triang[2, *]/nx)
167      indxmin = indxtriang0 < indxtriang2
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
171; nx-1 and not to column 0.
172      if keyword_set(key_periodic) AND nx EQ jpi then BEGIN
173      indxmax = indxtriang0 > indxtriang2
174      indxtriang = indxmin + (nx-1)*(indxmin EQ 0 AND indxmax EQ (nx-1))
175      ENDIF ELSE indxtriang = indxmin
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;
180; Now we have this list, we will make sure that we do not have triangles
181; with only a common summit.
182;
183      test = bytarr(nx, ny)
184      test[listrect] = 1
185      dejavire = 1b-test
186;
187      tempdeux = systime(1)     ; For key_performance =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)
193         if vire1[0] NE -1 THEN test[vire1] = 0 ; We delete the rectangle
194         vire2 = where( ((1-test)*(1-shift(test, -1, -1)) $
195                         *shift(test, 0, -1)*shift(test, -1, 0)) EQ 1)
196; We delete the top rectangle (same x index but equal to 1)
197         if vire2[0] NE -1 THEN test[vire2+nx] = 0
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 $
204       print, 'temps ciseauxtri: determinationdes rectangles a virer', systime(1)-tempdeux
205;
206      if avirer[0] NE -1 then begin
207      tempdeux = systime(1)     ; For key_performance =2
208      indnx = n_elements(listrect)
209      indny = n_elements(avirer)
210      ind = listrect[*]#replicate(1l, indny)
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;   
220;
221   if keyword_set(key_performance) THEN print, 'temps ciseauxtri', systime(1)-tempsun
222;
223   return,  triang
224end
Note: See TracBrowser for help on using the repository browser.