class OctaMapSamp{ public: int TotTexSizeX(){ return size; } int TotTexSizeY(){ return size; } static vector map; // mappa 2d di indici a dir static vector dir; // direzioni (uniche!) static vector dirrot; // direzioni ruotate (uniche!) vector sum; // somme (uniche!) vector div; // divisioni (uniche!) static int size; void Shade(){ //col.resize(dir.size()); /*for (int i=0; i1) col[i]=1; }*/ } static inline int nsamp(){ return dir.size(); } // duplicates those texels that are already douplicated void DuplicateTexels(vector &t, int s, int tx, int ty){ int e=size-1; // the end // four corners int k0=(tx+ (ty )*s)*3; int k1=(tx+e+(ty )*s)*3; int k2=(tx+e+(ty+e)*s)*3; int k3=(tx+ (ty+e)*s)*3; t[k0 ]=t[k1 ]=t[k2 ]=t[k3 ]; t[k0+1]=t[k1+1]=t[k2+1]=t[k3+1]; t[k0+2]=t[k1+2]=t[k2+2]=t[k3+2]; // sides for (int i=1; i &t, int s, int tx, int ty, float cr,float cg,float cb){ for (int y=0; y255) shade=255; t[k++]= shade; t[k++]= shade; t[k++]= shade;*/ /* float i=255.0*float(map[Index( x , y )])/(size*size*size); t[k++]= (int)i; t[k++]= (int)i; t[k++]= (int)i; int r=0, g=0, b=0; if (y=size*2) g=255; k=(x+(y)*s)*3; t[k++]= t[k++]/2+r/2; t[k++]= t[k++]/2+g/2; t[k++]= t[k++]/2+b/2; */ /* int r=0, g=0, b=0; if (y=size*2) g=255; t[k++]= r; t[k++]= g; t[k++]= b;*/ // printf("%4d ",map[Index( x , y )]); //printf("%3d ",shade); } //printf("\n"); } } inline static int Index(int x, int y){ return x+y*size; } inline static float sign(float x){ return (x<0)?-1:+1; } inline static float Abs(float x){ return (x<0)?-x:+x; } void Zero(){ int n=dir.size(); sum.resize(n,0); div.resize(n,0); } // smoothing of an octamap! void Smooth(vector &t, int s, int tx, int ty){ vector oldvalue(size*size*6); // copy old values for (int y=0; yTH) {sum+=w; ddiv++; } if (x!=0) w=oldvalue[i-dx]; else w=oldvalue[ Index( 1 , e-y ) ]; if(w>TH) {sum+=w; ddiv++; } if (y!=e) w=oldvalue[i+dy]; else w=oldvalue[ Index( e-x ,e-1 ) ]; if(w>TH) {sum+=w; ddiv++; } if (x!=e) w=oldvalue[i+dx]; else w=oldvalue[ Index( e-1 , e-y ) ]; if(w>TH) {sum+=w; ddiv++; } sum=(sum+ddiv/2)/ddiv; int k=(x+tx+(y+ty)*s)*3; t[k]=t[k+1]=t[k+2]=sum; } } // smoothing of an octamap! void Smooth(vector &t, int s, int tx, int ty){ vector oldvalue(size*size*6); // copy old values for (int y=0; yTH) {sum+=w; ddiv++; } if (x!=0) w=oldvalue[i-dx]; else w=oldvalue[ Index( 1 , e-y ) ]; if(w>TH) {sum+=w; ddiv++; } if (y!=e) w=oldvalue[i+dy]; else w=oldvalue[ Index( e-x ,e-1 ) ]; if(w>TH) {sum+=w; ddiv++; } if (x!=e) w=oldvalue[i+dx]; else w=oldvalue[ Index( e-1 , e-y ) ]; if(w>TH) {sum+=w; ddiv++; } sum=(sum+ddiv/2)/ddiv; int k=(x+tx+(y+ty)*s); t[k]=sum; } } static void SetSize(int _size){ size=_size; initMap(); ComputeWeight(); } static Point3f getDir(float x, float y){ float fs=float(size)-1; Point3f p(x*2/fs-1,y*2/fs-1,0); float ax=Abs(p[0]), ay=Abs(p[1]), az=+1; if (ax+ay>1.0) { p=Point3f( sign(p[0])*(1-ay), sign(p[1])*(1-ax), 0); az=-1; } p[2]=(1-ax-ay)*az; p.Normalize(); return p; } static void initMap(){ dir.resize(size*size); for (int y=0; y weight; static float Area(Point3f a, Point3f b, Point3f c){ return Abs( ((b-a)^(c-a)).Norm()*0.5 ); } static void ComputeWeight(){ weight.resize(size*size); for (int y=0,k=0; y &texture, const vector &sumtable, int texsize, float div, int tx, int ty ); OctaMapSamp(){ } };