Subversion Repositories gelsvn

Rev

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

Rev 633 Rev 635
Line 5... Line 5...
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
#include <thread>
7
#include <thread>
8
#include "smooth.h"
8
#include "smooth.h"
9
 
9
 
-
 
10
#include <future>
10
#include <vector>
11
#include <vector>
11
#include <algorithm>
12
#include <algorithm>
12
#include "../CGLA/Mat3x3d.h"
13
#include "../CGLA/Mat3x3d.h"
13
#include "../CGLA/Vec3d.h"
14
#include "../CGLA/Vec3d.h"
14
#include "../CGLA/Quatd.h"
15
#include "../CGLA/Quatd.h"
Line 66... Line 67...
66
    }
67
    }
67
    
68
    
68
    
69
    
69
    int CORES = 8;
70
    int CORES = 8;
70
    
71
    
-
 
72
    void laplacian_smooth_example(Manifold& m)
-
 
73
    {
-
 
74
        VertexAttributeVector<Vec3d> new_pos = m.positions_attribute_vector();
-
 
75
        for(VertexID v : m.vertices())
-
 
76
            if(!boundary(m, v))
-
 
77
            {
-
 
78
                Vec3d L(0);
-
 
79
                int n = circulate_vertex_ccw(m, v, [&](VertexID v){ L += m.pos(v); });
-
 
80
                new_pos[v] = L/n;
-
 
81
            }
-
 
82
        m.positions_attribute_vector() = new_pos;
-
 
83
    
-
 
84
    }
-
 
85
    
71
    void laplacian_smooth0(Manifold& m,float weight, int max_iter)
86
    void laplacian_smooth0(Manifold& m,float weight, int max_iter)
72
    {
87
    {
73
        for(int iter=0;iter<max_iter; ++iter) {
88
        for(int iter=0;iter<max_iter; ++iter) {
74
            VertexAttributeVector<Vec3d> L_attr(m.no_vertices());
89
            VertexAttributeVector<Vec3d> L_attr(m.no_vertices());
75
            
90
            
Line 193... Line 208...
193
        
208
        
194
    }
209
    }
195
    
210
    
196
    typedef vector<vector<VertexID>> VertexIDBatches;
211
    typedef vector<vector<VertexID>> VertexIDBatches;
197
    
212
    
-
 
213
//    template<typename  T>
-
 
214
//    void for_each_vertex_parallel(int no_threads, const VertexIDBatches& batches, const T& f) {
-
 
215
//        vector<future<void>> f_vec(no_threads);
-
 
216
//        for(auto t : range(0, no_threads))
-
 
217
//            f_vec[t] = async(launch::async, f, ref(batches[t]));
-
 
218
//    }
198
    template<typename  T>
219
    template<typename  T>
199
    void for_each_vertex_parallel(int no_threads, const VertexIDBatches& batches, const T& f) {
220
    void for_each_vertex_parallel(int no_threads, const VertexIDBatches& batches, const T& f) {
200
        vector<thread> t_vec(no_threads);
221
        vector<thread> t_vec(no_threads);
201
        for(auto t : range(0, no_threads))
222
        for(auto t : range(0, no_threads))
202
            t_vec[t] = thread(f, ref(batches[t]));
223
            t_vec[t] = thread(f, ref(batches[t]));
Line 233... Line 254...
233
 
254
 
234
 
255
 
235
 
256
 
236
    void laplacian_smooth(Manifold& m,float weight, int max_iter)
257
    void laplacian_smooth(Manifold& m,float weight, int max_iter)
237
    {
258
    {
-
 
259
        laplacian_smooth_example(m);
238
        laplacian_smooth6(m,weight,max_iter);
260
//        laplacian_smooth7(m,weight,max_iter);
239
//        Util::Timer tim;
261
//        Util::Timer tim;
240
//
262
//
241
//        cout << "Method 0: ";
263
//        cout << "Method 0: ";
242
//        for(int i=0;i<5;++i) {
264
//        for(int i=0;i<5;++i) {
243
//            Manifold m2 = m;
265
//            Manifold m2 = m;