diff --git a/src/fgt/filter_aging/filter_aging.cpp b/src/fgt/filter_aging/filter_aging.cpp index 6ac627c9f..f9f2ef68d 100644 --- a/src/fgt/filter_aging/filter_aging.cpp +++ b/src/fgt/filter_aging/filter_aging.cpp @@ -32,10 +32,11 @@ /* VCG includes */ #include #include +#include #include #include #include - +#include /* Constructor */ GeometryAgingPlugin::GeometryAgingPlugin() @@ -178,7 +179,6 @@ bool GeometryAgingPlugin::applyFilter(QAction *filter, MeshModel &m, FilterParam // edge predicate AgingEdgePred ep = AgingEdgePred((useQuality?AgingEdgePred::QUALITY:AgingEdgePred::ANGLE), selected, edgeLenTreshold, thresholdValue); - int fcount = 1; // face counter (to update progress bar) switch(ID(filter)) { case FP_ERODE: @@ -189,55 +189,58 @@ bool GeometryAgingPlugin::applyFilter(QAction *filter, MeshModel &m, FilterParam if(selected) tri::UpdateSelection::VertexFromFaceStrict(m.cm); // clear vertexes V bit (will be used to mark the vertexes as displaced) - for(CMeshO::VertexIterator vi=m.cm.vert.begin(); vi!=m.cm.vert.end(); vi++) - if(!(*vi).IsD()) (*vi).ClearV(); + tri::UpdateFlags::VertexClearV(m.cm); // displace vertexes for(int i=0; i gM; gM.Set(m.cm.face.begin(), m.cm.face.end()); + if(cb) (*cb)( (i+1)*100/dispSteps, "Aging..."); + + // blend toghether face normals and recompute vertex normal from these normals + // to get smoother offest directions + FaceNormalSmoothFF(m.cm,3); + tri::UpdateNormals::PerVertexFromCurrentFaceNormal(m.cm); + tri::UpdateNormals::NormalizeVertex(m.cm); + for(CMeshO::FaceIterator fi=m.cm.face.begin(); fi!=m.cm.face.end(); fi++) { - if(cb) (*cb)(((fcount++/dispSteps)/m.cm.fn)*100, "Aging..."); if((*fi).IsD()) continue; for(int j=0; j<3; j++) { if(ep.qaVertTest(face::Pos(&*fi,j)) && - !(*fi).V(j)->IsV() && - (!selected || ((*fi).IsS() && (*fi).FFp(j)->IsS())) ) { - double noise; // noise value - Point3f dispDir = (*fi).V(j)->N(); // displacement direction + !(*fi).V(j)->IsV() && + (!selected || ((*fi).IsS() && (*fi).FFp(j)->IsS())) ) + { + double noise; // noise value + Point3f dispDir = (*fi).V(j)->N(); // displacement direction - Point3f p = (*fi).V(j)->P() / noiseScale; - noise = generateNoiseValue(octaves, p); - // only values bigger than noiseClamp will be considered - noise = (noiseP() / noiseScale; + noise = generateNoiseValue(octaves, p); + // only values bigger than noiseClamp will be considered + noise = (noiseP() += offset; - if(faceIntersections(m.cm, face::Pos(&*fi,j), gM)) - (*fi).V(j)->P() -= offset; + (*fi).V(j)->P() += offset; + if(faceIntersections(m.cm, face::Pos(&*fi,j), gM)) + (*fi).V(j)->P() -= offset; - // mark as visited (displaced) - (*fi).V(j)->SetV(); - } + // mark as visited (displaced) + (*fi).V(j)->SetV(); + } } } // clear vertexes V bit again - for(CMeshO::VertexIterator vi=m.cm.vert.begin(); vi!=m.cm.vert.end(); vi++) - if(!(*vi).IsD()) (*vi).ClearV(); - + tri::UpdateFlags::VertexClearV(m.cm); + // update vertex normals - vcg::tri::UpdateNormals::PerVertexNormalized(m.cm); + vcg::tri::UpdateNormals::PerVertexNormalizedPerFace(m.cm); } // readjust selection if(selected) tri::UpdateSelection::VertexFromFaceLoose(m.cm); - - // update all normals (face and vertex) before return - vcg::tri::UpdateNormals::PerVertexNormalizedPerFace(m.cm); - + return true; default: assert(0);