-
Notifications
You must be signed in to change notification settings - Fork 5
/
openVCB.cpp
59 lines (50 loc) · 1.56 KB
/
openVCB.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
// Code for mostly misc stuff.
#include "openVCB.h"
namespace openVCB {
using namespace std;
using namespace glm;
void Project::toggleLatch(ivec2 pos) {
if (pos.x < 0 || pos.x >= width ||
pos.y < 0 || pos.y >= height)
return;
const int gid = indexImage[pos.x + pos.y * width];
toggleLatch(gid);
}
void Project::toggleLatch(int gid) {
if (setOff(stateInks[gid]) != Ink::LatchOff)
return;
states[gid].activeInputs = 1;
if (states[gid].visited) return;
states[gid].visited = 1;
updateQ[0][qSize++] = gid;
}
Project::~Project() {
if (originalImage) delete[] originalImage;
if (vmem) delete[] vmem;
if (image) delete[] image;
if (indexImage) delete[] indexImage;
if (decoration[0]) delete[] decoration[0];
if (decoration[1]) delete[] decoration[1];
if (decoration[2]) delete[] decoration[2];
if (writeMap.ptr) delete[] writeMap.ptr;
if (writeMap.rows) delete[] writeMap.rows;
if (states) delete[] states;
if (stateInks) delete[] stateInks;
if (updateQ[0]) delete[] updateQ[0];
if (updateQ[1]) delete[] updateQ[1];
if (lastActiveInputs) delete[] lastActiveInputs;
}
std::pair<Ink, int> Project::sample(ivec2 pos) {
if (pos.x < 0 || pos.x >= width ||
pos.y < 0 || pos.y >= height)
return { Ink::None, -1 };
int idx = pos.x + pos.y * width;
Ink type = image[idx].getInk();
idx = indexImage[idx];
if (type == Ink::Cross) return { Ink::Cross, idx };
if (idx == -1) return { Ink::None, -1 };
unsigned char state = states[idx].logic;
type = (Ink)(((int)type & 0x7f) | (state & 0x80));
return { type, idx };
}
}