Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/dataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ DataManager::loadPointCloud(const std::string& path){

void
DataManager::computeNormals(int k){
using WeightFunc = Ponca::DistWeightFunc<DataPoint,Ponca::ConstantWeightKernel<typename DataPoint::Scalar> >;
using PlaneFit = Ponca::Basket<DataPoint ,WeightFunc, Ponca::CovariancePlaneFit>;
using NeighborFilter = Ponca::DistWeightFunc<DataPoint,Ponca::ConstantWeightKernel<typename DataPoint::Scalar> >;
using PlaneFit = Ponca::Basket<DataPoint, NeighborFilter, Ponca::CovariancePlaneFit>;

std::cout << "Recompute normals" << std::endl;

for (auto& pp : m_points){
VectorType p {pp.x(),pp.y()};
PlaneFit fit;
fit.setWeightFunc(WeightFunc());
// Set the evaluation position
fit.init(p);
fit.setNeighborFilter(NeighborFilter(p));
// Fit plane (method compute handles multipass fitting
if (fit.computeWithIds(m_tree.k_nearest_neighbors(p, k), m_tree.points()) == Ponca::STABLE) {
pp.z() = std::acos(fit.primitiveGradient().normalized().x());
Expand Down
14 changes: 6 additions & 8 deletions src/drawingPasses/bestFieldFit.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct SingleFitField : public _Base {

using Base = _Base;
using FitType = _FitType;
using WeightFunc = typename FitType::WeightFunction;
using NeighborFilter = typename FitType::NeighborFilter;

virtual float configureAndFit(const KdTree& points, FitType& fit, RenderingContext ctx) = 0;

Expand Down Expand Up @@ -71,16 +71,15 @@ struct BestFitField : public SingleFitField<_FitType, DrawingPass> {
~BestFitField() override = default;

using FitType = _FitType;
using WeightFunc = typename FitType::WeightFunction;
using NeighborFilter = typename FitType::NeighborFilter;

/// Method called at the end of the fitting process, only for stable fits
virtual void postProcess(FitType& /*fit*/){};

inline float configureAndFit(const KdTree& points, FitType& fit, RenderingContext ctx) override {
// Configure computation to be centered on the point cloud coordinates
float scale = points.nodes()[0].getAabb()->diagonal().norm();
fit.setWeightFunc(WeightFunc(scale));
fit.init(points.nodes()[0].getAabb()->center());
fit.setNeighborFilter(NeighborFilter(points.nodes()[0].getAabb()->center(), scale));
// Compute fit
fit.compute(points.points());
postProcess(fit);
Expand All @@ -106,19 +105,18 @@ struct OnePointFitField : public SingleFitField<_FitType, BaseFitField>, public
~OnePointFitField() override = default;

using FitType = _FitType;
using WeightFunc = typename FitType::WeightFunction;
using NeighborFilter = typename FitType::NeighborFilter;
using Scalar = typename FitType::Scalar;

/// Method called at the end of the fitting process, only for stable fits
virtual void postProcess(FitType& /*fit*/){};

inline float configureAndFit(const KdTree& points, FitType& fit, RenderingContext ctx) override {
// Configure computation to be centered on the point cloud coordinates
fit.setWeightFunc(WeightFunc(BaseFitField::params.m_scale));
auto query = points.points()[pointId].pos();
// Compute fit
for (int iter = 0; iter != BaseFitField::params.m_iter; ++iter) {
fit.init(query);
// Configure computation to be centered on the point cloud coordinates
fit.setNeighborFilter(NeighborFilter(query, BaseFitField::params.m_scale));
if (fit.computeWithIds(points.range_neighbors(query, BaseFitField::params.m_scale), points.points()) ==
Ponca::STABLE) {
postProcess(fit);
Expand Down
15 changes: 6 additions & 9 deletions src/drawingPasses/poncaFitField.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct FitField : public BaseFitField {
~FitField() override = default;

using FitType = _FitType;
using WeightFunc = typename FitType::WeightFunction;
using NeighborFilter = typename FitType::NeighborFilter;

/// Method called at the end of the fitting process, only for stable fits
virtual void postProcess(FitType& /*fit*/){};
Expand All @@ -36,11 +36,10 @@ struct FitField : public BaseFitField {
DataPoint::VectorType query (coord.first, coord.second);

FitType fit;
// Set a weighting function instance
fit.setWeightFunc(WeightFunc(params.m_scale));
// Set the evaluation position
for (int iter = 0; iter != params.m_iter; ++iter) {
fit.init(query);
// Set a weighting function instance
fit.setNeighborFilter(NeighborFilter(query, params.m_scale));
// Fit plane (method compute handles multipass fitting
if (fit.computeWithIds(points.range_neighbors(query, params.m_scale), points.points()) ==
Ponca::STABLE) {
Expand Down Expand Up @@ -81,23 +80,21 @@ struct FitField : public BaseFitField {
float potential {0.f};
do {
FitType fit;
// Set a weighting function instance
fit.setWeightFunc(WeightFunc(params.m_scale));

// Set the evaluation position
for (int iter = 0; iter != params.m_iter; ++iter) {
x = nextx;

// project to next location and draw
fit.init(x);
// Set a weighting function instance
fit.setNeighborFilter(NeighborFilter(x, params.m_scale));
if (fit.computeWithIds(points.range_neighbors(x, params.m_scale), points.points()) ==
Ponca::STABLE) {
postProcess(fit);
nextx = fit.project(x);
potential = fit.potential(nextx);

// ask to stop the projection procedure if motion is below one pixel
int nbPix = bresenham(ctx.pointToPix( x ) , ctx.pointToPix( nextx ),
int nbPix = bresenham(ctx.pointToPix( x ), ctx.pointToPix( nextx ),
{ctx.w, ctx.h},
[buffer, ctx](int x, int y){
auto *b = buffer + (x + y * ctx.w) * 4;
Expand Down
18 changes: 9 additions & 9 deletions src/poncaTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class DataPoint
VectorType m_pos, m_normal;
};

using WeightFunc = Ponca::DistWeightFunc<DataPoint,Ponca::SmoothWeightKernel<typename DataPoint::Scalar> >;
using ConstWeightFunc = Ponca::DistWeightFunc<DataPoint,Ponca::ConstantWeightKernel<typename DataPoint::Scalar> >;
using WeightFunc = Ponca::DistWeightFunc<DataPoint,Ponca::SmoothWeightKernel<DataPoint::Scalar> >;
using ConstWeightFunc = Ponca::DistWeightFunc<DataPoint,Ponca::ConstantWeightKernel<DataPoint::Scalar> >;

using PlaneFit = Ponca::Basket<DataPoint ,WeightFunc, Ponca::CovariancePlaneFit>;
using ConstPlaneFit = Ponca::Basket<DataPoint ,ConstWeightFunc, Ponca::CovariancePlaneFit>;
using SphereFit = Ponca::Basket<DataPoint ,WeightFunc, Ponca::SphereFit>;
using ConstSphereFit = Ponca::Basket<DataPoint ,ConstWeightFunc, Ponca::SphereFit>;
using OrientedSphereFit= Ponca::Basket<DataPoint ,WeightFunc, Ponca::OrientedSphereFit>;
using ConstOrientedSphereFit= Ponca::Basket<DataPoint ,ConstWeightFunc, Ponca::OrientedSphereFit>;
using UnorientedSphereFit = Ponca::Basket<DataPoint ,WeightFunc, Ponca::UnorientedSphereFit>;
using PlaneFit = Ponca::Basket<DataPoint, WeightFunc, Ponca::CovariancePlaneFit>;
using ConstPlaneFit = Ponca::Basket<DataPoint, ConstWeightFunc, Ponca::CovariancePlaneFit>;
using SphereFit = Ponca::Basket<DataPoint, WeightFunc, Ponca::SphereFit>;
using ConstSphereFit = Ponca::Basket<DataPoint, ConstWeightFunc, Ponca::SphereFit>;
using OrientedSphereFit= Ponca::Basket<DataPoint, WeightFunc, Ponca::OrientedSphereFit>;
using ConstOrientedSphereFit= Ponca::Basket<DataPoint, ConstWeightFunc, Ponca::OrientedSphereFit>;
using UnorientedSphereFit = Ponca::Basket<DataPoint, WeightFunc, Ponca::UnorientedSphereFit>;



Expand Down
Loading