Subversion Repositories gelsvn

Rev

Rev 409 | Rev 456 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 *  VisObj.cpp
 *  GEL
 *
 *  Created by J. Andreas Bærentzen on 20/09/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include "VisObj.h"

#include <GLConsole/GLConsole.h>
#include <HMesh/load.h>
#include "curvature.h"

using namespace std;
using namespace CGLA;
using namespace HMesh;
using namespace CVarUtils;

int WINX=800, WINY=800;


bool VisObj::reload(string _file)
{
        if(_file != "") file = _file;
        mani.clear();
        if(!load(file, mani))
                return false;
        mani.get_bsphere(bsphere_center,bsphere_radius);
        view_ctrl.set_centre(bsphere_center);
        view_ctrl.set_eye_dist(2*bsphere_radius);
        return true;
}


void VisObj::display(const std::string& display_method , bool smooth)
{
        if(create_display_list)
        {
                create_display_list = false;
                delete renderer;
                
                string short_name = display_method.substr(0,3);
                if(short_name== "wir")
                        renderer = new WireframeRenderer(mani, smooth);
                else if(short_name == "har")
                        renderer = new HarmonicsRenderer(harmonics);
                else if(short_name == "iso")
                        renderer = new IsophoteLineRenderer(mani, smooth);
                else if(short_name == "ref")
                        renderer = new ReflectionLineRenderer(mani, smooth);
                else if(short_name == "gla")
                        renderer = new GlazedRenderer(mani, smooth, bsphere_radius);
                else if(short_name == "too")
                        renderer = new ToonRenderer(mani, smooth);
                else if(short_name == "cur")
                {
                        static string& line_direction = CreateCVar<string>("display.curvature_lines.direction", "min");
                        
                        std::vector<CGLA::Mat3x3d> curvature_tensors;
                        curvature_tensors_from_edges(mani, curvature_tensors);
                        smooth_curvature_tensors(mani,curvature_tensors);
                        smooth_curvature_tensors(mani,curvature_tensors);
                        std::vector<CGLA::Vec3d> min_curv_direction;
                        std::vector<CGLA::Vec3d> max_curv_direction;
                        string _line_direction = line_direction;
                        vector<Vec3d>& lines = (_line_direction == "min")?min_curv_direction:max_curv_direction;
                        
                        std::vector<double> curvature;
                        curvature_from_tensors(mani, curvature_tensors,
                                                                   min_curv_direction,
                                                                   max_curv_direction,
                                                                   curvature);
                        
                        renderer = new LineFieldRenderer(mani, smooth, lines, bsphere_radius);
                }
                else if(short_name == "gau")
                {
                        static float& smoothing = CreateCVar("display.gaussian_curvature_renderer.smoothing",2.0f);
                        vector<double> scalars;
                        gaussian_curvature_angle_defects(mani, scalars, smoothing);
                        double max_G = 0;
                        for(int i=0;i<scalars.size(); ++i)
                                max_G = max(abs(scalars[i]), max_G);
                        renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
                        
                }
                else if(short_name == "mea")
                {
                        static int& smoothing = CreateCVar("display.mean_curvature_renderer.smoothing",2);
                        vector<double> scalars;
                        mean_curvatures(mani, scalars, smoothing);
                        double max_G = 0;
                        double mean = 0;
                        for(int i=0;i<scalars.size(); ++i)
                        {
                                max_G = max(abs(scalars[i]), max_G);
                                mean += scalars[i];
                        }
                        renderer = new ScalarFieldRenderer(mani, smooth, scalars, max_G);
                }
                else if(short_name == "amb")
                {
                        static int& smoothing = CreateCVar("display.ambient_occlusion_renderer.smoothing",1);
                        vector<double> scalars;
                        mean_curvatures(mani, scalars, smoothing);
                        double max_G = 0;
                        for(int i=0;i<scalars.size(); ++i)
                                max_G = max(abs(scalars[i]), max_G);
                        renderer = new AmbientOcclusionRenderer(mani, smooth, scalars, max_G);
                        
                }
                else if(short_name == "cop")
                {
                        static int& smoothing = CreateCVar("display.patina_renderer.smoothing",1);
                        vector<double> scalars;
                        mean_curvatures(mani, scalars, smoothing);
                        double max_G = 0;
                        for(int i=0;i<scalars.size(); ++i)
                                max_G = max(abs(scalars[i]), max_G);
                        renderer = new CopperRenderer(mani, smooth, scalars, max_G,bsphere_radius);
                        
                }
                else
                        renderer = new NormalRenderer(mani,smooth);
                
        }
        view_ctrl.set_gl_modelview();
        renderer->draw();
}