edge.cpp 8.13 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1 2 3 4 5
#include "inmost.h"
#if defined(USE_MESH)
namespace INMOST
{
	
Kirill Terekhov's avatar
Kirill Terekhov committed
6
	Node Edge::getBeg() const 
Kirill Terekhov's avatar
Kirill Terekhov committed
7
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
8 9
		assert(GetHandleElementType(GetHandle())==EDGE);
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
10 11
		if( !GetMeshLink()->HideMarker() )
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
12
			adj_type const & lc = m->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
13
			if( lc.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
14 15
				return Node(m,InvalidHandle());
			return Node(m,lc.front());
Kirill Terekhov's avatar
Kirill Terekhov committed
16 17 18
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
19
			adj_type const & lc = m->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
20
			if( !lc.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
21
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
22
				enumerator i = ENUMUNDEF;
Kirill Terekhov's avatar
Kirill Terekhov committed
23
				MarkerType hm = m->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
24
				i = m->getNext(lc.data(),static_cast<enumerator>(lc.size()),i,hm);
Kirill Terekhov's avatar
Kirill Terekhov committed
25
				if( i != lc.size() ) return Node(m,lc[i]);
Kirill Terekhov's avatar
Kirill Terekhov committed
26
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
27
			return Node(m,InvalidHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
28 29
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
30
	Node Edge::getEnd() const 
Kirill Terekhov's avatar
Kirill Terekhov committed
31
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
32 33 34
		assert(GetHandleElementType(GetHandle())==EDGE);
		Mesh * m = GetMeshLink();
		if( !m->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
35
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
36
			adj_type const & lc = m->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
37
			if( lc.size() < 2 )
Kirill Terekhov's avatar
Kirill Terekhov committed
38 39
				return Node(m,InvalidHandle());
			return Node(m,lc.back());
Kirill Terekhov's avatar
Kirill Terekhov committed
40 41 42
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
43
			adj_type const & lc = m->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
44
			if( !lc.empty() )
Kirill Terekhov's avatar
Kirill Terekhov committed
45
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
46
				enumerator i = ENUMUNDEF;
Kirill Terekhov's avatar
Kirill Terekhov committed
47
				MarkerType hm = m->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
48 49
				i = m->getNext(lc.data(),static_cast<enumerator>(lc.size()),i,hm);
				i = m->getNext(lc.data(),static_cast<enumerator>(lc.size()),i,hm);
Kirill Terekhov's avatar
Kirill Terekhov committed
50
				if( i != lc.size() ) return Node(m,lc[i]);
Kirill Terekhov's avatar
Kirill Terekhov committed
51
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
52
			return Node(m,InvalidHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
53 54
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
55
	
Kirill Terekhov's avatar
Kirill Terekhov committed
56
	ElementArray<Node> Edge::getNodes() const
Kirill Terekhov's avatar
Kirill Terekhov committed
57
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
58 59 60
		assert(GetHandleElementType(GetHandle())==EDGE);
		Mesh * m = GetMeshLink();
		if( !m->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
61
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
62 63
			adj_type & lc = m->LowConn(GetHandle());
			return ElementArray<Node>(m,lc.data(),lc.data()+lc.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
64
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
65 66
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
67 68 69 70 71
			MarkerType hm = m->HideMarker();
			ElementArray<Node> aret(m);
			adj_type const & lc = m->LowConn(GetHandle());
			for(adj_type::size_type it = 0; it < lc.size(); ++it)
				if( !m->GetMarker(lc[it],hm) ) aret.push_back(lc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
72 73 74
			return aret;
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
75

Kirill Terekhov's avatar
Kirill Terekhov committed
76
	ElementArray<Node> Edge::getNodes(MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
77
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
78 79 80 81
		assert(GetHandleElementType(GetHandle())==EDGE);
		Mesh * m = GetMeshLink();
		ElementArray<Node> aret(m);
		if( !m->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
82
		{	
Kirill Terekhov's avatar
Kirill Terekhov committed
83
			adj_type const & lc = m->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
84 85 86 87 88 89 90 91 92 93
			if( isPrivate(mask) )
			{
				for(adj_type::size_type it = 0; it < lc.size(); ++it)
					if( invert ^ m->GetPrivateMarker(lc[it],mask) ) aret.push_back(lc[it]);
			}
			else
			{
				for(adj_type::size_type it = 0; it < lc.size(); ++it)
					if( invert ^ m->GetMarker(lc[it],mask) ) aret.push_back(lc[it]);
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
94 95 96
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
97 98
			MarkerType hm = m->HideMarker();
			adj_type const & lc = m->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
99 100 101 102 103 104 105 106 107 108
			if( isPrivate(mask) )
			{
				for(adj_type::size_type it = 0; it < lc.size(); ++it)
					if( (invert ^ m->GetPrivateMarker(lc[it],mask)) && !m->GetMarker(lc[it],hm) ) aret.push_back(lc[it]);
			}
			else
			{
				for(adj_type::size_type it = 0; it < lc.size(); ++it)
					if( (invert ^ m->GetMarker(lc[it],mask)) && !m->GetMarker(lc[it],hm) ) aret.push_back(lc[it]);
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
109 110 111
		}
		return aret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
112
	
Kirill Terekhov's avatar
Kirill Terekhov committed
113
	ElementArray<Face> Edge::getFaces() const
Kirill Terekhov's avatar
Kirill Terekhov committed
114
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
115 116 117
		assert(GetHandleElementType(GetHandle())==EDGE);
		Mesh * m = GetMeshLink();
		if( !m->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
118
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
119 120
			adj_type const & hc = m->HighConn(GetHandle());
			return ElementArray<Face>(m,hc.data(),hc.data()+hc.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
121
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
122 123
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
124 125 126 127 128
			MarkerType hm = m->HideMarker();
			ElementArray<Face> aret(m);
			adj_type const & hc = m->HighConn(GetHandle());
			for(adj_type::size_type it = 0; it < hc.size(); ++it)
				if( !m->GetMarker(hc[it],hm) ) aret.push_back(hc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
129 130 131
			return aret;
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
132 133


Kirill Terekhov's avatar
Kirill Terekhov committed
134
	ElementArray<Face> Edge::getFaces(MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
135
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
136 137 138 139
		assert(GetHandleElementType(GetHandle())==EDGE);
		Mesh * m = GetMeshLink();
		ElementArray<Face> aret(m);
		if( !m->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
140
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
141
			adj_type const & hc = m->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
142 143 144 145 146 147 148 149 150 151
			if( isPrivate(mask) )
			{
				for(adj_type::size_type it = 0; it < hc.size(); ++it)
					if( (invert ^ m->GetPrivateMarker(hc[it],mask)) ) aret.push_back(hc[it]);
			}
			else
			{
				for(adj_type::size_type it = 0; it < hc.size(); ++it)
					if( (invert ^ m->GetMarker(hc[it],mask)) ) aret.push_back(hc[it]);
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
152 153 154
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
155
			MarkerType hm = GetMeshLink()->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
156
			adj_type const & hc = m->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
157 158 159 160 161 162 163 164 165 166
			if( isPrivate(mask) )
			{
				for(adj_type::size_type it = 0; it < hc.size(); ++it)
					if( (invert ^ m->GetPrivateMarker(hc[it],mask)) && !m->GetMarker(hc[it],hm) ) aret.push_back(hc[it]);
			}
			else
			{
				for(adj_type::size_type it = 0; it < hc.size(); ++it)
					if( (invert ^ m->GetMarker(hc[it],mask)) && !m->GetMarker(hc[it],hm) ) aret.push_back(hc[it]);
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
167 168 169 170
		}
		return aret;
	}

Kirill Terekhov's avatar
Kirill Terekhov committed
171
	ElementArray<Cell> Edge::getCells() const
Kirill Terekhov's avatar
Kirill Terekhov committed
172
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
173
		assert(GetHandleElementType(GetHandle())==EDGE);
Kirill Terekhov's avatar
Kirill Terekhov committed
174
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
175
		ElementArray<Cell> aret(m);
Kirill Terekhov's avatar
Kirill Terekhov committed
176
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
177
		if( !m->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
178
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
179 180
			adj_type const & hc = m->HighConn(GetHandle());
			for(adj_type::size_type it = 0; it < hc.size(); it++) //faces
Kirill Terekhov's avatar
Kirill Terekhov committed
181
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
182 183
				adj_type const & ihc = m->HighConn(hc[it]);
				for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) //cels
Kirill Terekhov's avatar
Kirill Terekhov committed
184
					if( !m->GetPrivateMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
185
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
186
						aret.push_back(ihc[jt]);
Kirill Terekhov's avatar
Kirill Terekhov committed
187
						m->SetPrivateMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
188
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
189
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
190 191 192
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
193 194 195
			MarkerType hm = m->HideMarker();
			adj_type const & hc = m->HighConn(GetHandle());
			for(adj_type::size_type it = 0; it < hc.size(); it++) if( !m->GetMarker(hc[it],hm) ) //faces
Kirill Terekhov's avatar
Kirill Terekhov committed
196
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
197 198
				adj_type const & ihc = m->HighConn(hc[it]);
				for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !m->GetMarker(ihc[jt],hm) ) //cels
Kirill Terekhov's avatar
Kirill Terekhov committed
199
					if( !m->GetPrivateMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
200
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
201
						aret.push_back(ihc[jt]);
Kirill Terekhov's avatar
Kirill Terekhov committed
202
						m->SetPrivateMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
203
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
204
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
205
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
206
		for(ElementArray<Cell>::size_type it = 0; it < aret.size(); it++) 
Kirill Terekhov's avatar
Kirill Terekhov committed
207
			m->RemPrivateMarker(aret.at(it),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
208
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
209 210
		return aret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
211

Kirill Terekhov's avatar
Kirill Terekhov committed
212
	ElementArray<Cell> Edge::getCells(MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
213
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
214
		assert(GetHandleElementType(GetHandle())==EDGE);
Kirill Terekhov's avatar
Kirill Terekhov committed
215
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
216
		ElementArray<Cell> aret(m);
Kirill Terekhov's avatar
Kirill Terekhov committed
217
		MarkerType mrk = m->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
218
		if( isPrivate(mask) )
Kirill Terekhov's avatar
Kirill Terekhov committed
219
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
220
			if( !GetMeshLink()->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
221
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
				adj_type const & hc = m->HighConn(GetHandle());
				for(adj_type::size_type it = 0; it < hc.size(); it++) //faces
				{
					adj_type const & ihc = m->HighConn(hc[it]);
					for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) //cels
						if( (invert ^ m->GetPrivateMarker(ihc[jt],mask)) && !m->GetPrivateMarker(ihc[jt],mrk) )
						{
							aret.push_back(ihc[jt]);
							m->SetPrivateMarker(ihc[jt],mrk);
						}
				}
			}
			else
			{
				MarkerType hm = m->HideMarker();
				adj_type const & hc = m->HighConn(GetHandle());
				for(adj_type::size_type it = 0; it < hc.size(); it++) if( !m->GetMarker(hc[it],hm) ) //faces
				{
					adj_type const & ihc = m->HighConn(hc[it]);
					for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !m->GetMarker(ihc[jt],hm) ) //cels
						if( (invert ^ m->GetPrivateMarker(ihc[jt],mask)) && !m->GetPrivateMarker(ihc[jt],mrk) )
						{
							aret.push_back(ihc[jt]);
							m->SetPrivateMarker(ihc[jt],mrk);
						}
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
248
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
249 250 251
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
252
			if( !GetMeshLink()->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
253
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
				adj_type const & hc = m->HighConn(GetHandle());
				for(adj_type::size_type it = 0; it < hc.size(); it++) //faces
				{
					adj_type const & ihc = m->HighConn(hc[it]);
					for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) //cels
						if( (invert ^ m->GetMarker(ihc[jt],mask)) && !m->GetPrivateMarker(ihc[jt],mrk) )
						{
							aret.push_back(ihc[jt]);
							m->SetPrivateMarker(ihc[jt],mrk);
						}
				}
			}
			else
			{
				MarkerType hm = m->HideMarker();
				adj_type const & hc = m->HighConn(GetHandle());
				for(adj_type::size_type it = 0; it < hc.size(); it++) if( !m->GetMarker(hc[it],hm) ) //faces
				{
					adj_type const & ihc = m->HighConn(hc[it]);
					for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !m->GetMarker(ihc[jt],hm) ) //cels
						if( (invert ^ m->GetMarker(ihc[jt],mask)) && !m->GetPrivateMarker(ihc[jt],mrk) )
						{
							aret.push_back(ihc[jt]);
							m->SetPrivateMarker(ihc[jt],mrk);
						}
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
280
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
281
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
282
		for(ElementArray<Cell>::size_type it = 0; it < aret.size(); it++) 
Kirill Terekhov's avatar
Kirill Terekhov committed
283
			m->RemPrivateMarker(aret.at(it),mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
284
		m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
285 286
		return aret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
287 288 289
}

#endif