diff --git a/HoleFillerPlugin.cc b/HoleFillerPlugin.cc index 71fe020577f99199d6ce3de540b0d632f21390aa..ef09f973882ecd337533f7907ec9c181cd116304 100644 --- a/HoleFillerPlugin.cc +++ b/HoleFillerPlugin.cc @@ -638,7 +638,7 @@ void HoleFillerPlugin::fillHole(int _objectID, int _edgeHandle){ } //check edgeHandle - TriMesh::EdgeHandle eh(_edgeHandle); + OpenMesh::SmartEdgeHandle eh(_edgeHandle); if ( !eh.is_valid() || !mesh->is_boundary(eh) ){ emit log(LOGERR, tr("Invalid edge handle.") ); diff --git a/HoleFillerT.hh b/HoleFillerT.hh index de345b67cebc0a2d2b7cbbfbe12791465bb9d22d..fa57851b86ddeb065ce2891711993f79d24d5837 100644 --- a/HoleFillerT.hh +++ b/HoleFillerT.hh @@ -53,6 +53,7 @@ #include <OpenMesh/Core/Utils/vector_cast.hh> #include "OpenMeshUtils.hh" #include <OpenMesh/Tools/Smoother/JacobiLaplaceSmootherT.hh> +#include <OpenMesh/Core/Mesh/PolyConnectivity.hh> //============================================================================= @@ -105,7 +106,8 @@ public: void fill_hole( EH _eh, int _stages = 3 ); // Fair a filling - void fairing( std::vector< FH >& _faceHandles ); + //void fairing( std::vector< FH >& _faceHandles ); + void fairing( std::vector< OpenMesh::SmartFaceHandle >& _faceHandles ); // Remove degenerated faces from the filling void removeDegeneratedFaces( std::vector< FH >& _faceHandles ); @@ -116,7 +118,7 @@ private: bool refine( FH _fh ); // Relax an edge - bool relax_edge( EH _eh ); + bool relax_edge( OpenMesh::SmartEdgeHandle _eh ); // Test whether a point _x lies in the circumsphere of _a,_b,_c. bool in_circumsphere( const Point & _x, @@ -131,7 +133,7 @@ private: Weight weight( int _i, int _j, int _k ); // Does edge (_u,_v) already exist? - bool exists_edge( VH _u, VH _w ); + bool exists_edge( OpenMesh::SmartVertexHandle _u, VH _w ); // Compute the area of the triangle (_a,_b,_c). Scalar area( VH _a, VH _b, VH _c ); @@ -171,16 +173,16 @@ private: // This vector contains all vertices of the hole (in order) - VHVec boundary_vertex_; + std::vector< OpenMesh::SmartVertexHandle > boundary_vertex_; // This vector contains all vertices that are opposite to an edge of the hole VHVec opposite_vertex_; // This vector contains all edges of the hole (in order) - std::vector< EH > hole_edge_; + std::vector< OpenMesh::SmartEdgeHandle > hole_edge_; // This vector stores handles to all triangles of the current hole - std::vector< FH > hole_triangle_; + std::vector< OpenMesh::SmartFaceHandle > hole_triangle_; // These are the two central arrays that are needed for the dynamic // programming approach to hole filling. diff --git a/HoleFillerT_impl.hh b/HoleFillerT_impl.hh index be101c951823b22b71bbe99d1bd82862fbae7687..5a04df4a130e8a5d8fc40f90ac229c82cfaf41a3 100644 --- a/HoleFillerT_impl.hh +++ b/HoleFillerT_impl.hh @@ -89,21 +89,19 @@ HoleFiller< MeshT >::fill_all_holes( int _stages ) std::vector< EH > bdry_edge; - for ( EI ei = mesh_.edges_begin(); - ei != mesh_.edges_end(); ++ei ) - if ( mesh_.is_boundary( *ei ) ) - bdry_edge.push_back( *ei ); + for (auto ei : mesh_.edges()) + if ( ei.is_boundary() ) + bdry_edge.push_back( ei ); // Fill holes int cnt = 0; - for ( typename std::vector< EH >::iterator i = bdry_edge.begin(); - i != bdry_edge.end(); ++i ) - if ( mesh_.is_boundary( *i ) ) + for (auto i : bdry_edge) + if ( mesh_.is_boundary( i ) ) { ++cnt; std::cerr << "Filling hole " << cnt << "\n"; - fill_hole( *i, _stages ); + fill_hole( i, _stages ); } @@ -148,9 +146,10 @@ HoleFiller< MeshT >::fill_hole( EH _eh, int _stages ) // Get boundary halfedge - HH hh = mesh_.halfedge_handle( _eh, 0 ); - if ( ! mesh_.is_boundary( hh ) ) - hh = mesh_.opposite_halfedge_handle( hh ); + OpenMesh::SmartHalfedgeHandle hh = make_smart(_eh, mesh_).h0(); + + if ( ! hh.is_boundary() ) + hh = hh.opp(); // Collect boundary vertices @@ -158,28 +157,26 @@ HoleFiller< MeshT >::fill_hole( EH _eh, int _stages ) boundary_vertex_.clear(); opposite_vertex_.clear(); - HH ch = hh; + OpenMesh::SmartHalfedgeHandle ch = hh; do { - boundary_vertex_.push_back( mesh_.from_vertex_handle( ch ) ); - opposite_vertex_.push_back( mesh_.to_vertex_handle - (mesh_.next_halfedge_handle( mesh_.opposite_halfedge_handle( ch ) ) ) ); - + boundary_vertex_.push_back( ch.from() ); + opposite_vertex_.push_back( ch.opp().next().to() ); //check number of outgoing boundary HEH's at Vertex int c = 0; - VH vh = mesh_.to_vertex_handle(ch); + OpenMesh::SmartVertexHandle vh = ch.to(); - for ( typename MeshT::VertexOHalfedgeIter voh_it(mesh_,vh); voh_it.is_valid(); ++voh_it) - if ( mesh_.is_boundary( *voh_it ) ) + for (auto voh_it : vh.outgoing_halfedges()) + if ( voh_it.is_boundary() ) c++; if ( c >= 2){ - HH op = mesh_.opposite_halfedge_handle( ch ); + OpenMesh::SmartHalfedgeHandle op = ch.opp(); typename MeshT::VertexOHalfedgeIter voh_it(mesh_,op); ch = *(++voh_it); }else - ch = mesh_.next_halfedge_handle( ch ); + ch = ch.next(); } while ( ch != hh ); @@ -235,7 +232,7 @@ HoleFiller< MeshT >::fill_hole( EH _eh, int _stages ) std::cerr << " Stage 2 : Fairing the filling ... "; - std::vector< FH > handles = hole_triangle_; + std::vector< OpenMesh::SmartFaceHandle > handles = hole_triangle_; fairing(handles); @@ -256,7 +253,7 @@ HoleFiller< MeshT >::fill_hole( EH _eh, int _stages ) /// path fairing template< class MeshT > void -HoleFiller< MeshT >::fairing( std::vector< FH >& _faceHandles ){ +HoleFiller< MeshT >::fairing( std::vector< OpenMesh::SmartFaceHandle >& _faceHandles ){ //generate vector of all edges hole_edge_.clear(); @@ -277,24 +274,17 @@ HoleFiller< MeshT >::fairing( std::vector< FH >& _faceHandles ){ if (! mesh_.get_property_handle(orderProp,"orderProp") ) mesh_.add_property( orderProp, "orderProp" ); - EI eIt; - EI eEnd = mesh_.edges_end(); - VI vIt; - VI vEnd = mesh_.vertices_end(); - FI fIt; - FI fEnd = mesh_.faces_end(); - //init properties by setting all of them to false - for (fIt = mesh_.faces_begin(); fIt != fEnd; ++fIt){ - mesh_.property( orderProp, *fIt ) = false; - mesh_.property( faceProp, *fIt ) = false; + for (auto fIt : mesh_.faces()) { + mesh_.property( orderProp, fIt ) = false; + mesh_.property( faceProp, fIt ) = false; } - for (eIt = mesh_.edges_begin(); eIt != eEnd; ++eIt) - mesh_.property( edgeProp, *eIt ) = false; + for (auto eIt : mesh_.edges()) + mesh_.property( edgeProp, eIt ) = false; - for (vIt = mesh_.vertices_begin(); vIt != vEnd; ++vIt){ - mesh_.property( vertexProp, *vIt ) = false; + for (auto vIt : mesh_.vertices()) { + mesh_.property( vertexProp, vIt ) = false; } //set face property @@ -304,53 +294,52 @@ HoleFiller< MeshT >::fairing( std::vector< FH >& _faceHandles ){ //set properties for (unsigned int i = 0; i < hole_triangle_.size(); i++){ - for (FEI fei = mesh_.fe_iter( hole_triangle_[i] ); fei.is_valid(); ++fei){ - mesh_.status( *fei ).set_locked(true); + for (auto fei : hole_triangle_[i].edges()) { + mesh_.status( fei ).set_locked(true); //set edge property for all edges inside the hole (eg not on the hole boundary) - if (mesh_.property( faceProp, mesh_.face_handle(mesh_.halfedge_handle(*fei, 0) ) ) && - mesh_.property( faceProp, mesh_.face_handle(mesh_.halfedge_handle(*fei, 1) ) ) ){ + if (mesh_.property( faceProp, fei.h0().face() ) && + mesh_.property( faceProp, fei.h1().face() ) ){ - mesh_.property( edgeProp, *fei ) = true; - hole_edge_.push_back( *fei ); - mesh_.status( *fei ).set_locked(false); + mesh_.property( edgeProp, fei ) = true; + hole_edge_.push_back( fei ); + mesh_.status( fei ).set_locked(false); } } /// @TODO, strange iterator at property! - for (FVI fvi = mesh_.fv_iter( hole_triangle_[i] ); fvi.is_valid(); ++fvi){ + for (auto fvi : hole_triangle_[i].vertices()){ //set vertex property for all vertices of the hole - for ( VFI vfi = mesh_.vf_iter( *fvi ); vfi.is_valid(); ++vfi ) - mesh_.property( vertexProp, *fvi ) = true; + for ( auto vfi : fvi.faces() ) + mesh_.property( vertexProp, fvi ) = true; } } //calculate scaling weights for vertices - for (vIt = mesh_.vertices_begin(); vIt != vEnd; ++vIt) - if (mesh_.property(vertexProp, *vIt)){ + for (auto vIt : mesh_.vertices()) + if (mesh_.property(vertexProp, vIt)){ Scalar cnt = 0; Scalar scale = 0; - for ( VOHI voh_it = mesh_.voh_iter( *vIt ); voh_it.is_valid(); ++voh_it ) + for ( auto voh_it : vIt.outgoing_halfedges()) { - HH h2 = mesh_.opposite_halfedge_handle( *voh_it ); - if (mesh_.face_handle(*voh_it).is_valid() && - mesh_.face_handle(h2).is_valid() && - mesh_.property(faceProp, mesh_.face_handle( *voh_it ) ) && - mesh_.property(faceProp, mesh_.face_handle(h2) )) + if (voh_it.face().is_valid() && + voh_it.opp().face().is_valid() && + mesh_.property(faceProp, voh_it.face() ) && + mesh_.property(faceProp, voh_it.opp().face() )) continue; cnt += 1.0f; - Point p0 = mesh_.point( *vIt ); - Point p1 = mesh_.point( mesh_.to_vertex_handle( *voh_it ) ); + Point p0 = mesh_.point( vIt ); + Point p1 = mesh_.point( voh_it.to() ); scale += ( p1 - p0 ).norm(); } scale /= cnt; - mesh_.property( scale_, *vIt ) = scale; + mesh_.property( scale_, vIt ) = scale; } mesh_.remove_property(edgeProp); @@ -376,8 +365,8 @@ HoleFiller< MeshT >::fairing( std::vector< FH >& _faceHandles ){ } // unlock everything - for ( EI ei = mesh_.edges_begin(); ei != mesh_.edges_end(); ++ei ) - mesh_.status( *ei ).set_locked( false ); + for ( auto ei : mesh_.edges()) + mesh_.status( ei ).set_locked( false ); } //============================================================================= @@ -397,9 +386,9 @@ HoleFiller< MeshT >::refine( FH _fh ) // Collect the three edges of the face into e0, e1, e2 FEI fei = mesh_.fe_iter( _fh ); - EH e0 = *fei; ++fei; - EH e1 = *fei; ++fei; - EH e2 = *fei; ++fei; + OpenMesh::SmartEdgeHandle e0 = *fei; ++fei; + OpenMesh::SmartEdgeHandle e1 = *fei; ++fei; + OpenMesh::SmartEdgeHandle e2 = *fei; ++fei; // Collect the vertices, vertex positions and scale factors of the face. @@ -440,20 +429,19 @@ HoleFiller< MeshT >::refine( FH _fh ) ( d2 > scale && d2 > scale2 ) ) { // Split the face ... - - VH ch = mesh_.add_vertex( center ); + OpenMesh::SmartVertexHandle ch = mesh_.add_vertex( center ); mesh_.split( _fh, ch ); // ... put the new triangles into the global triangle list ... - for ( VFI vfi = mesh_.vf_iter( ch ); vfi.is_valid(); ++vfi ) - if ( *vfi != _fh ) - hole_triangle_.push_back( *vfi ); + for ( auto vfi : ch.faces() ) + if ( vfi != _fh ) + hole_triangle_.push_back( vfi ); // ... put the new edges into the global edge list ... - for ( VEI vei = mesh_.ve_iter( ch ); vei.is_valid(); ++vei ) - hole_edge_.push_back( *vei ); + for ( auto vei : ch.edges() ) + hole_edge_.push_back( vei ); // ... and set the appropriate scale factor for the new vertex. @@ -480,30 +468,25 @@ HoleFiller< MeshT >::refine( FH _fh ) template< class MeshT > bool -HoleFiller< MeshT >::relax_edge( EH _eh ) +HoleFiller< MeshT >::relax_edge( OpenMesh::SmartEdgeHandle _eh ) { if ( mesh_.status( _eh ).locked() ) return false; // Abbreviations for the two halfedges of _eh - HH h0 = mesh_.halfedge_handle( _eh, 0 ); - HH h1 = mesh_.halfedge_handle( _eh, 1 ); + OpenMesh::SmartHalfedgeHandle h0 = _eh.h0(); + OpenMesh::SmartHalfedgeHandle h1 = _eh.h1(); // Get the two end-vertices u and v of the edge - Point u( mesh_.point( mesh_.to_vertex_handle( h0 ) ) ); - Point v( mesh_.point( mesh_.to_vertex_handle( h1 ) ) ); + Point u( mesh_.point( h0.to() ) ); + Point v( mesh_.point( h1.to() ) ); // Get the two opposing vertices a and b - Point a( mesh_.point - ( mesh_.to_vertex_handle - ( mesh_.next_halfedge_handle( h0 ) ) ) ); - - Point b( mesh_.point - ( mesh_.to_vertex_handle - ( mesh_.next_halfedge_handle( h1 ) ) ) ); + Point a( mesh_.point( h0.next().to() ) ); + Point b( mesh_.point( h1.next().to() ) ); // If the circumsphere criterion is fullfilled AND if the flip is // topologically admissible, we do it. @@ -583,7 +566,7 @@ HoleFiller< MeshT >::fill( int _i, int _j ) // Create and store the middle triangle, store its edges. - FH fh = mesh_.add_face( boundary_vertex_[_i], + OpenMesh::SmartFaceHandle fh = mesh_.add_face( boundary_vertex_[_i], boundary_vertex_[ l_[_i][_j] ], boundary_vertex_[_j] ); hole_triangle_.push_back( fh ); @@ -688,11 +671,11 @@ HoleFiller< MeshT >::weight( int _i, int _j, int _k ) template< class MeshT > bool -HoleFiller< MeshT >::exists_edge( VH _u, VH _w ) +HoleFiller< MeshT >::exists_edge( OpenMesh::SmartVertexHandle _u, VH _w ) { - for ( VOHI vohi = mesh_.voh_iter( _u ); vohi.is_valid(); ++vohi ) - if ( ! mesh_.is_boundary( mesh_.edge_handle( *vohi ) ) ) - if ( mesh_.to_vertex_handle( *vohi ) == _w ) + for ( auto vohi : _u.outgoing_halfedges() ) + if ( ! vohi.edge().is_boundary() ) + if ( vohi.to() == _w ) return true; return false; diff --git a/HoleInfoT.hh b/HoleInfoT.hh index f3c8c248d91937ac4c38929b41228cc1d5bccfea..582dda4f215cc07047cbf9204a761b962732a904 100644 --- a/HoleInfoT.hh +++ b/HoleInfoT.hh @@ -54,7 +54,7 @@ class HoleInfo : public PerObjectData { public : - typedef std::vector< typename MeshT::EdgeHandle > Hole; + typedef std::vector< typename OpenMesh::SmartEdgeHandle > Hole; private : // the mesh @@ -103,7 +103,7 @@ class HoleInfo : public PerObjectData */ void getHoleInfo(const unsigned int _index, size_t& _edges, typename MeshT::Scalar& _diagonal, typename MeshT::Scalar& _boundaryLength) const; - std::vector< std::vector< typename MeshT::EdgeHandle > >* holes(); + std::vector< std::vector< typename OpenMesh::SmartEdgeHandle > >* holes(); }; #if defined(INCLUDE_TEMPLATES) && !defined(HOLEINFO_C) diff --git a/HoleInfoT_impl.hh b/HoleInfoT_impl.hh index 3932d99a9221aabb7a0188af3c8676df82500b82..56c6228c2bc8cf135254cac8848c3070c7009fe9 100644 --- a/HoleInfoT_impl.hh +++ b/HoleInfoT_impl.hh @@ -75,27 +75,26 @@ void HoleInfo< MeshT >::getHoles() mesh_->add_property( boundary_search, "Boundary search" ); // Initialize Property - typename MeshT::EdgeIter e_it, e_end=mesh_->edges_end(); - for (e_it=mesh_->edges_begin(); e_it!=e_end; ++e_it) { - mesh_->property( boundary_search , *e_it ) = false; + for (auto e_it : mesh_->edges()) { + mesh_->property( boundary_search , e_it ) = false; } holes_.clear(); - for (e_it=mesh_->edges_begin(); e_it!=e_end; ++e_it) { + for (auto e_it : mesh_->edges()) { // Skip already visited edges - if ( mesh_->property( boundary_search , *e_it ) ) + if ( mesh_->property( boundary_search , e_it ) ) continue; // Check only boundary edges - if ( !mesh_->is_boundary(*e_it)) + if ( !e_it.is_boundary()) continue; // Get boundary halfedge - typename MeshT::HalfedgeHandle hh = mesh_->halfedge_handle( *e_it, 0 ); - if ( ! mesh_->is_boundary( hh ) ) - hh = mesh_->opposite_halfedge_handle( hh ); + typename OpenMesh::SmartHalfedgeHandle hh = e_it.h0(); + if ( ! hh.is_boundary() ) + hh = hh.opp(); typename MeshT::Point center(0,0,0); @@ -103,30 +102,30 @@ void HoleInfo< MeshT >::getHoles() Hole currentHole; // Collect boundary edges - typename MeshT::HalfedgeHandle ch = hh; + typename OpenMesh::SmartHalfedgeHandle ch = hh; do { - currentHole.push_back( mesh_->edge_handle(ch) ); + currentHole.push_back( ch.edge() ); - center += mesh_->point( mesh_->from_vertex_handle(ch) ); + center += mesh_->point( ch.from() ); - mesh_->property( boundary_search , mesh_->edge_handle(ch) ) = true; + mesh_->property( boundary_search , ch.edge() ) = true; //check number of outgoing boundary HEH's at Vertex int c = 0; - typename MeshT::VertexHandle vh = mesh_->to_vertex_handle(ch); + typename OpenMesh::SmartVertexHandle vh = ch.to(); - for ( typename MeshT::VertexOHalfedgeIter voh_it(*mesh_,vh); voh_it.is_valid(); ++voh_it) - if ( mesh_->is_boundary( *voh_it ) ) + for ( auto voh_it : vh.outgoing_halfedges()) + if ( voh_it.is_boundary() ) c++; if ( c >= 2){ - typename MeshT::HalfedgeHandle op = mesh_->opposite_halfedge_handle( ch ); + typename MeshT::HalfedgeHandle op = ch.opp(); typename MeshT::VertexOHalfedgeIter voh_it(*mesh_,op); ch = *(++voh_it); } else - ch = mesh_->next_halfedge_handle( ch ); + ch = ch.next(); } while ( ch != hh ); @@ -138,7 +137,7 @@ void HoleInfo< MeshT >::getHoles() int err = 0; for (unsigned int i=0; i < currentHole.size(); i++){ - typename MeshT::HalfedgeHandle hh = mesh_->halfedge_handle( currentHole[i], 0 ); + typename MeshT::HalfedgeHandle hh = currentHole[i].h0(); if ( ! mesh_->is_boundary( hh ) ) hh = mesh_->opposite_halfedge_handle( hh ); @@ -288,7 +287,7 @@ void HoleInfo< MeshT >::getHoleInfo(const unsigned int _index, size_t& _edges, t /// get the holes vector template< class MeshT > -std::vector< std::vector< typename MeshT::EdgeHandle > >* HoleInfo< MeshT >::holes() +std::vector< std::vector< typename OpenMesh::SmartEdgeHandle > >* HoleInfo< MeshT >::holes() { return &holes_; }