Subversion Repositories gelsvn

Rev

Rev 657 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
647 janba 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
 
662 janba 12
#include <mutex>
647 janba 13
#include <string>
649 janba 14
#include "../GLGraphics/Console.h"
15
#include "../GLGraphics/VisObj.h"
16
#include "../GLGraphics/GLViewController.h"
647 janba 17
 
662 janba 18
 
647 janba 19
namespace GLGraphics {
662 janba 20
    extern std::mutex parallel_work;
647 janba 21
 
22
    class MeshEditor
23
    {
24
        bool console_visible = false;
656 janba 25
 
26
        bool dragging = false;
27
        int mouse_x, mouse_y;
28
        float depth;
29
        HMesh::VertexAttributeVector<float> weight_vector;
30
        HMesh::VertexAttributeVector<CGLA::Vec3d> orig_pos;
31
 
647 janba 32
        static const int NO_MESHES = 9;
33
        std::array<VisObj,NO_MESHES> vo;
662 janba 34
 
35
    public:
650 janba 36
        VisObj& active_visobj() { return vo[active]; }
37
        const VisObj& active_visobj() const { return vo[active]; }
662 janba 38
    private:
650 janba 39
        GLViewController& active_view_control() {
40
            return active_visobj().view_control();
41
        }
647 janba 42
 
656 janba 43
        Console theConsole;
44
        Console::variable<int> active;
45
        Console::variable<std::string> display_render_mode;
657 janba 46
        Console::variable<float> brush_size;
656 janba 47
        Console::variable<int> display_smooth_shading;
48
        Console::variable<float> display_gamma;
647 janba 49
 
50
    public:
657 janba 51
        MeshEditor():active(0), display_render_mode("normal"), brush_size(0.01), display_smooth_shading(true),
647 janba 52
        display_gamma(2.2) {}
53
 
54
        /// Initialize the mesh editor. Do this only when OpenGL state is available.
55
        void init();
656 janba 56
 
657 janba 57
        bool select_vertex(const CGLA::Vec2i& pos) {
58
            return active_visobj().select_vertex(pos);
59
        }
656 janba 60
 
657 janba 61
         HMesh::VertexAttributeVector<int>& get_vertex_selection()  {
62
            return active_visobj().get_vertex_selection();
63
        }
64
 
65
 
66
 
656 janba 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();
647 janba 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();
662 janba 86
        void save_ball();
87
        void load_ball();
647 janba 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
        }
650 janba 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();}
647 janba 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();
650 janba 131
 
132
        /// Returns a reference to active mesh.
133
        HMesh::Manifold& active_mesh() { return active_visobj().mesh(); }
662 janba 134
 
135
        /// Returns a reference to mesh i
136
        HMesh::Manifold& get_mesh(int i) { return vo[i].mesh(); }
137
 
650 janba 138
       /// Add a file to the next empty slot.
647 janba 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();}
148
 
149
    };
150
}
151
 
152
#endif /* defined(__GEL__MeshEditor__) */