source: trunk/SRC/ToBeReviewed/TRIANGULATION/definetri.pro @ 325

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1;+
2;
3; @file_comments
4; Define a triangulation array like <proidl>TRIANGULATE</proidl>.
5;
6; But in a VERY SIMPLE CASE:
7; the points are regularly-gridded on nx*ny array.
8; Find a Delaunay triangulation for this set of points is easy:
9; Points define (nx-1)*(ny-1) rectangles which we can cut in 2 triangles.
10;
11; cf. figure above
12;
13; <fixe>
14;      ny-1*---*---*. . . . . .*---*---*
15;          |  +|  +|           |  +|  +|
16;          | + | + |           | + | + |
17;          |+  |+  |           |+  |+  |
18;      ny-2*---*---*. . . . . .*---*---*
19;          .       .           .       .
20;          .       .           .       .
21;          .       .           .       .
22;         1*---*---*. . . . . .*---*---*
23;          |  +|  +|           |  +|  +|
24;          | + | + |           | + | + |
25;          |+  |+  |           |+  |+  |
26;         0*---*---*. . . . . .*---*---*
27;           0   1   2        nx-3  nx-2 nx-1
28; </fixe>
29;
30;  You have 2 ways to cut a rectangle:
31;      1) the upward diagonal       2) the downward diagonal
32;
33; <fixe>
34;          *---*                        *---*
35;          |  +|                        |+  |
36;          | + |                        | + |
37;          |+  |                        |  +|
38;          *---*                        *---*
39; </fixe>
40;
41; @categories
42; Utilities
43;
44; @param nx {in}{required}
45; The x dimension array
46;
47; @param ny {in}{required}
48; The y dimension array
49;
50; @param downward {in}{optional}
51; When downward is undefined all rectangles are cut in using the upward
52; diagonal.
53; downward is a vector which contains the rectangles numbers which are cut in
54; using the downward diagonal.
55; The rectangle number is defined by the index (in a nx*ny vector) of the
56; lower-left corner of the rectangle.
57;
58; @returns
59; triangles is a 2d array and its dimensions are 3 and 2*(nx-1)*(ny-1).
60; triangles is defined like in the TRIANGULATE procedure.
61;
62; @examples
63;
64; IDL> triangles=definetri(3,3,[1,3])
65;
66; triangles will be this kind of triangulation:
67;
68; <fixe>
69;          *---*---*
70;          |+  |  +|
71;          | + | + |
72;          |  +|+  |
73;          *---*---*
74;          |  +|+  |
75;          | + | + |
76;          |+  |  +|
77;          *---*---*
78;
79; <fixe>
80;
81; @history
82; sebastien Masson (smlod\@ipsl.jussieu.fr)
83;                       4/3/1999
84;
85; @version
86; $Id$
87;-
88FUNCTION definetri, nx, ny, downward
89;
90  compile_opt idl2, strictarrsubs
91;
92   nx = long(nx)
93   ny = long(ny)
94   if n_elements(downward) NE 0 THEN BEGIN
95      if n_elements(downward) GT (nx-1)*(ny-1) then begin
96         print, 'downward a trop d''elements par rapport a nx et ny!'
97         return,  -1
98      endif
99      downward = long(downward)
100   ENDIF
101; we define triangles
102   triangles = lonarr(3, 2*(nx-1)*(ny-1))
103;----------------------------------------------------------------------------------
104; we cut the rectangles with the upward diagonal
105;----------------------------------------------------------------------------------
106   if n_elements(downward) NE (nx-1)*(ny-1) then BEGIN ; there is some rectangle to cut.
107; we define upward: upward is a vector which contains the rectangles
108; numbers which are cut in using the upward diagonal.
109; The rectangle number is defined by the index (in a nx*ny vector) of
110; the lower-left corner of the rectangle.
111      upward = bytarr(nx, ny)+1
112      upward[*, ny-1] = 0
113      upward[nx-1, *] = 0
114      if n_elements(downward) NE 0 then upward[downward] = 0
115      upward = where(upward EQ 1)
116      n1 = n_elements(upward)
117;
118; 4 corners indexes of a rectangle number i are
119;
120;       i+nx  i+nx+1
121;          *---*
122;          |  +|
123;          | + |
124;          |+  |
125;          *---*
126;          i   i+1
127;
128      trinumber = 2*(upward-upward/nx)
129; we define the right triangles
130      triangles[0, trinumber] = upward
131      triangles[1, trinumber] = upward+1
132      triangles[2, trinumber] = upward+1+nx
133; we define the left triangles
134      triangles[0, trinumber+1] = upward+1+nx
135      triangles[1, trinumber+1] = upward+nx
136      triangles[2, trinumber+1] = upward
137   ENDIF ELSE n1 = 0
138;----------------------------------------------------------------------------------
139; we cut the rectangles with the downward diagonal
140;----------------------------------------------------------------------------------
141   if n_elements(downward) NE 0 then BEGIN
142      n2 = n_elements(downward)
143      trinumber = 2*(downward-downward/nx)
144; we define the right triangles
145      triangles[0, trinumber] = downward+1
146      triangles[1, trinumber] = downward+nx+1
147      triangles[2, trinumber] = downward+nx
148; we define the left triangles
149      triangles[0, trinumber+1] = downward+nx
150      triangles[1, trinumber+1] = downward
151      triangles[2, trinumber+1] = downward+1
152   endif
153
154   return, triangles
155end
Note: See TracBrowser for help on using the repository browser.