-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContourChainGroup.cpp
117 lines (90 loc) · 3.19 KB
/
ContourChainGroup.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
#include "ContourChainGroup.h"
ContourChainGroup::ContourChainGroup() {
}
void ContourChainGroup::addSegmentToGroup(const QVector3D &v1, const QVector3D &v2)
{
waitingForAdd.push_front(v1);
waitingForAdd.push_front(v2);
while (tryAddingWaitingToGroup()) { };
}
void ContourChainGroup::finishedAdding() {
//there are no more pairs coming... so chains that aren't yet closed are never going to be, so force-close them
while (waitingForAdd.size()>0) {
for (ContourChain & c : contourChainGroup) {
if (!c.isChainClosed()) {
c.forceChainClosed();
}
}
while (tryAddingWaitingToGroup()) { };
}
}
bool ContourChainGroup::tryAddingWaitingToGroup()
{
//REFACTORTODO - do not make this a while loop
//go through each chain and try to add, if we can't return false
//if we can, return true
//chains are "done" when they are closed
bool haveOpenChains=false;
for (ContourChain & c : contourChainGroup) {
if (!c.isChainClosed()) {
//printf("Already have a chain that's open.\n",contourChainGroup.size());
haveOpenChains=true;
break;
}
}
if (!haveOpenChains) {
contourChainGroup.push_front(ContourChain());
//printf("\tI made a new chain... There were no open ones...\n");
}
//we iterate through each pair in the waiting list, and try to add them to each chain in the group that is not yet closed
//printf("%i segments waiting to get in, on %i lines.\n",waitingForAdd.size()/2,contourChainGroup.size());
for (int i=0; i+1<waitingForAdd.size(); i+=2) {
QVector3D & v1= waitingForAdd[i];
QVector3D & v2= waitingForAdd[i+1];
for (ContourChain & c : contourChainGroup) {
if (c.isChainClosed()) {
continue;
}
if (c.connectsToChain(v1,v2)) {
//printf("\tAdding segment to chain!\n");
//printf("\tLength before: %i\n",eachChain.getLength());
c.addSegmentToChain(v1,v2);
//printf("\tLength after: %i\n",eachChain.getLength());
waitingForAdd.removeAt(i);
waitingForAdd.removeAt(i);
return true;
}
}
}
return false;
}
void ContourChainGroup::draw(int minChainLength)
{
for (ContourChain & c : contourChainGroup) {
if (c.getLength()>=minChainLength) {
c.draw();
}
}
}
void ContourChainGroup::drawAsSplines(int minChainLength, float maxstrokewidth, int numReverseChaikinPasses) {
glLineWidth(maxstrokewidth);
for (ContourChain & c : contourChainGroup) {
if (c.getLength()>=minChainLength) {
c.drawAsSpline(numReverseChaikinPasses);
}
}
}
void ContourChainGroup::drawAsSplineOBJ(int minChainLength, OBJObject *obj, float maxstrokewidth, int numReverseChaikinPasses) {
for (ContourChain & c : contourChainGroup) {
if (c.getLength()>=minChainLength) {
c.drawAsSplineOBJ(obj, maxstrokewidth, numReverseChaikinPasses);
}
}
}
void ContourChainGroup::resetGroup() {
for (ContourChain & c : contourChainGroup) {
c.reset();
}
contourChainGroup.clear();
waitingForAdd.clear();
}