16 void Insert(std::vector<std::vector<CConvexHull::TEdge> >& vec_edges,
17 const std::array<UInt32, 3>& arr_vertices) {
18 for(
UInt32 un_idx_i = 0; un_idx_i < arr_vertices.size(); un_idx_i++) {
19 for(
UInt32 un_idx_j = 0; un_idx_j < arr_vertices.size(); un_idx_j++) {
20 if(un_idx_i != un_idx_j) {
22 vec_edges[arr_vertices[un_idx_i]][arr_vertices[un_idx_j]];
23 for(
UInt32 un_idx_k = 0; un_idx_k < arr_vertices.size(); un_idx_k++) {
24 if(un_idx_k != un_idx_i && un_idx_k != un_idx_j) {
25 tEdge.push_back(arr_vertices[un_idx_k]);
36 void Erase(std::vector<std::vector<CConvexHull::TEdge> >& vec_edges,
37 const std::array<UInt32, 3>& arr_vertices) {
38 for(
UInt32 un_idx_i = 0; un_idx_i < arr_vertices.size(); un_idx_i++) {
39 for(
UInt32 un_idx_j = 0; un_idx_j < arr_vertices.size(); un_idx_j++) {
40 if(un_idx_i != un_idx_j) {
42 vec_edges[arr_vertices[un_idx_i]][arr_vertices[un_idx_j]];
43 for(
UInt32 un_idx_k = 0; un_idx_k < arr_vertices.size(); un_idx_k++) {
44 if(un_idx_k != un_idx_i && un_idx_k != un_idx_j) {
46 std::find(std::begin(tEdge), std::end(tEdge), arr_vertices[un_idx_k]);
47 if(itErase != std::end(tEdge)) {
66 m_vecPoints(vec_points) {
68 std::vector<std::vector<TEdge> > m_vecEdge;
69 m_vecEdge.resize(m_vecPoints.size());
70 for(std::vector<TEdge>& vec_edge : m_vecEdge) {
71 vec_edge.resize(m_vecPoints.size());
75 std::array<UInt32, 4> arrInitialPoints;
76 bool bFoundInitialPoints =
false;
77 for (
UInt32 unI = 0; unI < m_vecPoints.size() && !bFoundInitialPoints; unI++) {
78 for (
UInt32 unJ = unI + 1; unJ < m_vecPoints.size() && !bFoundInitialPoints; unJ++) {
79 for (
UInt32 unK = unJ + 1; unK < m_vecPoints.size() && !bFoundInitialPoints; unK++) {
80 for (
UInt32 unL = unK + 1; unL < m_vecPoints.size(); unL++) {
83 (m_vecPoints[unI] - m_vecPoints[unJ]).CrossProduct(m_vecPoints[unI] - m_vecPoints[unK]);
87 if (cNormal.
Length() < 0.000001)
90 if ((cNormal.
DotProduct(m_vecPoints[unL] - m_vecPoints[unI]) < 0.000001) &&
91 (cNormal.
DotProduct(m_vecPoints[unL] - m_vecPoints[unI]) > -0.000001) )
93 arrInitialPoints = {unI, unJ, unK, unL};
94 bFoundInitialPoints =
true;
101 for (
UInt32 un_idx_i = 0; un_idx_i < 4; un_idx_i++) {
102 for (
UInt32 un_idx_j = un_idx_i + 1; un_idx_j < 4; un_idx_j++) {
103 for (
UInt32 un_idx_k = un_idx_j + 1; un_idx_k < 4; un_idx_k++) {
104 m_vecFaces.emplace_back(m_vecPoints,
105 arrInitialPoints[un_idx_i],
106 arrInitialPoints[un_idx_j],
107 arrInitialPoints[un_idx_k],
108 arrInitialPoints[6 - un_idx_i - un_idx_j - un_idx_k]);
109 const SFace& sFace = m_vecFaces.back();
115 for (
UInt32 un_idx_point = 0; un_idx_point < m_vecPoints.size(); un_idx_point++) {
116 const CVector3& cPoint = m_vecPoints[un_idx_point];
120 std::find(std::begin(arrInitialPoints), std::end(arrInitialPoints), un_idx_point);
121 if(itPoint != std::end(arrInitialPoints)) {
125 for (
const SFace& s_face : m_vecFaces) {
126 if (s_face.Normal.DotProduct(cPoint) > s_face.Direction + 0.000001) {
127 Erase(m_vecEdge, s_face.VertexIndices);
131 std::remove_if(std::begin(m_vecFaces), std::end(m_vecFaces), [cPoint] (
const SFace& s_face) {
134 m_vecFaces.erase(itEraseFrom, std::end(m_vecFaces));
136 std::vector<SFace> vecFacesToAdd;
137 for (
const SFace& s_face : m_vecFaces) {
138 for (
UInt32 unIdxA = 0; unIdxA < 3; unIdxA++) {
139 for (
UInt32 unIdxB = unIdxA + 1; unIdxB < 3; unIdxB++) {
142 UInt32 unIdxC = 3 - unIdxA - unIdxB;
143 vecFacesToAdd.emplace_back(m_vecPoints,
148 SFace& sFace = vecFacesToAdd.back();
162 std::move(std::begin(vecFacesToAdd),
163 std::end(vecFacesToAdd),
164 std::back_inserter(m_vecFaces));
165 vecFacesToAdd.clear();
178 Normal = (vec_points[un_B] - vec_points[un_A]).CrossProduct(vec_points[un_C] - vec_points[un_A]);
191 Direction = -Direction;
192 std::swap(VertexIndices[1], VertexIndices[2]);
unsigned int UInt32
32-bit unsigned integer.
The namespace containing all the ARGoS related code.
void Erase(std::vector< std::vector< CConvexHull::TEdge > > &vec_edges, const std::array< UInt32, 3 > &arr_vertices)
void Insert(std::vector< std::vector< CConvexHull::TEdge > > &vec_edges, const std::array< UInt32, 3 > &arr_vertices)
std::vector< UInt32 > TEdge
CConvexHull(const std::vector< CVector3 > &vec_points)
std::array< UInt32, 3 > VertexIndices
SFace(const std::vector< CVector3 > &vec_points, UInt32 un_A, UInt32 un_B, UInt32 un_C, UInt32 un_inside_point)
Real Length() const
Returns the length of this vector.
Real DotProduct(const CVector3 &c_vector3) const
Returns the dot product between this vector and the passed one.