Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into projfix
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 14, 2019
2 parents 8367aac + 271f7a3 commit 3da8c26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
12 changes: 12 additions & 0 deletions pdal/Mesh.hpp
Expand Up @@ -34,6 +34,7 @@

#pragma once

#include <array>
#include <deque>

namespace pdal
Expand All @@ -48,8 +49,19 @@ class PDAL_DLL Triangle
PointId m_a;
PointId m_b;
PointId m_c;

friend bool operator == (const Triangle& a, const Triangle& b);
};

inline bool operator == (const Triangle& a, const Triangle& b)
{
std::array<PointId, 3> aa { {a.m_a, a.m_b, a.m_c} };
std::array<PointId, 3> bb { {b.m_a, b.m_b, b.m_c} };
std::sort(aa.begin(), aa.end());
std::sort(bb.begin(), bb.end());
return aa == bb;
}

/**
A mesh is a way to represent a set of points connected by edges. Point
indices are into a point view.
Expand Down
2 changes: 1 addition & 1 deletion pdal/SrsBounds.cpp
Expand Up @@ -82,7 +82,7 @@ void SrsBounds::parse(const std::string& s, std::string::size_type& pos)

std::ostream& operator << (std::ostream& out, const SrsBounds& srsBounds)
{
out << (Bounds&)srsBounds;
out << static_cast<const Bounds&>(srsBounds);
out << " / " << srsBounds.m_srs;
return out;
}
Expand Down
46 changes: 11 additions & 35 deletions test/unit/filters/DelaunayFilterTest.cpp
Expand Up @@ -52,19 +52,19 @@ TEST(DelaunayFilterTest, test1)
// input file. For each of these triangles, we will check for all
// index permutations, as long as the vertices appear in
// counterclockwise order.
std::vector<std::vector<size_t>> expectedTriangles =
std::vector<Triangle> expectedTriangles =
{
{5, 2, 0},
{2, 5, 4},
{3, 2, 4},
{2, 1, 0},
{3, 1, 2}
};

// Number of detected occurrences of each of the expected triangles.
// Initialize to zeros.
std::vector<int> expectedTrianglesOccurrences(expectedTriangles.size(), 0);

Options readerOps;
readerOps.add("filename",
Support::datapath("filters/delaunaytest.txt"));
Expand All @@ -84,42 +84,18 @@ TEST(DelaunayFilterTest, test1)
EXPECT_EQ(view->size(), 6u);
TriangularMesh *mesh = view->mesh("delaunay2d");
EXPECT_EQ(mesh->size(), expectedTriangles.size());

// Loop through the triangles of the generated mesh...
for (size_t i = 0; i < mesh->size(); i++)
{
Triangle triangle = (*mesh)[i];

// Build a vector so we can compare to an expected triangle with
// the == operator.
std::vector<size_t> triangleVector = {triangle.m_a, triangle.m_b, triangle.m_c};

// Go through all of the expected triangles to check for a
// match.
for (size_t i = 0; i < expectedTriangles.size(); i++)
{
std::vector<size_t> expectedTriangle = expectedTriangles[i];

// Go through all counterclockwise vertex permutations for
// this expected triangle.
for (std::vector<size_t>::iterator iter = expectedTriangle.begin(); iter != expectedTriangle.end(); iter++)
{
std::vector<size_t> expectedTrianglePermutation = {0, 0, 0};
std::rotate_copy(expectedTriangle.begin(), iter, expectedTriangle.end(), expectedTrianglePermutation.begin());

if (triangleVector == expectedTrianglePermutation)
{
// We have a match!
expectedTrianglesOccurrences[i] += 1;
}
}
}
}

// Assert that each of the expected triangles occurred exactly once.
for (int triangleOccurrences : expectedTrianglesOccurrences)
{
EXPECT_EQ(triangleOccurrences, 1);

auto it = std::find(expectedTriangles.begin(), expectedTriangles.end(),
triangle);
bool found = (it != expectedTriangles.end());
EXPECT_TRUE(found);
expectedTriangles.erase(it);
}
EXPECT_EQ(expectedTriangles.size(), (size_t)0);
}

0 comments on commit 3da8c26

Please sign in to comment.