Skip to content

Commit

Permalink
Hook greedy triangulation into filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 17, 2017
1 parent 727f94f commit 2cd676f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 15 deletions.
20 changes: 17 additions & 3 deletions filters/GreedyProjection.cpp
Expand Up @@ -38,12 +38,25 @@
#include <cassert>

#include <pdal/KDIndex.hpp>
#include <pdal/pdal_macros.hpp>

#include "GreedyProjection.hpp"

namespace pdal
{

static PluginInfo const s_info =
PluginInfo("filters.greedygrid", "Greedy Triangulation filter",
"http://pdal.io/stages/filters.greedygrid.html");

CREATE_STATIC_PLUGIN(1, 0, GreedyProjection, Filter, s_info)

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


void GreedyProjection::addArgs(ProgramArgs& args)
{
args.add("multiplier", "Nearest neighbor distance multiplier",
Expand Down Expand Up @@ -96,13 +109,14 @@ Eigen::Vector3d GreedyProjection::getNormalCoord(PointId id)

void GreedyProjection::addTriangle(PointId a, PointId b, PointId c)
{
grid_.emplace_back(a, b, c);
view_->mesh().add(a, b, c);
}


void GreedyProjection::filter(PointView& view)
{
KD3Index tree(view);
tree.build();

view_ = &view;
const double sqr_mu = mu_ * mu_;
Expand Down Expand Up @@ -1170,8 +1184,8 @@ void GreedyProjection::filter(PointView& view)
}
}
}
log()->get(LogLevel::Debug) << "Number of triangles: " << grid_.size() <<
".\n";
log()->get(LogLevel::Debug) << "Number of triangles: " <<
view_->mesh().size() << ".\n";
log()->get(LogLevel::Debug) << "Number of unconnected parts: " << nr_parts <<
".\n";
if (increase_nnn4fn > 0)
Expand Down
20 changes: 8 additions & 12 deletions filters/GreedyProjection.hpp
Expand Up @@ -42,8 +42,12 @@
#include <fstream>
#include <iostream>
#include <pdal/Filter.hpp>
#include <pdal/plugin.hpp>
#include <Eigen/Dense>

extern "C" int32_t GreedyProjection_ExitFunc();
extern "C" PF_ExitFunc GreedyProjection_InitPlugin();

namespace pdal
{
/** \brief Returns if a point X is visible from point R (or the origin)
Expand Down Expand Up @@ -177,6 +181,10 @@ namespace pdal
view_(nullptr)
{};

static void * create();
static int32_t destroy(void *);
std::string getName() const;

/** \brief Don't consider points for triangulation if their normal deviates more than this value from the query point's normal.
* \param[in] eps_angle maximum surface angle
* \note As normal estimation methods usually give smooth transitions at sharp edges, this ensures correct triangulation
Expand Down Expand Up @@ -270,16 +278,6 @@ namespace pdal
Eigen::Vector2d second;
};

struct Triangle
{
Triangle(PointId ta, PointId tb, PointId tc) : a(ta), b(tb), c(tc)
{}

PointId a;
PointId b;
PointId c;
};

// Variables made global to decrease the number of parameters to helper functions

/** \brief A list of angles to neighbors **/
Expand Down Expand Up @@ -338,8 +336,6 @@ namespace pdal
Eigen::Vector2d uvn_next_sfn_;
/** \brief Temporary variable to store 3 coordiantes **/
Eigen::Vector3d tmp_;
/** \brief Output grid **/
std::vector<Triangle> grid_;
/** \brief Pointer to current point view. **/
PointView *view_;

Expand Down
71 changes: 71 additions & 0 deletions pdal/Mesh.hpp
@@ -0,0 +1,71 @@
/******************************************************************************
* Copyright (c) 2017, Hobu Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#pragma once

#include <deque>

namespace pdal
{

class Triangle
{
public:
Triangle(PointId a, PointId b, PointId c) : m_a(a), m_b(b), m_c(c)
{}

PointId m_a;
PointId m_b;
PointId m_c;
};

/**
A mesh is a way to represent a set of points connected by edges. Point
indices are into a
*/
class PDAL_DLL TriangularMesh
{
public:
TriangularMesh()
{}

size_t size() const
{ return m_index.size(); }
void add(PointId a, PointId b, PointId c)
{ m_index.emplace_back(a, b, c); }
protected:
std::deque<Triangle> m_index;
};

} // namespace pdal
5 changes: 5 additions & 0 deletions pdal/PointView.hpp
Expand Up @@ -36,6 +36,7 @@

#include <pdal/DimDetail.hpp>
#include <pdal/DimType.hpp>
#include <pdal/Mesh.hpp>
#include <pdal/PointContainer.hpp>
#include <pdal/PointLayout.hpp>
#include <pdal/PointRef.hpp>
Expand Down Expand Up @@ -272,6 +273,9 @@ class PDAL_DLL PointView : public PointContainer
}
MetadataNode toMetadata() const;

TriangularMesh& mesh()
{ return m_mesh; }

protected:
PointTableRef m_pointTable;
std::deque<PointId> m_index;
Expand All @@ -281,6 +285,7 @@ class PDAL_DLL PointView : public PointContainer
int m_id;
std::queue<PointId> m_temps;
SpatialReference m_spatialReference;
TriangularMesh m_mesh;

private:
static int m_lastId;
Expand Down
2 changes: 2 additions & 0 deletions pdal/StageFactory.cpp
Expand Up @@ -50,6 +50,7 @@
#include <filters/ELMFilter.hpp>
#include <filters/EstimateRankFilter.hpp>
#include <filters/FerryFilter.hpp>
#include <filters/GreedyProjection.hpp>
#include <filters/GroupByFilter.hpp>
#include <filters/HAGFilter.hpp>
#include <filters/IQRFilter.hpp>
Expand Down Expand Up @@ -251,6 +252,7 @@ StageFactory::StageFactory(bool no_plugins)
PluginManager::initializePlugin(ELMFilter_InitPlugin);
PluginManager::initializePlugin(EstimateRankFilter_InitPlugin);
PluginManager::initializePlugin(FerryFilter_InitPlugin);
PluginManager::initializePlugin(GreedyProjection_InitPlugin);
PluginManager::initializePlugin(GroupByFilter_InitPlugin);
PluginManager::initializePlugin(HAGFilter_InitPlugin);
PluginManager::initializePlugin(IQRFilter_InitPlugin);
Expand Down

0 comments on commit 2cd676f

Please sign in to comment.