summaryrefslogtreecommitdiffstats
path: root/lib/tqwtplot3d/examples/mesh2/src/femreader.h
blob: 374a181768b53dca744f6d0dc7aa8266e91e2999 (plain)
1
2
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
30
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef femreader_h__2004_03_07_14_03_begin_guarded_code
#define femreader_h__2004_03_07_14_03_begin_guarded_code

#include <math.h>
#include <fstream>
#include "qwt3d_global.h"
#include "qwt3d_types.h"

class NodeFilter
{
	public:
		explicit NodeFilter()
		{
			values = std::vector<double>(6);
		}
		
		Qwt3D::Triple readLine(std::ifstream& str)
		{
			for (unsigned i = 0; i!=values.size(); ++i)
				str >> values[i];

      return Qwt3D::Triple(values[1], values[2], values[5] / 1000);
		}
	
	private:				
		std::vector<double> values;
};

class CellFilter
{
	public:
		
		Qwt3D::Cell readLine(std::ifstream& str)
		{
			Qwt3D::Cell cell(4);
			str >> cell[0]; // dummy (cell number) - overridden in next step
			for (unsigned i = 0; i<cell.size(); ++i)
			{
				str >> cell[i];
				cell[i] = cell[i] - 1;
			}
			return cell;
		}
};


template <typename FILTER>
bool readNodes(Qwt3D::TripleField& v, const char* fname, FILTER fil)
{
	std::ifstream file(fname);
	
	v.clear();

	Qwt3D::Triple t;
	while ( file ) 
	{
		t = fil.readLine( file );			
		if (!file.good())
			break;
		v.push_back( t );
	}
	return true;
}

template <typename FILTER>
bool readConnections(Qwt3D::CellField& v, const char* fname, FILTER fil)
{
	std::ifstream file(fname);

	v.clear();

	Qwt3D::Cell cell;
	while ( file ) 
	{
		cell = fil.readLine( file );
		if (!file.good())
			break;
		v.push_back(cell);	
	}
	return true;
}

#endif /* include guarded */