// Voronoi.h #ifndef Voronoih #define Voronoih #pragma once #include "stdafx.h" #include "Voronoi.h" #include "..\Primitives/g3.h" double Voronoi::Get(double x, double y, double z, VoronoiType V, DistanceMethod Distance) { double d, da[4], pa[12]; switch(V) { default: Calculate(x,y,z, da, pa, Distance); d=da[V]; break; case Difference21: Calculate(x,y,z, da, pa, Distance); d=da[1]-da[0]; break; case Difference32: Calculate(x,y,z, da, pa, Distance); d=da[2]-da[1]; break; case Crackle: d=Max(1.,10*Get(x,y,z,Difference21, Distance)); break; } return d*M_SQRT2/M_SQRT3; } void Voronoi::Calculate(double x, double y, double z, double da[4], double pa[12], DistanceMethod Distance) { int xi=Floor(x); // Standard floor flushes the processor pipeline. This is from Global.h included in g3.h int yi=Floor(y); int zi=Floor(z); da[0]=da[1]=da[2]=da[3]=DBL_MAX; g3Vector V; for(int xx=xi-1; xx<=xi+1; ++xx) { for(int yy=yi-1; yy<=yi+1; ++yy) { for(int zz=zi-1; zz<=zi+1; ++zz) { // Things in this inner loop will happen 27 times: const float* p=GetPoint(xx, yy, zz); V.Set(x-(p[0]+xx), y-(p[1]+yy), z-(p[2]+zz)); double d; switch(Distance) { default: case Length : d=V.GetLength (); break; // Euclidean (shortest line). case Length2 : d=V.GetL2 (); break; // The length squared. Saves the slow Square Root for some calculations. case Manhattan : d=V.GetManhattan (); break; // The length of the distance in axial directions (as if travelling around a city). Saves the slow Square Root for some calculations. case Chebychev : d=V.GetChebychev (); break; // The length of the longest Axial journey. Saves the slow Square Root for some calculations. case Quadratic : d=V.GetQuadratic (); break; // The sum of everything multiplied by everything else! case Minkowski4: d=V.GetMinkowski4(); break; // Minkowski(4); pow(x*x*x*x+y*y*y*y+z*z*z*z,0.25); p=4 in: pow(pow(x.abs(), p) + pow(y.abs(), p) + pow(z.abs(), M_E), 1.0/p); case Minkowski5: d=V.GetMinkowski5(); break; // Same as Minkowski(0.5); } if(d