Subversion Repositories gelsvn

Rev

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

Rev 633 Rev 636
Line 184... Line 184...
184
    {
184
    {
185
        if(!in_use(vid))
185
        if(!in_use(vid))
186
            return false;
186
            return false;
187
    
187
    
188
        vector<FaceID> faces;
188
        vector<FaceID> faces;
189
        
-
 
190
        int N = circulate_vertex_ccw(*this, vid, [&](FaceID f) {
189
        int N = circulate_vertex_ccw(*this, vid, (std::function<void(FaceID)>)[&](FaceID f) {
191
            faces.push_back(f);
190
            faces.push_back(f);
192
        });
191
        });
193
        for(size_t i=0;i<N;++i)
192
        for(size_t i=0;i<N;++i)
194
            remove_face(faces[i]);
193
            remove_face(faces[i]);
195
            
194
            
Line 436... Line 435...
436
    
435
    
437
    size_t link_intersection(const Manifold& m, VertexID v0, VertexID v1, vector<VertexID>& lisect)
436
    size_t link_intersection(const Manifold& m, VertexID v0, VertexID v1, vector<VertexID>& lisect)
438
    {
437
    {
439
        // get the one-ring of v0
438
        // get the one-ring of v0
440
        vector<VertexID> link0;
439
        vector<VertexID> link0;
441
        circulate_vertex_ccw(m, v0, [&](VertexID vn) {
440
        circulate_vertex_ccw(m, v0, (std::function<void(VertexID)>)[&](VertexID vn) {
442
            link0.push_back(vn);
441
            link0.push_back(vn);
443
        });
442
        });
444
		
443
		
445
        // get the one-ring of v1
444
        // get the one-ring of v1
446
        vector<VertexID> link1;
445
        vector<VertexID> link1;
447
        circulate_vertex_ccw(m, v1, [&](VertexID vn) {
446
        circulate_vertex_ccw(m, v1, (std::function<void(VertexID)>)[&](VertexID vn) {
448
            link1.push_back(vn);
447
            link1.push_back(vn);
449
        });
448
        });
450
		
449
		
451
        // sort the vertices of the two rings
450
        // sort the vertices of the two rings
452
        sort(link0.begin(), link0.end());
451
        sort(link0.begin(), link0.end());
Line 534... Line 533...
534
                }
533
                }
535
            }
534
            }
536
            
535
            
537
            
536
            
538
            if(v0b != v0a)
537
            if(v0b != v0a)
539
                circulate_vertex_ccw(*this, v0b, [&](Walker hew) {
538
                circulate_vertex_ccw(*this, v0b, (std::function<void(Walker&)>)[&](Walker hew) {
540
                    kernel.set_vert(hew.opp().halfedge(), v0a);
539
                    kernel.set_vert(hew.opp().halfedge(), v0a);
541
                });
540
                });
542
            
541
            
543
            if(v1b != v1a)
542
            if(v1b != v1a)
544
                circulate_vertex_ccw(*this, v1b, [&](Walker hew) {
543
                circulate_vertex_ccw(*this, v1b, (std::function<void(Walker&)>)[&](Walker hew) {
545
                    kernel.set_vert(hew.opp().halfedge(), v1a);
544
                    kernel.set_vert(hew.opp().halfedge(), v1a);
546
                });
545
                });
547
            
546
            
548
            if(v0a != v0b)
547
            if(v0a != v0b)
549
            {
548
            {
Line 1300... Line 1299...
1300
    bool precond_flip_edge(const Manifold& m, HalfEdgeID h)
1299
    bool precond_flip_edge(const Manifold& m, HalfEdgeID h)
1301
    {
1300
    {
1302
        Walker j = m.walker(h);
1301
        Walker j = m.walker(h);
1303
        
1302
        
1304
        FaceID hf = j.face();
1303
        FaceID hf = j.face();
1305
        //        HalfEdgeID ho = j.opp().halfedge();
-
 
1306
        FaceID hof = j.opp().face();
1304
        FaceID hof = j.opp().face();
1307
        
1305
        
1308
        // boundary case
1306
        // boundary case
1309
        if(hf == InvalidFaceID || hof == InvalidFaceID)
1307
        if(hf == InvalidFaceID || hof == InvalidFaceID)
1310
            return false;
1308
           return false;
-
 
1309
        
1311
        
1310
        
1312
        // We can only flip an edge if both incident polygons are triangles.
1311
        // We can only flip an edge if both incident polygons are triangles.
1313
        if(no_edges(m, hf) != 3 || no_edges(m, hof) !=3)
1312
        if(no_edges(m, hf) != 3 || no_edges(m, hof) !=3)
1314
            return false;
1313
            return false;
1315
        
1314
        
-
 
1315
 
1316
        // non boundary vertices with a valency of less than 4(less than 3 after operation) degenerates mesh.
1316
        // non boundary vertices with a valency of less than 4(less than 3 after operation) degenerates mesh.
1317
        VertexID hv = j.vertex();
1317
        VertexID hv = j.vertex();
1318
        VertexID hov = j.opp().vertex();
1318
        VertexID hov = j.opp().vertex();
1319
        if((valency(m, hv) < 4 && !boundary(m, hv)) || (valency(m, hov) < 4 && !boundary(m, hov)))
1319
        if((valency(m, hv) < 4 && !boundary(m, hv)) || (valency(m, hov) < 4 && !boundary(m, hov))){
1320
            return false;
1320
            return false;
-
 
1321
        }
1321
        
1322
        
1322
        // Disallow flip if vertices being connected already are.
1323
        // Disallow flip if vertices being connected already are.
1323
        VertexID hnv = j.next().vertex();
1324
        VertexID hnv = j.next().vertex();
1324
        VertexID honv = j.opp().next().vertex();
1325
        VertexID honv = j.opp().next().vertex();
1325
        if(connected(m, hnv, honv))
1326
        if(connected(m, hnv, honv)){
1326
            return false;
1327
           return false;
-
 
1328
        }
1327
        
1329
        
1328
        return true;
1330
        return true;
1329
    }
1331
    }
1330
    
1332
    
1331
    bool boundary(const Manifold& m, VertexID v)
1333
    bool boundary(const Manifold& m, VertexID v)
1332
    {
1334
    {
1333
        Walker j  = m.walker(v);
1335
        Walker j  = m.walker(v);
1334
        return boundary(m, j.halfedge());
1336
        return boundary(m, j.halfedge());
1335
    }
1337
    }
-
 
1338
 
1336
    int valency(const Manifold& m, VertexID v)
1339
    int valency(const Manifold& m, VertexID v)
1337
    {
1340
    {
1338
        return circulate_vertex_ccw(m,v, [](Walker){});
1341
        return circulate_vertex_ccw(m,v, (std::function<void(Walker&)>)[](Walker){});
1339
    }
1342
    }
1340
    
1343
    
1341
    Manifold::Vec normal(const Manifold& m, VertexID v)
1344
    Manifold::Vec normal(const Manifold& m, VertexID v)
1342
    {
1345
    {
1343
        Manifold::Vec p0 = m.pos(v);
1346
        Manifold::Vec p0 = m.pos(v);
1344
        vector<Manifold::Vec> one_ring;
1347
        vector<Manifold::Vec> one_ring;
1345
        
1348
        
1346
        // run through outgoing edges, and store them normalized
1349
        // run through outgoing edges, and store them normalized
1347
        int N = circulate_vertex_ccw(m, v, [&](VertexID vn) {
1350
        int N = circulate_vertex_ccw(m, v, (std::function<void(VertexID)>)[&](VertexID vn) {
1348
            Manifold::Vec edge = m.pos(vn) - p0;
1351
            Manifold::Vec edge = m.pos(vn) - p0;
1349
            double l = length(edge);
1352
            double l = length(edge);
1350
            if(l > 0.0)
1353
            if(l > 0.0)
1351
                one_ring.push_back(edge/l);
1354
                one_ring.push_back(edge/l);
1352
        });
1355
        });
Line 1374... Line 1377...
1374
        if(sqr_l > 0.0f) return n / sqrt(sqr_l);
1377
        if(sqr_l > 0.0f) return n / sqrt(sqr_l);
1375
        
1378
        
1376
        return n;
1379
        return n;
1377
    }
1380
    }
1378
    
1381
    
-
 
1382
    
1379
    bool connected(const Manifold& m, VertexID v0, VertexID v1)
1383
    bool connected(const Manifold& m, VertexID v0, VertexID v1)
1380
    {
1384
    {
1381
        bool c=false;
1385
        bool c=false;
1382
        circulate_vertex_ccw(m, v0, [&](VertexID v){ c |= (v==v1);});
1386
        circulate_vertex_ccw(m, v0, (std::function<void(VertexID)>)[&](VertexID v){ c |= (v==v1);});
1383
        return c;
1387
        return c;
1384
    }
1388
    }
-
 
1389
 
1385
    
1390
    
1386
    int no_edges(const Manifold& m, FaceID f)
1391
    int no_edges(const Manifold& m, FaceID f)
1387
    {
1392
    {
1388
        return circulate_face_ccw(m, f, [](Walker w){});
1393
        return circulate_face_ccw(m, f, (std::function<void(Walker&)>)[](Walker w){});
1389
    }
1394
    }
1390
    
1395
    
1391
    Manifold::Vec normal(const Manifold& m, FaceID f)
1396
    Manifold::Vec normal(const Manifold& m, FaceID f)
1392
    {
1397
    {
1393
        vector<Manifold::Vec> v;
1398
        vector<Manifold::Vec> v;
1394
        
1399
        
1395
        int k= circulate_face_ccw(m, f, [&](VertexID vid) {
1400
        int k= circulate_face_ccw(m, f, (std::function<void(VertexID)>)[&](VertexID vid) {
1396
            v.push_back(m.pos(vid));
1401
            v.push_back(m.pos(vid));
1397
        });
1402
        });
1398
        
1403
        
1399
        Manifold::Vec norm(0);
1404
        Manifold::Vec norm(0);
1400
        for(int i=0;i<k;++i)
1405
        for(int i=0;i<k;++i)
Line 1412... Line 1417...
1412
    
1417
    
1413
    double area(const Manifold& m, FaceID fid)
1418
    double area(const Manifold& m, FaceID fid)
1414
    {
1419
    {
1415
        // Get all projected vertices
1420
        // Get all projected vertices
1416
        vector<Manifold::Vec> vertices;
1421
        vector<Manifold::Vec> vertices;
1417
        int N = circulate_face_ccw(m, fid, [&](VertexID vid) {
1422
        int N = circulate_face_ccw(m, fid, (std::function<void(VertexID)>)[&](VertexID vid) {
1418
            vertices.push_back(m.pos(vid));
1423
            vertices.push_back(m.pos(vid));
1419
        });
1424
        });
1420
 
1425
 
1421
        
1426
        
1422
        double area = 0;
1427
        double area = 0;
Line 1427... Line 1432...
1427
    }
1432
    }
1428
    
1433
    
1429
    Manifold::Vec centre(const Manifold& m, FaceID f)
1434
    Manifold::Vec centre(const Manifold& m, FaceID f)
1430
    {
1435
    {
1431
        Manifold::Vec c(0);
1436
        Manifold::Vec c(0);
1432
        int n = circulate_face_ccw(m, f, [&](VertexID v) {c+=m.pos(v);});
1437
        int n = circulate_face_ccw(m, f, (std::function<void(VertexID)>)[&](VertexID v) {c+=m.pos(v);});
1433
        return c / n;
1438
        return c / n;
1434
    }
1439
    }
1435
    
1440
    
1436
    double perimeter(const Manifold& m, FaceID f)
1441
    double perimeter(const Manifold& m, FaceID f)
1437
    {
1442
    {
1438
        double l=0.0;
1443
        double l=0.0;
1439
        circulate_face_ccw(m, f, [&](HalfEdgeID h) { l+= length(m, h);});
1444
        circulate_face_ccw(m, f, (std::function<void(HalfEdgeID)>)[&](HalfEdgeID h) { l+= length(m, h);});
1440
        return l;
1445
        return l;
1441
    }
1446
    }
1442
    
1447
    
1443
    bool boundary(const Manifold& m, HalfEdgeID h)
1448
    bool boundary(const Manifold& m, HalfEdgeID h)
1444
    {
1449
    {