46 for (
size_t i = 0; i < f.
vertices.size(); i++)
53 const vector<math::TPolygon3D>& polys, vector<TPoint3D>& vertices,
54 vector<CPolyhedron::TPolyhedronFace>& faces)
56 vertices.reserve(4 * polys.size());
57 faces.reserve(polys.size());
58 for (
const auto& poly : polys)
60 size_t N = poly.size();
61 if (N < 3)
return false;
64 for (
size_t i = 0; i < N; i++)
66 auto it2 =
find(vertices.begin(), vertices.end(), poly[i]);
67 if (it2 == vertices.end())
70 vertices.push_back(poly[i]);
73 f.
vertices[i] = it2 - vertices.begin();
99 vector<JohnsonBodyPart>& parts)
110 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
115 if (numBaseEdges & 1)
return false;
116 if (i == N - 1)
return false;
120 if (i != N - 1)
return false;
121 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
128 if (parts.size() > 0)
return false;
138 if (numBaseEdges != 10)
return false;
139 if (i == N - 1)
return false;
143 if (i != N - 1)
return false;
144 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
151 if (parts.size() > 0)
return false;
161 if (i == N - 1)
return false;
172 if (i == N - 1)
return false;
177 if (numBaseEdges > 5)
return false;
178 if (i != N - 1)
return false;
179 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
183 if (numBaseEdges > 5)
return false;
184 if (i != 1)
return false;
189 if (parts.size() > 0 && (*parts.rbegin() ==
PRISM))
191 if (parts.size() == 0) parts.push_back(
INF_NO_BODY);
192 parts.push_back(
PRISM);
203 if (parts.size() == 0)
return false;
218 return numBaseEdges >> 1;
225 size_t numBaseEdges,
double angleShift,
double baseRadius,
226 double edgeLength,
bool isRotated,
bool isUpwards,
size_t base,
227 vector<TPoint3D>& verts, vector<CPolyhedron::TPolyhedronFace>& faces)
229 size_t edges2 = numBaseEdges >> 1;
231 baseRadius * sin(
M_PI / numBaseEdges) / sin(
M_PI / edges2);
238 baseRadius * cos(
M_PI / numBaseEdges) -
239 minorRadius * cos(
M_PI / edges2)));
240 double height = verts[base].z + (isUpwards ? h : -h);
241 angleShift +=
M_PI / edges2 +
242 (isRotated ? -
M_PI / numBaseEdges :
M_PI / numBaseEdges);
243 size_t minorBase = verts.size();
244 for (
size_t i = 0; i < edges2; i++)
246 double ang = angleShift + 2 *
M_PI * i / edges2;
248 minorRadius * cos(ang), minorRadius * sin(ang),
height);
254 size_t iq = isRotated ? 1 : 2, it = 0;
255 for (
size_t i = 0; i < edges2; i++)
258 size_t iiq = (iq + 1) % numBaseEdges + base;
259 size_t iiiq = (iiq + 1) % numBaseEdges + base;
260 size_t iit = (it + 1) % edges2 + minorBase;
268 iq = (iq + 2) % numBaseEdges;
269 it = (it + 1) % edges2;
270 faces.push_back(tri);
271 faces.push_back(quad);
273 if (edges2 >= 3) faces.push_back(cBase);
276 double angleShift,
double baseRadius,
bool isRotated,
bool isUpwards,
277 size_t base, vector<TPoint3D>& verts,
278 vector<CPolyhedron::TPolyhedronFace>& faces)
280 double R1 = baseRadius * sqrt((5.0 - sqrt(5.0)) / 10.0);
281 double R2 = baseRadius * sqrt((5.0 + sqrt(5.0)) / 10.0);
282 double baseHeight = verts[base].z;
284 angleShift +=
M_PI / 10;
285 if (isRotated) angleShift +=
M_PI / 5;
286 for (
size_t i = 0; i < 5; i++)
288 double a = (i + i + 1) *
M_PI / 5 + angleShift;
289 double b = (i + i) *
M_PI / 5 + angleShift;
290 double ca = cos(
a), sa = sin(
a), cb = cos(
b), sb = sin(
b);
293 p1[i].
z = baseHeight + (isUpwards ? R2 : -R2);
296 p2[i].
z = baseHeight + (isUpwards ? R1 : -R1);
298 size_t newBase = verts.size();
299 for (
const auto& i : p1) verts.push_back(i);
300 for (
const auto& i : p2) verts.push_back(i);
303 g.vertices.resize(5);
304 size_t baseStart = isRotated ? 2 : 1;
305 for (
size_t i = 0; i < 5; i++)
307 size_t ii = (i + 1) % 5;
313 f.
vertices[1] = ((i + i + baseStart) % 10) + base;
314 f.
vertices[2] = ((i + i + 9 + baseStart) % 10) + base;
316 g.vertices[0] = newBase + (ii % 5) + 5;
317 g.vertices[1] = newBase + i;
318 g.vertices[2] = newBase + i + 5;
319 g.vertices[3] = (i + i + baseStart) % 10 + base;
320 g.vertices[4] = (i + i + baseStart + 1) % 10 + base;
323 for (
size_t i = 0; i < 5; i++)
g.vertices[i] = i + newBase;
334 return numBaseEdges + ((numBaseEdges >= 6) ? 1 : 0);
338 return numBaseEdges << 1;
348 for (
unsigned int vertice : f.
vertices)
349 if (vertice == e.
v1 || vertice == e.
v2) hm++;
355 if (planes.size() < 3)
return false;
360 for (
size_t i = 1; i < planes.size(); i++)
switch (o)
364 if (
obj.getPlane(pl))
366 else if (
obj.getLine(l))
368 else if (
obj.getPoint(pnt))
377 else if (
obj.getPoint(pnt))
383 if (!planes[i]->contains(pnt))
return false;
395 for (
const auto& it : fs)
397 const vector<uint32_t>& f = it.vertices;
399 for (
unsigned int it2 : f)
408 if (hmf == 7)
return true;
416 for (where = 0; where < es.size(); where++)
424 throw std::logic_error(
"Internal error. Edge not found");
427 const vector<CPolyhedron::TPolyhedronFace>::const_iterator&
begin,
428 const vector<CPolyhedron::TPolyhedronFace>::const_iterator&
end,
431 for (vector<CPolyhedron::TPolyhedronFace>::const_iterator it =
begin;
434 const vector<uint32_t>& f = it->vertices;
436 for (
unsigned int it2 : f)
441 if (
res == 3)
return true;
449 throw std::logic_error(
"Faces must have exactly 3, 4 or 5 vertices.");
452 for (
size_t i = 1; i < N; i++)
454 throw std::logic_error(
"There is a non-regular polygon.");
458 throw std::logic_error(
"There is a non-regular polygon.");
471 const vector<TPoint3D>& vertices)
const 476 double CPolyhedron::TPolyhedronFace::area(
const vector<TPoint3D>& vs)
const 479 size_t N = vertices.size();
480 vector<SegmentVector> d(N - 1);
481 for (
size_t i = 1; i < N; i++)
484 for (
size_t j = 0; j < 3; j++)
486 d[i - 1][j] = vs[vertices[i]][j] - vs[vertices[0]][j];
487 d[i - 1].mod +=
square(d[i - 1][j]);
489 d[i - 1].mod = sqrt(d[i - 1].mod);
492 for (
size_t i = 1; i < N - 1; i++)
494 square(d[i - 1].mod * d[i].mod) -
495 square(dotProduct<3, double>(d[i - 1], d[i])));
499 void CPolyhedron::TPolyhedronFace::getCenter(
500 const vector<TPoint3D>& vrts,
TPoint3D&
p)
const 502 p.x =
p.y =
p.z = 0.0;
503 for (
unsigned int vertice : vertices)
505 p.x += vrts[vertice].x;
506 p.y += vrts[vertice].y;
507 p.z += vrts[vertice].z;
509 size_t N = vertices.size();
515 CPolyhedron::CPolyhedron(
const std::vector<math::TPolygon3D>& polys)
516 : mEdges(), mWireframe(false), mLineWidth(1), polygonsUpToDate(false)
518 std::vector<TPoint3D> vertices(0);
519 std::vector<TPolyhedronFace> faces;
521 throw std::logic_error(
"Can't create CPolygon");
523 mFaces = std::move(faces);
529 const vector<TPoint3D>& vertices,
const vector<vector<uint32_t>>& faces)
531 vector<TPolyhedronFace> aux;
532 for (
const auto&
face : faces)
542 double x1,
double x2,
double y1,
double y2,
double z1,
double z2)
544 vector<TPoint3D> verts;
545 vector<TPolyhedronFace> faces;
546 for (
int i = 0; i < 8; i++)
548 (i & 1) ? x2 : x1, (i & 2) ? y2 : y1, (i & 4) ? z2 : z1);
549 static uint32_t faceVertices[] = {0, 1, 5, 4, 2, 3, 7, 6, 0, 2, 6, 4,
550 1, 3, 7, 5, 0, 1, 3, 2, 4, 5, 7, 6};
552 for (
auto*
p = reinterpret_cast<uint32_t*>(&faceVertices);
563 const vector<TPoint2D>& baseVertices,
double height)
566 if (baseVertices.size() < 3)
throw std::logic_error(
"Not enought vertices");
567 vector<TPoint3D> verts;
568 vector<TPolyhedronFace> faces;
569 verts.emplace_back(0, 0,
height);
570 for (
auto baseVertice : baseVertices)
571 verts.emplace_back(baseVertice.x, baseVertice.y, 0);
576 g.vertices.push_back(1);
583 g.vertices.push_back(i);
590 const vector<TPoint2D>& baseVertices,
double height1,
double height2)
593 if (N < 3)
throw std::logic_error(
"Not enought vertices");
594 vector<TPoint3D> verts;
595 verts.reserve(N + 2);
596 vector<TPolyhedronFace> faces;
597 faces.reserve(N << 1);
598 verts.emplace_back(0, 0, height1);
599 for (
auto baseVertice : baseVertices)
600 verts.emplace_back(baseVertice.x, baseVertice.y, 0);
601 verts.emplace_back(0, 0, -height2);
604 g.vertices.resize(3);
606 g.vertices[0] = N + 1;
621 const vector<TPoint2D>& baseVertices,
double height,
double ratio)
624 if (
n < 3)
throw std::logic_error(
"Not enough vertices");
625 vector<TPoint3D> verts(
n +
n);
626 vector<TPolyhedronFace> faces(
n + 2);
629 g.vertices.resize(
n);
633 verts[i] =
TPoint3D(baseVertices[i].
x, baseVertices[i].
y, 0);
635 baseVertices[i].
x * ratio, baseVertices[i].
y * ratio,
height);
651 const vector<TPoint2D>& bottomBase,
const vector<TPoint2D>& topBase,
655 if (
n < 3)
throw std::logic_error(
"Not enough vertices");
656 if (
n != topBase.size())
657 throw std::logic_error(
"Bases' number of vertices do not match");
658 vector<TPoint3D> verts(
n +
n);
659 vector<TPolyhedronFace> faces(
n +
n + 2);
662 g.vertices.resize(
n);
666 verts[i] =
TPoint3D(bottomBase[i].
x, bottomBase[i].
y, 0);
681 faces[
n +
n + 1] = h;
689 vector<TPoint3D> verts(8);
690 vector<TPolyhedronFace> faces(6);
694 if (i & 1) verts[i] = verts[i] +
v1;
695 if (i & 2) verts[i] = verts[i] +
v2;
696 if (i & 4) verts[i] = verts[i] +
v3;
718 faces[i + 3].vertices.resize(4);
720 faces[i + 3].vertices[j] = faces[i].vertices[j] + valueAdd;
726 const vector<TPoint2D>& baseVertices,
double height1,
double ratio1,
727 double height2,
double ratio2)
730 size_t N = baseVertices.size();
731 vector<TPoint3D> verts(3 * N);
733 for (
size_t i = 0; i < N; i++)
735 double x = baseVertices[i].x;
736 double y = baseVertices[i].y;
740 verts[i + N].x =
x * ratio1;
741 verts[i + N].y =
y * ratio1;
742 verts[i + N].z = height1;
743 verts[i + N2].x =
x * ratio2;
744 verts[i + N2].y =
y * ratio2;
745 verts[i + N2].z = -height2;
749 vector<TPolyhedronFace> faces(N2 + 2);
752 g.vertices.resize(N);
754 for (
size_t i = 0; i < N; i++)
756 size_t i2 = (i + 1) % N;
774 uint32_t numBaseEdges,
double baseRadius,
double basesDistance)
776 if (numBaseEdges < 3)
throw std::logic_error(
"Not enough vertices");
777 if (basesDistance == 0 || baseRadius == 0)
return CreateEmpty();
778 size_t numBaseEdges2 = numBaseEdges << 1;
779 vector<TPoint3D> verts(numBaseEdges2 + 2);
780 double space = 2 *
M_PI / numBaseEdges;
781 double shift = space / 2;
782 double height1 = basesDistance / 2;
783 double cospii = cos(
M_PI / numBaseEdges);
785 height1 * (cospii + 1) /
787 for (
size_t i = 0; i < numBaseEdges; i++)
789 double ang = space * i;
790 double ang2 = ang + shift;
791 size_t ii = i + numBaseEdges;
792 verts[i].x = baseRadius * cos(ang);
793 verts[i].y = baseRadius * sin(ang);
794 verts[i].z = -height1;
795 verts[ii].x = baseRadius * cos(ang2);
796 verts[ii].y = baseRadius * sin(ang2);
797 verts[ii].z = height1;
799 verts[numBaseEdges2].x = 0;
800 verts[numBaseEdges2].y = 0;
801 verts[numBaseEdges2].z = -height2;
802 verts[numBaseEdges2 + 1].x = 0;
803 verts[numBaseEdges2 + 1].y = 0;
804 verts[numBaseEdges2 + 1].z = height2;
805 vector<TPolyhedronFace> faces(numBaseEdges2);
808 g.vertices.resize(4);
810 g.vertices[3] = numBaseEdges2 + 1;
811 for (
size_t i = 0; i < numBaseEdges; i++)
813 size_t ii = (i + 1) % numBaseEdges;
814 size_t i2 = i + numBaseEdges;
820 g.vertices[2] = ii + numBaseEdges;
822 faces[i + numBaseEdges] =
g;
832 if (numBaseEdges < 3)
throw std::logic_error(
"Not enough vertices");
833 vector<JohnsonBodyPart> parts;
835 throw std::logic_error(
"Invalid string");
837 size_t nParts = parts.size();
838 double edgeLength = 2 * baseRadius * sin(
M_PI / numBaseEdges);
839 double antiPrismHeight = sqrt(
841 square(baseRadius) * (2 - 2 * cos(
M_PI / numBaseEdges)));
843 size_t nVerts = numBaseEdges * (nParts - 1) +
847 for (
size_t i = 0; i < nParts; i++)
849 vector<TPoint3D> verts;
850 verts.reserve(nVerts);
851 vector<TPolyhedronFace> faces;
852 faces.reserve(nFaces);
855 double h, mHeight = 0;
856 vector<pair<double, size_t>> basePositionInfo(nParts - 1);
857 for (
size_t i = 0; i < nParts - 1; i++)
859 if (parts[i] ==
PRISM)
868 basePositionInfo[i] = make_pair(mHeight += h, shifts);
871 double semi =
M_PI / numBaseEdges;
873 for (
auto it = basePositionInfo.begin(); it != basePositionInfo.end(); ++it)
875 numBaseEdges, baseRadius, it->first - mHeight, semi * it->second,
877 size_t initialBase = 0, endBase = 0;
879 face.vertices.reserve(numBaseEdges);
881 for (
size_t p = 0;
p < nParts;
p++)
887 face.vertices.resize(numBaseEdges);
888 for (
size_t i = 0; i < numBaseEdges; i++)
889 face.vertices[i] = endBase + i;
890 faces.push_back(
face);
894 face.vertices.resize(numBaseEdges);
895 for (
size_t i = 0; i < numBaseEdges; i++)
896 face.vertices[i] = initialBase + i;
897 faces.push_back(
face);
903 baseRadius * sqrt(4 *
square(sin(
M_PI / numBaseEdges)) - 1);
904 face.vertices.resize(3);
905 face.vertices[0] = verts.size();
906 face.vertices[1] = initialBase + numBaseEdges - 1;
907 face.vertices[2] = initialBase;
910 faces.push_back(
face);
911 face.vertices[1] =
face.vertices[2];
913 }
while (
face.vertices[2] < initialBase + numBaseEdges);
914 verts.emplace_back(0, 0, verts[initialBase].
z + apexHeight);
921 baseRadius * sqrt(4 *
square(sin(
M_PI / numBaseEdges)) - 1);
922 face.vertices.resize(3);
923 face.vertices[0] = verts.size();
924 face.vertices[1] = endBase + numBaseEdges - 1;
925 face.vertices[2] = endBase;
928 faces.push_back(
face);
929 face.vertices[1] =
face.vertices[2];
931 }
while (
face.vertices[2] < endBase + numBaseEdges);
932 verts.emplace_back(0, 0, verts[endBase].
z - apexHeight);
939 numBaseEdges, basePositionInfo.rbegin()->second * semi,
940 baseRadius, edgeLength,
false,
true, initialBase, verts,
947 numBaseEdges, basePositionInfo[0].second * semi, baseRadius,
948 edgeLength,
false,
false, endBase, verts, faces);
954 numBaseEdges, basePositionInfo.rbegin()->second * semi,
955 baseRadius, edgeLength,
true,
true, initialBase, verts,
962 numBaseEdges, basePositionInfo[0].second * semi, baseRadius,
963 edgeLength,
true,
false, endBase, verts, faces);
967 face.vertices.resize(4);
968 for (
size_t i = 0; i < numBaseEdges; i++)
970 size_t ii = (i + 1) % numBaseEdges;
971 face.vertices[0] = initialBase + i;
972 face.vertices[1] = endBase + i;
973 face.vertices[2] = endBase + ii;
974 face.vertices[3] = initialBase + ii;
975 faces.push_back(
face);
981 face.vertices.resize(3);
982 face.vertices[0] = initialBase;
983 face.vertices[1] = endBase;
984 face.vertices[2] = initialBase + 1;
985 bool nextIsEnd =
true;
987 size_t nextInitial = 2;
988 for (
size_t i = 0; i < numBaseEdges << 1; i++)
990 faces.push_back(
face);
991 face.vertices[0] =
face.vertices[1];
992 face.vertices[1] =
face.vertices[2];
995 face.vertices[2] = endBase + nextEnd;
996 nextEnd = (nextEnd + 1) % numBaseEdges;
1000 face.vertices[2] = initialBase + nextInitial;
1001 nextInitial = (nextInitial + 1) % numBaseEdges;
1003 nextIsEnd = !nextIsEnd;
1011 basePositionInfo.rbegin()->second * semi, baseRadius,
false,
1012 true, initialBase, verts, faces);
1018 basePositionInfo[0].second * semi, baseRadius,
false,
false,
1019 endBase, verts, faces);
1025 basePositionInfo.rbegin()->second * semi, baseRadius,
true,
1026 true, initialBase, verts, faces);
1032 basePositionInfo[0].second * semi, baseRadius,
true,
false,
1033 endBase, verts, faces);
1036 throw std::logic_error(
"Internal error");
1038 initialBase = endBase;
1039 endBase += numBaseEdges;
1050 #if MRPT_HAS_OPENGL_GLUT 1059 for (
const auto& mEdge :
mEdges)
1076 for (
const auto& mFace :
mFaces)
1079 glNormal3f(mFace.normal[0], mFace.normal[1], mFace.normal[2]);
1080 for (
auto it2 = mFace.vertices.begin(); it2 != mFace.vertices.end();
1101 lengths.resize(
mEdges.size());
1102 auto it2 = lengths.begin();
1103 for (
auto it =
mEdges.begin(); it !=
mEdges.end(); ++it, ++it2)
1109 areas.resize(
mFaces.size());
1110 auto it2 = areas.begin();
1111 for (
auto it =
mFaces.begin(); it !=
mFaces.end(); ++it, ++it2)
1127 vector<double> areas(
mFaces.size());
1129 auto itA = areas.begin();
1130 for (
auto it =
mFaces.begin(); it !=
mFaces.end(); ++it, ++itP, ++itA)
1131 res += abs(itP->plane.distance(center)) * (*itA);
1140 for (
size_t i = 0; i < N; i++) vec[i] =
tempPolygons[i].poly;
1144 std::vector<math::TPolygon3D>& vec)
const 1146 vec.resize(
mFaces.size());
1148 vector<TPoint3D> nVerts;
1159 vector<TPolygon3D> polys, polysTMP, polys2;
1161 polys2.reserve(polys.size());
1162 for (
auto it = polys.begin(); it != polys.end(); ++it)
1164 polys2.insert(polys2.end(), polysTMP.begin(), polysTMP.end());
1166 polys2.push_back(*it);
1171 for (
auto& mFace :
mFaces)
1174 throw std::logic_error(
"Bad face specification");
1182 if (N == 0)
throw new std::logic_error(
"There are no vertices");
1183 center.
x = center.
y = center.
z = 0;
1186 center.
x += mVertice.x;
1187 center.
y += mVertice.y;
1188 center.
z += mVertice.z;
1306 size_t NV =
mFaces.size();
1307 size_t NE =
mEdges.size();
1309 vector<TPlane> planes(NF);
1310 for (
size_t i = 0; i < NF; i++)
1320 vector<TPoint3D> vertices(NV);
1321 for (
size_t i = 0; i < NV; i++)
1323 for (
size_t j = 0; j < NF; j++) incidence(i, j) =
false;
1324 vector<const TPlane*> fPls;
1325 fPls.reserve(
mFaces[i].vertices.size());
1326 for (
auto it =
mFaces[i].vertices.begin();
1327 it !=
mFaces[i].vertices.end(); ++it)
1329 incidence(i, *it) =
true;
1330 fPls.push_back(&planes[*it]);
1333 throw std::logic_error(
"Dual polyhedron cannot be found");
1335 vector<TPolyhedronFace> faces(NF);
1336 for (
size_t i = 0; i < NF; i++)
1337 for (
size_t j = 0; j < NV; j++)
1338 if (incidence(j, i)) faces[i].vertices.push_back(j);
1342 for (
size_t i = 0; i < NE; i++)
1343 for (
size_t j = 0; j < NV; j++)
1345 for (
auto& it : faces)
1347 vector<uint32_t>&
face = it.vertices;
1348 if (
face.size() <= 3)
continue;
1355 for (
size_t i = 0; i < NE; i++)
1371 return std::make_shared<CPolyhedron>(vertices, faces);
1379 else if (factor < 1)
1381 size_t NE =
mEdges.size();
1383 size_t NF =
mFaces.size();
1384 vector<TPoint3D> vertices(NE << 1);
1385 vector<TPolyhedronFace> faces(NV + NF);
1386 for (
size_t i = 0; i < NE; i++)
1392 for (
size_t j = 0; j < 3; j++)
1394 double d = (p2[j] - p1[j]) * factor / 2;
1398 faces[
mEdges[i].v1].vertices.push_back(i + i);
1399 faces[
mEdges[i].v2].vertices.push_back(i + i + 1);
1401 for (
size_t i = 0; i < NV; i++)
1403 vector<uint32_t>& f = faces[i].vertices;
1404 size_t sf = f.size();
1405 if (sf == 3)
continue;
1406 for (
size_t j = 1; j < sf - 1; j++)
1412 if (!((e1.
v1 == i || e1.
v2 == i) &&
1413 (e2.
v1 == i || e2.
v2 == i)))
1417 (e2.
v1 == i) ? e2.
v2 : e2.
v1))
1420 f.erase(f.begin() + j);
1425 for (
size_t i = 0; i < NF; i++)
1427 vector<uint32_t>& f = faces[i + NV].vertices;
1428 const vector<uint32_t>& cf =
mFaces[i].vertices;
1429 size_t hmV = cf.size();
1430 f.reserve(hmV << 1);
1431 for (
size_t j = 0; j < hmV; j++)
1436 f.push_back(where << 1);
1437 f.push_back((where << 1) + 1);
1441 f.push_back((where << 1) + 1);
1442 f.push_back(where << 1);
1446 return std::make_shared<CPolyhedron>(vertices, faces);
1448 else if (factor == 1)
1450 size_t NE =
mEdges.size();
1452 size_t NF =
mFaces.size();
1453 vector<TPoint3D> vertices(NE);
1454 vector<TPolyhedronFace> faces(NV + NF);
1455 for (
size_t i = 0; i < NE; i++)
1460 for (
size_t j = 0; j < 3; j++)
dst[j] = (p1[j] + p2[j]) / 2;
1461 faces[
mEdges[i].v1].vertices.push_back(i);
1462 faces[
mEdges[i].v2].vertices.push_back(i);
1464 for (
size_t i = 0; i < NV; i++)
1466 vector<uint32_t>& f = faces[i].vertices;
1467 size_t sf = f.size();
1468 if (sf == 3)
continue;
1469 for (
size_t j = 1; j < sf - 1; j++)
1475 if (!((e1.
v1 == i || e1.
v2 == i) &&
1476 (e2.
v1 == 1 || e2.
v2 == i)))
1480 (e2.
v1 == i) ? e2.
v2 : e2.
v1))
1483 f.erase(f.begin() + j);
1488 for (
size_t i = 0; i < NF; i++)
1490 vector<uint32_t>& f = faces[i + NV].vertices;
1491 const vector<uint32_t>& cf =
mFaces[i].vertices;
1492 size_t hmV = cf.size();
1494 for (
size_t j = 0; j < hmV; j++)
1501 return std::make_shared<CPolyhedron>(vertices, faces);
1511 else if (factor == 0)
1514 size_t NE =
mEdges.size();
1515 size_t NF =
mFaces.size();
1516 vector<TPolygon3D> origFaces(NF);
1520 vector<TPoint3D> polyCenters(NF);
1521 vector<TPoint3D> polyNewCenters(NF);
1523 for (
size_t i = 0; i < NF; i++)
1525 origFaces[i].getCenter(polyCenters[i]);
1526 polyCenters[i] -= cnt;
1527 polyNewCenters[i] = polyCenters[i];
1528 polyNewCenters[i] *= (1 + factor);
1529 polyNewCenters[i] += cnt;
1530 NNV += origFaces[i].size();
1532 vector<TPoint3D> vertices(NNV);
1533 vector<TPolyhedronFace> faces(NF + NV + NE);
1535 for (
size_t i = 0; i < NF; i++)
1537 const TPoint3D& oC = polyCenters[i];
1538 const TPoint3D& nC = polyNewCenters[i];
1540 vector<uint32_t>& f = faces[i].vertices;
1541 size_t oPS = oP.size();
1542 for (
size_t j = 0; j < oPS; j++)
1544 vertices[j + ind] = nC + (oP[j] - oC);
1545 f.push_back(j + ind);
1546 size_t curr =
mFaces[i].vertices[j];
1547 faces[NF + curr].vertices.push_back(j + ind);
1550 mEdges, curr,
mFaces[i].vertices[(j + oPS - 1) % oPS], edge);
1551 faces[NF + NV + edge].vertices.push_back(j + ind);
1553 mEdges, curr,
mFaces[i].vertices[(j + 1) % oPS], edge);
1554 faces[NF + NV + edge].vertices.push_back(j + ind);
1558 auto begin = faces.begin(), edgeBegin = faces.begin() + NF + NV,
1560 for (
auto it = faces.begin() + NF; it != faces.begin() + NF + NV; ++it)
1562 vector<uint32_t>& f = it->vertices;
1563 if (f.size() == 3)
continue;
1564 for (
size_t i = 1; i < f.size() - 1; i++)
1571 f.erase(f.begin() + i);
1575 for (
auto it = faces.begin() + NF + NV; it != faces.end(); ++it)
1577 vector<uint32_t>& f =
1579 for (
size_t i = 1; i < 3; i++)
1586 f.erase(f.begin() + i);
1590 return std::make_shared<CPolyhedron>(vertices, faces);
1596 size_t NF =
mFaces.size();
1597 vector<TPoint3D> vertices(NV + NF);
1600 for (
const auto& mFace :
mFaces) tnf += mFace.vertices.size();
1601 vector<TPolyhedronFace> faces(tnf);
1610 for (
size_t i = 0; i < NF; i++)
1612 TPoint3D& vertex = vertices[NV + i];
1613 const vector<uint32_t>&
face =
mFaces[i].vertices;
1614 size_t N =
face.size();
1621 for (
size_t j = 0; j < 3; j++)
1624 for (
size_t j = 0; j < 3; j++)
1627 for (
size_t j = 0; j < N; j++)
1631 faces[iF + j] = fTmp;
1641 size_t NF =
mFaces.size();
1644 for (
const auto& mFace :
mFaces)
1645 if (mFace.vertices.size() == numVertices)
1653 vector<TPoint3D> vertices(tnv);
1655 vector<TPolyhedronFace> faces(tnf);
1665 for (
size_t i = 0; i < NF; i++)
1667 const vector<uint32_t>&
face =
mFaces[i].vertices;
1668 size_t N =
face.size();
1669 if (N != numVertices)
1671 faces[iF].vertices =
face;
1676 for (
size_t j = 0; j < numVertices; j++) tmp[j] =
mVertices[
face[j]];
1681 for (
size_t j = 0; j < 3; j++)
1684 for (
size_t j = 0; j < 3; j++)
1687 for (
size_t j = 0; j < N; j++)
1691 faces[iF + j] = fTmp;
1702 size_t NF =
mFaces.size();
1703 vector<TPoint3D> vertices(NV + NF);
1706 for (
const auto& mFace :
mFaces) tnf += mFace.vertices.size();
1707 vector<TPolyhedronFace> faces(tnf);
1716 for (
size_t i = 0; i < NF; i++)
1718 TPoint3D& vertex = vertices[NV + i];
1719 const vector<uint32_t>&
face =
mFaces[i].vertices;
1720 size_t N =
face.size();
1728 for (
size_t j = 0; j < 3; j++)
1731 for (
size_t j = 0; j < 3; j++)
1734 for (
size_t j = 0; j < N; j++)
1738 faces[iF + j] = fTmp;
1748 size_t NF =
mFaces.size();
1751 for (
const auto& mFace :
mFaces)
1752 if (mFace.vertices.size() == numVertices)
1760 vector<TPoint3D> vertices(tnv);
1762 vector<TPolyhedronFace> faces(tnf);
1772 for (
size_t i = 0; i < NF; i++)
1774 const vector<uint32_t>&
face =
mFaces[i].vertices;
1775 size_t N =
face.size();
1776 if (N != numVertices)
1778 faces[iF].vertices =
face;
1783 for (
size_t j = 0; j < numVertices; j++) tmp[j] =
mVertices[
face[j]];
1789 for (
size_t j = 0; j < 3; j++)
1792 for (
size_t j = 0; j < 3; j++)
1795 for (
size_t j = 0; j < N; j++)
1799 faces[iF + j] = fTmp;
1810 double c = cos(angle),
s = sin(angle);
1811 for (
auto& vertice : vertices)
1813 double A = vertice.
x;
1814 double B = vertice.y;
1815 vertice.x =
A *
c - B *
s;
1816 vertice.y = B *
c +
A *
s;
1825 throw std::logic_error(
"Factor must be a strictly positive number");
1826 for (
auto& vertice : vertices)
1828 vertice.x *= factor;
1829 vertice.y *= factor;
1835 uint32_t numBaseEdges,
double baseRadius)
1837 vector<TPoint2D> base(numBaseEdges);
1838 for (
size_t i = 0; i < numBaseEdges; i++)
1840 double ang = 2 *
M_PI * i / numBaseEdges;
1841 base[i].x = baseRadius * cos(ang);
1842 base[i].y = baseRadius * sin(ang);
1848 uint32_t numBaseEdges,
double baseRadius)
1850 vector<TPoint2D> base(numBaseEdges);
1851 double shift =
M_PI / numBaseEdges;
1852 for (
size_t i = 0; i < numBaseEdges; i++)
1854 double ang = shift + 2 *
M_PI * i / numBaseEdges;
1855 base[i].x = baseRadius * cos(ang);
1856 base[i].y = baseRadius * sin(ang);
1863 vector<TPoint3D>& vec)
1865 for (
size_t i = 0; i < numBaseEdges; i++)
1867 double ang = 2 *
M_PI * i / numBaseEdges;
1868 vec.emplace_back(baseRadius * cos(ang), baseRadius * sin(ang),
height);
1873 uint32_t numBaseEdges,
double baseRadius,
double height,
double shift,
1874 vector<TPoint3D>& vec)
1876 for (
size_t i = 0; i < numBaseEdges; i++)
1878 double ang = 2 *
M_PI * i / numBaseEdges + shift;
1879 vec.emplace_back(baseRadius * cos(ang), baseRadius * sin(ang),
height);
1894 size_t N = doCheck ? f.
vertices.size() : 3;
1898 if (!poly.
getPlane(tmp))
return false;
1902 if (tmp.evaluatePoint(
c) > 0)
1903 for (
double& i : f.
normal) i = -i;
1927 const vector<TPoint3D>& vertices,
const vector<TPolyhedronFace>& faces)
1929 size_t N = vertices.size();
1930 if (vertices.size() > 0)
1931 for (
auto it = vertices.begin(); it != vertices.end() - 1; ++it)
1932 for (
auto it2 = it + 1; it2 != vertices.end(); ++it2)
1933 if (*it == *it2)
return false;
1934 for (
const auto&
face : faces)
1936 const vector<uint32_t>& e =
face.vertices;
1937 for (
unsigned int it2 : e)
1938 if (it2 >= N)
return false;
1946 for (
const auto& mEdge :
mEdges)
1947 if (mEdge.v1 == vertex || mEdge.v2 == vertex)
res++;
1954 for (
const auto& mFace :
mFaces)
1955 if (
find(mFace.vertices.begin(), mFace.vertices.end(), vertex) !=
1956 mFace.vertices.end())
1971 out << o.
v1 << o.
v2;
2006 throw std::logic_error(
"Inconsistent data read from stream");
2007 for (
auto& mFace :
mFaces)
2010 throw std::logic_error(
"Bad face specification");
2077 for (
auto& mVertice : tetra->mVertices) mVertice.z -= radius / 3;
2083 double r = radius / sqrt(3.0);
2096 double ang =
M_PI / 5;
2097 double s2 = 4 *
square(sin(ang));
2098 double prop = sqrt(s2 - 1) + sqrt(s2 - 2 + 2 * cos(ang)) / 2;
2112 ->truncate(2 - sqrt(2.0));
2119 double radius,
bool type)
2123 type ?
"C-PRC+" :
"GC-PRC+", 3);
2128 10, radius,
type ?
"GR-R+" :
"R-R+", 1);
2133 ->truncate(1 - sqrt(0.2));
2138 ->truncate(2.0 / 3.0);
2143 ->cantellate(1.5 * (sqrt(5.0) - 1));
2196 const vector<TPoint2D>& baseVertices,
double height,
double ratio)
2201 const vector<TPoint2D>& baseVertices,
double height)
2223 uint32_t numBaseEdges,
double baseRadius,
double height1,
double height2)
2226 generateBase(numBaseEdges, baseRadius), height1, height2);
2229 uint32_t numBaseEdges,
double baseRadius)
2234 uint32_t numBaseEdges,
double baseRadius)
2239 uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio)
2245 uint32_t numBaseEdges,
double baseRadius,
double height,
double ratio)
2248 numBaseEdges, baseRadius,
height, ratio);
2251 uint32_t numBaseEdges,
double baseRadius,
double height1,
double ratio1,
2252 double height2,
double ratio2)
2255 generateBase(numBaseEdges, baseRadius), height1, ratio1, height2,
2259 uint32_t numBaseEdges,
double edgeLength)
2262 numBaseEdges, edgeLength / (2 * sin(
M_PI / numBaseEdges)),
"C+");
2276 const vector<TPoint3D>& vertices,
const vector<TPolyhedronFace>& faces)
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 notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
bool mWireframe
This flag determines whether the polyhedron will be displayed as a solid object or as a set of edges...
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.
bool splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components.
double x
X,Y,Z coordinates.
size_t facesInVertex(size_t vertex) const
Returns how many faces converge in a given vertex.
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
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dse3=nullptr, 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...
size_t edgesInVertex(size_t vertex) const
Returns how many edges converge in a given vertex.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define THROW_EXCEPTION(msg)
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
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...
#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)
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.
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
This file implements several operations that operate element-wise on individual or pairs of container...
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)
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...
#define GL_ONE_MINUS_SRC_ALPHA
GLenum GLenum GLuint components
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.
GLsizei GLsizei GLuint * obj
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
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.
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL's display lists.
#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.
T square(const T x)
Inline function for the square of a number.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray trace.
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.
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 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.
double normal[3]
Normal vector.
void unitarize()
Unitarize normal vector.
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)
GLfloat GLfloat GLfloat GLfloat v3
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).
bool getPlane(TPlane &p) const
Gets a plane which contains the polygon.
static std::vector< mrpt::math::TPoint2D > generateBase(uint32_t numBaseEdges, double baseRadius)
Generates a list of 2D vertices constituting a regular polygon.
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLsizei const GLchar ** string
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.
std::vector< TPolyhedronEdge > mEdges
List of polyhedron's edges.
std::vector< mrpt::math::TPoint3D > mVertices
List of vertices presents in the polyhedron.
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...
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
CPolyhedron::Ptr scale(double factor) const
Scales a polyhedron to a given factor.
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
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...
static CPolyhedron::Ptr CreateRegularAntiprism(uint32_t numBaseEdges, double baseRadius, double height)
Creates an antiprism whose base is a regular polygon.
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
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.
GLdouble GLdouble GLdouble r
void updatePolygons() const
Updates the mutable list of polygons used in rendering and ray tracing.
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).
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.
double getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
static CPolyhedron::Ptr CreateTruncatedIcosahedron(double radius)
Creates a truncated icosahedron, consisting of 20 hexagons and 12 pentagons.
GLuint GLsizei GLsizei * length
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.
double evaluatePoint(const TPoint3D &point) const
Evaluate a point in the plane's equation.
GLAPI void GLAPIENTRY glEnd(void)
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, mrpt::opengl::CLight &o)
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...
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 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.
double mLineWidth
When displaying as wireframe object, this variable stores the width of the edges. ...
T operator()(const CPolyhedron::TPolyhedronFace &f)
void render_dl() const override
Render.
GLfloat GLfloat GLfloat v2
double operator[](size_t i) const
void getCenter(mrpt::math::TPoint3D ¢er) const
Gets the center of the polyhedron.
std::vector< TPolyhedronFace > mFaces
List of polyhedron's faces.
void getFacesArea(std::vector< double > &areas) const
Gets a vector with each face's area.
GLuint GLenum GLenum transform
void getBestFittingPlane(TPlane &p) const
Gets the best fitting plane, disregarding whether the polygon actually fits inside or not...
double getHeight(const TPolygon3D &p, const TPoint3D &c)
GLenum GLsizei GLsizei height
unsigned __int32 uint32_t
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.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
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...
std::array< double, 4 > coefs
Plane coefficients, stored as an array: .
GLubyte GLubyte GLubyte a
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.
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...
GLuint GLuint GLsizei GLenum type
void readFromStreamRender(mrpt::serialization::CArchive &in)
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.
void getCenter(TPoint3D &p) const
Get polygon's central point.
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.
GLenum GLuint GLint GLenum face
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.
void getNormalVector(double(&vec)[3]) const
Get plane's normal vector.
3D line, represented by a base point and a director vector.