# surface curvature | set color on vertices

Hi,

I'm working on my 1st OCC app ( written in pythonocc ), which is displaying the curvature of a surface.
I've got the curvature computed, though the problem I've got is that I do not know how to

1) map the curvature to a ( red->blue ) falsecolor mapping
2) assign this mapping to the vertices

If you could point me in the direction, that would mean a lot to me.

Thanks,

-jelle Hi jelle,

assumed you defined your colors as an rgb array:

float * curvatureColors; //blue to red or whatever

you could use something like this:

double span = 1;
span = (maxVisualizedCurvature - minVisualizedCurvature) / (double) (numberColors - 1);
int spanNumber = 0;
double curvatureStrength = 0;

loop over all faces & triangles

if (facing->HasUVNodes())
{
for(int k = 1; k <= 3 ; k++)
{
if(k == 1)
prop.SetParameters(UVNodes(n1).X(), UVNodes(n1).Y());
else if(k == 2)
prop.SetParameters(UVNodes(n2).X(), UVNodes(n2).Y());
else
prop.SetParameters(UVNodes(n3).X(), UVNodes(n3).Y());

if (prop.IsCurvatureDefined())
{
switch (myCurvatureType)
{
case Gaussian:
curvature = prop.GaussianCurvature();
break;
case Mean:
curvature = prop.MeanCurvature();
break;
case Min:
curvature = prop.MinCurvature();
break;
case Max:
curvature = prop.MaxCurvature();
break;
default:
curvature = prop.GaussianCurvature();
}

visualizationDone = true;

if(span != 0)
{
spanNumber = 1 + (int) ( (curvature - minVisualizedCurvature) /span);
curvatureStrength = (curvature - minVisualizedCurvature - (spanNumber - 1) * span) / span;
}
else
{
curvatureStrength = 1.0;
spanNumber = 0;
}

if( (spanNumber < 0) || (spanNumber > numberColors - 1) ||
(curvatureStrength > 1.0) || (curvatureStrength < 0) )
{
curvatureStrength = 1.0;

if(spanNumber > numberColors - 1)
spanNumber = numberColors - 1;
else if(spanNumber < 0)
spanNumber = 0;
}

if(spanNumber > 0 )
{
prevR = curvatureColors[3 * (spanNumber - 1) + 0];
prevG = curvatureColors[3 * (spanNumber - 1) + 1];
prevB = curvatureColors[3 * (spanNumber - 1) + 2];
}
else
{
prevR = curvatureColors;
prevG = curvatureColors;
prevB = curvatureColors;
}

R = prevR + (float)curvatureStrength * ( curvatureColors[3 * spanNumber + 0] - prevR );
G = prevG + (float)curvatureStrength * ( curvatureColors[3 * spanNumber + 1] - prevG );
B = prevB + (float)curvatureStrength * ( curvatureColors[3 * spanNumber + 2] - prevB );

{
R = ceil(R);
G = ceil(G);
B = ceil(B);
}

points(k).SetColor(Quantity_Color(R,G,B,Quantity_TOC_RGB));
}
}

}

Pawel Dear Pawel,

Thank you so much for sharing that code with me, things are working out perfectly!
Thanks again,

-jelle No problem - I'm glad I could help.
Pawel