earray.cpp 2.89 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1 2 3 4 5 6 7 8 9 10 11
#include "inmost_mesh.h"
#if defined(USE_MESH)
namespace INMOST
{
	template<typename StorageType>
	void ElementArray<StorageType>::Unite(const HandleType * h, INMOST_DATA_ENUM_TYPE num)
	{
		if( empty() ) container.insert(container.end(),h,h+num);
		else
		{
			Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
12 13
			MarkerType mrk = m->CreatePrivateMarker();
			SetPrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
14
			for(INMOST_DATA_ENUM_TYPE it = 0; it < num; it++) 
Kirill Terekhov's avatar
Kirill Terekhov committed
15
				if( !m->GetPrivateMarker(h[it],mrk) ) 
Kirill Terekhov's avatar
Kirill Terekhov committed
16 17
				{
					container.push_back(h[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
18
					m->SetPrivateMarker(h[it],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
19
				}
Kirill Terekhov's avatar
Kirill Terekhov committed
20 21
			RemPrivateMarker(mrk);
			m->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
22 23 24 25 26 27 28 29 30
		}
	}

	template<typename StorageType>
	void ElementArray<StorageType>::Subtract(const HandleType * h, INMOST_DATA_ENUM_TYPE num)
	{
		if( !empty() )
		{
			Mesh * mesh = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
31
			MarkerType mrk = mesh->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
32
			//other.SetMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
33
			mesh->SetPrivateMarkerArray(h,num,mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
34 35 36 37
			{
				size_type m = 0, n = 0;
				while( m < size() ) 
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
38
					if( !mesh->GetPrivateMarker(container[m],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
39 40 41 42 43 44
						container[n++] = container[m];
					m++;
				}
				container.resize(n);
			}
			//other.RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
45 46
			mesh->RemPrivateMarkerArray(h,num,mrk);
			mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
47 48 49 50 51 52 53 54
		}
	}
	template <typename StorageType>
	void ElementArray<StorageType>::Intersect(const HandleType * h, INMOST_DATA_ENUM_TYPE num)
	{
		if( !empty() )
		{
			Mesh * mesh = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
55
			MarkerType mrk = mesh->CreatePrivateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
56
			//other.SetMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
57
			mesh->SetPrivateMarkerArray(h,num,mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
58 59 60 61
			{
				size_type m = 0, n = 0;
				while( m < size() ) 
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
62
					if( mesh->GetPrivateMarker(container[m],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
63 64 65 66 67 68
						container[n++] = container[m];
					m++;
				}
				container.resize(n);
			}
			//other.RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
69 70
			mesh->RemPrivateMarkerArray(h,num,mrk);
			mesh->ReleasePrivateMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
		}
	}

	template <typename StorageType>
	void ElementArray<StorageType>::SetMarker(MarkerType m) const
	{
		Mesh * mesh = GetMeshLink();
		for(size_type it = 0; it < size(); it++) mesh->SetMarker(container[it],m);
	}

	template <typename StorageType>
	void ElementArray<StorageType>::RemMarker(MarkerType m) const
	{
		Mesh * mesh = GetMeshLink();
		for(size_type it = 0; it < size(); it++) mesh->RemMarker(container[it],m);
	}

Kirill Terekhov's avatar
Kirill Terekhov committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
  template <typename StorageType>
	void ElementArray<StorageType>::SetPrivateMarker(MarkerType m) const
	{
		Mesh * mesh = GetMeshLink();
		for(size_type it = 0; it < size(); it++) mesh->SetPrivateMarker(container[it],m);
	}

	template <typename StorageType>
	void ElementArray<StorageType>::RemPrivateMarker(MarkerType m) const
	{
		Mesh * mesh = GetMeshLink();
		for(size_type it = 0; it < size(); it++) mesh->RemPrivateMarker(container[it],m);
	}

Kirill Terekhov's avatar
Kirill Terekhov committed
102 103 104 105 106 107 108 109
	//all possible templates
	template class ElementArray<Element>;
	template class ElementArray<Node>;
	template class ElementArray<Edge>;
	template class ElementArray<Face>;
	template class ElementArray<Cell>;
	template class ElementArray<Storage>;
}
Kirill Terekhov's avatar
Kirill Terekhov committed
110
#endif