Issue reading colors compared with CAD assistant.

Hello,
Does Current version v7.8.0 (or previous one like v7.7.0) use the same methods to get label colors as it does the CAD Assistant tool?
In our case we are facing the same issue since v7.7.0, where on IGES files we are unable to get colors from labels.

Things that we know:

- CAD Assitant reads those colors as we can see them on its viewer.
- IGES contains colors as when we read the label COLORS, we get all of them. This is an example code of what we are doing to read them:

    auto colorTool = XCAFDoc_DocumentTool::ColorTool(occtDocument->Main());
    TDF_LabelSequence colorsSequence;
    colorTool->GetColors(colorsSequence);
    for (TDF_LabelSequence::Iterator it(colorsSequence); it.More(); it.Next())
    {
        auto colorLabel = it.Value();
        Quantity_Color color;
        colorTool->GetColor(colorLabel, color);
     }

Things that we tried and didn't worked:

- Reading the colors from shapes using revert iteration.
Didn't work with any of the IGES files that we are facing this issue.

- Reading colors from a certain label:

void OcctLabelTraversal::ReadLabelColor(const TDF_Label& label, OcctLabel* pLabel)
{
    Quantity_Color color;
    color.SetValues(0.5, 0.5, 0.5, Quantity_TOC_sRGB);

    if (colorTool->GetColor(label, XCAFDoc_ColorType::XCAFDoc_ColorSurf, color))
    {
        //do something with color
    }
    // repeated if for XCAFDoc_ColorGen and XCAFDoc_ColorCurv
}

- We make sure that SetColorMode is set to true:

    auto reader = IGESCAFControl_Reader();
    reader.SetColorMode(true);

- Trying to see the IGES file through Inspector always crash when we try to open it.

Is that an issue from the IGES reader? What are we doing wrong? I want to repeat that CAD Assistant displays those colors properly.

Kind regards,
Lorenzo Navarro

Dmitrii Pasukhin's picture

Hello, CAD Assistent use similar functionality with XCAFPrs::CollectStyleSettings. You can use this functionality.

I don't think that there is some issue with IGES. When you perform revert iteration. do you find any related Handle(TDataStd_TreeNode) to iterate on?

To open file into Inspector, please save XCAF as xbf and then open result xbf file.

Best regards, Dmitrii.

Lorenzo Napl's picture

I don't think that there is some issue with IGES. When you perform revert iteration. do you find any related Handle(TDataStd_TreeNode) to iterate on?
No, we don't get any related Handle(TDataStd_TreeNode) to iterate on. The only way we get that it's when we open the IGES file with CAD Assistant, then we save it as an IGES again. When we read the final IGES with our code, then we get Handle(TDataStd_TreeNode) that we can iterate and get the labels that are using the colors.

CAD Assistent use similar functionality with XCAFPrs::CollectStyleSettings. You can use this functionality
We also tried to use that (with faces), and no colors are being set as styles:

void FaceProcessor::GetColors(const TopoDS_Face& face)
{
    TopLoc_Location loc = face.Location();
    XCAFPrs_IndexedDataMapOfShapeStyle settings;
    XCAFPrs::CollectStyleSettings(pLabel->GetLabel(), loc, settings);
    
    XCAFPrs_Style aStyle;
    settings.FindFromKey(face, aStyle);
    
    Quantity_Color shape_col = aStyle.GetColorSurf();
    Quantity_Color curv = aStyle.GetColorCurv();
    
    bool hasColor = aStyle.IsSetColorSurf();
    bool hasCurvColor = aStyle.IsSetColorCurv();
    double r = shape_col.Red();
    double g = shape_col.Green();
    double b = shape_col.Blue();
    
    std::cout << "Color:" << (hasColor || hasCurvColor) << r << g << b << std::endl;
}

To open file into Inspector, please save XCAF as xbf and then open result xbf file.
Any example or documentation on how to achieve that? If we save from CAD Assistant to xbf format, then Handle(TDataStd_TreeNode) appears when we do the revert iteration.

Conclusion:
Converting original IGES file to IGES or XBF using CAD Assistant give us the Handle(TDataStd_TreeNode), but this is not intention. Our intention is to read it directly.
Please find attached the demo IGES that we are using.

Attachments: 
Dmitrii Pasukhin's picture

You can see that there are colurs (I use just IgesCafControl_Reader)

To save xbf. you can use the next doc: https://dev.opencascade.org/doc/overview/html/occt_user_guides__ocaf.htm...

Best regards, Dmitrii,

Lorenzo Napl's picture

Hello Dimitri,
The following code snippet contains what are we doing in order to obtain the TDataStd_TreeNode, from colors label:
 

    auto colorTool = XCAFDoc_DocumentTool::ColorTool(occtDocument->Main());
    auto shapeTool = XCAFDoc_DocumentTool::ShapeTool(occtDocument->Main());

    TDF_LabelSequence colorsSequence;
    colorTool->GetColors(colorsSequence);
    for (TDF_LabelSequence::Iterator it(colorsSequence); it.More(); it.Next())
    {
        auto colorLabel = it.Value();
        Quantity_Color color;
        colorTool->GetColor(colorLabel, color);

        Handle(TDataStd_TreeNode) aMainNode;
        if (colorLabel.FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv), aMainNode))
        {
           //Do something with aMainNode
        }
        else if (colorLabel.FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf), aMainNode))
        {
           //Do something with aMainNode
        }
        else if(colorLabel.FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen), aMainNode))
        {
           //Do something with aMainNode
        }
        else 
        {
            continue;
        }
    }

We are also debugging the TDF_Label.cxx FindAttribute method:

We are only being able to iterate over the following 2 attributes, so as we said on previous messages, the TDataStd_TreeNode never arrives:

Please note that Green square are the attributes that we found. Red square are attributes that we never found.
We can saw this attributes on the inspector as we did a previous CAD conversion (using CAD assistant) from IGES (original file format) to STEP.

Lorenzo Napl's picture

<deleted message by duplication>

Dmitrii Pasukhin's picture

i just used DRAW command. I'm not sure that there is can be some problem with configuration. The only one diffence is this command. I can't find a reason for that kind of behavior. Probably there is can be some problem with move or assign operator. Please use consturcor directly

  Standard_Integer onlyVisible = Interface_Static::IVal("read.iges.onlyvisible");
  aReader.SetReadVisible(onlyVisible == 1);

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

When you have not sanded comment, please wait for approving that comment. Not create a new one. We have a little critical spam protection for now.

Best regards, Dmitrii.

Lorenzo Napl's picture

Apologies, it was an issue from yesterday that I thought that previous message was not sent.

Lorenzo Napl's picture

Hello, Dimitrii

That command seems to doesn't affect the final result, at least in this scenario.

We noticed that using DRAW from precompiled binaries from 7.8 seems to display the correctly CAD structure:

If we use DRAW with our compiled binaries (using cmake), we get:

As you can see with precompiled binaries we have colors and names, with our binaries we have no colors (we only have color table) and we have no names.
Maybe we are doing something wrong at our Cmake config? Let me break it down just in case we are missing something in order to correctly get the full structure o the document:

3RDParty

BUILD

INSTALL

USE

Best regards,

Lorenzo Navarro

Dmitrii Pasukhin's picture

IGES import has no dependences on CMake flags(we have no specific defines depends on that). It is really interesting why it happened. I can't answer that. I used FreeImage addtionally and openGL. I just build on usual way delivery with no magic flags.

Just for recommendation - You can use another memory manager (jemalloc) (USE_MMGR_TYPE) that will be increase the performance. And you can disable build of BUILD_Module_DETools. It is our internal tool, that not used in general solutions.

Best regards, Dmitrii.

Lorenzo Napl's picture

Hello Dimitrii,

Please could you confirm which extra checks you are using in order to generate properly binaries?
By properly I meant in order to be able to read colors and names, as seen in our previous messages, some crucial differences must exist in order that IGES performs different and the same for DRAW application.

As I understood:

- You are using USE_MMGR_TYPE as jemalloc.
- Use FreeImage (I asume that Install FreeImage is also checked).
- Uncheck BUILD_Module_DETools.
- Check "Use OPENGL".

Dmitrii Pasukhin's picture

The latest build was configured with the next use commands

# Use of third-party libraries.
set (OpenCASCADE_WITH_TCL       ON)
set (OpenCASCADE_WITH_FREETYPE  ON)
set (OpenCASCADE_WITH_FREEIMAGE ON)
set (OpenCASCADE_WITH_TBB       ON)
set (OpenCASCADE_WITH_VTK       ON)
set (OpenCASCADE_WITH_FFMPEG    ON)
set (OpenCASCADE_WITH_GLES2     ON)
set (OpenCASCADE_WITH_D3D       ON)

But non-of them should be related with colour problem. It is just full build for delivery. INSTALL flags not related to build result, only on installing dll in bin folder after build.

It is my dayli config and there everything working well (VS 22/msvc143)

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

Could you please say which branch do you use? I test on latest master and tag V7_8_0

Best regards, Dmitrii.

Lorenzo Napl's picture

I tested with code from:

Source package from Latest release download page 

And also from:
Release V7_8_0 · Open-Cascade-SAS/OCCT (github.com) (occt-vc143-32.zip)

Kind regards, Lorenzo Navarro.

Lorenzo Napl's picture

Hello Dimitrii,

We recently discovered that with our compiled binaries from OCCT, DRAW.exe only displays the correct hierarchy of the object when it is executed from the draw.bat.

Normally we get the following files from installation in order to be used within our app:

- All files that are generated at:

  1. win64\vc14\bind
  2. win64\vc14\libd
  3. \inc

Note that on cmake we mark the install checkbox of what we need.

Are we missing something? If we try to directly execute DRAW.exe we get this error at start:

Anyway, I asume that for translating an IGES the draw application is not really needed, but we are using it as a reference since we are able to see the internal hierarchy.

Kind regards,

Lorenzo Navarro

Lorenzo Napl's picture

Hello Dimitrii,

We finally managed to read colors and names properly. It seems that the issue comes from the fact that we weren't defining as environment variables: CSF_IGESDefaults and CSF_STEPDefaults, set with path to the folder XSTEPResource which contains some settings files:

I'm confused tho, since as you can see at IGESData.cxx, those parameters are already being set but it seems that they are never used:

Any explanation on what is happening?

Kind regards,

Lorenzo Navarro

Lorenzo Napl's picture

Hello Dimitrii,

Any news on that?
In order to get rid from XSTEPResource and the config files FILES, IGES and STEP, we are using the following code:

auto setup = IGESControl_Controller::Init();
auto reader = IGESCAFControl_Reader();
//Transfer to document and rest of the code...

We can also confirm that IGESData::Init() is being executed so methods like Interface_Static::Init ("XSTEP", "FromIGES.exec.op", 't', "FixShape"); are executed, which we assumed that are the necessary to get the colors and names properly.
Any other thing that we are missing? With the previous code changes we are facing the same issues...

Kind regards,
Lorenzo Navarro

hc cheng's picture

Setting Interface_Static::Init("XSTEP", "read.iges.resource.name", 't', "") before new IGESCAFControl_Reader works well. I think OCCT will ignore IGES file in XSTEPResource dir.

Dmitrii Pasukhin's picture

Hi, I can't check your issue so fast. I will check it later.

Best regards, Dmitrii.