-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileReader.h
54 lines (41 loc) · 1.21 KB
/
FileReader.h
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
#ifndef FILE_READER_H_
#define FILE_READER_H_
#include <fstream>
#include <itkVector.h>
#include "Constants.h"
class FileReader
{
public:
FileReader(const std::string & filename);
~FileReader();
template<typename T>
T Read()
{
T read;
this->reader.read((char*)&read, sizeof(T));
return read;
}
template<typename T>
void Read(T* pointer, size_t count)
{
this->reader.read((char*)pointer, sizeof(T) * count);
}
template<typename T>
void Read(Constants::EigenValuesType* pointer, size_t count)
{
Constants::EigenValuesType::ValueType* array = new Constants::EigenValuesType::ValueType[count * Constants::EigenValuesType::GetVectorDimension()];
this->reader.read((char*)array, sizeof(Constants::EigenValuesType::ValueType) * Constants::EigenValuesType::GetVectorDimension() * count);
for (size_t i = 0; i < count; ++i, ++pointer)
{
*pointer = Constants::EigenValuesType();
pointer->SetElement(0, array[3*i]);
pointer->SetElement(1, array[3*i + 1]);
pointer->SetElement(2, array[3*i + 2]);
}
delete[] array;
}
private:
void Init();
std::ifstream reader;
};
#endif // FILE_READER_H_