Subversion Repositories gelsvn

Rev

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

Rev Author Line No. Line
647 janba 1
/*
2
 *  VisObj.cpp
3
 *  GEL
4
 *
5
 *  Created by J. Andreas Bærentzen on 20/09/08.
6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
7
 *
8
 */
9
 
10
#include "VisObj.h"
11
 
12
#include <GLGraphics/Console.h>
13
#include <HMesh/Manifold.h>
14
#include <HMesh/AttributeVector.h>
15
#include <HMesh/load.h>
16
#include <HMesh/curvature.h>
17
 
18
#include <CGLA/Mat3x3d.h>
19
#include <CGLA/Vec3d.h>
20
#include <CGLA/Vec4d.h>
21
 
22
using namespace std;
23
using namespace CGLA;
24
using namespace HMesh;
25
using namespace GLGraphics;
26
 
27
int WINX=800, WINY=800;
28
 
29
namespace GLGraphics {
30
 
31
    void VisObj::refit()
32
    {
33
        bsphere(mani, bsphere_center, bsphere_radius);
34
 
35
        view_ctrl.set_centre(Vec3f(bsphere_center));
36
        view_ctrl.set_eye_dist(2*bsphere_radius);
37
    }
38
 
39
    bool VisObj::reload(string _file)
40
    {
41
        if(_file != "") file = _file;
42
        mani.clear();
43
        if(!load(file, mani))
44
            return false;
45
        refit();
46
        return true;
47
    }
48
 
49
    bool VisObj::add_mesh(string file)
50
    {
51
        if(!load(file, mani))
52
            return false;
53
        refit();
54
        return true;
55
    }
56
 
57
 
58
 
59
    void VisObj::display(const std::string& display_method , Console& cs, bool smooth, float gamma)
60
    {
61
        if(create_display_list){
62
            create_display_list = false;
63
 
64
            delete renderer;
65
 
66
            string short_name = display_method.substr(0,3);
67
            if(short_name== "wir")
68
                renderer = new WireframeRenderer(mani, smooth);
69
 
70
            	else if(short_name == "har")
71
            			renderer = new HarmonicsRenderer(mani, harm, cs);
72
 
73
            else if(short_name == "iso") {
74
                renderer = new IsophoteLineRenderer();
75
                renderer->compile_display_list(mani,smooth);
76
            }
77
            else if(short_name == "ref") {
78
                renderer = new ReflectionLineRenderer();
79
                renderer->compile_display_list(mani,smooth);
80
            }
81
            else if(short_name == "gla") {
82
                renderer = new GlazedRenderer();
83
                dynamic_cast<GlazedRenderer*>(renderer)->compile_display_list(mani,smooth);
84
            }
85
 
86
 
87
            else if(short_name == "too") {
88
                renderer = new ToonRenderer();
89
                renderer->compile_display_list(mani,smooth);
90
            }
91
 
92
 
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();
140
                dynamic_cast<ScalarFieldRenderer*>(renderer)->compile_display_list(mani, smooth, scalars, max_G, gamma);
141
 
142
            }
143
            else if(short_name == "mea"){
144
                static Console::variable<int> smoothing(2);
145
                smoothing.reg(cs, "display.mean_curvature_renderer.smoothing", "");
146
 
147
                VertexAttributeVector<double> scalars(mani.allocated_vertices());
148
                mean_curvatures(mani, scalars, smoothing);
149
                double max_G = 0;
150
                double mean = 0;
151
 
152
                for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
153
                    max_G = max(abs(scalars[*v]), max_G);
154
                    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
            }
184
 
185
 
186
        }
187
        view_ctrl.set_gl_modelview();
188
        renderer->draw();
189
    }
190
}