Removed a lot of warnings, added initial cleaning of mesh (to avoid crashes due to NaN in normals) removed a strange ndebug define.

This commit is contained in:
Paolo Cignoni cignoni 2008-12-19 00:37:15 +00:00
parent 4d350e45ac
commit 2327af3fa1
8 changed files with 32 additions and 23 deletions

View File

@ -123,7 +123,7 @@ void BallTree<_Scalar>::buildNode(Node& node, std::vector<int>& indices, AxisAli
}
unsigned int dim = vcg::MaxCoeffId(diag);
node.dim = dim;
node.splitValue = 0.5*(aabb.max[dim] + aabb.min[dim]);
node.splitValue = Scalar(0.5*(aabb.max[dim] + aabb.min[dim]));
node.leaf = 0;
AxisAlignedBoxType aabbLeft=aabb, aabbRight=aabb;

View File

@ -165,7 +165,7 @@ void KdTree<Scalar>::createTree(unsigned int nodeId, unsigned int start, unsigne
VectorType diag = aabb.max - aabb.min;
unsigned int dim = vcg::MaxCoeffId(diag);
node.dim = dim;
node.splitValue = 0.5*(aabb.max[dim] + aabb.min[dim]);
node.splitValue = Scalar(0.5*(aabb.max[dim] + aabb.min[dim]));
unsigned int midId = split(start, end, dim, node.splitValue);

View File

@ -88,8 +88,8 @@ public:
mAABB = mpSurface->boundingBox();
VectorType diag = mAABB.max - mAABB.min;
mAABB.min -= diag * 0.1;
mAABB.max += diag * 0.1;
mAABB.min -= diag * 0.1f;
mAABB.max += diag * 0.1f;
diag = mAABB.max - mAABB.min;
if ( (diag[0]<=0.)
@ -221,7 +221,7 @@ public:
id1 = GetLocalCellIdFromGlobal(p1);
id2 = GetLocalCellIdFromGlobal(p2);
// interpol along the edge
ScalarType epsilon = 1e-5;
ScalarType epsilon = ScalarType(1e-5);
const GridElement& c1 = mCache[id1];
const GridElement& c2 = mCache[id2];
if (fabs(mIsoValue-c1.value) < epsilon)

View File

@ -23,8 +23,6 @@
#include <QtGui>
#define NDEBUG
#include <math.h>
#include <stdlib.h>
#include <time.h>
@ -101,6 +99,7 @@ const QString MlsPlugin::filterName(FilterIDType filterId)
case FP_SELECT_SMALL_COMPONENTS : return QString("Small component selection");
default : assert(0);
}
return QString("Filter Unknown");
}
const MeshFilterInterface::FilterClass MlsPlugin::getClass(QAction *a)
@ -120,6 +119,7 @@ const MeshFilterInterface::FilterClass MlsPlugin::getClass(QAction *a)
case FP_SELECT_SMALL_COMPONENTS : return MeshFilterInterface::Selection;
}
assert(0);
return MeshFilterInterface::Generic;
}
// Info() must return the longer string describing each filtering action
@ -187,7 +187,7 @@ void MlsPlugin::initParameterSet(QAction* action, MeshDocument& md, FilterParame
if (id == FP_SELECT_SMALL_COMPONENTS)
{
parlst.addFloat("NbFaceRatio",
0.1,
0.1f,
"Small component ratio",
"This ratio (between 0 and 1) defines the meaning of <i>small</i> as the threshold ratio between the number of faces"
"of the largest component and the other ones. A larger value will select more components.");
@ -229,7 +229,7 @@ void MlsPlugin::initParameterSet(QAction* action, MeshDocument& md, FilterParame
"Scale of the spatial low pass filter.\n"
"It is relative to the radius (local point spacing) of the vertices.");
parlst.addFloat("ProjectionAccuracy",
1e-4,
1e-4f,
"Projection - Accuracy (adv)",
"Threshold value used to stop the projections.\n"
"This value is scaled by the mean point spacing to get the actual threshold.");
@ -384,6 +384,14 @@ bool MlsPlugin::applyFilter(QAction* filter, MeshDocument& md, FilterParameterSe
// we are doing some MLS based stuff
{
if(md.mm()->cm.fn > 0)
{ // if we start from a mesh, and it has unreferenced vertices
// normals are undefined on that vertices.
int delvert=tri::Clean<CMeshO>::RemoveUnreferencedVertex(md.mm()->cm);
if(delvert) Log(GLLogStream::Info, "Pre-MLS Cleaning: Removed %d unreferenced vertices",delvert);
}
tri::Allocator<CMeshO>::CompactVertexVector(md.mm()->cm);
// We require a per vertex radius so as a first thing check it
if(!md.mm()->hasDataMask(MeshModel::MM_VERTRADIUS))
{
@ -415,7 +423,7 @@ bool MlsPlugin::applyFilter(QAction* filter, MeshDocument& md, FilterParameterSe
// create the MLS surface
cb(1, "Create the MLS data structures...");
MlsSurface<CMeshO>* mls = 0;
RIMLS<CMeshO>* rimls = 0;
APSS<CMeshO>* apss = 0;
@ -495,11 +503,12 @@ bool MlsPlugin::applyFilter(QAction* filter, MeshDocument& md, FilterParameterSe
//bool approx = apss && par.getBool("ApproxCurvature");
int ct = par.getEnum("CurvatureType");
int size = mesh->cm.vert.size();
uint size = mesh->cm.vert.size();
//std::vector<float> curvatures(size);
float minc=1e9, maxc=-1e9, minabsc=1e9;
vcg::Point3f grad;
vcg::Matrix33f hess;
// pass 1: computes curvatures and statistics
for (unsigned int i = 0; i< size; i++)
{
@ -584,7 +593,7 @@ bool MlsPlugin::applyFilter(QAction* filter, MeshDocument& md, FilterParameterSe
{
mesh->updateDataMask(MeshModel::MM_FACEFACETOPO | MeshModel::MM_FACEFLAGBORDER);
// selection...
vcg::tri::SmallComponent<CMeshO>::Select(mesh->cm, 0.1);
vcg::tri::SmallComponent<CMeshO>::Select(mesh->cm, 0.1f);
// deletion...
vcg::tri::SmallComponent<CMeshO>::DeleteFaceVert(mesh->cm);
mesh->clearDataMask(MeshModel::MM_FACEFACETOPO | MeshModel::MM_FACEFLAGBORDER);

View File

@ -67,7 +67,7 @@ class MlsSurface
mFilterScale = 4.0;
mMaxNofProjectionIterations = 20;
mProjectionAccuracy = 1e-4;
mProjectionAccuracy = (Scalar)1e-4;
mBallTree = 0;
mGradientHint = MLS_DERIVATIVE_ACCURATE;
mHessianHint = MLS_DERIVATIVE_ACCURATE;
@ -143,7 +143,7 @@ class MlsSurface
}
const vcg::Box3<Scalar>& boundingBox() const { return mAABB; }
static const Scalar InvalidValue() { return 12345679810.11121314151617; }
static const Scalar InvalidValue() { return Scalar(12345679810.11121314151617); }
void computeVertexRaddi(const int nbNeighbors = 16);
protected:

View File

@ -39,11 +39,11 @@ public:
{
return *reinterpret_cast<const DataType*>(mpData + i*mStride);
}
inline int size() const { return mSize; }
inline size_t size() const { return mSize; }
protected:
const unsigned char* mpData;
int mStride;
int mSize;
size_t mSize;
};
namespace vcg {

View File

@ -57,8 +57,8 @@ class RIMLS : public MlsSurface<_MeshType>
: Base(points)
{
mSigmaR = 0;
mSigmaN = 0.8;
mRefittingThreshold = 1e-3;
mSigmaN = Scalar(0.8);
mRefittingThreshold = Scalar(1e-3);
mMinRefittingIters = 1;
mMaxRefittingIters = 3;
}

View File

@ -47,7 +47,7 @@ public:
// the different components as a list of face pointer
std::vector< std::vector<FacePointer> > components;
for(int faceSeed = 0; faceSeed<m.face.size(); )
for(uint faceSeed = 0; faceSeed<m.face.size(); )
{
// find the first not selected face
bool foundSeed = false;
@ -104,22 +104,22 @@ public:
// now the segmentation is done, let's compute the absolute face count threshold
int total_selected = 0;
int maxComponent = 0;
for (int i=0; i<components.size(); ++i)
for (uint i=0; i<components.size(); ++i)
{
//std::cout << "Component " << i << " -> " << components[i].size() << "\n";
total_selected += components[i].size();
maxComponent = std::max<int>(maxComponent,components[i].size());
}
int remaining = m.face.size() - total_selected;
int th = std::max(maxComponent,remaining) * nbFaceRatio;
uint th = std::max(maxComponent,remaining) * nbFaceRatio;
int selCount = 0;
for (int i=0; i<components.size(); ++i)
for (uint i=0; i<components.size(); ++i)
{
if (components[i].size()<th)
{
selCount += components[i].size();
for (int j=0; j<components[i].size(); ++j)
for (uint j=0; j<components[i].size(); ++j)
components[i][j]->SetS();
}
}