feat: add whitebox module support for linux(#4654) (#5075)

* feat: fix whitebox module to work on linux(#4654)

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* update with AZStl

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* feat: update format

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: minor changes

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: update clang warnings

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: fix clang errors

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: remove unused refrence for g_indices and address range based for loop warnings

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: fix clang warnings for test cases

Signed-off-by: Michael Pollind <mpollind@gmail.com>
This commit is contained in:
Michael Pollind
2021-11-15 01:21:50 -08:00
committed by GitHub
parent 57adfd795e
commit 0ada8b335b
12 changed files with 78 additions and 88 deletions
@@ -426,10 +426,6 @@ namespace WhiteBox
Mesh::TexCoord2D(0.0f, 0.0f),
};
// indices related to halfedges - start iterating on first halfedge, pointing to
// vertex 0, then follow next to get vertex 2 and then 3 (anti-clockwise winding)
const int g_indices[] = {0, 1, 2, 0, 2, 3};
// conversion functions between OpenMesh and AZ types
// convert WhiteBox face handle to OpenMesh face handle
@@ -600,7 +596,7 @@ namespace WhiteBox
VertexHandles vertexHandles;
vertexHandles.reserve(whiteBox.mesh.n_vertices());
for (const auto vertexHandle : whiteBox.mesh.vertices())
for (const auto& vertexHandle : whiteBox.mesh.vertices())
{
vertexHandles.push_back(wb_vh(vertexHandle));
}
@@ -614,7 +610,7 @@ namespace WhiteBox
FaceHandles faceHandles;
faceHandles.reserve(whiteBox.mesh.n_faces());
for (const auto faceHandle : whiteBox.mesh.faces())
for (const auto& faceHandle : whiteBox.mesh.faces())
{
faceHandles.push_back(wb_fh(faceHandle));
}
@@ -660,7 +656,7 @@ namespace WhiteBox
EdgeHandles orderedEdgeHandles;
orderedEdgeHandles.reserve(halfedgeHandles.size());
for (const auto halfedgeHandle : halfedgeHandles)
for (const auto& halfedgeHandle : halfedgeHandles)
{
orderedEdgeHandles.push_back(HalfedgeEdgeHandle(whiteBox, halfedgeHandle));
}
@@ -712,7 +708,7 @@ namespace WhiteBox
EdgeHandles edgeHandles;
edgeHandles.reserve(whiteBox.mesh.n_edges());
for (const auto edgeHandle : whiteBox.mesh.edges())
for (const auto& edgeHandle : whiteBox.mesh.edges())
{
edgeHandles.push_back(wb_eh(edgeHandle));
}
@@ -771,7 +767,7 @@ namespace WhiteBox
EdgeHandles edgeHandles;
edgeHandles.reserve(3);
for (const auto halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
for (const auto& halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
{
edgeHandles.push_back(HalfedgeEdgeHandle(whiteBox, halfedgeHandle));
}
@@ -789,7 +785,7 @@ namespace WhiteBox
VertexHandles vertexHandles;
vertexHandles.reserve(3);
for (const auto halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
for (const auto& halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
{
vertexHandles.emplace_back(HalfedgeVertexHandleAtTip(whiteBox, halfedgeHandle));
}
@@ -809,7 +805,7 @@ namespace WhiteBox
AZStd::vector<AZ::Vector3> triangles;
triangles.reserve(faceHandles.size() * 3);
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
const auto corners = FaceVertexPositions(whiteBox, faceHandle);
triangles.insert(triangles.end(), corners.begin(), corners.end());
@@ -953,7 +949,7 @@ namespace WhiteBox
// all halfedges for a given face
const auto halfedges = FaceHalfedgeHandles(whiteBox, faceHandle);
for (const HalfedgeHandle halfedgeHandle : halfedges)
for (const HalfedgeHandle& halfedgeHandle : halfedges)
{
const FaceHandle oppositeFaceHandle = OppositeFaceHandle(whiteBox, halfedgeHandle);
@@ -983,15 +979,15 @@ namespace WhiteBox
// build all possible halfedge handles
HalfedgeHandles halfedgeHandles;
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
// find all vertices for a given face
const auto vertexHandles = FaceVertexHandles(whiteBox, faceHandle);
for (const auto vertexHandle : vertexHandles)
for (const auto& vertexHandle : vertexHandles)
{
// find all outgoing halfedges from vertex
const auto outgoingHalfedgeHandles = VertexOutgoingHalfedgeHandles(whiteBox, vertexHandle);
for (const auto halfedgeHandle : outgoingHalfedgeHandles)
for (const auto& halfedgeHandle : outgoingHalfedgeHandles)
{
// find what face corresponds to this halfedge
const FaceHandle halfedgeFaceHandle = HalfedgeFaceHandle(whiteBox, halfedgeHandle);
@@ -1098,7 +1094,7 @@ namespace WhiteBox
VertexHandles orderedVertexHandles;
orderedVertexHandles.reserve(halfedgeHandles.size());
for (const auto halfedgeHandle : halfedgeHandles)
for (const auto& halfedgeHandle : halfedgeHandles)
{
orderedVertexHandles.push_back(HalfedgeVertexHandleAtTip(whiteBox, halfedgeHandle));
}
@@ -1121,10 +1117,10 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
VertexHandles vertexHandles;
for (const FaceHandle faceHandle : faceHandles)
for (const FaceHandle& faceHandle : faceHandles)
{
const auto faceVertexHandles = FaceVertexHandles(whiteBox, faceHandle);
for (const VertexHandle faceVertexHandle : faceVertexHandles)
for (const VertexHandle& faceVertexHandle : faceVertexHandles)
{
const auto* const vertexIt =
AZStd::find(vertexHandles.cbegin(), vertexHandles.cend(), faceVertexHandle);
@@ -1318,10 +1314,10 @@ namespace WhiteBox
visitedVertexHandles.push_back(vertexHandle);
// for all connected vertex handles to this edge
for (const auto vertexEdgeHandle : VertexEdgeHandles(whiteBox, vertexHandle))
for (const auto& vertexEdgeHandle : VertexEdgeHandles(whiteBox, vertexHandle))
{
// check all halfedges in the edge
for (const auto halfedgeHandle : EdgeHalfedgeHandles(whiteBox, vertexEdgeHandle))
for (const auto& halfedgeHandle : EdgeHalfedgeHandles(whiteBox, vertexEdgeHandle))
{
// only track the edge if it's a 'user' edge (selectable - not a 'mesh' edge)
if (!EdgeIsUser(whiteBox, halfedgeHandle, vertexEdgeHandle))
@@ -1339,7 +1335,7 @@ namespace WhiteBox
// store the edge to the grouping
edgeGrouping.push_back(vertexEdgeHandle);
for (const auto nextVertexHandle : Api::EdgeVertexHandles(whiteBox, vertexEdgeHandle))
for (const auto& nextVertexHandle : Api::EdgeVertexHandles(whiteBox, vertexEdgeHandle))
{
// if we haven't seen this vertex yet, add it to
// the vertex handles to explore
@@ -1978,7 +1974,7 @@ namespace WhiteBox
Faces faces;
faces.reserve(MeshFaceCount(whiteBox));
for (const auto faceHandle : MeshFaceHandles(whiteBox))
for (const auto& faceHandle : MeshFaceHandles(whiteBox))
{
const auto halfEdgeHandles = FaceHalfedgeHandles(whiteBox, faceHandle);
@@ -2002,14 +1998,13 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
auto& mesh = whiteBox.mesh;
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
for (Mesh::ConstFaceHalfedgeCCWIter faceHalfedgeIt = mesh.fh_ccwiter(om_fh(faceHandle));
faceHalfedgeIt.is_valid(); ++faceHalfedgeIt)
{
const Mesh::HalfedgeHandle heh = *faceHalfedgeIt;
const Mesh::VertexHandle vh = mesh.to_vertex_handle(heh);
const Mesh::FaceHandle fh = mesh.face_handle(heh);
const AZ::Vector3 position = mesh.point(vh);
const AZ::Vector3 normal = FaceNormal(whiteBox, faceHandle);
@@ -2064,7 +2059,7 @@ namespace WhiteBox
polygonHandle.m_faceHandles.push_back(faceHandleToVisit);
// for all halfedges
for (const auto faceHalfedgeHandle : faceHalfedges)
for (const auto& faceHalfedgeHandle : faceHalfedges)
{
const EdgeHandle edgeHandle = HalfedgeEdgeHandle(whiteBox, faceHalfedgeHandle);
// if we haven't seen this halfedge before and we want to track it,
@@ -2092,10 +2087,10 @@ namespace WhiteBox
static void PopulatePolygonProps(FaceHandlePolygonMapping& polygonProps, const FaceHandles& faceHandles)
{
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
auto polygonIt = polygonProps.find(om_fh(faceHandle));
for (const auto innerFaceHandle : faceHandles)
for (const auto& innerFaceHandle : faceHandles)
{
polygonIt->second.push_back(om_fh(innerFaceHandle));
}
@@ -2104,7 +2099,7 @@ namespace WhiteBox
static void ClearPolygonProps(FaceHandlePolygonMapping& polygonProps, const FaceHandles& faceHandles)
{
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
if (auto polygonIt = polygonProps.find(om_fh(faceHandle)); polygonIt != polygonProps.end())
{
@@ -2116,9 +2111,9 @@ namespace WhiteBox
// restore all vertices along the restored edges (after creating a new polygon)
static void RestoreVertexHandlesForEdges(WhiteBoxMesh& whiteBox, const EdgeHandles& restoredEdgeHandles)
{
for (const auto edgeHandle : restoredEdgeHandles)
for (const auto& edgeHandle : restoredEdgeHandles)
{
for (const auto vertexHandle : EdgeVertexHandles(whiteBox, edgeHandle))
for (const auto& vertexHandle : EdgeVertexHandles(whiteBox, edgeHandle))
{
RestoreVertex(whiteBox, vertexHandle);
}
@@ -2280,19 +2275,19 @@ namespace WhiteBox
auto& polygonProps = whiteBox.mesh.property(polygonPropsHandle);
// update all face handles to refer to the new face handles in the group
for (const auto faceHandle : combinedFaceHandles)
for (const auto& faceHandle : combinedFaceHandles)
{
auto polygonIt = polygonProps.find(om_fh(faceHandle));
polygonIt->second.clear();
for (const auto innerFaceHandle : combinedFaceHandles)
for (const auto& innerFaceHandle : combinedFaceHandles)
{
polygonIt->second.push_back(om_fh(innerFaceHandle));
}
}
// hide any vertices that are not connected to a 'user' edge
for (const auto vertexHandle : firstPolygonVertexHandles)
for (const auto& vertexHandle : firstPolygonVertexHandles)
{
if (VertexIsIsolated(whiteBox, vertexHandle))
{
@@ -2339,7 +2334,7 @@ namespace WhiteBox
omFaceHandles.erase(AZStd::unique(omFaceHandles.begin(), omFaceHandles.end()), omFaceHandles.end());
// update all face handles to point to the new polygon grouping
for (const auto omFaceHandle2 : omFaceHandles)
for (const auto& omFaceHandle2 : omFaceHandles)
{
polygonProps[omFaceHandle2] = omFaceHandles;
}
@@ -2413,7 +2408,7 @@ namespace WhiteBox
omExistingPolygonHandle.push_back(om_fh(newFaceHandle));
// update all face handles to point to the new polygon grouping
for (const Mesh::FaceHandle faceHandle : omExistingPolygonHandle)
for (const Mesh::FaceHandle& faceHandle : omExistingPolygonHandle)
{
polygonProps[faceHandle] = omExistingPolygonHandle;
}
@@ -2510,7 +2505,7 @@ namespace WhiteBox
auto& polygonProps = whiteBox.mesh.property(polygonPropsHandle);
// multiple face handles map to a polygon handle
for (const auto faceHandle : polygon)
for (const auto& faceHandle : polygon)
{
polygonProps[faceHandle] = polygon;
}
@@ -2658,7 +2653,7 @@ namespace WhiteBox
{
AZ_PROFILE_FUNCTION(AzToolsFramework);
for (const Mesh::FaceHandle faceHandle : whiteBox.mesh.faces())
for (const Mesh::FaceHandle& faceHandle : whiteBox.mesh.faces())
{
for (Mesh::FaceHalfedgeCCWIter faceHalfedgeIt = whiteBox.mesh.fh_ccwiter(faceHandle);
faceHalfedgeIt.is_valid(); ++faceHalfedgeIt)
@@ -2705,7 +2700,7 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
AzToolsFramework::MidpointCalculator midpointCalculator;
for (const auto vertexHandle : vertexHandles)
for (const auto& vertexHandle : vertexHandles)
{
midpointCalculator.AddPosition(VertexPosition(whiteBox, vertexHandle));
}
@@ -2723,7 +2718,7 @@ namespace WhiteBox
const auto adjacentPolygonEdgeHandles = PolygonBorderEdgeHandlesFlattened(whiteBox, adjacentPolygonHandle);
// iterate over all halfedges in the adjacent polygon
for (const auto edgeHandle : adjacentPolygonEdgeHandles)
for (const auto& edgeHandle : adjacentPolygonEdgeHandles)
{
const auto* const foundEdgeHandleInSelectedPolygon =
AZStd::find(selectedPolygonEdgeHandles.cbegin(), selectedPolygonEdgeHandles.cend(), edgeHandle);
@@ -2732,7 +2727,7 @@ namespace WhiteBox
if (foundEdgeHandleInSelectedPolygon == selectedPolygonEdgeHandles.cend())
{
// find outgoing edge handles
for (const auto halfedgeHandle :
for (const auto& halfedgeHandle :
VertexOutgoingHalfedgeHandles(whiteBox, vertexHandlePair.m_existing))
{
// attempt to find one of the outgoing halfedge handles in the adjacent polygon
@@ -2793,7 +2788,7 @@ namespace WhiteBox
FaceVertHandlesCollection& vertsForLinkingAdjacentPolygons)
{
// find all faces connected to this edge
for (const auto faceHandle : EdgeFaceHandles(whiteBox, edgeHandle))
for (const auto& faceHandle : EdgeFaceHandles(whiteBox, edgeHandle))
{
// find a face that is _not_ part of the polygon being appended/selected
if (AZStd::find(
@@ -2934,7 +2929,7 @@ namespace WhiteBox
// erase face handles from the polygon map and
// delete the faces from OpenMesh
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
polygonProps.erase(om_fh(faceHandle));
whiteBox.mesh.delete_face(om_fh(faceHandle), false);
@@ -2975,10 +2970,9 @@ namespace WhiteBox
using ModifiedFaceHandle = AZStd::pair<Mesh::FaceHandle, Mesh::FaceHandle>;
using ModifiedFaceHandles = AZStd::vector<ModifiedFaceHandle>;
// find all face handles that no longer match (where garbage_collect has invalidated the handles)
const ModifiedFaceHandles modifiedFaceHandles = std::transform_reduce(
faceHandlesCopy.cbegin(), faceHandlesCopy.cend(), faceHandlePtrs.cbegin(), ModifiedFaceHandles{},
// reduce
const ModifiedFaceHandles modifiedFaceHandles = AZStd::inner_product(
faceHandlesCopy.begin(), faceHandlesCopy.end(), faceHandlePtrs.begin(), ModifiedFaceHandles{},
//reduce
[](ModifiedFaceHandles modifiedFaceHandles, const ModifiedFaceHandle& fh)
{
if (fh.first.is_valid())
@@ -2988,7 +2982,7 @@ namespace WhiteBox
return modifiedFaceHandles;
},
// transform
//transform
[](const Mesh::FaceHandle lhs, const Mesh::FaceHandle* rhs)
{
// if any of the faceHandlePtrs differ, we know the handles
@@ -3030,14 +3024,14 @@ namespace WhiteBox
faces.reserve(existingFaces.size());
// for each face
for (const FaceHandle faceHandle : existingFaces)
for (const FaceHandle& faceHandle : existingFaces)
{
VertexHandles vertexHandlesForFace;
vertexHandlesForFace.reserve(3);
const auto vertexHandles = FaceVertexHandles(whiteBox, faceHandle);
// for each vertex handle
for (const VertexHandle vertexHandle : vertexHandles)
for (const VertexHandle& vertexHandle : vertexHandles)
{
// find vertex handle in vertices list
const auto* const vertexHandlePairIt = AZStd::find_if(
@@ -3092,11 +3086,11 @@ namespace WhiteBox
Internal::AppendedVerts appendedVerts;
appendedVerts.m_vertexHandlePairs.reserve(existingVertexHandles.size());
for (const VertexHandle existingVertexHandle : existingVertexHandles)
for (const VertexHandle& existingVertexHandle : existingVertexHandles)
{
bool vertexHandleAdded = false;
// visit all connected halfedge handles
for (const auto halfedgeHandle : VertexHalfedgeHandles(whiteBox, existingVertexHandle))
for (const auto& halfedgeHandle : VertexHalfedgeHandles(whiteBox, existingVertexHandle))
{
const auto edgeHandle = HalfedgeEdgeHandle(whiteBox, halfedgeHandle);
const bool boundaryEdge = EdgeIsBoundary(whiteBox, edgeHandle);
@@ -3372,7 +3366,7 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
const AZ::Transform polygonSpace = PolygonSpace(whiteBox, polygonHandle, pivot);
for (const auto vertexHandle : PolygonVertexHandles(whiteBox, polygonHandle))
for (const auto& vertexHandle : PolygonVertexHandles(whiteBox, polygonHandle))
{
SetVertexPosition(
whiteBox, vertexHandle,