STEP surface color cannot be retrieved anymore since OpenCascade upgrade to 7.x

Hi,

To read and triangulate my STEP files, I use OpenCascade 6.9.x and tried to upgrade to 7.4.0.

However, since my 7.4.0, i can not retrieve the colors of some of my step file shapes anymore. I would usually recursively iterate through my shapes to get the surface colors, but it doesn't work anymore as the aColorTool->GetColor now always returns false. Is use OpenCascade 7.4.0 with a ISO-10303-21 STEP file. 

Any idea of any major change since 6.9.x that could cause that ? I feel like the color tool doesn't make the "link" anymore with the shapes... Thank you !

 

bool CAD_reader::queryColor(const TopoDS_Shape& shape, Quantity_Color& color)
{
	color.SetValues(0.5, 0.5, 0.5, Quantity_TOC_RGB);

	if (aColorTool->GetColor(shape, XCAFDoc_ColorGen, color))
		return true;
	else if (aColorTool->GetColor(shape, XCAFDoc_ColorCurv, color))
		return true;
	else if (aColorTool->GetColor(shape, XCAFDoc_ColorSurf, color))
		return true;

	return false;
};

Please note that I tried the last CADAssistant to check and the colors show well in it

Benjamin Bihler's picture

You do not show what "aColorTool" is. We read STEP colors like this:

void ImporterExporter::setSTEPShapeColors(const STEPConstruct_Styles& styleTool,
		ShapeSequence& shapes)
{
	Standard_Integer stylesCount = styleTool.NbStyles();

	for (Standard_Integer styleIndex = 1; styleIndex <= stylesCount; ++styleIndex)
	{
		Handle(StepVisual_StyledItem) style = styleTool.Style(styleIndex);

		if (style.IsNull())
		{
			continue;
		}

		Handle(StepVisual_Colour) surfaceColor, boundColor, curveColor;
		Standard_Boolean isComponent = Standard_False;

		if (!styleTool.GetColors(style, surfaceColor, boundColor, curveColor,
				isComponent))
		{
			continue;
		}

		TopoDS_Shape currentShape = STEPConstruct::FindShape(
				styleTool.TransientProcess(), style->Item());

		for (auto& shape : shapes)
		{
			if (currentShape.IsEqual(shape.shape))
			{
				Quantity_Color shapeColor;

				if (!curveColor.IsNull())
				{
					styleTool.DecodeColor(curveColor, shapeColor);
					shape.color = shapeColor.Name();
				}
				else if (!surfaceColor.IsNull())
				{
					styleTool.DecodeColor(surfaceColor, shapeColor);
					shape.color = shapeColor.Name();
				}
				else if (!boundColor.IsNull())
				{
					styleTool.DecodeColor(boundColor, shapeColor);
					shape.color = shapeColor.Name();
				}
				else
				{
					throw Exception("Problem decoding the color of a shape", __TRACE__);
				}
			}
		}
	}
}

Hope it helps,

Benjamin

Pierre Nah's picture

Thanks for your answer ! Sorry if I didn't say what aColorTool is, it is actually this :

STEP_reader::STEP_reader()

	{
		hApp = XCAFApp_Application::GetApplication();
		hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);

		aShapeTool = XCAFDoc_DocumentTool::ShapeTool(hDoc->Main());
		aColorTool = XCAFDoc_DocumentTool::ColorTool(hDoc->Main());

		STEPControl_Controller::Init();
		Interface_Static::SetIVal("read.surfacecurve.mode", 3);
	}
int STEP_reader::read(Standard_CString& path)

{

if (reader.ReadFile(path) != IFSelect_RetDone)

{

reader.Reader().PrintCheckLoad(Standard_True, IFSelect_ItemsByEntity);

return 1;

}

reader.SetColorMode(true);

reader.SetNameMode(true);

reader.SetLayerMode(true);

reader.SetPropsMode(true);

reader.SetGDTMode(true);

reader.SetSHUOMode(true);

reader.SetMatMode(true);



STEPControl_Reader reader0 = reader.Reader();

int nr = reader0.NbRootsForTransfer();

reader0.TransferRoots();



reader.Transfer(hDoc);



TDF_LabelSequence shapes;

aShapeTool->GetShapes(shapes);

...

}

I'm going to try your approach but it seems very different from mine. I'll tell you if it worked !

My approach is that once i have all the root shapes using GetShapes, i just iterate over their children shapes recursively to get the colors with aColorTool. It used to work, but it it broken since 7.x.x ...

You can also note that the colors can be found with the same tool using GetColors, and this piece of code still works to find all the colors (without them being assigned to shapes specifically unfortunately). That's why it's very strange.

	TDF_LabelSequence all_colours;
	aColorTool->GetColors(all_colours);
	printf("Number of colours: %d\n", all_colours.Length());
	for (int i = 1; i <= all_colours.Length(); i++) {
		Quantity_Color col;
		std::stringstream col_rgb;
		aColorTool->GetColor(all_colours.Value(i), col);
		col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
		printf("Colour %s %s\n", col.StringName(col.Name()), col_rgb.str().c_str());

	}
Pierre Nah's picture

Any news on this bug? We've been fighting on it for a few weeks now...

To give it more context, this issue occurs when our STEP File only has a shape as the root, and the faces of this root shape are colored. When our STEP file has subshapes it works pretty fine we can get the colors of these subshapes.

I can still find all the colors of the document with the code above, but there is no way i can get the faces associated with these respective colors...

Does anyone from OpenCascade could tell me what changed since 6.9.1 on XCAF color getting logic?

Kirill Gavrilov's picture

I don't recall any cardinal changes in XCAF document structure related to colors since OCCT 6.9.1.
So I believe that it remains the same, just some STEP reader bugfix(es) probably corrected previously misplaced color labels in some specific cases.

As XCAFPrs_AISObject displays colors of the model correctly - there is no reason to consider XCAF document being broken / lost colors.

So I would try to prepare a minimal code snippet reproducing the issue detached from application code and STEP file sample to see where the problem in code might appear and suggest an update.