Can not get colors of faces


While i triangulate a shape, I explore all the faces and trying to get their colors by using XCAFDoc_ColorTool GetColor method.

Since i updated to OpenCascade 7.4.0, i cannot get colors.

Does anyone know this situation?  



for(int i=1;i<=nbS;++i)


const TDF_Label& label=labels.Value(i);



Handle(XCAFDoc_ColorTool) colors;

Quantity_Color color;

TopoDS_Face face=TopoDS::Face(explorer.current());



// Always it comes false



Kirill Gavrilov's picture

Which file format do you open?

selman3004_150899's picture

Step File

Kirill Gavrilov's picture

Colors might be assigned in various ways within STEP file - iterating over shape Faces is only one place where colors might be found.
Have you tried displaying your model in Draw Harness or in CAD Assistant? Are there any colors?

ReadStep D myStep.stp
XDisplay -dispMode 1 D

XCAFPrs::CollectStyleSettings() is more reliable way to collect color information within the document.

selman3004_150899's picture

thanks for your advice. I've done it.

g b's picture

I am also trying to get colors from STEP and set them to a mesh.
What I have by now is following code:

for(Standard_Integer i(1); i <= length; ++i)
    const TDF_Label& label = frshapes.Value(i);
    TopoDS_Shape shape;
    myAssembly->GetShape(label, shape);
    BRepMesh_IncrementalMesh Mesh(shape, 0.1);

    for(TopExp_Explorer aExpSolid(shape,TopAbs_SOLID); aExpSolid.More(); aExpSolid.Next())
        for(TopExp_Explorer aExpFace(aExpSolid.Current(),TopAbs_FACE); aExpFace.More(); aExpFace.Next())

            TopLoc_Location loc;
            XCAFPrs::CollectStyleSettings(label, loc, set);

            XCAFPrs_Style aStyle;
            set.FindFromKey(shape, aStyle);
            Quantity_Color shape_col = aStyle.GetColorSurf();

            double r = shape_col.Red();
            double g = shape_col.Green();
            double b = shape_col.Blue();
            //... do other mesh stuff and assingn color to triangles

I have tested in on a STEP that I exported from Freecad with assemblies and subassemblies in it.
So for a file with just two colored cubes it works, but for subasemblies it only works for some.
So do I have to collect colorsettings somewhere else as well??

EDIT: I solved it myself. The problem was that I was looking up solids in the stylesettings which did not work, but when i loop over faces to get the color it works as expected