AmbientColor on surface representation

Dear all,

In my c++ custom application I want to the surface representation of my contour filter to a solid color.
I have tried to change the property but the color doesn’t change.

Can you help me to understand what is wrong in this code?

contourFilter = builder->createFilter("filters", "Contour", fitsSource);
auto reprSurface = builder->createDataRepresentation(contourFilter->getOutputPort(0), viewCube);
auto reprProxySurface = reprSurface->getProxy();
vtkSMPropertyHelper(reprProxySurface, "Representation").Set("Surface");
double red[3] = { 1.0, 0.0, 0.0 };
vtkSMPropertyHelper(reprProxySurface, "AmbientColor").Set(red, 3);

Did you update your server state using reprProxySurface->UpdateVTKObject() ?

Also you may want to trigger a render in your view after that.

Yes I do, but the contour continue to be colored by my scalar instead ad the red solid color

Ambient coloring involves two controls: Ambient Color and Ambient. Try setting the Ambient factor to 1.0. Also, there’s a Diffuse factor too. Of you set Ambient to 1, you may want to set Diffuse to 0 to avoid over saturation.

Setting Ambient to 1 and Diffuse to 0 makes my color brighter but the contour filter stays colored with my scalar and not a solid color. I think I need to somehow set the color mapping to “solid color” like I can do with the paraview GUI

Oh indeed if you have some data coloring already enable then you’ll need to disable it.
To do that I usually use the vtkSMPVRepresentationProxy class, it goes something like :

vtkSMPVRepresentationProxy::SetScalarColoring(
  reprProxySurface, nullptr, 0);

Note that this class is also usefull to enable the scalar coloring and play with the displayed data ranges.

Thanks!