ofCloudServerApp.hpp 5.73 KB
Newer Older
expoclient's avatar
expoclient committed
1
2
#ifndef CLOUDLIB_OFCLOUDSERVERAPP_HPP
#define CLOUDLIB_OFCLOUDSERVERAPP_HPP
expoclient's avatar
expoclient committed
3
4
5
6
7

#include "ofMain.h"
#undef Success // X hack de #include de X

#include "ofxCameraSaveLoad.h"
8
9
#include "ofxGui.h"
#include "ofxPanel.h"
10
#include "ofxPublishableParameterGroup.h"
11

12
13
14
15
16
17
#include "ofxCloudLib/Common.hpp"
#include "ofxCloudLib/EuclidianExtractor.hpp"
#include "ofxCloudLib/Merger.hpp"
#include "ofxCloudLib/VoxelFilter.hpp"


18
19
20
21
22
namespace ofxCloudLib
{
class ofCloudServerApp : public ofBaseApp
{
  public:
23
24
    //  ofCloudServerApp() : ofBaseApp(){};
    //  ~ofCloudServerApp(){};
expoclient's avatar
expoclient committed
25

26
    void setup()
expoclient's avatar
expoclient committed
27
    {
28
29
        cloudserver_will_setup();

30
31
32
33
34
35
        ofSetFrameRate(60);
        ofSetWindowTitle("Cloud Server");

        merger_.setup();

        gui_.setup();
36
37
38
39
40
41
42
43
        gui_.setName("CloudServer");

        cloudserver_parameters_.setName("Cloudserver");
        cloudserver_parameters_.add(draw_gui_.set("<g> draw gui", true));
        cloudserver_parameters_.add(merger_.parameters_);
        cloudserver_parameters_.add(voxel_resolution_.set("voxel resolution", .05, 0, .5));
        cloudserver_parameters_.add(draw_clusters_.set("<s> draw segmentation", false));
        cloudserver_parameters_.add(euclidian_extractor_.parameters);
44
45
46

        setup_after_merger();

47
48
        gui_.add(cloudserver_parameters_);

49
50
51
52
53
        load_gui_params_from_file(0);
    }

    void update()
    {
54
        // merge elements are channel threaded
55
        if (merger_.update()) {
56
            //   std::cout << "new stuff in merger" << std::endl;
57
58
            voxel_filter_.perform(mesh_converter_.perform(merger_.get_mesh()), voxel_resolution_);
            euclidian_extractor_.send(voxel_filter_.get());
59
        }
60
        // euclidian_extractor is channel threaded
61
62
        if (euclidian_extractor_.receive()) {
            cluster_tracker_.track(euclidian_extractor_.get_clouds());
63
        }
64
65
66
67
68
69
        update_after_merger();
    }

    void draw()
    {
        ofClear(0, 0, 0, 0);
70
71
        cloudserver_will_draw();

72
        ofPushStyle();
expoclient's avatar
expoclient committed
73
74
75
76
77
78
79
80
        {
            final_fbo_.begin();
            {
                ofClear(0, 0, 0, 0);
                cam_.begin();
                {
                    ofEnableDepthTest();
                    glPointSize(1);
81

82
83
                    ofPushMatrix();

expoclient's avatar
expoclient committed
84
                    merger_.draw_models();
85
                    ofPopMatrix();
86

expoclient's avatar
expoclient committed
87
                    draw_in_camera_before_cloud();
88

89
                    ofPushMatrix();
90
                    ofScale(100, 100, 100); // somehow seems reasonable
expoclient's avatar
expoclient committed
91
                    merger_.draw();
92
93
94
95
96

                    if (draw_clusters_) {
                        euclidian_extractor_.draw();
                    }

97
                    ofPopMatrix();
98

expoclient's avatar
expoclient committed
99
                    draw_in_camera_after_cloud();
100

expoclient's avatar
expoclient committed
101
102
103
104
105
106
                    ofDisableDepthTest();
                }
                cam_.end();
            }
            final_fbo_.end();
        }
107
108
        ofPopStyle();
        final_fbo_.draw(0, 0, 1920, 1080);
109
        
110
111
112
113
114
115
116
        draw_after_fbo();

        ofSetColor(255, 255, 255, 255);
        if (draw_gui_) {
            ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate()), 20, ofGetHeight() - 20);
            gui_.draw();
            merger_.draw_gui();
expoclient's avatar
expoclient committed
117
        }
118
119
120
121
122
123
124
    }

    void keyPressed(int key)
    {
        if (key == 'r') cam_.reset();
        if (key == 'g') draw_gui_ = !draw_gui_;
        if (key == 'r') merger_.reload_model();
125
126
        if (key == 'q') merger_.draw_marqueurs_ = !merger_.draw_marqueurs_;
        if (key == 'u') merger_.draw_lights_ = !merger_.draw_lights_;
127
        if (key == 'w') merger_.wireframe_models_ = !merger_.wireframe_models_;
128
129
130
131
        if (key == 'n') merger_.draw_scene_ = !merger_.draw_scene_;
        if (key == 't') merger_.draw_raw_mesh_ = !merger_.draw_raw_mesh_;
        if (key == 'c') merger_.draw_cam_colors_ = !merger_.draw_cam_colors_;
        if (key == 's') draw_clusters_ = !draw_clusters_;
132

133
        key_pressed(key); // passe aux subclasses? pas clair si bonne approche
134
135
136
137
138
139
140
141
142
143
144
145
146
    }

    void keyReleased(int key) { key_released(key); }
    void mouseMoved(int x, int y) {}
    void mouseDragged(int x, int y, int button) {}
    void mousePressed(int x, int y, int button) {}
    void mouseReleased(int x, int y, int button) {}
    void mouseEntered(int x, int y) {}
    void mouseExited(int x, int y) {}
    void windowResized(int w, int h) {}
    void gotMessage(ofMessage msg) {}
    void dragEvent(ofDragInfo dragInfo) {}

147
148
149
150
    void exit()
    {
        exit_before_app();
        save_gui_params_to_file(0);
151
    }
152
153
154

    void save_gui_params_to_file(int i)
    {
155
        gui_.saveToFile("presets/cloudserver_" + ofToString(i) + ".json");
156
        // ofxSaveCamera(cam_, "cameras/current.txt");
157
158
159
160
    }

    void load_gui_params_from_file(int i)
    {
161
        gui_.loadFromFile("presets/cloudserver_" + ofToString(i) + ".json");
162
        //  ofxLoadCamera(cam_, "cameras/current.txt");
163
164
165
166
167
168
        save_gui_params_to_file(0);
    }

    ofxCloudLib::Merger merger_;
    ofEasyCam cam_;
    ofxPanel gui_;
169
    PublishableParameterGroup cloudserver_parameters_;
170
    ofFbo final_fbo_;
171

172
    ofParameter<bool> draw_gui_;
173
174
175
176
177
178
179
    ofParameter<float> voxel_resolution_;
    ofParameter<bool> draw_clusters_;

    ofxCloudLib::VoxelFilter voxel_filter_;
    ofxCloudLib::EuclidianExtractor euclidian_extractor_;
    ofxCloudLib::ClusterTracker cluster_tracker_;
    ofxCloudLib::MeshToCloudConverter mesh_converter_;
180

181
182
    virtual void cloudserver_will_draw(){};
    virtual void cloudserver_will_setup(){};
183
184
185
186
187
    virtual void setup_after_merger(){};
    virtual void update_after_merger(){};
    virtual void draw_in_camera_before_cloud(){};
    virtual void draw_in_camera_after_cloud(){};
    virtual void draw_after_fbo(){};
188
    virtual void exit_before_app(){};
189
190
191
    virtual void key_pressed(int key){};
    virtual void key_released(int key){};
};
expoclient's avatar
expoclient committed
192
193
}

expoclient's avatar
expoclient committed
194
#endif // CLOUDLIB_OFCLOUDSERVERAPP_HPP