From 38323a3c48a92023ef7728d3199272937f7714a3 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 15 Jul 2008 10:40:10 +0000 Subject: [PATCH] disambiguated a pow() call --- vcg/complex/trimesh/update/color.h | 406 ++++++++++++++--------------- 1 file changed, 203 insertions(+), 203 deletions(-) diff --git a/vcg/complex/trimesh/update/color.h b/vcg/complex/trimesh/update/color.h index 9708d06d..35e4bc7f 100644 --- a/vcg/complex/trimesh/update/color.h +++ b/vcg/complex/trimesh/update/color.h @@ -313,57 +313,57 @@ static void VertexQuality(UpdateMeshType &m) } VertexQuality(m,minq,maxq); } - -//Fill the mesh with the selected color. -static int Filling(UpdateMeshType &m, Color4b c, const bool ProcessSelected=false) -{ - int counter=0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - (*vi).C() = c; - ++counter; - } - } - } - 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) -{ - int counter=0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - float value = ComputeLightness((*vi).C()); - - if(value<=treshold) (*vi).C() = c1; - else (*vi).C() = c2; - ++counter; - } - } - } - return counter; -} - -//Computes the luminance value for a specified color. -static float ComputeLightness(Color4b c) -{ - float min_rgb = math::Min((float)c[0],(float)c[1]); - min_rgb = math::Min(min_rgb,(float)c[2]); - float max_rgb = math::Max((float)c[0],(float)c[1]); - max_rgb = math::Max(max_rgb,(float)c[2]); - return (max_rgb + min_rgb)/2; -} + +//Fill the mesh with the selected color. +static int Filling(UpdateMeshType &m, Color4b c, const bool ProcessSelected=false) +{ + int counter=0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + (*vi).C() = c; + ++counter; + } + } + } + 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) +{ + int counter=0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + float value = ComputeLightness((*vi).C()); + + if(value<=treshold) (*vi).C() = c1; + else (*vi).C() = c2; + ++counter; + } + } + } + return counter; +} + +//Computes the luminance value for a specified color. +static float ComputeLightness(Color4b c) +{ + float min_rgb = math::Min((float)c[0],(float)c[1]); + min_rgb = math::Min(min_rgb,(float)c[2]); + float max_rgb = math::Max((float)c[0],(float)c[1]); + max_rgb = math::Max(max_rgb,(float)c[2]); + return (max_rgb + min_rgb)/2; +} //Apply the brightness filter, with the given amount, to the mesh. static int Brighting(UpdateMeshType &m, float amount, const bool ProcessSelected=false) @@ -387,158 +387,158 @@ static int Brighting(UpdateMeshType &m, float amount, const bool ProcessSelected } return counter; } - -static int Contrast(UpdateMeshType &m, float factor, const bool ProcessSelected=false) -{ - int counter=0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - (*vi).C() = ColorMul((*vi).C(),factor); - ++counter; - } - } - } - return counter; -} - -//Subtracts a middle value, multiplies the rgb components of the color for a factor, -//and adds the middle value back.This is used for contrast operation. -static Color4b ColorMul(Color4b c, float factor) -{ - return Color4b( ValueMul(c[0], factor), ValueMul(c[1], factor), ValueMul(c[2], factor), 1); -} - -static int ValueMul(int value, float factor) -{ - return math::Clamp((int)((value - 128)*factor + 128), 0, 255); -} - -static int ContrastBrightness(UpdateMeshType &m, float factor, float amount, const bool ProcessSelected=false) -{ - int counter=0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - (*vi).C() = ColorMulAdd((*vi).C(),factor,amount); - ++counter; - } - } - } - return counter; -} - -//This is a composition of ColorMul() and ColorAdd(), used for Contrast&Brightness operations. -//The result is clamped just one time after all computations; this get a more accurate result. -static Color4b ColorMulAdd(Color4b c, float factor, float amount) -{ - return Color4b( ValueMulAdd(c[0], factor, amount), ValueMulAdd(c[1], factor, amount), ValueMulAdd(c[2], factor, amount), 1 ); -} - -static int ValueMulAdd(int value, float factor, float amount) -{ - return math::Clamp((int)((value - 128)*factor + 128 + amount), 0, 255); -} - -//Invert the rgb components of the color. -static int Invert(UpdateMeshType &m, const bool ProcessSelected=false) -{ - int counter=0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - (*vi).C() = ColorInvert((*vi).C()); - ++counter; - } - } - } - return counter; -} - -//invert the given color -static Color4b ColorInvert(Color4b c) -{ - return Color4b( ValueInvert(c[0]), ValueInvert(c[1]), ValueInvert(c[2]), 1); -} - -static int ValueInvert(int value) -{ - return 255-value; -} -//Apply the gamma correction filter, with the given gamma exponet, to the mesh. -static int Gamma(UpdateMeshType &m, float gamma, const bool ProcessSelected=false) -{ - int counter=0; - - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - (*vi).C() = ColorPow((*vi).C(), 1/gamma); - ++counter; - } - } - } - return counter; -} - -//computes the gamma transformation on a given color, according to new_val = old_val^gamma -static Color4b ColorPow(Color4b c, float exponent) -{ - return vcg::Color4b( - math::Clamp((int)( ValuePow(float(c[0])/255, exponent)*255), 0, 255), - math::Clamp((int)( ValuePow(float(c[1])/255, exponent)*255), 0, 255), - math::Clamp((int)( ValuePow(float(c[2])/255, exponent)*255), 0, 255), - 255); -} - -static float ValuePow(float value, float exponent) -{ - return pow((double)value, exponent); -} - -static int Colourisation(UpdateMeshType &m, Color4b c, float intensity, const bool ProcessSelected=false) -{ - int counter=0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... - { - if(!(*vi).IsD()) //if it has not been deleted... - { - if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation - { - (*vi).C() = ColorApplyDiff((*vi).C(), c, intensity); - ++counter; - } - } - } - return counter; -} - -static Color4b ColorApplyDiff(Color4b old_color, Color4b new_color, float intensity) -{ - return Color4b( ValueApplyDiff(old_color[0],new_color[0],intensity), ValueApplyDiff(old_color[1],new_color[1],intensity), ValueApplyDiff(old_color[2], new_color[2],intensity), 1); -} - -static int ValueApplyDiff(int old_value, int new_value, float intensity) -{ - return math::Clamp((int)(old_value + intensity * (new_value - old_value)), 0, 255); -} + +static int Contrast(UpdateMeshType &m, float factor, const bool ProcessSelected=false) +{ + int counter=0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + (*vi).C() = ColorMul((*vi).C(),factor); + ++counter; + } + } + } + return counter; +} + +//Subtracts a middle value, multiplies the rgb components of the color for a factor, +//and adds the middle value back.This is used for contrast operation. +static Color4b ColorMul(Color4b c, float factor) +{ + return Color4b( ValueMul(c[0], factor), ValueMul(c[1], factor), ValueMul(c[2], factor), 1); +} + +static int ValueMul(int value, float factor) +{ + return math::Clamp((int)((value - 128)*factor + 128), 0, 255); +} + +static int ContrastBrightness(UpdateMeshType &m, float factor, float amount, const bool ProcessSelected=false) +{ + int counter=0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + (*vi).C() = ColorMulAdd((*vi).C(),factor,amount); + ++counter; + } + } + } + return counter; +} + +//This is a composition of ColorMul() and ColorAdd(), used for Contrast&Brightness operations. +//The result is clamped just one time after all computations; this get a more accurate result. +static Color4b ColorMulAdd(Color4b c, float factor, float amount) +{ + return Color4b( ValueMulAdd(c[0], factor, amount), ValueMulAdd(c[1], factor, amount), ValueMulAdd(c[2], factor, amount), 1 ); +} + +static int ValueMulAdd(int value, float factor, float amount) +{ + return math::Clamp((int)((value - 128)*factor + 128 + amount), 0, 255); +} + +//Invert the rgb components of the color. +static int Invert(UpdateMeshType &m, const bool ProcessSelected=false) +{ + int counter=0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + (*vi).C() = ColorInvert((*vi).C()); + ++counter; + } + } + } + return counter; +} + +//invert the given color +static Color4b ColorInvert(Color4b c) +{ + return Color4b( ValueInvert(c[0]), ValueInvert(c[1]), ValueInvert(c[2]), 1); +} + +static int ValueInvert(int value) +{ + return 255-value; +} +//Apply the gamma correction filter, with the given gamma exponet, to the mesh. +static int Gamma(UpdateMeshType &m, float gamma, const bool ProcessSelected=false) +{ + int counter=0; + + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + (*vi).C() = ColorPow((*vi).C(), 1/gamma); + ++counter; + } + } + } + return counter; +} + +//computes the gamma transformation on a given color, according to new_val = old_val^gamma +static Color4b ColorPow(Color4b c, float exponent) +{ + return vcg::Color4b( + math::Clamp((int)( ValuePow(float(c[0])/255, exponent)*255), 0, 255), + math::Clamp((int)( ValuePow(float(c[1])/255, exponent)*255), 0, 255), + math::Clamp((int)( ValuePow(float(c[2])/255, exponent)*255), 0, 255), + 255); +} + +static float ValuePow(float value, float exponent) +{ + return powf(value, exponent); +} + +static int Colourisation(UpdateMeshType &m, Color4b c, float intensity, const bool ProcessSelected=false) +{ + int counter=0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... + { + if(!(*vi).IsD()) //if it has not been deleted... + { + if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation + { + (*vi).C() = ColorApplyDiff((*vi).C(), c, intensity); + ++counter; + } + } + } + return counter; +} + +static Color4b ColorApplyDiff(Color4b old_color, Color4b new_color, float intensity) +{ + return Color4b( ValueApplyDiff(old_color[0],new_color[0],intensity), ValueApplyDiff(old_color[1],new_color[1],intensity), ValueApplyDiff(old_color[2], new_color[2],intensity), 1); +} + +static int ValueApplyDiff(int old_value, int new_value, float intensity) +{ + return math::Clamp((int)(old_value + intensity * (new_value - old_value)), 0, 255); +} };