-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadFieldDataFromFile.cpp
111 lines (87 loc) · 1.6 KB
/
LoadFieldDataFromFile.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// #include "stdafx.h"
// #include "LoadFieldDataFromFile.h"
// #include <fstream>
// #include <string>
// #include <vector>
// #include <iostream>
#include "DXUT.h"
#include "LoadFieldDataFromFile.h"
using namespace std;
typedef vector<vector<string> > vvs;
template <class T>
void convertFromString(T &value, const std::string &s) {
std::stringstream ss(s);
ss >> value;
}
LoadFieldDataFromFile::LoadFieldDataFromFile(void)
{
u_div = v_div =0;
}
LoadFieldDataFromFile::~LoadFieldDataFromFile(void)
{
}
void LoadFieldDataFromFile::Initialise(char* filename)
{
ifstream infile(filename);
infile>>noskipws;
int row =0;
int col = 0;
char chr;
while(infile>>chr)
{
switch(chr)
{
case '\n':
++ row;
col = 0;
break;
case ' ':
++ col;
break;
default:;
}
}
infile.close();
row ++; col++;
u_div = row;
v_div = col;
vvs data;
//vvs data_spilt;
data.resize(row);
for(int k = 0; k < row; k ++)
data[k].resize(col);
ifstream infile2(filename);
size_t trow, tcol;
trow = tcol = 0;
string str;
while(trow < row)
{
while(tcol < col-1)
{
getline(infile2,str,' ');
data[trow][tcol] = str;
tcol++;
}
getline(infile2,str,'\n');
data[trow][tcol] = str;
tcol = 0;
trow ++;
}
infile2.close();
m_pdirection = new D3DXVECTOR2[row*col];
assert(m_pdirection);
for (size_t r = 0; r != row; ++r)
{
for (size_t c=0; c != col; ++c)
{
m_pdirection[r*col+c] = D3DXVECTOR2(data[r][c][0]-'0',data[r][c][2]-'0');
}
}
}
void LoadFieldDataFromFile::Release()
{
if (m_pdirection)
{
delete [] m_pdirection;
}
}