44 for (
size_t i = 0; i < f.
vertices.size(); i++)
51 const vector<math::TPolygon3D>& polys, vector<TPoint3D>& vertices,
52 vector<CPolyhedron::TPolyhedronFace>& faces)
54 vertices.reserve(4 * polys.size());
55 faces.reserve(polys.size());
56 for (
const auto& poly : polys)
58 size_t N = poly.size();
59 if (N < 3)
return false;
62 for (
size_t i = 0; i < N; i++)
64 auto it2 =
find(vertices.begin(), vertices.end(), poly[i]);
65 if (it2 == vertices.end())
68 vertices.push_back(poly[i]);
71 f.
vertices[i] = it2 - vertices.begin();
96 const std::string& components, uint32_t numBaseEdges,
97 vector<JohnsonBodyPart>& parts)
99 size_t N = components.length();
104 switch (components[i])
108 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
113 if (numBaseEdges & 1)
return false;
114 if (i == N - 1)
return false;
116 if (components[i] ==
'+')
118 if (i != N - 1)
return false;
119 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
124 else if (components[i] ==
'-')
126 if (parts.size() > 0)
return false;
136 if (numBaseEdges != 10)
return false;
137 if (i == N - 1)
return false;
139 if (components[i] ==
'+')
141 if (i != N - 1)
return false;
142 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
147 else if (components[i] ==
'-')
149 if (parts.size() > 0)
return false;
159 if (i == N - 1)
return false;
161 if (components[i] ==
'C' || components[i] ==
'R')
170 if (i == N - 1)
return false;
172 switch (components[i])
175 if (numBaseEdges > 5)
return false;
176 if (i != N - 1)
return false;
177 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
181 if (numBaseEdges > 5)
return false;
182 if (i != 1)
return false;
187 if (parts.size() > 0 && (*parts.rbegin() ==
PRISM))
189 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
190 parts.push_back(
PRISM);
201 if (parts.size() == 0)
return false;
216 return numBaseEdges >> 1;
223 size_t numBaseEdges,
double angleShift,
double baseRadius,
224 double edgeLength,
bool isRotated,
bool isUpwards,
size_t base,
225 vector<TPoint3D>& verts, vector<CPolyhedron::TPolyhedronFace>& faces)
227 size_t edges2 = numBaseEdges >> 1;
229 baseRadius * sin(
M_PI / numBaseEdges) / sin(
M_PI / edges2);
236 baseRadius * cos(
M_PI / numBaseEdges) -
237 minorRadius * cos(
M_PI / edges2)));
238 double height = verts[base].z + (isUpwards ? h : -h);
239 angleShift +=
M_PI / edges2 +
240 (isRotated ? -
M_PI / numBaseEdges :
M_PI / numBaseEdges);
241 size_t minorBase = verts.size();
242 for (
size_t i = 0; i < edges2; i++)
244 double ang = angleShift + 2 *
M_PI * i / edges2;
246 minorRadius * cos(ang), minorRadius * sin(ang), height);
252 size_t iq = isRotated ? 1 : 2, it = 0;
253 for (
size_t i = 0; i < edges2; i++)
256 size_t iiq = (iq + 1) % numBaseEdges + base;
257 size_t iiiq = (iiq + 1) % numBaseEdges + base;
258 size_t iit = (it + 1) % edges2 + minorBase;
266 iq = (iq + 2) % numBaseEdges;
267 it = (it + 1) % edges2;
268 faces.push_back(tri);
269 faces.push_back(quad);
271 if (edges2 >= 3) faces.push_back(cBase);
274 double angleShift,
double baseRadius,
bool isRotated,
bool isUpwards,
275 size_t base, vector<TPoint3D>& verts,
276 vector<CPolyhedron::TPolyhedronFace>& faces)
278 double R1 = baseRadius * sqrt((5.0 - sqrt(5.0)) / 10.0);
279 double R2 = baseRadius * sqrt((5.0 + sqrt(5.0)) / 10.0);
280 double baseHeight = verts[base].z;
282 angleShift +=
M_PI / 10;
283 if (isRotated) angleShift +=
M_PI / 5;
284 for (
size_t i = 0; i < 5; i++)
286 double a = (i + i + 1) *
M_PI / 5 + angleShift;
287 double b = (i + i) *
M_PI / 5 + angleShift;
288 double ca = cos(a), sa = sin(a), cb = cos(b), sb = sin(b);
291 p1[i].
z = baseHeight + (isUpwards ? R2 : -R2);
294 p2[i].
z = baseHeight + (isUpwards ? R1 : -R1);
296 size_t newBase = verts.size();
297 for (
const auto& i : p1) verts.push_back(i);
298 for (
const auto& i : p2) verts.push_back(i);
302 size_t baseStart = isRotated ? 2 : 1;
303 for (
size_t i = 0; i < 5; i++)
305 size_t ii = (i + 1) % 5;
311 f.
vertices[1] = ((i + i + baseStart) % 10) + base;
312 f.
vertices[2] = ((i + i + 9 + baseStart) % 10) + base;
314 g.
vertices[0] = newBase + (ii % 5) + 5;
317 g.
vertices[3] = (i + i + baseStart) % 10 + base;
318 g.
vertices[4] = (i + i + baseStart + 1) % 10 + base;
321 for (
size_t i = 0; i < 5; i++) g.
vertices[i] = i + newBase;
332 return numBaseEdges + ((numBaseEdges >= 6) ? 1 : 0);
336 return numBaseEdges << 1;
346 for (
unsigned int vertice : f.
vertices)
347 if (vertice == e.
v1 || vertice == e.
v2) hm++;
353 if (planes.size() < 3)
return false;
358 for (
size_t i = 1; i < planes.size(); i++)
switch (o)
361 if (!
intersect(pl, *planes[i], obj))
return false;
372 if (!
intersect(l, *planes[i], obj))
return false;
381 if (!planes[i]->contains(pnt))
return false;
390 const vector<CPolyhedron::TPolyhedronFace>& fs, uint32_t v1, uint32_t v2,
393 for (
const auto& it : fs)
395 const vector<uint32_t>& f = it.vertices;
397 for (
unsigned int it2 : f)
406 if (hmf == 7)
return true;
411 const vector<CPolyhedron::TPolyhedronEdge>& es, uint32_t v1, uint32_t v2,
414 for (where = 0; where < es.size(); where++)
417 if (e.
v1 == v1 && e.
v2 == v2)
419 else if (e.
v1 == v2 && e.
v2 == v1)
422 throw std::logic_error(
"Internal error. Edge not found");
425 const vector<CPolyhedron::TPolyhedronFace>::const_iterator&
begin,
426 const vector<CPolyhedron::TPolyhedronFace>::const_iterator&
end,
427 uint32_t v1, uint32_t v2)
429 for (vector<CPolyhedron::TPolyhedronFace>::const_iterator it =
begin;
432 const vector<uint32_t>& f = it->vertices;
434 for (
unsigned int it2 : f)
439 if (res == 3)
return true;
447 throw std::logic_error(
"Faces must have exactly 3, 4 or 5 vertices.");
450 for (
size_t i = 1; i < N; i++)
453 throw std::logic_error(
"There is a non-regular polygon.");
457 throw std::logic_error(
"There is a non-regular polygon.");
469 double CPolyhedron::TPolyhedronEdge::length(
470 const vector<TPoint3D>& vertices)
const 475 double CPolyhedron::TPolyhedronFace::area(
const vector<TPoint3D>& vs)
const 478 size_t N = vertices.size();
479 vector<SegmentVector> d(N - 1);
480 for (
size_t i = 1; i < N; i++)
483 for (
size_t j = 0; j < 3; j++)
485 d[i - 1][j] = vs[vertices[i]][j] - vs[vertices[0]][j];
486 d[i - 1].mod +=
square(d[i - 1][j]);
488 d[i - 1].mod = sqrt(d[i - 1].mod);
491 for (
size_t i = 1; i < N - 1; i++)
493 square(d[i - 1].mod * d[i].mod) -
494 square(dotProduct<3, double>(d[i - 1], d[i])));
498 void CPolyhedron::TPolyhedronFace::getCenter(
499 const vector<TPoint3D>& vrts,
TPoint3D& p)
const 501 p.
x = p.
y = p.
z = 0.0;
502 for (
unsigned int vertice : vertices)
504 p.
x += vrts[vertice].x;
505 p.
y += vrts[vertice].y;
506 p.
z += vrts[vertice].z;
508 size_t N = vertices.size();
514 CPolyhedron::CPolyhedron(
const std::vector<math::TPolygon3D>& polys)
515 : m_Edges(), m_Wireframe(false), polygonsUpToDate(false)
517 std::vector<TPoint3D> vertices(0);
518 std::vector<TPolyhedronFace> faces;
520 throw std::logic_error(
"Can't create CPolygon");
528 const vector<TPoint3D>& vertices,
const vector<vector<uint32_t>>& faces)
530 vector<TPolyhedronFace> aux;
531 for (
const auto& face : faces)
541 double x1,
double x2,
double y1,
double y2,
double z1,
double z2)
543 vector<TPoint3D> verts;
544 vector<TPolyhedronFace> faces;
545 for (
int i = 0; i < 8; i++)
547 (i & 1) ? x2 : x1, (i & 2) ? y2 : y1, (i & 4) ? z2 : z1);
548 static uint32_t faceVertices[] = {0, 1, 5, 4, 2, 3, 7, 6, 0, 2, 6, 4,
549 1, 3, 7, 5, 0, 1, 3, 2, 4, 5, 7, 6};
551 for (
auto* p = reinterpret_cast<uint32_t*>(&faceVertices);
552 p < 24 + reinterpret_cast<uint32_t*>(&faceVertices); p += 4)
562 const vector<TPoint2D>& baseVertices,
double height)
564 uint32_t n = baseVertices.size();
565 if (baseVertices.size() < 3)
throw std::logic_error(
"Not enough vertices");
566 vector<TPoint3D> verts;
567 vector<TPolyhedronFace> faces;
568 verts.emplace_back(0, 0, height);
569 for (
auto baseVertice : baseVertices)
570 verts.emplace_back(baseVertice.x, baseVertice.y, 0);
577 for (uint32_t i = 2; i <= n; i++)
589 const vector<TPoint2D>& baseVertices,
double height1,
double height2)
591 uint32_t N = baseVertices.size();
592 if (N < 3)
throw std::logic_error(
"Not enough vertices");
593 vector<TPoint3D> verts;
594 verts.reserve(N + 2);
595 vector<TPolyhedronFace> faces;
596 faces.reserve(N << 1);
597 verts.emplace_back(0, 0, height1);
598 for (
auto baseVertice : baseVertices)
599 verts.emplace_back(baseVertice.x, baseVertice.y, 0);
600 verts.emplace_back(0, 0, -height2);
606 for (uint32_t i = 1; i < N; i++)
620 const vector<TPoint2D>& baseVertices,
double height,
double ratio)
622 uint32_t n = baseVertices.size();
623 if (n < 3)
throw std::logic_error(
"Not enough vertices");
624 vector<TPoint3D> verts(n + n);
625 vector<TPolyhedronFace> faces(n + 2);
630 for (uint32_t i = 0; i < n; i++)
632 verts[i] =
TPoint3D(baseVertices[i].x, baseVertices[i].y, 0);
634 baseVertices[i].x * ratio, baseVertices[i].y * ratio, height);
635 uint32_t ii = (i + 1) % n;
650 const vector<TPoint2D>& bottomBase,
const vector<TPoint2D>& topBase,
653 uint32_t n = bottomBase.size();
654 if (n < 3)
throw std::logic_error(
"Not enough vertices");
655 if (n != topBase.size())
656 throw std::logic_error(
"Bases' number of vertices do not match");
657 vector<TPoint3D> verts(n + n);
658 vector<TPolyhedronFace> faces(n + n + 2);
663 for (uint32_t i = 0; i < n; i++)
665 verts[i] =
TPoint3D(bottomBase[i].x, bottomBase[i].y, 0);
666 verts[n + i] =
TPoint3D(topBase[i].x, topBase[i].y, height);
667 uint32_t ii = (i + 1) % n;
680 faces[n + n + 1] = h;
688 vector<TPoint3D> verts(8);
689 vector<TPolyhedronFace> faces(6);
690 for (uint32_t i = 0; i < 8; i++)
693 if (i & 1) verts[i] = verts[i] + v1;
694 if (i & 2) verts[i] = verts[i] + v2;
695 if (i & 4) verts[i] = verts[i] + v3;
714 for (uint32_t i = 0; i < 3; i++)
716 uint32_t valueAdd = 4 >> i;
717 faces[i + 3].vertices.resize(4);
718 for (uint32_t j = 0; j < 4; j++)
719 faces[i + 3].vertices[j] = faces[i].vertices[j] + valueAdd;
725 const vector<TPoint2D>& baseVertices,
double height1,
double ratio1,
726 double height2,
double ratio2)
729 size_t N = baseVertices.size();
730 vector<TPoint3D> verts(3 * N);
732 for (
size_t i = 0; i < N; i++)
734 double x = baseVertices[i].x;
735 double y = baseVertices[i].y;
739 verts[i + N].x = x * ratio1;
740 verts[i + N].y = y * ratio1;
741 verts[i + N].z = height1;
742 verts[i + N2].x = x * ratio2;
743 verts[i + N2].y = y * ratio2;
744 verts[i + N2].z = -height2;
748 vector<TPolyhedronFace> faces(N2 + 2);
753 for (
size_t i = 0; i < N; i++)
755 size_t i2 = (i + 1) % N;
773 uint32_t numBaseEdges,
double baseRadius,
double basesDistance)
775 if (numBaseEdges < 3)
throw std::logic_error(
"Not enough vertices");
776 if (basesDistance == 0 || baseRadius == 0)
return CreateEmpty();
777 size_t numBaseEdges2 = numBaseEdges << 1;
778 vector<TPoint3D> verts(numBaseEdges2 + 2);
779 double space = 2 *
M_PI / numBaseEdges;
780 double shift = space / 2;
781 double height1 = basesDistance / 2;
782 double cospii = cos(
M_PI / numBaseEdges);
784 height1 * (cospii + 1) /
786 for (
size_t i = 0; i < numBaseEdges; i++)
788 double ang = space * i;
789 double ang2 = ang + shift;
790 size_t ii = i + numBaseEdges;
791 verts[i].x = baseRadius * cos(ang);
792 verts[i].y = baseRadius * sin(ang);
793 verts[i].z = -height1;
794 verts[ii].x = baseRadius * cos(ang2);
795 verts[ii].y = baseRadius * sin(ang2);
796 verts[ii].z = height1;
798 verts[numBaseEdges2].x = 0;
799 verts[numBaseEdges2].y = 0;
800 verts[numBaseEdges2].z = -height2;
801 verts[numBaseEdges2 + 1].x = 0;
802 verts[numBaseEdges2 + 1].y = 0;
803 verts[numBaseEdges2 + 1].z = height2;
804 vector<TPolyhedronFace> faces(numBaseEdges2);
810 for (
size_t i = 0; i < numBaseEdges; i++)
812 size_t ii = (i + 1) % numBaseEdges;
813 size_t i2 = i + numBaseEdges;
821 faces[i + numBaseEdges] = g;
827 uint32_t numBaseEdges,
double baseRadius,
const std::string& components,
831 if (numBaseEdges < 3)
throw std::logic_error(
"Not enough vertices");
832 vector<JohnsonBodyPart> parts;
834 throw std::logic_error(
"Invalid string");
836 size_t nParts = parts.size();
837 double edgeLength = 2 * baseRadius * sin(
M_PI / numBaseEdges);
838 double antiPrism_height = sqrt(
840 square(baseRadius) * (2 - 2 * cos(
M_PI / numBaseEdges)));
842 size_t nVerts = numBaseEdges * (nParts - 1) +
846 for (
size_t i = 0; i < nParts; i++)
848 vector<TPoint3D> verts;
849 verts.reserve(nVerts);
850 vector<TPolyhedronFace> faces;
851 faces.reserve(nFaces);
854 double h, m_height = 0;
855 vector<pair<double, size_t>> basePositionInfo(nParts - 1);
856 for (
size_t i = 0; i < nParts - 1; i++)
858 if (parts[i] ==
PRISM)
862 h = antiPrism_height;
867 basePositionInfo[i] = make_pair(m_height += h, shifts);
870 double semi =
M_PI / numBaseEdges;
872 for (
auto it = basePositionInfo.begin(); it != basePositionInfo.end(); ++it)
874 numBaseEdges, baseRadius, it->first - m_height, semi * it->second,
876 size_t initialBase = 0, endBase = 0;
878 face.
vertices.reserve(numBaseEdges);
880 for (
size_t p = 0; p < nParts; p++)
887 for (
size_t i = 0; i < numBaseEdges; i++)
889 faces.push_back(face);
894 for (
size_t i = 0; i < numBaseEdges; i++)
896 faces.push_back(face);
902 baseRadius * sqrt(4 *
square(sin(
M_PI / numBaseEdges)) - 1);
905 face.
vertices[1] = initialBase + numBaseEdges - 1;
909 faces.push_back(face);
912 }
while (face.
vertices[2] < initialBase + numBaseEdges);
913 verts.emplace_back(0, 0, verts[initialBase].z + apexHeight);
920 baseRadius * sqrt(4 *
square(sin(
M_PI / numBaseEdges)) - 1);
923 face.
vertices[1] = endBase + numBaseEdges - 1;
927 faces.push_back(face);
930 }
while (face.
vertices[2] < endBase + numBaseEdges);
931 verts.emplace_back(0, 0, verts[endBase].z - apexHeight);
938 numBaseEdges, basePositionInfo.rbegin()->second * semi,
939 baseRadius, edgeLength,
false,
true, initialBase, verts,
946 numBaseEdges, basePositionInfo[0].second * semi, baseRadius,
947 edgeLength,
false,
false, endBase, verts, faces);
953 numBaseEdges, basePositionInfo.rbegin()->second * semi,
954 baseRadius, edgeLength,
true,
true, initialBase, verts,
961 numBaseEdges, basePositionInfo[0].second * semi, baseRadius,
962 edgeLength,
true,
false, endBase, verts, faces);
967 for (
size_t i = 0; i < numBaseEdges; i++)
969 size_t ii = (i + 1) % numBaseEdges;
973 face.
vertices[3] = initialBase + ii;
974 faces.push_back(face);
984 bool nextIsEnd =
true;
986 size_t nextInitial = 2;
987 for (
size_t i = 0; i < numBaseEdges << 1; i++)
989 faces.push_back(face);
994 face.
vertices[2] = endBase + nextEnd;
995 nextEnd = (nextEnd + 1) % numBaseEdges;
999 face.
vertices[2] = initialBase + nextInitial;
1000 nextInitial = (nextInitial + 1) % numBaseEdges;
1002 nextIsEnd = !nextIsEnd;
1010 basePositionInfo.rbegin()->second * semi, baseRadius,
false,
1011 true, initialBase, verts, faces);
1017 basePositionInfo[0].second * semi, baseRadius,
false,
false,
1018 endBase, verts, faces);
1024 basePositionInfo.rbegin()->second * semi, baseRadius,
true,
1025 true, initialBase, verts, faces);
1031 basePositionInfo[0].second * semi, baseRadius,
true,
false,
1032 endBase, verts, faces);
1035 throw std::logic_error(
"Internal error");
1037 initialBase = endBase;
1038 endBase += numBaseEdges;
1051 lengths.resize(
m_Edges.size());
1052 auto it2 = lengths.begin();
1053 for (
auto it =
m_Edges.begin(); it !=
m_Edges.end(); ++it, ++it2)
1060 auto it2 = areas.begin();
1061 for (
auto it =
m_Faces.begin(); it !=
m_Faces.end(); ++it, ++it2)
1077 vector<double> areas(
m_Faces.size());
1079 auto itA = areas.begin();
1080 for (
auto it =
m_Faces.begin(); it !=
m_Faces.end(); ++it, ++itP, ++itA)
1081 res += std::abs(itP->plane.distance(center)) * (*itA);
1090 for (
size_t i = 0; i < N; i++) vec[i] =
tempPolygons[i].poly;
1094 std::vector<math::TPolygon3D>& vec)
const 1098 vector<TPoint3D> nVerts;
1109 vector<TPolygon3D> polys, polysTMP, polys2;
1111 polys2.reserve(polys.size());
1112 for (
auto it = polys.begin(); it != polys.end(); ++it)
1114 polys2.insert(polys2.end(), polysTMP.begin(), polysTMP.end());
1116 polys2.push_back(*it);
1124 throw std::logic_error(
"Bad face specification");
1132 if (N == 0)
throw new std::logic_error(
"There are no vertices");
1133 center.
x = center.
y = center.
z = 0;
1136 center.
x += mVertice.x;
1137 center.
y += mVertice.y;
1138 center.
z += mVertice.z;
1259 vector<TPlane> planes(NF);
1260 for (
size_t i = 0; i < NF; i++)
1270 vector<TPoint3D> vertices(NV);
1271 for (
size_t i = 0; i < NV; i++)
1273 for (
size_t j = 0; j < NF; j++) incidence(i, j) =
false;
1274 vector<const TPlane*> fPls;
1275 fPls.reserve(
m_Faces[i].vertices.size());
1276 for (
auto it =
m_Faces[i].vertices.begin();
1277 it !=
m_Faces[i].vertices.end(); ++it)
1279 incidence(i, *it) =
true;
1280 fPls.push_back(&planes[*it]);
1283 throw std::logic_error(
"Dual polyhedron cannot be found");
1285 vector<TPolyhedronFace> faces(NF);
1286 for (
size_t i = 0; i < NF; i++)
1287 for (
size_t j = 0; j < NV; j++)
1288 if (incidence(j, i)) faces[i].vertices.push_back(j);
1292 for (
size_t i = 0; i < NE; i++)
1293 for (
size_t j = 0; j < NV; j++)
1295 for (
auto& it : faces)
1297 vector<uint32_t>& face = it.vertices;
1298 if (face.size() <= 3)
continue;
1300 while (index < face.size() - 1)
1305 for (
size_t i = 0; i < NE; i++)
1306 if (arrayEF(i, face[index]) && arrayEF(i, face[index + 1]))
1313 size_t val = face[index + 1];
1314 face.erase(face.begin() + index + 1);
1315 face.push_back(
val);
1321 return std::make_shared<CPolyhedron>(vertices, faces);
1329 else if (factor < 1)
1334 vector<TPoint3D> vertices(NE << 1);
1335 vector<TPolyhedronFace> faces(NV + NF);
1336 for (
size_t i = 0; i < NE; i++)
1341 TPoint3D& v2 = vertices[i + i + 1];
1342 for (
size_t j = 0; j < 3; j++)
1344 double d = (p2[j] - p1[j]) * factor / 2;
1348 faces[
m_Edges[i].v1].vertices.push_back(i + i);
1349 faces[
m_Edges[i].v2].vertices.push_back(i + i + 1);
1351 for (
size_t i = 0; i < NV; i++)
1353 vector<uint32_t>& f = faces[i].vertices;
1354 size_t sf = f.size();
1355 if (sf == 3)
continue;
1356 for (
size_t j = 1; j < sf - 1; j++)
1362 if (!((e1.
v1 == i || e1.
v2 == i) &&
1363 (e2.
v1 == i || e2.
v2 == i)))
1367 (e2.
v1 == i) ? e2.
v2 : e2.
v1))
1369 uint32_t tmpV = f[j];
1370 f.erase(f.begin() + j);
1375 for (
size_t i = 0; i < NF; i++)
1377 vector<uint32_t>& f = faces[i + NV].vertices;
1378 const vector<uint32_t>& cf =
m_Faces[i].vertices;
1379 size_t hmV = cf.size();
1380 f.reserve(hmV << 1);
1381 for (
size_t j = 0; j < hmV; j++)
1386 f.push_back(where << 1);
1387 f.push_back((where << 1) + 1);
1391 f.push_back((where << 1) + 1);
1392 f.push_back(where << 1);
1396 return std::make_shared<CPolyhedron>(vertices, faces);
1398 else if (factor == 1)
1403 vector<TPoint3D> vertices(NE);
1404 vector<TPolyhedronFace> faces(NV + NF);
1405 for (
size_t i = 0; i < NE; i++)
1410 for (
size_t j = 0; j < 3; j++) dst[j] = (p1[j] + p2[j]) / 2;
1411 faces[
m_Edges[i].v1].vertices.push_back(i);
1412 faces[
m_Edges[i].v2].vertices.push_back(i);
1414 for (
size_t i = 0; i < NV; i++)
1416 vector<uint32_t>& f = faces[i].vertices;
1417 size_t sf = f.size();
1418 if (sf == 3)
continue;
1419 for (
size_t j = 1; j < sf - 1; j++)
1425 if (!((e1.
v1 == i || e1.
v2 == i) &&
1426 (e2.
v1 == 1 || e2.
v2 == i)))
1430 (e2.
v1 == i) ? e2.
v2 : e2.
v1))
1432 uint32_t tmpV = f[j];
1433 f.erase(f.begin() + j);
1438 for (
size_t i = 0; i < NF; i++)
1440 vector<uint32_t>& f = faces[i + NV].vertices;
1441 const vector<uint32_t>& cf =
m_Faces[i].vertices;
1442 size_t hmV = cf.size();
1444 for (
size_t j = 0; j < hmV; j++)
1451 return std::make_shared<CPolyhedron>(vertices, faces);
1461 else if (factor == 0)
1466 vector<TPolygon3D> origFaces(NF);
1470 vector<TPoint3D> polyCenters(NF);
1471 vector<TPoint3D> polyNewCenters(NF);
1473 for (
size_t i = 0; i < NF; i++)
1475 origFaces[i].getCenter(polyCenters[i]);
1476 polyCenters[i] -= cnt;
1477 polyNewCenters[i] = polyCenters[i];
1478 polyNewCenters[i] *= (1 + factor);
1479 polyNewCenters[i] += cnt;
1480 NNV += origFaces[i].size();
1482 vector<TPoint3D> vertices(NNV);
1483 vector<TPolyhedronFace> faces(NF + NV + NE);
1485 for (
size_t i = 0; i < NF; i++)
1487 const TPoint3D& oC = polyCenters[i];
1488 const TPoint3D& nC = polyNewCenters[i];
1490 vector<uint32_t>& f = faces[i].vertices;
1491 size_t oPS = oP.size();
1492 for (
size_t j = 0; j < oPS; j++)
1494 vertices[j + ind] = nC + (oP[j] - oC);
1495 f.push_back(j + ind);
1496 size_t curr =
m_Faces[i].vertices[j];
1497 faces[NF + curr].vertices.push_back(j + ind);
1501 faces[NF + NV + edge].vertices.push_back(j + ind);
1504 faces[NF + NV + edge].vertices.push_back(j + ind);
1508 auto begin = faces.begin(), edgeBegin = faces.begin() + NF + NV,
1510 for (
auto it = faces.begin() + NF; it != faces.begin() + NF + NV; ++it)
1512 vector<uint32_t>& f = it->vertices;
1513 if (f.size() == 3)
continue;
1514 for (
size_t i = 1; i < f.size() - 1; i++)
1520 uint32_t tmp = f[i];
1521 f.erase(f.begin() + i);
1525 for (
auto it = faces.begin() + NF + NV; it != faces.end(); ++it)
1527 vector<uint32_t>& f =
1529 for (
size_t i = 1; i < 3; i++)
1535 uint32_t tmp = f[i];
1536 f.erase(f.begin() + i);
1540 return std::make_shared<CPolyhedron>(vertices, faces);
1547 vector<TPoint3D> vertices(NV + NF);
1550 for (
const auto& mFace :
m_Faces) tnf += mFace.vertices.size();
1551 vector<TPolyhedronFace> faces(tnf);
1560 for (
size_t i = 0; i < NF; i++)
1562 TPoint3D& vertex = vertices[NV + i];
1563 const vector<uint32_t>& face =
m_Faces[i].vertices;
1564 size_t N = face.size();
1566 for (
size_t j = 0; j < N; j++) tmp[j] =
m_Vertices[face[j]];
1571 for (
size_t j = 0; j < 3; j++)
1572 vertex[j] = cTmp[j] - height * pTmp.
coefs[j];
1574 for (
size_t j = 0; j < 3; j++)
1575 vertex[j] = cTmp[j] + height * pTmp.
coefs[j];
1577 for (
size_t j = 0; j < N; j++)
1580 fTmp.
vertices[2] = face[(j + 1) % N];
1581 faces[iF + j] = fTmp;
1594 for (
const auto& mFace :
m_Faces)
1595 if (mFace.vertices.size() == numVertices)
1603 vector<TPoint3D> vertices(tnv);
1605 vector<TPolyhedronFace> faces(tnf);
1615 for (
size_t i = 0; i < NF; i++)
1617 const vector<uint32_t>& face =
m_Faces[i].vertices;
1618 size_t N = face.size();
1619 if (N != numVertices)
1621 faces[iF].vertices = face;
1626 for (
size_t j = 0; j < numVertices; j++) tmp[j] =
m_Vertices[face[j]];
1631 for (
size_t j = 0; j < 3; j++)
1632 vertex[j] = cTmp[j] - height * pTmp.
coefs[j];
1634 for (
size_t j = 0; j < 3; j++)
1635 vertex[j] = cTmp[j] + height * pTmp.
coefs[j];
1637 for (
size_t j = 0; j < N; j++)
1640 fTmp.
vertices[2] = face[(j + 1) % N];
1641 faces[iF + j] = fTmp;
1653 vector<TPoint3D> vertices(NV + NF);
1656 for (
const auto& mFace :
m_Faces) tnf += mFace.vertices.size();
1657 vector<TPolyhedronFace> faces(tnf);
1666 for (
size_t i = 0; i < NF; i++)
1668 TPoint3D& vertex = vertices[NV + i];
1669 const vector<uint32_t>& face =
m_Faces[i].vertices;
1670 size_t N = face.size();
1672 for (
size_t j = 0; j < N; j++) tmp[j] =
m_Vertices[face[j]];
1678 for (
size_t j = 0; j < 3; j++)
1679 vertex[j] = cTmp[j] - height * pTmp.
coefs[j];
1681 for (
size_t j = 0; j < 3; j++)
1682 vertex[j] = cTmp[j] + height * pTmp.
coefs[j];
1684 for (
size_t j = 0; j < N; j++)
1687 fTmp.
vertices[2] = face[(j + 1) % N];
1688 faces[iF + j] = fTmp;
1701 for (
const auto& mFace :
m_Faces)
1702 if (mFace.vertices.size() == numVertices)
1710 vector<TPoint3D> vertices(tnv);
1712 vector<TPolyhedronFace> faces(tnf);
1722 for (
size_t i = 0; i < NF; i++)
1724 const vector<uint32_t>& face =
m_Faces[i].vertices;
1725 size_t N = face.size();
1726 if (N != numVertices)
1728 faces[iF].vertices = face;
1733 for (
size_t j = 0; j < numVertices; j++) tmp[j] =
m_Vertices[face[j]];
1739 for (
size_t j = 0; j < 3; j++)
1740 vertex[j] = cTmp[j] - height * pTmp.
coefs[j];
1742 for (
size_t j = 0; j < 3; j++)
1743 vertex[j] = cTmp[j] + height * pTmp.
coefs[j];
1745 for (
size_t j = 0; j < N; j++)
1748 fTmp.
vertices[2] = face[(j + 1) % N];
1749 faces[iF + j] = fTmp;
1760 double c = cos(angle), s = sin(angle);
1761 for (
auto& vertice : vertices)
1763 double A = vertice.
x;
1764 double B = vertice.y;
1765 vertice.x =
A * c - B * s;
1766 vertice.y = B * c +
A * s;
1775 throw std::logic_error(
"Factor must be a strictly positive number");
1776 for (
auto& vertice : vertices)
1778 vertice.x *= factor;
1779 vertice.y *= factor;
1785 uint32_t numBaseEdges,
double baseRadius)
1787 vector<TPoint2D> base(numBaseEdges);
1788 for (
size_t i = 0; i < numBaseEdges; i++)
1790 double ang = 2 *
M_PI * i / numBaseEdges;
1791 base[i].x = baseRadius * cos(ang);
1792 base[i].y = baseRadius * sin(ang);
1798 uint32_t numBaseEdges,
double baseRadius)
1800 vector<TPoint2D> base(numBaseEdges);
1801 double shift =
M_PI / numBaseEdges;
1802 for (
size_t i = 0; i < numBaseEdges; i++)
1804 double ang = shift + 2 *
M_PI * i / numBaseEdges;
1805 base[i].x = baseRadius * cos(ang);
1806 base[i].y = baseRadius * sin(ang);
1812 uint32_t numBaseEdges,
double baseRadius,
double height,
1813 vector<TPoint3D>& vec)
1815 for (
size_t i = 0; i < numBaseEdges; i++)
1817 double ang = 2 *
M_PI * i / numBaseEdges;
1818 vec.emplace_back(baseRadius * cos(ang), baseRadius * sin(ang), height);
1823 uint32_t numBaseEdges,
double baseRadius,
double height,
double shift,
1824 vector<TPoint3D>& vec)
1826 for (
size_t i = 0; i < numBaseEdges; i++)
1828 double ang = 2 *
M_PI * i / numBaseEdges + shift;
1829 vec.emplace_back(baseRadius * cos(ang), baseRadius * sin(ang), height);
1844 size_t N = doCheck ? f.
vertices.size() : 3;
1848 if (!poly.
getPlane(tmp))
return false;
1849 f.
normal = tmp.getNormalVector();
1852 if (tmp.evaluatePoint(c) > 0) f.
normal *= -1;
1876 const vector<TPoint3D>& vertices,
const vector<TPolyhedronFace>& faces)
1878 size_t N = vertices.size();
1879 if (vertices.size() > 0)
1880 for (
auto it = vertices.begin(); it != vertices.end() - 1; ++it)
1881 for (
auto it2 = it + 1; it2 != vertices.end(); ++it2)
1882 if (*it == *it2)
return false;
1883 for (
const auto& face : faces)
1885 const vector<uint32_t>& e = face.vertices;
1886 for (
unsigned int it2 : e)
1887 if (it2 >= N)
return false;
1895 for (
const auto& mEdge :
m_Edges)
1896 if (mEdge.v1 == vertex || mEdge.v2 == vertex) res++;
1903 for (
const auto& mFace :
m_Faces)
1904 if (
find(mFace.vertices.begin(), mFace.vertices.end(), vertex) !=
1905 mFace.vertices.end())
1955 throw std::logic_error(
"Inconsistent data read from stream");
1959 throw std::logic_error(
"Bad face specification");
2026 for (
auto& mVertice : tetra->m_Vertices) mVertice.z -= radius / 3;
2032 double r = radius / sqrt(3.0);
2045 double ang =
M_PI / 5;
2046 double s2 = 4 *
square(sin(ang));
2047 double prop = sqrt(s2 - 1) + sqrt(s2 - 2 + 2 * cos(ang)) / 2;
2061 ->truncate(2 - sqrt(2.0));
2068 double radius,
bool type)
2072 type ?
"C-PRC+" :
"GC-PRC+", 3);
2077 10, radius, type ?
"GR-R+" :
"R-R+", 1);
2082 ->truncate(1 - sqrt(0.2));
2087 ->truncate(2.0 / 3.0);
2092 ->cantellate(1.5 * (sqrt(5.0) - 1));
2145 const vector<TPoint2D>& baseVertices,
double height,
double ratio)
2150 const vector<TPoint2D>& baseVertices,
double height)
2155 uint32_t numBaseEdges,
double baseRadius,
double height)
2162 uint32_t numBaseEdges,
double baseRadius,
double height)
2167 uint32_t numBaseEdges,
double baseRadius,
double height)
2172 uint32_t numBaseEdges,
double baseRadius,
double height1,
double height2)
2175 generateBase(numBaseEdges, baseRadius), height1, height2);
2178 uint32_t numBaseEdges,
double baseRadius)
2183 uint32_t numBaseEdges,
double baseRadius)
2188 uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio)
2191 generateBase(numBaseEdges, baseRadius), height, ratio);
2194 uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio)
2197 numBaseEdges, baseRadius, height, ratio);
2200 uint32_t numBaseEdges,
double baseRadius,
double height1,
double ratio1,
2201 double height2,
double ratio2)
2204 generateBase(numBaseEdges, baseRadius), height1, ratio1, height2,
2208 uint32_t numBaseEdges,
double edgeLength)
2211 numBaseEdges, edgeLength / (2 * sin(
M_PI / numBaseEdges)),
"C+");
2214 uint32_t numBaseEdges,
double height)
2219 uint32_t numBaseEdges,
double height)
2225 const vector<TPoint3D>& vertices,
const vector<TPolyhedronFace>& faces)
2255 for (
const auto& edge :
m_Edges)
2261 cbd.assign(vbd.size(),
m_color);
2269 for (
const auto& face :
m_Faces)
2271 const size_t N = face.vertices.size();
2272 if (N < 3)
continue;
2275 for (
size_t i = 0; i < N - 2; i++)
2277 const size_t ip0 = 0;
2278 const size_t ip1 = (i + 1) % N;
2279 const size_t ip2 = (i + 2) % N;
2287 if (mrpt::math::dotProduct<3, double, TPoint3D, TPoint3D>(
2291 tris.emplace_back(p0, p1, p2);
2296 for (
auto& t : tris) t.setColor(
m_color);
static CPolyhedron::Ptr CreateEmpty()
Creates an empty Polyhedron.
static CPolyhedron::Ptr CreateRhombicuboctahedron(double radius, bool type=true)
Creates a rhombicuboctahedron, with 18 squares and 8 triangles (see http://en.wikipedia.org/wiki/Rhombicuboctahedron), calculated as an elongated square bicupola.
static CPolyhedron::Ptr CreateBifrustum(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height1, double ratio1, double height2, double ratio2)
Creates a bifrustum, or double truncated pyramid, given a base which will lie on the XY plane...
static CPolyhedron::Ptr CreateTrapezohedron(uint32_t numBaseEdges, double baseRadius, double basesDistance)
Creates a trapezohedron, consisting of 2*N kites, where N is the number of edges in the base...
void insertCupola(size_t numBaseEdges, double angleShift, double baseRadius, double edgeLength, bool isRotated, bool isUpwards, size_t base, vector< TPoint3D > &verts, vector< CPolyhedron::TPolyhedronFace > &faces)
static CPolyhedron::Ptr CreateRhombicTriacontahedron(double radius)
Creates a rhombic triacontahedron, dual to the icosidodecahedron.
static CPolyhedron::Ptr CreateIcosidodecahedron(double radius, bool type=true)
Creates an icosidodecahedron, with 12 pentagons and 20 triangles (see http://en.wikipedia.org/wiki/Icosidodecahedron).
void addEdges(const TPolyhedronFace &e)
Adds, to the existing list of edges, each edge in a given face.
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
bool splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components.
size_t facesInVertex(size_t vertex) const
Returns how many faces converge in a given vertex.
void getCenter(TPoint3D &p) const
Get polygon's central point.
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CPolyhedron::TPolyhedronEdge &o)
Reads a polyhedron edge from a binary stream.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
const_iterator find(const KEY &key) const
size_t edgesInVertex(size_t vertex) const
Returns how many edges converge in a given vertex.
#define THROW_EXCEPTION(msg)
double getVolume() const
Gets the polyhedron volume.
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
static std::vector< mrpt::math::TPoint2D > generateShiftedBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon, with an angle shift which makes it su...
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void InitFromVertAndFaces(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces, bool doCheck=true)
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
static CPolyhedron::Ptr CreateCuboctahedron(double radius)
Creates a cuboctahedron, consisting of six square faces and eight triangular ones (see http://en...
void makeConvexPolygons()
Recomputes polygons, if necessary, so that each one is convex.
bool getVerticesAndFaces(const vector< math::TPolygon3D > &polys, vector< TPoint3D > &vertices, vector< CPolyhedron::TPolyhedronFace > &faces)
static CPolyhedron::Ptr CreateTriakisIcosahedron(double radius)
Creates a triakis icosahedron, dual to the truncated dodecahedron.
mrpt::opengl::shader_id_t shader_id
This file implements several operations that operate element-wise on individual or pairs of container...
COpenGLScene::Ptr & operator<<(COpenGLScene::Ptr &s, const CRenderizable::Ptr &r)
Inserts an openGL object into a scene.
The base class of 3D objects that can be directly rendered through OpenGL.
CPolyhedron::Ptr getDual() const
Given a polyhedron, creates its dual.
static CPolyhedron::Ptr CreateCatalanDoublePyramid(uint32_t numBaseEdges, double height)
Creates a double pyramid whose dual is exactly an archimedean prism.
size_t additionalFaces(JohnsonBodyPart j, uint32_t numBaseEdges)
bool m_Wireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges...
bool getPlane(TPlane &p) const
Gets the content as a plane, returning false if the type is not adequate.
mrpt::math::TVector3D normal
Normal vector.
CPolyhedron::Ptr rotate(double angle) const
Rotates a polyhedron around the Z axis a given amount of radians.
Standard object for storing any 3D lightweight object.
static CPolyhedron::Ptr CreateTetrakisHexahedron(double radius)
Creates a tetrakis hexahedron, dual to the truncated octahedron.
static CPolyhedron::Ptr CreateIcosahedron(double radius)
Creates a regular icosahedron (see http://en.wikipedia.org/wiki/Icosahedron).
static CPolyhedron::Ptr CreateRegularPrism(uint32_t numBaseEdges, double baseRadius, double height)
Creates a regular prism whose base is a regular polygon and whose edges are either parallel or perpen...
static CPolyhedron::Ptr CreateArchimedeanRegularAntiprism(uint32_t numBaseEdges, double baseRadius)
Creates a regular antiprism whose lateral polygons are equilateral triangles, and so each face of its...
std::vector< TPolyhedronFace > m_Faces
List of polyhedron's faces.
bool getPlanesIntersection(const vector< const TPlane *> &planes, TPoint3D &pnt)
static CPolyhedron::Ptr CreateCubicPrism(double x1, double x2, double y1, double y2, double z1, double z2)
Creates a cubic prism, given the coordinates of two opposite vertices.
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
std::vector< TPolyhedronEdge > m_Edges
List of polyhedron's edges.
static CPolyhedron::Ptr CreateCupola(uint32_t numBaseEdges, double edgeLength)
Creates a cupola.
This class represents arbitrary polyhedra.
const vector< TPoint3D > & verts
static CPolyhedron::Ptr CreateTriakisTetrahedron(double radius)
Creates a triakis tetrahedron, dual to the truncated tetrahedron.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
Context for calls to render()
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
static CPolyhedron::Ptr CreateJohnsonSolidWithConstantBase(uint32_t numBaseEdges, double baseRadius, const std::string &components, size_t shifts=0)
Creates a series of concatenated solids (most of which are prismatoids) whose base is a regular polyg...
CPolyhedron::Ptr cantellate(double factor) const
Cantellates a polyhedron to a given factor.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
static CPolyhedron::Ptr CreateTetrahedron(double radius)
Creates a regular tetrahedron (see http://en.wikipedia.org/wiki/Tetrahedron).
static CPolyhedron::Ptr CreateCatalanTrapezohedron(uint32_t numBaseEdges, double height)
Creates a trapezohedron whose dual is exactly an archimedean antiprism.
static CPolyhedron::Ptr CreateTruncatedPyramid(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height, double ratio)
Creates a truncated pyramid, using a set of vertices which will lie on the XY plane.
static CPolyhedron::Ptr CreateTruncatedDodecahedron(double radius)
Creates a truncated dodecahedron, consisting of 12 dodecagons and 20 triangles (see http://en...
std::vector< uint32_t > vertices
Vector of indices to the vertex list.
This base provides a set of functions for maths stuff.
std::vector< mrpt::math::TPolygonWithPlane > tempPolygons
Mutable list of actual polygons, maintained for speed.
static CPolyhedron::Ptr CreateRandomPolyhedron(double radius)
Creates a random polyhedron from the static methods.
double evaluatePoint(const TPoint3D &point) const
Evaluate a point in the plane's equation.
static CPolyhedron::Ptr CreateFrustum(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height, double ratio)
This is a synonym for CreateTruncatedPyramid.
void writeToStreamRender(mrpt::serialization::CArchive &out) const
static CPolyhedron::Ptr CreateRhombicosidodecahedron(double radius)
Creates a rhombicosidodecahedron, consisting of 30 squares, 12 pentagons and 20 triangles (see http:/...
void insertRotunda(double angleShift, double baseRadius, bool isRotated, bool isUpwards, size_t base, vector< TPoint3D > &verts, vector< CPolyhedron::TPolyhedronFace > &faces)
FCreatePolygonFromFace(const vector< TPoint3D > &v)
static CPolyhedron::Ptr CreatePentagonalRotunda(double radius)
Creates a pentagonal rotunda (half an icosidodecahedron), consisting of six pentagons, ten triangles and a decagon (see http://en.wikipedia.org/wiki/Pentagonal_rotunda).
Struct used to store a polyhedron face.
void getSetOfPolygons(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons.
static CPolyhedron::Ptr CreateTruncatedOctahedron(double radius)
Creates a truncated octahedron, with eight hexagons and eight squares (see http://en.wikipedia.org/wiki/Truncated_octahedron).
static constexpr shader_id_t WIREFRAME
static CPolyhedron::Ptr CreatePyramid(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height)
Creates a custom pyramid, using a set of 2D vertices which will lie on the XY plane.
static CPolyhedron::Ptr CreateRegularPyramid(uint32_t numBaseEdges, double baseRadius, double height)
Creates a regular pyramid whose base is a regular polygon.
CPolyhedron()
Basic empty constructor.
Struct used to store a polyhedron edge.
bool searchForEdge(const vector< CPolyhedron::TPolyhedronEdge > &es, uint32_t v1, uint32_t v2, size_t &where)
3D Plane, represented by its equation
static CPolyhedron::Ptr CreateTriakisOctahedron(double radius)
Creates a triakis octahedron, dual to the truncated hexahedron.
static CPolyhedron::Ptr CreateOctahedron(double radius)
Creates a regular octahedron (see http://en.wikipedia.org/wiki/Octahedron).
void unitarize()
Unitarize normal vector.
static std::vector< mrpt::math::TPoint2D > generateBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon.
TPoint3D_< double > TPoint3D
Lightweight 3D point.
void getBestFittingPlane(TPlane &p) const
Gets the best fitting plane, disregarding whether the polygon actually fits inside or not...
static CPolyhedron::Ptr CreateParallelepiped(const mrpt::math::TPoint3D &base, const mrpt::math::TPoint3D &v1, const mrpt::math::TPoint3D &v2, const mrpt::math::TPoint3D &v3)
Creates a parallelepiped, given a base point and three vectors represented as points.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
static Ptr Create(Args &&... args)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
bool getPoint(TPoint3D &p) const
Gets the content as a point, returning false if the type is not adequate.
CPolyhedron::Ptr scale(double factor) const
Scales a polyhedron to a given factor.
static constexpr shader_id_t TRIANGLES
size_t additionalVertices(JohnsonBodyPart j, uint32_t numBaseEdges)
static CPolyhedron::Ptr CreateCustomAntiprism(const std::vector< mrpt::math::TPoint2D > &bottomBase, const std::vector< mrpt::math::TPoint2D > &topBase, double height)
Creates a custom antiprism, using two custom bases.
mrpt::img::TColor m_color
Color components in the range [0,255].
static CPolyhedron::Ptr CreateTruncatedTetrahedron(double radius)
Creates a truncated tetrahedron, consisting of four triangular faces and for hexagonal ones (see http...
return_t square(const num_t x)
Inline function for the square of a number.
static CPolyhedron::Ptr CreateRegularAntiprism(uint32_t numBaseEdges, double baseRadius, double height)
Creates an antiprism whose base is a regular polygon.
const_iterator end() const
std::vector< mrpt::img::TColor > m_color_buffer_data
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool polygonsUpToDate
Whether the set of actual polygons is up to date or not.
bool setNormal(TPolyhedronFace &f, bool doCheck=true)
Calculates the normal vector to a face.
const_iterator begin() const
bool analyzeJohnsonPartsString(const std::string &components, uint32_t numBaseEdges, vector< JohnsonBodyPart > &parts)
Virtual base class for "archives": classes abstracting I/O streams.
void updatePolygons() const
Updates the mutable list of polygons used in rendering and ray tracing.
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
double getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
static CPolyhedron::Ptr CreateRhombicDodecahedron(double radius)
Creates a rhombic dodecahedron, dual to the cuboctahedron.
static CPolyhedron::Ptr CreateRegularDoublePyramid(uint32_t numBaseEdges, double baseRadius, double height1, double height2)
Creates a regular double pyramid whose base is a regular polygon.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
mrpt::vision::TStereoCalibResults out
double & operator[](size_t i)
static CPolyhedron::Ptr CreateRegularBifrustum(uint32_t numBaseEdges, double baseRadius, double height1, double ratio1, double height2, double ratio2)
Creates a bifrustum (double truncated pyramid) whose base is a regular polygon lying in the XY plane...
static CPolyhedron::Ptr CreateNoCheck(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces)
Creates a polyhedron without checking its correctness.
static CPolyhedron::Ptr CreateTruncatedIcosahedron(double radius)
Creates a truncated icosahedron, consisting of 20 hexagons and 12 pentagons.
static CPolyhedron::Ptr CreateDodecahedron(double radius)
Creates a regular dodecahedron (see http://en.wikipedia.org/wiki/Dodecahedron).
The namespace for 3D scene representation and rendering.
static CPolyhedron::Ptr CreateRegularTruncatedPyramid(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
Creates a regular truncated pyramid whose base is a regular polygon.
bool getLine(TLine3D &r) const
Gets the content as a line, returning false if the type is not adequate.
CPolyhedron::Ptr truncate(double factor) const
Truncates a polyhedron to a given factor.
static CPolyhedron::Ptr CreateArchimedeanRegularPrism(uint32_t numBaseEdges, double baseRadius)
Creates a regular prism whose lateral area is comprised of squares, and so each face of its is a regu...
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
void readFromStreamRender(mrpt::serialization::CArchive &in)
static CPolyhedron::Ptr CreateDeltoidalHexecontahedron(double radius)
Creates a deltoidal hexecontahedron, dual to the rhombicosidodecahedron.
static CPolyhedron::Ptr CreateHexahedron(double radius)
Creates a regular cube, also called hexahedron (see http://en.wikipedia.org/wiki/Hexahedron).
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::optional_ref< mrpt::math::CMatrixDouble33 > out_jacobian_df_dpoint=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dpose=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dse3=std::nullopt, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
void getEdgesLength(std::vector< double > &lengths) const
Gets a vector with each edge's length.
static CPolyhedron::Ptr CreateRegularFrustum(uint32_t numBaseEdges, double baseRadius, double height, double ratio)
This is a synonym for CreateRegularTruncatedPyramid.
static bool checkConsistence(const std::vector< mrpt::math::TPoint3D > &vertices, const std::vector< TPolyhedronFace > &faces)
Checks whether a set of faces is suitable for a set of vertices.
T operator()(const CPolyhedron::TPolyhedronFace &f)
double operator[](size_t i) const
void getCenter(mrpt::math::TPoint3D ¢er) const
Gets the center of the polyhedron.
void getFacesArea(std::vector< double > &areas) const
Gets a vector with each face's area.
std::vector< mrpt::math::TPoint3D > m_Vertices
List of vertices presents in the polyhedron.
double getHeight(const TPolygon3D &p, const TPoint3D &c)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
static CPolyhedron::Ptr CreatePentakisDodecahedron(double radius)
Creates a pentakis dodecahedron, dual to the truncated icosahedron.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
std::array< double, 4 > coefs
Plane coefficients, stored as an array: .
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
bool searchForFace(const vector< CPolyhedron::TPolyhedronFace > &fs, uint32_t v1, uint32_t v2, uint32_t v3)
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
bool getPlane(TPlane &p) const
Gets a plane which contains the polygon.
static CPolyhedron::Ptr CreateDeltoidalIcositetrahedron(double radius)
Creates a deltoidal icositetrahedron, dual to the rhombicuboctahedron.
static CPolyhedron::Ptr CreateCustomPrism(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height)
Creates a custom prism with vertical edges, given any base which will lie on the XY plane...
3D polygon, inheriting from std::vector<TPoint3D>
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
static CPolyhedron::Ptr CreateDoublePyramid(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height1, double height2)
Creates a double pyramid, using a set of 2D vertices which will lie on the XY plane.
CPolyhedron::Ptr augment(double height) const
Augments a polyhedron to a given height.
bool faceContainsEdge(const CPolyhedron::TPolyhedronFace &f, const CPolyhedron::TPolyhedronEdge &e)
static CPolyhedron::Ptr CreateTruncatedHexahedron(double radius)
Creates a truncated hexahedron, with six octogonal faces and eight triangular ones (see http://en...
void getSetOfPolygonsAbsolute(std::vector< math::TPolygon3D > &vec) const
Gets the polyhedron as a set of polygons, with the pose transformation already applied.
for(unsigned int i=0;i< NUM_IMGS;i++)
3D line, represented by a base point and a director vector.
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.