Commit 21f82e2d authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'fix_color_cal_in_singlevtpexport'

0b20b2a4 fix a case where color could exceed 1.0
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !4737
parents ea980a25 0b20b2a4
......@@ -384,6 +384,39 @@ void vtkSingleVTPExporter::WriteVTP(
opd->GetPointData()->SetNormals(otnormals);
}
// compute the maximum color in case it goes over 1.0
float maxColor = 1.0;
for (size_t i = 0; i < actors.size(); ++i)
{
actorData *ad = &(actors[i]);
vtkProperty *prop = ad->Actor->GetProperty();
double *dcolor = prop->GetDiffuseColor();
double diffuse = prop->GetDiffuse();
double *acolor = prop->GetAmbientColor();
double ambient = prop->GetAmbient();
float col[3] = {
static_cast<float>(
dcolor[0]*diffuse + acolor[0]*ambient),
static_cast<float>(
dcolor[1]*diffuse + acolor[1]*ambient),
static_cast<float>(
dcolor[2]*diffuse + acolor[2]*ambient)
};
if (col[0] > maxColor)
{
maxColor = col[0];
}
if (col[1] > maxColor)
{
maxColor = col[1];
}
if (col[2] > maxColor)
{
maxColor = col[2];
}
}
maxColor = 255.0/maxColor;
int pointOffset = 0;
for (size_t i = 0; i < actors.size(); ++i)
{
......@@ -475,11 +508,11 @@ void vtkSingleVTPExporter::WriteVTP(
double opacity = prop->GetOpacity();
float col[4] = {
static_cast<float>(
vtkMath::Min(255.0*(dcolor[0]*diffuse + acolor[0]*ambient),255.0)),
vtkMath::Min(maxColor*(dcolor[0]*diffuse + acolor[0]*ambient),255.0)),
static_cast<float>(
vtkMath::Min(255.0*(dcolor[1]*diffuse + acolor[1]*ambient),255.0)),
vtkMath::Min(maxColor*(dcolor[1]*diffuse + acolor[1]*ambient),255.0)),
static_cast<float>(
vtkMath::Min(255.0*(dcolor[2]*diffuse + acolor[2]*ambient),255.0)),
vtkMath::Min(maxColor*(dcolor[2]*diffuse + acolor[2]*ambient),255.0)),
static_cast<float>(opacity*255.0)
};
if (!is)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment