element.cpp 43.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 72 73 74 75
		Mesh * mesh = GetMeshLink();
		dynarray<HandleType,128> result;
		integer conn[4] = {0,0,0,0};
		integer myconn, i;
		enumerator ret = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
76 77 78 79 80 81
		
		for(ElementType e = NODE, i = 0; e <= CELL; i++, e = e << 1)
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
82
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
83 84 85 86 87 88 89 90 91
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					ret += 1;
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
92
					ret += static_cast<enumerator>(mesh->HighConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
93 94 95
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
96
					ret += static_cast<enumerator>(mesh->LowConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
97 98 99
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
100
					MarkerType mrk = mesh->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
101 102
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
103 104 105 106 107
						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
108
								if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
109
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
110
									result.push_back(ihc[jt]);
Kirill Terekhov's avatar
Kirill Terekhov committed
111
									mesh->SetPrivateMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
112
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
113 114
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
115 116 117
					}
					else if( GetElementType() & FACE )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
118
						ret += static_cast<enumerator>(mesh->LowConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
119 120 121
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
122 123 124 125 126
						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++)
Kirill Terekhov's avatar
Kirill Terekhov committed
127
								if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
128
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
129
									result.push_back(ilc[jt]);
Kirill Terekhov's avatar
Kirill Terekhov committed
130
									mesh->SetPrivateMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
131
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
132 133
						}		
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
134
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
135
					for(dynarray<HandleType,128>::size_type it = 0; it < result.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
136
						mesh->RemPrivateMarker(result[it],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
137
					result.clear();
Kirill Terekhov's avatar
Kirill Terekhov committed
138
					mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
139 140 141 142 143
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
144
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
145 146 147 148 149 150 151 152
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					if( !GetMarker(hm) ) ret ++;
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
153 154 155
					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
156 157 158
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
159 160 161
					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
162 163 164
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
165
					MarkerType mrk = mesh->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
166 167
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
168 169 170 171 172 173
						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
174
								if( !mesh->GetPrivateMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
175
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
176
									result.push_back(ihc[jt]);
Kirill Terekhov's avatar
Kirill Terekhov committed
177
									mesh->SetPrivateMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
178
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
179 180 181
							}
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
182 183 184
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
185 186 187 188 189
						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) )
Kirill Terekhov's avatar
Kirill Terekhov committed
190
								if( !mesh->GetPrivateMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
191
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
192
									result.push_back(ilc[jt]);
Kirill Terekhov's avatar
Kirill Terekhov committed
193
									mesh->SetPrivateMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
194
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
195 196
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
197
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
198
					for(dynarray<HandleType,128>::size_type it = 0; it < result.size(); it++)
Kirill Terekhov's avatar
Kirill Terekhov committed
199
						mesh->RemPrivateMarker(result[it],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
200
					result.clear();
Kirill Terekhov's avatar
Kirill Terekhov committed
201
					mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
202 203 204 205 206
				}
			}
		}
		return ret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
207 208


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

Kirill Terekhov's avatar
Kirill Terekhov committed
1026
	void Element::PrintElementConnectivity() const
Kirill Terekhov's avatar
Kirill Terekhov committed
1027
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1028 1029 1030 1031 1032 1033 1034
		Mesh * mesh = GetMeshLink();
		HandleType me = GetHandle();
		std::cout << "Element " << ElementTypeName(GetElementType()) << " " << LocalID() << std::endl;

		adj_type const & hc = mesh->HighConn(GetHandle());
		std::cout << "Upper adjacencies (" << hc.size() << "):" << std::endl;
		for(adj_type::size_type jt = 0; jt < hc.size(); jt++) //iterate over upper adjacent
Kirill Terekhov's avatar
Kirill Terekhov committed
1035
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
1036 1037 1038 1039 1040
			std::cout << "[" << std::setw(3) << jt << "] " << ElementTypeName(GetHandleElementType(hc[jt])) << " " << GetHandleID(hc[jt]) << " lower ";
			bool found = false;
			adj_type const & ilc = mesh->LowConn(hc[jt]);
			std::cout << "(" << ilc.size() << "): ";
			for(adj_type::size_type kt = 0; kt < ilc.size(); kt++) //search for the link to me
Kirill Terekhov's avatar
Kirill Terekhov committed
1041
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
1042 1043
				std::cout << ElementTypeName(GetHandleElementType(ilc[kt])) << " " << GetHandleID(ilc[kt]) << " ";
				if( ilc[kt] == me ) found = true;
Kirill Terekhov's avatar
Kirill Terekhov committed
1044
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
1045 1046
			if( !found ) std::cout << " no me here! ";
			std::cout << std::endl;
Kirill Terekhov's avatar
Kirill Terekhov committed
1047
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1048 1049 1050
		adj_type const & lc = mesh->LowConn(GetHandle());
		std::cout << "Lower adjacencies (" << lc.size() << "):" << std::endl;
		for(adj_type::size_type jt = 0; jt < lc.size(); jt++) //iterate over lower adjacent
Kirill Terekhov's avatar
Kirill Terekhov committed
1051
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
1052 1053 1054 1055 1056
			std::cout << "[" <<  std::setw(3) <<  jt << "] " << ElementTypeName(GetHandleElementType(lc[jt])) << " " << GetHandleID(lc[jt]) << " higher ";
			bool found = false;
			adj_type const & ihc = mesh->HighConn(lc[jt]);
			std::cout << "(" << ihc.size() << "): ";
			for(adj_type::size_type kt = 0; kt < ihc.size(); kt++) //search for the link to me
Kirill Terekhov's avatar
Kirill Terekhov committed
1057
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
1058 1059
				std::cout << ElementTypeName(GetHandleElementType(ihc[kt])) << " " << GetHandleID(ihc[kt]) << " ";
				if( ihc[kt] == me ) found = true;
Kirill Terekhov's avatar
Kirill Terekhov committed
1060
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
1061 1062
			if( !found ) std::cout << " no me here! ";
			std::cout << std::endl;
Kirill Terekhov's avatar
Kirill Terekhov committed
1063 1064 1065 1066 1067
		}
	}
	
	bool Element::CheckConnectivity(Mesh * m)
	{
1068
		bool check = true;
Kirill Terekhov's avatar
Kirill Terekhov committed
1069
		for(Mesh::iteratorElement it = m->BeginElement(CELL | FACE | EDGE | NODE); it != m->EndElement(); it++)
1070 1071
			if( !it->CheckElementConnectivity() ) check = false;
		return check;
Kirill Terekhov's avatar
Kirill Terekhov committed
1072 1073 1074 1075
	}
	
	
	
1076
	ElementArray<Element> Element::BridgeAdjacencies(ElementType Bridge, ElementType Dest,  MarkerType bridge_mask, bool bridge_invert, MarkerType target_mask, bool target_invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
1077 1078
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
1079
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
1080 1081 1082
		ElementArray<Element> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(Dest);
Kirill Terekhov's avatar
Kirill Terekhov committed
1083
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetPrivateMarker(mrk);
1084
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++) if(bridge_mask == 0 || (bridge_invert ^ (isPrivate(bridge_mask) ? it->GetPrivateMarker(bridge_mask) : it->GetMarker(bridge_mask))))
Kirill Terekhov's avatar
Kirill Terekhov committed
1085 1086 1087
		{
			ElementArray<Element> sub = it->getAdjElements(Dest);
			for(ElementArray<Element>::iterator jt = sub.begin(); jt != sub.end(); jt++)
1088
				if( !jt->GetPrivateMarker(mrk) && (target_mask == 0 || (target_invert ^ (isPrivate(target_mask) ? jt->GetPrivateMarker(target_mask) : jt->GetMarker(target_mask)))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1089
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
1090
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
1091
					jt->SetPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1092 1093
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1094 1095 1096
		for(ElementArray<Element>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemPrivateMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemPrivateMarker(mrk);
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1097 1098 1099 1100
		return adjcells;
	}


1101
	ElementArray<Node> Element::BridgeAdjacencies2Node(ElementType Bridge, MarkerType bridge_mask, bool bridge_invert, MarkerType target_mask, bool target_invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
1102 1103
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
1104
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
1105 1106 1107
		ElementArray<Node> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(NODE);
Kirill Terekhov's avatar
Kirill Terekhov committed
1108
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetPrivateMarker(mrk);
1109
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++) if(bridge_mask == 0 || (bridge_invert ^ (isPrivate(bridge_mask) ? it->GetPrivateMarker(bridge_mask) : it->GetMarker(bridge_mask))))
Kirill Terekhov's avatar
Kirill Terekhov committed
1110 1111 1112
		{
			ElementArray<Node> sub = it->getNodes();
			for(ElementArray<Node>::iterator jt = sub.begin(); jt != sub.end(); jt++)
1113
				if( !jt->GetPrivateMarker(mrk) && (target_mask == 0 || (target_invert ^ (isPrivate(target_mask) ? jt->GetPrivateMarker(target_mask) : jt->GetMarker(target_mask)))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1114
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
1115
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
1116
					jt->SetPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1117 1118
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1119 1120 1121
		for(ElementArray<Node>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemPrivateMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemPrivateMarker(mrk);
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1122 1123 1124
		return adjcells;
	}

1125
	ElementArray<Edge> Element::BridgeAdjacencies2Edge(ElementType Bridge,  MarkerType bridge_mask, bool bridge_invert, MarkerType target_mask, bool target_invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
1126 1127
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
1128
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
1129 1130 1131
		ElementArray<Edge> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(EDGE);
Kirill Terekhov's avatar
Kirill Terekhov committed
1132
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetPrivateMarker(mrk);
1133
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++) if(bridge_mask == 0 || (bridge_invert ^ (isPrivate(bridge_mask) ? it->GetPrivateMarker(bridge_mask) : it->GetMarker(bridge_mask))))
Kirill Terekhov's avatar
Kirill Terekhov committed
1134 1135 1136
		{
			ElementArray<Edge> sub = it->getEdges();
			for(ElementArray<Edge>::iterator jt = sub.begin(); jt != sub.end(); jt++)
1137
				if( !jt->GetPrivateMarker(mrk) && (target_mask == 0 || (target_invert ^ (isPrivate(target_mask) ? jt->GetPrivateMarker(target_mask) : jt->GetMarker(target_mask)))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1138
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
1139
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
1140
					jt->SetPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1141 1142
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1143 1144 1145
		for(ElementArray<Edge>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemPrivateMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemPrivateMarker(mrk);
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1146 1147 1148
		return adjcells;
	}

1149
	ElementArray<Face> Element::BridgeAdjacencies2Face(ElementType Bridge, MarkerType bridge_mask, bool bridge_invert, MarkerType target_mask, bool target_invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
1150 1151
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
1152
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
1153 1154 1155
		ElementArray<Face> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(FACE);
Kirill Terekhov's avatar
Kirill Terekhov committed
1156
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetPrivateMarker(mrk);
1157
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++) if(bridge_mask == 0 || (bridge_invert ^ (isPrivate(bridge_mask) ? it->GetPrivateMarker(bridge_mask) : it->GetMarker(bridge_mask))))
Kirill Terekhov's avatar
Kirill Terekhov committed
1158 1159 1160
		{
			ElementArray<Face> sub = it->getFaces();
			for(ElementArray<Face>::iterator jt = sub.begin(); jt != sub.end(); jt++)
1161
				if( !jt->GetPrivateMarker(mrk) && (target_mask == 0 || (target_invert ^ (isPrivate(target_mask) ? jt->GetPrivateMarker(target_mask) : jt->GetMarker(target_mask)))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1162
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
1163
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
1164
					jt->SetPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1165 1166
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1167 1168 1169
		for(ElementArray<Face>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemPrivateMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemPrivateMarker(mrk);
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1170 1171 1172
		return adjcells;
	}

1173
	ElementArray<Cell> Element::BridgeAdjacencies2Cell(ElementType Bridge,  MarkerType bridge_mask, bool bridge_invert, MarkerType target_mask, bool target_invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
1174 1175
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
1176
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
1177 1178 1179
		ElementArray<Cell> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(CELL);
Kirill Terekhov's avatar
Kirill Terekhov committed
1180
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetPrivateMarker(mrk);
1181
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++) if(bridge_mask == 0 || (bridge_invert ^ (isPrivate(bridge_mask) ? it->GetPrivateMarker(bridge_mask) : it->GetMarker(bridge_mask))))
Kirill Terekhov's avatar
Kirill Terekhov committed
1182 1183 1184
		{
			ElementArray<Cell> sub = it->getCells();
			for(ElementArray<Cell>::iterator jt = sub.begin(); jt != sub.end(); jt++)
1185
				if( !jt->GetPrivateMarker(mrk) && (target_mask == 0 || (target_invert ^ (isPrivate(target_mask) ? jt->GetPrivateMarker(target_mask) : jt->GetMarker(target_mask)))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
1186
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
1187
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
1188
					jt->SetPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1189 1190
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
1191 1192 1193
		for(ElementArray<Cell>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemPrivateMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemPrivateMarker(mrk);
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
1194 1195 1196 1197
		return adjcells;
	}


Kirill Terekhov's avatar
Kirill Terekhov committed
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
	Element::Status Element::GetStatus() const
	{
		assert(isValid());
		return GetMeshLink()->GetStatus(GetHandle());
	}
	void Element::SetStatus(Status status) const
	{
		GetMeshLink()->SetStatus(GetHandle(),status);
	}
	Storage::integer & Element::GlobalID() const
	{
		return GetMeshLink()->GlobalID(GetHandle());
	}
	void Element::Centroid  (Storage::real * cnt) const
	{
		GetMeshLink()->GetGeometricData(GetHandle(),CENTROID,cnt);
	}
	void Element::Barycenter(Storage::real * cnt) const
	{
		GetMeshLink()->GetGeometricData(GetHandle(),BARYCENTER,cnt);
	}
	/*
Kirill Terekhov's avatar
Kirill Terekhov committed
1220 1221
	Element::adj_type &       Element::HighConn() 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1222 1223
		assert(isValid()); 
		return GetMeshLink()->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
1224 1225 1226
	}
	Element::adj_type &       Element::LowConn () 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1227 1228
		assert(isValid()); 
		return GetMeshLink()->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
1229 1230 1231
	}
	Element::adj_type const & Element::HighConn() const 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1232 1233
		assert(isValid()); 
		return GetMeshLink()->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
1234 1235 1236
	}
	Element::adj_type const & Element::LowConn () const 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1237 1238
		assert(isValid()); 
		return GetMeshLink()->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
1239
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1240 1241
	*/
	Element::GeometricType Element::GetGeometricType() const 
Kirill Terekhov's avatar
Kirill Terekhov committed
1242
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1243 1244
		assert(isValid()); 
		return GetMeshLink()->GetGeometricType(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
1245 1246 1247
	}
	void Element::SetGeometricType(GeometricType t)
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
1248 1249
		assert(isValid()); 
		GetMeshLink()->SetGeometricType(GetHandle(),t); 
Kirill Terekhov's avatar
Kirill Terekhov committed
1250
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1251

Kirill Terekhov's avatar
Kirill Terekhov committed
1252
	
Kirill Terekhov's avatar
Kirill Terekhov committed
1253

Kirill Terekhov's avatar
Kirill Terekhov committed
1254 1255
}
#endif