-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolyhedron.cpp
More file actions
150 lines (127 loc) · 3.8 KB
/
polyhedron.cpp
File metadata and controls
150 lines (127 loc) · 3.8 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 "polyhedron.h"
#include <fstream>
Polyhedron::Polyhedron()
{
}
Polyhedron::Polyhedron(const vector<CPolygon>& polygons)
{
polygons_ = polygons;
}
void Polyhedron::clear()
{
polygons_.clear();
}
void Polyhedron::addPolygonsList(const list<CPolygon> &polygons)
{
for(list<CPolygon>::const_iterator i = polygons.begin() ; i != polygons.end(); ++i)
polygons_.push_back(*i);
}
void Polyhedron::draw()
{
for(ushort i=0; i<polygons_.size(); ++i)
polygons_[i].draw();
}
bool Polyhedron::polyhedronSection(const Plane& plane,
Polyhedron* polyhedron1,
Polyhedron* polyhedron2,
array<double, 4> color)
{
CPolygon tempPolygon1, tempPolygon2;
list<Point> tempSectionLine;
list<CPolygon> polygonsList1, polygonsList2;
list<list<Point>> sectionLines;
// Для дебага
for(ushort i=0; i < polygons_.size(); ++i)
{
if(polygons_[i].polygonSection(plane, &tempPolygon1, &tempPolygon2, &tempSectionLine))
{
polygonsList1.push_back(tempPolygon1);
polygonsList2.push_back(tempPolygon2);
}
else
{
if(!tempPolygon1.empty())
polygonsList1.push_back(tempPolygon1);
if(!tempPolygon2.empty())
polygonsList2.push_back(tempPolygon2);
}
if(tempSectionLine.size() > 1)
sectionLines.push_back(tempSectionLine);
tempPolygon1.clear(); tempPolygon2.clear(); tempSectionLine.clear();
}
// Костыль! Такой большой и деревянный. Нет, на самом деле это можно оставить, но так не хочется.
// Костыль в костыле. Деревянная нога капитана Флинта (не помню была ли у него деревянная нога)
// Поиск и удаление повторений.
if(sectionLines.size() > 2)
for(auto i = sectionLines.begin(), j = i; i != --sectionLines.end(); ++i, j = i)
for(++j; j != sectionLines.end(); )
{
if((i->front() == j->front() && i->back() == j->back()) ||
(i->front() == j->back() && i->back() == j->front()) )
j = sectionLines.erase(j);
else
++j;
}
for(bool endThis = false; sectionLines.size() > 2 && endThis != true; )
{
for(auto i = ++sectionLines.begin(); i != sectionLines.end(); ++i)
if(i->front() == sectionLines.front().back())
{
/*
if(sectionLines.front().front() == i->back())
{
endThis = true;
break;
}
*/
sectionLines.front().push_back(i->back());
sectionLines.erase(i);
break;
}
else if(i->back() == sectionLines.front().back())
{
/*
if(sectionLines.front().front() == i->front())
{
endThis = true;
break;
}
*/
sectionLines.front().push_back(i->front());
sectionLines.erase(i);
break;
}
}
if(sectionLines.size() > 0 && sectionLines.front().size() > 2)
{
polygonsList1.push_back(CPolygon(sectionLines.front(), color));
polygonsList2.push_back(CPolygon(sectionLines.front(), color));
}
if(polyhedron1 != 0)
{
polyhedron1->clear();
polyhedron1->addPolygonsList(polygonsList1);
}
if(polyhedron2 != 0)
{
polyhedron2->clear();
polyhedron2->addPolygonsList(polygonsList2);
}
return (polygonsList1.size() > 3) && (polygonsList2.size() > 3);
}
bool Polyhedron::polyhedronGroupSection(const Plane& plane,
const bool& xyzPlanesSymmetry,
//const bool& someVectorSymmetry,
Polyhedron* polyhedron1,
Polyhedron* polyhedron2,
array<double, 4> color)
{
bool temp = false;
temp = temp || this->polyhedronSection(plane, polyhedron1, polyhedron2, color);
if(xyzPlanesSymmetry == true)
{
PlanesGroup_xyzPlanesSymmetry planesXYZ(plane);
for(auto i = ++planesXYZ.planes_.begin(); i != planesXYZ.planes_.end(); ++i)
polyhedron1->polyhedronSection((*i), polyhedron1, polyhedron2, color);
}
}