forked from precious/dr_program
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_utils.cpp
More file actions
52 lines (46 loc) · 1.77 KB
/
file_utils.cpp
File metadata and controls
52 lines (46 loc) · 1.77 KB
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
#include "file_utils.h"
float File::scaleFactor = 0.001; // by default coordinates are given in millimeters
vector<PlaneType>* File::getCoordinatesFromFile(char *filename) {
filebuf fb;
if (!fb.open(filename,ios::in)) {
cerr << "An error occurred while opening file" << endl;
return NULL;
}
istream fileInputStream(&fb);
vector<PlaneType>* coordinatesList = new vector<PlaneType>();
ThreePoints *tempThreePoints;
int i;
while(!fileInputStream.eof()) {
tempThreePoints = new ThreePoints();
// read 3 points
for (i = 0;i < 3;i++) {
fileInputStream >> tempThreePoints->set[i].x
>> tempThreePoints->set[i].y
>> tempThreePoints->set[i].z;
if (fileInputStream.fail()) {
if (!fileInputStream.eof())
fileInputStream.clear();
break;
} /*else {
tempThreePoints->set[i].x *= SCALE;
tempThreePoints->set[i].y *= SCALE;
tempThreePoints->set[i].z *= SCALE;
}*/
}
// if all values have been read successfuly then push array to result list
if (i == 3) {
coordinatesList->push_back(PlaneType(*tempThreePoints));
for (i = 0;i < 3;i++) {
coordinatesList->back().set[i].x *= scaleFactor;
coordinatesList->back().set[i].y *= scaleFactor;
coordinatesList->back().set[i].z *= scaleFactor;
}
}
// then delete it
delete tempThreePoints;
// scipping remaining characters in current string
while (!fileInputStream.eof() && fileInputStream.get() != '\n');
}
fb.close();
return coordinatesList;
}