Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli #12

Merged
merged 11 commits into from
Feb 2, 2024
Prev Previous commit
Next Next commit
Centralise DrawingPasses storage and creation in DataManager
  • Loading branch information
nmellado committed Jan 26, 2024
commit 20f44941c93a1cf152010144107bf80a5049e3ad
37 changes: 17 additions & 20 deletions src/application.cpp
Original file line number Diff line number Diff line change
@@ -32,14 +32,12 @@ Screen(Vector2i(1200, 1024), "PoncaPlot"), m_dataMgr(mgr){

m_dataMgr->setKdTreePostUpdateFunction([this]() { this->renderPasses(); });

passDFWithKdTree = new DistanceFieldWithKdTree();
passPlaneFit = new PlaneFitField();
passSphereFit = new SphereFitField();
passOrientedSphereFit = new OrientedSphereFitField();
passUnorientedSphereFit = new UnorientedSphereFitField();
// force creation of all supported DrawingPasses
for(int i=0;i!=m_dataMgr->nbSupportedDrawingPasses;++i)
m_dataMgr->getDrawingPass(i);

m_passes[0] = new FillPass( {1,1,1,1});
m_passes[1] = passOrientedSphereFit;
m_passes[1] = m_dataMgr->getDrawingPass("Oriented Sphere");
m_passes[2] = new ColorMap({1,1,1,1});
m_passes[3] = new DisplayPoint({0,0,0,1});

@@ -98,22 +96,16 @@ Screen(Vector2i(1200, 1024), "PoncaPlot"), m_dataMgr(mgr){


new nanogui::Label(window, "Select Fit Type", "sans-bold");
auto combo =new nanogui::ComboBox(window,
{ "Distance Field",
"Plane",
"Sphere",
"Oriented Sphere",
"Unoriented Sphere"});

std::vector<std::string> names;
names.resize(m_dataMgr->nbSupportedDrawingPasses);
for (const auto& p : m_dataMgr->supportedDrawingPasses)
names[p.second] = p.first;

auto combo =new nanogui::ComboBox(window, names);
combo->set_selected_index(3);
combo->set_callback([this](int id){
switch (id) {
case 0: m_passes[1] = passDFWithKdTree; break;
case 1: m_passes[1] = passPlaneFit; break;
case 2: m_passes[1] = passSphereFit; break;
case 3: m_passes[1] = passOrientedSphereFit; break;
case 4: m_passes[1] = passUnorientedSphereFit; break;
default: throw std::runtime_error("Unknown Field type!");
}
m_passes[1] = m_dataMgr->getDrawingPass(id);
buildPassInterface(id);
renderPasses();
});
@@ -141,6 +133,11 @@ Screen(Vector2i(1200, 1024), "PoncaPlot"), m_dataMgr(mgr){
new nanogui::Label(distanceFieldWidget, "no parameter available");
}

passPlaneFit = dynamic_cast<BaseFitField*>(m_dataMgr->getDrawingPass("Plane"));
passSphereFit = dynamic_cast<BaseFitField*>(m_dataMgr->getDrawingPass("Sphere"));
passOrientedSphereFit = dynamic_cast<BaseFitField*>(m_dataMgr->getDrawingPass("Oriented Sphere"));
passUnorientedSphereFit = dynamic_cast<BaseFitField*>(m_dataMgr->getDrawingPass("Unoriented Sphere"));

{
genericFitWidget = new nanogui::Widget(window);
genericFitWidget->set_layout(new GroupLayout());
8 changes: 3 additions & 5 deletions src/application.h
Original file line number Diff line number Diff line change
@@ -46,9 +46,7 @@ class PoncaPlotApplication : public nanogui::Screen {
*genericFitWidget, //< parameters applicable to all fitting techniques
*planeFitWidget, *sphereFitWidget, *orientedSphereFitWidget, *unorientedSphereFitWidget,
*pass3Widget,*pass4Widget;
DistanceFieldWithKdTree *passDFWithKdTree;
PlaneFitField *passPlaneFit;
SphereFitField *passSphereFit;
OrientedSphereFitField *passOrientedSphereFit;
UnorientedSphereFitField *passUnorientedSphereFit;


BaseFitField* passPlaneFit, *passSphereFit, *passOrientedSphereFit, *passUnorientedSphereFit;
};
42 changes: 42 additions & 0 deletions src/dataManager.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,15 @@
#include <iostream>
#include <fstream>

DataManager::DataManager() {
m_drawingPasses.fill(nullptr);
}

DataManager::~DataManager() {
for (auto* p : m_drawingPasses)
delete p;
}

bool
DataManager::savePointCloud(const std::string& path) const{
if( path.empty() ) return false;
@@ -106,3 +115,36 @@ DataManager::fitPointCloudToRange(const std::pair<float,float>& rangesEnd, const
}
}

DrawingPass*
DataManager::getDrawingPass(const std::string& name){
return getDrawingPass(supportedDrawingPasses.at(name));
}

DrawingPass*
DataManager::getDrawingPass(size_t index){
if (index >= nbSupportedDrawingPasses) return nullptr;

DrawingPass** p = &(m_drawingPasses[index]);
if((*p) == nullptr) {
switch (index) {
case 0: //Distance Field
*p = new DistanceFieldWithKdTree();
break;
case 1: // Plane
*p = new PlaneFitField();
break;
case 2: // Sphere
*p = new SphereFitField();
break;
case 3: // Oriented Sphere
*p = new OrientedSphereFitField();
break;
case 4: // Unoriented Sphere
*p = new UnorientedSphereFitField();
break;
default:
break;
}
}
return *p;
}
51 changes: 51 additions & 0 deletions src/dataManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <map>
#include <optional>
#include <utility> //pair
#include <vector>
@@ -11,6 +12,8 @@
#include <Ponca/SpatialPartitioning>

#include "poncaTypes.h"
#include "drawingPasses/distanceField.h"
#include "drawingPasses/poncaFitField.h"


#ifndef M_PI
@@ -20,6 +23,8 @@
#define DEFAULT_POINT_ANGLE M_PI / 2.


struct DrawingPass;

/// Structure holding shared data
struct DataManager {
public:
@@ -28,6 +33,9 @@ struct DataManager {
using PointContainer = std::vector<nanogui::Vector3f>; // stores x,y,normal angle in radians
using VectorType = typename KdTree::VectorType;

DataManager();
~DataManager();

/// Read access to point collection
inline const KdTree& getKdTree() const { return m_tree; }

@@ -62,9 +70,52 @@ struct DataManager {
/// \param Number of neighbors (3 means current point and 2 closest points: left and right)
void computeNormals(int k = 3);

/// Names of the supported drawing passes
static constexpr size_t nbSupportedDrawingPasses = 5;
const std::map<const std::string, size_t> supportedDrawingPasses {
{"Distance Field", 0},
{"Plane", 1},
{"Sphere", 2},
{"Oriented Sphere", 3},
{"Unoriented Sphere", 4}
};

DrawingPass* getDrawingPass(const std::string& name);

/// Build a a drawing pass
/// \param index of the pass name in supportedDrawingPasses
DrawingPass* getDrawingPass(size_t index);

template <typename Functor>
bool processPass(int index, Functor f) {
switch (index) {
case 0: //Distance Field
f(dynamic_cast<DistanceFieldWithKdTree*>(getDrawingPass(0)));
break;
case 1: // Plane
f(dynamic_cast<PlaneFitField*>(getDrawingPass(1)));
break;
case 2: // Sphere
f(dynamic_cast<SphereFitField*>(getDrawingPass(2)));
break;
case 3: // Oriented Sphere
f(dynamic_cast<OrientedSphereFitField*>(getDrawingPass(3)));
break;
case 4: // Unoriented Sphere
f(dynamic_cast<UnorientedSphereFitField*>(getDrawingPass(4)));
break;
default:
return false;
}
return true;
}


private:
PointContainer m_points;
KdTree m_tree;
std::function<void()> m_updateFunction {[](){}};

std::array<DrawingPass*,nbSupportedDrawingPasses> m_drawingPasses;
};