Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
667 khor 1
//
2
//  MeshEditor.h
3
//  GEL
4
//
5
//  Created by J. Andreas Bærentzen on 09/10/13.
6
//
7
//
8
 
9
#ifndef __GEL__MeshEditor__
10
#define __GEL__MeshEditor__
11
 
676 janba 12
#include <mutex>
667 khor 13
#include <string>
14
#include "../GLGraphics/Console.h"
15
#include "../GLGraphics/VisObj.h"
16
#include "../GLGraphics/GLViewController.h"
17
 
676 janba 18
 
667 khor 19
namespace GLGraphics {
676 janba 20
    extern std::mutex parallel_work;
667 khor 21
 
22
    class MeshEditor
23
    {
676 janba 24
        bool console_visible = false;
667 khor 25
 
676 janba 26
        bool dragging = false;
667 khor 27
        int mouse_x, mouse_y;
28
        float depth;
29
        HMesh::VertexAttributeVector<float> weight_vector;
30
        HMesh::VertexAttributeVector<CGLA::Vec3d> orig_pos;
31
 
32
        static const int NO_MESHES = 9;
33
        std::array<VisObj,NO_MESHES> vo;
676 janba 34
 
35
    public:
667 khor 36
        VisObj& active_visobj() { return vo[active]; }
37
        const VisObj& active_visobj() const { return vo[active]; }
676 janba 38
    private:
667 khor 39
        GLViewController& active_view_control() {
40
            return active_visobj().view_control();
41
        }
42
 
43
        Console theConsole;
44
        Console::variable<int> active;
45
        Console::variable<std::string> display_render_mode;
46
        Console::variable<float> brush_size;
47
        Console::variable<int> display_smooth_shading;
48
        Console::variable<float> display_gamma;
49
 
50
    public:
676 janba 51
        MeshEditor():active(0), display_render_mode("normal"), brush_size(0.01), display_smooth_shading(true),
667 khor 52
        display_gamma(2.2) {}
53
 
54
        /// Initialize the mesh editor. Do this only when OpenGL state is available.
55
        void init();
56
 
57
        bool select_vertex(const CGLA::Vec2i& pos) {
58
            return active_visobj().select_vertex(pos);
59
        }
60
 
61
         HMesh::VertexAttributeVector<int>& get_vertex_selection()  {
62
            return active_visobj().get_vertex_selection();
63
        }
64
 
65
 
66
 
67
        /** Tests whether the position passed as argument is on the mesh (return true) 
68
         or background (false). This function also retains the 3D unprojection of the 
69
         grabbed position. */
70
        bool grab_mesh(const CGLA::Vec2i& pos);
71
 
72
        /** Provided grab_mesh has been called and returned true, drag_mesh computes a 
73
         vector to the new position given as argument and moves a small subset of the mesh
74
         according to the vector from grabbed to dragged position. */
75
        bool drag_mesh(const CGLA::Vec2i& pos);
76
 
77
        /** Releases the mesh. We are no longer dragging. */
78
        void release_mesh();
79
 
80
        // GLViewController stuff
81
        void reshape(int w, int h);
82
        void grab_ball(TrackBallAction action, const CGLA::Vec2i& pos);
83
        void roll_ball(const CGLA::Vec2i& pos);
84
        void release_ball();
85
        bool try_spinning_ball();
676 janba 86
        void save_ball();
87
        void load_ball();
667 khor 88
 
89
        /// Align means that we sync view controllers.
90
        void align(int src, int dst)
91
        {
92
            vo[dst].view_control() =
93
            vo[src].view_control();
94
        }
95
 
96
        /// Make sure the object fits in the window.
97
        void refit() {
98
            active_visobj().refit();
99
        }
100
 
101
        /// Returns the name of the file whence the active mesh was loaded.
102
        const std::string& file_name() const {return active_visobj().file_name();}
103
 
104
        // Get mesh and mesh state.
105
        void save_active_mesh() {active_visobj().save_old();}
106
        void restore_active_mesh() {active_visobj().restore_old();}
107
 
108
        // Display functions ------------
109
 
110
        /// Notify the visualization object that we need to regenerate the display list.
111
        void post_create_display_list() {active_visobj().post_create_display_list();}
112
 
113
        /// Render the active mesh.
114
        void display(int scale = 1);
115
 
116
 
117
        // Console functions --------------
118
 
119
        void register_console_function(const std::string& name,
120
                                       const std::function<void(MeshEditor*, const std::vector<std::string>&)>& con_fun,
121
                                       const std::string& help_txt);
122
 
123
        void printf(const char* format, ...);
124
        void keyparse(unsigned short c);
125
        void key_up();
126
        void key_down();
127
        void key_left();
128
        void key_right();
129
        void key_home();
130
        void key_end();
131
 
132
        /// Returns a reference to active mesh.
133
        HMesh::Manifold& active_mesh() { return active_visobj().mesh(); }
676 janba 134
 
135
        /// Returns a reference to mesh i
136
        HMesh::Manifold& get_mesh(int i) { return vo[i].mesh(); }
137
 
667 khor 138
       /// Add a file to the next empty slot.
139
        bool add_file(const std::string& str);
140
 
141
        /// Load the mesh given as argument to the current slot.
142
        bool reload_active_from_file(const std::string& str);
143
 
144
        /// Load the mesh but without clearing, effectively combining it with existing mesh.
145
        bool add_to_active_from_file(const std::string& str);
146
 
147
        void harmonics_analyze_mesh() {active_visobj().harmonics_analyze();}
676 janba 148
        void harmonics_reset_shape() {active_visobj().harmonics_reset_shape();}
149
        void harmonics_partial_reconstruct(int E0, int E1, float scale) {active_visobj().harmonics_partial_reconstruct(E0, E1, scale);}
667 khor 150
 
151
    };
152
}
153
 
154
#endif /* defined(__GEL__MeshEditor__) */