Get coordinates in the global coordinate system (STEP)?

Dear friends!

I work with the STEP format. There is a Big problem before me. When I read STEP, I noticed the not all solids were positioned correctly.
I read the list of Shapes from the Step files and each Shape we triangulate by the Mesh function. We see the coordinates of received vertexes have been determined in the local coordinate system of specific Shape. But we would like to obtain coordinates relative to the global coordinate system of the total assembly. Could you please prompt how and from where can we obtain data about position of local coordinate system of Shape relative to the global coordinate system?

Best regards,

Alex

Eugine's picture

Hello, Alex,

You should do the following:

TopoDS_Shape aShape; // The shape to extract mesh from
TopLoc_Location aShapeLocation = aShape.Location();

gp_Trsf aTransformation;
aTransformation.SetTransformation(aShapeLocation.Transformation());
aTransformation.Invert();

// Meshing aShape

for (int i = 0; i < aVertexCount; i++)
{
gp_XYZ aVertex;
// Here you should convert mesh vertex to gp_XYZ (aVertex)
aTrsf.Transforms(aVertex);
}

Best regards,
Eugine.

Alex Prokoshev's picture

Dear Eugine!

In the function:
aTransformation.SetTransformation(aShapeLocation.Transformation());

SetTransformation requires type gp_Ax3
but aShapeLocation.Transformation returned gp_Trsf

Compiler output error!

What should I do?

Best regards,
Alex

Eugine's picture

Sorry, it was my mistake.

You should replace:

aTransformation.SetTransformation(aShapeLocation.Transformation());

with

aTransformation.Multiply(aShapeLocation.Transformation());

Best regards,
Eugine.

Alex Prokoshev's picture

Dear Eugine!

The listing of programm:

STEPCAFControl_Reader Reader; Reader.Perform(FileName,StepDocument);
Handle(XCAFDoc_ShapeTool) root = XCAFDoc_DocumentTool::ShapeTool(StepDocument->Main());
TDF_LabelSequence FreeShapesLabel; root->GetShapes(FreeShapesLabel);
int nsolid=FreeShapesLabel.Length();
TopoDS_Shape tpShape;

for(i=0;iGetShape(FreeShapesLabel.Value(i),tpShape);

if(tpShape.ShapeType()!=TopAbs_SOLID && tpShape.ShapeType()!=TopAbs_COMPSOLID) continue;

TopLoc_Location location=tpShape.Location();
gp_Trsf transformation; transformation.Multiply(location.Transformation());

BRepMesh::Mesh(tpShape,Property->StepAccuracyFactor);
}

transformation – obtained matrix = identity matrix and vector loc={0,0,0} .

No displacements of the local coordinate system.

Attachments: 
Eugine's picture

Dear, Alex,

After you mesh your shape you should extract all mesh vertexes from mesh structure.
Then you should apply the transformation:

gp_Trsf transformation;
TopLoc_Location location=tpShape.Location();
transformation.Multiply(location.Transformation());

to each vertex of the mesh.

After that all your vertexes will have the coordinates in the global coordinate system.

Best regards,
Eugine.

Eugine's picture

Just some remark:

gp_Trsf transformation;
TopLoc_Location location=tpShape.Location();
transformation.Multiply(location.Transformation());
transformation.Invert();

Best regards,
Eugine.

Alex Prokoshev's picture

Dear Eugine!

Unfortunately nothing happened.
Possibly we didn't take into account something more.
Transformation matrix is edentity matrix.

The bug is visible on the picture.

Attachments: 
Eugine's picture

Dear, Alex,

Could you post your code here?
The code should include transformation of mesh vertexes and displaing mesh?

Best regards,
Eugine.

Alex Prokoshev's picture

Dear Eugine!

The whole program is very big, so I will lay out a logical part, which explains our actions.

1. Read STEP file.
2. Filled structure StepDocument.
3. Read all Shapes.
4. Made the transformation for each Shapes.
5. Make a Mesh.

The listing:

STEPCAFControl_Reader Reader; Reader.Perform(FileName,StepDocument);
Handle(XCAFDoc_ShapeTool) root = XCAFDoc_DocumentTool::ShapeTool(StepDocument->Main());
TDF_LabelSequence FreeShapesLabel; root->GetShapes(FreeShapesLabel);
int nsolid=FreeShapesLabel.Length();
TopoDS_Shape tpShape;

for(i=0;iGetShape(FreeShapesLabel.Value(i),tpShape);
if(tpShape.ShapeType()!=TopAbs_SOLID && tpShape.ShapeType()!=TopAbs_COMPSOLID) continue;
TopLoc_Location location=tpShape.Location();

gp_Trsf transformation;
transformation.Multiply(location.Transformation());
transformation.Invert();

// see in the debugger
transformation.scale=1
transformation.loc={0,0,0}
transformation.matrix={1,0,0}{0,1,0}{0,0,1}
// These values we see for each read by the Shape.
// In our opinion transformation.matrix={1,0,0}{0,1,0}{0,0,1} should be different for rotated bodies.
// In our case, the matrix is the same for all Shapes read. Hence there is no body rotated.
// But it is not. The second body is rotated relative to the first. Obviously we are wrong somewhere in
// the logic or consistency.

BRepMesh::Mesh(tpShape,Property->StepAccuracyFactor);
}

If we manually change the value of transformation.loc={400,0,0}, the Shape moves. Ie everything works. If we take the data structure of StepDocument, an error occurs.

Eugine's picture

Dear, Alex,

I still do not see where you extract all vertexes from mesh and transform them.
Could you post the value of location.Transformation()?
Sorry, but the invertion of the transformation is not necessary here.

Best regards,
Eugine.

Alex Prokoshev's picture

Dear Eugine!

All in the attached file.

Best regards.
Alex

Attachments: