Subversion Repositories gelsvn

Rev

Rev 632 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 632 Rev 652
Line 10... Line 10...
10
#include <cfloat>
10
#include <cfloat>
11
#include <queue>
11
#include <queue>
12
#include <vector>
12
#include <vector>
13
 
13
 
14
#include "../CGLA/Vec3d.h"
14
#include "../CGLA/Vec3d.h"
15
 
-
 
-
 
15
#include "../Geometry/Implicit.h"
16
//#include "Manifold.h"
16
//#include "Manifold.h"
17
#include "AttributeVector.h"
17
#include "AttributeVector.h"
-
 
18
#include "triangulate.h"
-
 
19
#include "smooth.h"
18
 
20
 
19
namespace HMesh
21
namespace HMesh
20
{
22
{
21
    using namespace std;
23
    using namespace std;
22
    using namespace CGLA;
24
    using namespace CGLA;
-
 
25
    using namespace Geometry;
23
	
26
	
24
    // Small utility functions
27
    // Small utility functions
25
    namespace 
28
    namespace 
26
    {
29
    {
27
        class LineSeg
30
        class LineSeg
Line 674... Line 677...
674
		if(anneal)
677
		if(anneal)
675
			simulated_annealing_optimization(m, energy_fun);
678
			simulated_annealing_optimization(m, energy_fun);
676
		else
679
		else
677
			priority_queue_optimization(m, energy_fun);
680
			priority_queue_optimization(m, energy_fun);
678
	}
681
	}
-
 
682
    
-
 
683
    
-
 
684
    void edge_equalize(Manifold& m, const Implicit& imp, int max_iter)
-
 
685
    {
-
 
686
        
-
 
687
        for(int iter=0;iter<max_iter;++iter)
-
 
688
        {
-
 
689
            float avg_edge_len=0;
-
 
690
            for(HalfEdgeIDIterator h = m.halfedges_begin(); h != m.halfedges_end();++h)
-
 
691
                avg_edge_len += length(m, *h);
-
 
692
            avg_edge_len /= m.no_halfedges();
-
 
693
            
-
 
694
            TAL_smoothing(m,1,1);
-
 
695
            for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
696
                imp.push_to_surface(m.pos(*vid),0,avg_edge_len*0.5);
-
 
697
            
-
 
698
            vector<float> edge_lengths;
-
 
699
            int n=0;
-
 
700
            for(HalfEdgeIDIterator h = m.halfedges_begin(); h != m.halfedges_end();++h,++n)
-
 
701
                edge_lengths.push_back(length(m, *h));
-
 
702
            sort(edge_lengths.begin(), edge_lengths.end());
-
 
703
            float med_len = edge_lengths[n/2];
-
 
704
            
-
 
705
            vector<HalfEdgeID> short_edges, long_edges;
-
 
706
            for(HalfEdgeIDIterator h = m.halfedges_begin(); h != m.halfedges_end();++h)
-
 
707
                if(*h<m.walker(*h).opp().halfedge())
-
 
708
                {
-
 
709
                    float l = length(m,*h);
-
 
710
                    if(l> (4/3.0) * med_len)
-
 
711
                        long_edges.push_back(*h);
-
 
712
                    else if(l< (4/5.0) * med_len)
-
 
713
                        short_edges.push_back(*h);
-
 
714
                }
-
 
715
            for(int i=0;i<long_edges.size(); ++i)
-
 
716
                if(m.in_use(long_edges[i]))
-
 
717
                    m.split_edge(long_edges[i]);
-
 
718
            shortest_edge_triangulate(m);
-
 
719
            
-
 
720
            for(int i=0;i<short_edges.size(); ++i)
-
 
721
                if(m.in_use(short_edges[i]) && precond_collapse_edge(m, short_edges[i]))
-
 
722
                {
-
 
723
                    Walker w = m.walker(short_edges[i]);
-
 
724
                    Vec3d mid_point = 0.5*(m.pos(w.vertex())+m.pos(w.opp().vertex()));
-
 
725
                    bool illegal = false;
-
 
726
                    for(Walker wc=m.walker(w.vertex()); !wc.full_circle(); wc = wc.circulate_vertex_ccw())
-
 
727
                        if(length(m.pos(wc.vertex())-mid_point) > (4/3.0)* med_len)
-
 
728
                            illegal = true;
-
 
729
                    for(Walker wc=m.walker(w.opp().vertex()); !wc.full_circle(); wc = wc.circulate_vertex_ccw())
-
 
730
                        if(length(m.pos(wc.vertex())-mid_point) > (4/3.0)* med_len)
-
 
731
                            illegal = true;
-
 
732
                    
-
 
733
                    if(!illegal)
-
 
734
                    {
-
 
735
                        if(boundary(m,w.vertex()) && !boundary(m,w.opp().vertex()))
-
 
736
                            m.collapse_edge(short_edges[i],false);
-
 
737
                        else if(!boundary(m,w.vertex()) && boundary(m,w.opp().vertex()));
-
 
738
                        else
-
 
739
                            m.collapse_edge(short_edges[i],true);
-
 
740
                    }
-
 
741
                }
-
 
742
            //        TAL_smoothing(m,.95,5);
-
 
743
            //        for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
744
            //            imp.push_to_surface(m.pos(*vid));
-
 
745
            
-
 
746
            maximize_min_angle(m, 0.9);
-
 
747
        }
-
 
748
        m.cleanup();
-
 
749
        
-
 
750
    }
679
}
751
}