forked from fuag15/volumetric_visualization_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorMap.cpp
executable file
·193 lines (175 loc) · 3.79 KB
/
ColorMap.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "ColorMap.h"
ColorMap::ColorMap() : QObject()
{
size = 0;
startNode = new MapNode();
endNode = new MapNode();
startNode->setValue(-1);
startNode -> setNext(endNode);
endNode -> setValue(9999);
endNode -> setPrev(startNode);
}
void ColorMap::emitUpdate()
{
emit(affected());
return;
}
void ColorMap::affected()
{
emit(changed());
return;
}
ColorMapItr* ColorMap::getIter()
{
return new ColorMapItr(startNode, endNode);
}
void ColorMap::valueAffected(int index)
{
MapNode* cursorNode = start();
MapNode* temp;
MapNode* temp2;
while(cursorNode != endNode && cursorNode->getValue() != index)
{
cursorNode = cursorNode -> getNext();
}
if(cursorNode->getValue() == index)
{
temp = cursorNode->getPrev();
while(temp != startNode && cursorNode->getValue() < temp->getValue())
{
//swap down
temp = cursorNode->getPrev();
temp2 = cursorNode->getNext();
temp2->setPrev(temp);
temp->setNext(temp2);
temp2 = temp->getPrev();
cursorNode->setPrev(temp2);
cursorNode->setNext(temp);
temp->setPrev(cursorNode);
temp2->setNext(cursorNode);
temp = cursorNode->getPrev();
}
temp = cursorNode->getNext();
while(temp != endNode && cursorNode->getValue() > temp->getValue())
{
//swap up
temp = cursorNode->getNext();
temp2 = cursorNode->getPrev();
temp->setPrev(temp2);
temp2->setNext(temp);
temp2 = temp->getNext();
cursorNode->setPrev(temp);
cursorNode->setNext(temp2);
temp2->setPrev(cursorNode);
temp->setNext(cursorNode);
temp = cursorNode->getNext();
}
}
else
{
qDebug() << "BIG FUCKING PROBLEM";
}
emit(changed());
return;
}
void ColorMap::print()
{
MapNode* cursorNode = startNode;
while(cursorNode != endNode)
{
qDebug() << cursorNode->getValue() << "addres" << cursorNode;
cursorNode = cursorNode->getNext();
}
qDebug() << cursorNode->getValue() << "addres" << cursorNode;
}
MapNode* ColorMap::addMap(float x, float y, float z, float alpha, int value)
{
MapNode* newn = new MapNode();
newn->setRed(x);
newn->setGreen(y);
newn->setBlue(z);
newn->setAlpha(alpha);
newn->setValue(value);
MapNode* temp;
MapNode* temp2;
if(size == 0)// if empty put one in
{
temp = newn;
temp -> setNext(endNode);
temp -> setPrev(startNode);
endNode->setPrev(temp);
startNode->setNext(temp);
}
else// if not empty
{
MapNode* cursorNode = start();
while(cursorNode != endNode && cursorNode->getValue() <= value)
{
cursorNode = cursorNode->getNext();
}
//we are now where we should put prev is where node shoudl be put
newn->setNext(cursorNode);
temp = cursorNode->getPrev();
newn->setPrev(temp);
cursorNode->setPrev(newn);
temp->setNext(newn);
}
connect(newn, SIGNAL(nodeChanged()), this, SLOT(affected()));
connect(newn, SIGNAL(killMe(int)), this, SLOT(removeSlot(int)));
connect(newn, SIGNAL(valueChanged(int)), this, SLOT(valueAffected(int)));
size++;
emit(sizeChanged());
emit(changed());
newn -> activate();
return newn;
}
void ColorMap::removeSlot(int index)
{
remove(index);
}
int ColorMap::length()
{
return size;
}
MapNode* ColorMap::start()
{
return startNode;
}
MapNode* ColorMap::end()
{
return endNode;
}
void ColorMap::remove(int value)
{
MapNode* temp;
MapNode* temp2;
MapNode* cursorNode = start();
while((cursorNode != endNode) && (cursorNode->getValue() != value))
{
cursorNode = cursorNode->getNext();
}
if(cursorNode->value == value)
{
temp = cursorNode;
temp2 = cursorNode->getPrev();
cursorNode = cursorNode->getNext();
temp2->setNext(cursorNode);
cursorNode->setPrev(temp2);
delete(temp);
}
size--;
emit(sizeChanged());
emit(changed());
}
ColorMap::~ColorMap()
{
MapNode* temp;
MapNode* cursorNode = start();
while(cursorNode != endNode)
{
temp = cursorNode;
cursorNode = cursorNode->getNext();
delete(temp);
}
delete(endNode);
}