How to know from a shape, which color from label corresponds to it?

Hi!

I'm using XCAFDoc_ColorTool::GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color);
I using this function for every type of color:

XCAFDoc_ColorType::XCAFDoc_ColorGen,
XCAFDoc_ColorType::XCAFDoc_ColorCurv,
XCAFDoc_ColorType::XCAFDoc_ColorSurf,

After that for that label I iterate over its shapes and repeat the same action (with GetColor(const TopoDS_Shape& S...)), and most of the shapes doesn't return any color.
How do I know which color should I assign to that shape? From the label I only received a XCAFDoc_ColorSurf color but none of type XCAFDoc_ColorGen, which was the one I was expecting for that scenario.
My actual scenario:
STEP file (cube) with 2 faces with different color and the rest maintains the same color. (eg: yellow, pink, gray, gray...)

Regards!

Dmitrii Pasukhin's picture

Hello.

Plase make a look into documentation.

On each label can be attach any types of color(gen(combined), curve, surface). 

The colour is only on one of the labels in the hierarchy if it is should means that all its children must be the same colour. That is, the colour attribute is inherited deep into the hierarchy and is only overloaded with another colour label.

You need to go through the labels and get the right styles in the hierarchy.

Best regards, Dmitrii.

Lorenzo Napl's picture

My I assume that if two labels have the same tag, the labels are repeated?

Regards.

Dmitrii Pasukhin's picture

Tag is a just a number of the label's childs below.

For example. 0:1:1:1:1 has tag 1 and 0:1:2:1 has the tag 1

You need to work with entry(ascii combination of tags)

TCollection_AsciiString aLabelStr;
TDF_Tool::Entry(aLabel, aLabelStr);
// aLabelStr = 0:1:1:1:1 for example

For checking for repeating use NCollection_Map or something similar.

Best regards, Dmitrii

Lorenzo Napl's picture

I'm getting a different definition from TDF_Label (attached image). Please can you confirm?

Attachments: 
Dmitrii Pasukhin's picture

0:1:1:1:1

0 - tag 1 - tag 1 - tag 1 - tag 1 - tag

Each number is a tag. But combination of them are entry. Tags can be repeated in different position. But entry is unique.

Best regards, Dmitrii

Lorenzo Napl's picture

So do I need to use entry in order to know if label1 contains same shape than label2?

Dmitrii Pasukhin's picture

No, it entry can't help you with it. You need to get shape and only then check the shape.

Best regards, Dmitrii.

Lorenzo Napl's picture

So despite the fact that labels can have same Tag, shapes related to them could be completely different?
The only way to check if labels have same related shapes is using TopoDS_Shape methods like IsPartner, IsSame, IsEqual...?
My purpose is try to avoid unnecessary computing time by reading again shapes that could contain same info.

Dmitrii Pasukhin's picture

Yes, you are right. Sometimes it can be.

But it takes not too much CPU time. But TopoDS_Shape can reference to the same TopoDS_TShape but with another orientation or location, please make attention.

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

Please take a look into XCAFPrs

Best regards, Dmitrii.