From 168ea81ca8e4df1d32473a2f1ea28a2ab80c3f06 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Tue, 16 Jun 2009 08:57:24 +0000 Subject: [PATCH] Added PerlinColor function and ColorNoise function --- vcg/complex/trimesh/update/color.h | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/vcg/complex/trimesh/update/color.h b/vcg/complex/trimesh/update/color.h index 33b5c6bf..f7674bfc 100644 --- a/vcg/complex/trimesh/update/color.h +++ b/vcg/complex/trimesh/update/color.h @@ -67,7 +67,8 @@ Changed name from plural to singular (normals->normal) #include #include #include - +#include +#include namespace vcg { namespace tri { @@ -856,6 +857,39 @@ static Color4b ColorWhiteBalance(Color4b c, Color4b unbalancedWhite) 255); } +static void PerlinColor(MeshType& m, Box3f bbox, float freq, Point3i channelOffsets) +{ + typedef typename MeshType::ScalarType ScalarType; + + Point3 p; + for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi) + { + if(!(*vi).IsD()){ + p = bbox.GlobalToLocal(m.Tr * (*vi).P()); //actual vertex position scaled to bbox + (*vi).C() = Color4b( int(255*math::Perlin::Noise(channelOffsets[0]+p[0]*freq,channelOffsets[0]+p[1]*freq,channelOffsets[0]+p[2]*freq)), + int(255*math::Perlin::Noise(channelOffsets[1]+p[0]*freq,channelOffsets[1]+p[1]*freq,channelOffsets[1]+p[2]*freq)), + int(255*math::Perlin::Noise(channelOffsets[2]+p[0]*freq,channelOffsets[2]+p[1]*freq,channelOffsets[2]+p[2]*freq)), + 255 ); + } + } +} + +static void ColorNoise(MeshType& m, int noiseBits) +{ + if(noiseBits>8) noiseBits = 8; + if(noiseBits<1) return; + + math::SubtractiveRingRNG randomGen = math::SubtractiveRingRNG(time(NULL)); + for(VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); ++vi) + { + if(!(*vi).IsD()){ + (*vi).C()[0] = math::Clamp((*vi).C()[0] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255); + (*vi).C()[1] = math::Clamp((*vi).C()[1] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255); + (*vi).C()[2] = math::Clamp((*vi).C()[2] + randomGen.generate(int(2*pow(2.0f,noiseBits))) - int(pow(2.0f,noiseBits)),0,255); + } + } +} + }; }// end namespace