Subversion Repositories gelsvn

Rev

Rev 658 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 658 Rev 662
Line 6... Line 6...
6
#include <iterator>
6
#include <iterator>
7
#include "Manifold.h"
7
#include "Manifold.h"
8
 
8
 
9
#include <iostream>
9
#include <iostream>
10
#include <vector>
10
#include <vector>
11
#include <map>
11
#include <unordered_map>
12
#include <iterator>
12
#include <iterator>
13
 
13
 
14
#include "../Geometry/TriMesh.h"
14
#include "../Geometry/TriMesh.h"
15
 
15
 
16
namespace HMesh
16
namespace HMesh
Line 50... Line 50...
50
                }
50
                }
51
                else{
51
                else{
52
                    return v1 < k2.v1;
52
                    return v1 < k2.v1;
53
                }
53
                }
54
            }
54
            }
-
 
55
            
-
 
56
            bool operator==(const EdgeKey& k2) const {return k2.v0 == v0 && k2.v1==v1;}
-
 
57
            
-
 
58
            size_t hash() const {return v0.get_index()*3125*49+v1.get_index()*3125+7;}
55
        private:
59
        private:
56
            VertexID v0;
60
            VertexID v0;
57
            VertexID v1;
61
            VertexID v1;
58
        };
62
        };
59
		
63
		
Line 519... Line 523...
519
                {
523
                {
520
                    vector<VertexID>::iterator iter;
524
                    vector<VertexID>::iterator iter;
521
                    
525
                    
522
                    if(v0a == v0b)
526
                    if(v0a == v0b)
523
                    {
527
                    {
524
                        iter = find(lisect.begin(), lisect.end(), v1a);
528
                        iter = find(lisect.begin(), lisect.end(), v0a);
525
                        if(iter != lisect.end())
529
                        if(iter != lisect.end())
526
                            lisect.erase(iter);
530
                            lisect.erase(iter);
527
                    }
531
                    }
528
                    iter = find(lisect.begin(), lisect.end(), kernel.vert(kernel.next(h1)));
532
                    iter = find(lisect.begin(), lisect.end(), kernel.vert(kernel.next(h1)));
529
                    if(iter != lisect.end())
533
                    if(iter != lisect.end())
Line 963... Line 967...
963
        {
967
        {
964
            const float_type* v0 = &vertvec[i*3];
968
            const float_type* v0 = &vertvec[i*3];
965
            pos(vids[i] = kernel.add_vertex()) = Manifold::Vec(v0[0], v0[1], v0[2]);
969
            pos(vids[i] = kernel.add_vertex()) = Manifold::Vec(v0[0], v0[1], v0[2]);
966
        }
970
        }
967
        
971
        
-
 
972
        auto hash_fun = [](const EdgeKey& k) {return k.hash();};
968
        //map over the created edges - needed to preserve edge uniqueness
973
        //map over the created edges - needed to preserve edge uniqueness
969
        typedef map<EdgeKey, Edge> EdgeMap;
974
        typedef unordered_map<EdgeKey, Edge, decltype(hash_fun)> EdgeMap;
970
        EdgeMap edge_map;
975
        EdgeMap edge_map(no_vertices+no_faces,hash_fun);
971
        
976
        
972
        // counter that jumps between faces in indices vector
977
        // counter that jumps between faces in indices vector
973
        int_type n  = 0;
978
        int_type n  = 0;
974
        
979
        
975
        // create faces correspponding to faces stored in facevec
980
        // create faces correspponding to faces stored in facevec
Line 990... Line 995...
990
                VertexID v0 = vids[static_cast<size_type>(indices[j + n])];
995
                VertexID v0 = vids[static_cast<size_type>(indices[j + n])];
991
                VertexID v1 = vids[static_cast<size_type>(indices[(j + 1) % N + n])];
996
                VertexID v1 = vids[static_cast<size_type>(indices[(j + 1) % N + n])];
992
                
997
                
993
                // create key and search map for edge
998
                // create key and search map for edge
994
                EdgeKey ek(v0, v1);
999
                EdgeKey ek(v0, v1);
995
                EdgeMap::iterator em_iter = edge_map.find(ek);
1000
                typename EdgeMap::iterator em_iter = edge_map.find(ek);
996
                
1001
                
997
                // current edge has not been created
1002
                // current edge has not been created
998
                if(em_iter == edge_map.end()){
1003
                if(em_iter == edge_map.end()){
999
                    // create edge for map
1004
                    // create edge for map
1000
                    Edge e;
1005
                    Edge e;
Line 1052... Line 1057...
1052
                kernel.remove_vertex(*v);
1057
                kernel.remove_vertex(*v);
1053
        }
1058
        }
1054
        
1059
        
1055
        // boundary check while avoiding unused vertices
1060
        // boundary check while avoiding unused vertices
1056
        for(VertexIDIterator v = vertices_begin(); v != vertices_end(); ++v){
1061
        for(VertexIDIterator v = vertices_begin(); v != vertices_end(); ++v){
1057
            if((*v) != InvalidVertexID)
1062
            if((*v) != InvalidVertexID && in_use(*v))
1058
                ensure_boundary_consistency(*v);
1063
                ensure_boundary_consistency(*v);
1059
        }
1064
        }
1060
    }
1065
    }
1061
    void Manifold::link(HalfEdgeID h0, HalfEdgeID h1)
1066
    void Manifold::link(HalfEdgeID h0, HalfEdgeID h1)
1062
    {
1067
    {
Line 1072... Line 1077...
1072
    {
1077
    {
1073
        // boundary consistency check by performing two vertex circulations
1078
        // boundary consistency check by performing two vertex circulations
1074
        HalfEdgeID h = kernel.out(v);
1079
        HalfEdgeID h = kernel.out(v);
1075
        HalfEdgeID last = h;
1080
        HalfEdgeID last = h;
1076
        
1081
        
-
 
1082
        int c = 0;
1077
        // step 1: circle through edges pointing away from vertex until reaching a null face
1083
        // step 1: circle through edges pointing away from vertex until reaching a null face
1078
        while(kernel.face(h) != InvalidFaceID){
1084
        while(kernel.face(h) != InvalidFaceID){
1079
            h = kernel.opp(kernel.prev(h));
1085
            h = kernel.opp(kernel.prev(h));
1080
            if(h == last) // We came full circle - vertex not boundary - return.
1086
            if(h == last || ++c == 1e6) // We came full circle - vertex not boundary - return.
1081
                return;
1087
                return;
1082
        }
1088
        }
1083
        // null face encountered, we update our vertex with half edge index and prepare for step 2
1089
        // null face encountered, we update our vertex with half edge index and prepare for step 2
1084
        kernel.set_out(v, h);
1090
        kernel.set_out(v, h);
1085
        HalfEdgeID ho = kernel.opp(h);
1091
        HalfEdgeID ho = kernel.opp(h);