Skip to content

Commit

Permalink
Don't run triangulation if we don't have at least three points.
Browse files Browse the repository at this point in the history
Use filter() instead of run() for cleaner interface.
Close #2513
  • Loading branch information
abellgithub committed Jun 3, 2019
1 parent 96119a0 commit cdcb96c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
63 changes: 34 additions & 29 deletions filters/DelaunayFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,44 @@ std::string DelaunayFilter::getName() const
return s_info.name;
}

PointViewSet DelaunayFilter::run(PointViewPtr pointView)

DelaunayFilter::DelaunayFilter()
{}


DelaunayFilter::~DelaunayFilter()
{}


void DelaunayFilter::filter(PointView& pointView)
{
// Returns NULL if the mesh already exists
TriangularMesh *mesh = pointView->createMesh("delaunay2d");

if (mesh != NULL)
TriangularMesh *mesh = pointView.createMesh("delaunay2d");

if (!mesh)
throwError("Unable to create mesh 'delaunay2d'.");
if (pointView.size() < 3)
{
std::vector<double> delaunayPoints;
for (PointId i = 0; i < pointView->size(); i++)
{
PointRef point(*pointView, i);
double x(point.getFieldAs<double>(Dimension::Id::X));
double y(point.getFieldAs<double>(Dimension::Id::Y));

delaunayPoints.push_back(x);
delaunayPoints.push_back(y);
}

// Actually perform the triangulation
delaunator::Delaunator triangulation(delaunayPoints);

for (std::size_t i = 0; i < triangulation.triangles.size(); i += 3)
{
mesh->add(triangulation.triangles[i+2],
triangulation.triangles[i+1],
triangulation.triangles[i]);
}
log()->get(LogLevel::Warning) << getName() << ": triangulation "
"requested for fewer than three points.\n";
return;
}

PointViewSet viewSet;
viewSet.insert(pointView);

return viewSet;

std::vector<double> delaunayPoints;
for (PointId i = 0; i < pointView.size(); i++)
{
delaunayPoints.push_back(
pointView.getFieldAs<double>(Dimension::Id::X, i));
delaunayPoints.push_back(
pointView.getFieldAs<double>(Dimension::Id::Y, i));
}

// Actually perform the triangulation
delaunator::Delaunator triangulation(delaunayPoints);

for (std::size_t i = 0; i < triangulation.triangles.size(); i += 3)
mesh->add(triangulation.triangles[i+2], triangulation.triangles[i+1],
triangulation.triangles[i]);
}

} // namespace pdal
12 changes: 6 additions & 6 deletions filters/DelaunayFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ namespace pdal
class PDAL_DLL DelaunayFilter : public Filter
{
public:
DelaunayFilter() : Filter()
{}
DelaunayFilter& operator=(const DelaunayFilter&) = delete;
DelaunayFilter(const DelaunayFilter&) = delete;
DelaunayFilter();
virtual ~DelaunayFilter();

std::string getName() const;

private:
virtual PointViewSet run(PointViewPtr view);

DelaunayFilter& operator=(const DelaunayFilter&); // not implemented
DelaunayFilter(const DelaunayFilter&); // not implemented
virtual void filter(PointView& view);
};

} // namespace pdal

0 comments on commit cdcb96c

Please sign in to comment.