Skip to content

Commit

Permalink
Merge pull request #9 from poncateam/correct_fields_sign
Browse files Browse the repository at this point in the history
Correct fields sign
  • Loading branch information
nmellado authored Jan 26, 2024
2 parents 4ebb089 + 5f384a5 commit cb850a1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@
2d plot application displaying scalar fields reconstructed using [Ponca](https://poncateam.github.io/ponca/)


## Test different types of fits

<img width="500" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/baddf074-6e32-447d-83aa-21d16fcd8977">
<img width="500" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/aec9fa7c-ba5c-43b9-8953-56e8f8d2ed09">



## Test different scales

<img width="333" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/9d3e26b5-86f4-4248-965a-6fa0ed9497df">
<img width="333" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/7b605409-a38e-45f6-a0d2-b3bcc1e3b17e">
<img width="333" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/468eb5d9-711d-483e-a1af-ee6824905a57">

## Change display options

<img width="500" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/9b6497bb-c4c5-49e0-b42b-0a97d6fc37e6">
<img width="500" alt="image" src="https://github.com/poncateam/poncaplot/assets/6310221/e4221532-d32a-479f-82d3-66e7b394e037">


## Video

(old version)

https://github.com/poncateam/poncaplot/assets/6310221/a1885def-4135-4afa-b833-f2968697586f

Expand Down
2 changes: 1 addition & 1 deletion external/ponca
Submodule ponca updated 34 files
+6 −0 CHANGELOG
+4 −2 Ponca/src/Fitting/algebraicSphere.h
+1 −0 Ponca/src/Fitting/covarianceLineFit.h
+3 −1 Ponca/src/Fitting/covariancePlaneFit.h
+7 −0 Ponca/src/Fitting/defines.h
+3 −1 Ponca/src/Fitting/linePrimitive.h
+1 −0 Ponca/src/Fitting/meanPlaneFit.h
+2 −1 Ponca/src/Fitting/mlsSphereFitDer.h
+2 −1 Ponca/src/Fitting/mongePatch.h
+1 −0 Ponca/src/Fitting/orientedSphereFit.h
+3 −1 Ponca/src/Fitting/plane.h
+1 −0 Ponca/src/Fitting/sphereFit.h
+1 −0 Ponca/src/Fitting/unorientedSphereFit.h
+1 −1 Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeKNearestQueries.h
+1 −1 Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeNearestQueries.h
+6 −5 Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeQuery.h
+2 −2 Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeRangeQueries.h
+241 −109 Ponca/src/SpatialPartitioning/KdTree/kdTree.h
+50 −54 Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp
+4 −5 Ponca/src/SpatialPartitioning/KnnGraph/knnGraph.h
+58 −23 doc/src/ponca_module_spatialpartitioning.mdoc
+2 −2 examples/cpp/nanoflann/ponca_nanoflann.cpp
+2 −2 examples/cpp/ponca_basic_cpu.cpp
+2 −2 examples/cpp/ponca_customize_kdtree.cpp
+1 −1 examples/cpp/ponca_neighbor_search.cpp
+3 −3 tests/src/basket.cpp
+1 −1 tests/src/fit_monge_patch.cpp
+1 −1 tests/src/fit_plane.cpp
+5 −5 tests/src/gls_paraboloid_der.cpp
+1 −1 tests/src/plane_primitive.cpp
+1 −1 tests/src/projection.cpp
+4 −4 tests/src/queries_knearest.cpp
+6 −4 tests/src/queries_nearest.cpp
+13 −5 tests/src/queries_range.cpp
6 changes: 3 additions & 3 deletions src/dataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DataManager::savePointCloud(const std::string& path) const{
if( ! file.is_open() ) return false;

file << "# x y nx ny " << "\n";
for( const auto & p : m_tree.point_data() ){
for( const auto & p : m_tree.points() ){
file << p.pos().transpose() << " " << p.normal().transpose() << "\n";
}
file.close();
Expand Down Expand Up @@ -80,7 +80,7 @@ DataManager::computeNormals(int k){
// Set the evaluation position
fit.init(p);
// Fit plane (method compute handles multipass fitting
if (fit.computeWithIds(m_tree.k_nearest_neighbors(p, k), m_tree.point_data()) == Ponca::STABLE) {
if (fit.computeWithIds(m_tree.k_nearest_neighbors(p, k), m_tree.points()) == Ponca::STABLE) {
pp.z() = std::acos(fit.primitiveGradient().normalized().x());
} else
std::cerr << "Something weird happened here..." << std::endl;
Expand All @@ -92,7 +92,7 @@ void
DataManager::fitPointCloudToRange(const std::pair<float,float>& rangesEnd, const std::pair<float,float>& rangesStart){
if (m_points.empty()) return;
if (m_tree.node_count() == 0) updateKdTree();
auto aabb = m_tree.node_data()[0].getAabb();
auto aabb = m_tree.nodes()[0].getAabb();
if (aabb){
VectorType requestedSize {rangesEnd.first - rangesStart.first, rangesEnd.second - rangesStart.second};
VectorType scaleFactors = requestedSize.array() / aabb->diagonal().array();
Expand Down
2 changes: 1 addition & 1 deletion src/dataManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct MyKdTreeNode : Ponca::KdTreeCustomizableNode<Index, NodeIndex, DataPoint,
struct DataManager {
public:
// using KdTree = Ponca::KdTree<DataPoint>;
using KdTree = Ponca::KdTreeBase<Ponca::KdTreeDefaultTraits<DataPoint,MyKdTreeNode>>;
using KdTree = Ponca::KdTreeDenseBase<Ponca::KdTreeDefaultTraits<DataPoint,MyKdTreeNode>>;
using PointContainer = std::vector<nanogui::Vector3f>; // stores x,y,normal angle in radians
using VectorType = typename KdTree::VectorType;

Expand Down
2 changes: 1 addition & 1 deletion src/drawingPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct DisplayPoint : public DrawingPass {
const auto pLargeSize = 2.f*m_halfSize;
#pragma omp parallel for default(none) shared(points, buffer, w, h,pLargeSize)
for (int pid = 0; pid< points.point_count(); ++pid){
const auto& p = points.point_data()[pid];
const auto& p = points.points()[pid];
// Build vector that is orthogonal to the normal vector
const VectorType& tangent {p.normal().y(), -p.normal().x()};
int i (std::floor(p.pos().x()));
Expand Down
8 changes: 4 additions & 4 deletions src/drawingPasses/distanceField.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
struct DistanceField : public DrawingPass {
inline explicit DistanceField() : DrawingPass() {}
void render(const DataManager::KdTree& points, float*buffer, int w, int h) override {
if(points.point_data().empty())
if(points.points().empty())
{
buffer[1] = ColorMap::NO_FIELD;
return;
Expand All @@ -17,7 +17,7 @@ struct DistanceField : public DrawingPass {
for (int i = 0; i < w; ++i) {
auto *b = buffer + (i + j * w) * 4;
float minDist {float(w*h)}; //distance should necessarily be smaller
for (const auto &p : points.point_data()) {
for (const auto &p : points.points()) {
int u(std::floor(p.pos().x()));
int v(std::floor(p.pos().y()));
auto dist = float(std::sqrt((i-u)*(i-u) + (j-v)*(j-v)));
Expand All @@ -35,7 +35,7 @@ struct DistanceField : public DrawingPass {
struct DistanceFieldWithKdTree : public DrawingPass {
inline explicit DistanceFieldWithKdTree() : DrawingPass() {}
void render(const DataManager::KdTree& points, float*buffer, int w, int h) override{
if(points.point_data().empty())
if(points.points().empty())
{
buffer[1] = ColorMap::NO_FIELD;
return;
Expand All @@ -49,7 +49,7 @@ struct DistanceFieldWithKdTree : public DrawingPass {
DataPoint::VectorType query (i, j);
auto res = points.nearest_neighbor( query );
if(res.begin()!=res.end()) {
auto nei = points.point_data()[res.get()].pos();
auto nei = points.points()[res.get()].pos();
float dist = (nei-query).norm();
b[0] = dist;
b[2] = ColorMap::VALUE_IS_VALID;
Expand Down
8 changes: 4 additions & 4 deletions src/drawingPasses/poncaFitField.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct FitField : public BaseFitField {
virtual void postProcess(FitType& /*fit*/){};

void render(const DataManager::KdTree& points, float*buffer, int w, int h) override{
if(points.point_data().empty()) return;
if(points.points().empty()) return;

float maxVal = 0;
#pragma omp parallel for collapse(2) default(none) shared(points, buffer, w, h) reduction(max : maxVal)
Expand All @@ -38,7 +38,7 @@ struct FitField : public BaseFitField {
for (int iter = 0; iter != m_iter; ++iter) {
fit.init(query);
// Fit plane (method compute handles multipass fitting
if (fit.computeWithIds(points.range_neighbors(query, m_scale), points.point_data()) ==
if (fit.computeWithIds(points.range_neighbors(query, m_scale), points.points()) ==
Ponca::STABLE) {
query = fit.project(query);
}
Expand All @@ -49,8 +49,8 @@ struct FitField : public BaseFitField {
float dist = fit.potential({i,j});
if (std::abs(dist)> maxVal) maxVal = std::abs(dist);

b[0] = dist; // set pixel value
b[3] = ColorMap::SCALAR_FIELD; // set field type
b[0] = fit.isSigned() ? dist : std::abs(dist); // set pixel value
b[3] = ColorMap::SCALAR_FIELD; // set field type
}
}
}
Expand Down

0 comments on commit cb850a1

Please sign in to comment.