Subversion Repositories gelsvn

Rev

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

Rev 647 Rev 657
Line 53... Line 53...
53
        refit();
53
        refit();
54
        return true;
54
        return true;
55
    }
55
    }
56
    
56
    
57
    
57
    
58
    
-
 
59
    void VisObj::display(const std::string& display_method , Console& cs, bool smooth, float gamma)
58
    bool VisObj::select_vertex(const CGLA::Vec2i& pos)
60
    {
59
    {
61
        if(create_display_list){
60
        float d;
62
            create_display_list = false;
61
        if(depth_pick(pos[0], pos[1], d))
63
            
62
        {
64
            delete renderer;
63
            Vec3d c;
65
            
64
            float r;
-
 
65
            bsphere(mani, c, r);
66
            string short_name = display_method.substr(0,3);
66
            VertexID closest = InvalidVertexID;
67
            if(short_name== "wir")
67
            double min_dist = DBL_MAX;
68
                renderer = new WireframeRenderer(mani, smooth);
68
            for(auto vid : mani.vertices())
69
            
69
            {
70
            	else if(short_name == "har")
70
                Vec3d wp = world2screen(mani.pos(vid));
71
            			renderer = new HarmonicsRenderer(mani, harm, cs);
71
                if(sqr_length(Vec2d(wp[0],wp[1])-Vec2d(pos))<100)
72
            
72
                {
73
            else if(short_name == "iso") {
-
 
74
                renderer = new IsophoteLineRenderer();
73
                    double dist = sqr_length(screen2world(pos[0], pos[1], d)-mani.pos(vid));
75
                renderer->compile_display_list(mani,smooth);
74
                    if(dist < min_dist)
76
            }
75
                    {
77
            else if(short_name == "ref") {
76
                        min_dist = dist;
78
                renderer = new ReflectionLineRenderer();
77
                        closest = vid;
79
                renderer->compile_display_list(mani,smooth);
78
                    }
-
 
79
                }
80
            }
80
            }
81
            else if(short_name == "gla") {
81
            if(closest != InvalidVertexID) {
-
 
82
                vertex_selection.resize(mani.allocated_vertices(),0);
-
 
83
                vertex_selection[closest] = 1;
82
                renderer = new GlazedRenderer();
84
                active_selection = true;
83
                dynamic_cast<GlazedRenderer*>(renderer)->compile_display_list(mani,smooth);
85
                post_create_display_list();
-
 
86
                return true;
84
            }
87
            }
-
 
88
        }
-
 
89
        return false;
-
 
90
        
-
 
91
    }
-
 
92
 
-
 
93
    void VisObj::produce_renderer(const std::string& display_method , Console& cs, bool smooth, float gamma)
-
 
94
    {
-
 
95
        delete renderer;
-
 
96
        
-
 
97
        string short_name = display_method.substr(0,3);
-
 
98
        if(short_name== "wir")
-
 
99
            renderer = new WireframeRenderer(mani, smooth);
-
 
100
        
-
 
101
        else if(short_name == "har")
-
 
102
            renderer = new HarmonicsRenderer(mani, harm, cs);
-
 
103
        
-
 
104
        else if(short_name == "iso") {
-
 
105
            renderer = new IsophoteLineRenderer();
-
 
106
            renderer->compile_display_list(mani,smooth);
-
 
107
        }
-
 
108
        else if(short_name == "ref") {
-
 
109
            renderer = new ReflectionLineRenderer();
-
 
110
            renderer->compile_display_list(mani,smooth);
-
 
111
        }
-
 
112
        else if(short_name == "gla") {
-
 
113
            renderer = new GlazedRenderer();
-
 
114
            dynamic_cast<GlazedRenderer*>(renderer)->compile_display_list(mani,smooth);
-
 
115
        }
-
 
116
        
-
 
117
        
-
 
118
        else if(short_name == "too") {
-
 
119
            renderer = new ToonRenderer();
-
 
120
            renderer->compile_display_list(mani,smooth);
-
 
121
        }
-
 
122
        
-
 
123
        
-
 
124
        else if(short_name == "cur"){
-
 
125
            static Console::variable<string> line_direction("min");
-
 
126
            static Console::variable<string> method("tensors");
-
 
127
            static Console::variable<int> smoothing_iter(1);
-
 
128
            
-
 
129
            line_direction.reg(cs,"display.curvature_lines.direction", "");
-
 
130
            method.reg(cs, "display.curvature_lines.method", "");
-
 
131
            smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
-
 
132
            
-
 
133
            VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
-
 
134
            VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
-
 
135
            VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
-
 
136
            string _line_direction = line_direction;
-
 
137
            VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
-
 
138
            VertexAttributeVector<Vec2d> curvature(mani.allocated_vertices());
85
            
139
            
-
 
140
            if(string(method) == "tensors")
-
 
141
            {
-
 
142
                curvature_tensors_from_edges(mani, curvature_tensors);
-
 
143
                for(int i=0;i<smoothing_iter; ++i)
-
 
144
                    smooth_curvature_tensors(mani,curvature_tensors);
-
 
145
                
-
 
146
                curvature_from_tensors(mani, curvature_tensors,
-
 
147
                                       min_curv_direction,
-
 
148
                                       max_curv_direction,
-
 
149
                                       curvature);
-
 
150
            }
-
 
151
            else
-
 
152
                curvature_paraboloids(mani,
-
 
153
                                      min_curv_direction,
-
 
154
                                      max_curv_direction,
-
 
155
                                      curvature);
86
            
156
            
-
 
157
            renderer = new LineFieldRenderer();
-
 
158
            dynamic_cast<LineFieldRenderer*>(renderer)->compile_display_list(mani, lines);
-
 
159
        }
87
            else if(short_name == "too") {
160
        else if(short_name == "gau"){
88
                renderer = new ToonRenderer();
161
            static Console::variable<float> smoothing(2.0f);
-
 
162
            smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
-
 
163
            VertexAttributeVector<double> scalars(mani.allocated_vertices());
89
                renderer->compile_display_list(mani,smooth);
164
            gaussian_curvature_angle_defects(mani, scalars, smoothing);
90
            }
165
            double max_G = 0;
91
            
166
            
-
 
167
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
-
 
168
                max_G = max(abs(scalars[*v]), max_G);
92
            
169
            
93
            else if(short_name == "cur"){
-
 
94
                static Console::variable<string> line_direction("min");
-
 
95
                static Console::variable<string> method("tensors");
-
 
96
                static Console::variable<int> smoothing_iter(1);
-
 
97
                
-
 
98
                line_direction.reg(cs,"display.curvature_lines.direction", "");
-
 
99
                method.reg(cs, "display.curvature_lines.method", "");
-
 
100
                smoothing_iter.reg(cs, "display.curvature_lines.smoothing_iter", "");
-
 
101
                
-
 
102
                VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
-
 
103
                VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
-
 
104
                VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
-
 
105
                string _line_direction = line_direction;
-
 
106
                VertexAttributeVector<Vec3d>& lines = (_line_direction == "min") ? min_curv_direction : max_curv_direction;
-
 
107
                VertexAttributeVector<Vec2d> curvature(mani.allocated_vertices());
-
 
108
                
-
 
109
                if(string(method) == "tensors")
-
 
110
                {
-
 
111
                    curvature_tensors_from_edges(mani, curvature_tensors);
-
 
112
                    for(int i=0;i<smoothing_iter; ++i)
-
 
113
                        smooth_curvature_tensors(mani,curvature_tensors);
-
 
114
                    
-
 
115
                    curvature_from_tensors(mani, curvature_tensors,
-
 
116
                                           min_curv_direction,
-
 
117
                                           max_curv_direction,
-
 
118
                                           curvature);
-
 
119
                }
-
 
120
                else
-
 
121
                    curvature_paraboloids(mani,
-
 
122
                                          min_curv_direction,
-
 
123
                                          max_curv_direction,
-
 
124
                                          curvature);
-
 
125
                
-
 
126
                renderer = new LineFieldRenderer();
-
 
127
                dynamic_cast<LineFieldRenderer*>(renderer)->compile_display_list(mani, lines);
-
 
128
            }
-
 
129
            else if(short_name == "gau"){
-
 
130
                static Console::variable<float> smoothing(2.0f);
-
 
131
                smoothing.reg(cs, "display.gaussian_curvature_renderer.smoothing", "");
-
 
132
                VertexAttributeVector<double> scalars(mani.allocated_vertices());
-
 
133
                gaussian_curvature_angle_defects(mani, scalars, smoothing);
-
 
134
                double max_G = 0;
-
 
135
                
-
 
136
                for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
-
 
137
                    max_G = max(abs(scalars[*v]), max_G);
-
 
138
                
-
 
139
                renderer = new ScalarFieldRenderer();
170
            renderer = new ScalarFieldRenderer();
140
                dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
171
            dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
141
                
172
            
142
            }
173
        }
143
            else if(short_name == "mea"){
174
        else if(short_name == "mea"){
144
                static Console::variable<int> smoothing(2);
175
            static Console::variable<int> smoothing(2);
145
                smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
176
            smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
146
                
177
            
147
                VertexAttributeVector<double> scalars(mani.allocated_vertices());
178
            VertexAttributeVector<double> scalars(mani.allocated_vertices());
148
                mean_curvatures(mani, scalars, smoothing);
179
            mean_curvatures(mani, scalars, smoothing);
149
                double max_G = 0;
180
            double max_G = 0;
150
                double mean = 0;
181
            double mean = 0;
151
                
182
            
152
                for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
183
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
153
                    max_G = max(abs(scalars[*v]), max_G);
184
                max_G = max(abs(scalars[*v]), max_G);
154
                    mean += scalars[*v];
185
                mean += scalars[*v];
155
                }
-
 
156
                
-
 
157
                renderer = new ScalarFieldRenderer();
-
 
158
                dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
-
 
159
            }
-
 
160
            else if(short_name == "amb"){
-
 
161
                static Console::variable<int> smoothing(2);
-
 
162
                smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
-
 
163
                
-
 
164
                VertexAttributeVector<double> scalars(mani.allocated_vertices());
-
 
165
                mean_curvatures(mani, scalars, smoothing);
-
 
166
                double max_G = 0;
-
 
167
                
-
 
168
                for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
-
 
169
                    max_G = max(abs(scalars[*v]), max_G);
-
 
170
                
-
 
171
                renderer = new AmbientOcclusionRenderer();
-
 
172
                dynamic_cast<AmbientOcclusionRenderer*>(renderer)->compile_display_list(mani, scalars, max_G);
-
 
173
                
-
 
174
            }
-
 
175
            else if(short_name == "deb")
-
 
176
            {
-
 
177
                renderer = new DebugRenderer;
-
 
178
                renderer->compile_display_list(mani, smooth);
-
 
179
            }
-
 
180
            else {
-
 
181
                renderer = new NormalRenderer();
-
 
182
                renderer->compile_display_list(mani, smooth);
-
 
183
            }
186
            }
184
            
187
            
-
 
188
            renderer = new ScalarFieldRenderer();
-
 
189
            dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
-
 
190
        }
-
 
191
        else if(short_name == "amb"){
-
 
192
            static Console::variable<int> smoothing(2);
-
 
193
            smoothing.reg(cs, "display.ambient_occlusion_renderer.smoothing", "");
-
 
194
            
-
 
195
            VertexAttributeVector<double> scalars(mani.allocated_vertices());
-
 
196
            mean_curvatures(mani, scalars, smoothing);
-
 
197
            double max_G = 0;
-
 
198
            
-
 
199
            for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
-
 
200
                max_G = max(abs(scalars[*v]), max_G);
185
            
201
            
-
 
202
            renderer = new AmbientOcclusionRenderer();
-
 
203
            dynamic_cast<AmbientOcclusionRenderer*>(renderer)->compile_display_list(mani, scalars, max_G);
-
 
204
            
-
 
205
        }
-
 
206
        else if(short_name == "deb")
-
 
207
        {
-
 
208
            renderer = new DebugRenderer;
-
 
209
            renderer->compile_display_list(mani, smooth);
-
 
210
        }
-
 
211
        else {
-
 
212
            renderer = new NormalRenderer();
-
 
213
            renderer->compile_display_list(mani, smooth);
-
 
214
        }
-
 
215
 
-
 
216
    
-
 
217
    }
-
 
218
    
-
 
219
    void VisObj::draw_selection()
-
 
220
    {
-
 
221
        Vec3d c;
-
 
222
        float r;
-
 
223
        bsphere(mani, c, r);
-
 
224
        r *= 0.003;
-
 
225
        glDisable(GL_LIGHTING);
-
 
226
        for(auto vid : mani.vertices())
-
 
227
        {
-
 
228
            Vec3d p = mani.pos(vid);
-
 
229
            if(vertex_selection[vid])
-
 
230
                glColor3f(1,1,0);
-
 
231
            else
-
 
232
                glColor3f(0, 0, 0.3);
-
 
233
            glPushMatrix();
-
 
234
            glTranslated(p[0], p[1], p[2]);
-
 
235
            glScalef(r, r, r);
-
 
236
            draw_ball();
-
 
237
            glPopMatrix();
-
 
238
        }
-
 
239
        glEnable(GL_LIGHTING);
-
 
240
    }
-
 
241
 
-
 
242
    
-
 
243
    void VisObj::display(const std::string& display_method , Console& cs, bool smooth, float gamma)
-
 
244
    {
-
 
245
        if(create_display_list){
-
 
246
            create_display_list = false;
-
 
247
            produce_renderer(display_method, cs, smooth, gamma);
186
        }
248
        }
187
        view_ctrl.set_gl_modelview();
249
        view_ctrl.set_gl_modelview();
188
        renderer->draw();
250
        renderer->draw();
-
 
251
        if(active_selection)
-
 
252
            draw_selection();
189
    }
253
    }
190
}
254
}
191
 
255