59 #define BOUNDARYSNAPPING_CC 63 #include "BoundarySnappingT.hh" 77 template<
typename MeshT>
78 bool sort_less_pair_second(
const std::pair<typename MeshT::VertexHandle,double> &lhs,
const std::pair<typename MeshT::VertexHandle,double> &rhs)
80 return lhs.second < rhs.second;
86 std::vector<typename MeshT::VertexHandle> v_boundary;
89 for (
typename MeshT::VertexIter v_iter = mesh_.vertices_begin(); v_iter != mesh_.vertices_end(); ++v_iter)
90 if (mesh_.is_boundary(*v_iter) && mesh_.status(*v_iter).selected())
91 v_boundary.push_back(*v_iter);
96 std::vector< std::pair<typename MeshT::VertexHandle,double> > vertexDistMap;
97 std::map<typename MeshT::VertexHandle,std::vector<std::pair<typename MeshT::VertexHandle,double> > > vertexVertexMap;
100 for (
typename std::vector< typename MeshT::VertexHandle >::iterator oIter = v_boundary.begin(); oIter != v_boundary.end(); ++oIter)
102 typename MeshT::Point pos = mesh_.point(*oIter);
103 if (!mesh_.status(*oIter).deleted())
105 std::vector< std::pair<typename MeshT::VertexHandle,double> > verticesInRange;
108 for (
typename std::vector<typename MeshT::VertexHandle>::iterator cIter = v_boundary.begin(); cIter != v_boundary.end(); ++cIter)
110 if ( !mesh_.status(*cIter).deleted() && cIter != oIter)
112 double dist = (pos - mesh_.point(*cIter)).length();
114 if ( dist <= _epsilon )
115 verticesInRange.push_back(std::make_pair(*cIter,dist));
120 if (!verticesInRange.empty())
122 std::sort( verticesInRange.begin(),verticesInRange.end(),&sort_less_pair_second<MeshT> );
123 vertexDistMap.push_back(std::make_pair(*oIter,verticesInRange[0].second));
124 vertexVertexMap[*oIter] = verticesInRange;
129 bool finished =
false;
134 double min = _epsilon;
135 typename MeshT::VertexHandle v_old;
136 typename MeshT::VertexHandle v_new;
137 typename std::vector<std::pair<typename MeshT::VertexHandle,double> >::iterator v_oldIter = vertexDistMap.end();
138 typename std::vector<std::pair<typename MeshT::VertexHandle,double> >::iterator v_newIter;
141 for (
typename std::vector<std::pair<typename MeshT::VertexHandle,double> >::iterator vd_iter = vertexDistMap.begin(); vd_iter != vertexDistMap.end(); ++vd_iter)
143 typename MeshT::VertexHandle v_1 = vd_iter->first;
144 if (v_1.is_valid() && !mesh_.status(v_1).deleted() && vertexVertexMap.find(v_1) != vertexVertexMap.end())
146 typename MeshT::VertexHandle v_2;
147 std::vector<std::pair<typename MeshT::VertexHandle,double> >& verticesInRange = vertexVertexMap[v_1];
149 for (
typename std::vector<std::pair<typename MeshT::VertexHandle,double> >::iterator iter = verticesInRange.begin(); iter != verticesInRange.end(); ++iter)
155 for(
typename MeshT::VertexFaceIter vf_iter = mesh_.vf_begin(v_1); vf_iter.is_valid() && v_2.is_valid(); ++vf_iter)
156 for (
typename MeshT::FaceVertexIter fv_iter = mesh_.fv_begin(*vf_iter); fv_iter.is_valid() && v_2.is_valid(); ++fv_iter)
158 v_2 =
typename MeshT::VertexHandle();
160 const bool validPair = v_2.is_valid() && !mesh_.status(v_2).deleted() && mesh_.is_boundary(v_2);
163 if (validPair && iter->second <= min)
181 vertexVertexMap[v_old].erase(v_newIter);
183 std::vector<typename MeshT::FaceHandle> faces;
184 for (
typename MeshT::VertexFaceIter vf_iter = mesh_.vf_begin(v_old); vf_iter.is_valid(); ++vf_iter)
185 if (!mesh_.status(*vf_iter).deleted())
186 faces.push_back(*vf_iter);
189 for (
typename std::vector<typename MeshT::FaceHandle>::iterator f_iter = faces.begin(); f_iter !=faces.end(); ++f_iter)
191 typename MeshT::FaceHandle fHandle = *f_iter;
192 if (!fHandle.is_valid() || mesh_.status(fHandle).deleted())
196 std::vector<typename MeshT::VertexHandle> f_vertices;
197 for(
typename MeshT::FaceVertexIter fv_iter = mesh_.fv_begin(fHandle); fv_iter.is_valid(); ++fv_iter)
198 f_vertices.push_back( *fv_iter );
200 mesh_.delete_face(fHandle,
false);
203 std::vector<typename MeshT::VertexHandle> newFace_vertices(f_vertices);
204 std::replace(newFace_vertices.begin(),newFace_vertices.end(),v_old,v_new);
205 typename MeshT::FaceHandle faceH = mesh_.add_face(newFace_vertices);
207 if (!faceH.is_valid())
210 std::reverse(newFace_vertices.begin(),newFace_vertices.end());
211 faceH = mesh_.add_face(newFace_vertices);
212 if (!faceH.is_valid())
215 mesh_.add_face(f_vertices);
220 vertexDistMap.erase(v_oldIter);
224 mesh_.delete_isolated_vertices();
226 mesh_.garbage_collection();
void snap(double _epsilon)
snaps boundary vertices
Snaps selected vertices at boundaries.