mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-19 02:54:36 +00:00
Added a blue disk for the visualization of the point fitted in the plane fitting selection tool.
This commit is contained in:
parent
cdb95d0e18
commit
80e84d1f2d
@ -22,7 +22,7 @@ template <typename _MyMeshType, typename _MyVertexType>
|
||||
class ComponentFinder {
|
||||
public:
|
||||
static std::vector<_MyVertexType*> &FindComponent(_MyMeshType& m, _MyVertexType& v, int numOfNeighbours, int numOfHop);
|
||||
static std::vector<_MyVertexType*> &FindComponent(_MyMeshType& m, _MyVertexType& v, int numOfNeighbours, float dim, float maxHopDist, vector<_MyVertexType*> &borderVect, vector<_MyVertexType*> ¬ReachableVect, bool fitting = false, float planeDim = 0.0, float distanceFromPlane = 0.0);
|
||||
static std::vector<_MyVertexType*> &FindComponent(_MyMeshType& m, float dim, vector<_MyVertexType*> &borderVect, vector<_MyVertexType*> ¬ReachableVect, bool fitting = false, float planeDim = 0.0, float distanceFromPlane = 0.0, Plane3<typename _MyMeshType::ScalarType> *fittingPlane = NULL);
|
||||
|
||||
static void DeletePerVertexAttribute(_MyMeshType& m);
|
||||
|
||||
@ -81,9 +81,6 @@ std::vector<_MyVertexType*> &ComponentFinder<_MyMeshType, _MyVertexType>::FindCo
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename _MyMeshType, typename _MyVertexType>
|
||||
class Compare {
|
||||
private:
|
||||
@ -106,7 +103,7 @@ public:
|
||||
* maximum distance we want between two vertex (with the Shortest Path we also compute the geodesic distance)
|
||||
**/
|
||||
template <typename _MyMeshType, typename _MyVertexType>
|
||||
std::vector<_MyVertexType*> &ComponentFinder<_MyMeshType, _MyVertexType>::FindComponent(_MyMeshType& m, _MyVertexType& v, int numOfNeighbours, float dim, float maxHopDist, vector<_MyVertexType*> &borderVect, vector<_MyVertexType*> ¬ReachableVect, bool fitting, float planeDim, float distanceFromPlane) {
|
||||
std::vector<_MyVertexType*> &ComponentFinder<_MyMeshType, _MyVertexType>::FindComponent(_MyMeshType& m, float dim, vector<_MyVertexType*> &borderVect, vector<_MyVertexType*> ¬ReachableVect, bool fitting, float planeDim, float distanceFromPlane, Plane3<typename _MyMeshType::ScalarType> *fittingPlane) {
|
||||
vector<_MyVertexType*> *resultVect = new vector<_MyVertexType*>();
|
||||
vector<typename _MyMeshType::CoordType> pointToFit = vector<typename _MyMeshType::CoordType>();
|
||||
|
||||
@ -119,8 +116,6 @@ std::vector<_MyVertexType*> &ComponentFinder<_MyMeshType, _MyVertexType>::FindCo
|
||||
if (hasDistParam) distFromCenter = vcg::tri::Allocator<_MyMeshType>::template GetPerVertexAttribute<float>(m, std::string("DistParam"));
|
||||
else return *resultVect;
|
||||
|
||||
QTime t;
|
||||
t.start();
|
||||
for (typename _MyMeshType::VertexIterator vi = m.vert.begin(); vi != m.vert.end(); vi++) {
|
||||
if (fitting) {
|
||||
if (distFromCenter[vi] < planeDim) {
|
||||
@ -129,25 +124,17 @@ std::vector<_MyVertexType*> &ComponentFinder<_MyMeshType, _MyVertexType>::FindCo
|
||||
}
|
||||
else if (distFromCenter[vi] < dim) resultVect->push_back(&*vi);
|
||||
}
|
||||
//printf("FindComponent linear: %d ms\n", t.elapsed());
|
||||
|
||||
|
||||
typename vector<_MyVertexType*>::iterator it;
|
||||
if (fitting) {
|
||||
Plane3<typename _MyMeshType::ScalarType> fittingPlane = Plane3<typename _MyMeshType::ScalarType>();
|
||||
|
||||
//QTime t2;
|
||||
//t2.start();
|
||||
vcg::PlaneFittingPoints(pointToFit, fittingPlane);
|
||||
//printf("plane fitting: %d ms\n", t2.elapsed());
|
||||
vcg::PlaneFittingPoints(pointToFit, *fittingPlane);
|
||||
|
||||
for (typename _MyMeshType::VertexIterator vi = m.vert.begin(); vi != m.vert.end(); vi++) {
|
||||
if (distFromCenter[vi] < dim && math::Abs(vcg::SignedDistancePlanePoint<typename _MyMeshType::ScalarType>(fittingPlane, vi->cP())) < distanceFromPlane) resultVect->push_back(&*vi);
|
||||
if (distFromCenter[vi] < dim && math::Abs(vcg::SignedDistancePlanePoint<typename _MyMeshType::ScalarType>(*fittingPlane, vi->cP())) < distanceFromPlane) resultVect->push_back(&*vi);
|
||||
}
|
||||
for (it = notReachableVect.begin(); it != notReachableVect.end(); it++) {
|
||||
if (distFromCenter[*it] < dim && math::Abs(vcg::SignedDistancePlanePoint<typename _MyMeshType::ScalarType>(fittingPlane, (*it)->cP())) < distanceFromPlane) borderVect.push_back(*it);
|
||||
if (distFromCenter[*it] < dim && math::Abs(vcg::SignedDistancePlanePoint<typename _MyMeshType::ScalarType>(*fittingPlane, (*it)->cP())) < distanceFromPlane) borderVect.push_back(*it);
|
||||
}
|
||||
//printf("FindComponent FITTING: %d ms\n", t.elapsed());
|
||||
}
|
||||
else {
|
||||
for (it = notReachableVect.begin(); it != notReachableVect.end(); it++) {
|
||||
@ -172,12 +159,9 @@ void ComponentFinder<_MyMeshType, _MyVertexType>::Dijkstra(_MyMeshType& m, _MyVe
|
||||
}
|
||||
else distFromCenter = vcg::tri::Allocator<_MyMeshType>::template GetPerVertexAttribute<float>(m, std::string("DistParam"));
|
||||
|
||||
//QTime t;
|
||||
//t.start();
|
||||
if (!hasKNNGraph) {
|
||||
KNNTree<_MyMeshType, _MyVertexType>::MakeKNNTree(m, numOfNeighbours);
|
||||
}
|
||||
//printf("KNNGraph Creation: %d ms\n", t.elapsed());
|
||||
|
||||
typename _MyMeshType::template PerVertexAttributeHandle<vector<_MyVertexType*>* > neighboursVect = vcg::tri::Allocator<_MyMeshType>::template GetPerVertexAttribute<vector<_MyVertexType*>* >(m,"KNNGraph");
|
||||
|
||||
|
||||
@ -31,6 +31,8 @@
|
||||
#include <wrap/qt/gl_label.h>
|
||||
#include <vcg/space/fitting3.h>
|
||||
|
||||
#include <vcg/complex/algorithms/create/platonic.h>
|
||||
|
||||
#include "connectedComponent.h"
|
||||
|
||||
|
||||
@ -56,11 +58,8 @@ void EditPointPlugin::Decorate(MeshModel &m, GLArea * gla, QPainter *p)
|
||||
if(NewSel.size() > 0) {
|
||||
startingVertex = NewSel.front();
|
||||
|
||||
//timer.start();
|
||||
ComponentFinder<CMeshO, CVertexO>::Dijkstra(m.cm, *startingVertex, k, this->maxHop, this->NotReachableVector);
|
||||
|
||||
//printf("ComponentFinder in Decorate::Dijkstra: %d ms\n", timer.elapsed());
|
||||
|
||||
ComponentVector.push_back(startingVertex);
|
||||
}
|
||||
|
||||
@ -110,7 +109,7 @@ void EditPointPlugin::Decorate(MeshModel &m, GLArea * gla, QPainter *p)
|
||||
}
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glColor4f(1,0,0,.6f);
|
||||
glColor4f(1,0,0,.5f);
|
||||
|
||||
for (CMeshO::VertexIterator vi = m.cm.vert.begin(); vi != m.cm.vert.end(); vi++) {
|
||||
if (vi->IsS()) glVertex(vi->cP());
|
||||
@ -119,7 +118,7 @@ void EditPointPlugin::Decorate(MeshModel &m, GLArea * gla, QPainter *p)
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glColor4f(1,1,0,.6f);
|
||||
glColor4f(1,1,0,.5f);
|
||||
|
||||
for(vector<CMeshO::VertexPointer>::iterator vi = BorderVector.begin(); vi != BorderVector.end(); ++vi)
|
||||
{
|
||||
@ -128,6 +127,24 @@ void EditPointPlugin::Decorate(MeshModel &m, GLArea * gla, QPainter *p)
|
||||
|
||||
glEnd();
|
||||
|
||||
if (editType == SELECT_FITTING_PLANE_MODE) {
|
||||
fittingCircle.Clear();
|
||||
vcg::tri::OrientedDisk<CMeshO>(fittingCircle, 192, fittingPlane.Projection(startingVertex->cP()), fittingPlane.Direction(), this->fittingRadius);
|
||||
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glColor4f(0.69,0.93,0.93,.7f);
|
||||
|
||||
CMeshO::VertexIterator vi;
|
||||
for (vi = fittingCircle.vert.begin(); vi != fittingCircle.vert.end(); vi++) {
|
||||
glVertex(vi->cP());
|
||||
}
|
||||
vi = fittingCircle.vert.begin();
|
||||
vi++;
|
||||
glVertex(vi->cP());
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
}
|
||||
@ -156,11 +173,12 @@ bool EditPointPlugin::StartEdit(MeshModel &m, GLArea *gla) {
|
||||
}
|
||||
|
||||
void EditPointPlugin::EndEdit(MeshModel &m, GLArea *gla) {
|
||||
fittingCircle.Clear();
|
||||
ComponentFinder<CMeshO, CVertexO>::DeletePerVertexAttribute(m.cm);
|
||||
}
|
||||
|
||||
|
||||
void EditPointPlugin::mousePressEvent(QMouseEvent *ev, MeshModel &m, GLArea *gla ) {
|
||||
void EditPointPlugin::mousePressEvent(QMouseEvent *ev, MeshModel &m, GLArea *gla) {
|
||||
startingVertex = NULL;
|
||||
|
||||
cur = ev->pos();
|
||||
@ -201,10 +219,10 @@ void EditPointPlugin::mouseMoveEvent(QMouseEvent *ev, MeshModel &m, GLArea *gla
|
||||
BorderVector.clear();
|
||||
|
||||
if (editType == SELECT_DEFAULT_MODE)
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, *startingVertex, k, this->dist, this->maxHop, BorderVector, NotReachableVector);
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, this->dist, BorderVector, NotReachableVector);
|
||||
else if (editType == SELECT_FITTING_PLANE_MODE) {
|
||||
this->fittingRadius = dist * fittingRadiusPerc;
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, *startingVertex, k, this->dist, this->maxHop, BorderVector, NotReachableVector, true, fittingRadius, planeDist);
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, this->dist, BorderVector, NotReachableVector, true, fittingRadius, planeDist, &fittingPlane);
|
||||
}
|
||||
|
||||
gla->update();
|
||||
@ -288,20 +306,14 @@ void EditPointPlugin::keyPressEvent(QKeyEvent *ev, MeshModel &m, GLArea *gla) {
|
||||
|
||||
|
||||
if (hopDistModified) {
|
||||
//timer.restart();
|
||||
ComponentFinder<CMeshO, CVertexO>::Dijkstra(m.cm, *startingVertex, 6, this->maxHop, this->NotReachableVector);
|
||||
|
||||
//printf("ComponentFinder in ChangeHop::Dijkstra: %d ms\n", timer.elapsed());
|
||||
}
|
||||
if (parameterModified) {
|
||||
//printf("fittingRadius: %f\n", fittingRadius);
|
||||
//printf("planeDist: %f\n", planeDist);
|
||||
|
||||
BorderVector.clear();
|
||||
if (editType == SELECT_DEFAULT_MODE)
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, *startingVertex, k, this->dist, this->maxHop, BorderVector, NotReachableVector);
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, this->dist, BorderVector, NotReachableVector);
|
||||
else if (editType == SELECT_FITTING_PLANE_MODE)
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, *startingVertex, k, this->dist, this->maxHop, BorderVector, NotReachableVector, true, fittingRadius, planeDist);
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, this->dist, BorderVector, NotReachableVector, true, fittingRadius, planeDist, &fittingPlane);
|
||||
}
|
||||
|
||||
gla->update();
|
||||
@ -326,17 +338,14 @@ void EditPointPlugin::wheelEvent(QWheelEvent* ev, MeshModel &m, GLArea *gla) {
|
||||
}
|
||||
|
||||
if (hopDistModified) {
|
||||
//timer.restart();
|
||||
ComponentFinder<CMeshO, CVertexO>::Dijkstra(m.cm, *startingVertex, k, this->maxHop, this->NotReachableVector);
|
||||
|
||||
//printf("ComponentFinder in ChangeHop::Dijkstra: %d ms\n", timer.elapsed());
|
||||
|
||||
BorderVector.clear();
|
||||
|
||||
if (editType == SELECT_DEFAULT_MODE)
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, *startingVertex, k, this->dist, this->maxHop, BorderVector, NotReachableVector);
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, this->dist, BorderVector, NotReachableVector);
|
||||
else if (editType == SELECT_FITTING_PLANE_MODE)
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, *startingVertex, k, this->dist, this->maxHop, BorderVector, NotReachableVector, true, fittingRadius, planeDist);
|
||||
ComponentVector = ComponentFinder<CMeshO, CVertexO>::FindComponent(m.cm, this->dist, BorderVector, NotReachableVector, true, fittingRadius, planeDist, &fittingPlane);
|
||||
}
|
||||
|
||||
gla->update();
|
||||
|
||||
@ -71,6 +71,9 @@ private:
|
||||
float fittingRadius;
|
||||
float planeDist;
|
||||
|
||||
vcg::Plane3<CMeshO::ScalarType> fittingPlane;
|
||||
CMeshO fittingCircle;
|
||||
|
||||
std::vector<CMeshO::VertexPointer> ComponentVector;
|
||||
std::vector<CMeshO::VertexPointer> BorderVector;
|
||||
std::vector<CMeshO::VertexPointer> NotReachableVector;
|
||||
|
||||
@ -50,10 +50,7 @@ void KNNTree<_MyMeshType, _MyVertexType>::MakeKNNTree(_MyMeshType& m, int numOfN
|
||||
}
|
||||
ConstDataWrapper<typename _MyMeshType::CoordType> DW(&(input[0]), input.size());
|
||||
|
||||
//QTime t2;
|
||||
//t2.start();
|
||||
KdTree<float> tree(DW);
|
||||
//printf("KdTree Creation: %d ms\n", t2.elapsed());
|
||||
|
||||
tree.setMaxNofNeighbors(neighboursVectSize);
|
||||
|
||||
@ -62,7 +59,6 @@ void KNNTree<_MyMeshType, _MyVertexType>::MakeKNNTree(_MyMeshType& m, int numOfN
|
||||
//the highest value (inserted by the doQueryK function of the vcg library). Moreover
|
||||
//we have to exclude the queryPoint!
|
||||
|
||||
//t2.restart();
|
||||
int neightId = -1;
|
||||
for (int j = 0; j < m.vn; j++) {
|
||||
tree.doQueryK(m.vert[j].cP());
|
||||
@ -74,7 +70,6 @@ void KNNTree<_MyMeshType, _MyVertexType>::MakeKNNTree(_MyMeshType& m, int numOfN
|
||||
kNeighboursVect[m.vert[j]]->push_back(&(m.vert[neightId]));
|
||||
}
|
||||
}
|
||||
//printf("KdTree Creation (knn-query): %d ms\n", t2.elapsed());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user