-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPossibleFaces.cpp
More file actions
150 lines (138 loc) · 4.33 KB
/
Copy pathPossibleFaces.cpp
File metadata and controls
150 lines (138 loc) · 4.33 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include<cmath>
#include "ThreeDModelGenerator.h"
float angleBtwLines(Line l1, Line l2){
float firstX, firstY, firstZ;
float secondX, secondY, secondZ, cos_theta;
float dotProduct;
float firstMag;
float secondMag;
firstX = l1.getFirstPoint().getX() - l1.getSecondPoint().getX();
secondX = l2.getFirstPoint().getX() - l2.getSecondPoint().getX();
firstY = l1.getFirstPoint().getY() - l1.getSecondPoint().getY();
secondY = l2.getFirstPoint().getX() - l2.getSecondPoint().getX();
firstZ = l1.getFirstPoint().getZ() - l1.getSecondPoint().getZ();
secondZ = l2.getFirstPoint().getZ() - l2.getSecondPoint().getZ();
dotProduct = firstX*secondX + firstY*secondY + firstZ*secondZ;
firstMag = sqrt(firstX*firstX + firstY*firstY + firstZ*firstZ);
secondMag = sqrt(secondX*secondX + secondY*secondY + secondZ*secondZ);
cos_theta = dotProduct/(firstMag * secondMag);
return acos(cos_theta);
}
float angleBtwPlanes(Plane p1, Plane p2){
float a1 = p1.getA();
float b1 = p1.getB();
float c1 = p1.getC();
float a2 = p2.getA();
float b2 = p2.getB();
float c2 = p2.getC();
float dotProduct = a1*a2 + b1*b2 + c1*c2;
float firstMag = sqrt(a1*a1 + b1*b1 + c1*c1);
float secondMag = sqrt(a2*a2 + b2*b2 + c2*c2);
float cos_theta = dotProduct/(firstMag * secondMag);
return acos(cos_theta);
}
bool checkEqualPoints(Point p1, Point p2){
if(p1.getX() == p2.getX() && p1.getY() == p2.getY() && p1.getZ() == p2.getZ()){
return true;
}
return false;
}
bool checkEqualLines(Line l1, Line l2){
if(checkEqualPoints(l1.getFirstPoint(), l2.getFirstPoint()) && checkEqualPoints(l1.getSecondPoint(), l2.getSecondPoint())){
return true;
}
return false;
}
bool member(Line l, Line* lines, int count){
for(int i = 0; i < count; i++){
if(checkEqualLines(lines[i],l)){
return true;
}
}
return false;
}
int memberIndex(Line l, Line* lines, int count){
for(int i = 0; i < count; i++){
if(checkEqualLines(lines[i],l)){
return i;
}
}
return -1;
}
LineList getLinesAtPoint(Point p, LineList l){
Line* lines;
lines = l.getLines();
Line resLines[l.getSize()];
int count = 0;
for(int i = 0; i < l.getSize(); i++){
if(checkEqualPoints(lines[i].getFirstPoint(), p) || checkEqualPoints(lines[i].getSecondPoint(), p)){
if(!(member(lines[i],resLines,count))){
resLines[count] = lines[i];
}
}
}
LineList ob;
ob.setLines(resLines);
ob.setSize(count);
return ob;
}
Line getMinLine(Line l, LineList list){
float min = 100;
Line minLine;
int size = list.getSize();
Line lines[size];
for(int i = 0; i < size; i++){
if(angleBtwLines(l,lines[i]) < min){
min = angleBtwLines(l,lines[i]);
minLine = l;
}
}
return minLine;
}
void ThreeDModelGenerator::PossibleClosedLoopConstructor(PlaneWithLines possiblePlane){
//initial line
Line firstLine = *possiblePlane.getArrayLines();
Line prevLine = *possiblePlane.getArrayLines();
//Array of loop lines
Line loopLines[possiblePlane.getNumLines()];
//Array of approached points of each line
Point approachedPoints[possiblePlane.getNumLines()];
int loopLinesLen = 0;
for(int i = 0; i < possiblePlane.getNumLines(); i++){
LineList l;
l.setLines(possiblePlane.getArrayLines());
l.setSize(possiblePlane.getNumLines());
LineList temp = getLinesAtPoint(prevLine.getSecondPoint(),l);
Line nextLine = getMinLine(prevLine, temp);
if(member(nextLine, loopLines, i)){
//index represents the index where the line is found
int index = memberIndex(nextLine, loopLines, i);
//if edge is false edge
if(index != -1 && checkEqualPoints(approachedPoints[index],prevLine.getSecondPoint())){
//implement remove function for lineList
this->possibleEdges.remove(nextLine);
ThreeDModelGenerator::PossibleSurfacesConstructor(this->possibleEdges);
}
else{
if(checkEqualLines(nextLine,firstLine)){
break;
}
}
}
else{
//update the parameters
loopLines[loopLinesLen] = nextLine;
loopLinesLen++;
prevLine = nextLine;
}
}
}
void ThreeDModelGenerator::PossibleClosedLoopFacesConstructor(planeWithLinesList possibleSurfaces){
int size = possibleSurfaces.getSize();
PlaneWithLines* surfaces;
surfaces = possibleSurfaces.getPlaneWithLines();
for(int i = 0; i < size; i++){
PossibleClosedLoopConstructor(*surfaces);
surfaces++;
}
}