Color bugs when converting assembly from OCCT to VTK

DanB

CAD community veteran
This problem has been bugging me for days. We have built a pipeline converting an assembly from TopoDS to VTK polydata. Where we use the recursive method proposed by @Quaoar in the youtube video about assembly's to read the assembly before converting. Using XCAFDoc_ColorTool::GetColor() to get colors from the step-file, then we write the colors to a vtkColorTransferFunction lookUpTable - and further use this to set the colors to the vtkMapper based on IDs. For reasons I cannot understand, some sub-shapes get the wrong color. Is someone able to spot our error, or have an explanation for this?

Color bug:
1644398229299.png
Correct colors from FreeCad:
1644398301864.png

This is the function generating the colormap:
1644398432031.png

The input to createColorMap comes from this iterator going through all shapes:
1644398589057.png
DisplayShape:
1644398685821.png
 

Attachments

  • UR10e_Fusion_v4.zip
    9.6 MB · Views: 5
Last edited:

natalia

Moderator
Staff member
The result of the sample proposed by @Quaoar in the youtube video
for this file looks:

UR10e_Fusion_v4_lesson.jpg
That means that colours read from this STEP, later transformed into an OCAF document and shown through AIS presentations are valid.

So comparing two pieces of the code might solve wrong appearance. The first one is from the youtube lesson, which is placed in the "Lesson12_XDE" directory of https://gitlab.com/ssv/lessons and the current implementation.

The recursive processing is different. Less recursion in the attached code leads to skipping some children colours. To compare:

C++:
  // In case of an assembly, move on to the nested component.
  for ( TDF_ChildIterator childIt(refLabel); childIt.More(); childIt.Next() )
  {
    TDF_Label childLabel = childIt.Value();

    if ( !childLabel.IsNull() && ( childLabel.HasAttribute() || childLabel.HasChild() ) )
    {
      TopLoc_Location trsf = parentTrsf * ShapeTool->GetLocation(childLabel);
      this->displayItem(childLabel, trsf, defStyle, itemId, mapOfOriginals);
    }
  }

Following this code should fix vtk result.
 
Last edited:

DanB

CAD community veteran
The result of the sample proposed by @Quaoar in the youtube video
for this file looks:

View attachment 163
That means that colours read from this STEP, later transformed into an OCAF document and shown through AIS presentations are valid.

So comparing two pieces of the code might solve wrong appearance. The first one is from the youtube lesson, which is placed in the "Lesson12_XDE" directory of https://gitlab.com/ssv/lessons and the current implementation.

The recursive processing is different. Less recursion in the attached code leads to skipping some children colours. To compare:

C++:
  // In case of an assembly, move on to the nested component.
  for ( TDF_ChildIterator childIt(refLabel); childIt.More(); childIt.Next() )
  {
    TDF_Label childLabel = childIt.Value();

    if ( !childLabel.IsNull() && ( childLabel.HasAttribute() || childLabel.HasChild() ) )
    {
      TopLoc_Location trsf = parentTrsf * ShapeTool->GetLocation(childLabel);
      this->displayItem(childLabel, trsf, defStyle, itemId, mapOfOriginals);
    }
  }

Following this code should fix vtk result.
Sorry for the late reply.

So if I understand you correctly: we need to use DisplayShape inside the first if-statement as well?
 

natalia

Moderator
Staff member
Hi, @DanB. Yes, you understand correctly. Here, you might either get this method as is or repeat the logic of it in your implementation taking care of the similar recursion.
 
Last edited:
Top