From d89a3da4ea81576f9d3913da90afe268a00fb089 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Thu, 24 Jul 2008 09:53:18 +0000 Subject: [PATCH] commented --- vcg/complex/trimesh/update/color.h | 51 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/vcg/complex/trimesh/update/color.h b/vcg/complex/trimesh/update/color.h index 7ff09289..ed9b2b65 100644 --- a/vcg/complex/trimesh/update/color.h +++ b/vcg/complex/trimesh/update/color.h @@ -334,8 +334,8 @@ static int Filling(UpdateMeshType &m, Color4b c, const bool ProcessSelected=fals return counter; } -//Reduces the mesh to two colors according to a treshold. -static int Tresholding(UpdateMeshType &m, float treshold, Color4b c1 = Color4::Black, Color4b c2 = Color4::White, const bool ProcessSelected=false) +//Reduces the mesh to two colors according to a threshold. +static int Thresholding(UpdateMeshType &m, float threshold, Color4b c1 = Color4::Black, Color4b c2 = Color4::White, const bool ProcessSelected=false) { int counter=0; VertexIterator vi; @@ -347,7 +347,7 @@ static int Tresholding(UpdateMeshType &m, float treshold, Color4b c1 = Color4 lightness){ - lightness = v; - unbalancedWhite = (*vi).C(); + lightness = v; //save lightness + unbalancedWhite = (*vi).C(); //save the color } } } } } + //in this loop the transformation is applied to the mesh for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... { if(!(*vi).IsD()) //if it has not been deleted... @@ -749,8 +762,14 @@ static int WhiteBalance(UpdateMeshType &m, bool automatic, Color4b userColor, co return counter; } +//Balnce the white of the color, applying a correction factor based on the unbalancedWhite color. static Color4b ColorWhiteBalance(Color4b c, Color4b unbalancedWhite) { + //sanity check to avoid division by zero... + if(unbalancedWhite[0]==0) unbalancedWhite[0]=1; + if(unbalancedWhite[1]==0) unbalancedWhite[1]=1; + if(unbalancedWhite[2]==0) unbalancedWhite[2]=1; + return Color4b( math::Clamp((int)(c[0]*(255.0f/unbalancedWhite[0])), 0, 255), math::Clamp((int)(c[1]*(255.0f/unbalancedWhite[1])), 0, 255),