Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__voronoi__.cc @ 10154:40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Jan 2010 17:33:41 -0500 |
parents | 2c279308f6ab |
children | 89f4d7e294cc |
comparison
equal
deleted
inserted
replaced
10153:2c28f9d0360f | 10154:40dfc0c99116 |
---|---|
76 const char *options; | 76 const char *options; |
77 | 77 |
78 if (nargin == 2) | 78 if (nargin == 2) |
79 { | 79 { |
80 if (! args (1).is_string ()) | 80 if (! args (1).is_string ()) |
81 { | 81 { |
82 error ("__voronoi__: second argument must be a string"); | 82 error ("__voronoi__: second argument must be a string"); |
83 return retval; | 83 return retval; |
84 } | 84 } |
85 | 85 |
86 options = args (1).string_value().c_str (); | 86 options = args (1).string_value().c_str (); |
87 } | 87 } |
88 else | 88 else |
89 options = ""; | 89 options = ""; |
98 | 98 |
99 //double pt_array[dim * np]; | 99 //double pt_array[dim * np]; |
100 //for (int i = 0; i < np; i++) | 100 //for (int i = 0; i < np; i++) |
101 // { | 101 // { |
102 // for (int j = 0; j < dim; j++) | 102 // for (int j = 0; j < dim; j++) |
103 // { | 103 // { |
104 // pt_array[j+i*dim] = p(i,j); | 104 // pt_array[j+i*dim] = p(i,j); |
105 // } | 105 // } |
106 // } | 106 // } |
107 | 107 |
108 boolT ismalloc = false; | 108 boolT ismalloc = false; |
109 | 109 |
110 OCTAVE_LOCAL_BUFFER (char, flags, 250); | 110 OCTAVE_LOCAL_BUFFER (char, flags, 250); |
125 | 125 |
126 octave_idx_type i = 0, n = 1, k = 0, m = 0, fidx = 0, j = 0, r = 0; | 126 octave_idx_type i = 0, n = 1, k = 0, m = 0, fidx = 0, j = 0, r = 0; |
127 OCTAVE_LOCAL_BUFFER (octave_idx_type, ni, np); | 127 OCTAVE_LOCAL_BUFFER (octave_idx_type, ni, np); |
128 | 128 |
129 for (i = 0; i < np; i++) | 129 for (i = 0; i < np; i++) |
130 ni[i] = 0; | 130 ni[i] = 0; |
131 qh_setvoronoi_all (); | 131 qh_setvoronoi_all (); |
132 bool infinity_seen = false; | 132 bool infinity_seen = false; |
133 facetT *neighbor, **neighborp; | 133 facetT *neighbor, **neighborp; |
134 coordT *voronoi_vertex; | 134 coordT *voronoi_vertex; |
135 | 135 |
136 FORALLfacets | 136 FORALLfacets |
137 { | 137 { |
138 facet->seen = false; | 138 facet->seen = false; |
139 } | 139 } |
140 | 140 |
141 FORALLvertices | 141 FORALLvertices |
142 { | 142 { |
143 if (qh hull_dim == 3) | 143 if (qh hull_dim == 3) |
144 qh_order_vertexneighbors (vertex); | 144 qh_order_vertexneighbors (vertex); |
145 infinity_seen = false; | 145 infinity_seen = false; |
146 | 146 |
147 FOREACHneighbor_ (vertex) | 147 FOREACHneighbor_ (vertex) |
148 { | 148 { |
149 if (! neighbor->upperdelaunay) | 149 if (! neighbor->upperdelaunay) |
150 { | 150 { |
151 if (! neighbor->seen) | 151 if (! neighbor->seen) |
152 { | 152 { |
153 n++; | 153 n++; |
154 neighbor->seen = true; | 154 neighbor->seen = true; |
155 } | 155 } |
156 ni[k]++; | 156 ni[k]++; |
157 } | 157 } |
158 else if (! infinity_seen) | 158 else if (! infinity_seen) |
159 { | 159 { |
160 infinity_seen = true; | 160 infinity_seen = true; |
161 ni[k]++; | 161 ni[k]++; |
162 } | 162 } |
163 } | 163 } |
164 k++; | 164 k++; |
165 } | 165 } |
166 | 166 |
167 Matrix v (n, dim); | 167 Matrix v (n, dim); |
168 for (octave_idx_type d = 0; d < dim; d++) | 168 for (octave_idx_type d = 0; d < dim; d++) |
169 v(0,d) = octave_Inf; | 169 v(0,d) = octave_Inf; |
170 | 170 |
171 boolMatrix AtInf (np, 1); | 171 boolMatrix AtInf (np, 1); |
172 for (i = 0; i < np; i++) | 172 for (i = 0; i < np; i++) |
173 AtInf(i) = false; | 173 AtInf(i) = false; |
174 octave_value_list F (np, octave_value ()); | 174 octave_value_list F (np, octave_value ()); |
175 k = 0; | 175 k = 0; |
176 i = 0; | 176 i = 0; |
177 | 177 |
178 FORALLfacets | 178 FORALLfacets |
179 { | 179 { |
180 facet->seen = false; | 180 facet->seen = false; |
181 } | 181 } |
182 | 182 |
183 FORALLvertices | 183 FORALLvertices |
184 { | 184 { |
185 if (qh hull_dim == 3) | 185 if (qh hull_dim == 3) |
186 qh_order_vertexneighbors(vertex); | 186 qh_order_vertexneighbors(vertex); |
187 infinity_seen = false; | 187 infinity_seen = false; |
188 RowVector facet_list (ni[k++]); | 188 RowVector facet_list (ni[k++]); |
189 m = 0; | 189 m = 0; |
190 | 190 |
191 FOREACHneighbor_(vertex) | 191 FOREACHneighbor_(vertex) |
192 { | 192 { |
193 if (neighbor->upperdelaunay) | 193 if (neighbor->upperdelaunay) |
194 { | 194 { |
195 if (! infinity_seen) | 195 if (! infinity_seen) |
196 { | 196 { |
197 infinity_seen = true; | 197 infinity_seen = true; |
198 facet_list(m++) = 1; | 198 facet_list(m++) = 1; |
199 AtInf(j) = true; | 199 AtInf(j) = true; |
200 } | 200 } |
201 } | 201 } |
202 else | 202 else |
203 { | 203 { |
204 if (! neighbor->seen) | 204 if (! neighbor->seen) |
205 { | 205 { |
206 voronoi_vertex = neighbor->center; | 206 voronoi_vertex = neighbor->center; |
207 fidx = neighbor->id; | 207 fidx = neighbor->id; |
208 i++; | 208 i++; |
209 for (octave_idx_type d = 0; d < dim; d++) | 209 for (octave_idx_type d = 0; d < dim; d++) |
210 { | 210 { |
211 v(i,d) = *(voronoi_vertex++); | 211 v(i,d) = *(voronoi_vertex++); |
212 } | 212 } |
213 neighbor->seen = true; | 213 neighbor->seen = true; |
214 neighbor->visitid = i; | 214 neighbor->visitid = i; |
215 } | 215 } |
216 facet_list(m++) = neighbor->visitid + 1; | 216 facet_list(m++) = neighbor->visitid + 1; |
217 } | 217 } |
218 } | 218 } |
219 F(r++) = facet_list; | 219 F(r++) = facet_list; |
220 j++; | 220 j++; |
221 } | 221 } |
222 | 222 |
223 Cell C(r, 1); | 223 Cell C(r, 1); |
224 for (i = 0; i < r; i++) | 224 for (i = 0; i < r; i++) |
225 C.elem (i) = F(i); | 225 C.elem (i) = F(i); |
226 | 226 |
227 retval(0) = v; | 227 retval(0) = v; |
228 retval(1) = C; | 228 retval(1) = C; |
229 AtInf.resize (r, 1); | 229 AtInf.resize (r, 1); |
230 retval(2) = AtInf; | 230 retval(2) = AtInf; |
235 // free short memory and memory allocator | 235 // free short memory and memory allocator |
236 int curlong, totlong; | 236 int curlong, totlong; |
237 qh_memfreeshort (&curlong, &totlong); | 237 qh_memfreeshort (&curlong, &totlong); |
238 | 238 |
239 if (curlong || totlong) | 239 if (curlong || totlong) |
240 warning ("__voronoi__: did not free %d bytes of long memory (%d pieces)", totlong, curlong); | 240 warning ("__voronoi__: did not free %d bytes of long memory (%d pieces)", totlong, curlong); |
241 } | 241 } |
242 else | 242 else |
243 error ("__voronoi__: qhull failed"); | 243 error ("__voronoi__: qhull failed"); |
244 | 244 |
245 #else | 245 #else |