-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolume.h
More file actions
135 lines (103 loc) · 3.5 KB
/
Copy pathvolume.h
File metadata and controls
135 lines (103 loc) · 3.5 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef VOLUME_H
#define VOLUME_H
#include <map>
#include <string>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "voxel.h"
namespace volly {
struct ivec4_cmp {
bool operator() (const glm::ivec4 &a, const glm::ivec4 &b) const {
return memcmp((void*) &a[0], (void*) &b[0], sizeof(glm::ivec4)) < 0;
}
};
/*
// Base class which -- you guessed it -- stores volume data
template<typename Data_T>
class VolumeStore_Base {
public:
glm::ivec3 size;
//glm::ivec3 mid = glm::ivec3(0);
//glm::vec4 size_v4 = glm::vec4(0);
//glm::vec4 mid_v4 = glm::vec4(0);
VolumeStore_Base(glm::ivec3 size): size(size) {}
virtual ~VolumeStore_Base() {}
bool inBounds(glm::ivec3 p) {
return
(p.x < size.x) &
(p.y < size.y) &
(p.z < size.z) &
(p.x >= 0) &
(p.y >= 0) &
(p.z >= 0);
}
virtual Data_T& sample(int x, int y, int z) = 0;
virtual void put(Data_T d, int x, int y, int z) = 0;
virtual Data_T& sample(glm::ivec3 inp) = 0;
virtual void put(Data_T d, glm::ivec3 inp) = 0;
};*/
// Default Volume Store which stores data in an array. Pretty great, right?
template<typename Data_T>
class VolumeStore{
public:
glm::ivec3 size;
Data_T *data;
bool inBounds(glm::ivec3 p) {
return
(p.x < size.x) &
(p.y < size.y) &
(p.z < size.z) &
(p.x >= 0) &
(p.y >= 0) &
(p.z >= 0);
}
Data_T& sample(int x, int y, int z) {
return data[x + this->size.x * (y + this->size.y * z)];
}
void put(Data_T d, int x, int y, int z) {
data[x + this->size.x * (y + this->size.y * z)] = d;
}
Data_T& sample(glm::ivec3 inp) {
return data[inp.x + this->size.x * (inp.y + this->size.y * inp.z)];
}
void put(Data_T d, glm::ivec3 inp) {
data[inp.x + this->size.x * (inp.y + this->size.y * inp.z)] = d;
}
VolumeStore(glm::ivec3 size): size(size) {
data = new Data_T[this->size.x*this->size.y*this->size.z];
}
~VolumeStore() {
delete[] data;
}
// load this up with a hardcoded sphere, so we can test without access to files
void fillSphere(Data_T fillWith) {
glm::ivec3 pt(0);
int ind = 0;
glm::vec3 mid = glm::vec3(this->size)/glm::vec3(2.f);
for(pt.z=0; pt.z < this->size.z; ++pt.z) {
for(pt.y=0; pt.y < this->size.y; ++pt.y) {
for(pt.x=0; pt.x < this->size.x; ++pt.x) {
glm::vec3 rad = 4.0f*(glm::vec3(pt)-mid)/(glm::vec3(this->size));
float radSquare = glm::dot(rad,rad);
bool yes = radSquare < 1;
data[ind] = yes?fillWith:Data_T();
++ind;
}
}
}
}
};
inline VolumeStore<Voxel>* volumeFromVoxelMap(std::map<glm::ivec4, Voxel, ivec4_cmp>* mp, int res, int scale) {
VolumeStore<Voxel>* ret = new VolumeStore<Voxel>(glm::ivec3(res,res,res));
for(auto it = mp->begin(); it != mp->end(); ++it) {
if(it->first.w == scale)
ret->put(it->second, it->first);
}
return ret;
}
VolumeStore<Voxel>* readOFFFile(std::string filename, int resolution, int coloringMode);
void readSimpleVolFile(std::string filename, VolumeStore<Voxel>** myVol);
void readVolFile(std::string filename, VolumeStore<Voxel>** myVol);
}
#endif // VOLUME_H