Wed, 07/13/2022 - 15:31
Hi everyone, I am trying to extract some data (mass, volume, area, position (of the center of mass) and its orientation, that is the angle that the figure is rotated about each global axis) from the attached STEP file, containing a 20 mm cube translated 40mm in every axis and rotated 30 deg in every axis.
I know how to get the mass, provided there is a density in the file (which in this case is, but I OCCT somehow does not read it), the area, the volume and its center of mass (ironically in global coordinates) but rotation angles are challenging me.
I am able to get the rotation angles in the local coordinate system, which evidently are all 0. The process I use is:
Read STEP file & extract TopoDS_Shape from it -> TopoDS_Shape.Location() -> TopoDS_Shape.Location().Transformation()
From the gp_Trsf it returns (let s call it trsf) I do trsf.TranslationPart().Coord() to get the coordinates, which are (0,0,0).
From the gp_Trsf it returns (let s call it trsf) I do trsf.GetRotation().GetEulerAngles(gp_EulerSequence.gp_Extrinsic_XYZ) to get the eulerian angles, which are (0,0,0) too.
I suspect this happens because TopoDS_Shape.Location() returns the TopLoc_Location in the local coordinate system, but I am not sure.
Does anybody know how to extract these properties from a global (absolute) coordinate system ?
Thank you very much before hand.
Wed, 07/13/2022 - 20:02
OCCT does read material density from STEP - see information displayed by CAD Assistant from XCAF document:
TopoDS_Shape::Location() returns location it was set before. Whatever it is defined in some local or global coordinate system depends on how your coordinates systems are defined and how / with which flags you explore the root shape. Please share a comprehensive code sample on how you change location and how you try to read it back to give some advise on what might be done wrong.
Thu, 07/14/2022 - 10:20
Hi Kirill, thank you very much for your answer.
I am using a Python wrapper of Open Cascade, so this sample is in written in Python:
I suspect that the method
read_step_file
is part of this python library. This is its definition:Similarly, I assume that the method
list_of_shapes_to_compound
is also from the library. Here it is:About the mass and density, why is it that I don't get the mass in the variable mass_or_volume ? About the rotation angles and location, hope you can understand this python code. If not, I could try to transcribe it into C++, but it would be very bad code.
Thank you for the effort!
Thu, 07/14/2022 - 12:03
Density / material properties are not part of B-Rep (TopoDS_Shape) definition - it is a supplementary information stored as attributes. In case of OCCT, it could be retrieved from XCAF document (XCAFDoc_Material/XCAFDoc_MaterialTool) when STEP file is translated into XCAF. Your code uses a simplified interface read_step_file() returning TopoDS_Shape, so that you loose all document attributes (names, colors, materials) except geometry definition.
Your code doesn't applies any transformation to the shape and just prints location of a TopoDS_Compound storing the list of all root (free) shapes in the document, so that of course this compound will have an identity location. You need to explore model to see locations assigned to root shapes or it's subshapes, in case if they are defined within STEP file (I guess this is not the case), or set your own location to this compound moving it to another place.