Updated to the new geodesic api

This commit is contained in:
Paolo Cignoni cignoni 2013-10-10 10:56:55 +00:00
parent d61fc239b6
commit 2df9834e76

View File

@ -30,7 +30,7 @@
Revision 1.1 2007/12/02 07:57:48 cignoni
Added the new sample filter plugin that removes border faces
*****************************************************************************/
#include <Qt>
@ -39,19 +39,19 @@
using namespace std;
using namespace vcg;
FilterGeodesic::FilterGeodesic()
FilterGeodesic::FilterGeodesic()
{
typeList << FP_QUALITY_BORDER_GEODESIC
<< FP_QUALITY_POINT_GEODESIC;
<< FP_QUALITY_POINT_GEODESIC;
FilterIDType tt;
foreach(tt , types())
actionList << new QAction(filterName(tt), this);
actionList << new QAction(filterName(tt), this);
}
FilterGeodesic::~FilterGeodesic() {
for (int i = 0; i < actionList.count() ; i++ )
for (int i = 0; i < actionList.count() ; i++ )
delete actionList.at(i);
}
@ -59,9 +59,9 @@ QString FilterGeodesic::filterName(FilterIDType filter) const
{
switch(filter)
{
case FP_QUALITY_BORDER_GEODESIC : return QString("Colorize by border distance");
case FP_QUALITY_POINT_GEODESIC : return QString("Colorize by distance from a given point");
default: assert(0);
case FP_QUALITY_BORDER_GEODESIC : return QString("Colorize by border distance");
case FP_QUALITY_POINT_GEODESIC : return QString("Colorize by distance from a given point");
default: assert(0);
}
return QString("error!");
}
@ -70,9 +70,9 @@ QString FilterGeodesic::filterName(FilterIDType filter) const
{
switch(filterId)
{
case FP_QUALITY_BORDER_GEODESIC: return tr("Store in the quality field the geodesic distance from borders and color the mesh accordingly.");
case FP_QUALITY_POINT_GEODESIC: return tr("Store in the quality field the geodesic distance from a given point and color the mesh accordingly.");
default: assert(0);
case FP_QUALITY_BORDER_GEODESIC: return tr("Store in the quality field the geodesic distance from borders and color the mesh accordingly.");
case FP_QUALITY_POINT_GEODESIC: return tr("Store in the quality field the geodesic distance from a given point and color the mesh accordingly.");
default: assert(0);
}
return QString("error!");
}
@ -85,7 +85,7 @@ QString FilterGeodesic::filterName(FilterIDType filter) const
case FP_QUALITY_POINT_GEODESIC :
return FilterGeodesic::FilterClass(MeshFilterInterface::VertexColoring + MeshFilterInterface::Quality);
default : assert(0);
return MeshFilterInterface::Generic;
return MeshFilterInterface::Generic;
}
}
@ -93,8 +93,8 @@ QString FilterGeodesic::filterName(FilterIDType filter) const
{
switch(ID(action))
{
case FP_QUALITY_BORDER_GEODESIC :
case FP_QUALITY_POINT_GEODESIC : return MeshModel::MM_VERTFACETOPO ;
case FP_QUALITY_BORDER_GEODESIC :
case FP_QUALITY_POINT_GEODESIC : return MeshModel::MM_VERTFACETOPO ;
default: assert(0);
}
return 0;
@ -104,33 +104,34 @@ bool FilterGeodesic::applyFilter(QAction *filter, MeshDocument &md, RichParamete
{
MeshModel &m=*(md.mm());
CMeshO::FaceIterator fi;
CMeshO::VertexIterator vi;
switch (ID(filter)) {
case FP_QUALITY_POINT_GEODESIC:
{
m.updateDataMask(MeshModel::MM_VERTFACETOPO);
m.updateDataMask(MeshModel::MM_VERTMARK);
m.updateDataMask(MeshModel::MM_VERTQUALITY);
m.updateDataMask(MeshModel::MM_VERTCOLOR);
tri::UpdateFlags<CMeshO>::FaceBorderFromVF(m.cm);
tri::UpdateFlags<CMeshO>::VertexBorderFromFace(m.cm);
Point3f startPoint = par.getPoint3f("startPoint");
// first search the closest point on the surface;
CMeshO::VertexPointer startVertex=0;
float minDist= std::numeric_limits<float>::max();
CMeshO::VertexIterator vi;
switch (ID(filter)) {
case FP_QUALITY_POINT_GEODESIC:
{
m.updateDataMask(MeshModel::MM_VERTFACETOPO);
m.updateDataMask(MeshModel::MM_VERTMARK);
m.updateDataMask(MeshModel::MM_VERTQUALITY);
m.updateDataMask(MeshModel::MM_VERTCOLOR);
tri::UpdateFlags<CMeshO>::FaceBorderFromVF(m.cm);
tri::UpdateFlags<CMeshO>::VertexBorderFromFace(m.cm);
Point3f startPoint = par.getPoint3f("startPoint");
// first search the closest point on the surface;
CMeshO::VertexPointer startVertex=0;
float minDist= std::numeric_limits<float>::max();
for(vi=m.cm.vert.begin();vi!=m.cm.vert.end();++vi) if(!(*vi).IsD())
if(SquaredDistance(startPoint,(*vi).P()) < minDist) {
startVertex=&*vi;
minDist=SquaredDistance(startPoint,(*vi).P());
}
Log("Input point is %f %f %f Closest on surf is %f %f %f",startPoint[0],startPoint[1],startPoint[2],startVertex->P()[0],startVertex->P()[1],startVertex->P()[2]);
// Now actually compute the geodesic distnace from the closest point
// Now actually compute the geodesic distnace from the closest point
float dist_thr = par.getAbsPerc("maxDistance");
tri::Geodesic<CMeshO>::Compute(m.cm, vector<CVertexO*>(1,startVertex),dist_thr);
tri::EuclideanDistance<CMeshO> dd;
tri::Geodesic<CMeshO>::Compute(m.cm, vector<CVertexO*>(1,startVertex),dd,dist_thr);
// Cleaning Quality value of the unrefernced vertices
// Unreached vertexes has a quality that is maxfloat
@ -143,9 +144,9 @@ bool FilterGeodesic::applyFilter(QAction *filter, MeshDocument &md, RichParamete
}
if(unreachedCnt >0 )
Log("Warning: %i vertices were unreacheable from the borders, probably your mesh has unreferenced vertices",unreachedCnt);
tri::UpdateColor<CMeshO>::PerVertexQualityRamp(m.cm);
}
break;
case FP_QUALITY_BORDER_GEODESIC:
@ -170,28 +171,28 @@ bool FilterGeodesic::applyFilter(QAction *filter, MeshDocument &md, RichParamete
}
if(unreachedCnt >0 )
Log("Warning: %i vertices were unreacheable from the borders, probably your mesh has unreferenced vertices",unreachedCnt);
if(!ret) Log("Mesh Has no borders. No geodesic distance computed");
else tri::UpdateColor<CMeshO>::PerVertexQualityRamp(m.cm);
else tri::UpdateColor<CMeshO>::PerVertexQualityRamp(m.cm);
}
break;
default: assert(0);
break;
}
return true;
return true;
}
void FilterGeodesic::initParameterSet(QAction *action,MeshModel &m, RichParameterSet & parlst)
{
switch(ID(action))
switch(ID(action))
{
case FP_QUALITY_POINT_GEODESIC :
parlst.addParam(new RichPoint3f("startPoint",m.cm.bbox.min,"Starting point","The starting point from which geodesic distance has to be computed. If it is not a surface vertex, the closest vertex to the specified point is used as starting seed point."));
parlst.addParam(new RichAbsPerc("maxDistance",m.cm.bbox.Diag(),0,m.cm.bbox.Diag()*2,"Max Distance","If not zero it indicates a cut off value to be used during geodesic distance computation."));
parlst.addParam(new RichAbsPerc("maxDistance",m.cm.bbox.Diag(),0,m.cm.bbox.Diag()*2,"Max Distance","If not zero it indicates a cut off value to be used during geodesic distance computation."));
break;
default: break; // do not add any parameter for the other filters
}
default: break; // do not add any parameter for the other filters
}
return;
}