Issue reading colors compared with CAD assistant.

I found some issues when I get colors from a STEP file (I created myself with FreeCad).
The method that I use is searching for all types of colors (gen, curv, surf) and then store them in data like:

Quantity_Color color;
color.SetValues(0.5, 0.5, 0.5, Quantity_TOC_RGB);
XCAFDoc_ColorType colorTypes[] =
{
       XCAFDoc_ColorType::XCAFDoc_ColorGen,
        XCAFDoc_ColorType::XCAFDoc_ColorCurv,
        XCAFDoc_ColorType::XCAFDoc_ColorSurf,
};

for (const XCAFDoc_ColorType& colorType : colorTypes)
{
     if (colorTool->GetColor(label, colorType, color))
    {
       //Save color....

When I compare the results with the ones that I get from saving the same STEP file as OBJ with CAD Asistant:
Colors from custom implementation:

newmtl Material0
     Kd 0.4019778072834015 0 1

newmtl Material1
     Kd 0.06847815960645676 0.06847815960645676 0.16202938556671143

newmtl Material2
     Kd 1 1 0

Colors from CAD Assistant:

newmtl Material_2
     Kd 0.6666667 0 1

newmtl Material_1
     Kd 0.2901961 0.2901961 0.4392157

newmtl Material_3
     Kd 1 1 0

I also attached images for a better comparison.

Best regards, Lorenzo

Dmitrii Pasukhin's picture

Hello 

Problem with color format. The main format for CAD Assistant is sRGB and any colours from step saved as sRGB.

Please take a look into https://dev.opencascade.org/content/occt-3d-viewer-becomes-srgb-aware

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

I find out that XCAF don't care about which format is saved. I think we need to analyse it and improve. Thank you. I will create a issue to keep this idea.

Best regards, Dmitrii.

Lorenzo Napl's picture

Yes seems that changing from Quantity_TOC_RGB to Quantity_TOC_sRGB doesn't fix the issue.
I finally get the good values using Quantity_Color::Convert_LinearRGB_To_sRGB(), so anyone facing a similar issue, this should work.
Thanks again for your work!

Best regards, Lorenzo.

gkv311 n's picture

OBJ relies on a legacy shading model with not well-defined color definition. If you are using some own OBJ writer - make sure to convert color components, as it is done by RWObj_CafWriter:

double anRgb[3] = {};
color.Values(anRgb[0], anRgb[1], anRgb[2], Quantity_TOC_sRGB);

Your code snippets are incomplete, so fill free to share more details if problem is still unclear.

Lorenzo Napl's picture

As stated by Dimitrii, using GetValues with Quantity_TOC_sRGB, return the same values as using it with Quantity_TOC_RGB. The last upper message that I post works as a workaround until they fix it.

Best regards, Lorenzo.

Dmitrii Pasukhin's picture

Quantity_Color::Values(aR,aG,aB, Quantity_TOC_sRGB) calls internally Convert_LinearRGB_To_sRGB. The result should be the same(in latests version of occt)

Best regards, Dmitrii.

Lorenzo Napl's picture

With Quantity_Color::Values(aR,aG,aB, Quantity_TOC_sRGB) seems to work as well.

Thanks!

Best regards, Lorenzo.