Commit 3d874bc8 authored by Nicolas Mellado's avatar Nicolas Mellado

Fix several bugs in Grenaille::GlViewer demo

parent 3b457f95
......@@ -3,10 +3,11 @@
FittingManager::FittingManager(QObject *parent) :
QObject(parent),
_fitType(FittingManager::PLANE_COV),
_mesh(NULL),
_mesh(nullptr),
_neiApproximation(new Mesh()),
_scale(0.02),
_evalPos(Mesh::Vector::Zero()),
_stateUpdateNei(false)
_stateUpdateNei(true)
{
}
void
......@@ -20,6 +21,7 @@ FittingManager::setBasketType(FIT_TYPE type){
void
FittingManager::setEvaluationPoint(const PatateCommon::GLTri3DMesh::Vector &pos){
_evalPos = pos;
_stateUpdateNei = true;
std::cout << __PRETTY_FUNCTION__ << std::endl;
emit evaluationPointChanged();
......@@ -30,6 +32,7 @@ FittingManager::setEvaluationPoint(const PatateCommon::GLTri3DMesh::Vector &pos)
void
FittingManager::setScale(float scale){
_scale = scale;
_stateUpdateNei = true;
std::cout << __PRETTY_FUNCTION__ << std::endl;
emit scaleChanged();
......@@ -40,6 +43,7 @@ FittingManager::setScale(float scale){
void
FittingManager::setScale(double scale){
_scale = scale;
_stateUpdateNei = true;
std::cout << __PRETTY_FUNCTION__ << std::endl;
emit scaleChanged();
......@@ -62,9 +66,9 @@ FittingManager::fitPrimitive(){
// - fit primitive
// - project nei vertices on primitive
//
_neiApproximation = Mesh();
if (_stateUpdateNei){
Mesh nei;
// accessing using UNSUPPORTED returns default params
typedef typename fittingmanagerspace::BasketMaker<UNSUPPORTED>::WeightFunc WFunc;
typedef typename Mesh::Vector VectorType;
......@@ -88,15 +92,16 @@ FittingManager::fitPrimitive(){
if (add){
_neiApproximation.addVertex(list[0].pos());
_neiApproximation.addVertex(list[1].pos());
_neiApproximation.addVertex(list[2].pos());
nei.addVertex(list[0].pos());
nei.addVertex(list[1].pos());
nei.addVertex(list[2].pos());
_neiApproximation.addFace(vertexId, vertexId+1, vertexId+2);
nei.addFace(vertexId, vertexId+1, vertexId+2);
vertexId += 3;
}
}
_neiApproximation->setFrom(nei);
}
......@@ -108,11 +113,9 @@ FittingManager::fitPrimitive(){
f.setWeightFunc(WFunc(_scale)); \
f.init(_evalPos); \
f.compute(_mesh->begin(), _mesh->end()); \
if (_stateUpdateNei){ \
for (Mesh::posIterator it = _mesh->vertexBegin(); \
it != _mesh->vertexEnd(); ++it) \
*it = f.project(*it); \
}
for (Mesh::posIterator it = _neiApproximation->vertexBegin(); \
it != _neiApproximation->vertexEnd(); ++it) \
*it = f.project(*it);
switch(_fitType){
......@@ -131,6 +134,14 @@ FittingManager::fitPrimitive(){
std::cout << "Kappa: " << f.kappa() << std::endl;
break;
}
case SPHERE:
{
COMPUTE(SPHERE);
std::cout << "Tau: " << f.tau() << std::endl;
std::cout << "Eta: " << f.eta().transpose() << std::endl;
std::cout << "Kappa: " << f.kappa() << std::endl;
break;
}
case UNSUPPORTED:
default:
return;
......@@ -145,7 +156,7 @@ FittingManager::fitPrimitive(){
* Internally, the weighting function is created, and used to select the vertices
* having an influence on the fit
*/
FittingManager::Mesh
FittingManager::computeNeighborhoodMeshApprox() const {
FittingManager::Mesh *
FittingManager::getNeighborhoodMeshApprox() {
return _neiApproximation;
}
......@@ -17,6 +17,7 @@ public:
enum FIT_TYPE {
PLANE_COV,
SPHERE_ORIENTED,
SPHERE,
UNSUPPORTED
};
......@@ -25,8 +26,8 @@ public:
inline void setMesh(Mesh* mesh) { _mesh = mesh; }
//! \brief Generate a new mesh that is an approximation of the current nei.
Mesh computeNeighborhoodMeshApprox() const;
//! \brief Getter on the projected mesh.
Mesh *getNeighborhoodMeshApprox();
signals:
//! \brief Signal emitted when the basket has been applied to the input data.
......@@ -40,15 +41,11 @@ public slots:
void setScale(float scale);
void setScale(double scale);
void fitPrimitive();
void setNeighborhoodApproxUpdate(bool update) {
_stateUpdateNei = update;
if(update) fitPrimitive();
}
private:
FIT_TYPE _fitType;
PatateCommon::GLTri3DMesh *_mesh;
PatateCommon::GLTri3DMesh _neiApproximation;
PatateCommon::GLTri3DMesh *_neiApproximation;
Scalar _scale;
typename Mesh::Vector _evalPos;
......@@ -66,15 +63,20 @@ struct BasketMaker {
template <>
struct BasketMaker<FittingManager::PLANE_COV>{
typedef Grenaille::DistWeightFunc<MyPoint,Grenaille::SmoothWeightKernel<MyPoint::Scalar> > WeightFunc;
typedef Grenaille::Basket<MyPoint,WeightFunc, Grenaille::CompactPlane,
Grenaille::CovariancePlaneFit> Basket;
typedef Grenaille::Basket<MyPoint,WeightFunc, Grenaille::CovariancePlaneFit> Basket;
};
template <>
struct BasketMaker<FittingManager::SPHERE_ORIENTED>{
typedef Grenaille::DistWeightFunc<MyPoint,Grenaille::SmoothWeightKernel<MyPoint::Scalar> > WeightFunc;
typedef Grenaille::Basket<MyPoint,WeightFunc, Grenaille::AlgebraicSphere,
Grenaille::OrientedSphereFit,
typedef Grenaille::Basket<MyPoint,WeightFunc, Grenaille::OrientedSphereFit,
Grenaille::GLSParam> Basket;
};
template <>
struct BasketMaker<FittingManager::SPHERE>{
typedef Grenaille::DistWeightFunc<MyPoint,Grenaille::SmoothWeightKernel<MyPoint::Scalar> > WeightFunc;
typedef Grenaille::Basket<MyPoint,WeightFunc, Grenaille::SphereFit,
Grenaille::GLSParam> Basket;
};
......
......@@ -36,8 +36,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(&_manager, SIGNAL(fitPerformed()),
this, SLOT(updateNeighborhoodMesh()));
connect(ui->_paramDisplayProjectedNei, SIGNAL(clicked(bool)),
&_manager, SLOT(setNeighborhoodApproxUpdate(bool)));
ui->_viewer->setNeighborhoodMesh(_manager.getNeighborhoodMeshApprox());
}
MainWindow::~MainWindow()
......@@ -78,5 +77,5 @@ void MainWindow::on__paramBasketType_currentIndexChanged(int index)
}
void MainWindow::updateNeighborhoodMesh(){
ui->_viewer->setNeighborhoodMesh(_manager.computeNeighborhoodMeshApprox());
ui->_viewer->update();
}
......@@ -20,7 +20,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>19</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
......@@ -59,6 +59,11 @@
<string>Oriented Sphere Fit</string>
</property>
</item>
<item>
<property name="text">
<string>Sphere Fit</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
......@@ -97,25 +102,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="_paramDisplayGroup">
<property name="title">
<string>Display</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="_paramDisplayProjectedNei">
<property name="toolTip">
<string>May slow down performances</string>
</property>
<property name="text">
<string>Show projected neighborhood</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
......@@ -200,13 +200,18 @@ void Viewer::paintGL()
{
qglClearColor(Qt::white);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_CULL_FACE);
if (_mesh != NULL){
draw(_mesh, _meshAttribs);
if(_pickedPointId != -1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw(&_neighborhoodMesh, _sphereAttribs);
if(_pickedPointId != -1) drawPicked();
{
draw(_mesh, _sphereAttribs);
glClear(/*GL_COLOR_BUFFER_BIT |*/ GL_DEPTH_BUFFER_BIT);
draw(_neighborhoodMesh, _meshAttribs);
} else {
draw(_mesh, _meshAttribs);
}
//if(_pickedPointId != -1) drawPicked();
}
}
......
......@@ -68,7 +68,7 @@ public:
public slots:
void setScale(double scale) { _scale = scale; update(); }
void setNeighborhoodMesh (const Mesh& mesh) { _neighborhoodMesh = mesh; update(); }
void setNeighborhoodMesh (Mesh* mesh) { _neighborhoodMesh = mesh; update(); }
signals:
void selectedPointChanged(const PatateCommon::GLTri3DMesh::Vector& point);
......@@ -118,8 +118,8 @@ private:
double _scale;
Mesh *_mesh;
Mesh _unitSphere, _neighborhoodMesh;
Mesh *_mesh, *_neighborhoodMesh;
Mesh _unitSphere;
MeshAttributesValues _meshAttribs, _sphereAttribs;
QTimer *_refreshTimer; // automatically update the view
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment