How to read STEP color properly as CAD Assistant

Dear OCCT community,
when I use CAD assistant to read a STEP file and I open material manager I see this:

When I read color by using XCAFDoc_ColorTool as colorReader->GetColor(label, XCAFDoc_ColorSurf, color) I will get color circled as blue #101603FF, which is too dark .
How should I read color in different way to get the correct one, circled as red #495421 .

Thank you for help.

Best Regards
Pavel Chmelar

Dmitrii Pasukhin's picture

Hello, which version of OCCT do you use? CAD Assistent use the same color system as native OCCT XCAF.

Best regards, Dmitrii.

Pavel Chmelar's picture

Hello, I'm using the latest version 7.7.2.
I've found this lesson on Quaoar and it seems that I need to iterate also through faces, because this model (see the attachment) in CAD Assistant:

I reading as:

When I go through assembly I reading only the blue part of a wheel (oposit side of wheels is not visible because of normals, when I rotate the model all four wheels are visible). The red part is missing.

Best Regards
Pavel

Attachments: 
gkv311 n's picture

The first color hex name is generated by XCAFDoc_ColorTool::AddColor() method and the second one - by Quantity_ColorRGBA::ColorToHex(). The second method converts color from linear to non-linear sRGB color space, while the first one converts values to hex directly, which is wrong. I think it is a bug in XCAFDoc_ColorTool::AddColor().

    //! Returns hex sRGBA string in format "#RRGGBBAA".
    static TCollection_AsciiString ColorToHex (const Quantity_ColorRGBA& theColor,
                                               const bool theToPrefixHash = true)
    {
      NCollection_Vec4<Standard_ShortReal> anSRgb = Convert_LinearRGB_To_sRGB ((NCollection_Vec4<Standard_ShortReal> )theColor);
      NCollection_Vec4<Standard_Integer> anSRgbInt (anSRgb * 255.0f + NCollection_Vec4<Standard_ShortReal> (0.5f));
      char aBuff[12];
      Sprintf (aBuff, theToPrefixHash ? "#%02X%02X%02X%02X" : "%02X%02X%02X%02X",
               anSRgbInt.r(), anSRgbInt.g(), anSRgbInt.b(), anSRgbInt.a());
      return aBuff;
    }
Pavel Chmelar's picture

Thank you very much @gkv311 n. It's exactly this reason why the color was wrong.

 

To my post above. The model wasn't complete because I didn't expected that a top shape itself with some sub-shapes contains also space data.  

Best Regards
Pavel

Josep Fontdecaba i Buj's picture

Hi
I am quite new here. I am using version 7.7.0 to read STEP files.
I can't get the color from a STEP file generated by SolidWorks with all COLOUR_RGB labels apparently in place.
I try the standard:
Handle(XCAFDoc_ColorTool) ColorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel);
Quantity_Color color;
Standard_Boolean ok = ColorTool->GetColor(label, XCAFDoc_ColorSurf, color);
It always returns false.
Should I move to 7.7.2 ? Where can I download it ?
Or do I need colors saved by SW in a particular manner ?
Thanks in advance

Dmitrii Pasukhin's picture

label should contains a color? 7.7.2 have no updates about color extractions

Best regards, Dmitrii.

Josep Fontdecaba i Buj's picture

Dimitrii
Forgive my poor background on STEP format. I just dropped here a week ago.
I understand every shape is associated to a label, and there is entities that are descendents of either. I am trying to find what descendent entities they have so I can find the one containing color information.
I was trying to follow the tree structure so I can see what information is associated to every shape. I am trying to build a small STEP->to->STL converter and add relevant information to the STL header for every shape I find.
Any help on that direction will be appreciated.
Thanks in advance.
Josep