Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into hexer-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed May 7, 2018
2 parents ca6d006 + d9f49f2 commit e7c2c5d
Show file tree
Hide file tree
Showing 16 changed files with 368 additions and 196 deletions.
2 changes: 1 addition & 1 deletion cmake/macros.cmake
Expand Up @@ -132,7 +132,7 @@ macro(PDAL_ADD_PLUGIN _name _type _shortname)
${PROJECT_BINARY_DIR}/include
${PDAL_INCLUDE_DIR})
target_link_libraries(${${_name}}
PUBLIC
PRIVATE
${PDAL_BASE_LIB_NAME}
${PDAL_UTIL_LIB_NAME}
${PDAL_ADD_PLUGIN_LINK_WITH}
Expand Down
8 changes: 8 additions & 0 deletions filters/ColorizationFilter.cpp
Expand Up @@ -126,6 +126,14 @@ ColorizationFilter::BandInfo parseDim(const std::string& dim,

} // unnamed namespace

ColorizationFilter::ColorizationFilter()
{}


ColorizationFilter::~ColorizationFilter()
{}


void ColorizationFilter::addArgs(ProgramArgs& args)
{
args.add("raster", "Raster filename", m_rasterFilename);
Expand Down
4 changes: 2 additions & 2 deletions filters/ColorizationFilter.hpp
Expand Up @@ -69,9 +69,9 @@ class PDAL_DLL ColorizationFilter : public Filter, public Streamable
Dimension::Type m_type;
};

ColorizationFilter();
~ColorizationFilter();

ColorizationFilter()
{}
ColorizationFilter& operator=(const ColorizationFilter&) = delete;
ColorizationFilter(const ColorizationFilter&) = delete;

Expand Down
78 changes: 46 additions & 32 deletions filters/CropFilter.cpp
Expand Up @@ -58,6 +58,16 @@ static StaticPluginInfo const s_info

CREATE_STATIC_STAGE(CropFilter, s_info)

struct CropArgs
{
bool m_cropOutside;
SpatialReference m_assignedSrs;
std::vector<Bounds> m_bounds;
std::vector<filter::Point> m_centers;
double m_distance;
std::vector<Polygon> m_polys;
};

CropFilter::ViewGeom::ViewGeom(const Polygon& poly) : m_poly(poly)
{}

Expand All @@ -67,25 +77,28 @@ CropFilter::ViewGeom::ViewGeom(ViewGeom&& vg) :

std::string CropFilter::getName() const { return s_info.name; }

CropFilter::CropFilter() : m_cropOutside(false)
CropFilter::CropFilter() : m_args(new CropArgs)
{}


CropFilter::~CropFilter()
{}


void CropFilter::addArgs(ProgramArgs& args)
{
args.add("outside", "Whether we keep points inside or outside of the "
"bounding region", m_cropOutside);
args.add("a_srs", "Spatial reference for bounding region", m_assignedSrs);
args.add("bounds", "Point box for cropped points", m_bounds);
"bounding region", m_args->m_cropOutside);
args.add("a_srs", "Spatial reference for bounding region",
m_args->m_assignedSrs);
args.add("bounds", "Point box for cropped points", m_args->m_bounds);
args.add("point", "Center of circular/spherical crop region. Use with "
"'distance'.", m_centers).setErrorText("Invalid point specification. "
"Must be valid GeoJSON/WKT. "
"Ex: \"(1.00, 1.00)\" or \"(1.00, 1.00, 1.00)\"");
"'distance'.", m_args->m_centers).
setErrorText("Invalid point specification. Must be valid "
"GeoJSON/WKT. Ex: \"(1.00, 1.00)\" or \"(1.00, 1.00, 1.00)\"");
args.add("distance", "Crop with this distance from 2D or 3D 'point'",
m_distance);
args.add("polygon", "Bounding polying for cropped points", m_polys).
m_args->m_distance);
args.add("polygon", "Bounding polying for cropped points", m_args->m_polys).
setErrorText("Invalid polygon specification. "
"Must be valid GeoJSON/WKT");
}
Expand All @@ -94,10 +107,10 @@ void CropFilter::addArgs(ProgramArgs& args)
void CropFilter::initialize()
{
// Set geometry from polygons.
if (m_polys.size())
if (m_args->m_polys.size())
{
m_geoms.clear();
for (Polygon& poly : m_polys)
for (Polygon& poly : m_args->m_polys)
{
// Throws if invalid.
poly.valid();
Expand All @@ -106,26 +119,26 @@ void CropFilter::initialize()
}

m_boxes.clear();
for (auto& bound : m_bounds)
for (auto& bound : m_args->m_bounds)
m_boxes.push_back(bound.to2d());

m_distance2 = m_distance * m_distance;
m_distance2 = m_args->m_distance * m_args->m_distance;
}


void CropFilter::ready(PointTableRef table)
{
// If the user didn't provide an SRS, take one from the table.
if (m_assignedSrs.empty())
if (m_args->m_assignedSrs.empty())
{
m_assignedSrs = table.anySpatialReference();
m_args->m_assignedSrs = table.anySpatialReference();
if (!table.spatialReferenceUnique())
log()->get(LogLevel::Warning) << "Can't determine spatial "
"reference for provided bounds. Consider using 'a_srs' "
"option.\n";
}
for (auto& geom : m_geoms)
geom.m_poly.setSpatialReference(m_assignedSrs);
geom.m_poly.setSpatialReference(m_args->m_assignedSrs);
}


Expand All @@ -140,7 +153,7 @@ bool CropFilter::processOne(PointRef& point)
if (!crop(point, box))
return false;

for (auto& center: m_centers)
for (auto& center: m_args->m_centers)
if (!crop(point, center))
return false;

Expand Down Expand Up @@ -177,26 +190,27 @@ void CropFilter::transform(const SpatialReference& srs)
}

// If we don't have any SRS, do nothing.
if (srs.empty() && m_assignedSrs.empty())
if (srs.empty() && m_args->m_assignedSrs.empty())
return;
if (srs.empty() || m_assignedSrs.empty())
if (srs.empty() || m_args->m_assignedSrs.empty())
throwError("Unable to transform crop geometry to point "
"coordinate system.");

for (auto& box : m_boxes)
{
if (!gdal::reprojectBounds(box, m_assignedSrs.getWKT(), srs.getWKT()))
if (!gdal::reprojectBounds(box, m_args->m_assignedSrs.getWKT(),
srs.getWKT()))
throwError("Unable to reproject bounds.");
}
for (auto& point : m_centers)
for (auto& point : m_args->m_centers)
{
if (!gdal::reprojectPoint(point.x, point.y, point.z,
m_assignedSrs.getWKT(), srs.getWKT()))
m_args->m_assignedSrs.getWKT(), srs.getWKT()))
throwError("Unable to reproject point center.");
}
// Set the assigned SRS for the points/bounds to the one we've
// transformed to.
m_assignedSrs = srs;
m_args->m_assignedSrs = srs;
}


Expand All @@ -219,7 +233,7 @@ PointViewSet CropFilter::run(PointViewPtr view)
viewSet.insert(outView);
}

for (auto& point: m_centers)
for (auto& point: m_args->m_centers)
{
PointViewPtr outView = view->makeNew();
crop(point, *view, *outView);
Expand All @@ -236,7 +250,7 @@ bool CropFilter::crop(const PointRef& point, const BOX2D& box)
double y = point.getFieldAs<double>(Dimension::Id::Y);

// Return true if we're keeping a point.
return (m_cropOutside != box.contains(x, y));
return (m_args->m_cropOutside != box.contains(x, y));
}


Expand All @@ -246,7 +260,7 @@ void CropFilter::crop(const BOX2D& box, PointView& input, PointView& output)
for (PointId idx = 0; idx < input.size(); ++idx)
{
point.setPointId(idx);
if (m_cropOutside != crop(point, box))
if (m_args->m_cropOutside != crop(point, box))
output.appendPoint(input, idx);
}
}
Expand All @@ -256,7 +270,7 @@ bool CropFilter::crop(const PointRef& point, GridPnp& g)
{
double x = point.getFieldAs<double>(Dimension::Id::X);
double y = point.getFieldAs<double>(Dimension::Id::Y);
return (m_cropOutside != g.inside(x, y));
return (m_args->m_cropOutside != g.inside(x, y));
}


Expand All @@ -281,21 +295,21 @@ bool CropFilter::crop(const PointRef& point, const filter::Point& center)
double y = point.getFieldAs<double>(Dimension::Id::Y);
x = std::abs(x - center.x);
y = std::abs(y - center.y);
if (x > m_distance || y > m_distance)
return (m_cropOutside);
if (x > m_args->m_distance || y > m_args->m_distance)
return (m_args->m_cropOutside);

bool inside;
if (center.is3d())
{
double z = point.getFieldAs<double>(Dimension::Id::Z);
z = std::abs(z - center.z);
if (z > m_distance)
return (m_cropOutside);
if (z > m_args->m_distance)
return (m_args->m_cropOutside);
inside = (x * x + y * y + z * z < m_distance2);
}
else
inside = (x * x + y * y < m_distance2);
return (m_cropOutside != inside);
return (m_args->m_cropOutside != inside);
}


Expand Down
16 changes: 8 additions & 8 deletions filters/CropFilter.hpp
Expand Up @@ -35,18 +35,22 @@
#pragma once

#include <list>
#include <memory>

#include <pdal/Filter.hpp>
#include <pdal/Polygon.hpp>
#include <pdal/Streamable.hpp>

#include "private/Point.hpp"

namespace pdal
{

class ProgramArgs;
class GridPnp;
struct CropArgs;
namespace filter
{
class Point;
}

// removes any points outside of the given range
// updates the header accordingly
Expand All @@ -55,6 +59,7 @@ class PDAL_DLL CropFilter : public Filter, public Streamable
public:
CropFilter();
~CropFilter();

std::string getName() const;

private:
Expand All @@ -68,13 +73,8 @@ class PDAL_DLL CropFilter : public Filter, public Streamable
Polygon m_poly;
std::vector<std::unique_ptr<GridPnp>> m_gridPnps;
};
std::vector<Bounds> m_bounds;
bool m_cropOutside;
std::vector<Polygon> m_polys;
SpatialReference m_assignedSrs;
double m_distance;
std::unique_ptr<CropArgs> m_args;
double m_distance2;
std::vector<filter::Point> m_centers;
std::vector<ViewGeom> m_geoms;
std::vector<BOX2D> m_boxes;

Expand Down
4 changes: 4 additions & 0 deletions filters/GreedyProjection.hpp
Expand Up @@ -39,6 +39,10 @@

#pragma once

// This is for M_PI on Windows. cmath
#define _USE_MATH_DEFINES
#include <math.h>

#include <fstream>
#include <iostream>

Expand Down
42 changes: 29 additions & 13 deletions filters/NormalFilter.cpp
Expand Up @@ -33,6 +33,7 @@
****************************************************************************/

#include "NormalFilter.hpp"
#include "private/Point.hpp"

#include <pdal/EigenUtils.hpp>
#include <pdal/KDIndex.hpp>
Expand All @@ -55,18 +56,33 @@ static StaticPluginInfo const s_info

CREATE_STATIC_STAGE(NormalFilter, s_info)

struct NormalArgs
{
int m_knn;
filter::Point m_viewpoint;
bool m_up;
};

NormalFilter::NormalFilter() : m_args(new NormalArgs)
{}


NormalFilter::~NormalFilter()
{}


std::string NormalFilter::getName() const
{
return s_info.name;
}

void NormalFilter::addArgs(ProgramArgs& args)
{
args.add("knn", "k-Nearest Neighbors", m_knn, 8);
m_viewpointArg =
&args.add("viewpoint", "Viewpoint as WKT or GeoJSON", m_viewpoint);
args.add("always_up", "Normals always oriented with positive Z?", m_up,
true);
args.add("knn", "k-Nearest Neighbors", m_args->m_knn, 8);
m_viewpointArg = &args.add("viewpoint",
"Viewpoint as WKT or GeoJSON", m_args->m_viewpoint);
args.add("always_up", "Normals always oriented with positive Z?",
m_args->m_up, true);
}

void NormalFilter::addDimensions(PointLayoutPtr layout)
Expand All @@ -80,7 +96,7 @@ void NormalFilter::addDimensions(PointLayoutPtr layout)
// public method to access filter, used by GreedyProjection and Poisson filters
void NormalFilter::doFilter(PointView& view, int knn)
{
m_knn = knn;
m_args->m_knn = knn;
ProgramArgs args;
addArgs(args);
// We're never parsing anything, so we'll just end up with default vals.
Expand All @@ -90,11 +106,11 @@ void NormalFilter::doFilter(PointView& view, int knn)

void NormalFilter::prepared(PointTableRef table)
{
if (m_up && m_viewpointArg->set())
if (m_args->m_up && m_viewpointArg->set())
{
log()->get(LogLevel::Warning)
<< "Viewpoint provided. Ignoring always_up = TRUE." << std::endl;
m_up = false;
m_args->m_up = false;
}
}

Expand All @@ -105,7 +121,7 @@ void NormalFilter::filter(PointView& view)
for (PointId i = 0; i < view.size(); ++i)
{
// find the k-nearest neighbors
auto ids = kdi.neighbors(i, m_knn);
auto ids = kdi.neighbors(i, m_args->m_knn);

// compute covariance of the neighborhood
auto B = eigen::computeCovariance(view, ids);
Expand All @@ -121,13 +137,13 @@ void NormalFilter::filter(PointView& view)
{
PointRef p = view.point(i);
Eigen::Vector3f vp(
m_viewpoint.x - p.getFieldAs<double>(Dimension::Id::X),
m_viewpoint.y - p.getFieldAs<double>(Dimension::Id::Y),
m_viewpoint.z - p.getFieldAs<double>(Dimension::Id::Z));
m_args->m_viewpoint.x - p.getFieldAs<double>(Dimension::Id::X),
m_args->m_viewpoint.y - p.getFieldAs<double>(Dimension::Id::Y),
m_args->m_viewpoint.z - p.getFieldAs<double>(Dimension::Id::Z));
if (vp.dot(normal) < 0)
normal *= -1.0;
}
else if (m_up)
else if (m_args->m_up)
{
if (normal[2] < 0)
normal *= -1.0;
Expand Down

0 comments on commit e7c2c5d

Please sign in to comment.