Subversion Repositories gelsvn

Rev

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

Rev 657 Rev 662
Line 3... Line 3...
3
//  GEL
3
//  GEL
4
//
4
//
5
//  Created by J. Andreas Bærentzen on 09/10/13.
5
//  Created by J. Andreas Bærentzen on 09/10/13.
6
//
6
//
7
//
7
//
8
 
-
 
-
 
8
#include <thread>
-
 
9
#include <unistd.h>
9
#include <GL/glew.h>
10
#include <GL/glew.h>
10
#include <functional>
11
#include <functional>
11
#include "MeshEditor.h"
12
#include "MeshEditor.h"
12
#include <string>
13
#include <string>
13
#include <iostream>
14
#include <iostream>
Line 157... Line 158...
157
            VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
158
            VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
158
            VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
159
            VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
159
            VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
160
            VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
160
            VertexAttributeVector<Vec2d> curvature(mani.allocated_vertices());
161
            VertexAttributeVector<Vec2d> curvature(mani.allocated_vertices());
161
            
162
            
162
            //    curvature_tensors_from_edges(mani, curvature_tensors);
-
 
163
            //    for(int i=0;i<3; ++i)
-
 
164
            //        smooth_curvature_tensors(mani,curvature_tensors);
-
 
165
            //    curvature_from_tensors(mani, curvature_tensors,
-
 
166
            //                        min_curv_direction,
-
 
167
            //                        max_curv_direction,
-
 
168
            //                        curvature);
-
 
169
            
-
 
170
            //    void console_refit_polar(MeshEditor* me, const std::vector<std::string> & args)
-
 
171
            //    {
-
 
172
            //        if(wantshelp(args)) {
-
 
173
            //            me->printf("usage: simplify.polar <mesh 1> <mesh 2> <iter>");
-
 
174
            //            return;
-
 
175
            //        }
-
 
176
            //        int m1=1;
-
 
177
            //        int m2=2;
-
 
178
            //        int iter=1;
-
 
179
            //        int dim = 64;
-
 
180
            //        if(args.size() > 0){
-
 
181
            //            istringstream a0(args[0]);
-
 
182
            //            a0 >> m1;
-
 
183
            //        }
-
 
184
            //        if(args.size() > 1){
-
 
185
            //            istringstream a0(args[1]);
-
 
186
            //            a0 >> m2;
-
 
187
            //        }
-
 
188
            //        if(args.size() > 2){
-
 
189
            //            istringstream a0(args[2]);
-
 
190
            //            a0 >> iter;
-
 
191
            //        }
-
 
192
            //
-
 
193
            //        if(args.size() > 3){
-
 
194
            //            istringstream a0(args[3]);
-
 
195
            //            a0 >> dim;
-
 
196
            //        }
-
 
197
            //
-
 
198
            //
-
 
199
            //
-
 
200
            //        me->save_active_mesh();
-
 
201
            //
-
 
202
            //        smooth_and_refit(get_vis_obj(m1-1).mesh() , get_vis_obj(m2-1).mesh(), iter, dim);
-
 
203
            //    }
-
 
204
            //
-
 
205
            
163
            
206
            
164
            
207
            curvature_paraboloids(mani,
165
            curvature_paraboloids(mani,
208
                                  min_curv_direction,
166
                                  min_curv_direction,
209
                                  max_curv_direction,
167
                                  max_curv_direction,
Line 1163... Line 1121...
1163
            }
1121
            }
1164
            me->restore_active_mesh();
1122
            me->restore_active_mesh();
1165
            return;
1123
            return;
1166
        }
1124
        }
1167
        
1125
        
-
 
1126
        void console_save_trackball(MeshEditor* me, const std::vector<std::string> & args)
-
 
1127
        {
-
 
1128
            if(wantshelp(args)) {
-
 
1129
                me->printf("usage:  display.save_trackball");
-
 
1130
                me->printf("This function saves the trackball to disk");
-
 
1131
                return;
-
 
1132
            }
-
 
1133
            me->save_ball();
-
 
1134
            return;
-
 
1135
        }
-
 
1136
 
-
 
1137
        void console_load_trackball(MeshEditor* me, const std::vector<std::string> & args)
-
 
1138
        {
-
 
1139
            if(wantshelp(args)) {
-
 
1140
                me->printf("usage:  display.load_trackball");
-
 
1141
                me->printf("This function loads the trackball from disk");
-
 
1142
                return;
-
 
1143
            }
-
 
1144
            me->load_ball();
-
 
1145
            return;
-
 
1146
        }
-
 
1147
 
1168
        
1148
        
1169
    }
1149
    }
1170
    
1150
    
1171
    
1151
    
1172
    void MeshEditor::register_console_function(const std::string& name,
1152
    void MeshEditor::register_console_function(const std::string& name,
Line 1185... Line 1165...
1185
            return;
1165
            return;
1186
        }
1166
        }
1187
        
1167
        
1188
        if (console_visible)
1168
        if (console_visible)
1189
        {
1169
        {
-
 
1170
            static Timer tim;
-
 
1171
            if(key==13)
-
 
1172
                tim.start();
1190
            theConsole.keyboard(key);
1173
            theConsole.keyboard(key);
1191
            if(key == 13)
1174
            if(key == 13)
1192
            {
1175
            {
1193
                active_visobj().post_create_display_list();
1176
                active_visobj().post_create_display_list();
-
 
1177
                double t = tim.get_secs();
-
 
1178
                printf("%f seconds",t);
1194
            }
1179
            }
1195
            return;
1180
            return;
1196
        }
1181
        }
1197
        else {
1182
        else {
1198
            
1183
            
Line 1269... Line 1254...
1269
    void MeshEditor::key_left(){theConsole.key_left();}
1254
    void MeshEditor::key_left(){theConsole.key_left();}
1270
    void MeshEditor::key_right(){theConsole.key_right();}
1255
    void MeshEditor::key_right(){theConsole.key_right();}
1271
    void MeshEditor::key_home(){theConsole.key_home();}
1256
    void MeshEditor::key_home(){theConsole.key_home();}
1272
    void MeshEditor::key_end(){theConsole.key_end();}
1257
    void MeshEditor::key_end(){theConsole.key_end();}
1273
    
1258
    
-
 
1259
    
-
 
1260
    
1274
    void MeshEditor::grab_ball(TrackBallAction action, const CGLA::Vec2i& pos){
1261
    void MeshEditor::grab_ball(TrackBallAction action, const CGLA::Vec2i& pos){
1275
        active_view_control().grab_ball(action, pos);
1262
        active_view_control().grab_ball(action, pos);
1276
    }
1263
    }
1277
    void MeshEditor::roll_ball(const CGLA::Vec2i& pos){
1264
    void MeshEditor::roll_ball(const CGLA::Vec2i& pos){
1278
        active_view_control().roll_ball(pos);
1265
        active_view_control().roll_ball(pos);
Line 1282... Line 1269...
1282
    }
1269
    }
1283
    bool MeshEditor::try_spinning_ball(){
1270
    bool MeshEditor::try_spinning_ball(){
1284
        return active_view_control().try_spin();
1271
        return active_view_control().try_spin();
1285
    }
1272
    }
1286
    
1273
    
-
 
1274
    void MeshEditor::save_ball() {
-
 
1275
        ofstream ofs("trackball.bin", ios_base::binary);
-
 
1276
        active_view_control().save(ofs);
-
 
1277
        
-
 
1278
    }
-
 
1279
    void MeshEditor::load_ball() {
-
 
1280
        ifstream ifs("trackball.bin", ios_base::binary);
-
 
1281
        active_view_control().load(ifs);
-
 
1282
    
-
 
1283
    }
-
 
1284
 
-
 
1285
    
1287
    bool MeshEditor::grab_mesh(const CGLA::Vec2i& pos)
1286
    bool MeshEditor::grab_mesh(const CGLA::Vec2i& pos)
1288
    {
1287
    {
1289
        if(depth_pick(pos[0], pos[1], depth))
1288
        if(depth_pick(pos[0], pos[1], depth))
1290
        {
1289
        {
1291
            dragging = true;
1290
            dragging = true;
Line 1327... Line 1326...
1327
    {
1326
    {
1328
        dragging = false;
1327
        dragging = false;
1329
    }
1328
    }
1330
 
1329
 
1331
    
1330
    
1332
 
-
 
-
 
1331
    mutex parallel_work;
1333
    void MeshEditor::display(int scale){
1332
    void MeshEditor::display(int scale){
1334
        glClearColor(1, 1, 1, 0);
1333
        glClearColor(1, 1, 1, 0);
1335
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1334
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
 
1335
        
-
 
1336
//        parallel_work.lock();
-
 
1337
//        active_visobj().post_create_display_list();
1336
        active_visobj().display(display_render_mode, theConsole, display_smooth_shading, display_gamma);
1338
        active_visobj().display(display_render_mode, theConsole, display_smooth_shading, display_gamma);
1337
        if(console_visible)
1339
        if(console_visible)
1338
        {
1340
        {
1339
            glUseProgram(0);
1341
            glUseProgram(0);
1340
            theConsole.display(scale);
1342
            theConsole.display(scale);
1341
        }
1343
        }
1342
 
-
 
-
 
1344
//        parallel_work.unlock();
-
 
1345
//        std::this_thread::sleep_for(std::chrono::milliseconds(10));
1343
    }
1346
    }
1344
    
1347
    
1345
    void MeshEditor::reshape(int w, int h) {
1348
    void MeshEditor::reshape(int w, int h) {
1346
        for(VisObj& v : vo)
1349
        for(VisObj& v : vo)
1347
            v.view_control().reshape(w, h);
1350
            v.view_control().reshape(w, h);
Line 1415... Line 1418...
1415
        register_console_function("harmonics.analyze", console_analyze, "");
1418
        register_console_function("harmonics.analyze", console_analyze, "");
1416
        //        register_console_function("harmonics.partial_reconstruct", console_partial_reconstruct,"");
1419
        //        register_console_function("harmonics.partial_reconstruct", console_partial_reconstruct,"");
1417
 
1420
 
1418
        register_console_function("Dijkstra", console_Dijkstra,"");
1421
        register_console_function("Dijkstra", console_Dijkstra,"");
1419
        
1422
        
-
 
1423
        register_console_function("display.save_trackball", console_save_trackball, "Saves trackball to disk");
-
 
1424
        register_console_function("display.load_trackball", console_load_trackball, "Load trackball to disk");
-
 
1425
        
1420
        register_console_function("transform.scale", console_scale, "Scale mesh");
1426
        register_console_function("transform.scale", console_scale, "Scale mesh");
1421
        register_console_function("test", console_test, "Test some shit");
1427
        register_console_function("test", console_test, "Test some shit");
1422
        active.reg(theConsole, "active_mesh", "The active mesh");
1428
        active.reg(theConsole, "active_mesh", "The active mesh");
1423
        display_render_mode.reg(theConsole, "display.render_mode", "Display render mode");
1429
        display_render_mode.reg(theConsole, "display.render_mode", "Display render mode");
1424
        brush_size.reg(theConsole, "brush_size", "Size of brush used for editing");
1430
        brush_size.reg(theConsole, "brush_size", "Size of brush used for editing");