element.cpp 67.2 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
#include "inmost.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
2
#include <iomanip>
Kirill Terekhov's avatar
Kirill Terekhov committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#if defined(USE_MESH)
namespace INMOST
{

	const char * Element::GeometricTypeName(GeometricType t)
	{
		switch(t)
		{
			case Unset:        return "Unset";
			case Vertex:       return "Vertex";
			case Line:         return "Line";
			case MultiLine:    return "MultiLine";
			case Tri:          return "Tri";
			case Quad:         return "Quad";
			case Polygon:      return "Polygon";
			case MultiPolygon: return "MultiPolygon";
			case Tet:          return "Tet";
			case Hex:          return "Hex";
			case Prism:        return "Prism";
			case Pyramid:      return "Pyramid";
			case Polyhedron:   return "Polyhedron";
			case Set:          return "Set";
		};
		return "Unset";
	}
	
	
Kirill Terekhov's avatar
Kirill Terekhov committed
30
	Storage::integer Element::GetGeometricDimension(GeometricType m_type)
Kirill Terekhov's avatar
Kirill Terekhov committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	{
		switch(m_type)
		{
			case Vertex:		return 0;
			case Line:			return 1;
			case MultiLine:
			case Tri:
			case Quad: 			
			case Polygon:		return 2;
			case MultiPolygon:
			case Tet:
			case Hex:
			case Prism:
			case Pyramid:
			case Polyhedron:	return 3;
			default: return UINT_MAX;
		}
		return UINT_MAX;
	}
	
	const char * Element::StatusName(Status s)
	{
		switch(s)
		{
			case Owned:  return "Owned";
			case Shared: return "Shared";
			case Ghost:  return "Ghost";
		}
		return "Unknown";
	}
	
	
	
	
	
Kirill Terekhov's avatar
Kirill Terekhov committed
66
	Storage::enumerator Element::nbAdjElements(ElementType _etype)const 
Kirill Terekhov's avatar
Kirill Terekhov committed
67
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
68
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->nbAdjElements(_etype);
Kirill Terekhov's avatar
Kirill Terekhov committed
69
70
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
71
		Mesh * mesh = GetMeshLink();
72
		std::vector<HandleType> result;
73
		INMOST_DATA_INTEGER_TYPE conn[4] = {0,0,0,0};
74
		INMOST_DATA_INTEGER_TYPE myconn = -1, i = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
75
		enumerator ret = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
76
		
77
		for(ElementType e = NODE; e <= CELL; e = NextElementType(e))
Kirill Terekhov's avatar
Kirill Terekhov committed
78
79
80
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
81
			i++;
Kirill Terekhov's avatar
Kirill Terekhov committed
82
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
83
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
84
85
86
87
88
89
90
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					ret += 1;
				}
91
				else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
92
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
93
					ret += static_cast<enumerator>(mesh->HighConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
94
				}
95
				else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
96
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
97
					ret += static_cast<enumerator>(mesh->LowConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
98
				}
99
				else if( i == myconn + 2 )
Kirill Terekhov's avatar
Kirill Terekhov committed
100
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
101
					MarkerType mrk = mesh->CreatePrivateMarker();
102
103
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
104
					{
105
106
107
108
109
110
111
112
113
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
							if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
							{
								result.push_back(ihc[jt]);
								mesh->SetPrivateMarker(ihc[jt],mrk);
							}
					}
					ret += static_cast<enumerator>(result.size());
114
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0],(enumerator)result.size(),mrk);
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
					result.clear();
					mesh->ReleasePrivateMarker(mrk);
				}					
				else if( i == myconn - 2 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++)
					{
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
							if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
							{
								result.push_back(ilc[jt]);
								mesh->SetPrivateMarker(ilc[jt],mrk);
							}
					}		
					ret += static_cast<enumerator>(result.size());
133
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
134
135
136
137
138
139
140
141
142
143
144
					result.clear();
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn + 3 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++)
					{
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
145
						{
146
147
148
							adj_type const & jhc = mesh->HighConn(ihc[jt]);
							for(adj_type::size_type kt = 0; kt < jhc.size(); kt++)
								if( !mesh->GetPrivateMarker(jhc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
149
								{
150
151
									result.push_back(jhc[kt]);
									mesh->SetPrivateMarker(jhc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
152
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
153
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
154
					}
155
					ret += static_cast<enumerator>(result.size());
156
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
157
158
159
160
161
162
163
164
					result.clear();
					mesh->ReleasePrivateMarker(mrk);
				}					
				else if( i == myconn - 3 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
165
					{
166
167
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
168
						{
169
170
171
							adj_type const & jlc = mesh->LowConn(ilc[jt]);
							for(adj_type::size_type kt = 0; kt < jlc.size(); kt++)
								if( !mesh->GetPrivateMarker(jlc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
172
								{
173
174
									result.push_back(jlc[kt]);
									mesh->SetPrivateMarker(jlc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
175
								}
176
177
178
						}
					}		
					ret += static_cast<enumerator>(result.size());
179
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
180
					result.clear();
Kirill Terekhov's avatar
Kirill Terekhov committed
181
					mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
182
183
184
185
186
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
187
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
188
189
190
191
192
193
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					if( !GetMarker(hm) ) ret ++;
				}
194
				else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
195
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
196
197
198
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( !mesh->GetMarker(hc[it],hm) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
199
				}
200
				else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
201
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
202
203
204
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( !mesh->GetMarker(lc[it],hm) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
205
				}
206
				else if( i == myconn + 2 )
Kirill Terekhov's avatar
Kirill Terekhov committed
207
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
208
					MarkerType mrk = mesh->CreatePrivateMarker();
209
210
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
211
					{
212
213
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
214
						{
215
216
217
218
219
220
221
222
							if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
							{
								result.push_back(ihc[jt]);
								mesh->SetPrivateMarker(ihc[jt],mrk);
							}
						}
					}
					ret += static_cast<enumerator>(result.size());
223
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
224
225
226
227
228
229
230
231
232
233
234
235
					result.clear();
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn - 2 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
					{
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
							if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
236
							{
237
238
239
240
241
								result.push_back(ilc[jt]);
								mesh->SetPrivateMarker(ilc[jt],mrk);
							}
					}
					ret += static_cast<enumerator>(result.size());
242
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
					result.clear();
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn + 3 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
					{
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
						{
							adj_type const & jhc = mesh->HighConn(ihc[jt]);
							for(adj_type::size_type kt = 0; kt < jhc.size(); kt++) if( !mesh->GetMarker(jhc[kt],hm) )
								if( !mesh->GetPrivateMarker(jhc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
258
								{
259
260
									result.push_back(jhc[kt]);
									mesh->SetPrivateMarker(jhc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
261
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
262
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
263
					}
264
					ret += static_cast<enumerator>(result.size());
265
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
266
267
268
269
270
271
272
273
					result.clear();
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn - 3 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
274
					{
275
276
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
277
						{
278
279
280
							adj_type const & jlc = mesh->LowConn(ilc[jt]);
							for(adj_type::size_type kt = 0; kt < jlc.size(); kt++) if( !mesh->GetMarker(jlc[kt],hm) )
								if( !mesh->GetPrivateMarker(jlc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
281
								{
282
283
									result.push_back(jlc[kt]);
									mesh->SetPrivateMarker(jlc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
284
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
285
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
286
					}
287
					ret += static_cast<enumerator>(result.size());
288
					if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
289
					result.clear();
Kirill Terekhov's avatar
Kirill Terekhov committed
290
					mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
291
292
293
294
295
				}
			}
		}
		return ret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
296
297


Kirill Terekhov's avatar
Kirill Terekhov committed
298
	Storage::enumerator Element::nbAdjElements(ElementType _etype, MarkerType mask, bool invert)const 
Kirill Terekhov's avatar
Kirill Terekhov committed
299
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
300
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->nbAdjElements(_etype,mask,invert);
Kirill Terekhov's avatar
Kirill Terekhov committed
301
302
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
303
		Mesh * mesh = GetMeshLink();
304
		std::vector<HandleType> result;
305
		INMOST_DATA_INTEGER_TYPE conn[4] = {0,0,0,0};
306
		INMOST_DATA_INTEGER_TYPE myconn = -1, i = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
307
		enumerator ret = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
308
		
309
		for(ElementType e = NODE; e <= CELL; e = NextElementType(e))
Kirill Terekhov's avatar
Kirill Terekhov committed
310
311
312
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
313
			i++;
Kirill Terekhov's avatar
Kirill Terekhov committed
314
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
315
		if( isPrivate(mask) )
Kirill Terekhov's avatar
Kirill Terekhov committed
316
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
317
			if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
318
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
319
				for(i = 0; i < 4; i++) if( conn[i] )
Kirill Terekhov's avatar
Kirill Terekhov committed
320
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
321
322
323
324
					if( i == myconn )
					{
						if( invert ^ GetPrivateMarker(mask) ) ret += 1;
					}
325
					else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
326
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
327
						adj_type const & hc = mesh->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
328
329
330
						for(adj_type::size_type it = 0; it < hc.size(); ++it) 
							if( invert ^ mesh->GetPrivateMarker(hc[it],mask) ) ret++;
					}
331
					else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
332
333
334
335
336
					{
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); ++it) 
							if( invert ^ mesh->GetPrivateMarker(lc[it],mask) ) ret++;
					}
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
					else if( i == myconn + 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
								if( (invert ^ mesh->GetPrivateMarker(ihc[jt],mask)) && !mesh->GetPrivateMarker(ihc[jt],mrk) )
								{
									result.push_back(ihc[jt]);
									mesh->SetPrivateMarker(ihc[jt],mrk);
								}
						}
						ret += static_cast<enumerator>(result.size());
352
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
								if( (invert ^ mesh->GetPrivateMarker(ilc[jt],mask)) && !mesh->GetPrivateMarker(ilc[jt],mrk) )
								{
									result.push_back(ilc[jt]);
									mesh->SetPrivateMarker(ilc[jt],mrk);
								}
						}
						ret += static_cast<enumerator>(result.size());
371
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
372
373
374
375
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn + 3 )
Kirill Terekhov's avatar
Kirill Terekhov committed
376
377
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
378
379
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
380
						{
381
382
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
383
							{
384
385
386
387
								adj_type const & jhc = mesh->HighConn(ihc[jt]);
								for(adj_type::size_type kt = 0; kt < jhc.size(); kt++)
								{
									if( (invert ^ mesh->GetPrivateMarker(jhc[kt],mask)) && !mesh->GetPrivateMarker(jhc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
388
									{
389
390
										result.push_back(jhc[kt]);
										mesh->SetPrivateMarker(jhc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
391
									}
392
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
393
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
394
						}
395
						ret += static_cast<enumerator>(result.size());
396
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
397
398
399
400
401
402
403
404
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 3 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
405
						{
406
407
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
408
							{
409
410
411
412
								adj_type const & jlc = mesh->LowConn(ilc[jt]);
								for(adj_type::size_type kt = 0; kt < jlc.size(); kt++)
								{
									if( (invert ^ mesh->GetPrivateMarker(jlc[kt],mask)) && !mesh->GetPrivateMarker(jlc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
413
									{
414
415
										result.push_back(jlc[kt]);
										mesh->SetPrivateMarker(jlc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
416
									}
417
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
418
419
							}
						}
420
						ret += static_cast<enumerator>(result.size());
421
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
422
423
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
424
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
425
426
427
428
429
430
431
432
433
434
435
				}
			}
			else
			{
				MarkerType hm = mesh->HideMarker();
				for(i = 0; i < 4; i++) if( conn[i] )
				{
					if( i == myconn )
					{
						if( !GetMarker(hm) && (invert ^ GetPrivateMarker(mask)) ) ret ++;
					}
436
					else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
437
438
439
440
441
					{
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); ++it)
							if( !mesh->GetMarker(hc[it],hm) && (invert ^ mesh->GetPrivateMarker(hc[it],mask)) ) ret++;
					}
442
					else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
443
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
444
						adj_type const & lc = mesh->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
445
446
447
						for(adj_type::size_type it = 0; it < lc.size(); ++it)
							if( !mesh->GetMarker(lc[it],hm) && (invert ^ mesh->GetPrivateMarker(lc[it],mask)) ) ret++;
					}
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
					else if( i == myconn + 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
								if( (invert ^ mesh->GetPrivateMarker(ihc[jt],mask)) && !mesh->GetPrivateMarker(ihc[jt],mrk) )
								{
									result.push_back(ihc[jt]);
									mesh->SetPrivateMarker(ihc[jt],mrk);
								}
						}
						ret += static_cast<enumerator>(result.size());
463
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
								if( (invert ^ mesh->GetPrivateMarker(ilc[jt],mask)) && !mesh->GetPrivateMarker(ilc[jt],mrk) )
								{
									result.push_back(ilc[jt]);
									mesh->SetPrivateMarker(ilc[jt],mrk);
								}
						}		
						ret += static_cast<enumerator>(result.size());
482
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
483
484
485
486
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn + 3 )
Kirill Terekhov's avatar
Kirill Terekhov committed
487
488
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
489
490
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
491
						{
492
493
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
494
							{
495
496
497
498
								adj_type const & jhc = mesh->HighConn(ihc[jt]);
								for(adj_type::size_type kt = 0; kt < jhc.size(); kt++) if( !mesh->GetMarker(jhc[kt],hm) )
								{
									if( (invert ^ mesh->GetPrivateMarker(jhc[kt],mask)) && !mesh->GetPrivateMarker(jhc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
499
									{
500
501
										result.push_back(jhc[kt]);
										mesh->SetPrivateMarker(jhc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
502
									}
503
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
504
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
505
						}
506
						ret += static_cast<enumerator>(result.size());
507
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
508
509
510
511
512
513
514
515
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 3 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
516
						{
517
518
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
519
							{
520
521
522
523
								adj_type const & jlc = mesh->LowConn(ilc[jt]);
								for(adj_type::size_type kt = 0; kt < jlc.size(); kt++) if( !mesh->GetMarker(jlc[kt],hm) )
								{
									if( (invert ^ mesh->GetPrivateMarker(jlc[kt],mask)) && !mesh->GetPrivateMarker(jlc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
524
									{
525
526
										result.push_back(jlc[kt]);
										mesh->SetPrivateMarker(jlc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
527
									}
528
529
530
531
								}
							}
						}		
						ret += static_cast<enumerator>(result.size());
532
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
533
534
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
535
536
537
538
539
540
					}
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
541
			if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
542
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
543
				for(i = 0; i < 4; i++) if( conn[i] )
Kirill Terekhov's avatar
Kirill Terekhov committed
544
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
545
546
547
548
					if( i == myconn )
					{
						if( invert ^ GetMarker(mask) ) ret += 1;
					}
549
					else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
550
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
551
						adj_type const & hc = mesh->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
552
553
554
						for(adj_type::size_type it = 0; it < hc.size(); ++it) 
							if( invert ^ mesh->GetMarker(hc[it],mask) ) ret++;
					}
555
					else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
556
557
558
559
560
					{
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); ++it) 
							if( invert ^ mesh->GetMarker(lc[it],mask) ) ret++;
					}
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
					else if( i == myconn + 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
								if( (invert ^ mesh->GetMarker(ihc[jt],mask)) && !mesh->GetPrivateMarker(ihc[jt],mrk) )
								{
									result.push_back(ihc[jt]);
									mesh->SetPrivateMarker(ihc[jt],mrk);
								}
						}
						ret += static_cast<enumerator>(result.size());
576
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
								if( (invert ^ mesh->GetMarker(ilc[jt],mask)) && !mesh->GetPrivateMarker(ilc[jt],mrk) )
								{
									result.push_back(ilc[jt]);
									mesh->SetPrivateMarker(ilc[jt],mrk);
								}
						}
						ret += static_cast<enumerator>(result.size());
595
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
596
597
598
599
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn + 3 )
Kirill Terekhov's avatar
Kirill Terekhov committed
600
601
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
602
603
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
604
						{
605
606
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
607
							{
608
609
610
611
								adj_type const & jhc = mesh->HighConn(ihc[jt]);
								for(adj_type::size_type kt = 0; kt < jhc.size(); kt++)
								{
									if( (invert ^ mesh->GetMarker(jhc[kt],mask)) && !mesh->GetPrivateMarker(jhc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
612
									{
613
614
										result.push_back(jhc[kt]);
										mesh->SetPrivateMarker(jhc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
615
									}
616
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
617
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
618
						}
619
						ret += static_cast<enumerator>(result.size());
620
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
621
622
623
624
625
626
627
628
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 3 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
629
						{
630
631
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
632
							{
633
634
635
636
								adj_type const & jlc = mesh->LowConn(ilc[jt]);
								for(adj_type::size_type kt = 0; kt < jlc.size(); kt++)
								{
									if( (invert ^ mesh->GetMarker(jlc[kt],mask)) && !mesh->GetPrivateMarker(jlc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
637
									{
638
639
										result.push_back(jlc[kt]);
										mesh->SetPrivateMarker(jlc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
640
									}
641
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
642
643
							}
						}
644
						ret += static_cast<enumerator>(result.size());
645
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
646
647
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
648
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
649
650
651
652
653
654
655
656
657
658
659
				}
			}
			else
			{
				MarkerType hm = mesh->HideMarker();
				for(i = 0; i < 4; i++) if( conn[i] )
				{
					if( i == myconn )
					{
						if( !GetMarker(hm) && (invert ^ GetMarker(mask)) ) ret ++;
					}
660
					else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
661
662
663
664
665
					{
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); ++it)
							if( !mesh->GetMarker(hc[it],hm) && (invert ^ mesh->GetMarker(hc[it],mask)) ) ret++;
					}
666
					else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
667
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
668
						adj_type const & lc = mesh->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
669
670
671
						for(adj_type::size_type it = 0; it < lc.size(); ++it)
							if( !mesh->GetMarker(lc[it],hm) && (invert ^ mesh->GetMarker(lc[it],mask)) ) ret++;
					}
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
					else if( i == myconn + 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
								if( (invert ^ mesh->GetMarker(ihc[jt],mask)) && !mesh->GetPrivateMarker(ihc[jt],mrk) )
								{
									result.push_back(ihc[jt]);
									mesh->SetPrivateMarker(ihc[jt],mrk);
								}
						}
						ret += static_cast<enumerator>(result.size());
687
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 2 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
								if( (invert ^ mesh->GetMarker(ilc[jt],mask)) && !mesh->GetPrivateMarker(ilc[jt],mrk) )
								{
									result.push_back(ilc[jt]);
									mesh->SetPrivateMarker(ilc[jt],mrk);
								}
						}		
						ret += static_cast<enumerator>(result.size());
706
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
707
708
709
710
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn + 3 )
Kirill Terekhov's avatar
Kirill Terekhov committed
711
712
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
713
714
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
715
						{
716
717
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
718
							{
719
720
721
722
								adj_type const & jhc = mesh->HighConn(ihc[jt]);
								for(adj_type::size_type kt = 0; kt < jhc.size(); kt++) if( !mesh->GetMarker(jhc[kt],hm) )
								{
									if( (invert ^ mesh->GetMarker(jhc[kt],mask)) && !mesh->GetPrivateMarker(jhc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
723
									{
724
725
										result.push_back(jhc[kt]);
										mesh->SetPrivateMarker(jhc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
726
									}
727
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
728
729
							}
						}
730
						ret += static_cast<enumerator>(result.size());
731
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
732
733
734
735
736
737
738
739
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
					}
					else if( i == myconn - 3 )
					{
						MarkerType mrk = mesh->CreatePrivateMarker();
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
740
						{
741
742
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
743
							{
744
745
746
747
								adj_type const & jlc = mesh->LowConn(ilc[jt]);
								for(adj_type::size_type kt = 0; kt < jlc.size(); kt++) if( !mesh->GetMarker(jlc[kt],hm) )
								{
									if( (invert ^ mesh->GetMarker(jlc[kt],mask)) && !mesh->GetPrivateMarker(jlc[kt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
748
									{
749
750
										result.push_back(jlc[kt]);
										mesh->SetPrivateMarker(jlc[kt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
751
									}
752
753
754
755
								}
							}
						}		
						ret += static_cast<enumerator>(result.size());
756
						if( !result.empty() ) mesh->RemPrivateMarkerArray(&result[0], (enumerator)result.size(),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
757
758
						result.clear();
						mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
759
760
761
762
763
764
					}
				}
			}
		}
		return ret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
765
	
Kirill Terekhov's avatar
Kirill Terekhov committed
766
	ElementArray<Element> Element::getAdjElements(ElementType _etype) const 
Kirill Terekhov's avatar
Kirill Terekhov committed
767
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
768
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->getAdjElements(_etype);
Kirill Terekhov's avatar
Kirill Terekhov committed
769
770
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
771
772
		INMOST::Mesh * mesh = GetMeshLink();
		ElementArray<Element> result(mesh);
773
774
		INMOST_DATA_INTEGER_TYPE conn[4] = {0,0,0,0};
		INMOST_DATA_INTEGER_TYPE myconn = -1, i = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
775
		
776
		for(ElementType e = NODE; e <= CELL; e = NextElementType(e))
Kirill Terekhov's avatar
Kirill Terekhov committed
777
778
779
780
781
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
			i++;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
782
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
783
784
785
786
787
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
788
					result.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
789
				}
790
				else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
791
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
792
793
					adj_type const & hc = mesh->HighConn(GetHandle());
					result.insert(result.end(),hc.begin(),hc.end());
Kirill Terekhov's avatar
Kirill Terekhov committed
794
				}
795
				else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
796
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
797
798
					adj_type const & lc = mesh->LowConn(GetHandle());
					result.insert(result.end(),lc.begin(),lc.end());
Kirill Terekhov's avatar
Kirill Terekhov committed
799
				}
800
				else if( i == myconn + 2 )
Kirill Terekhov's avatar
Kirill Terekhov committed
801
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
802
					MarkerType mrk = mesh->CreatePrivateMarker();
803
804
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
805
					{
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
							if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
							{
								result.push_back(ihc[jt]);
								mesh->SetPrivateMarker(ihc[jt],mrk);
							}
					}
					result.RemPrivateMarker(mrk);
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn - 2 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++)
					{
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
							if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
							{
								result.push_back(ilc[jt]);
								mesh->SetPrivateMarker(ilc[jt],mrk);
							}
					}
					result.RemPrivateMarker(mrk);
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn + 3 )
				{
836
					//~ std::vector<HandleType> tmp;
837
838
839
840
841
842
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++)
					{
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
843
844
845
846
847
848
849
850
851
852
853
854
							//~ if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
							{
								//~ mesh->SetPrivateMarker(ihc[jt],mrk);
								//~ tmp.push_back(ihc[jt]);
								adj_type const & jhc = mesh->HighConn(ihc[jt]);
								for(adj_type::size_type kt = 0; kt < jhc.size(); kt++)
									if( !mesh->GetPrivateMarker(jhc[kt],mrk) )
									{
										result.push_back(jhc[kt]);
										mesh->SetPrivateMarker(jhc[kt],mrk);
									}
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
855
					}
856
					//~ if(!tmp.empty()) mesh->RemPrivateMarkerArray(&tmp[0],tmp.size(),mrk);
857
858
859
860
861
					result.RemPrivateMarker(mrk);
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn - 3 )
				{
862
					//~ std::vector<HandleType> tmp;
863
864
865
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
866
					{
867
868
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
869
870
871
872
873
874
875
876
877
878
879
880
							//~ if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
							{
								//~ mesh->SetPrivateMarker(ilc[jt],mrk);
								//~ tmp.push_back(ilc[jt]);
								adj_type const & jlc = mesh->LowConn(ilc[jt]);
								for(adj_type::size_type kt = 0; kt < jlc.size(); kt++)
									if( !mesh->GetPrivateMarker(jlc[kt],mrk) )
									{
										result.push_back(jlc[kt]);
										mesh->SetPrivateMarker(jlc[kt],mrk);
									}
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
881
					}
882
					//~ if(!tmp.empty()) mesh->RemPrivateMarkerArray(&tmp[0],tmp.size(),mrk);
883
					result.RemPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
884
					mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
885
886
887
888
889
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
890
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
891
892
893
894
895
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					if( !GetMarker(hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
896
						result.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
897
				}
898
				else if( i == myconn + 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
899
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
900
901
902
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( !mesh->GetMarker(hc[it],hm) ) result.push_back(hc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
903
904
					
				}
905
				else if( i == myconn - 1 )
Kirill Terekhov's avatar
Kirill Terekhov committed
906
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
907
908
909
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( !mesh->GetMarker(lc[it],hm) ) result.push_back(lc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
910
				}
911
				else if( i == myconn + 2 )
Kirill Terekhov's avatar
Kirill Terekhov committed
912
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
913
					MarkerType mrk = mesh->CreatePrivateMarker();
914
915
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
916
					{
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
							if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
							{
								result.push_back(ihc[jt]);
								mesh->SetPrivateMarker(ihc[jt],mrk);
							}
					}
					result.RemPrivateMarker(mrk);
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn - 2 )
				{
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
					{
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt != ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
							if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
							{
								result.push_back(ilc[jt]);
								mesh->SetPrivateMarker(ilc[jt],mrk);
							}
					}
					result.RemPrivateMarker(mrk);
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn + 3 )
				{
947
					//~ std::vector<HandleType> tmp;
948
949
950
951
952
953
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
					{
						adj_type const & ihc = mesh->HighConn(hc[it]);
						for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
954
						{
955
							//~ if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
956
							{
957
958
959
960
								//~ mesh->SetPrivateMarker(ihc[jt],mrk);
								//~ tmp.push_back(ihc[jt]);
								adj_type const & jhc = mesh->HighConn(ihc[jt]);
								for(adj_type::size_type kt = 0; kt < jhc.size(); kt++) if( !mesh->GetMarker(jhc[kt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
961
								{
962
963
964
965
966
									if( !mesh->GetPrivateMarker(jhc[kt],mrk) )
									{
										result.push_back(jhc[kt]);
										mesh->SetPrivateMarker(jhc[kt],mrk);
									}
Kirill Terekhov's avatar
Kirill Terekhov committed
967
								}
968
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
969
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
970
					}
971
					//~ if(!tmp.empty()) mesh->RemPrivateMarkerArray(&tmp[0],tmp.size(),mrk);
972
973
974
975
976
					result.RemPrivateMarker(mrk);
					mesh->ReleasePrivateMarker(mrk);
				}
				else if( i == myconn - 3 )
				{
977
					//~ std::vector<HandleType> tmp;
978
979
980
					MarkerType mrk = mesh->CreatePrivateMarker();
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
981
					{
982
983
						adj_type const & ilc = mesh->LowConn(lc[it]);
						for(adj_type::size_type jt = 0; jt != ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
984
						{
985
							//~ if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
986
							{
987
988
989
990
								//~ mesh->SetPrivateMarker(ilc[jt],mrk);
								//~ tmp.push_back(ilc[jt]);
								adj_type const & jlc = mesh->LowConn(ilc[jt]);
								for(adj_type::size_type kt = 0; kt < jlc.size(); kt++) if( !mesh->GetMarker(jlc[kt],hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
991
								{
992
993
994
995
996
									if( !mesh->GetPrivateMarker(jlc[kt],mrk) )
									{
										result.push_back(jlc[kt]);
										mesh->SetPrivateMarker(jlc[kt],mrk);
									}
Kirill Terekhov's avatar
Kirill Terekhov committed
997
								}
998
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
999
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
1000
					}
1001
					//~ if(!tmp.empty()) mesh->RemPrivateMarkerArray(&tmp[0],tmp.size(),mrk);
1002
					result.RemPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1003
					mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1004
1005
1006
1007
1008
1009
				}
			}
		}
		return result;
	}
	
Kirill Terekhov's avatar
Kirill Terekhov committed
1010
	ElementArray<Element> Element::getAdjElements(ElementType _etype, MarkerType mask, bool invert) const 
Kirill Terekhov's avatar
Kirill Terekhov committed
1011
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1012
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->getAdjElements(_etype,mask,invert);
Kirill Terekhov's avatar
Kirill Terekhov committed
1013
1014
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
1015
1016
		INMOST::Mesh * mesh = GetMeshLink();
		ElementArray<Element> result(mesh);
1017
1018
		INMOST_DATA_INTEGER_TYPE conn[4] = {0,0,0,0};
		INMOST_DATA_INTEGER_TYPE myconn = -1, i = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
1019
		
1020
		for(ElementType e = NODE; e <= CELL; e = NextElementType(e))
Kirill Terekhov's avatar
Kirill Terekhov committed
1021
1022
1023
1024
1025
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
			i++;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1026
		if( isPrivate(mask) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1027
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
1028
			if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
1029
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
1030
				for(i = 0; i < 4; i++) if( conn[i] )