Newer
Older
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
#include "MantidDataHandling/LoadBinStl.h"
#include "MantidKernel/BinaryStreamReader.h"
#include<iostream>
#include <fstream>
namespace Mantid {
namespace DataHandling {
Kernel::V3D LoadBinStl::makeV3(char *facet) {
char xChar[4] = {facet[0], facet[1], facet[2], facet[3]};
char yChar[4] = {facet[4], facet[5], facet[6], facet[7]};
char zChar[4] = {facet[8], facet[9], facet[10], facet[11]};
float xx = *((float *)xChar);
float yy = *((float *)yChar);
float zz = *((float *)zChar);
Kernel::V3D vec = Kernel::V3D(double(xx),double(yy),double(zz));
return vec;
}
void LoadBinStl::readStl(std::string filename) {
std::ifstream myFile(filename.c_str(), std::ios::in | std::ios::binary);
char header_info[80] = "";
char nTri[4];
unsigned long numberTrianglesLong;
Kernel::BinaryStreamReader streamReader = Kernel::BinaryStreamReader(myFile);
//skip header
streamReader.moveStreamToPosition(80);
// change this after implementing uint32 into the reader
if (myFile) {
myFile.read(nTri, 4);
numberTrianglesLong = *((unsigned long *)nTri);
}
int next = 80;
// now read in all the triangles
for (unsigned long i = 0; i < numberTrianglesLong; i++) {
next = next + i*50;
if (myFile) {
// populate each point of the triangle
for(i=0;i<3;i++){
float xVal;
float yVal;
float zVal;
streamReader >> xVal;
streamReader >> yVal;
streamReader >> zVal;
Kernel::V3D vec = Kernel::V3D(double(xVal),double(yVal),double(zVal));
verticies.push_back(vec);
}
// add index of new verticies to triangle
int newIndex = triangle.size();
triangle.push_back(newIndex);
triangle.push_back(newIndex + 1);
triangle.push_back(newIndex + 2);
}
}
myFile.close()
return;
}
}//namespace datahandling
}//namespace mantid