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

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

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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