NO_QT defines to explicitly disable qt dependant behavior
This commit is contained in:
parent
2631ae5351
commit
499822bc17
|
@ -8,7 +8,7 @@
|
|||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
|
@ -69,13 +69,13 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
int CurrentSlice;
|
||||
typedef tri::FaceTmark<Old_Mesh> MarkerFace;
|
||||
MarkerFace markerFunctor;
|
||||
|
||||
|
||||
|
||||
|
||||
VertexIndex *_x_cs; // indici dell'intersezioni della superficie lungo gli Xedge della fetta corrente
|
||||
VertexIndex *_y_cs; // indici dell'intersezioni della superficie lungo gli Yedge della fetta corrente
|
||||
VertexIndex *_z_cs; // indici dell'intersezioni della superficie lungo gli Zedge della fetta corrente
|
||||
VertexIndex *_x_ns; // indici dell'intersezioni della superficie lungo gli Xedge della prossima fetta
|
||||
VertexIndex *_z_ns; // indici dell'intersezioni della superficie lungo gli Zedge della prossima fetta
|
||||
VertexIndex *_x_ns; // indici dell'intersezioni della superficie lungo gli Xedge della prossima fetta
|
||||
VertexIndex *_z_ns; // indici dell'intersezioni della superficie lungo gli Zedge della prossima fetta
|
||||
|
||||
//float *_v_cs;///values of distance fields for each direction in current slice
|
||||
//float *_v_ns;///values of distance fields for each direction in next slice
|
||||
|
@ -87,19 +87,19 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
New_Mesh *_newM;
|
||||
Old_Mesh *_oldM;
|
||||
GridType _g;
|
||||
|
||||
|
||||
public:
|
||||
float max_dim; // the limit value of the search (that takes into account of the offset)
|
||||
float offset; // an offset value that is always added to the returned value. Useful for extrarting isosurface at a different threshold
|
||||
bool DiscretizeFlag; // if the extracted surface should be discretized or not.
|
||||
bool MultiSampleFlag;
|
||||
bool AbsDistFlag; // if true the Distance Field computed is no more a signed one.
|
||||
bool AbsDistFlag; // if true the Distance Field computed is no more a signed one.
|
||||
Walker(const Box3f &_bbox, Point3i _siz )
|
||||
{
|
||||
this->bbox= _bbox;
|
||||
this->siz=_siz;
|
||||
ComputeDimAndVoxel();
|
||||
|
||||
|
||||
SliceSize = (this->siz.X()+1)*(this->siz.Z()+1);
|
||||
CurrentSlice = 0;
|
||||
offset=0;
|
||||
|
@ -115,33 +115,33 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
|
||||
_v_cs= new field_value[(this->siz.X()+1)*(this->siz.Z()+1)];
|
||||
_v_ns= new field_value[(this->siz.X()+1)*(this->siz.Z()+1)];
|
||||
|
||||
|
||||
};
|
||||
|
||||
~Walker()
|
||||
{}
|
||||
|
||||
|
||||
|
||||
float V(const Point3i &p)
|
||||
{
|
||||
return V(p.V(0),p.V(1),p.V(2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::pair<bool,float> VV(int x,int y,int z)
|
||||
{
|
||||
assert ((y==CurrentSlice)||(y==(CurrentSlice+1)));
|
||||
|
||||
|
||||
//test if it is outside the bb of the mesh
|
||||
//vcg::Point3f test=vcg::Point3f((float)x,(float)y,(float)z);
|
||||
/*if (!_oldM->bbox.IsIn(test))
|
||||
return (1.f);*/
|
||||
int index=GetSliceIndex(x,z);
|
||||
|
||||
|
||||
if (y==CurrentSlice) return _v_cs[index];
|
||||
else return _v_ns[index];
|
||||
else return _v_ns[index];
|
||||
}
|
||||
|
||||
|
||||
float V(int x,int y,int z)
|
||||
{
|
||||
if(DiscretizeFlag) return VV(x,y,z).second+offset<0?-1:1;
|
||||
|
@ -161,22 +161,22 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
vcg::Point3f pip(-1,-1,-1);
|
||||
|
||||
// Note that PointDistanceBaseFunctor does not require the edge and plane precomptued.
|
||||
// while the PointDistanceFunctor requires them.
|
||||
|
||||
// while the PointDistanceFunctor requires them.
|
||||
|
||||
DISTFUNCTOR PDistFunct;
|
||||
f = _g.GetClosest(PDistFunct,markerFunctor,testPt,max_dist,dist,closestPt);
|
||||
if (f==NULL) return field_value(false,0);
|
||||
if(AbsDistFlag) return field_value(true,dist);
|
||||
if(AbsDistFlag) return field_value(true,dist);
|
||||
assert(!f->IsD());
|
||||
bool retIP;
|
||||
|
||||
// To compute the interpolated normal we use the more robust function that require to know what is the most orhogonal direction of the face.
|
||||
|
||||
// To compute the interpolated normal we use the more robust function that require to know what is the most orhogonal direction of the face.
|
||||
if((*f).Flags() & Old_Mesh::FaceType::NORMX) retIP=InterpolationParameters(*f,0,closestPt, pip);
|
||||
else if((*f).Flags() & Old_Mesh::FaceType::NORMY) retIP=InterpolationParameters(*f,1,closestPt, pip);
|
||||
else if((*f).Flags() & Old_Mesh::FaceType::NORMZ) retIP=InterpolationParameters(*f,2,closestPt, pip);
|
||||
else assert(0);
|
||||
assert(retIP); // this should happen only if the starting mesh has degenerate faces.
|
||||
|
||||
|
||||
closestNormV = (f->V(0)->cN())*pip[0] + (f->V(1)->cN())*pip[1] + (f->V(2)->cN())*pip[2] ;
|
||||
closestNormF = f->cN() ;
|
||||
|
||||
|
@ -186,15 +186,15 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
// Surface normal for improved robustness is computed both by face and interpolated from vertices.
|
||||
float signV = dir.dot(closestNormV) ;
|
||||
float signF = dir.dot(closestNormF) ;
|
||||
|
||||
// Note that the two signs could be discordant.
|
||||
|
||||
// Note that the two signs could be discordant.
|
||||
// Always choose the best one according to the magnitude.
|
||||
float signBest;
|
||||
if(fabs(signV) > fabs(signF)) signBest = signV;
|
||||
else signBest = signF;
|
||||
|
||||
|
||||
if(signBest<0) dist=-dist;
|
||||
|
||||
|
||||
return field_value(true,dist);
|
||||
}
|
||||
|
||||
|
@ -205,21 +205,21 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
const int MultiSample=7;
|
||||
const Point3f delta[7]={Point3f(0,0,0),
|
||||
Point3f( 0.2, -0.01, -0.02),
|
||||
Point3f(-0.2, 0.01, 0.02),
|
||||
Point3f( 0.01, 0.2, 0.01),
|
||||
Point3f( 0.03, -0.2, -0.03),
|
||||
Point3f(-0.2, 0.01, 0.02),
|
||||
Point3f( 0.01, 0.2, 0.01),
|
||||
Point3f( 0.03, -0.2, -0.03),
|
||||
Point3f(-0.02, -0.03, 0.2 ),
|
||||
Point3f(-0.01, 0.01, -0.2 )};
|
||||
|
||||
for(int qq=0;qq<MultiSample;++qq)
|
||||
{
|
||||
Point3f pp2=pp+delta[qq];
|
||||
Point3f pp2=pp+delta[qq];
|
||||
field_value ff= DistanceFromMesh(pp2,_oldM);
|
||||
if(ff.first==false) return field_value(false,0);
|
||||
distSum += fabs(ff.second);
|
||||
if(ff.second>0) positiveCnt ++;
|
||||
}
|
||||
if(positiveCnt<=MultiSample/2) distSum = -distSum;
|
||||
if(positiveCnt<=MultiSample/2) distSum = -distSum;
|
||||
return field_value(true, distSum/MultiSample);
|
||||
}
|
||||
|
||||
|
@ -239,9 +239,9 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
}
|
||||
//ComputeConsensus(slice,slice_values);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
For some reasons it can happens that the sign of the computed distance could not correct.
|
||||
For some reasons it can happens that the sign of the computed distance could not correct.
|
||||
this function tries to correct these issues by flipping the isolated voxels with discordant sign
|
||||
*/
|
||||
void ComputeConsensus(int slice, field_value *slice_values)
|
||||
|
@ -268,27 +268,30 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
if(i < this->siz.X() ) index_r=GetSliceIndex(i+1,k); else index_r = index;
|
||||
if(k > 0 ) index_d=GetSliceIndex(i,k-1); else index_d = index;
|
||||
if(k < this->siz.Z() ) index_u=GetSliceIndex(i,k+1); else index_u = index;
|
||||
|
||||
|
||||
if(slice_values[index_l].first) { goodCnt++; if(fabs(slice_values[index_l].second - curVal) > max_dist) badCnt++; }
|
||||
if(slice_values[index_r].first) { goodCnt++; if(fabs(slice_values[index_r].second - curVal) > max_dist) badCnt++; }
|
||||
if(slice_values[index_u].first) { goodCnt++; if(fabs(slice_values[index_u].second - curVal) > max_dist) badCnt++; }
|
||||
if(slice_values[index_d].first) { goodCnt++; if(fabs(slice_values[index_d].second - curVal) > max_dist) badCnt++; }
|
||||
|
||||
|
||||
if(badCnt >= goodCnt) {
|
||||
slice_values[index].second *=-1.0f;
|
||||
//slice_values[index].first = false;
|
||||
flippedCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
flippedTot+=flippedCnt;
|
||||
flippedTimes++;
|
||||
} while(flippedCnt>0);
|
||||
|
||||
if(flippedTot>0)
|
||||
qDebug("Flipped %i values in %i times",flippedTot,flippedTimes);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_QT
|
||||
if(flippedTot>0)
|
||||
qDebug("Flipped %i values in %i times",flippedTot,flippedTimes);
|
||||
#endif
|
||||
}
|
||||
template<class EXTRACTOR_TYPE>
|
||||
void ProcessSlice(EXTRACTOR_TYPE &extractor)
|
||||
{
|
||||
|
@ -303,7 +306,7 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
for(int jj=0;jj<2;++jj)
|
||||
for(int kk=0;kk<2;++kk)
|
||||
goodCell &= VV(p1[0]+ii,p1[1]+jj,p1[2]+kk).first;
|
||||
|
||||
|
||||
if(goodCell) extractor.ProcessCell(p1, p2);
|
||||
}
|
||||
}
|
||||
|
@ -315,12 +318,12 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
{
|
||||
_newM=&new_mesh;
|
||||
_oldM=&old_mesh;
|
||||
|
||||
|
||||
// the following two steps are required to be sure that the point-face distance without precomputed data works well.
|
||||
tri::UpdateNormals<Old_Mesh>::PerVertexNormalizedPerFaceNormalized(old_mesh);
|
||||
tri::UpdateFlags<Old_Mesh>::FaceProjection(old_mesh);
|
||||
int _size=(int)old_mesh.fn*100;
|
||||
|
||||
|
||||
_g.Set(_oldM->face.begin(),_oldM->face.end(),_size);
|
||||
markerFunctor.SetMesh(&old_mesh);
|
||||
|
||||
|
@ -335,7 +338,7 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
{
|
||||
cb((100*j)/this->siz.Y(),"Marching ");
|
||||
t0 = clock();
|
||||
ProcessSlice<EXTRACTOR_TYPE>(extractor);//find cells where there is the isosurface and examine it
|
||||
ProcessSlice<EXTRACTOR_TYPE>(extractor);//find cells where there is the isosurface and examine it
|
||||
t1 = clock();
|
||||
NextSlice();
|
||||
t2 = clock();
|
||||
|
@ -343,31 +346,32 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
extractTime += t2-t1;
|
||||
}
|
||||
extractor.Finalize();
|
||||
#ifndef NO_QT
|
||||
qDebug("Extract %i, Compute %i",t1-t0,t2-t1);
|
||||
|
||||
#endif
|
||||
typename New_Mesh::VertexIterator vi;
|
||||
for(vi=new_mesh.vert.begin();vi!=new_mesh.vert.end();++vi)
|
||||
for(vi=new_mesh.vert.begin();vi!=new_mesh.vert.end();++vi)
|
||||
if(!(*vi).IsD())
|
||||
{
|
||||
IPfToPf((*vi).cP(),(*vi).P());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//return the index of a vertex in slide as it was stored
|
||||
int GetSliceIndex(int x,int z)
|
||||
{
|
||||
VertexIndex index = x+z*(this->siz.X()+1);
|
||||
return (index);
|
||||
}
|
||||
|
||||
|
||||
//swap slices , the initial value of distance fields ids set as double of bbox of space
|
||||
void NextSlice()
|
||||
void NextSlice()
|
||||
{
|
||||
|
||||
|
||||
memset(_x_cs, -1, SliceSize*sizeof(VertexIndex));
|
||||
memset(_y_cs, -1, SliceSize*sizeof(VertexIndex));
|
||||
memset(_z_cs, -1, SliceSize*sizeof(VertexIndex));
|
||||
|
||||
|
||||
|
||||
std::swap(_x_cs, _x_ns);
|
||||
std::swap(_z_cs, _z_ns);
|
||||
|
@ -375,10 +379,10 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
std::swap(_v_cs, _v_ns);
|
||||
|
||||
CurrentSlice ++;
|
||||
|
||||
|
||||
ComputeSliceValues(CurrentSlice + 1,_v_ns);
|
||||
}
|
||||
|
||||
|
||||
//initialize data strucures , the initial value of distance fields ids set as double of bbox of space
|
||||
void Begin()
|
||||
{
|
||||
|
@ -395,11 +399,11 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
ComputeSliceValues(CurrentSlice+1,_v_ns);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Exist(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
{
|
||||
{
|
||||
int i = p1.X();// - _bbox.min.X())/_cell_size.X();
|
||||
int z = p1.Z();// - _bbox.min.Z())/_cell_size.Z();
|
||||
VertexIndex index = i+z*this->siz.X();
|
||||
|
@ -479,9 +483,9 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
return false;
|
||||
}
|
||||
|
||||
///interpolate
|
||||
///interpolate
|
||||
NewCoordType Interpolate(const vcg::Point3i &p1, const vcg::Point3i &p2,int dir)
|
||||
{
|
||||
{
|
||||
float f1 = (float)V(p1);
|
||||
float f2 = (float)V(p2);
|
||||
float u = (float) f1/(f1-f2);
|
||||
|
@ -491,12 +495,12 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
}
|
||||
|
||||
///if there is a vertex in z axis of a cell return the vertex or create it
|
||||
void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
{
|
||||
void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
{
|
||||
assert(p1.X()+1 == p2.X());
|
||||
assert(p1.Y() == p2.Y());
|
||||
assert(p1.Z() == p2.Z());
|
||||
|
||||
|
||||
int i = p1.X();// (p1.X() - _bbox.min.X())/_cell_size.X();
|
||||
int z = p1.Z();//(p1.Z() - _bbox.min.Z())/_cell_size.Z();
|
||||
VertexIndex index = i+z*this->siz.X();
|
||||
|
@ -527,14 +531,14 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
}
|
||||
v = &_newM->vert[pos];
|
||||
}
|
||||
|
||||
|
||||
///if there is a vertex in y axis of a cell return the vertex or create it
|
||||
void GetYIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
void GetYIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
{
|
||||
assert(p1.X() == p2.X());
|
||||
assert(p1.Y()+1 == p2.Y());
|
||||
assert(p1.Z() == p2.Z());
|
||||
|
||||
|
||||
int i = p1.X(); // (p1.X() - _bbox.min.X())/_cell_size.X();
|
||||
int z = p1.Z(); // (p1.Z() - _bbox.min.Z())/_cell_size.Z();
|
||||
VertexIndex index = i+z*this->siz.X();
|
||||
|
@ -549,14 +553,14 @@ template <class OLD_MESH_TYPE,class NEW_MESH_TYPE, class FLT, class DISTFUNCTOR
|
|||
}
|
||||
v = &_newM->vert[pos];
|
||||
}
|
||||
|
||||
|
||||
///if there is a vertex in z axis of a cell return the vertex or create it
|
||||
void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointer &v)
|
||||
{
|
||||
assert(p1.X() == p2.X());
|
||||
assert(p1.Y() == p2.Y());
|
||||
assert(p1.Z()+1 == p2.Z());
|
||||
|
||||
|
||||
int i = p1.X(); //(p1.X() - _bbox.min.X())/_cell_size.X();
|
||||
int z = p1.Z(); //(p1.Z() - _bbox.min.Z())/_cell_size.Z();
|
||||
VertexIndex index = i+z*this->siz.X();
|
||||
|
@ -602,18 +606,18 @@ static void Resample(Old_Mesh &old_mesh,New_Mesh &new_mesh, Box3f volumeBox, vc
|
|||
{
|
||||
///be sure that the bounding box is updated
|
||||
vcg::tri::UpdateBounding<Old_Mesh>::Box(old_mesh);
|
||||
|
||||
|
||||
MyWalker walker(volumeBox,accuracy);
|
||||
|
||||
walker.max_dim=max_dist+fabs(thr);
|
||||
walker.offset = - thr;
|
||||
walker.offset = - thr;
|
||||
walker.DiscretizeFlag = DiscretizeFlag;
|
||||
walker.MultiSampleFlag = MultiSampleFlag;
|
||||
walker.AbsDistFlag = AbsDistFlag;
|
||||
MyMarchingCubes mc(new_mesh, walker);
|
||||
walker.BuildMesh(old_mesh,new_mesh,mc,cb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};//end class resampler
|
||||
|
||||
|
|
Loading…
Reference in New Issue