From 50b109625e66025d3636bc7240e49ba0df7ecfa7 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 9 Sep 2004 22:38:57 +0000 Subject: [PATCH] Initial Update --- apps/shadevis/gen_normal.h | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 apps/shadevis/gen_normal.h diff --git a/apps/shadevis/gen_normal.h b/apps/shadevis/gen_normal.h new file mode 100644 index 00000000..078c296c --- /dev/null +++ b/apps/shadevis/gen_normal.h @@ -0,0 +1,139 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ +****************************************************************************/ + +#ifndef __VCG_GEN_NORMAL +#define __VCG_GEN_NORMAL +#include +namespace vcg { + + +template +class GenNormal +{ +public: +typedef Point3 Point3x; + +static void Random(int vn, std::vector > &NN) +{ + NN.clear(); + while(NN.size() > &NN) +{ + OctaLevel pp; + + int ll=10; + while(pow(4,ll)+2>vn) ll--; + + pp.Init(ll); + sort(pp.v.begin(),pp.v.end()); + int newsize = unique(pp.v.begin(),pp.v.end())-pp.v.begin(); + pp.v.resize(newsize); + + NN=pp.v; + Perturb(NN); + } + +static void Perturb(std::vector > &NN) +{ + float width=0.2f/sqrt(float(NN.size())); + + for(vector::iterator vi=NN.begin(); vi!=NN.end();++vi) + { + Point3x pp(float(rand())/RAND_MAX,float(rand())/RAND_MAX,float(rand())/RAND_MAX); + pp=pp*2.0-Point3x(1,1,1); + pp*=width; + (*vi)+=pp; + (*vi).Normalize(); + } + +} + +private : +class OctaLevel + { + public: + std::vector v; + int level; + int sz; + + Point3f &Val(int i, int j) { + assert(i>=0 && i=0 && j::iterator vi=v.begin(); vi!=v.end();++vi) + (*vi).Normalize(); + + } + } + }; +}; +} +#endif